2012-04-12 22:21:50 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/binding_test.h"
|
2012-04-12 22:21:50 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
#include "tests/cefclient/browser/test_runner.h"
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
namespace client {
|
2012-04-12 22:21:50 +02:00
|
|
|
namespace binding_test {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
const char kTestUrlPath[] = "/binding";
|
2014-01-28 00:31:03 +01:00
|
|
|
const char kTestMessageName[] = "BindingTest";
|
2012-04-12 22:21:50 +02:00
|
|
|
|
|
|
|
// Handle messages in the browser process.
|
2014-01-28 00:31:03 +01:00
|
|
|
class Handler : public CefMessageRouterBrowserSide::Handler {
|
2012-04-12 22:21:50 +02:00
|
|
|
public:
|
2014-01-28 00:31:03 +01:00
|
|
|
Handler() {}
|
|
|
|
|
|
|
|
// Called due to cefQuery execution in binding.html.
|
|
|
|
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int64 query_id,
|
|
|
|
const CefString& request,
|
|
|
|
bool persistent,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<Callback> callback) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
// Only handle messages from the test URL.
|
|
|
|
const std::string& url = frame->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!test_runner::IsTestURL(url, kTestUrlPath)) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
const std::string& message_name = request;
|
|
|
|
if (message_name.find(kTestMessageName) == 0) {
|
|
|
|
// Reverse the string and return.
|
|
|
|
std::string result = message_name.substr(sizeof(kTestMessageName));
|
|
|
|
std::reverse(result.begin(), result.end());
|
|
|
|
callback->Success(result);
|
2012-04-12 22:21:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) {
|
2014-01-28 00:31:03 +01:00
|
|
|
handlers.insert(new Handler());
|
2012-04-12 22:21:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace binding_test
|
2015-01-22 21:21:21 +01:00
|
|
|
} // namespace client
|