Add JavaScript binding example to cefclient.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@590 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-04-12 20:21:50 +00:00
parent b5c62d3bbb
commit 647c74cf96
33 changed files with 535 additions and 302 deletions

18
cef.gyp
View File

@ -221,8 +221,10 @@
'libcef_dll_wrapper',
],
'sources': [
'tests/cefclient/cefclient_switches.cpp',
'tests/cefclient/cefclient_switches.h',
'tests/cefclient/client_app.cpp',
'tests/cefclient/client_app.h',
'tests/cefclient/client_switches.cpp',
'tests/cefclient/client_switches.h',
'tests/unittests/command_line_unittest.cc',
'tests/unittests/cookie_unittest.cc',
'tests/unittests/navigation_unittest.cc',
@ -232,9 +234,7 @@
'tests/unittests/scheme_handler_unittest.cc',
'tests/unittests/stream_unittest.cc',
'tests/unittests/string_unittest.cc',
'tests/unittests/test_app.cc',
'tests/unittests/test_app.h',
'tests/unittests/test_app_tests.cc',
'tests/unittests/client_app_delegates.cc',
'tests/unittests/test_handler.cc',
'tests/unittests/test_handler.h',
'tests/unittests/test_suite.cc',
@ -940,13 +940,13 @@
'.',
],
'sources': [
'tests/cefclient/client_app.cpp',
'tests/cefclient/client_app.h',
'tests/cefclient/process_helper_mac.cpp',
'tests/unittests/client_app_delegates.h',
'tests/unittests/process_message_unittest.cc',
'tests/unittests/test_app.cc',
'tests/unittests/test_app.h',
'tests/unittests/test_app_tests.cc',
'tests/unittests/test_handler.cc',
'tests/unittests/test_handler.h',
'tests/unittests/test_helper_mac.cc',
'tests/unittests/test_util.cc',
'tests/unittests/test_util.h',
'tests/unittests/v8_unittest.cc',

View File

@ -80,10 +80,14 @@
'cefclient_sources_common': [
'tests/cefclient/cefclient.cpp',
'tests/cefclient/cefclient.h',
'tests/cefclient/cefclient_switches.cpp',
'tests/cefclient/cefclient_switches.h',
'tests/cefclient/client_app.cpp',
'tests/cefclient/client_app.h',
'tests/cefclient/client_app_delegates.cpp',
'tests/cefclient/client_handler.cpp',
'tests/cefclient/client_handler.h',
'tests/cefclient/client_switches.cpp',
'tests/cefclient/client_switches.h',
'tests/cefclient/res/binding.html',
'tests/cefclient/res/localstorage.html',
'tests/cefclient/res/logo.png',
'tests/cefclient/res/xmlhttprequest.html',
@ -110,13 +114,14 @@
'tests/cefclient/resource_util_mac.mm',
],
'cefclient_sources_mac_helper': [
'tests/cefclient/cefclient_helper_mac.cc',
'tests/cefclient/process_helper_mac.cpp',
],
'cefclient_bundle_resources_mac': [
'tests/cefclient/mac/cefclient.icns',
'tests/cefclient/mac/English.lproj/InfoPlist.strings',
'tests/cefclient/mac/English.lproj/MainMenu.xib',
'tests/cefclient/mac/Info.plist',
'tests/cefclient/res/binding.html',
'tests/cefclient/res/localstorage.html',
'tests/cefclient/res/logo.png',
'tests/cefclient/res/xmlhttprequest.html',
@ -127,6 +132,7 @@
'tests/cefclient/resource_util_linux.cpp',
],
'cefclient_bundle_resources_linux': [
'tests/cefclient/res/binding.html',
'tests/cefclient/res/localstorage.html',
'tests/cefclient/res/logo.png',
'tests/cefclient/res/xmlhttprequest.html',

View File

@ -0,0 +1,104 @@
// 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 "cefclient/binding_test.h"
#include <algorithm>
#include <string>
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/resource_util.h"
namespace binding_test {
namespace {
const char* kTestUrl = "http://tests/binding";
const char* kMessageName = "binding_test";
// Handle messages in the browser process.
class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
public:
ProcessMessageDelegate() {
}
// From ClientHandler::ProcessMessageDelegate.
virtual bool OnProcessMessageRecieved(
CefRefPtr<ClientHandler> handler,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
std::string message_name = message->GetName();
if (message_name == kMessageName) {
// Handle the message.
std::string result;
CefRefPtr<CefListValue> args = message->GetArgumentList();
if (args->GetSize() >= 0 && args->GetType(0) == VTYPE_STRING) {
// Our result is a reverse of the original message.
result = args->GetString(0);
std::reverse(result.begin(), result.end());
} else {
result = "Invalid request";
}
// Send the result back to the render process.
CefRefPtr<CefProcessMessage> response =
CefProcessMessage::Create(kMessageName);
response->GetArgumentList()->SetString(0, result);
browser->SendProcessMessage(PID_RENDERER, response);
return true;
}
return false;
}
IMPLEMENT_REFCOUNTING(ProcessMessageDelegate);
};
// Handle resource loading in the browser process.
class RequestDelegate: public ClientHandler::RequestDelegate {
public:
RequestDelegate() {
}
// From ClientHandler::RequestDelegate.
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<ClientHandler> handler,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) OVERRIDE {
std::string url = request->GetURL();
if (url == kTestUrl) {
// Show the binding contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("binding.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
return NULL;
}
IMPLEMENT_REFCOUNTING(RequestDelegate);
};
} // namespace
void CreateProcessMessageDelegates(
ClientHandler::ProcessMessageDelegateSet& delegates) {
delegates.insert(new ProcessMessageDelegate);
}
void CreateRequestDelegates(ClientHandler::RequestDelegateSet& delegates) {
delegates.insert(new RequestDelegate);
}
void RunTest(CefRefPtr<CefBrowser> browser) {
// Load the test URL.
browser->GetMainFrame()->LoadURL(kTestUrl);
}
} // namespace binding_test

View File

@ -0,0 +1,24 @@
// 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.
#ifndef CEF_TESTS_CEFCLIENT_BINDING_TEST_H_
#define CEF_TESTS_CEFCLIENT_BINDING_TEST_H_
#pragma once
#include "cefclient/client_app.h"
#include "cefclient/client_handler.h"
namespace binding_test {
// Delegate creation. Called from ClientApp and ClientHandler.
void CreateProcessMessageDelegates(
ClientHandler::ProcessMessageDelegateSet& delegates);
void CreateRequestDelegates(ClientHandler::RequestDelegateSet& delegates);
// Run the test.
void RunTest(CefRefPtr<CefBrowser> browser);
} // namespace binding_test
#endif // CEF_TESTS_CEFCLIENT_BINDING_TEST_H_

View File

@ -12,8 +12,8 @@
#include "include/cef_command_line.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/cefclient_switches.h"
#include "cefclient/client_handler.h"
#include "cefclient/client_switches.h"
#include "cefclient/string_util.h"
#include "cefclient/util.h"
@ -28,33 +28,6 @@ int GetIntValue(const CefString& str) {
return atoi(stdStr.c_str());
}
// ClientApp implementation.
class ClientApp : public CefApp,
public CefProxyHandler {
public:
ClientApp(cef_proxy_type_t proxy_type, const CefString& proxy_config)
: proxy_type_(proxy_type),
proxy_config_(proxy_config) {
}
// CefApp methods
virtual CefRefPtr<CefProxyHandler> GetProxyHandler() OVERRIDE { return this; }
// CefProxyHandler methods
virtual void GetProxyForUrl(const CefString& url,
CefProxyInfo& proxy_info) OVERRIDE {
proxy_info.proxyType = proxy_type_;
if (!proxy_config_.empty())
CefString(&proxy_info.proxyList) = proxy_config_;
}
protected:
cef_proxy_type_t proxy_type_;
CefString proxy_config_;
IMPLEMENT_REFCOUNTING(ClientApp);
};
} // namespace
CefRefPtr<ClientHandler> g_handler;
@ -87,7 +60,8 @@ CefRefPtr<CefCommandLine> AppGetCommandLine() {
}
// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app) {
void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) {
ASSERT(app.get());
ASSERT(g_command_line.get());
if (!g_command_line.get())
return;
@ -179,7 +153,7 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app) {
if (has_proxy) {
// Provide a ClientApp instance to handle proxy resolution.
app = new ClientApp(proxy_type, proxy_config);
app->SetProxyConfig(proxy_type, proxy_config);
}
}
@ -281,7 +255,7 @@ void AppGetBrowserSettings(CefBrowserSettings& settings) {
void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
class Visitor : public CefStringVisitor {
public:
Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
explicit Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
virtual void Visit(const CefString& string) OVERRIDE {
std::string source = StringReplace(string, "<", "&lt;");
source = StringReplace(source, ">", "&gt;");
@ -300,7 +274,7 @@ void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
void RunGetTextTest(CefRefPtr<CefBrowser> browser) {
class Visitor : public CefStringVisitor {
public:
Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
explicit Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
virtual void Visit(const CefString& string) OVERRIDE {
std::string text = StringReplace(string, "<", "&lt;");
text = StringReplace(text, ">", "&gt;");

View File

@ -8,6 +8,7 @@
#include <string>
#include "include/cef_base.h"
#include "cefclient/client_app.h"
class CefApp;
class CefBrowser;
@ -29,7 +30,7 @@ void AppInitCommandLine(int argc, const char* const* argv);
CefRefPtr<CefCommandLine> AppGetCommandLine();
// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app);
void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app);
// Returns the application browser settings based on command line arguments.
void AppGetBrowserSettings(CefBrowserSettings& settings);

View File

@ -28,6 +28,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// Binary
//
IDS_BINDING BINARY "res\\binding.html"
IDS_LOGO BINARY "res\\logo.png"
IDS_LOGOBALL BINARY "res\\logoball.png"
IDS_LOCALSTORAGE BINARY "res\\localstorage.html"
@ -65,6 +66,7 @@ BEGIN
MENUITEM "Popup Window", ID_TESTS_POPUP
MENUITEM "Request", ID_TESTS_REQUEST
MENUITEM "Scheme Handler", ID_TESTS_SCHEME_HANDLER
MENUITEM "JavaScript Binding", ID_TESTS_BINDING
MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
MENUITEM "Accelerated 2D Canvas", ID_TESTS_ACCELERATED2DCANVAS

View File

@ -11,6 +11,7 @@
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
@ -76,6 +77,14 @@ gboolean SchemeHandlerActivated(GtkWidget* widget) {
return FALSE; // Don't stop this message.
}
// Callback for Debug > JavaScript Binding... menu item.
gboolean BindingActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
binding_test::RunTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Popup Window... menu item.
gboolean PopupWindowActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
@ -191,6 +200,8 @@ GtkWidget* CreateMenuBar() {
G_CALLBACK(XMLHttpRequestActivated));
AddMenuEntry(debug_menu, "Scheme Handler",
G_CALLBACK(SchemeHandlerActivated));
AddMenuEntry(debug_menu, "JavaScript Binding",
G_CALLBACK(BindingActivated));
AddMenuEntry(debug_menu, "Popup Window",
G_CALLBACK(PopupWindowActivated));
AddMenuEntry(debug_menu, "Accelerated 2D Canvas",
@ -219,9 +230,10 @@ static gboolean HandleFocus(GtkWidget* widget,
int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
CefRefPtr<ClientApp> app(new ClientApp);
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, NULL);
int exit_code = CefExecuteProcess(main_args, app.get());
if (exit_code >= 0)
return exit_code;
@ -236,13 +248,12 @@ int main(int argc, char* argv[]) {
AppInitCommandLine(argc, argv);
CefSettings settings;
CefRefPtr<CefApp> app;
// Populate the settings based on command line arguments.
AppGetSettings(settings, app);
// Initialize CEF.
CefInitialize(main_args, settings, app);
CefInitialize(main_args, settings, app.get());
// Register the scheme handler.
InitSchemeTest();

View File

@ -1,12 +0,0 @@
// 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 "include/cef_app.h"
int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
// Execute the secondary process.
return CefExecuteProcess(main_args, NULL);
}

View File

@ -11,6 +11,7 @@
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/resource_util.h"
#include "cefclient/scheme_test.h"
@ -228,6 +229,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
- (IBAction)testLocalStorage:(id)sender;
- (IBAction)testXMLHttpRequest:(id)sender;
- (IBAction)testSchemeHandler:(id)sender;
- (IBAction)testBinding:(id)sender;
- (IBAction)testPopupWindow:(id)sender;
- (IBAction)testAccelerated2DCanvas:(id)sender;
- (IBAction)testAcceleratedLayers:(id)sender;
@ -267,6 +269,9 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
[testMenu addItemWithTitle:@"Scheme Handler"
action:@selector(testSchemeHandler:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"JavaScript Binding"
action:@selector(testBinding:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Local Storage"
action:@selector(testLocalStorage:)
keyEquivalent:@""];
@ -409,6 +414,11 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
RunSchemeTest(g_handler->GetBrowser());
}
- (IBAction)testBinding:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
binding_test::RunTest(g_handler->GetBrowser());
}
- (IBAction)testPopupWindow:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunPopupTest(g_handler->GetBrowser());
@ -457,9 +467,10 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
CefRefPtr<ClientApp> app(new ClientApp);
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, NULL);
int exit_code = CefExecuteProcess(main_args, app.get());
if (exit_code >= 0)
return exit_code;
@ -476,13 +487,12 @@ int main(int argc, char* argv[]) {
AppInitCommandLine(argc, argv);
CefSettings settings;
CefRefPtr<CefApp> app;
// Populate the settings based on command line arguments.
AppGetSettings(settings, app);
// Initialize CEF.
CefInitialize(main_args, settings, app);
CefInitialize(main_args, settings, app.get());
// Initialize tests.
InitSchemeTest();

View File

@ -13,6 +13,7 @@
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/resource.h"
#include "cefclient/scheme_test.h"
@ -53,9 +54,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
UNREFERENCED_PARAMETER(lpCmdLine);
CefMainArgs main_args(hInstance);
CefRefPtr<ClientApp> app(new ClientApp);
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, NULL);
int exit_code = CefExecuteProcess(main_args, app.get());
if (exit_code >= 0)
return exit_code;
@ -67,13 +69,12 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
AppInitCommandLine(0, NULL);
CefSettings settings;
CefRefPtr<CefApp> app;
// Populate the settings based on command line arguments.
AppGetSettings(settings, app);
// Initialize CEF.
CefInitialize(main_args, settings, app);
CefInitialize(main_args, settings, app.get());
// Register the scheme handler.
InitSchemeTest();
@ -372,6 +373,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
if (browser.get())
RunSchemeTest(browser);
return 0;
case ID_TESTS_BINDING: // Test JavaScript binding
if (browser.get())
binding_test::RunTest(browser);
return 0;
case ID_TESTS_LOCALSTORAGE: // Test localStorage
if (browser.get())
RunLocalStorageTest(browser);

View File

@ -2,13 +2,17 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "tests/unittests/test_app.h"
// This file is shared by cefclient and cef_unittests so don't include using
// a qualified path.
#include "client_app.h" // NOLINT(build/include)
#include <string>
#include "include/cef_process_message.h"
#include "include/cef_task.h"
#include "include/cef_v8.h"
#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@ -97,11 +101,11 @@ void SetList(CefRefPtr<CefListValue> source, CefRefPtr<CefV8Value> target) {
}
// Handles the native implementation for the test_app extension.
class TestAppExtensionHandler : public CefV8Handler {
// Handles the native implementation for the client_app extension.
class ClientAppExtensionHandler : public CefV8Handler {
public:
explicit TestAppExtensionHandler(CefRefPtr<TestApp> test_app)
: test_app_(test_app) {
explicit ClientAppExtensionHandler(CefRefPtr<ClientApp> client_app)
: client_app_(client_app) {
}
virtual bool Execute(const CefString& name,
@ -139,7 +143,8 @@ class TestAppExtensionHandler : public CefV8Handler {
std::string name = arguments[0]->GetStringValue();
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
int browser_id = context->GetBrowser()->GetIdentifier();
test_app_->SetMessageCallback(name, browser_id, context, arguments[1]);
client_app_->SetMessageCallback(name, browser_id, context,
arguments[1]);
handled = true;
}
} else if (name == "removeMessageCallback") {
@ -148,7 +153,7 @@ class TestAppExtensionHandler : public CefV8Handler {
std::string name = arguments[0]->GetStringValue();
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
int browser_id = context->GetBrowser()->GetIdentifier();
bool removed = test_app_->RemoveMessageCallback(name, browser_id);
bool removed = client_app_->RemoveMessageCallback(name, browser_id);
retval = CefV8Value::CreateBool(removed);
handled = true;
}
@ -161,19 +166,20 @@ class TestAppExtensionHandler : public CefV8Handler {
}
private:
CefRefPtr<TestApp> test_app_;
CefRefPtr<ClientApp> client_app_;
IMPLEMENT_REFCOUNTING(TestAppExtensionHandler);
IMPLEMENT_REFCOUNTING(ClientAppExtensionHandler);
};
} // namespace
TestApp::TestApp() {
CreateTests(tests_);
ClientApp::ClientApp()
: proxy_type_(PROXY_TYPE_DIRECT) {
CreateRenderDelegates(render_delegates_);
}
void TestApp::SetMessageCallback(const std::string& message_name,
void ClientApp::SetMessageCallback(const std::string& message_name,
int browser_id,
CefRefPtr<CefV8Context> context,
CefRefPtr<CefV8Value> function) {
@ -184,7 +190,7 @@ void TestApp::SetMessageCallback(const std::string& message_name,
std::make_pair(context, function)));
}
bool TestApp::RemoveMessageCallback(const std::string& message_name,
bool ClientApp::RemoveMessageCallback(const std::string& message_name,
int browser_id) {
DCHECK(CefCurrentlyOn(TID_RENDERER));
@ -198,60 +204,57 @@ bool TestApp::RemoveMessageCallback(const std::string& message_name,
return false;
}
// static
bool TestApp::TestFailed() {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
if (command_line->HasSwitch("single-process")) {
// Check for a failure on the current test only.
return ::testing::UnitTest::GetInstance()->current_test_info()->result()->
Failed();
} else {
// Check for any global failure.
return ::testing::UnitTest::GetInstance()->Failed();
}
void ClientApp::GetProxyForUrl(const CefString& url,
CefProxyInfo& proxy_info) {
proxy_info.proxyType = proxy_type_;
if (!proxy_config_.empty())
CefString(&proxy_info.proxyList) = proxy_config_;
}
void TestApp::OnWebKitInitialized() {
// Register the test_app extension.
std::string test_app_code =
"var test_app;"
"if (!test_app)"
" test_app = {};"
void ClientApp::OnWebKitInitialized() {
// Register the client_app extension.
std::string app_code =
"var app;"
"if (!app)"
" app = {};"
"(function() {"
" test_app.sendMessage = function(name, arguments) {"
" app.sendMessage = function(name, arguments) {"
" native function sendMessage();"
" return sendMessage(name, arguments);"
" };"
" test_app.setMessageCallback = function(name, callback) {"
" app.setMessageCallback = function(name, callback) {"
" native function setMessageCallback();"
" return setMessageCallback(name, callback);"
" };"
" app.removeMessageCallback = function(name) {"
" native function removeMessageCallback();"
" return removeMessageCallback(name);"
" };"
"})();";
CefRegisterExtension("v8/test_app", test_app_code,
new TestAppExtensionHandler(this));
CefRegisterExtension("v8/app", app_code,
new ClientAppExtensionHandler(this));
// Execute test callbacks.
TestSet::iterator it = tests_.begin();
for (; it != tests_.end(); ++it)
// Execute delegate callbacks.
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end(); ++it)
(*it)->OnWebKitInitialized(this);
}
void TestApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
void ClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
// Execute test callbacks.
TestSet::iterator it = tests_.begin();
for (; it != tests_.end(); ++it)
// Execute delegate callbacks.
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end(); ++it)
(*it)->OnContextCreated(this, browser, frame, context);
}
void TestApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
void ClientApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
// Execute test callbacks.
TestSet::iterator it = tests_.begin();
for (; it != tests_.end(); ++it)
// Execute delegate callbacks.
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end(); ++it)
(*it)->OnContextReleased(this, browser, frame, context);
// Remove any JavaScript callbacks registered for the context that has been
@ -267,7 +270,7 @@ void TestApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
}
}
bool TestApp::OnProcessMessageRecieved(
bool ClientApp::OnProcessMessageRecieved(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
@ -275,9 +278,9 @@ bool TestApp::OnProcessMessageRecieved(
bool handled = false;
// Execute test callbacks.
TestSet::iterator it = tests_.begin();
for (; it != tests_.end() && !handled; ++it) {
// Execute delegate callbacks.
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end() && !handled; ++it) {
handled = (*it)->OnProcessMessageRecieved(this, browser, source_process,
message);
}

View File

@ -2,8 +2,8 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_TESTS_UNITTESTS_TEST_APP_H_
#define CEF_TESTS_UNITTESTS_TEST_APP_H_
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_APP_H_
#define CEF_TESTS_CEFCLIENT_CLIENT_APP_H_
#pragma once
#include <map>
@ -12,41 +12,43 @@
#include <utility>
#include "include/cef_app.h"
class TestApp : public CefApp,
public CefRenderProcessHandler {
class ClientApp : public CefApp,
public CefProxyHandler,
public CefRenderProcessHandler {
public:
// Interface for renderer tests. All tests must be returned via CreateTests.
// Do not perform work in the test constructor as this will slow down every
// test run.
class Test : public virtual CefBase {
// Interface for renderer delegates. All RenderDelegates must be returned via
// CreateRenderDelegates. Do not perform work in the RenderDelegate
// constructor.
class RenderDelegate : public virtual CefBase {
public:
// Called when WebKit is initialized. Used to register V8 extensions.
virtual void OnWebKitInitialized(CefRefPtr<TestApp> test_app) {
virtual void OnWebKitInitialized(CefRefPtr<ClientApp> app) {
};
// Called when a V8 context is created. Used to create V8 window bindings
// and set message callbacks. Tests should check for unique URLs to avoid
// interfering with each other.
virtual void OnContextCreated(CefRefPtr<TestApp> test_app,
// and set message callbacks. RenderDelegates should check for unique URLs
// to avoid interfering with each other.
virtual void OnContextCreated(CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
};
// Called when a V8 context is released. Used to clean up V8 window
// bindings. Tests should check for unique URLs to avoid interfering with
// each other.
virtual void OnContextReleased(CefRefPtr<TestApp> test_app,
// bindings. RenderDelegates should check for unique URLs to avoid
// interfering with each other.
virtual void OnContextReleased(CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
};
// Called when a process message is received. Return true if the message was
// handled and should not be passed on to other handlers. Tests should check
// for unique message names to avoid interfering with each other.
// handled and should not be passed on to other handlers. RenderDelegates
// should check for unique message names to avoid interfering with each
// other.
virtual bool OnProcessMessageRecieved(
CefRefPtr<TestApp> test_app,
CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
@ -54,14 +56,21 @@ class TestApp : public CefApp,
}
};
typedef std::set<CefRefPtr<Test> > TestSet;
typedef std::set<CefRefPtr<RenderDelegate> > RenderDelegateSet;
TestApp();
ClientApp();
// Set the proxy configuration. Should only be called during initialization.
void SetProxyConfig(cef_proxy_type_t proxy_type,
const CefString& proxy_config) {
proxy_type_ = proxy_type;
proxy_config_ = proxy_config;
}
// Set a JavaScript callback for the specified |message_name| and |browser_id|
// combination. Will automatically be removed when the associated context is
// released. Callbacks can also be set in JavaScript using the
// test_app.setMessageCallback function.
// app.setMessageCallback function.
void SetMessageCallback(const std::string& message_name,
int browser_id,
CefRefPtr<CefV8Context> context,
@ -69,22 +78,25 @@ class TestApp : public CefApp,
// Removes the JavaScript callback for the specified |message_name| and
// |browser_id| combination. Returns true if a callback was removed. Callbacks
// can also be removed in JavaScript using the test_app.removeMessageCallback
// can also be removed in JavaScript using the app.removeMessageCallback
// function.
bool RemoveMessageCallback(const std::string& message_name,
int browser_id);
// Returns true if the currently running test has failed.
static bool TestFailed();
private:
// Creates all of the test objects. Implemented in test_app_tests.cc.
static void CreateTests(TestSet& tests);
// Creates all of the RenderDelegate objects. Implemented in
// client_app_delegates.
static void CreateRenderDelegates(RenderDelegateSet& delegates);
// CefApp methods.
virtual CefRefPtr<CefProxyHandler> GetProxyHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler()
OVERRIDE { return this; }
// CefProxyHandler methods.
virtual void GetProxyForUrl(const CefString& url,
CefProxyInfo& proxy_info) OVERRIDE;
// CefRenderProcessHandler methods.
virtual void OnWebKitInitialized() OVERRIDE;
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
@ -98,16 +110,20 @@ class TestApp : public CefApp,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE;
// Proxy configuration.
cef_proxy_type_t proxy_type_;
CefString proxy_config_;
// Map of message callbacks.
typedef std::map<std::pair<std::string, int>,
std::pair<CefRefPtr<CefV8Context>, CefRefPtr<CefV8Value> > >
CallbackMap;
CallbackMap callback_map_;
// Set of supported tests.
TestSet tests_;
// Set of supported RenderDelegates.
RenderDelegateSet render_delegates_;
IMPLEMENT_REFCOUNTING(TestApp);
IMPLEMENT_REFCOUNTING(ClientApp);
};
#endif // CEF_TESTS_UNITTESTS_TEST_APP_H_
#endif // CEF_TESTS_CEFCLIENT_CLIENT_APP_H_

View File

@ -8,7 +8,10 @@
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/binding_test.h"
#include "cefclient/cefclient.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
@ -21,11 +24,28 @@ ClientHandler::ClientHandler()
m_StopHwnd(NULL),
m_ReloadHwnd(NULL),
m_bFormElementHasFocus(false) {
CreateProcessMessageDelegates(process_message_delegates_);
CreateRequestDelegates(request_delegates_);
}
ClientHandler::~ClientHandler() {
}
bool ClientHandler::OnProcessMessageRecieved(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
bool handled = false;
// Execute delegate callbacks.
ProcessMessageDelegateSet::iterator it = process_message_delegates_.begin();
for (; it != process_message_delegates_.end() && !handled; ++it) {
handled = (*it)->OnProcessMessageRecieved(this, browser, source_process,
message);
}
return handled;
}
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
@ -102,6 +122,45 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
frame->LoadString(ss.str(), failedUrl);
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
std::string url = request->GetURL();
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
CefRefPtr<CefStreamReader> stream =
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
ASSERT(stream.get());
return new CefStreamResourceHandler("text/plain", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("localstorage.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("xmlhttprequest.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
CefRefPtr<CefResourceHandler> handler;
// Execute delegate callbacks.
RequestDelegateSet::iterator it = request_delegates_.begin();
for (; it != request_delegates_.end() && !handler.get(); ++it)
handler = (*it)->GetResourceHandler(this, browser, frame, request);
return handler;
}
void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
@ -204,3 +263,16 @@ void ClientHandler::ShowDevTools() {
void ClientHandler::CloseDevTools() {
}
// static
void ClientHandler::CreateProcessMessageDelegates(
ProcessMessageDelegateSet& delegates) {
// Create the binding test delegates.
binding_test::CreateProcessMessageDelegates(delegates);
}
// static
void ClientHandler::CreateRequestDelegates(RequestDelegateSet& delegates) {
// Create the binding test delegates.
binding_test::CreateRequestDelegates(delegates);
}

View File

@ -7,6 +7,7 @@
#pragma once
#include <map>
#include <set>
#include <string>
#include "include/cef_client.h"
#include "cefclient/util.h"
@ -25,6 +26,42 @@ class ClientHandler : public CefClient,
public CefDisplayHandler,
public CefGeolocationHandler {
public:
// Interface for process message delegates. Do not perform work in the
// RenderDelegate constructor.
class ProcessMessageDelegate : public virtual CefBase {
public:
// Called when a process message is received. Return true if the message was
// handled and should not be passed on to other handlers.
// ProcessMessageDelegates should check for unique message names to avoid
// interfering with each other.
virtual bool OnProcessMessageRecieved(
CefRefPtr<ClientHandler> handler,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
return false;
}
};
typedef std::set<CefRefPtr<ProcessMessageDelegate> >
ProcessMessageDelegateSet;
// Interface for request handler delegates. Do not perform work in the
// RequestDelegate constructor.
class RequestDelegate : public virtual CefBase {
public:
// Called to retrieve a resource handler.
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<ClientHandler> handler,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
return NULL;
}
};
typedef std::set<CefRefPtr<RequestDelegate> > RequestDelegateSet;
ClientHandler();
virtual ~ClientHandler();
@ -44,6 +81,10 @@ class ClientHandler : public CefClient,
virtual CefRefPtr<CefGeolocationHandler> GetGeolocationHandler() OVERRIDE {
return this;
}
virtual bool OnProcessMessageRecieved(CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message)
OVERRIDE;
// CefLifeSpanHandler methods
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
@ -129,6 +170,13 @@ class ClientHandler : public CefClient,
void SetLoading(bool isLoading);
void SetNavState(bool canGoBack, bool canGoForward);
// Create all of ProcessMessageDelegate objects.
static void CreateProcessMessageDelegates(
ProcessMessageDelegateSet& delegates);
// Create all of RequestDelegateSet objects.
static void CreateRequestDelegates(RequestDelegateSet& delegates);
// The child browser window
CefRefPtr<CefBrowser> m_Browser;
@ -156,6 +204,10 @@ class ClientHandler : public CefClient,
// True if a form element currently has focus
bool m_bFormElementHasFocus;
// Registered delegates.
ProcessMessageDelegateSet process_message_delegates_;
RequestDelegateSet request_delegates_;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientHandler);
// Include the default locking implementation.

View File

@ -7,10 +7,6 @@
#include "cefclient/client_handler.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
// ClientHandler::ClientLifeSpanHandler implementation
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
@ -24,38 +20,6 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
return false;
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
std::string url = request->GetURL();
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
CefRefPtr<CefStreamReader> stream =
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
ASSERT(stream.get());
return new CefStreamResourceHandler("text/plain", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("localstorage.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("xmlhttprequest.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
return NULL;
}
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {

View File

@ -7,11 +7,7 @@
#include "cefclient/client_handler.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/cefclient.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
// ClientHandler::ClientLifeSpanHandler implementation
@ -26,38 +22,6 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
return false;
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
std::string url = request->GetURL();
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
CefRefPtr<CefStreamReader> stream =
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
ASSERT(stream.get());
return new CefStreamResourceHandler("text/plain", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("localstorage.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("xmlhttprequest.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
return NULL;
}
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {

View File

@ -6,11 +6,7 @@
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/resource.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
const CefPopupFeatures& popupFeatures,
@ -23,38 +19,6 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
return false;
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
std::string url = request->GetURL();
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
CefRefPtr<CefStreamReader> stream =
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
ASSERT(stream.get());
return new CefStreamResourceHandler("text/plain", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader(IDS_LOCALSTORAGE);
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader(IDS_XMLHTTPREQUEST);
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
return NULL;
}
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {

View File

@ -4,7 +4,7 @@
// This file is shared by cefclient and cef_unittests so don't include using
// a qualified path.
#include "cefclient_switches.h" // NOLINT(build/include)
#include "client_switches.h" // NOLINT(build/include)
namespace cefclient {

View File

@ -3,12 +3,15 @@
// be found in the LICENSE file.
#include "include/cef_app.h"
#include "tests/unittests/test_app.h"
// This file is shared by cefclient and cef_unittests so don't include using
// a qualified path.
#include "client_app.h" // NOLINT(build/include)
int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
CefRefPtr<CefApp> app(new TestApp);
CefRefPtr<CefApp> app(new ClientApp);
// Execute the secondary process.
return CefExecuteProcess(main_args, app);

View File

@ -0,0 +1,27 @@
<html>
<head>
<title>Binding Test</title>
<script language="JavaScript">
// Register the callback for messages from the browser process.
app.setMessageCallback('binding_test', function(name, args) {
document.getElementById('result').value = "Response: "+args[0];
});
// Send a message to the browser process.
function sendMessage() {
var msg = document.getElementById("message").value;
app.sendMessage('binding_test', [msg]);
}
</script>
</head>
<body>
<form>
Message: <input type="text" id="message" value="My Message">
<br/><input type="button" onclick="sendMessage();" value="Send Message">
<br/>You should see the reverse of your message below:
<br/><textarea rows="10" cols="40" id="result"></textarea>
</form>
</body>
</html>

View File

@ -37,11 +37,13 @@
#define ID_TESTS_XMLHTTPREQUEST 32770
#define ID_TESTS_DRAGDROP 32771
#define ID_TESTS_GEOLOCATION 32772
#define ID_TESTS_BINDING 32773
#define IDC_STATIC -1
#define IDS_LOGO 1000
#define IDS_LOGOBALL 1001
#define IDS_LOCALSTORAGE 1002
#define IDS_XMLHTTPREQUEST 1003
#define IDS_BINDING 1000
#define IDS_LOGO 1001
#define IDS_LOGOBALL 1002
#define IDS_LOCALSTORAGE 1003
#define IDS_XMLHTTPREQUEST 1004
// Avoid files associated with MacOS
#define _X86_

View File

@ -24,8 +24,9 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId);
// Load the resource with the specified name.
bool LoadBinaryResource(const char* resource_name, std::string& resource_data);
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name);
#endif
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name);
#endif // CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_

View File

@ -5,6 +5,7 @@
#include "cefclient/resource_util.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_byte_read_handler.h"
#include "cefclient/util.h"
#if defined(OS_WIN)
@ -37,4 +38,24 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId) {
return NULL;
}
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
// Map of resource labels to BINARY id values.
static struct _resource_map {
char* name;
int id;
} resource_map[] = {
{"binding.html", IDS_BINDING},
{"localstorage.html", IDS_LOCALSTORAGE},
{"xmlhttprequest.html", IDS_XMLHTTPREQUEST},
};
for (int i = 0; i < sizeof(resource_map)/sizeof(_resource_map); ++i) {
if (!strcmp(resource_map[i].name, resource_name))
return GetBinaryResourceReader(resource_map[i].id);
}
ASSERT(FALSE); // The resource should be found.
return NULL;
}
#endif // OS_WIN

View File

@ -0,0 +1,17 @@
// 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/client_app.h"
// static
void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) {
// Bring in the process message tests.
extern void CreateProcessMessageRendererTests(
ClientApp::RenderDelegateSet& delegates);
CreateProcessMessageRendererTests(delegates);
// Bring in the V8 tests.
extern void CreateV8RendererTests(ClientApp::RenderDelegateSet& delegates);
CreateV8RendererTests(delegates);
}

View File

@ -4,7 +4,7 @@
#include "include/cef_process_message.h"
#include "include/cef_task.h"
#include "tests/unittests/test_app.h"
#include "tests/cefclient/client_app.h"
#include "tests/unittests/test_handler.h"
#include "tests/unittests/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -40,12 +40,12 @@ CefRefPtr<CefProcessMessage> CreateTestMessage() {
}
// Renderer side.
class SendRecvRendererTest : public TestApp::Test {
class SendRecvRendererTest : public ClientApp::RenderDelegate {
public:
SendRecvRendererTest() {}
virtual bool OnProcessMessageRecieved(
CefRefPtr<TestApp> test_app,
CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
@ -90,9 +90,9 @@ class SendRecvTestHandler : public TestHandler {
"<html><head>\n"
"<script>\n"
"function cb(name, args) {\n"
" test_app.sendMessage(name, args);\n"
" app.sendMessage(name, args);\n"
"}\n"
"test_app.setMessageCallback('"+std::string(kSendRecvMsg)+"', cb);\n"
"app.setMessageCallback('"+std::string(kSendRecvMsg)+"', cb);\n"
"</script>\n"
"<body>TEST JAVASCRIPT</body>\n"
"</head></html>";
@ -176,8 +176,9 @@ TEST(ProcessMessageTest, Copy) {
// Entry point for creating process message renderer test objects.
// Called from test_app_tests.cc.
void CreateProcessMessageRendererTests(TestApp::TestSet& tests) {
// Called from client_app_delegates.cc.
void CreateProcessMessageRendererTests(
ClientApp::RenderDelegateSet& delegates) {
// For ProcessMessageTest.SendRecv
tests.insert(new SendRecvRendererTest);
delegates.insert(new SendRecvRendererTest);
}

View File

@ -4,7 +4,7 @@
#include "include/cef_app.h"
#include "include/cef_task.h"
#include "tests/unittests/test_app.h"
#include "tests/cefclient/client_app.h"
#include "tests/unittests/test_suite.h"
#include "base/bind.h"
#include "base/command_line.h"
@ -51,7 +51,7 @@ int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
#endif
CefRefPtr<CefApp> app(new TestApp);
CefRefPtr<CefApp> app(new ClientApp);
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, app);

View File

@ -1,16 +0,0 @@
// 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/unittests/test_app.h"
// static
void TestApp::CreateTests(TestSet& tests) {
// Bring in the process message tests.
extern void CreateProcessMessageRendererTests(TestApp::TestSet& tests);
CreateProcessMessageRendererTests(tests);
// Bring in the V8 tests.
extern void CreateV8RendererTests(TestApp::TestSet& tests);
CreateV8RendererTests(tests);
}

View File

@ -3,6 +3,7 @@
// can be found in the LICENSE file.
#include "tests/unittests/test_handler.h"
#include "include/cef_command_line.h"
#include "include/cef_runnable.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_stream_resource_handler.h"
@ -114,3 +115,16 @@ void WaitForThread(CefThreadId thread_id) {
CefPostTask(thread_id, NewCefRunnableFunction(&NotifyEvent, &event));
event.Wait();
}
bool TestFailed() {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
if (command_line->HasSwitch("single-process")) {
// Check for a failure on the current test only.
return ::testing::UnitTest::GetInstance()->current_test_info()->result()->
Failed();
} else {
// Check for any global failure.
return ::testing::UnitTest::GetInstance()->Failed();
}
}

View File

@ -114,4 +114,7 @@ void WaitForThread(CefThreadId thread_id);
#define WaitForIOThread() WaitForThread(TID_IO)
#define WaitForUIThread() WaitForThread(TID_UI)
// Returns true if the currently running test has failed.
bool TestFailed();
#endif // CEF_TESTS_UNITTESTS_TEST_HANDLER_H_

View File

@ -3,7 +3,7 @@
// can be found in the LICENSE file.
#include "tests/unittests/test_suite.h"
#include "tests/cefclient/cefclient_switches.h"
#include "tests/cefclient/client_switches.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/test/test_suite.h"

View File

@ -5,7 +5,7 @@
#include <sstream>
#include "include/cef_task.h"
#include "include/cef_v8.h"
#include "tests/unittests/test_app.h"
#include "tests/cefclient/client_app.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -60,7 +60,7 @@ enum V8TestMode {
};
// Renderer side.
class V8RendererTest : public TestApp::Test {
class V8RendererTest : public ClientApp::RenderDelegate {
public:
V8RendererTest() {}
@ -1384,7 +1384,7 @@ class V8RendererTest : public TestApp::Test {
DestroyTest();
}
virtual void OnContextCreated(CefRefPtr<TestApp> test_app,
virtual void OnContextCreated(CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) OVERRIDE {
@ -1443,12 +1443,12 @@ class V8RendererTest : public TestApp::Test {
}
virtual bool OnProcessMessageRecieved(
CefRefPtr<TestApp> test_app,
CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
if (message->GetName() == kV8TestMsg) {
test_app_ = test_app;
app_ = app;
browser_ = browser;
V8TestMode test_mode =
@ -1467,7 +1467,7 @@ class V8RendererTest : public TestApp::Test {
// Return from the test.
void DestroyTest() {
// Check if the test has failed.
bool result = !TestApp::TestFailed();
bool result = !TestFailed();
// Return the result to the browser process.
CefRefPtr<CefProcessMessage> return_msg =
@ -1475,7 +1475,7 @@ class V8RendererTest : public TestApp::Test {
EXPECT_TRUE(return_msg->GetArgumentList()->SetBool(0, result));
EXPECT_TRUE(browser_->SendProcessMessage(PID_BROWSER, return_msg));
test_app_ = NULL;
app_ = NULL;
browser_ = NULL;
}
@ -1486,7 +1486,7 @@ class V8RendererTest : public TestApp::Test {
return context;
}
CefRefPtr<TestApp> test_app_;
CefRefPtr<ClientApp> app_;
CefRefPtr<CefBrowser> browser_;
IMPLEMENT_REFCOUNTING(SendRecvRendererTest);
@ -1562,9 +1562,9 @@ class V8TestHandler : public TestHandler {
// Entry point for creating V8 renderer test objects.
// Called from test_app_tests.cc.
void CreateV8RendererTests(TestApp::TestSet& tests) {
tests.insert(new V8RendererTest);
// Called from client_app_delegates.cc.
void CreateV8RendererTests(ClientApp::RenderDelegateSet& delegates) {
delegates.insert(new V8RendererTest);
}