diff options
Diffstat (limited to 'tests/cefclient/browser/binding_test.cc')
-rw-r--r-- | tests/cefclient/browser/binding_test.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/cefclient/browser/binding_test.cc b/tests/cefclient/browser/binding_test.cc new file mode 100644 index 00000000..0dfdc775 --- /dev/null +++ b/tests/cefclient/browser/binding_test.cc @@ -0,0 +1,58 @@ +// 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. + +#include "tests/cefclient/browser/binding_test.h" + +#include <algorithm> +#include <string> + +#include "tests/cefclient/browser/test_runner.h" + +namespace client { +namespace binding_test { + +namespace { + +const char kTestUrlPath[] = "/binding"; +const char kTestMessageName[] = "BindingTest"; + +// Handle messages in the browser process. +class Handler : public CefMessageRouterBrowserSide::Handler { + public: + 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, + CefRefPtr<Callback> callback) override { + // Only handle messages from the test URL. + const std::string& url = frame->GetURL(); + if (!test_runner::IsTestURL(url, kTestUrlPath)) { + return false; + } + + 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); + return true; + } + + return false; + } +}; + +} // namespace + +void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) { + handlers.insert(new Handler()); +} + +} // namespace binding_test +} // namespace client |