Make CEF compliant with Google/Chromium style (issue #473).

- Add a new check_style tool based on Google's cpplint that can be used to verify compliance of pending changes and specific files/directories.
- Update existing CEF source code to be compliant with the style requirements.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@463 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2012-01-09 23:46:23 +00:00
parent 9cc61f448b
commit 1073577d03
558 changed files with 9002 additions and 10977 deletions

View File

@@ -2,18 +2,19 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "binding_test.h"
#include "cefclient/binding_test.h"
#include <sstream>
#include <string>
#include <vector>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_v8.h"
#include <sstream>
// Implementation of the V8 handler class for the "window.cef_test.Dump"
// function.
class ClientV8FunctionHandler : public CefV8Handler
{
public:
class ClientV8FunctionHandler : public CefV8Handler {
public:
ClientV8FunctionHandler() {}
virtual ~ClientV8FunctionHandler() {}
@@ -23,17 +24,14 @@ public:
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception) OVERRIDE
{
if(name == "Dump")
{
CefString& exception) OVERRIDE {
if (name == "Dump") {
// The "Dump" function will return a human-readable dump of the input
// arguments.
std::stringstream stream;
size_t i;
for(i = 0; i < arguments.size(); ++i)
{
for (i = 0; i < arguments.size(); ++i) {
stream << "arg[" << i << "] = ";
PrintValue(arguments[i], stream, 0);
stream << "\n";
@@ -41,15 +39,13 @@ public:
retval = CefV8Value::CreateString(stream.str());
return true;
}
else if(name == "Call")
{
} else if (name == "Call") {
// The "Call" function will execute a function to get an object and then
// return the result of calling a function belonging to that object. The
// first arument is the function that will return an object and the second
// argument is the function that will be called on that returned object.
int argSize = arguments.size();
if(argSize < 2 || !arguments[0]->IsFunction()
if (argSize < 2 || !arguments[0]->IsFunction()
|| !arguments[1]->IsString())
return false;
@@ -68,7 +64,7 @@ public:
return false;
// Verify that the returned value is an object.
if(!objectPtr.get() || !objectPtr->IsObject())
if (!objectPtr.get() || !objectPtr->IsObject())
return false;
// Retrieve the member function specified by name in the second argument
@@ -76,13 +72,13 @@ public:
CefRefPtr<CefV8Value> funcPtr =
objectPtr->GetValue(arguments[1]->GetStringValue());
// Verify that the returned value is a function.
if(!funcPtr.get() || !funcPtr->IsFunction())
if (!funcPtr.get() || !funcPtr->IsFunction())
return false;
// Pass any additional arguments on to the member function.
for(int i = 2; i < argSize; ++i)
for (int i = 2; i < argSize; ++i)
argList.push_back(arguments[i]);
// Execute the member function.
result = funcPtr->ExecuteFunction(arguments[0], argList, retval,
exceptionPtr, false);
@@ -95,40 +91,39 @@ public:
// Simple function for formatted output of a V8 value.
void PrintValue(CefRefPtr<CefV8Value> value, std::stringstream &stream,
int indent)
{
int indent) {
std::stringstream indent_stream;
for(int i = 0; i < indent; ++i)
for (int i = 0; i < indent; ++i)
indent_stream << " ";
std::string indent_str = indent_stream.str();
if(value->IsUndefined())
if (value->IsUndefined())
stream << "(undefined)";
else if(value->IsNull())
else if (value->IsNull())
stream << "(null)";
else if(value->IsBool())
else if (value->IsBool())
stream << "(bool) " << (value->GetBoolValue() ? "true" : "false");
else if(value->IsInt())
else if (value->IsInt())
stream << "(int) " << value->GetIntValue();
else if(value->IsDouble())
else if (value->IsDouble())
stream << "(double) " << value->GetDoubleValue();
else if(value->IsString())
else if (value->IsString())
stream << "(string) " << std::string(value->GetStringValue());
else if(value->IsFunction())
else if (value->IsFunction())
stream << "(function) " << std::string(value->GetFunctionName());
else if(value->IsArray()) {
else if (value->IsArray()) {
stream << "(array) [";
int len = value->GetArrayLength();
for(int i = 0; i < len; ++i) {
for (int i = 0; i < len; ++i) {
stream << "\n " << indent_str.c_str() << i << " = ";
PrintValue(value->GetValue(i), stream, indent+1);
}
stream << "\n" << indent_str.c_str() << "]";
} else if(value->IsObject()) {
} else if (value->IsObject()) {
stream << "(object) [";
std::vector<CefString> keys;
if(value->GetKeys(keys)) {
for(size_t i = 0; i < keys.size(); ++i) {
if (value->GetKeys(keys)) {
for (size_t i = 0; i < keys.size(); ++i) {
stream << "\n " << indent_str.c_str() << keys[i].c_str() << " = ";
PrintValue(value->GetValue(keys[i]), stream, indent+1);
}
@@ -143,8 +138,7 @@ public:
void InitBindingTest(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
CefRefPtr<CefV8Value> object) {
// Create the new V8 object.
CefRefPtr<CefV8Value> testObjPtr = CefV8Value::CreateObject(NULL, NULL);
// Add the new V8 object to the global window object with the name
@@ -164,8 +158,7 @@ void InitBindingTest(CefRefPtr<CefBrowser> browser,
V8_PROPERTY_ATTRIBUTE_NONE);
}
void RunBindingTest(CefRefPtr<CefBrowser> browser)
{
void RunBindingTest(CefRefPtr<CefBrowser> browser) {
std::string html =
"<html><body>ClientV8FunctionHandler says:<br><pre>"
"<script language=\"JavaScript\">"
@@ -178,7 +171,8 @@ void RunBindingTest(CefRefPtr<CefBrowser> browser)
" var obj = {};"
" (function() {"
" obj.GetMessage = function(a) {"
" return 'Calling a function with value '+a+' on a user object succeeded.';"
" return 'Calling a function with value '+a+' on a user object "
"succeeded.';"
" };"
" })();"
" return obj;"

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_BINDING_TEST_H
#define _CEFCLIENT_BINDING_TEST_H
#ifndef CEF_TESTS_CEFCLIENT_BINDING_TEST_H_
#define CEF_TESTS_CEFCLIENT_BINDING_TEST_H_
#pragma once
#include "include/cef_base.h"
@@ -19,4 +20,4 @@ void InitBindingTest(CefRefPtr<CefBrowser> browser,
// Run the test.
void RunBindingTest(CefRefPtr<CefBrowser> browser);
#endif // _CEFCLIENT_BINDING_TEST_H
#endif // CEF_TESTS_CEFCLIENT_BINDING_TEST_H_

View File

@@ -2,27 +2,26 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient.h"
#include "cefclient/cefclient.h"
#include <stdio.h>
#include <cstdlib>
#include <sstream>
#include <string>
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "include/cef_web_urlrequest.h"
#include "cefclient_switches.h"
#include "client_handler.h"
#include "binding_test.h"
#include "string_util.h"
#include "util.h"
#include <cstdlib>
#include <sstream>
#include <stdio.h>
#include <string>
#include "cefclient/cefclient_switches.h"
#include "cefclient/client_handler.h"
#include "cefclient/binding_test.h"
#include "cefclient/string_util.h"
#include "cefclient/util.h"
namespace {
void UIT_InvokeScript(CefRefPtr<CefBrowser> browser)
{
void UIT_InvokeScript(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
@@ -67,8 +66,7 @@ void UIT_InvokeScript(CefRefPtr<CefBrowser> browser)
}
// Return the int representation of the specified string.
int GetIntValue(const CefString& str)
{
int GetIntValue(const CefString& str) {
if (str.empty())
return 0;
@@ -79,13 +77,11 @@ int GetIntValue(const CefString& str)
// ClientApp implementation.
class ClientApp : public CefApp,
public CefProxyHandler
{
public:
public CefProxyHandler {
public:
ClientApp(cef_proxy_type_t proxy_type, const CefString& proxy_config)
: proxy_type_(proxy_type),
proxy_config_(proxy_config)
{
proxy_config_(proxy_config) {
}
// CefApp methods
@@ -93,41 +89,37 @@ public:
// CefProxyHandler methods
virtual void GetProxyForUrl(const CefString& url,
CefProxyInfo& proxy_info) OVERRIDE
{
CefProxyInfo& proxy_info) OVERRIDE {
proxy_info.proxyType = proxy_type_;
if (!proxy_config_.empty())
CefString(&proxy_info.proxyList) = proxy_config_;
}
protected:
protected:
cef_proxy_type_t proxy_type_;
CefString proxy_config_;
IMPLEMENT_REFCOUNTING(ClientApp);
};
} // namespace
} // namespace
CefRefPtr<ClientHandler> g_handler;
CefRefPtr<CefCommandLine> g_command_line;
CefRefPtr<CefBrowser> AppGetBrowser()
{
if(!g_handler.get())
CefRefPtr<CefBrowser> AppGetBrowser() {
if (!g_handler.get())
return NULL;
return g_handler->GetBrowser();
}
CefWindowHandle AppGetMainHwnd()
{
if(!g_handler.get())
CefWindowHandle AppGetMainHwnd() {
if (!g_handler.get())
return NULL;
return g_handler->GetMainHwnd();
}
void AppInitCommandLine(int argc, const char* const* argv)
{
void AppInitCommandLine(int argc, const char* const* argv) {
g_command_line = CefCommandLine::CreateCommandLine();
#if defined(OS_WIN)
g_command_line->InitFromString(::GetCommandLineW());
@@ -137,14 +129,12 @@ void AppInitCommandLine(int argc, const char* const* argv)
}
// Returns the application command line object.
CefRefPtr<CefCommandLine> AppGetCommandLine()
{
CefRefPtr<CefCommandLine> AppGetCommandLine() {
return g_command_line;
}
// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app)
{
void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app) {
ASSERT(g_command_line.get());
if (!g_command_line.get())
return;
@@ -247,8 +237,7 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app)
}
// Returns the application browser settings based on command line arguments.
void AppGetBrowserSettings(CefBrowserSettings& settings)
{
void AppGetBrowserSettings(CefBrowserSettings& settings) {
ASSERT(g_command_line.get());
if (!g_command_line.get())
return;
@@ -344,46 +333,39 @@ void AppGetBrowserSettings(CefBrowserSettings& settings)
g_command_line->HasSwitch(cefclient::kFullscreenEnabled);
}
static void ExecuteGetSource(CefRefPtr<CefFrame> frame)
{
static void ExecuteGetSource(CefRefPtr<CefFrame> frame) {
// Retrieve the current page source and display.
std::string source = frame->GetSource();
source = StringReplace(source, "<", "&lt;");
source = StringReplace(source, ">", "&gt;");
std::stringstream ss;
ss << "<html><body>Source:" << "<pre>" << source
<< "</pre></body></html>";
ss << "<html><body>Source:<pre>" << source << "</pre></body></html>";
frame->LoadString(ss.str(), "http://tests/getsource");
}
void RunGetSourceTest(CefRefPtr<CefBrowser> browser)
{
void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
// Execute the GetSource() call on the UI thread.
CefPostTask(TID_UI,
NewCefRunnableFunction(&ExecuteGetSource, browser->GetMainFrame()));
}
static void ExecuteGetText(CefRefPtr<CefFrame> frame)
{
static void ExecuteGetText(CefRefPtr<CefFrame> frame) {
std::string text = frame->GetText();
text = StringReplace(text, "<", "&lt;");
text = StringReplace(text, ">", "&gt;");
std::stringstream ss;
ss << "<html><body>Text:" << "<pre>" << text
<< "</pre></body></html>";
ss << "<html><body>Text:<pre>" << text << "</pre></body></html>";
frame->LoadString(ss.str(), "http://tests/gettext");
}
void RunGetTextTest(CefRefPtr<CefBrowser> browser)
{
void RunGetTextTest(CefRefPtr<CefBrowser> browser) {
// Execute the GetText() call on the UI thread.
CefPostTask(TID_UI,
NewCefRunnableFunction(&ExecuteGetText, browser->GetMainFrame()));
}
void RunRequestTest(CefRefPtr<CefBrowser> browser)
{
// Create a new request
void RunRequestTest(CefRefPtr<CefBrowser> browser) {
// Create a new request
CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
// Set the request URL
@@ -409,14 +391,12 @@ void RunRequestTest(CefRefPtr<CefBrowser> browser)
browser->GetMainFrame()->LoadRequest(request);
}
void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser)
{
void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->ExecuteJavaScript(
"alert('JavaScript execute works!');", "about:blank", 0);
}
void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser)
{
void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser) {
if (CefCurrentlyOn(TID_UI)) {
UIT_InvokeScript(browser);
} else {
@@ -425,56 +405,46 @@ void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser)
}
}
void RunPopupTest(CefRefPtr<CefBrowser> browser)
{
void RunPopupTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->ExecuteJavaScript(
"window.open('http://www.google.com');", "about:blank", 0);
}
void RunLocalStorageTest(CefRefPtr<CefBrowser> browser)
{
void RunLocalStorageTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://tests/localstorage");
}
void RunAccelerated2DCanvasTest(CefRefPtr<CefBrowser> browser)
{
void RunAccelerated2DCanvasTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL(
"http://mudcu.be/labs/JS1k/BreathingGalaxies.html");
}
void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser)
{
void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL(
"http://webkit.org/blog-files/3d-transforms/poster-circle.html");
}
void RunWebGLTest(CefRefPtr<CefBrowser> browser)
{
void RunWebGLTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL(
"http://webglsamples.googlecode.com/hg/field/field.html");
}
void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser)
{
void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL(
"http://www.youtube.com/watch?v=siOHh0uzcuY&html5=True");
}
void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser)
{
void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://tests/xmlhttprequest");
}
void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
{
class RequestClient : public CefWebURLRequestClient
{
public:
RequestClient(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser) {
class RequestClient : public CefWebURLRequestClient {
public:
explicit RequestClient(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
RequestState state)
{
virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
RequestState state) {
REQUIRE_UI_THREAD();
if (state == WUR_STATE_DONE) {
buffer_ = StringReplace(buffer_, "<", "&lt;");
@@ -486,36 +456,31 @@ void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
"http://tests/weburlrequest");
}
}
virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response)
{
virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response) {
REQUIRE_UI_THREAD();
}
virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefResponse> response)
{
virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefResponse> response) {
REQUIRE_UI_THREAD();
}
virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
uint64 bytesSent, uint64 totalBytesToBeSent)
{
virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
uint64 bytesSent, uint64 totalBytesToBeSent) {
REQUIRE_UI_THREAD();
}
virtual void OnData(CefRefPtr<CefWebURLRequest> requester,
const void* data, int dataLength)
{
virtual void OnData(CefRefPtr<CefWebURLRequest> requester,
const void* data, int dataLength) {
REQUIRE_UI_THREAD();
buffer_.append(static_cast<const char*>(data), dataLength);
}
virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
ErrorCode errorCode)
{
virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
ErrorCode errorCode) {
REQUIRE_UI_THREAD();
std::stringstream ss;
ss << "Load failed with error code " << errorCode;
@@ -523,7 +488,7 @@ void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
"http://tests/weburlrequest");
}
protected:
protected:
CefRefPtr<CefBrowser> browser_;
std::string buffer_;
@@ -538,27 +503,24 @@ void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
CefWebURLRequest::CreateWebURLRequest(request, client));
}
void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
{
class Listener : public CefDOMEventListener
{
public:
void RunDOMAccessTest(CefRefPtr<CefBrowser> browser) {
class Listener : public CefDOMEventListener {
public:
Listener() {}
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event)
{
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event) {
CefRefPtr<CefDOMDocument> document = event->GetDocument();
ASSERT(document.get());
std::stringstream ss;
CefRefPtr<CefDOMNode> button = event->GetTarget();
ASSERT(button.get());
std::string buttonValue = button->GetElementAttribute("value");
ss << "You clicked the " << buttonValue.c_str() << " button. ";
if (document->HasSelection()) {
std::string startName, endName;
// Determine the start name by first trying to locate the "id" attribute
// and then defaulting to the tag name.
{
@@ -590,7 +552,7 @@ void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
} else {
ss << "Nothing is selected.";
}
// Update the description.
CefRefPtr<CefDOMNode> desc = document->GetElementById("description");
ASSERT(desc.get());
@@ -603,12 +565,10 @@ void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
IMPLEMENT_REFCOUNTING(Listener);
};
class Visitor : public CefDOMVisitor
{
public:
class Visitor : public CefDOMVisitor {
public:
Visitor() {}
virtual void Visit(CefRefPtr<CefDOMDocument> document)
{
virtual void Visit(CefRefPtr<CefDOMDocument> document) {
// Register an click listener for the button.
CefRefPtr<CefDOMNode> button = document->GetElementById("button");
ASSERT(button.get());
@@ -626,12 +586,10 @@ void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
browser->GetMainFrame()->LoadURL("http://tests/domaccess");
}
void RunDragDropTest(CefRefPtr<CefBrowser> browser)
{
void RunDragDropTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://html5demos.com/drag");
}
void RunModalDialogTest(CefRefPtr<CefBrowser> browser)
{
void RunModalDialogTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://tests/modalmain");
}

View File

@@ -2,9 +2,11 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_H
#define _CEFCLIENT_H
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
#pragma once
#include <string>
#include "include/cef_base.h"
class CefApp;
@@ -55,4 +57,4 @@ void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser);
void RunGetImageTest(CefRefPtr<CefBrowser> browser);
#endif
#endif // _CEFCLIENT_H
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_H_

View File

@@ -2,24 +2,22 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include "cefclient/cefclient.h"
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "binding_test.h"
#include "client_handler.h"
#include "extension_test.h"
#include "scheme_test.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <unistd.h>
#include "string_util.h"
#include <iostream>
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/extension_test.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
using namespace std;
char szWorkingDir[512]; // The current working directory
char szWorkingDir[512]; // The current working directory
// The global ClientHandler reference.
extern CefRefPtr<ClientHandler> g_handler;
@@ -35,31 +33,31 @@ void TerminationSignalHandler(int signatl) {
// Callback for Debug > Get Source... menu item.
gboolean GetSourceActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
RunGetSourceTest(g_handler->GetBrowser());
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunGetSourceTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Get Source... menu item.
gboolean GetTextActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
RunGetTextTest(g_handler->GetBrowser());
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunGetTextTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > JS Binding... menu item.
gboolean JSBindngActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
RunBindingTest(g_handler->GetBrowser());
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunBindingTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > JS Extension... menu item.
gboolean JSExtensionActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunExtensionTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -67,7 +65,7 @@ gboolean JSExtensionActivated(GtkWidget* widget) {
// Callback for Debug > JS Execute... menu item.
gboolean JSExecuteActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunJavaScriptExecuteTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -75,7 +73,7 @@ gboolean JSExecuteActivated(GtkWidget* widget) {
// Callback for Debug > Request... menu item.
gboolean RequestActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunRequestTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -83,7 +81,7 @@ gboolean RequestActivated(GtkWidget* widget) {
// Callback for Debug > Local Storage... menu item.
gboolean LocalStorageActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunLocalStorageTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -91,7 +89,7 @@ gboolean LocalStorageActivated(GtkWidget* widget) {
// Callback for Debug > XMLHttpRequest... menu item.
gboolean XMLHttpRequestActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunXMLHTTPRequestTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -99,7 +97,7 @@ gboolean XMLHttpRequestActivated(GtkWidget* widget) {
// Callback for Debug > WebURLRequest... menu item.
gboolean WebURLRequestActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunWebURLRequestTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -107,7 +105,7 @@ gboolean WebURLRequestActivated(GtkWidget* widget) {
// Callback for Debug > DOM Access... menu item.
gboolean DOMAccessActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunDOMAccessTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -115,7 +113,7 @@ gboolean DOMAccessActivated(GtkWidget* widget) {
// Callback for Debug > Scheme Handler... menu item.
gboolean SchemeHandlerActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunSchemeTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -123,7 +121,7 @@ gboolean SchemeHandlerActivated(GtkWidget* widget) {
// Callback for Debug > Popup Window... menu item.
gboolean PopupWindowActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunPopupTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -131,7 +129,7 @@ gboolean PopupWindowActivated(GtkWidget* widget) {
// Callback for Debug > Accelerated 2D Canvas:... menu item.
gboolean Accelerated2DCanvasActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunAccelerated2DCanvasTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -139,7 +137,7 @@ gboolean Accelerated2DCanvasActivated(GtkWidget* widget) {
// Callback for Debug > Accelerated Layers:... menu item.
gboolean AcceleratedLayersActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunAcceleratedLayersTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -147,7 +145,7 @@ gboolean AcceleratedLayersActivated(GtkWidget* widget) {
// Callback for Debug > WebGL:... menu item.
gboolean WebGLActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunWebGLTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -155,7 +153,7 @@ gboolean WebGLActivated(GtkWidget* widget) {
// Callback for Debug > HTML5 Video... menu item.
gboolean HTML5VideoActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunHTML5VideoTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
@@ -163,7 +161,7 @@ gboolean HTML5VideoActivated(GtkWidget* widget) {
// Callback for Debug > Zoom In... menu item.
gboolean ZoomInActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
}
@@ -173,7 +171,7 @@ gboolean ZoomInActivated(GtkWidget* widget) {
// Callback for Debug > Zoom Out... menu item.
gboolean ZoomOutActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
}
@@ -183,7 +181,7 @@ gboolean ZoomOutActivated(GtkWidget* widget) {
// Callback for Debug > Zoom Reset... menu item.
gboolean ZoomResetActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->SetZoomLevel(0.0);
}
@@ -192,7 +190,7 @@ gboolean ZoomResetActivated(GtkWidget* widget) {
}
gboolean DragDropActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
RunDragDropTest(browser);
}
@@ -201,7 +199,7 @@ gboolean DragDropActivated(GtkWidget* widget) {
}
gboolean ShowDevtoolsActivated(GtkWidget* widget) {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->ShowDevTools();
}
@@ -237,7 +235,7 @@ void ReloadButtonClicked(GtkButton* button) {
void URLEntryActivate(GtkEntry* entry) {
if (!g_handler.get() || !g_handler->GetBrowserHwnd())
return;
const gchar* url = gtk_entry_get_text(entry);
g_handler->GetBrowser()->GetMainFrame()->LoadURL(std::string(url).c_str());
}
@@ -263,7 +261,7 @@ GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) {
GtkWidget* CreateMenuBar() {
GtkWidget* menu_bar = gtk_menu_bar_new();
GtkWidget* debug_menu = CreateMenu(menu_bar, "Tests");
AddMenuEntry(debug_menu, "Get Source",
G_CALLBACK(GetSourceActivated));
AddMenuEntry(debug_menu, "Get Text",
@@ -311,7 +309,7 @@ GtkWidget* CreateMenuBar() {
// WebViewDelegate::TakeFocus in the test webview delegate.
static gboolean HandleFocus(GtkWidget* widget,
GdkEventFocus* focus) {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
// Give focus to the browser window.
g_handler->GetBrowser()->SetFocus(true);
}
@@ -320,10 +318,10 @@ static gboolean HandleFocus(GtkWidget* widget,
}
int main(int argc, char *argv[]) {
if(!getcwd(szWorkingDir, sizeof (szWorkingDir)))
if (!getcwd(szWorkingDir, sizeof (szWorkingDir)))
return -1;
GtkWidget *window;
GtkWidget* window;
gtk_init(&argc, &argv);
@@ -387,10 +385,10 @@ int main(int argc, char *argv[]) {
GtkToolItem* tool_item = gtk_tool_item_new();
gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd);
gtk_tool_item_set_expand(tool_item, TRUE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1); //append
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1); // append
gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_widget_destroyed), &window);
g_signal_connect(G_OBJECT(window), "destroy",

View File

@@ -3,20 +3,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cefclient.h"
#import <Cocoa/Cocoa.h>
#include <sstream>
#include "cefclient/cefclient.h"
#include "include/cef_app.h"
#import "include/cef_application_mac.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "binding_test.h"
#include "client_handler.h"
#include "extension_test.h"
#include "resource_util.h"
#include "scheme_test.h"
#include "string_util.h"
#import <Cocoa/Cocoa.h>
#include <sstream>
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/extension_test.h"
#include "cefclient/resource_util.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
// The global ClientHandler reference.
extern CefRefPtr<ClientHandler> g_handler;
@@ -144,7 +144,7 @@ static NSAutoreleasePool* g_autopool = nil;
}
- (void)windowDidBecomeKey:(NSNotification*)notification {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
// Give focus to the browser window.
g_handler->GetBrowser()->SetFocus(true);
}
@@ -393,130 +393,130 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
}
- (IBAction)testGetSource:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunGetSourceTest(g_handler->GetBrowser());
}
- (IBAction)testGetText:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunGetTextTest(g_handler->GetBrowser());
}
- (IBAction)testJSBinding:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunBindingTest(g_handler->GetBrowser());
}
- (IBAction)testJSExtension:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunExtensionTest(g_handler->GetBrowser());
}
- (IBAction)testJSExtensionPerf:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunExtensionPerfTest(g_handler->GetBrowser());
}
- (IBAction)testJSExecute:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunJavaScriptExecuteTest(g_handler->GetBrowser());
}
- (IBAction)testJSInvoke:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunJavaScriptInvokeTest(g_handler->GetBrowser());
}
- (IBAction)testRequest:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunRequestTest(g_handler->GetBrowser());
}
- (IBAction)testLocalStorage:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunLocalStorageTest(g_handler->GetBrowser());
}
- (IBAction)testXMLHttpRequest:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunXMLHTTPRequestTest(g_handler->GetBrowser());
}
- (IBAction)testWebURLRequest:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunWebURLRequestTest(g_handler->GetBrowser());
}
- (IBAction)testDOMAccess:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunDOMAccessTest(g_handler->GetBrowser());
}
- (IBAction)testSchemeHandler:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunSchemeTest(g_handler->GetBrowser());
}
- (IBAction)testPopupWindow:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunPopupTest(g_handler->GetBrowser());
}
- (IBAction)testAccelerated2DCanvas:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunAccelerated2DCanvasTest(g_handler->GetBrowser());
}
- (IBAction)testAcceleratedLayers:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunAcceleratedLayersTest(g_handler->GetBrowser());
}
- (IBAction)testWebGL:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunWebGLTest(g_handler->GetBrowser());
}
- (IBAction)testHTML5Video:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunHTML5VideoTest(g_handler->GetBrowser());
}
- (IBAction)testDragDrop:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd())
if (g_handler.get() && g_handler->GetBrowserHwnd())
RunDragDropTest(g_handler->GetBrowser());
}
- (IBAction)testZoomIn:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
}
}
- (IBAction)testZoomOut:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
}
}
- (IBAction)testZoomReset:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->SetZoomLevel(0.0);
}
}
- (IBAction)testDevToolsShow:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->ShowDevTools();
}
}
- (IBAction)testDevToolsClose:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->CloseDevTools();
}
@@ -538,8 +538,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
@end
int main(int argc, char* argv[])
{
int main(int argc, char* argv[]) {
// Retrieve the current working directory.
getcwd(szWorkingDir, sizeof(szWorkingDir));
@@ -580,7 +579,6 @@ int main(int argc, char* argv[])
// Global functions
std::string AppGetWorkingDirectory()
{
std::string AppGetWorkingDirectory() {
return szWorkingDir;
}

View File

@@ -2,7 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient_switches.h"
// This file is shared by cefclient and cef_unittests so don't include using
// a qualified path.
#include "cefclient_switches.h" // NOLINT(build/include)
namespace cefclient {

View File

@@ -4,8 +4,9 @@
// Defines all of the command line switches used by cefclient.
#ifndef _CEFCLIENT_SWITCHES_H
#define _CEFCLIENT_SWITCHES_H
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_
#pragma once
namespace cefclient {
@@ -85,4 +86,4 @@ extern const char kProxyConfig[];
} // namespace cefclient
#endif // _CEFCLIENT_SWITCHES_H
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_

File diff suppressed because it is too large Load Diff

View File

@@ -2,16 +2,16 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "client_handler.h"
#include "cefclient/client_handler.h"
#include <stdio.h>
#include <sstream>
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "binding_test.h"
#include "cefclient.h"
#include "download_handler.h"
#include "string_util.h"
#include <sstream>
#include <stdio.h>
#include <string>
#include "cefclient/binding_test.h"
#include "cefclient/cefclient.h"
#include "cefclient/download_handler.h"
#include "cefclient/string_util.h"
ClientHandler::ClientHandler()
@@ -22,30 +22,25 @@ ClientHandler::ClientHandler()
m_ForwardHwnd(NULL),
m_StopHwnd(NULL),
m_ReloadHwnd(NULL),
m_bFormElementHasFocus(false)
{
m_bFormElementHasFocus(false) {
}
ClientHandler::~ClientHandler()
{
ClientHandler::~ClientHandler() {
}
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
AutoLock lock_scope(this);
if(!m_Browser.get())
{
if (!m_Browser.get()) {
// We need to keep the main child window, but not popup windows
m_Browser = browser;
m_BrowserHwnd = browser->GetWindowHandle();
}
}
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
{
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
if (m_BrowserHwnd == browser->GetWindowHandle()) {
@@ -53,7 +48,7 @@ bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
// the parent window instead of the browser window.
CloseMainWindow();
// Return true here so that we can skip closing the browser window
// Return true here so that we can skip closing the browser window
// in this pass. (It will be destroyed due to the call to close
// the parent above.)
return true;
@@ -64,22 +59,20 @@ bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
return false;
}
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle()) {
if (m_BrowserHwnd == browser->GetWindowHandle()) {
// Free the browser pointer so that the browser can be destroyed
m_Browser = NULL;
}
}
void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
CefRefPtr<CefFrame> frame) {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
// We've just started loading a page
SetLoading(true);
}
@@ -87,16 +80,15 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode)
{
int httpStatusCode) {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
// We've just finished loading a page
SetLoading(false);
CefRefPtr<CefDOMVisitor> visitor = GetDOMVisitor(frame->GetURL());
if(visitor.get())
if (visitor.get())
frame->VisitDOM(visitor);
}
}
@@ -105,11 +97,10 @@ bool ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& failedUrl,
CefString& errorText)
{
CefString& errorText) {
REQUIRE_UI_THREAD();
if(errorCode == ERR_CACHE_MISS) {
if (errorCode == ERR_CACHE_MISS) {
// Usually caused by navigating to a page with POST data via back or
// forward buttons.
errorText = "<html><head><title>Expired Form Data</title></head>"
@@ -136,8 +127,7 @@ bool ClientHandler::GetDownloadHandler(CefRefPtr<CefBrowser> browser,
const CefString& mimeType,
const CefString& fileName,
int64 contentLength,
CefRefPtr<CefDownloadHandler>& handler)
{
CefRefPtr<CefDownloadHandler>& handler) {
REQUIRE_UI_THREAD();
// Create the handler for the file download.
@@ -152,8 +142,7 @@ bool ClientHandler::GetDownloadHandler(CefRefPtr<CefBrowser> browser,
void ClientHandler::OnNavStateChange(CefRefPtr<CefBrowser> browser,
bool canGoBack,
bool canGoForward)
{
bool canGoForward) {
REQUIRE_UI_THREAD();
SetNavState(canGoBack, canGoForward);
@@ -162,8 +151,7 @@ void ClientHandler::OnNavStateChange(CefRefPtr<CefBrowser> browser,
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message,
const CefString& source,
int line)
{
int line) {
REQUIRE_UI_THREAD();
bool first_message;
@@ -171,9 +159,9 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
{
AutoLock lock_scope(this);
first_message = m_LogFile.empty();
if(first_message) {
if (first_message) {
std::stringstream ss;
ss << AppGetWorkingDirectory();
#if defined(OS_WIN)
@@ -185,10 +173,10 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
m_LogFile = ss.str();
}
logFile = m_LogFile;
}
}
FILE* file = fopen(logFile.c_str(), "a");
if(file) {
if (file) {
std::stringstream ss;
ss << "Message: " << std::string(message) << "\r\nSource: " <<
std::string(source) << "\r\nLine: " << line <<
@@ -196,7 +184,7 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
fputs(ss.str().c_str(), file);
fclose(file);
if(first_message)
if (first_message)
SendNotification(NOTIFY_CONSOLE_MESSAGE);
}
@@ -205,8 +193,7 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
void ClientHandler::OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefDOMNode> node)
{
CefRefPtr<CefDOMNode> node) {
REQUIRE_UI_THREAD();
// Set to true if a form element has focus.
@@ -218,8 +205,7 @@ bool ClientHandler::OnKeyEvent(CefRefPtr<CefBrowser> browser,
int code,
int modifiers,
bool isSystemKey,
bool isAfterJavaScript)
{
bool isAfterJavaScript) {
REQUIRE_UI_THREAD();
if (isAfterJavaScript && !m_bFormElementHasFocus && code == 0x20) {
@@ -247,15 +233,14 @@ bool ClientHandler::GetPrintHeaderFooter(CefRefPtr<CefBrowser> browser,
CefString& topRight,
CefString& bottomLeft,
CefString& bottomCenter,
CefString& bottomRight)
{
CefString& bottomRight) {
REQUIRE_UI_THREAD();
// Place the page title at top left
topLeft = title;
// Place the page URL at top right
topRight = url;
// Place "Page X of Y" at bottom center
std::stringstream strstream;
strstream << "Page " << currentPage << " of " << maxPages;
@@ -266,8 +251,7 @@ bool ClientHandler::GetPrintHeaderFooter(CefRefPtr<CefBrowser> browser,
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context)
{
CefRefPtr<CefV8Context> context) {
REQUIRE_UI_THREAD();
// Add the V8 bindings.
@@ -276,8 +260,7 @@ void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
bool ClientHandler::OnDragStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
DragOperationsMask mask)
{
DragOperationsMask mask) {
REQUIRE_UI_THREAD();
// Forbid dragging of image files.
@@ -292,8 +275,7 @@ bool ClientHandler::OnDragStart(CefRefPtr<CefBrowser> browser,
bool ClientHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
DragOperationsMask mask)
{
DragOperationsMask mask) {
REQUIRE_UI_THREAD();
// Forbid dragging of link URLs.
@@ -303,33 +285,29 @@ bool ClientHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
return false;
}
bool ClientHandler::OnBeforeScriptExtensionLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& extensionName)
{
bool ClientHandler::OnBeforeScriptExtensionLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& extensionName) {
return false;
}
void ClientHandler::NotifyDownloadComplete(const CefString& fileName)
{
void ClientHandler::NotifyDownloadComplete(const CefString& fileName) {
SetLastDownloadFile(fileName);
SendNotification(NOTIFY_DOWNLOAD_COMPLETE);
}
void ClientHandler::NotifyDownloadError(const CefString& fileName)
{
void ClientHandler::NotifyDownloadError(const CefString& fileName) {
SetLastDownloadFile(fileName);
SendNotification(NOTIFY_DOWNLOAD_ERROR);
}
void ClientHandler::SetMainHwnd(CefWindowHandle hwnd)
{
void ClientHandler::SetMainHwnd(CefWindowHandle hwnd) {
AutoLock lock_scope(this);
m_MainHwnd = hwnd;
}
void ClientHandler::SetEditHwnd(CefWindowHandle hwnd)
{
void ClientHandler::SetEditHwnd(CefWindowHandle hwnd) {
AutoLock lock_scope(this);
m_EditHwnd = hwnd;
}
@@ -337,8 +315,7 @@ void ClientHandler::SetEditHwnd(CefWindowHandle hwnd)
void ClientHandler::SetButtonHwnds(CefWindowHandle backHwnd,
CefWindowHandle forwardHwnd,
CefWindowHandle reloadHwnd,
CefWindowHandle stopHwnd)
{
CefWindowHandle stopHwnd) {
AutoLock lock_scope(this);
m_BackHwnd = backHwnd;
m_ForwardHwnd = forwardHwnd;
@@ -346,27 +323,23 @@ void ClientHandler::SetButtonHwnds(CefWindowHandle backHwnd,
m_StopHwnd = stopHwnd;
}
std::string ClientHandler::GetLogFile()
{
std::string ClientHandler::GetLogFile() {
AutoLock lock_scope(this);
return m_LogFile;
}
void ClientHandler::SetLastDownloadFile(const std::string& fileName)
{
void ClientHandler::SetLastDownloadFile(const std::string& fileName) {
AutoLock lock_scope(this);
m_LastDownloadFile = fileName;
}
std::string ClientHandler::GetLastDownloadFile()
{
std::string ClientHandler::GetLastDownloadFile() {
AutoLock lock_scope(this);
return m_LastDownloadFile;
}
void ClientHandler::AddDOMVisitor(const std::string& path,
CefRefPtr<CefDOMVisitor> visitor)
{
CefRefPtr<CefDOMVisitor> visitor) {
AutoLock lock_scope(this);
DOMVisitorMap::iterator it = m_DOMVisitors.find(path);
if (it == m_DOMVisitors.end())
@@ -375,8 +348,7 @@ void ClientHandler::AddDOMVisitor(const std::string& path,
it->second = visitor;
}
CefRefPtr<CefDOMVisitor> ClientHandler::GetDOMVisitor(const std::string& path)
{
CefRefPtr<CefDOMVisitor> ClientHandler::GetDOMVisitor(const std::string& path) {
AutoLock lock_scope(this);
DOMVisitorMap::iterator it = m_DOMVisitors.find(path);
if (it != m_DOMVisitors.end())

View File

@@ -2,17 +2,20 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CLIENT_HANDLER_H
#define _CLIENT_HANDLER_H
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
#define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
#pragma once
#include <map>
#include <string>
#include "include/cef_client.h"
#include "download_handler.h"
#include "util.h"
#include "cefclient/download_handler.h"
#include "cefclient/util.h"
// Define this value to redirect all popup URLs to the main application browser
// window.
//#define TEST_REDIRECT_POPUP_URLS
// #define TEST_REDIRECT_POPUP_URLS
// ClientHandler implementation.
@@ -27,33 +30,42 @@ class ClientHandler : public CefClient,
public CefV8ContextHandler,
public CefDragHandler,
public CefPermissionHandler,
public DownloadListener
{
public:
public DownloadListener {
public:
ClientHandler();
virtual ~ClientHandler();
// CefClient methods
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE {
return this;
}
// CefLifeSpanHandler methods
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
@@ -77,7 +89,7 @@ public:
ErrorCode errorCode,
const CefString& failedUrl,
CefString& errorText) OVERRIDE;
// CefRequestHandler methods
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefRequest> request,
@@ -105,7 +117,7 @@ public:
const CefString& message,
const CefString& source,
int line) OVERRIDE;
// CefFocusHandler methods.
virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
@@ -133,7 +145,7 @@ public:
CefString& bottomLeft,
CefString& bottomCenter,
CefString& bottomRight) OVERRIDE;
// CefV8ContextHandler methods
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
@@ -163,7 +175,7 @@ public:
CefWindowHandle forwardHwnd,
CefWindowHandle reloadHwnd,
CefWindowHandle stopHwnd);
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
CefWindowHandle GetBrowserHwnd() { return m_BrowserHwnd; }
@@ -178,8 +190,7 @@ public:
// Send a notification to the application. Notifications should not block the
// caller.
enum NotificationType
{
enum NotificationType {
NOTIFY_CONSOLE_MESSAGE,
NOTIFY_DOWNLOAD_COMPLETE,
NOTIFY_DOWNLOAD_ERROR,
@@ -187,7 +198,7 @@ public:
void SendNotification(NotificationType type);
void CloseMainWindow();
protected:
protected:
void SetLoading(bool isLoading);
void SetNavState(bool canGoBack, bool canGoForward);
@@ -228,4 +239,4 @@ protected:
IMPLEMENT_LOCKING(ClientHandler);
};
#endif // _CLIENT_HANDLER_H
#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_

View File

@@ -2,12 +2,13 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "client_handler.h"
#include <gtk/gtk.h>
#include <string>
#include "cefclient/client_handler.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "resource_util.h"
#include "string_util.h"
#include <gtk/gtk.h>
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
// ClientHandler::ClientLifeSpanHandler implementation
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
@@ -15,8 +16,7 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo,
const CefString& url,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings)
{
CefBrowserSettings& settings) {
REQUIRE_UI_THREAD();
return false;
@@ -27,18 +27,18 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefString& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
CefRefPtr<CefResponse> response,
int loadFlags)
{
int loadFlags) {
REQUIRE_IO_THREAD();
std::string url = request->GetURL();
if(url == "http://tests/request") {
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
resourceStream = CefStreamReader::CreateForData(
(void*)dump.c_str(), dump.size());
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
response->SetMimeType("text/plain");
response->SetStatus(200);
} else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) {
@@ -46,17 +46,17 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
resourceStream = GetBinaryResourceReader("logo.png");
response->SetMimeType("image/png");
response->SetStatus(200);
} else if(url == "http://tests/localstorage") {
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
resourceStream = GetBinaryResourceReader("localstorage.html");
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/xmlhttprequest") {
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest HTML contents
resourceStream = GetBinaryResourceReader("xmlhttprequest.html");
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/domaccess") {
} else if (url == "http://tests/domaccess") {
// Show the domaccess HTML contents
resourceStream = GetBinaryResourceReader("domaccess.html");
response->SetMimeType("text/html");
@@ -64,15 +64,14 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
}
return false;
}
}
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url)
{
const CefString& url) {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
// Set the edit window text
std::string urlStr(url);
gtk_entry_set_text(GTK_ENTRY(m_EditHwnd), urlStr.c_str());
@@ -80,8 +79,7 @@ void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title)
{
const CefString& title) {
REQUIRE_UI_THREAD();
GtkWidget* window =
@@ -91,33 +89,29 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
gtk_window_set_title(GTK_WINDOW(window), titleStr.c_str());
}
void ClientHandler::SendNotification(NotificationType type)
{
void ClientHandler::SendNotification(NotificationType type) {
// TODO(port): Implement this method.
}
void ClientHandler::SetLoading(bool isLoading)
{
if(isLoading)
void ClientHandler::SetLoading(bool isLoading) {
if (isLoading)
gtk_widget_set_sensitive(GTK_WIDGET(m_StopHwnd), true);
else
gtk_widget_set_sensitive(GTK_WIDGET(m_StopHwnd), false);
}
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward)
{
if(canGoBack)
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
if (canGoBack)
gtk_widget_set_sensitive(GTK_WIDGET(m_BackHwnd), true);
else
gtk_widget_set_sensitive(GTK_WIDGET(m_BackHwnd), false);
if(canGoForward)
if (canGoForward)
gtk_widget_set_sensitive(GTK_WIDGET(m_ForwardHwnd), true);
else
gtk_widget_set_sensitive(GTK_WIDGET(m_ForwardHwnd), false);
}
void ClientHandler::CloseMainWindow()
{
void ClientHandler::CloseMainWindow() {
// TODO(port): Close main window.
}

View File

@@ -2,16 +2,17 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "client_handler.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "cefclient.h"
#include "resource_util.h"
#include "string_util.h"
#import <Cocoa/Cocoa.h>
#include "cefclient/client_handler.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "cefclient/cefclient.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
#ifdef TEST_REDIRECT_POPUP_URLS
#include "client_popup_handler.h"
#include "cefclient/client_popup_handler.h"
#endif
// ClientHandler::ClientLifeSpanHandler implementation
@@ -21,13 +22,12 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo,
const CefString& url,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings)
{
CefBrowserSettings& settings) {
REQUIRE_UI_THREAD();
#ifdef TEST_REDIRECT_POPUP_URLS
std::string urlStr = url;
if(urlStr.find("chrome-devtools:") == std::string::npos) {
if (urlStr.find("chrome-devtools:") == std::string::npos) {
// Show all popup windows excluding DevTools in the current window.
windowInfo.m_bHidden = true;
client = new ClientPopupHandler(m_Browser);
@@ -42,17 +42,17 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefString& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
CefRefPtr<CefResponse> response,
int loadFlags)
{
int loadFlags) {
REQUIRE_IO_THREAD();
std::string url = request->GetURL();
if(url == "http://tests/request") {
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
resourceStream = CefStreamReader::CreateForData(
(void*)dump.c_str(), dump.size());
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
response->SetMimeType("text/plain");
response->SetStatus(200);
} else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) {
@@ -60,17 +60,17 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
resourceStream = GetBinaryResourceReader("logo.png");
response->SetMimeType("image/png");
response->SetStatus(200);
} else if(url == "http://tests/localstorage") {
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
resourceStream = GetBinaryResourceReader("localstorage.html");
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/xmlhttprequest") {
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest HTML contents
resourceStream = GetBinaryResourceReader("xmlhttprequest.html");
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/domaccess") {
} else if (url == "http://tests/domaccess") {
// Show the domaccess HTML contents
resourceStream = GetBinaryResourceReader("domaccess.html");
response->SetMimeType("text/html");
@@ -82,12 +82,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url)
{
const CefString& url) {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
{
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
// Set the edit window text
NSTextField* textField = (NSTextField*)m_EditHwnd;
std::string urlStr(url);
@@ -97,8 +95,7 @@ void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title)
{
const CefString& title) {
REQUIRE_UI_THREAD();
// Set the frame window title bar
@@ -109,8 +106,7 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
[window setTitle:str];
}
void ClientHandler::SendNotification(NotificationType type)
{
void ClientHandler::SendNotification(NotificationType type) {
SEL sel = nil;
switch(type) {
case NOTIFY_CONSOLE_MESSAGE:
@@ -124,7 +120,7 @@ void ClientHandler::SendNotification(NotificationType type)
break;
}
if(sel == nil)
if (sel == nil)
return;
NSWindow* window = [AppGetMainHwnd() window];
@@ -132,17 +128,14 @@ void ClientHandler::SendNotification(NotificationType type)
[delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO];
}
void ClientHandler::SetLoading(bool isLoading)
{
void ClientHandler::SetLoading(bool isLoading) {
// TODO(port): Change button status.
}
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward)
{
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
// TODO(port): Change button status.
}
void ClientHandler::CloseMainWindow()
{
void ClientHandler::CloseMainWindow() {
// TODO(port): Close window
}

View File

@@ -2,15 +2,16 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "client_handler.h"
#include "cefclient/client_handler.h"
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "resource.h"
#include "resource_util.h"
#include "string_util.h"
#include "cefclient/resource.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
#ifdef TEST_REDIRECT_POPUP_URLS
#include "client_popup_handler.h"
#include "cefclient/client_popup_handler.h"
#endif
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
@@ -18,18 +19,17 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo,
const CefString& url,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings)
{
CefBrowserSettings& settings) {
REQUIRE_UI_THREAD();
#ifdef TEST_REDIRECT_POPUP_URLS
std::string urlStr = url;
if(urlStr.find("chrome-devtools:") == std::string::npos) {
if (urlStr.find("chrome-devtools:") == std::string::npos) {
// Show all popup windows excluding DevTools in the current window.
windowInfo.m_dwStyle &= ~WS_VISIBLE;
client = new ClientPopupHandler(m_Browser);
}
#endif // TEST_REDIRECT_POPUP_URLS
#endif // TEST_REDIRECT_POPUP_URLS
return false;
}
@@ -39,67 +39,67 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefString& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
CefRefPtr<CefResponse> response,
int loadFlags)
{
int loadFlags) {
REQUIRE_IO_THREAD();
std::string url = request->GetURL();
if(url == "http://tests/request") {
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
resourceStream =
CefStreamReader::CreateForData((void*)dump.c_str(), dump.size());
resourceStream = CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
response->SetMimeType("text/plain");
response->SetStatus(200);
} else if(strstr(url.c_str(), "/ps_logo2.png") != NULL) {
} else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) {
// Any time we find "ps_logo2.png" in the URL substitute in our own image
resourceStream = GetBinaryResourceReader(IDS_LOGO);
response->SetMimeType("image/png");
response->SetStatus(200);
} else if(url == "http://tests/uiapp") {
} else if (url == "http://tests/uiapp") {
// Show the uiapp contents
resourceStream = GetBinaryResourceReader(IDS_UIPLUGIN);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/osrapp") {
} else if (url == "http://tests/osrapp") {
// Show the osrapp contents
resourceStream = GetBinaryResourceReader(IDS_OSRPLUGIN);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/localstorage") {
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
resourceStream = GetBinaryResourceReader(IDS_LOCALSTORAGE);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/xmlhttprequest") {
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest HTML contents
resourceStream = GetBinaryResourceReader(IDS_XMLHTTPREQUEST);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/domaccess") {
} else if (url == "http://tests/domaccess") {
// Show the domaccess HTML contents
resourceStream = GetBinaryResourceReader(IDS_DOMACCESS);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(strstr(url.c_str(), "/logoball.png") != NULL) {
} else if (strstr(url.c_str(), "/logoball.png") != NULL) {
// Load the "logoball.png" image resource.
resourceStream = GetBinaryResourceReader(IDS_LOGOBALL);
response->SetMimeType("image/png");
response->SetStatus(200);
} else if(url == "http://tests/modalmain") {
} else if (url == "http://tests/modalmain") {
resourceStream = GetBinaryResourceReader(IDS_MODALMAIN);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/modaldialog") {
} else if (url == "http://tests/modaldialog") {
resourceStream = GetBinaryResourceReader(IDS_MODALDIALOG);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/transparency") {
} else if (url == "http://tests/transparency") {
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
response->SetMimeType("text/html");
response->SetStatus(200);
} else if(url == "http://tests/plugin") {
} else if (url == "http://tests/plugin") {
std::string html =
"<html><body>\n"
"Client Plugin loaded by Mime Type:<br>\n"
@@ -109,9 +109,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
// Add some extra space below the plugin to allow scrolling.
"<div style=\"height:1000px;\">&nbsp;</div>\n"
"</body></html>";
resourceStream =
CefStreamReader::CreateForData((void*)html.c_str(), html.size());
resourceStream = CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(html.c_str())),
html.size());
response->SetMimeType("text/html");
response->SetStatus(200);
}
@@ -121,37 +122,31 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url)
{
const CefString& url) {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
{
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
// Set the edit window text
SetWindowText(m_EditHwnd, std::wstring(url).c_str());
}
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title)
{
const CefString& title) {
REQUIRE_UI_THREAD();
// Set the frame window title bar
CefWindowHandle hwnd = browser->GetWindowHandle();
if(m_BrowserHwnd == hwnd)
{
if (m_BrowserHwnd == hwnd) {
// The frame window will be the parent of the browser window
hwnd = GetParent(hwnd);
}
SetWindowText(hwnd, std::wstring(title).c_str());
}
void ClientHandler::SendNotification(NotificationType type)
{
void ClientHandler::SendNotification(NotificationType type) {
UINT id;
switch(type)
{
switch (type) {
case NOTIFY_CONSOLE_MESSAGE:
id = ID_WARN_CONSOLEMESSAGE;
break;
@@ -167,22 +162,19 @@ void ClientHandler::SendNotification(NotificationType type)
PostMessage(m_MainHwnd, WM_COMMAND, id, 0);
}
void ClientHandler::SetLoading(bool isLoading)
{
void ClientHandler::SetLoading(bool isLoading) {
ASSERT(m_EditHwnd != NULL && m_ReloadHwnd != NULL && m_StopHwnd != NULL);
EnableWindow(m_EditHwnd, TRUE);
EnableWindow(m_ReloadHwnd, !isLoading);
EnableWindow(m_StopHwnd, isLoading);
}
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward)
{
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
ASSERT(m_BackHwnd != NULL && m_ForwardHwnd != NULL);
EnableWindow(m_BackHwnd, canGoBack);
EnableWindow(m_ForwardHwnd, canGoForward);
}
void ClientHandler::CloseMainWindow()
{
void ClientHandler::CloseMainWindow() {
::PostMessage(m_MainHwnd, WM_CLOSE, 0, 0);
}

View File

@@ -2,29 +2,25 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "client_popup_handler.h"
#include "cefclient/client_popup_handler.h"
#include "include/cef_frame.h"
#include "util.h"
#include "cefclient/util.h"
ClientPopupHandler::ClientPopupHandler(CefRefPtr<CefBrowser> parentBrowser)
: m_ParentBrowser(parentBrowser)
{
: m_ParentBrowser(parentBrowser) {
ASSERT(m_ParentBrowser.get());
}
ClientPopupHandler::~ClientPopupHandler()
{
ClientPopupHandler::~ClientPopupHandler() {
}
bool ClientPopupHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType,
bool isRedirect)
{
bool isRedirect) {
REQUIRE_UI_THREAD();
// Load the request in the parent browser window.
m_ParentBrowser->GetMainFrame()->LoadRequest(request);
browser->CloseBrowser();

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CLIENT_POPUP_HANDLER_H
#define _CLIENT_POPUP_HANDLER_H
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_POPUP_HANDLER_H_
#define CEF_TESTS_CEFCLIENT_CLIENT_POPUP_HANDLER_H_
#pragma once
#include "include/cef_browser.h"
#include "include/cef_client.h"
@@ -12,15 +13,15 @@
// Handler for popup windows that loads the request in an existing browser
// window.
class ClientPopupHandler : public CefClient,
public CefRequestHandler
{
public:
ClientPopupHandler(CefRefPtr<CefBrowser> parentBrowser);
public CefRequestHandler {
public:
explicit ClientPopupHandler(CefRefPtr<CefBrowser> parentBrowser);
virtual ~ClientPopupHandler();
// CefClient methods
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
return this;
}
// CefRequestHandler methods
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
@@ -28,11 +29,11 @@ public:
CefRefPtr<CefRequest> request,
NavType navType,
bool isRedirect) OVERRIDE;
protected:
protected:
CefRefPtr<CefBrowser> m_ParentBrowser;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientPopupHandler);
};
#endif // _CLIENT_POPUP_HANDLER_H
#endif // CEF_TESTS_CEFCLIENT_CLIENT_POPUP_HANDLER_H_

View File

@@ -3,7 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "clientplugin.h"
#include "cefclient/clientplugin.h"
#if defined(OS_WIN)
@@ -56,24 +56,21 @@ NPError NPP_ClientSetWindow(NPP instance, NPWindow* window_info) {
return NPERR_NO_ERROR;
}
} // anonymous
} // namespace
NPError API_CALL NP_ClientGetEntryPoints(NPPluginFuncs* pFuncs)
{
NPError API_CALL NP_ClientGetEntryPoints(NPPluginFuncs* pFuncs) {
pFuncs->newp = NPP_ClientNew;
pFuncs->destroy = NPP_ClientDestroy;
pFuncs->setwindow = NPP_ClientSetWindow;
return NPERR_NO_ERROR;
}
NPError API_CALL NP_ClientInitialize(NPNetscapeFuncs* pFuncs)
{
NPError API_CALL NP_ClientInitialize(NPNetscapeFuncs* pFuncs) {
g_browser = pFuncs;
return NPERR_NO_ERROR;
}
NPError API_CALL NP_ClientShutdown(void)
{
NPError API_CALL NP_ClientShutdown(void) {
g_browser = NULL;
return NPERR_NO_ERROR;
}
@@ -82,24 +79,20 @@ NPError API_CALL NP_ClientShutdown(void)
// ClientPlugin Implementation
ClientPlugin::ClientPlugin(int16 mode)
: mode_(mode)
{
: mode_(mode) {
}
ClientPlugin::~ClientPlugin()
{
ClientPlugin::~ClientPlugin() {
}
bool ClientPlugin::Initialize(HINSTANCE module_handle, NPP instance,
NPMIMEType mime_type, int16 argc, char* argn[],
char* argv[])
{
char* argv[]) {
RefreshDisplay();
return true;
}
bool ClientPlugin::SetWindow(HWND parent_window)
{
bool ClientPlugin::SetWindow(HWND parent_window) {
if (!::IsWindow(parent_window)) {
// No window created yet. Ignore this call.
if (!IsWindow())
@@ -119,23 +112,21 @@ bool ClientPlugin::SetWindow(HWND parent_window)
// First time in -- no window created by plugin yet.
::GetClientRect(parent_window, &parent_rect);
Create(parent_window, parent_rect, NULL, WS_CHILD | WS_BORDER);
UpdateWindow();
ShowWindow(SW_SHOW);
return true;
}
void ClientPlugin::Shutdown()
{
void ClientPlugin::Shutdown() {
if (IsWindow()) {
DestroyWindow();
}
}
LRESULT ClientPlugin::OnPaint(UINT message, WPARAM wparam, LPARAM lparam,
BOOL& handled)
{
BOOL& handled) {
PAINTSTRUCT paint_struct;
BeginPaint(&paint_struct);
Paint(paint_struct.hdc);
@@ -145,15 +136,13 @@ LRESULT ClientPlugin::OnPaint(UINT message, WPARAM wparam, LPARAM lparam,
// PrintClient is necessary to support off-screen rendering.
LRESULT ClientPlugin::OnPrintClient(UINT message, WPARAM wparam, LPARAM lparam,
BOOL& handled)
{
BOOL& handled) {
Paint(reinterpret_cast<HDC>(wparam));
return 0;
}
LRESULT ClientPlugin::OnEraseBackGround(UINT message, WPARAM wparam,
LPARAM lparam, BOOL& handled)
{
LPARAM lparam, BOOL& handled) {
HDC paint_device_context = reinterpret_cast<HDC>(wparam);
RECT erase_rect;
GetClipBox(paint_device_context, &erase_rect);
@@ -164,8 +153,7 @@ LRESULT ClientPlugin::OnEraseBackGround(UINT message, WPARAM wparam,
}
LRESULT ClientPlugin::OnLButtonDown(UINT message, WPARAM wparam, LPARAM lparam,
BOOL& handled)
{
BOOL& handled) {
MessageBox(L"You clicked on the client plugin!", L"Client Plugin", MB_OK);
return 0;
}
@@ -198,4 +186,4 @@ void ClientPlugin::Paint(HDC hdc) {
SetTextColor(hdc, old_color);
}
#endif // OS_WIN
#endif // OS_WIN

View File

@@ -6,15 +6,17 @@
// Portions of this implementation are borrowed from webkit\default_plugin\
// plugin_impl.h
#ifndef _CEFCLIENT_CLIENTPLUGIN_H
#define _CEFCLIENT_CLIENTPLUGIN_H
#ifndef CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
#define CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
#pragma once
#include "include/cef_nplugin.h"
#include "include/internal/cef_types.h"
#if defined(OS_WIN)
#include <atlbase.h>
#include <atlwin.h>
#include <atlbase.h> // NOLINT(build/include_order)
#include <atlwin.h> // NOLINT(build/include_order)
#include "include/cef_nplugin.h"
extern NPNetscapeFuncs* g_browser;
@@ -82,7 +84,7 @@ class ClientPlugin : public CWindowImpl<ClientPlugin> {
BOOL& handled);
LRESULT OnLButtonDown(UINT message, WPARAM wparam, LPARAM lparam,
BOOL& handled);
// Enables the plugin window if required and initiates an update of the
// the plugin window.
void RefreshDisplay();
@@ -96,6 +98,6 @@ class ClientPlugin : public CWindowImpl<ClientPlugin> {
int16 mode_;
};
#endif // OS_WIN
#endif // OS_WIN
#endif // _CEFCLIENT_CLIENTPLUGIN_H
#endif // CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_

View File

@@ -2,48 +2,45 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "download_handler.h"
#include "cefclient/download_handler.h"
#include <stdio.h>
#include <sstream>
#include <vector>
#include "include/cef_download_handler.h"
#include "include/cef_runnable.h"
#include "util.h"
#include <sstream>
#include <stdio.h>
#include <vector>
#include "cefclient/util.h"
#if defined(OS_WIN)
#include <windows.h>
#include <shlobj.h>
#include <shlwapi.h>
#endif // OS_WIN
#include <windows.h> // NOLINT(build/include_order)
#include <shlobj.h> // NOLINT(build/include_order)
#include <shlwapi.h> // NOLINT(build/include_order)
#endif // OS_WIN
// Implementation of the CefDownloadHandler interface.
class ClientDownloadHandler : public CefDownloadHandler
{
public:
class ClientDownloadHandler : public CefDownloadHandler {
public:
ClientDownloadHandler(CefRefPtr<DownloadListener> listener,
const CefString& fileName)
: listener_(listener), filename_(fileName), file_(NULL)
{
: listener_(listener), filename_(fileName), file_(NULL) {
}
~ClientDownloadHandler()
{
~ClientDownloadHandler() {
ASSERT(pending_data_.empty());
ASSERT(file_ == NULL);
if(!pending_data_.empty()) {
if (!pending_data_.empty()) {
// Delete remaining pending data.
std::vector<std::vector<char>*>::iterator it = pending_data_.begin();
for(; it != pending_data_.end(); ++it)
for (; it != pending_data_.end(); ++it)
delete (*it);
}
if(file_) {
if (file_) {
// Close the dangling file pointer on the FILE thread.
CefPostTask(TID_FILE,
NewCefRunnableFunction(&ClientDownloadHandler::CloseDanglingFile,
file_));
// Notify the listener that the download failed.
listener_->NotifyDownloadError(filename_);
}
@@ -53,8 +50,7 @@ public:
// The following methods are called on the UI thread.
// --------------------------------------------------
void Initialize()
{
void Initialize() {
// Open the file on the FILE thread.
CefPostTask(TID_FILE,
NewCefRunnableMethod(this, &ClientDownloadHandler::OnOpen));
@@ -63,11 +59,10 @@ public:
// A portion of the file contents have been received. This method will be
// called multiple times until the download is complete. Return |true| to
// continue receiving data and |false| to cancel.
virtual bool ReceivedData(void* data, int data_size)
{
virtual bool ReceivedData(void* data, int data_size) {
REQUIRE_UI_THREAD();
if(data_size == 0)
if (data_size == 0)
return true;
// Create a new vector for the data.
@@ -87,8 +82,7 @@ public:
}
// The download is complete.
virtual void Complete()
{
virtual void Complete() {
REQUIRE_UI_THREAD();
// Flush and close the file on the FILE thread.
@@ -100,41 +94,40 @@ public:
// The following methods are called on the FILE thread.
// ----------------------------------------------------
void OnOpen()
{
void OnOpen() {
REQUIRE_FILE_THREAD();
if(file_)
if (file_)
return;
#if defined(OS_WIN)
TCHAR szFolderPath[MAX_PATH];
// Save the file in the user's "My Documents" folder.
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
NULL, 0, szFolderPath))) {
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
NULL, 0, szFolderPath))) {
std::wstring fileNameStr = filename_;
LPWSTR name = PathFindFileName(fileNameStr.c_str());
LPWSTR ext = PathFindExtension(fileNameStr.c_str());
int ct = 0;
std::wstringstream ss;
if(ext) {
if (ext) {
name[ext-name] = 0;
ext++;
}
// Make sure the file name is unique.
do {
if(ct > 0)
if (ct > 0)
ss.str(L"");
ss << szFolderPath << L"\\" << name;
if(ct > 0)
if (ct > 0)
ss << L" (" << ct << L")";
if(ext)
if (ext)
ss << L"." << ext;
ct++;
} while(PathFileExists(ss.str().c_str()));
} while (PathFileExists(ss.str().c_str()));
{
AutoLock lock_scope(this);
@@ -146,15 +139,14 @@ public:
}
#else
// TODO(port): Implement this.
ASSERT(false); // Not implemented
ASSERT(false); // Not implemented
#endif
}
void OnComplete()
{
void OnComplete() {
REQUIRE_FILE_THREAD();
if(!file_)
if (!file_)
return;
// Make sure any pending data is written.
@@ -167,8 +159,7 @@ public:
listener_->NotifyDownloadComplete(filename_);
}
void OnReceivedData()
{
void OnReceivedData() {
REQUIRE_FILE_THREAD();
std::vector<std::vector<char>*> data;
@@ -176,32 +167,31 @@ public:
// Remove all data from the pending data queue.
{
AutoLock lock_scope(this);
if(!pending_data_.empty()) {
if (!pending_data_.empty()) {
data = pending_data_;
pending_data_.clear();
}
}
if(data.empty())
if (data.empty())
return;
// Write all pending data to file.
std::vector<std::vector<char>*>::iterator it = data.begin();
for(; it != data.end(); ++it) {
for (; it != data.end(); ++it) {
std::vector<char>* buffer = *it;
if(file_)
if (file_)
fwrite(&(*buffer)[0], buffer->size(), 1, file_);
delete buffer;
}
data.clear();
}
static void CloseDanglingFile(FILE *file)
{
static void CloseDanglingFile(FILE *file) {
fclose(file);
}
private:
private:
CefRefPtr<DownloadListener> listener_;
CefString filename_;
FILE* file_;
@@ -212,8 +202,7 @@ private:
};
CefRefPtr<CefDownloadHandler> CreateDownloadHandler(
CefRefPtr<DownloadListener> listener, const CefString& fileName)
{
CefRefPtr<DownloadListener> listener, const CefString& fileName) {
CefRefPtr<ClientDownloadHandler> handler =
new ClientDownloadHandler(listener, fileName);
handler->Initialize();

View File

@@ -2,17 +2,17 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_DOWNLOAD_HANDLER_H
#define _CEFCLIENT_DOWNLOAD_HANDLER_H
#ifndef CEF_TESTS_CEFCLIENT_DOWNLOAD_HANDLER_H_
#define CEF_TESTS_CEFCLIENT_DOWNLOAD_HANDLER_H_
#pragma once
#include "include/cef_base.h"
class CefDownloadHandler;
// Implement this interface to receive download notifications.
class DownloadListener : public virtual CefBase
{
public:
class DownloadListener : public virtual CefBase {
public:
// Called when the download is complete.
virtual void NotifyDownloadComplete(const CefString& fileName) =0;
@@ -24,4 +24,4 @@ public:
CefRefPtr<CefDownloadHandler> CreateDownloadHandler(
CefRefPtr<DownloadListener> listener, const CefString& fileName);
#endif // _CEFCLIENT_DOWNLOAD_HANDLER_H
#endif // CEF_TESTS_CEFCLIENT_DOWNLOAD_HANDLER_H_

View File

@@ -2,17 +2,17 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "extension_test.h"
#include "cefclient/extension_test.h"
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_stream.h"
#include "include/cef_v8.h"
#include "resource_util.h"
#include "cefclient/resource_util.h"
// Implementation of the V8 handler class for the "cef.test" extension.
class ClientV8ExtensionHandler : public CefV8Handler
{
public:
class ClientV8ExtensionHandler : public CefV8Handler {
public:
ClientV8ExtensionHandler() : test_param_("An initial string value.") {}
virtual ~ClientV8ExtensionHandler() {}
@@ -22,32 +22,24 @@ public:
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception)
{
if(name == "Dummy")
{
CefString& exception) {
if (name == "Dummy") {
// Used for performance testing.
return true;
}
else if(name == "SetTestParam")
{
} else if (name == "SetTestParam") {
// Handle the SetTestParam native function by saving the string argument
// into the local member.
if(arguments.size() != 1 || !arguments[0]->IsString())
if (arguments.size() != 1 || !arguments[0]->IsString())
return false;
test_param_ = arguments[0]->GetStringValue();
return true;
}
else if(name == "GetTestParam")
{
} else if (name == "GetTestParam") {
// Handle the GetTestParam native function by returning the local member
// value.
retval = CefV8Value::CreateString(test_param_);
return true;
}
else if(name == "GetTestObject")
{
} else if (name == "GetTestObject") {
// Handle the GetTestObject native function by creating and returning a
// new V8 object.
retval = CefV8Value::CreateObject(NULL, NULL);
@@ -60,9 +52,7 @@ public:
CefV8Value::CreateFunction("GetMessage", this),
V8_PROPERTY_ATTRIBUTE_NONE);
return true;
}
else if(name == "GetMessage")
{
} else if (name == "GetMessage") {
// Handle the GetMessage object function by returning a string.
retval = CefV8Value::CreateString(
"Calling a function on a native object succeeded.");
@@ -71,15 +61,14 @@ public:
return false;
}
private:
private:
CefString test_param_;
IMPLEMENT_REFCOUNTING(ClientV8ExtensionHandler);
};
void InitExtensionTest()
{
void InitExtensionTest() {
// Register a V8 extension with the below JavaScript code that calls native
// methods implemented in ClientV8ExtensionHandler.
std::string code = "var cef;"
@@ -94,7 +83,7 @@ void InitExtensionTest()
" });"
" cef.test.__defineSetter__('test_param', function(b) {"
" native function SetTestParam();"
" if(b) SetTestParam(b);"
" if (b) SetTestParam(b);"
" });"
" cef.test.test_object = function() {"
" native function GetTestObject();"
@@ -108,8 +97,7 @@ void InitExtensionTest()
CefRegisterExtension("v8/test", code, new ClientV8ExtensionHandler());
}
void RunExtensionTest(CefRefPtr<CefBrowser> browser)
{
void RunExtensionTest(CefRefPtr<CefBrowser> browser) {
std::string html =
"<html><body>ClientV8ExtensionHandler says:<br><pre>"
"<script language=\"JavaScript\">"
@@ -127,8 +115,7 @@ void RunExtensionTest(CefRefPtr<CefBrowser> browser)
browser->GetMainFrame()->LoadString(html, "about:blank");
}
void RunExtensionPerfTest(CefRefPtr<CefBrowser> browser)
{
void RunExtensionPerfTest(CefRefPtr<CefBrowser> browser) {
CefRefPtr<CefStreamReader> resourceStream;
#if defined(OS_WIN)
resourceStream = GetBinaryResourceReader(IDS_EXTENSIONPERF);

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_EXTENSION_TEST_H
#define _CEFCLIENT_EXTENSION_TEST_H
#ifndef CEF_TESTS_CEFCLIENT_EXTENSION_TEST_H_
#define CEF_TESTS_CEFCLIENT_EXTENSION_TEST_H_
#pragma once
#include "include/cef_base.h"
@@ -16,4 +17,4 @@ void InitExtensionTest();
void RunExtensionTest(CefRefPtr<CefBrowser> browser);
void RunExtensionPerfTest(CefRefPtr<CefBrowser> browser);
#endif // _CEFCLIENT_EXTENSION_TEST_H
#endif // CEF_TESTS_CEFCLIENT_EXTENSION_TEST_H_

View File

@@ -3,23 +3,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "osrplugin.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "cefclient.h"
#include "client_popup_handler.h"
#include "resource.h"
#include "resource_util.h"
#include "string_util.h"
#include "util.h"
#include <gl/gl.h>
#include <gl/glu.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <sstream>
#include "cefclient/osrplugin.h"
#if defined(OS_WIN)
#include <windows.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <sstream>
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "cefclient/cefclient.h"
#include "cefclient/client_popup_handler.h"
#include "cefclient/resource.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
#include "cefclient/util.h"
// Initialized in NP_Initialize.
NPNetscapeFuncs* g_osrbrowser = NULL;
@@ -38,11 +41,9 @@ bool g_offscreenTransparent = false;
#define GL_BYTE_COUNT (g_offscreenTransparent?4:3)
// Class holding pointers for the client plugin window.
class ClientPlugin
{
public:
ClientPlugin()
{
class ClientPlugin {
public:
ClientPlugin() {
hWnd = NULL;
hDC = NULL;
hRC = NULL;
@@ -59,19 +60,16 @@ class ClientOSRHandler : public CefClient,
public CefLoadHandler,
public CefRequestHandler,
public CefDisplayHandler,
public CefRenderHandler
{
public:
ClientOSRHandler(ClientPlugin* plugin)
public CefRenderHandler {
public:
explicit ClientOSRHandler(ClientPlugin* plugin)
: plugin_(plugin),
view_buffer_(NULL),
view_buffer_size_(0),
popup_buffer_(NULL),
popup_buffer_size_(0)
{
popup_buffer_size_(0) {
}
~ClientOSRHandler()
{
~ClientOSRHandler() {
if (view_buffer_)
delete [] view_buffer_;
if (popup_buffer_)
@@ -79,16 +77,21 @@ public:
}
// CefClient methods
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE {
return this;
}
// CefLifeSpanHandler methods
@@ -97,8 +100,7 @@ public:
CefWindowInfo& windowInfo,
const CefString& url,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) OVERRIDE
{
CefBrowserSettings& settings) OVERRIDE {
REQUIRE_UI_THREAD();
windowInfo.m_bWindowRenderingDisabled = TRUE;
@@ -106,8 +108,7 @@ public:
return false;
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
{
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
REQUIRE_UI_THREAD();
// Set the view size to match the plugin window size.
@@ -116,19 +117,17 @@ public:
g_offscreenBrowser = browser;
}
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE
{
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
g_offscreenBrowser = NULL;
}
// CefLoadHandler methods
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) OVERRIDE
{
CefRefPtr<CefFrame> frame) OVERRIDE {
REQUIRE_UI_THREAD();
if(!browser->IsPopup() && frame->IsMain()) {
if (!browser->IsPopup() && frame->IsMain()) {
// We've just started loading a page
SetLoading(true);
}
@@ -136,11 +135,10 @@ public:
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
int httpStatusCode) OVERRIDE {
REQUIRE_UI_THREAD();
if(!browser->IsPopup() && frame->IsMain()) {
if (!browser->IsPopup() && frame->IsMain()) {
// We've just finished loading a page
SetLoading(false);
}
@@ -153,12 +151,11 @@ public:
CefString& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
CefRefPtr<CefResponse> response,
int loadFlags) OVERRIDE
{
int loadFlags) OVERRIDE {
REQUIRE_IO_THREAD();
std::string url = request->GetURL();
if(url == "http://tests/transparency") {
if (url == "http://tests/transparency") {
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
response->SetMimeType("text/html");
response->SetStatus(200);
@@ -171,8 +168,7 @@ public:
virtual void OnNavStateChange(CefRefPtr<CefBrowser> browser,
bool canGoBack,
bool canGoForward) OVERRIDE
{
bool canGoForward) OVERRIDE {
REQUIRE_UI_THREAD();
// Set the "back" and "forward" button state in the HTML.
@@ -186,8 +182,7 @@ public:
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) OVERRIDE
{
const CefString& url) OVERRIDE {
REQUIRE_UI_THREAD();
// Set the "url" value in the HTML.
@@ -199,8 +194,7 @@ public:
}
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) OVERRIDE
{
const CefString& title) OVERRIDE {
REQUIRE_UI_THREAD();
// Set the "title" value in the HTML.
@@ -215,8 +209,7 @@ public:
// CefRenderHandler methods
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE
{
CefRect& rect) OVERRIDE {
REQUIRE_UI_THREAD();
// The simulated screen and view rectangle are the same. This is necessary
@@ -228,8 +221,7 @@ public:
}
virtual bool GetScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE
{
CefRect& rect) OVERRIDE {
return GetViewRect(browser, rect);
}
@@ -237,8 +229,7 @@ public:
int viewX,
int viewY,
int& screenX,
int& screenY) OVERRIDE
{
int& screenY) OVERRIDE {
REQUIRE_UI_THREAD();
// Convert the point from view coordinates to actual screen coordinates.
@@ -250,13 +241,12 @@ public:
}
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) OVERRIDE
{
bool show) OVERRIDE {
REQUIRE_UI_THREAD();
if(!show) {
if (!show) {
// Clear the popup buffer.
popup_rect_.Set(0,0,0,0);
popup_rect_.Set(0, 0, 0, 0);
if (popup_buffer_) {
delete [] popup_buffer_;
popup_buffer_ = NULL;
@@ -266,8 +256,7 @@ public:
}
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) OVERRIDE
{
const CefRect& rect) OVERRIDE {
REQUIRE_UI_THREAD();
if (rect.width > 0) {
@@ -282,8 +271,7 @@ public:
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer) OVERRIDE
{
const void* buffer) OVERRIDE {
REQUIRE_UI_THREAD();
wglMakeCurrent(plugin_->hDC, plugin_->hRC);
@@ -297,7 +285,7 @@ public:
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_textureID);
if (type == PET_VIEW) {
// Paint the view.
if (g_offscreenTransparent)
@@ -310,8 +298,8 @@ public:
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_width, g_height,
GL_IMAGE_FORMAT, GL_UNSIGNED_BYTE, view_buffer_);
}
if(popup_rect_.width > 0) {
if (popup_rect_.width > 0) {
if (type == PET_POPUP) {
// Paint the popup.
if (g_offscreenTransparent)
@@ -339,8 +327,7 @@ public:
}
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) OVERRIDE
{
CefCursorHandle cursor) OVERRIDE {
REQUIRE_UI_THREAD();
// Change the plugin window's cursor.
@@ -349,9 +336,8 @@ public:
SetCursor(cursor);
}
private:
void SetLoading(bool isLoading)
{
private:
void SetLoading(bool isLoading) {
// Set the "stop" and "reload" button state in the HTML.
std::stringstream ss;
ss << "document.getElementById('stop').disabled = "
@@ -362,10 +348,9 @@ private:
}
// Size the RGB buffer.
void SetBufferSize(int width, int height, bool view)
{
void SetBufferSize(int width, int height, bool view) {
int dst_size = width * height * GL_BYTE_COUNT;
// Allocate a new buffer if necesary.
if (view) {
if (dst_size > view_buffer_size_) {
@@ -385,8 +370,7 @@ private:
}
// Set the contents of the RGBA buffer.
void SetRGBA(const void* src, int width, int height, bool view)
{
void SetRGBA(const void* src, int width, int height, bool view) {
SetBufferSize(width, height, view);
ConvertToRGBA((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
height);
@@ -394,23 +378,21 @@ private:
// Convert from BGRA to RGBA format and from upper-left to lower-left origin.
static void ConvertToRGBA(const unsigned char* src, unsigned char* dst,
int width, int height)
{
int width, int height) {
int sp = 0, dp = (height-1) * width * 4;
for(int i = 0; i < height; i++) {
for(int j = 0; j < width; j++, dp += 4, sp += 4) {
dst[dp] = src[sp+2]; // R
dst[dp+1] = src[sp+1]; // G
dst[dp+2] = src[sp]; // B
dst[dp+3] = src[sp+3]; // A
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++, dp += 4, sp += 4) {
dst[dp] = src[sp+2]; // R
dst[dp+1] = src[sp+1]; // G
dst[dp+2] = src[sp]; // B
dst[dp+3] = src[sp+3]; // A
}
dp -= width * 8;
}
}
// Set the contents of the RGB buffer.
void SetRGB(const void* src, int width, int height, bool view)
{
void SetRGB(const void* src, int width, int height, bool view) {
SetBufferSize(width, height, view);
ConvertToRGB((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
height);
@@ -418,14 +400,13 @@ private:
// Convert from BGRA to RGB format and from upper-left to lower-left origin.
static void ConvertToRGB(const unsigned char* src, unsigned char* dst,
int width, int height)
{
int width, int height) {
int sp = 0, dp = (height-1) * width * 3;
for(int i = 0; i < height; i++) {
for(int j = 0; j < width; j++, dp += 3, sp += 4) {
dst[dp] = src[sp+2]; // R
dst[dp+1] = src[sp+1]; // G
dst[dp+2] = src[sp]; // B
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++, dp += 3, sp += 4) {
dst[dp] = src[sp+2]; // R
dst[dp+1] = src[sp+1]; // G
dst[dp+2] = src[sp]; // B
}
dp -= width * 6;
}
@@ -447,14 +428,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam);
// Enable GL.
void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
{
void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC) {
PIXELFORMATDESCRIPTOR pfd;
int format;
// Get the device context.
*hDC = GetDC(hWnd);
// Set the pixel format for the DC.
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
@@ -466,7 +446,7 @@ void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat(*hDC, &pfd);
SetPixelFormat(*hDC, format, &pfd);
// Create and enable the render context.
*hRC = wglCreateContext(*hDC);
wglMakeCurrent(*hDC, *hRC);
@@ -483,20 +463,18 @@ void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
}
// Disable GL.
void DisableGL(HWND hWnd, HDC hDC, HGLRC hRC)
{
void DisableGL(HWND hWnd, HDC hDC, HGLRC hRC) {
// Delete the texture.
if(g_textureID != -1)
if (g_textureID != -1)
glDeleteTextures(1, &g_textureID);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
ReleaseDC(hWnd, hDC);
}
// Size the GL view.
void SizeGL(ClientPlugin* plugin, int width, int height)
{
void SizeGL(ClientPlugin* plugin, int width, int height) {
g_width = width;
g_height = height;
@@ -517,7 +495,7 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
glEnable(GL_TEXTURE_2D);
// Delete the existing exture.
if(g_textureID != -1)
if (g_textureID != -1)
glDeleteTextures(1, &g_textureID);
// Create a new texture.
@@ -543,16 +521,15 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
}
delete [] buffer;
if(g_offscreenBrowser.get())
if (g_offscreenBrowser.get())
g_offscreenBrowser->SetSize(PET_VIEW, width, height);
}
// Render the view contents.
void RenderGL(ClientPlugin* plugin)
{
void RenderGL(ClientPlugin* plugin) {
wglMakeCurrent(plugin->hDC, plugin->hRC);
struct {
float tu, tv;
float x, y, z;
@@ -567,20 +544,20 @@ void RenderGL(ClientPlugin* plugin)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glTranslatef(0.0f, 0.0f, -3.0f);
// glTranslatef(0.0f, 0.0f, -3.0f);
// Draw the background gradient.
glPushAttrib(GL_ALL_ATTRIB_BITS);
glBegin(GL_QUADS);
glColor4f(1.0,0.0,0.0,1.0); // red
glVertex2f(-1.0,-1.0);
glVertex2f(1.0,-1.0);
glColor4f(0.0,0.0,1.0,1.0); // blue
glColor4f(1.0, 0.0, 0.0, 1.0); // red
glVertex2f(-1.0, -1.0);
glVertex2f(1.0, -1.0);
glColor4f(0.0, 0.0, 1.0, 1.0); // blue
glVertex2f(1.0, 1.0);
glVertex2f(-1.0, 1.0);
glEnd();
glPopAttrib();
// Rotate the view based on the mouse spin.
glRotatef(-g_spinX, 1.0f, 0.0f, 0.0f);
glRotatef(-g_spinY, 0.0f, 1.0f, 0.0f);
@@ -615,17 +592,17 @@ NPError NPP_NewImpl(NPMIMEType plugin_type, NPP instance, uint16 mode,
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
ClientPlugin *plugin = new ClientPlugin;
ClientPlugin* plugin = new ClientPlugin;
instance->pdata = reinterpret_cast<void*>(plugin);
return NPERR_NO_ERROR;
}
NPError NPP_DestroyImpl(NPP instance, NPSavedData** save) {
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
if (plugin) {
if(plugin->hWnd) {
if (plugin->hWnd) {
DestroyWindow(plugin->hWnd);
DisableGL(plugin->hWnd, plugin->hDC, plugin->hRC);
}
@@ -642,14 +619,13 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
if (window_info == NULL)
return NPERR_GENERIC_ERROR;
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
HWND parent_hwnd = reinterpret_cast<HWND>(window_info->window);
if (plugin->hWnd == NULL)
{
if (plugin->hWnd == NULL) {
WNDCLASS wc;
HINSTANCE hInstance = GetModuleHandle(NULL);
// Register the window class.
wc.style = CS_OWNDC;
wc.lpfnWndProc = PluginWndProc;
@@ -662,7 +638,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
wc.lpszMenuName = NULL;
wc.lpszClassName = L"ClientOSRPlugin";
RegisterClass(&wc);
// Create the main window.
plugin->hWnd = CreateWindow(L"ClientOSRPlugin", L"Client OSR Plugin",
WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, 0, 0, 0, 0, parent_hwnd, NULL,
@@ -670,7 +646,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
SetWindowLongPtr(plugin->hWnd, GWLP_USERDATA,
reinterpret_cast<LONG_PTR>(plugin));
// Enable GL drawing for the window.
EnableGL(plugin->hWnd, &(plugin->hDC), &(plugin->hRC));
@@ -699,22 +675,20 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
// Plugin window procedure.
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
LPARAM lParam) {
static POINT lastMousePos, curMousePos;
static bool mouseRotation = false;
static bool mouseTracking = false;
ClientPlugin* plugin =
reinterpret_cast<ClientPlugin*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
switch(message)
{
switch (message) {
case WM_CREATE:
// Start the timer that's used for redrawing.
SetTimer(hWnd, 1, 20, NULL);
return 0;
case WM_DESTROY:
// Stop the timer that's used for redrawing.
KillTimer(hWnd, 1);
@@ -724,10 +698,10 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
g_offscreenBrowser = NULL;
return 0;
case WM_TIMER:
case WM_TIMER:
RenderGL(plugin);
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
SetCapture(hWnd);
@@ -740,7 +714,7 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
} else {
if (g_offscreenBrowser.get()) {
g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
(message==WM_LBUTTONDOWN?MBT_LEFT:MBT_RIGHT), false, 1);
(message == WM_LBUTTONDOWN?MBT_LEFT:MBT_RIGHT), false, 1);
}
}
break;
@@ -757,13 +731,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
} else {
if (g_offscreenBrowser.get()) {
g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
(message==WM_LBUTTONUP?MBT_LEFT:MBT_RIGHT), true, 1);
(message == WM_LBUTTONUP?MBT_LEFT:MBT_RIGHT), true, 1);
}
}
break;
case WM_MOUSEMOVE:
if(mouseRotation) {
if (mouseRotation) {
// Apply rotation effect.
curMousePos.x = LOWORD(lParam);
curMousePos.y = HIWORD(lParam);
@@ -809,23 +783,24 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
GET_WHEEL_DELTA_WPARAM(wParam));
}
break;
case WM_SIZE: {
int width = LOWORD(lParam);
int width = LOWORD(lParam);
int height = HIWORD(lParam);
if(width > 0 && height > 0)
if (width > 0 && height > 0)
SizeGL(plugin, width, height);
} break;
break;
}
case WM_SETFOCUS:
case WM_KILLFOCUS:
if (g_offscreenBrowser.get())
g_offscreenBrowser->SendFocusEvent(message==WM_SETFOCUS);
g_offscreenBrowser->SendFocusEvent(message == WM_SETFOCUS);
break;
case WM_CAPTURECHANGED:
case WM_CANCELMODE:
if(!mouseRotation) {
if (!mouseRotation) {
if (g_offscreenBrowser.get())
g_offscreenBrowser->SendCaptureLostEvent();
}
@@ -846,7 +821,7 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
type = KT_KEYDOWN;
else if (message == WM_KEYUP || message == WM_SYSKEYUP)
type = KT_KEYUP;
if (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP ||
message == WM_SYSCHAR)
sysChar = true;
@@ -862,7 +837,8 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
} return 0;
return 0;
}
case WM_ERASEBKGND:
return 0;
@@ -871,36 +847,31 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
return DefWindowProc(hWnd, message, wParam, lParam);
}
} // namespace
} // namespace
NPError API_CALL NP_OSRGetEntryPoints(NPPluginFuncs* pFuncs)
{
NPError API_CALL NP_OSRGetEntryPoints(NPPluginFuncs* pFuncs) {
pFuncs->newp = NPP_NewImpl;
pFuncs->destroy = NPP_DestroyImpl;
pFuncs->setwindow = NPP_SetWindowImpl;
return NPERR_NO_ERROR;
}
NPError API_CALL NP_OSRInitialize(NPNetscapeFuncs* pFuncs)
{
NPError API_CALL NP_OSRInitialize(NPNetscapeFuncs* pFuncs) {
g_osrbrowser = pFuncs;
return NPERR_NO_ERROR;
}
NPError API_CALL NP_OSRShutdown(void)
{
NPError API_CALL NP_OSRShutdown(void) {
g_osrbrowser = NULL;
return NPERR_NO_ERROR;
}
CefRefPtr<CefBrowser> GetOffScreenBrowser()
{
CefRefPtr<CefBrowser> GetOffScreenBrowser() {
return g_offscreenBrowser;
}
void SetOffScreenTransparent(bool transparent)
{
void SetOffScreenTransparent(bool transparent) {
g_offscreenTransparent = transparent;
}
#endif // OS_WIN
#endif // OS_WIN

View File

@@ -6,8 +6,9 @@
// Portions of this implementation are borrowed from webkit\default_plugin\
// plugin_impl.h
#ifndef _CEFCLIENT_OSRPLUGIN_H
#define _CEFCLIENT_OSRPLUGIN_H
#ifndef CEF_TESTS_CEFCLIENT_OSRPLUGIN_H_
#define CEF_TESTS_CEFCLIENT_OSRPLUGIN_H_
#pragma once
#include "include/cef_base.h"
@@ -27,6 +28,6 @@ CefRefPtr<CefBrowser> GetOffScreenBrowser();
void SetOffScreenTransparent(bool transparent);
#endif // OS_WIN
#endif // OS_WIN
#endif // _CEFCLIENT_OSRPLUGIN_H
#endif // CEF_TESTS_CEFCLIENT_OSRPLUGIN_H_

View File

@@ -2,16 +2,16 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "osrplugin_test.h"
#include "cefclient/osrplugin_test.h"
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "osrplugin.h"
#include "cefclient.h"
#include "client_handler.h"
#include "plugin_test.h"
#include "cefclient/osrplugin.h"
#include "cefclient/cefclient.h"
#include "cefclient/client_handler.h"
#include "cefclient/plugin_test.h"
void InitOSRPluginTest()
{
void InitOSRPluginTest() {
// Structure providing information about the client plugin.
CefPluginInfo plugin_info;
CefString(&plugin_info.display_name).FromASCII("Client OSR Plugin");
@@ -28,27 +28,24 @@ void InitOSRPluginTest()
CefRegisterPlugin(plugin_info);
}
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent)
{
class Listener : public CefDOMEventListener
{
public:
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent) {
class Listener : public CefDOMEventListener {
public:
Listener() {}
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event)
{
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event) {
CefRefPtr<CefBrowser> browser = GetOffScreenBrowser();
CefRefPtr<CefDOMNode> element = event->GetTarget();
ASSERT(element.get());
std::string elementId = element->GetElementAttribute("id");
if (elementId == "back") {
browser->GoBack();
} else if(elementId == "forward") {
} else if (elementId == "forward") {
browser->GoForward();
} else if(elementId == "stop") {
} else if (elementId == "stop") {
browser->Reload();
} else if(elementId == "reload") {
} else if (elementId == "reload") {
browser->StopLoad();
} else if (elementId == "go") {
// Retrieve the value of the "url" field and load it in the off-screen
@@ -60,15 +57,15 @@ void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent)
CefString value = url->GetValue();
if (!value.empty())
browser->GetMainFrame()->LoadURL(value);
} else if(elementId == "testTransparency") {
} else if (elementId == "testTransparency") {
// Transparency test.
browser->GetMainFrame()->LoadURL(
"http://tests/transparency");
} else if(elementId == "testWindowlessPlugin") {
} else if (elementId == "testWindowlessPlugin") {
// Load flash, which is a windowless plugin.
browser->GetMainFrame()->LoadURL(
"http://www.adobe.com/software/flash/about/");
} else if(elementId == "viewSource") {
} else if (elementId == "viewSource") {
// View the page source for the host browser window.
AppGetBrowser()->GetMainFrame()->ViewSource();
} else {
@@ -80,24 +77,21 @@ void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent)
IMPLEMENT_REFCOUNTING(Listener);
};
class Visitor : public CefDOMVisitor
{
public:
class Visitor : public CefDOMVisitor {
public:
Visitor() {}
void RegisterClickListener(CefRefPtr<CefDOMDocument> document,
CefRefPtr<CefDOMEventListener> listener,
const std::string& elementId)
{
const std::string& elementId) {
CefRefPtr<CefDOMNode> element = document->GetElementById(elementId);
ASSERT(element.get());
element->AddEventListener("click", listener, false);
}
virtual void Visit(CefRefPtr<CefDOMDocument> document)
{
virtual void Visit(CefRefPtr<CefDOMDocument> document) {
CefRefPtr<CefDOMEventListener> listener(new Listener());
// Register click listeners for the various HTML elements.
RegisterClickListener(document, listener, "back");
RegisterClickListener(document, listener, "forward");

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_OSRPLUGIN_TEST_H
#define _CEFCLIENT_OSRPLUGIN_TEST_H
#ifndef CEF_TESTS_CEFCLIENT_OSRPLUGIN_TEST_H_
#define CEF_TESTS_CEFCLIENT_OSRPLUGIN_TEST_H_
#pragma once
#include "include/cef_base.h"
@@ -15,4 +16,4 @@ void InitOSRPluginTest();
// Run the test.
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent);
#endif // _CEFCLIENT_OSRPLUGIN_TEST_H
#endif // CEF_TESTS_CEFCLIENT_OSRPLUGIN_TEST_H_

View File

@@ -6,10 +6,9 @@
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_nplugin.h"
#include "clientplugin.h"
#include "cefclient/clientplugin.h"
void InitPluginTest()
{
void InitPluginTest() {
// Structure providing information about the client plugin.
CefPluginInfo plugin_info;
CefString(&plugin_info.display_name).FromASCII("Client Plugin");
@@ -26,8 +25,7 @@ void InitPluginTest()
CefRegisterPlugin(plugin_info);
}
void RunPluginTest(CefRefPtr<CefBrowser> browser)
{
void RunPluginTest(CefRefPtr<CefBrowser> browser) {
// Page content is provided in ClientHandler::OnBeforeResourceLoad().
browser->GetMainFrame()->LoadURL("http://tests/plugin");
}

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_PLUGIN_TEST_H
#define _CEFCLIENT_PLUGIN_TEST_H
#ifndef CEF_TESTS_CEFCLIENT_PLUGIN_TEST_H_
#define CEF_TESTS_CEFCLIENT_PLUGIN_TEST_H_
#pragma once
#include "include/cef_base.h"
@@ -15,4 +16,4 @@ void InitPluginTest();
// Run the test.
void RunPluginTest(CefRefPtr<CefBrowser> browser);
#endif // _CEFCLIENT_PLUGIN_TEST_H
#endif // CEF_TESTS_CEFCLIENT_PLUGIN_TEST_H_

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_RESOURCE_UTIL
#define _CEFCLIENT_RESOURCE_UTIL
#ifndef CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_
#define CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_
#pragma once
#include "include/cef_base.h"
@@ -11,13 +12,15 @@ class CefStreamReader;
#if defined(OS_WIN)
#include "resource.h"
#include "cefclient/resource.h"
// Load a resource of type BINARY
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes);
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId);
#elif (defined(OS_MACOSX) || defined(OS_POSIX))
#elif defined(OS_MACOSX) || defined(OS_POSIX)
#include <string> // NOLINT(build/include_order)
// Load the resource with the specified name.
bool LoadBinaryResource(const char* resource_name, std::string& resource_data);
@@ -25,4 +28,4 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name);
#endif
#endif // _CEFCLIENT_RESOURCE_UTIL
#endif // CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_

View File

@@ -3,18 +3,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "resource_util.h"
#include "include/cef_stream.h"
#include "util.h"
#include "cefclient/resource_util.h"
#include <stdio.h>
#include "base/file_util.h"
#include <string>
#include "include/cef_stream.h"
#include "cefclient/util.h"
bool GetResourceDir(std::string& dir) {
char buff[1024];
// Retrieve the executable path.
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
ssize_t len = readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len == -1)
return false;
@@ -26,7 +25,7 @@ bool GetResourceDir(std::string& dir) {
return false;
// Add "files" to the path.
strcpy(pos+1, "files");
strcpy(pos+1, "files"); // NOLINT(runtime/printf)
dir = std::string(buff);
return true;
}
@@ -50,7 +49,7 @@ bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
bytes_read = fread(buff, 1, sizeof(buff)-1, f);
if (bytes_read > 0)
resource_data.append(buff, bytes_read);
} while(bytes_read > 0);
} while (bytes_read > 0);
fclose(f);
return true;
@@ -58,7 +57,7 @@ bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
std::string path;
if (!GetResourceDir(path))
if (!GetResourceDir(path))
return NULL;
path.append("/");

View File

@@ -3,13 +3,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "resource_util.h"
#include "include/cef_stream.h"
#include "util.h"
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
#include <stdio.h>
#include "cefclient/resource_util.h"
#include "include/cef_stream.h"
#include "cefclient/util.h"
namespace {

View File

@@ -2,38 +2,34 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "resource_util.h"
#include "cefclient/resource_util.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_byte_read_handler.h"
#if defined(OS_WIN)
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
{
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes) {
extern HINSTANCE hInst;
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId),
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId),
MAKEINTRESOURCE(256));
if(hRes)
{
HGLOBAL hGlob = LoadResource(hInst, hRes);
if(hGlob)
{
dwSize = SizeofResource(hInst, hRes);
pBytes = (LPBYTE)LockResource(hGlob);
if(dwSize > 0 && pBytes)
return true;
}
}
if (hRes) {
HGLOBAL hGlob = LoadResource(hInst, hRes);
if (hGlob) {
dwSize = SizeofResource(hInst, hRes);
pBytes = (LPBYTE)LockResource(hGlob);
if (dwSize > 0 && pBytes)
return true;
}
}
return false;
return false;
}
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId)
{
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId) {
DWORD dwSize;
LPBYTE pBytes;
if(LoadBinaryResource(binaryId, dwSize, pBytes)) {
if (LoadBinaryResource(binaryId, dwSize, pBytes)) {
return CefStreamReader::CreateForHandler(
new CefByteReadHandler(pBytes, dwSize, NULL));
}
@@ -41,4 +37,4 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId)
return NULL;
}
#endif // OS_WIN
#endif // OS_WIN

View File

@@ -2,46 +2,46 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "scheme_test.h"
#include "cefclient/scheme_test.h"
#include <algorithm>
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_response.h"
#include "include/cef_request.h"
#include "include/cef_scheme.h"
#include "resource_util.h"
#include "string_util.h"
#include "util.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
#include "cefclient/util.h"
#if defined(OS_WIN)
#include "resource.h"
#include "cefclient/resource.h"
#endif
// Implementation of the schema handler for client:// requests.
class ClientSchemeHandler : public CefSchemeHandler
{
public:
class ClientSchemeHandler : public CefSchemeHandler {
public:
ClientSchemeHandler() : offset_(0) {}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefSchemeHandlerCallback> callback)
OVERRIDE
{
OVERRIDE {
REQUIRE_IO_THREAD();
bool handled = false;
AutoLock lock_scope(this);
std::string url = request->GetURL();
if(strstr(url.c_str(), "handler.html") != NULL) {
if (strstr(url.c_str(), "handler.html") != NULL) {
// Build the response html
data_ = "<html><head><title>Client Scheme Handler</title></head><body>"
"This contents of this page page are served by the "
"ClientSchemeHandler class handling the client:// protocol."
"<br/>You should see an image:"
"<br/><img src=\"client://tests/client.png\"><pre>";
// Output a string representation of the request
std::string dump;
DumpRequestContents(request, dump);
@@ -58,20 +58,19 @@ public:
// Set the resulting mime type
mime_type_ = "text/html";
}
else if(strstr(url.c_str(), "client.png") != NULL) {
} else if (strstr(url.c_str(), "client.png") != NULL) {
// Load the response image
#if defined(OS_WIN)
DWORD dwSize;
LPBYTE pBytes;
if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
if (LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
data_ = std::string(reinterpret_cast<const char*>(pBytes), dwSize);
handled = true;
// Set the resulting mime type
mime_type_ = "image/jpg";
}
#elif (defined(OS_MACOSX) || defined(OS_LINUX))
if(LoadBinaryResource("logo.png", data_)) {
#elif defined(OS_MACOSX) || defined(OS_LINUX)
if (LoadBinaryResource("logo.png", data_)) {
handled = true;
// Set the resulting mime type
mime_type_ = "image/png";
@@ -92,8 +91,7 @@ public:
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE
{
CefString& redirectUrl) OVERRIDE {
REQUIRE_IO_THREAD();
ASSERT(!data_.empty());
@@ -105,8 +103,7 @@ public:
response_length = data_.length();
}
virtual void Cancel() OVERRIDE
{
virtual void Cancel() OVERRIDE {
REQUIRE_IO_THREAD();
}
@@ -114,8 +111,7 @@ public:
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefSchemeHandlerCallback> callback)
OVERRIDE
{
OVERRIDE {
REQUIRE_IO_THREAD();
bool has_data = false;
@@ -123,7 +119,7 @@ public:
AutoLock lock_scope(this);
if(offset_ < data_.length()) {
if (offset_ < data_.length()) {
// Copy the next block of data into the buffer.
int transfer_size =
std::min(bytes_to_read, static_cast<int>(data_.length() - offset_));
@@ -137,7 +133,7 @@ public:
return has_data;
}
private:
private:
std::string data_;
std::string mime_type_;
size_t offset_;
@@ -147,15 +143,13 @@ private:
};
// Implementation of the factory for for creating schema handlers.
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory
{
public:
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
// Return a new scheme handler instance to handle the request.
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
const CefString& scheme_name,
CefRefPtr<CefRequest> request)
OVERRIDE
{
OVERRIDE {
REQUIRE_IO_THREAD();
return new ClientSchemeHandler();
}
@@ -163,14 +157,12 @@ public:
IMPLEMENT_REFCOUNTING(ClientSchemeHandlerFactory);
};
void InitSchemeTest()
{
void InitSchemeTest() {
CefRegisterCustomScheme("client", true, false, false);
CefRegisterSchemeHandlerFactory("client", "tests",
new ClientSchemeHandlerFactory());
}
void RunSchemeTest(CefRefPtr<CefBrowser> browser)
{
void RunSchemeTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("client://tests/handler.html");
}

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_SCHEME_TEST
#define _CEFCLIENT_SCHEME_TEST
#ifndef CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_
#define CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_
#pragma once
#include "include/cef_base.h"
@@ -15,4 +16,4 @@ void InitSchemeTest();
// Run the test.
void RunSchemeTest(CefRefPtr<CefBrowser> browser);
#endif // _CEFCLIENT_SCHEME_TEST
#endif // CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_

View File

@@ -2,12 +2,12 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "string_util.h"
#include "include/cef_request.h"
#include "cefclient/string_util.h"
#include <sstream>
#include <string>
#include "include/cef_request.h"
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
{
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str) {
std::stringstream ss;
ss << "URL: " << std::string(request->GetURL());
@@ -15,31 +15,31 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
if(headerMap.size() > 0) {
if (headerMap.size() > 0) {
ss << "\nHeaders:";
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
for(; it != headerMap.end(); ++it) {
for (; it != headerMap.end(); ++it) {
ss << "\n\t" << std::string((*it).first) << ": " <<
std::string((*it).second);
}
}
CefRefPtr<CefPostData> postData = request->GetPostData();
if(postData.get()) {
if (postData.get()) {
CefPostData::ElementVector elements;
postData->GetElements(elements);
if(elements.size() > 0) {
if (elements.size() > 0) {
ss << "\nPost Data:";
CefRefPtr<CefPostDataElement> element;
CefPostData::ElementVector::const_iterator it = elements.begin();
for(; it != elements.end(); ++it) {
for (; it != elements.end(); ++it) {
element = (*it);
if(element->GetType() == PDE_TYPE_BYTES) {
if (element->GetType() == PDE_TYPE_BYTES) {
// the element is composed of bytes
ss << "\n\tBytes: ";
if(element->GetBytesCount() == 0)
if (element->GetBytesCount() == 0) {
ss << "(empty)";
else {
} else {
// retrieve the data.
size_t size = element->GetBytesCount();
char* bytes = new char[size];
@@ -47,7 +47,7 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
ss << std::string(bytes, size);
delete [] bytes;
}
} else if(element->GetType() == PDE_TYPE_FILE) {
} else if (element->GetType() == PDE_TYPE_FILE) {
ss << "\n\tFile: " << std::string(element->GetFile());
}
}
@@ -58,18 +58,17 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
}
std::string StringReplace(const std::string& str, const std::string& from,
const std::string& to)
{
const std::string& to) {
std::string result = str;
std::string::size_type pos = 0;
std::string::size_type from_len = from.length();
std::string::size_type to_len = to.length();
do {
pos = result.find(from, pos);
if(pos != std::string::npos) {
if (pos != std::string::npos) {
result.replace(pos, from_len, to);
pos += to_len;
}
} while(pos != std::string::npos);
} while (pos != std::string::npos);
return result;
}

View File

@@ -2,9 +2,11 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_STRING_UTIL_H
#define _CEFCLIENT_STRING_UTIL_H
#ifndef CEF_TESTS_CEFCLIENT_STRING_UTIL_H_
#define CEF_TESTS_CEFCLIENT_STRING_UTIL_H_
#pragma once
#include <string>
#include "include/cef_base.h"
class CefRequest;
@@ -16,4 +18,4 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str);
std::string StringReplace(const std::string& str, const std::string& from,
const std::string& to);
#endif // _CEFCLIENT_STRING_UTIL_H
#endif // CEF_TESTS_CEFCLIENT_STRING_UTIL_H_

View File

@@ -3,15 +3,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "uiplugin.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "cefclient.h"
#include <gl/gl.h>
#include <sstream>
#include "cefclient/uiplugin.h"
#if defined(OS_WIN)
#include <windows.h>
#include <gl/gl.h>
#include <sstream>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "cefclient/cefclient.h"
// Initialized in NP_Initialize.
NPNetscapeFuncs* g_uibrowser = NULL;
@@ -22,11 +24,9 @@ float g_rotationspeed = 0.0f;
float g_theta = 0.0f;
// Class holding pointers for the client plugin window.
class ClientPlugin
{
public:
ClientPlugin()
{
class ClientPlugin {
public:
ClientPlugin() {
hWnd = NULL;
hDC = NULL;
hRC = NULL;
@@ -49,17 +49,17 @@ NPError NPP_NewImpl(NPMIMEType plugin_type, NPP instance, uint16 mode,
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
ClientPlugin *plugin = new ClientPlugin;
ClientPlugin* plugin = new ClientPlugin;
instance->pdata = reinterpret_cast<void*>(plugin);
return NPERR_NO_ERROR;
}
NPError NPP_DestroyImpl(NPP instance, NPSavedData** save) {
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
if (plugin) {
if(plugin->hWnd) {
if (plugin->hWnd) {
DestroyWindow(plugin->hWnd);
DisableOpenGL(plugin->hWnd, plugin->hDC, plugin->hRC);
}
@@ -78,14 +78,13 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
if (window_info == NULL)
return NPERR_GENERIC_ERROR;
ClientPlugin *plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
HWND parent_hwnd = reinterpret_cast<HWND>(window_info->window);
if (plugin->hWnd == NULL)
{
if (plugin->hWnd == NULL) {
WNDCLASS wc;
HINSTANCE hInstance = GetModuleHandle(NULL);
// Register the window class.
wc.style = CS_OWNDC;
wc.lpfnWndProc = PluginWndProc;
@@ -124,8 +123,7 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
}
// Send the notification to the browser as a JavaScript function call.
static void NotifyNewRotation(float value)
{
static void NotifyNewRotation(float value) {
std::stringstream buf;
buf << "notifyNewRotation(" << value << ");";
AppGetBrowser()->GetMainFrame()->ExecuteJavaScript(buf.str(), CefString(),
@@ -135,42 +133,40 @@ static void NotifyNewRotation(float value)
// Nice little fly polygon borrowed from the OpenGL Red Book.
const GLubyte fly[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60,
0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20,
0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60,
0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20,
0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20,
0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC,
0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30,
0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0,
0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0,
0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0,
0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0,
0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30,
0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08,
0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08,
0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08,
0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08,
0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08};
// Plugin window procedure.
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
LPARAM lParam) {
ClientPlugin* plugin =
reinterpret_cast<ClientPlugin*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
switch(message)
{
switch (message) {
case WM_CREATE:
// Start the timer that's used for redrawing.
SetTimer(hWnd, 1, 1, NULL);
return 0;
case WM_DESTROY:
// Stop the timer that's used for redrawing.
KillTimer(hWnd, 1);
return 0;
case WM_LBUTTONDOWN:
// Decrement rotation speed.
ModifyRotation(-2.0f);
@@ -201,24 +197,28 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
// Adjust the theta value and redraw the display when the timer fires.
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glEnable(GL_POLYGON_STIPPLE);
glPolygonStipple(fly);
glRotatef(g_theta, 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(0.7f, 0.7f);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.7f, -0.7f);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(-0.7f, -0.7f);
glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(-0.7f, 0.7f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.7f, 0.7f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.7f, -0.7f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(-0.7f, -0.7f);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex2f(-0.7f, 0.7f);
glEnd();
glDisable(GL_POLYGON_STIPPLE);
glPopMatrix();
SwapBuffers(plugin->hDC);
g_theta -= g_rotationspeed;
}
@@ -226,14 +226,13 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
}
// Enable OpenGL.
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
{
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC) {
PIXELFORMATDESCRIPTOR pfd;
int format;
// Get the device context.
*hDC = GetDC(hWnd);
// Set the pixel format for the DC.
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
@@ -245,51 +244,45 @@ void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat(*hDC, &pfd);
SetPixelFormat(*hDC, format, &pfd);
// Create and enable the render contex.
*hRC = wglCreateContext(*hDC);
}
// Disable OpenGL.
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
{
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
ReleaseDC(hWnd, hDC);
}
} // namespace
} // namespace
NPError API_CALL NP_UIGetEntryPoints(NPPluginFuncs* pFuncs)
{
NPError API_CALL NP_UIGetEntryPoints(NPPluginFuncs* pFuncs) {
pFuncs->newp = NPP_NewImpl;
pFuncs->destroy = NPP_DestroyImpl;
pFuncs->setwindow = NPP_SetWindowImpl;
return NPERR_NO_ERROR;
}
NPError API_CALL NP_UIInitialize(NPNetscapeFuncs* pFuncs)
{
NPError API_CALL NP_UIInitialize(NPNetscapeFuncs* pFuncs) {
g_uibrowser = pFuncs;
return NPERR_NO_ERROR;
}
NPError API_CALL NP_UIShutdown(void)
{
NPError API_CALL NP_UIShutdown(void) {
g_uibrowser = NULL;
return NPERR_NO_ERROR;
}
void ModifyRotation(float value)
{
void ModifyRotation(float value) {
g_rotationspeed += value;
NotifyNewRotation(g_rotationspeed);
}
void ResetRotation()
{
void ResetRotation() {
g_rotationspeed = 0.0;
NotifyNewRotation(g_rotationspeed);
}
#endif // OS_WIN
#endif // OS_WIN

View File

@@ -6,8 +6,9 @@
// Portions of this implementation are borrowed from webkit\default_plugin\
// plugin_impl.h
#ifndef _CEFCLIENT_UIPLUGIN_H
#define _CEFCLIENT_UIPLUGIN_H
#ifndef CEF_TESTS_CEFCLIENT_UIPLUGIN_H_
#define CEF_TESTS_CEFCLIENT_UIPLUGIN_H_
#pragma once
#include "include/cef_nplugin.h"
@@ -24,6 +25,6 @@ void ModifyRotation(float value);
// Function called to reset the rotation value.
void ResetRotation();
#endif // OS_WIN
#endif // OS_WIN
#endif // _CEFCLIENT_UIPLUGIN_H
#endif // CEF_TESTS_CEFCLIENT_UIPLUGIN_H_

View File

@@ -2,18 +2,18 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "uiplugin_test.h"
#include "cefclient/uiplugin_test.h"
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_v8.h"
#include "uiplugin.h"
#include "cefclient.h"
#include "cefclient/uiplugin.h"
#include "cefclient/cefclient.h"
// Implementation of the V8 handler class for the "window.uiapp" functions.
class ClientV8UIHandler : public CefV8Handler
{
public:
class ClientV8UIHandler : public CefV8Handler {
public:
ClientV8UIHandler() {}
// Execute with the specified argument list and return value. Return true if
@@ -22,32 +22,31 @@ public:
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception)
{
if(name == "modifyRotation") {
CefString& exception) {
if (name == "modifyRotation") {
// This function requires one argument.
if(arguments.size() != 1)
if (arguments.size() != 1)
return false;
float increment = 0.;
if(arguments[0]->IsInt()) {
if (arguments[0]->IsInt()) {
// The argument is an integer value.
increment = static_cast<float>(arguments[0]->GetIntValue());
} else if(arguments[0]->IsDouble()) {
} else if (arguments[0]->IsDouble()) {
// The argument is an double value.
increment = static_cast<float>(arguments[0]->GetDoubleValue());
}
if(increment != 0.) {
if (increment != 0.) {
// Modify the rotation accordingly.
ModifyRotation(increment);
return true;
}
} else if(name == "resetRotation") {
} else if (name == "resetRotation") {
// Reset the rotation value.
ResetRotation();
return true;
} else if(name == "viewSource") {
} else if (name == "viewSource") {
// View the page source.
AppGetBrowser()->GetMainFrame()->ViewSource();
return true;
@@ -59,8 +58,7 @@ public:
IMPLEMENT_REFCOUNTING(ClientV8UIHandler);
};
void InitUIPluginTest()
{
void InitUIPluginTest() {
// Structure providing information about the client plugin.
CefPluginInfo plugin_info;
CefString(&plugin_info.display_name).FromASCII("Client UI Plugin");
@@ -100,7 +98,6 @@ void InitUIPluginTest()
CefRegisterExtension("uiplugin/test", code, new ClientV8UIHandler());
}
void RunUIPluginTest(CefRefPtr<CefBrowser> browser)
{
void RunUIPluginTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://tests/uiapp");
}

View File

@@ -2,8 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_UIPLUGIN_TEST_H
#define _CEFCLIENT_UIPLUGIN_TEST_H
#ifndef CEF_TESTS_CEFCLIENT_UIPLUGIN_TEST_H_
#define CEF_TESTS_CEFCLIENT_UIPLUGIN_TEST_H_
#pragma once
#include "include/cef_base.h"
@@ -15,4 +16,4 @@ void InitUIPluginTest();
// Run the test.
void RunUIPluginTest(CefRefPtr<CefBrowser> browser);
#endif // _CEFCLIENT_UIPLUGIN_TEST_H
#endif // CEF_TESTS_CEFCLIENT_UIPLUGIN_TEST_H_

View File

@@ -2,35 +2,36 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEFCLIENT_UTIL_H
#define _CEFCLIENT_UTIL_H
#ifndef CEF_TESTS_CEFCLIENT_UTIL_H_
#define CEF_TESTS_CEFCLIENT_UTIL_H_
#pragma once
#include "include/cef_task.h"
#if defined(OS_WIN)
#include <windows.h>
#include <windows.h> // NOLINT(build/include_order)
#ifndef NDEBUG
#define ASSERT(condition) if(!(condition)) { DebugBreak(); }
#define ASSERT(condition) if (!(condition)) { DebugBreak(); }
#else
#define ASSERT(condition) ((void)0)
#endif
#else // !OS_WIN
#else // !OS_WIN
#include <assert.h>
#include <assert.h> // NOLINT(build/include_order)
#ifndef NDEBUG
#define ASSERT(condition) if(!(condition)) { assert(false); }
#define ASSERT(condition) if (!(condition)) { assert(false); }
#else
#define ASSERT(condition) ((void)0)
#endif
#endif // !OS_WIN
#endif // !OS_WIN
#define REQUIRE_UI_THREAD() ASSERT(CefCurrentlyOn(TID_UI));
#define REQUIRE_IO_THREAD() ASSERT(CefCurrentlyOn(TID_IO));
#define REQUIRE_FILE_THREAD() ASSERT(CefCurrentlyOn(TID_FILE));
#endif // _CEFCLIENT_UTIL_H
#endif // CEF_TESTS_CEFCLIENT_UTIL_H_

View File

@@ -7,13 +7,12 @@
namespace {
void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line)
{
void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line) {
std::string program = command_line->GetProgram();
EXPECT_EQ("test.exe", program);
EXPECT_TRUE(command_line->HasSwitches());
EXPECT_TRUE(command_line->HasSwitch("switch1"));
std::string switch1 = command_line->GetSwitchValue("switch1");
EXPECT_EQ("", switch1);
@@ -60,7 +59,7 @@ void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line)
EXPECT_TRUE(has4);
EXPECT_TRUE(command_line->HasArguments());
CefCommandLine::ArgumentList args;
command_line->GetArguments(args);
EXPECT_EQ((size_t)2, args.size());
@@ -70,11 +69,10 @@ void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line)
EXPECT_EQ("arg 2", arg1);
}
}
} // namespace
// Test creating a command line from argc/argv or string.
TEST(CommandLineTest, Init)
{
TEST(CommandLineTest, Init) {
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
EXPECT_TRUE(command_line.get() != NULL);
@@ -98,8 +96,7 @@ TEST(CommandLineTest, Init)
}
// Test creating a command line using set and append methods.
TEST(CommandLineTest, Manual)
{
TEST(CommandLineTest, Manual) {
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
EXPECT_TRUE(command_line.get() != NULL);

View File

@@ -3,8 +3,8 @@
// can be found in the LICENSE file.
#include "include/cef_content_filter.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
namespace {
@@ -12,121 +12,116 @@ bool g_ContentFilterTestHandlerHandleResourceResponseCalled;
bool g_ContentFilterProcessDataCalled;
bool g_ContentFilterDrainCalled;
class TestContentFilter : public CefContentFilter
{
public:
TestContentFilter()
{
look_for_ = "FAILURE!";
replace_with_ = "BIG SUCCESS!";
class TestContentFilter : public CefContentFilter {
public:
TestContentFilter() {
look_for_ = "FAILURE!";
replace_with_ = "BIG SUCCESS!";
}
virtual void ProcessData(const void* data, int data_size,
CefRefPtr<CefStreamReader>& substitute_data)
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
g_ContentFilterProcessDataCalled = true;
std::string in_out(static_cast<const char*>(data), data_size);
std::string::const_iterator look_for_it = look_for_.begin();
bool is_modified = false;
if (!remainder_.empty()) {
in_out.insert(in_out.begin(), remainder_.begin(), remainder_.end());
remainder_.clear();
}
virtual void ProcessData(const void* data, int data_size,
CefRefPtr<CefStreamReader>& substitute_data)
OVERRIDE
{
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
g_ContentFilterProcessDataCalled = true;
std::string in_out((char*)data, data_size);
std::string::const_iterator look_for_it = look_for_.begin();
bool is_modified = false;
if (!remainder_.empty()) {
in_out.insert(in_out.begin(), remainder_.begin(), remainder_.end());
remainder_.clear();
std::string::size_type off = 0;
do {
if ((look_for_it == look_for_.end()) ||
(look_for_it == look_for_.begin())) {
// start over
off = in_out.find(look_for_[0], off);
if (off == in_out.npos)
break;
look_for_it = look_for_.begin();
}
std::string::size_type off = 0;
do {
if ((look_for_it == look_for_.end()) ||
(look_for_it == look_for_.begin())) {
// start over
off = in_out.find(look_for_[0], off);
if (off == in_out.npos)
break;
while (look_for_it != look_for_.end()) {
if (*look_for_it != in_out[off]) {
look_for_it = look_for_.begin();
}
while (look_for_it != look_for_.end()) {
if (*look_for_it != in_out[off]) {
look_for_it = look_for_.begin();
break;
}
if (++off == in_out.length())
off = in_out.npos;
if (off == in_out.npos)
break;
look_for_it++;
break;
}
if (look_for_it == look_for_.end()) {
// found it
in_out.replace(in_out.begin() + off - look_for_.length(),
in_out.begin() + off,
replace_with_);
off += replace_with_.length() - look_for_.length();
if (off >= in_out.length())
off = in_out.npos;
if (++off == in_out.length())
off = in_out.npos;
look_for_it = look_for_.begin();
is_modified = true;
}
} while (off != in_out.npos);
if (off == in_out.npos)
break;
if (look_for_it != look_for_.begin()) {
// partial match at the end of the buffer
// save for next packet
size_t slice_off =
in_out.length() - (look_for_it - look_for_.begin()) - 1;
remainder_ = in_out.substr(slice_off);
in_out.erase(slice_off);
look_for_it++;
}
if (is_modified) {
substitute_data =
CefStreamReader::CreateForData((void*)in_out.data(), in_out.size());
if (look_for_it == look_for_.end()) {
// found it
in_out.replace(in_out.begin() + off - look_for_.length(),
in_out.begin() + off,
replace_with_);
off += replace_with_.length() - look_for_.length();
if (off >= in_out.length())
off = in_out.npos;
look_for_it = look_for_.begin();
is_modified = true;
}
} while (off != in_out.npos);
if (look_for_it != look_for_.begin()) {
// partial match at the end of the buffer
// save for next packet
size_t slice_off =
in_out.length() - (look_for_it - look_for_.begin()) - 1;
remainder_ = in_out.substr(slice_off);
in_out.erase(slice_off);
}
virtual void Drain(CefRefPtr<CefStreamReader>& remainder) OVERRIDE
{
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
g_ContentFilterDrainCalled = true;
if (remainder_.empty())
return;
remainder = CefStreamReader::CreateForData((void*)remainder_.data(),
remainder_.size());
if (is_modified) {
substitute_data = CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(in_out.data())),
in_out.size());
}
}
protected:
IMPLEMENT_REFCOUNTING(TestContentFilter);
virtual void Drain(CefRefPtr<CefStreamReader>& remainder) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
private:
std::string look_for_;
std::string replace_with_;
std::string remainder_;
g_ContentFilterDrainCalled = true;
if (remainder_.empty())
return;
remainder = CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(remainder_.data())),
remainder_.size());
}
protected:
IMPLEMENT_REFCOUNTING(TestContentFilter);
private:
std::string look_for_;
std::string replace_with_;
std::string remainder_;
};
class ContentFilterTestHandler : public TestHandler
{
public:
class Visitor : public CefDOMVisitor
{
public:
Visitor(ContentFilterTestHandler* handler) : handler_(handler) {}
class ContentFilterTestHandler : public TestHandler {
public:
class Visitor : public CefDOMVisitor {
public:
explicit Visitor(ContentFilterTestHandler* handler) : handler_(handler) {}
// Test if the filter succeeded in modifying the content
void TestContentReplaced(CefRefPtr<CefDOMDocument> document)
{
void TestContentReplaced(CefRefPtr<CefDOMDocument> document) {
// Navigate the complete document structure.
CefRefPtr<CefDOMNode> resultNode =
document->GetElementById("test_result");
@@ -135,10 +130,9 @@ public:
EXPECT_EQ("BIG SUCCESS!", resultNode->GetElementInnerText().ToString());
}
virtual void Visit(CefRefPtr<CefDOMDocument> document) OVERRIDE
{
virtual void Visit(CefRefPtr<CefDOMDocument> document) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
handler_->got_visitor_called_.yes();
TestContentReplaced(document);
@@ -146,22 +140,20 @@ public:
handler_->DestroyTest();
}
protected:
protected:
ContentFilterTestHandler* handler_;
IMPLEMENT_REFCOUNTING(Visitor);
};
};
ContentFilterTestHandler()
{
ContentFilterTestHandler() {
visitor_ = new Visitor(this);
}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
std::string mainHtml =
"<p>If filtering works you should see BIG SUCCESS! below:</p>"
"<div id=\"test_result\">FAILURE!</div>";
AddResource("http://tests/test_filter.html", mainHtml, "text/html");
CreateBrowser("http://tests/test_filter.html");
}
@@ -169,10 +161,10 @@ public:
virtual void OnResourceResponse(CefRefPtr<CefBrowser> browser,
const CefString& url,
CefRefPtr<CefResponse> response,
CefRefPtr<CefContentFilter>& filter) OVERRIDE
{
CefRefPtr<CefContentFilter>& filter)
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
g_ContentFilterTestHandlerHandleResourceResponseCalled = true;
ASSERT_EQ(url, "http://tests/test_filter.html");
@@ -193,11 +185,10 @@ public:
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
int httpStatusCode) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
if(frame->IsMain()) {
if (frame->IsMain()) {
// The page is done loading so visit the DOM.
browser->GetMainFrame()->VisitDOM(visitor_.get());
}
@@ -205,15 +196,14 @@ public:
TrackCallback got_visitor_called_;
private:
private:
CefRefPtr<Visitor> visitor_;
};
} // anonymous
} // namespace
// Verify send and recieve
TEST(ContentFilterTest, ContentFilter)
{
TEST(ContentFilterTest, ContentFilter) {
g_ContentFilterTestHandlerHandleResourceResponseCalled = false;
g_ContentFilterProcessDataCalled = false;
g_ContentFilterDrainCalled = false;

View File

@@ -2,13 +2,13 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include <vector>
#include "include/cef_cookie.h"
#include "include/cef_runnable.h"
#include "tests/unittests/test_suite.h"
#include "base/scoped_temp_dir.h"
#include "base/synchronization/waitable_event.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_suite.h"
#include <vector>
namespace {
@@ -19,8 +19,7 @@ const char* kTestPath = "/path/to/cookietest";
typedef std::vector<CefCookie> CookieVector;
void IOT_Set(const CefString& url, CookieVector* cookies,
base::WaitableEvent* event)
{
base::WaitableEvent* event) {
CookieVector::const_iterator it = cookies->begin();
for (; it != cookies->end(); ++it)
EXPECT_TRUE(CefSetCookie(url, *it));
@@ -28,28 +27,25 @@ void IOT_Set(const CefString& url, CookieVector* cookies,
}
void IOT_Delete(const CefString& url, const CefString& cookie_name,
base::WaitableEvent* event)
{
base::WaitableEvent* event) {
EXPECT_TRUE(CefDeleteCookies(url, cookie_name));
event->Signal();
}
class TestVisitor : public CefCookieVisitor
{
public:
class TestVisitor : public CefCookieVisitor {
public:
TestVisitor(CookieVector* cookies, bool deleteCookies,
base::WaitableEvent* event)
: cookies_(cookies), delete_cookies_(deleteCookies), event_(event)
{
: cookies_(cookies),
delete_cookies_(deleteCookies),
event_(event) {
}
virtual ~TestVisitor()
{
virtual ~TestVisitor() {
event_->Signal();
}
virtual bool Visit(const CefCookie& cookie, int count, int total,
bool& deleteCookie)
{
bool& deleteCookie) {
cookies_->push_back(cookie);
if (delete_cookies_)
deleteCookie = true;
@@ -66,8 +62,7 @@ public:
// Create a test cookie. If |withDomain| is true a domain cookie will be
// created, otherwise a host cookie will be created.
void CreateCookie(CefCookie& cookie, bool withDomain,
base::WaitableEvent& event)
{
base::WaitableEvent& event) {
CefString(&cookie.name).FromASCII("my_cookie");
CefString(&cookie.value).FromASCII("My Value");
if (withDomain)
@@ -83,7 +78,7 @@ void CreateCookie(CefCookie& cookie, bool withDomain,
CookieVector cookies;
cookies.push_back(cookie);
// Set the cookie.
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Set, kTestUrl, &cookies,
&event));
@@ -94,17 +89,16 @@ void CreateCookie(CefCookie& cookie, bool withDomain,
// is a domain cookie, otherwise a host cookie. if |deleteCookies| is true
// the cookie will be deleted when it's retrieved.
void GetCookie(const CefCookie& cookie, bool withDomain,
base::WaitableEvent& event, bool deleteCookies)
{
base::WaitableEvent& event, bool deleteCookies) {
CookieVector cookies;
// Get the cookie and delete it.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, deleteCookies, &event)));
event.Wait();
EXPECT_EQ((CookieVector::size_type)1, cookies.size());
const CefCookie& cookie_read = cookies[0];
EXPECT_EQ(CefString(&cookie_read.name), "my_cookie");
EXPECT_EQ(CefString(&cookie_read.value), "My Value");
@@ -128,8 +122,7 @@ void GetCookie(const CefCookie& cookie, bool withDomain,
// Verify that no cookies exist. If |withUrl| is true it will only check for
// cookies matching the URL.
void VerifyNoCookies(base::WaitableEvent& event, bool withUrl)
{
void VerifyNoCookies(base::WaitableEvent& event, bool withUrl) {
CookieVector cookies;
// Verify that the cookie has been deleted.
@@ -145,18 +138,16 @@ void VerifyNoCookies(base::WaitableEvent& event, bool withUrl)
}
// Delete all system cookies.
void DeleteAllCookies(base::WaitableEvent& event)
{
void DeleteAllCookies(base::WaitableEvent& event) {
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, CefString(),
CefString(), &event));
event.Wait();
}
} // anonymous
} // namespace
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookie)
{
TEST(CookieTest, DomainCookie) {
base::WaitableEvent event(false, false);
CefCookie cookie;
@@ -171,8 +162,7 @@ TEST(CookieTest, DomainCookie)
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookie)
{
TEST(CookieTest, HostCookie) {
base::WaitableEvent event(false, false);
CefCookie cookie;
@@ -187,8 +177,7 @@ TEST(CookieTest, HostCookie)
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookies)
{
TEST(CookieTest, MultipleCookies) {
base::WaitableEvent event(false, false);
std::stringstream ss;
int i;
@@ -196,9 +185,9 @@ TEST(CookieTest, MultipleCookies)
CookieVector cookies;
const int kNumCookies = 4;
// Create the cookies.
for(i = 0; i < kNumCookies; i++) {
for (i = 0; i < kNumCookies; i++) {
CefCookie cookie;
ss << "my_cookie" << i;
@@ -225,7 +214,7 @@ TEST(CookieTest, MultipleCookies)
EXPECT_EQ((CookieVector::size_type)kNumCookies, cookies.size());
CookieVector::const_iterator it = cookies.begin();
for(i = 0; it != cookies.end(); ++it, ++i) {
for (i = 0; it != cookies.end(); ++it, ++i) {
const CefCookie& cookie = *it;
ss << "my_cookie" << i;
@@ -242,7 +231,7 @@ TEST(CookieTest, MultipleCookies)
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, kTestUrl,
CefString("my_cookie1"), &event));
event.Wait();
// Verify that the cookie has been deleted.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, false, &event)));
@@ -259,7 +248,7 @@ TEST(CookieTest, MultipleCookies)
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, kTestUrl,
CefString(), &event));
event.Wait();
// Verify that the cookies have been deleted.
EXPECT_TRUE(CefVisitUrlCookies(kTestUrl, false,
new TestVisitor(&cookies, false, &event)));
@@ -268,7 +257,7 @@ TEST(CookieTest, MultipleCookies)
EXPECT_EQ((CookieVector::size_type)0, cookies.size());
// Create the cookies.
for(i = 0; i < kNumCookies; i++) {
for (i = 0; i < kNumCookies; i++) {
CefCookie cookie;
ss << "my_cookie" << i;
@@ -296,11 +285,10 @@ TEST(CookieTest, MultipleCookies)
EXPECT_EQ((CookieVector::size_type)0, cookies.size());
}
TEST(CookieTest, AllCookies)
{
TEST(CookieTest, AllCookies) {
base::WaitableEvent event(false, false);
CookieVector cookies;
// Delete all system cookies just in case something is left over from a
// different test.
CefPostTask(TID_IO, NewCefRunnableFunction(IOT_Delete, CefString(),
@@ -375,8 +363,7 @@ TEST(CookieTest, AllCookies)
VerifyNoCookies(event, false);
}
TEST(CookieTest, ChangeDirectory)
{
TEST(CookieTest, ChangeDirectory) {
base::WaitableEvent event(false, false);
CefCookie cookie;

View File

@@ -3,21 +3,18 @@
// can be found in the LICENSE file.
#include "include/cef_dom.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
namespace {
class TestDOMHandler : public TestHandler
{
public:
class Visitor : public CefDOMVisitor
{
public:
Visitor(TestDOMHandler* handler) : handler_(handler) {}
class TestDOMHandler : public TestHandler {
public:
class Visitor : public CefDOMVisitor {
public:
explicit Visitor(TestDOMHandler* handler) : handler_(handler) {}
void TestHeadNodeStructure(CefRefPtr<CefDOMNode> headNode)
{
void TestHeadNodeStructure(CefRefPtr<CefDOMNode> headNode) {
EXPECT_TRUE(headNode.get());
EXPECT_TRUE(headNode->IsElement());
EXPECT_FALSE(headNode->IsText());
@@ -26,7 +23,7 @@ public:
EXPECT_TRUE(headNode->HasChildren());
EXPECT_FALSE(headNode->HasElementAttributes());
CefRefPtr<CefDOMNode> titleNode = headNode->GetFirstChild();
EXPECT_TRUE(titleNode.get());
EXPECT_TRUE(titleNode->IsElement());
@@ -51,9 +48,8 @@ public:
EXPECT_FALSE(textNode->GetPreviousSibling().get());
EXPECT_FALSE(textNode->HasChildren());
}
void TestBodyNodeStructure(CefRefPtr<CefDOMNode> bodyNode)
{
void TestBodyNodeStructure(CefRefPtr<CefDOMNode> bodyNode) {
EXPECT_TRUE(bodyNode.get());
EXPECT_TRUE(bodyNode->IsElement());
EXPECT_FALSE(bodyNode->IsText());
@@ -113,7 +109,7 @@ public:
EXPECT_FALSE(brNode->IsText());
EXPECT_EQ(brNode->GetName(), "BR");
EXPECT_EQ(brNode->GetElementTagName(), "BR");
textNode = brNode->GetNextSibling();
EXPECT_TRUE(textNode.get());
EXPECT_FALSE(textNode->IsElement());
@@ -125,8 +121,7 @@ public:
}
// Test document structure by iterating through the DOM tree.
void TestStructure(CefRefPtr<CefDOMDocument> document)
{
void TestStructure(CefRefPtr<CefDOMDocument> document) {
EXPECT_EQ(document->GetTitle(), "The Title");
EXPECT_EQ(document->GetBaseURL(), "http://tests/main.html");
EXPECT_EQ(document->GetCompleteURL("foo.html"), "http://tests/foo.html");
@@ -152,7 +147,7 @@ public:
CefRefPtr<CefDOMNode> bodyNode = headNode->GetNextSibling();
TestBodyNodeStructure(bodyNode);
// Retrieve the head node directly.
headNode = document->GetHead();
TestHeadNodeStructure(headNode);
@@ -163,14 +158,14 @@ public:
}
// Test document modification by changing the H1 tag.
void TestModify(CefRefPtr<CefDOMDocument> document)
{
void TestModify(CefRefPtr<CefDOMDocument> document) {
CefRefPtr<CefDOMNode> bodyNode = document->GetBody();
CefRefPtr<CefDOMNode> h1Node = bodyNode->GetFirstChild();
ASSERT_EQ(h1Node->GetAsMarkup(),
"<h1>Hello From<br class=\"some_class\" id=\"some_id\">Main Frame</h1>");
"<h1>Hello From<br class=\"some_class\" id=\"some_id\">"
"Main Frame</h1>");
CefRefPtr<CefDOMNode> textNode = h1Node->GetFirstChild();
ASSERT_EQ(textNode->GetValue(), "Hello From");
ASSERT_TRUE(textNode->SetValue("A Different Message From"));
@@ -182,13 +177,13 @@ public:
EXPECT_EQ(brNode->GetElementAttribute("class"), "a_different_class");
ASSERT_EQ(h1Node->GetAsMarkup(),
"<h1>A Different Message From<br class=\"a_different_class\" id=\"some_id\">Main Frame</h1>");
"<h1>A Different Message From<br class=\"a_different_class\" "
"id=\"some_id\">Main Frame</h1>");
ASSERT_FALSE(h1Node->SetValue("Something Different"));
}
virtual void Visit(CefRefPtr<CefDOMDocument> document)
{
virtual void Visit(CefRefPtr<CefDOMDocument> document) {
handler_->got_visitor_called_.yes();
if (handler_->test_type_ == STRUCTURE)
@@ -199,7 +194,7 @@ public:
handler_->DestroyTest();
}
protected:
protected:
TestDOMHandler* handler_;
IMPLEMENT_REFCOUNTING(Visitor);
@@ -210,31 +205,29 @@ public:
MODIFY,
};
TestDOMHandler(TestType test) : test_type_(test)
{
explicit TestDOMHandler(TestType test) : test_type_(test) {
visitor_ = new Visitor(this);
}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
std::stringstream mainHtml;
mainHtml <<
"<html>"
"<head><title>The Title</title></head>"
"<body>"
"<h1>Hello From<br class=\"some_class\"/ id=\"some_id\"/>Main Frame</h1>"
"</body>"
"</html>";
"<html>"
"<head><title>The Title</title></head>"
"<body>"
"<h1>Hello From<br class=\"some_class\"/ id=\"some_id\"/>"
"Main Frame</h1>"
"</body>"
"</html>";
AddResource("http://tests/main.html", mainHtml.str(), "text/html");
CreateBrowser("http://tests/main.html");
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
if(frame->IsMain()) {
int httpStatusCode) OVERRIDE {
if (frame->IsMain()) {
// The page is done loading so visit the DOM.
browser->GetMainFrame()->VisitDOM(visitor_.get());
}
@@ -246,11 +239,10 @@ public:
TrackCallback got_visitor_called_;
};
} // namespace
} // namespace
// Test DOM structure reading.
TEST(DOMTest, Read)
{
TEST(DOMTest, Read) {
CefRefPtr<TestDOMHandler> handler =
new TestDOMHandler(TestDOMHandler::STRUCTURE);
handler->ExecuteTest();
@@ -259,8 +251,7 @@ TEST(DOMTest, Read)
}
// Test DOM modifications.
TEST(DOMTest, Modify)
{
TEST(DOMTest, Modify) {
CefRefPtr<TestDOMHandler> handler =
new TestDOMHandler(TestDOMHandler::MODIFY);
handler->ExecuteTest();

View File

@@ -3,8 +3,8 @@
// can be found in the LICENSE file.
#include "include/cef_scheme.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
namespace {
@@ -41,13 +41,11 @@ static NavListItem kNavList[] = {
#define NAV_LIST_SIZE() (sizeof(kNavList) / sizeof(NavListItem))
class HistoryNavTestHandler : public TestHandler
{
public:
class HistoryNavTestHandler : public TestHandler {
public:
HistoryNavTestHandler() : nav_(0) {}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
// Add the resources that we will navigate to/from.
AddResource(kNav1, "<html>Nav1</html>", "text/html");
AddResource(kNav2, "<html>Nav2</html>", "text/html");
@@ -57,8 +55,7 @@ public:
CreateBrowser(CefString());
}
void RunNav(CefRefPtr<CefBrowser> browser)
{
void RunNav(CefRefPtr<CefBrowser> browser) {
if (nav_ == NAV_LIST_SIZE()) {
// End of the nav list.
DestroyTest();
@@ -89,8 +86,7 @@ public:
}
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
{
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
TestHandler::OnAfterCreated(browser);
RunNav(browser);
@@ -100,8 +96,7 @@ public:
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType,
bool isRedirect) OVERRIDE
{
bool isRedirect) OVERRIDE {
const NavListItem& item = kNavList[nav_];
got_before_browse_[nav_].yes();
@@ -121,8 +116,7 @@ public:
virtual void OnNavStateChange(CefRefPtr<CefBrowser> browser,
bool canGoBack,
bool canGoForward) OVERRIDE
{
bool canGoForward) OVERRIDE {
const NavListItem& item = kNavList[nav_];
got_nav_state_change_[nav_].yes();
@@ -135,9 +129,8 @@ public:
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
if(browser->IsPopup() || !frame->IsMain())
int httpStatusCode) OVERRIDE {
if (browser->IsPopup() || !frame->IsMain())
return;
const NavListItem& item = kNavList[nav_];
@@ -166,11 +159,10 @@ public:
TrackCallback got_correct_can_go_forward2_[NAV_LIST_SIZE()];
};
} // namespace
} // namespace
// Verify history navigation.
TEST(NavigationTest, History)
{
TEST(NavigationTest, History) {
CefRefPtr<HistoryNavTestHandler> handler =
new HistoryNavTestHandler();
handler->ExecuteTest();
@@ -205,13 +197,11 @@ TEST(NavigationTest, History)
namespace {
class FrameNameIdentNavTestHandler : public TestHandler
{
public:
class FrameNameIdentNavTestHandler : public TestHandler {
public:
FrameNameIdentNavTestHandler() : browse_ct_(0) {}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
// Add the frame resources.
std::stringstream ss;
@@ -235,8 +225,7 @@ public:
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType,
bool isRedirect) OVERRIDE
{
bool isRedirect) OVERRIDE {
std::string url = request->GetURL();
std::string name = frame->GetName();
CefRefPtr<CefFrame> parent = frame->GetParent();
@@ -266,8 +255,7 @@ public:
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
int httpStatusCode) OVERRIDE {
std::string url = frame->GetURL();
CefRefPtr<CefFrame> parent = frame->GetParent();
@@ -294,9 +282,9 @@ public:
int browse_ct_;
long long frame1_ident_;
long long frame2_ident_;
long long frame3_ident_;
int64 frame1_ident_;
int64 frame2_ident_;
int64 frame3_ident_;
TrackCallback got_frame1_name_;
TrackCallback got_frame2_name_;
@@ -312,11 +300,10 @@ public:
TrackCallback got_frame3_ident_parent_after_;
};
} // namespace
} // namespace
// Verify frame names and identifiers.
TEST(NavigationTest, FrameNameIdent)
{
TEST(NavigationTest, FrameNameIdent) {
CefRefPtr<FrameNameIdentNavTestHandler> handler =
new FrameNameIdentNavTestHandler();
handler->ExecuteTest();
@@ -346,15 +333,13 @@ bool g_got_nav3_request = false;
bool g_got_nav4_request = false;
bool g_got_invalid_request = false;
class RedirectSchemeHandler : public CefSchemeHandler
{
public:
class RedirectSchemeHandler : public CefSchemeHandler {
public:
RedirectSchemeHandler() : offset_(0), status_(0) {}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefSchemeHandlerCallback> callback)
OVERRIDE
{
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
std::string url = request->GetURL();
@@ -387,11 +372,10 @@ public:
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE
{
CefString& redirectUrl) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_TRUE(status_ != 0);
EXPECT_NE(status_, 0);
response->SetStatus(status_);
response->SetMimeType("text/html");
@@ -399,7 +383,7 @@ public:
if (status_ == 302) {
// Redirect using HTTP 302
EXPECT_TRUE(location_.size() > 0);
EXPECT_GT(location_.size(), static_cast<size_t>(0));
response->SetStatusText("Found");
CefResponse::HeaderMap headers;
response->GetHeaderMap(headers);
@@ -407,13 +391,12 @@ public:
response->SetHeaderMap(headers);
} else if (status_ == -1) {
// Rdirect using redirectUrl
EXPECT_TRUE(location_.size() > 0);
EXPECT_GT(location_.size(), static_cast<size_t>(0));
redirectUrl = location_;
}
}
virtual void Cancel() OVERRIDE
{
virtual void Cancel() OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
}
@@ -421,12 +404,11 @@ public:
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefSchemeHandlerCallback> callback)
OVERRIDE
{
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
size_t size = content_.size();
if(offset_ < size) {
if (offset_ < size) {
int transfer_size =
std::min(bytes_to_read, static_cast<int>(size - offset_));
memcpy(data_out, content_.c_str() + offset_, transfer_size);
@@ -439,7 +421,7 @@ public:
return false;
}
protected:
protected:
std::string content_;
size_t offset_;
int status_;
@@ -448,16 +430,14 @@ protected:
IMPLEMENT_REFCOUNTING(RedirectSchemeHandler);
};
class RedirectSchemeHandlerFactory : public CefSchemeHandlerFactory
{
public:
class RedirectSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
RedirectSchemeHandlerFactory() {}
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
const CefString& scheme_name,
CefRefPtr<CefRequest> request)
OVERRIDE
{
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
return new RedirectSchemeHandler();
}
@@ -465,13 +445,11 @@ public:
IMPLEMENT_REFCOUNTING(RedirectSchemeHandlerFactory);
};
class RedirectTestHandler : public TestHandler
{
public:
class RedirectTestHandler : public TestHandler {
public:
RedirectTestHandler() {}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
// Create the browser.
CreateBrowser(kNav1);
}
@@ -480,8 +458,7 @@ public:
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType,
bool isRedirect) OVERRIDE
{
bool isRedirect) OVERRIDE {
// Should be called for each URL that is actually loaded.
std::string url = request->GetURL();
@@ -503,8 +480,7 @@ public:
CefString& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
CefRefPtr<CefResponse> response,
int loadFlags) OVERRIDE
{
int loadFlags) OVERRIDE {
// Should only be called for the first URL.
std::string url = request->GetURL();
@@ -519,8 +495,7 @@ public:
virtual void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
const CefString& old_url,
CefString& new_url) OVERRIDE
{
CefString& new_url) OVERRIDE {
// Should be called for each redirected URL.
if (old_url == kNav1 && new_url == kNav2) {
@@ -541,12 +516,11 @@ public:
}
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) OVERRIDE
{
CefRefPtr<CefFrame> frame) OVERRIDE {
// Should only be called for the final loaded URL.
std::string url = frame->GetURL();
if(url == kNav4) {
if (url == kNav4) {
got_nav4_load_start_.yes();
} else {
got_invalid_load_start_.yes();
@@ -555,12 +529,11 @@ public:
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
int httpStatusCode) OVERRIDE {
// Should only be called for the final loaded URL.
std::string url = frame->GetURL();
if(url == kNav4) {
if (url == kNav4) {
got_nav4_load_end_.yes();
DestroyTest();
} else {
@@ -584,15 +557,14 @@ public:
TrackCallback got_invalid_redirect_;
};
} // namespace
} // namespace
// Verify frame names and identifiers.
TEST(NavigationTest, Redirect)
{
TEST(NavigationTest, Redirect) {
CefRegisterSchemeHandlerFactory("http", "tests",
new RedirectSchemeHandlerFactory());
WaitForIOThread();
CefRefPtr<RedirectTestHandler> handler =
new RedirectTestHandler();
handler->ExecuteTest();

View File

@@ -3,8 +3,8 @@
// can be found in the LICENSE file.
#include "include/cef_request.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
// Verify that CefRequest::HeaderMap objects are equal
@@ -12,13 +12,12 @@
// |map2|.
static void VerifyMapEqual(CefRequest::HeaderMap &map1,
CefRequest::HeaderMap &map2,
bool allowExtras)
{
if(!allowExtras)
bool allowExtras) {
if (!allowExtras)
ASSERT_EQ(map1.size(), map2.size());
CefRequest::HeaderMap::const_iterator it1, it2;
for(it1 = map1.begin(); it1 != map1.end(); ++it1) {
for (it1 = map1.begin(); it1 != map1.end(); ++it1) {
it2 = map2.find(it1->first);
ASSERT_TRUE(it2 != map2.end());
ASSERT_EQ(it1->second, it2->second);
@@ -27,16 +26,14 @@ static void VerifyMapEqual(CefRequest::HeaderMap &map1,
// Verify that CefPostDataElement objects are equal
static void VerifyPostDataElementEqual(CefRefPtr<CefPostDataElement> elem1,
CefRefPtr<CefPostDataElement> elem2)
{
CefRefPtr<CefPostDataElement> elem2) {
ASSERT_EQ(elem1->GetType(), elem2->GetType());
switch(elem1->GetType()) {
switch (elem1->GetType()) {
case PDE_TYPE_BYTES: {
ASSERT_EQ(elem1->GetBytesCount(), elem2->GetBytesCount());
char *buff1, *buff2;
size_t bytesCt = elem1->GetBytesCount();
buff1 = new char[bytesCt];
buff2 = new char[bytesCt];
char* buff1 = new char[bytesCt];
char* buff2 = new char[bytesCt];
elem1->GetBytes(bytesCt, buff1);
elem2->GetBytes(bytesCt, buff2);
ASSERT_TRUE(!memcmp(buff1, buff2, bytesCt));
@@ -53,11 +50,10 @@ static void VerifyPostDataElementEqual(CefRefPtr<CefPostDataElement> elem1,
// Verify that CefPostData objects are equal
static void VerifyPostDataEqual(CefRefPtr<CefPostData> postData1,
CefRefPtr<CefPostData> postData2)
{
CefRefPtr<CefPostData> postData2) {
ASSERT_TRUE(!(postData1.get()) == !(postData2.get()));
ASSERT_EQ(postData1->GetElementCount(), postData2->GetElementCount());
CefPostData::ElementVector ev1, ev2;
postData1->GetElements(ev1);
postData1->GetElements(ev2);
@@ -65,7 +61,7 @@ static void VerifyPostDataEqual(CefRefPtr<CefPostData> postData1,
CefPostData::ElementVector::const_iterator it1 = ev1.begin();
CefPostData::ElementVector::const_iterator it2 = ev2.begin();
for(; it1 != ev1.end() && it2 != ev2.end(); ++it1, ++it2)
for (; it1 != ev1.end() && it2 != ev2.end(); ++it1, ++it2)
VerifyPostDataElementEqual((*it1), (*it2));
}
@@ -74,11 +70,10 @@ static void VerifyPostDataEqual(CefRefPtr<CefPostData> postData1,
// |request2|.
static void VerifyRequestEqual(CefRefPtr<CefRequest> request1,
CefRefPtr<CefRequest> request2,
bool allowExtras)
{
bool allowExtras) {
ASSERT_EQ(request1->GetURL(), request2->GetURL());
ASSERT_EQ(request1->GetMethod(), request2->GetMethod());
CefRequest::HeaderMap headers1, headers2;
request1->GetHeaderMap(headers1);
request2->GetHeaderMap(headers2);
@@ -88,8 +83,7 @@ static void VerifyRequestEqual(CefRefPtr<CefRequest> request1,
}
// Verify Set/Get methods for CefRequest, CefPostData and CefPostDataElement.
TEST(RequestTest, SetGet)
{
TEST(RequestTest, SetGet) {
// CefRequest CreateRequest
CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
ASSERT_TRUE(request.get() != NULL);
@@ -111,7 +105,7 @@ TEST(RequestTest, SetGet)
CefRefPtr<CefPostDataElement> element2(
CefPostDataElement::CreatePostDataElement());
ASSERT_TRUE(element2.get() != NULL);
// CefPostDataElement SetToFile
CefString file = "c:\\path\\to\\file.ext";
element1->SetToFile(file);
@@ -146,13 +140,13 @@ TEST(RequestTest, SetGet)
CefPostData::ElementVector elements;
postData->GetElements(elements);
CefPostData::ElementVector::const_iterator it = elements.begin();
for(size_t i = 0; it != elements.end(); ++it, ++i) {
if(i == 0)
for (size_t i = 0; it != elements.end(); ++it, ++i) {
if (i == 0)
VerifyPostDataElementEqual(element1, (*it).get());
else if(i == 1)
else if (i == 1)
VerifyPostDataElementEqual(element2, (*it).get());
}
// CefRequest SetURL
request->SetURL(url);
ASSERT_EQ(url, request->GetURL());
@@ -184,8 +178,7 @@ TEST(RequestTest, SetGet)
VerifyPostDataEqual(postData, request->GetPostData());
}
static void CreateRequest(CefRefPtr<CefRequest>& request)
{
static void CreateRequest(CefRefPtr<CefRequest>& request) {
request = CefRequest::CreateRequest();
ASSERT_TRUE(request.get() != NULL);
@@ -205,27 +198,25 @@ static void CreateRequest(CefRefPtr<CefRequest>& request)
ASSERT_TRUE(element1.get() != NULL);
element1->SetToFile("c:\\path\\to\\file.ext");
postData->AddElement(element1);
CefRefPtr<CefPostDataElement> element2(
CefPostDataElement::CreatePostDataElement());
ASSERT_TRUE(element2.get() != NULL);
char bytes[] = "Test Bytes";
element2->SetToBytes(sizeof(bytes), bytes);
postData->AddElement(element2);
request->SetPostData(postData);
}
bool g_RequestSendRecvTestHandlerHandleBeforeBrowseCalled;
bool g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled;
class RequestSendRecvTestHandler : public TestHandler
{
public:
class RequestSendRecvTestHandler : public TestHandler {
public:
RequestSendRecvTestHandler() {}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
// Create the test request
CreateRequest(request_);
@@ -233,8 +224,7 @@ public:
CreateBrowser(CefString());
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
{
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
TestHandler::OnAfterCreated(browser);
// Load the test request
@@ -245,13 +235,12 @@ public:
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType,
bool isRedirect) OVERRIDE
{
bool isRedirect) OVERRIDE {
g_RequestSendRecvTestHandlerHandleBeforeBrowseCalled = true;
// Verify that the request is the same
VerifyRequestEqual(request_, request, true);
return false;
}
@@ -260,10 +249,9 @@ public:
CefString& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
CefRefPtr<CefResponse> response,
int loadFlags) OVERRIDE
{
int loadFlags) OVERRIDE {
g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled = true;
// Verify that the request is the same
VerifyRequestEqual(request_, request, true);
@@ -277,8 +265,7 @@ public:
};
// Verify send and recieve
TEST(RequestTest, SendRecv)
{
TEST(RequestTest, SendRecv) {
g_RequestSendRecvTestHandlerHandleBeforeBrowseCalled = false;
g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled = false;

View File

@@ -2,9 +2,9 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "test_suite.h"
#include "include/cef_app.h"
#include "include/cef_task.h"
#include "tests/unittests/test_suite.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/threading/thread.h"
@@ -13,11 +13,10 @@ namespace {
// Thread used to run the test suite.
class CefTestThread : public base::Thread {
public:
CefTestThread(CefTestSuite* test_suite)
public:
explicit CefTestThread(CefTestSuite* test_suite)
: base::Thread("test_thread"),
test_suite_(test_suite)
{
test_suite_(test_suite) {
}
void RunTests() {
@@ -25,9 +24,8 @@ public:
retval_ = test_suite_->Run();
// Quit the CEF message loop.
class QuitTask : public CefTask
{
public:
class QuitTask : public CefTask {
public:
QuitTask() {}
virtual void Execute(CefThreadId threadId) { CefQuitMessageLoop(); }
IMPLEMENT_REFCOUNTING(QuitTask);
@@ -37,12 +35,12 @@ public:
int retval() { return retval_; }
protected:
protected:
CefTestSuite* test_suite_;
int retval_;
};
} // namespace
} // namespace
int main(int argc, char** argv) {
@@ -51,7 +49,7 @@ int main(int argc, char** argv) {
CefSettings settings;
CefTestSuite::GetSettings(settings);
#if defined(OS_MACOSX)
// Platform-specific initialization.
extern void PlatformInit();
@@ -92,7 +90,7 @@ int main(int argc, char** argv) {
// Shut down CEF.
CefShutdown();
#if defined(OS_MACOSX)
// Platform-specific cleanup.
extern void PlatformCleanup();

View File

@@ -5,22 +5,19 @@
#include "include/cef_origin_whitelist.h"
#include "include/cef_runnable.h"
#include "include/cef_scheme.h"
#include "test_handler.h"
#include "tests/unittests/test_handler.h"
namespace {
class TestResults
{
public:
class TestResults {
public:
TestResults()
: status_code(0),
sub_status_code(0),
delay(0)
{
: status_code(0),
sub_status_code(0),
delay(0) {
}
void reset()
{
void reset() {
url.clear();
html.clear();
status_code = 0;
@@ -58,15 +55,15 @@ public:
// Delay for returning scheme handler results.
int delay;
TrackCallback
got_request,
got_read,
got_output,
got_redirect,
got_error,
got_sub_request,
got_sub_read,
got_sub_success;
TrackCallback
got_request,
got_read,
got_output,
got_redirect,
got_error,
got_sub_request,
got_sub_read,
got_sub_success;
};
// Current scheme handler object. Used when destroying the test from
@@ -74,24 +71,20 @@ public:
class TestSchemeHandler;
TestSchemeHandler* g_current_handler = NULL;
class TestSchemeHandler : public TestHandler
{
public:
TestSchemeHandler(TestResults* tr)
: test_results_(tr)
{
class TestSchemeHandler : public TestHandler {
public:
explicit TestSchemeHandler(TestResults* tr)
: test_results_(tr) {
g_current_handler = this;
}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
CreateBrowser(test_results_->url);
}
// Necessary to make the method public in order to destroy the test from
// ClientSchemeHandler::ProcessRequest().
void DestroyTest()
{
void DestroyTest() {
TestHandler::DestroyTest();
}
@@ -99,8 +92,7 @@ public:
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType,
bool isRedirect) OVERRIDE
{
bool isRedirect) OVERRIDE {
std::string newUrl = request->GetURL();
if (!test_results_->exit_url.empty() &&
newUrl.find(test_results_->exit_url) != std::string::npos) {
@@ -110,7 +102,7 @@ public:
DestroyTest();
return true;
}
if (isRedirect) {
test_results_->got_redirect.yes();
EXPECT_EQ(newUrl, test_results_->redirect_url);
@@ -123,14 +115,13 @@ public:
test_results_->url = test_results_->redirect_url;
test_results_->redirect_url.clear();
}
return false;
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
int httpStatusCode) OVERRIDE {
std::string url = frame->GetURL();
if (url == test_results_->url || test_results_->status_code != 200) {
if (test_results_->sub_url.empty()) {
@@ -154,27 +145,28 @@ public:
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& failedUrl,
CefString& errorText) OVERRIDE
{
CefString& errorText) OVERRIDE {
test_results_->got_error.yes();
DestroyTest();
return false;
}
protected:
protected:
TestResults* test_results_;
};
class ClientSchemeHandler : public CefSchemeHandler
{
public:
ClientSchemeHandler(TestResults* tr)
: test_results_(tr), offset_(0), is_sub_(false), has_delayed_(false) {}
class ClientSchemeHandler : public CefSchemeHandler {
public:
explicit ClientSchemeHandler(TestResults* tr)
: test_results_(tr),
offset_(0),
is_sub_(false),
has_delayed_(false) {
}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefSchemeHandlerCallback> callback)
OVERRIDE
{
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
bool handled = false;
@@ -185,14 +177,14 @@ public:
if (is_sub_) {
test_results_->got_sub_request.yes();
if (!test_results_->sub_html.empty())
handled = true;
} else {
} else {
EXPECT_EQ(url, test_results_->url);
test_results_->got_request.yes();
if (!test_results_->html.empty())
handled = true;
}
@@ -217,8 +209,7 @@ public:
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE
{
CefString& redirectUrl) OVERRIDE {
if (is_sub_) {
response->SetStatus(test_results_->sub_status_code);
@@ -230,7 +221,7 @@ public:
test_results_->sub_allow_origin));
response->SetHeaderMap(headers);
}
if (!test_results_->sub_html.empty()) {
response->SetMimeType("text/html");
response_length = test_results_->sub_html.size();
@@ -247,8 +238,7 @@ public:
}
}
virtual void Cancel() OVERRIDE
{
virtual void Cancel() OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
}
@@ -256,8 +246,7 @@ public:
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefSchemeHandlerCallback> callback)
OVERRIDE
{
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (test_results_->delay > 0) {
@@ -290,7 +279,7 @@ public:
AutoLock lock_scope(this);
size_t size = data->size();
if(offset_ < size) {
if (offset_ < size) {
int transfer_size =
std::min(bytes_to_read, static_cast<int>(size - offset_));
memcpy(data_out, data->c_str() + offset_, transfer_size);
@@ -303,9 +292,8 @@ public:
return has_data;
}
private:
void ContinueAfterDelay(CefRefPtr<CefSchemeHandlerCallback> callback)
{
private:
void ContinueAfterDelay(CefRefPtr<CefSchemeHandlerCallback> callback) {
has_delayed_ = true;
callback->BytesAvailable();
}
@@ -319,17 +307,16 @@ private:
IMPLEMENT_LOCKING(ClientSchemeHandler);
};
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory
{
public:
ClientSchemeHandlerFactory(TestResults* tr)
: test_results_(tr){}
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
explicit ClientSchemeHandlerFactory(TestResults* tr)
: test_results_(tr) {
}
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
const CefString& scheme_name,
CefRefPtr<CefRequest> request)
OVERRIDE
{
OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
return new ClientSchemeHandler(test_results_);
}
@@ -343,8 +330,7 @@ public:
TestResults g_TestResults;
// If |domain| is empty the scheme will be registered as non-standard.
void RegisterTestScheme(const std::string& scheme, const std::string& domain)
{
void RegisterTestScheme(const std::string& scheme, const std::string& domain) {
g_TestResults.reset();
static std::set<std::string> schemes;
@@ -366,15 +352,13 @@ void RegisterTestScheme(const std::string& scheme, const std::string& domain)
WaitForIOThread();
}
void ClearTestSchemes()
{
void ClearTestSchemes() {
EXPECT_TRUE(CefClearSchemeHandlerFactories());
WaitForIOThread();
}
void SetUpXHR(const std::string& url, const std::string& sub_url,
const std::string& sub_allow_origin = std::string())
{
const std::string& sub_allow_origin = std::string()) {
g_TestResults.sub_url = sub_url;
g_TestResults.sub_html = "SUCCESS";
g_TestResults.sub_status_code = 200;
@@ -382,22 +366,22 @@ void SetUpXHR(const std::string& url, const std::string& sub_url,
g_TestResults.url = url;
std::stringstream ss;
ss << "<html><head>\
<script language=\"JavaScript\">\
function execXMLHttpRequest() {\
var result = 'FAILURE';\
try {\
xhr = new XMLHttpRequest();\
xhr.open(\"GET\", \"" << sub_url.c_str() << "\", false);\
xhr.send();\
result = xhr.responseText;\
} catch(e) {}\
document.location = \"http://tests/exit?result=\"+result;\
}\
</script>\
</head><body onload=\"execXMLHttpRequest();\">\
Running execXMLHttpRequest...\
</body></html>";
ss << "<html><head>"
"<script language=\"JavaScript\">"
"function execXMLHttpRequest() {"
" var result = 'FAILURE';"
" try {"
" xhr = new XMLHttpRequest();"
" xhr.open(\"GET\", \"" << sub_url.c_str() << "\", false);"
" xhr.send();"
" result = xhr.responseText;"
" } catch(e) {}"
" document.location = \"http://tests/exit?result=\"+result;"
"}"
"</script>"
"</head><body onload=\"execXMLHttpRequest();\">"
"Running execXMLHttpRequest..."
"</body></html>";
g_TestResults.html = ss.str();
g_TestResults.status_code = 200;
@@ -405,63 +389,61 @@ void SetUpXHR(const std::string& url, const std::string& sub_url,
}
void SetUpXSS(const std::string& url, const std::string& sub_url,
const std::string& domain = std::string())
{
const std::string& domain = std::string()) {
// 1. Load |url| which contains an iframe.
// 2. The iframe loads |xss_url|.
// 3. |xss_url| tries to call a JS function in |url|.
// 4. |url| tries to call a JS function in |xss_url|.
std::stringstream ss;
std::string domain_line;
if (!domain.empty())
domain_line = "document.domain = '" + domain + "';";
g_TestResults.sub_url = sub_url;
ss << "<html><head>\
<script language=\"JavaScript\">" << domain_line << "\
function getResult() {\
return 'SUCCESS';\
}\
function execXSSRequest() {\
var result = 'FAILURE';\
try {\
result = parent.getResult();\
} catch(e) {}\
document.location = \"http://tests/exit?result=\"+result;\
}\
</script>\
</head><body onload=\"execXSSRequest();\">\
Running execXSSRequest...\
</body></html>";
ss << "<html><head>"
"<script language=\"JavaScript\">" << domain_line <<
"function getResult() {"
" return 'SUCCESS';"
"}"
"function execXSSRequest() {"
" var result = 'FAILURE';"
" try {"
" result = parent.getResult();"
" } catch(e) {}"
" document.location = \"http://tests/exit?result=\"+result;"
"}"
"</script>"
"</head><body onload=\"execXSSRequest();\">"
"Running execXSSRequest..."
"</body></html>";
g_TestResults.sub_html = ss.str();
g_TestResults.sub_status_code = 200;
g_TestResults.url = url;
ss.str("");
ss << "<html><head>\
<script language=\"JavaScript\">" << domain_line << "\
function getResult() {\
try {\
return document.getElementById('s').contentWindow.getResult();\
} catch(e) {}\
return 'FAILURE';\
}\
</script>\
</head><body>\
<iframe src=\"" << sub_url.c_str() << "\" id=\"s\">\
</body></html>";
ss << "<html><head>"
"<script language=\"JavaScript\">" << domain_line << ""
"function getResult() {"
" try {"
" return document.getElementById('s').contentWindow.getResult();"
" } catch(e) {}"
" return 'FAILURE';"
"}"
"</script>"
"</head><body>"
"<iframe src=\"" << sub_url.c_str() << "\" id=\"s\">"
"</body></html>";
g_TestResults.html = ss.str();
g_TestResults.status_code = 200;
g_TestResults.exit_url = "http://tests/exit";
}
} // anonymous
} // namespace
// Test that scheme registration/unregistration works as expected.
TEST(SchemeHandlerTest, Registration)
{
TEST(SchemeHandlerTest, Registration) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://test/run.html";
g_TestResults.html =
@@ -505,8 +487,7 @@ TEST(SchemeHandlerTest, Registration)
}
// Test that a custom standard scheme can return normal results.
TEST(SchemeHandlerTest, CustomStandardNormalResponse)
{
TEST(SchemeHandlerTest, CustomStandardNormalResponse) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://test/run.html";
g_TestResults.html =
@@ -525,8 +506,7 @@ TEST(SchemeHandlerTest, CustomStandardNormalResponse)
// Test that a custom standard scheme can return normal results with delayed
// responses.
TEST(SchemeHandlerTest, CustomStandardNormalResponseDelayed)
{
TEST(SchemeHandlerTest, CustomStandardNormalResponseDelayed) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://test/run.html";
g_TestResults.html =
@@ -545,8 +525,7 @@ TEST(SchemeHandlerTest, CustomStandardNormalResponseDelayed)
}
// Test that a custom nonstandard scheme can return normal results.
TEST(SchemeHandlerTest, CustomNonStandardNormalResponse)
{
TEST(SchemeHandlerTest, CustomNonStandardNormalResponse) {
RegisterTestScheme("customnonstd", std::string());
g_TestResults.url = "customnonstd:some%20value";
g_TestResults.html =
@@ -564,14 +543,13 @@ TEST(SchemeHandlerTest, CustomNonStandardNormalResponse)
}
// Test that a custom standard scheme can return an error code.
TEST(SchemeHandlerTest, CustomStandardErrorResponse)
{
TEST(SchemeHandlerTest, CustomStandardErrorResponse) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://test/run.html";
g_TestResults.html =
"<html><head></head><body><h1>404</h1></body></html>";
g_TestResults.status_code = 404;
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -583,14 +561,13 @@ TEST(SchemeHandlerTest, CustomStandardErrorResponse)
}
// Test that a custom nonstandard scheme can return an error code.
TEST(SchemeHandlerTest, CustomNonStandardErrorResponse)
{
TEST(SchemeHandlerTest, CustomNonStandardErrorResponse) {
RegisterTestScheme("customnonstd", std::string());
g_TestResults.url = "customnonstd:some%20value";
g_TestResults.html =
"<html><head></head><body><h1>404</h1></body></html>";
g_TestResults.status_code = 404;
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -603,11 +580,10 @@ TEST(SchemeHandlerTest, CustomNonStandardErrorResponse)
// Test that custom standard scheme handling fails when the scheme name is
// incorrect.
TEST(SchemeHandlerTest, CustomStandardNameNotHandled)
{
TEST(SchemeHandlerTest, CustomStandardNameNotHandled) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd2://test/run.html";
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -620,11 +596,10 @@ TEST(SchemeHandlerTest, CustomStandardNameNotHandled)
// Test that custom nonstandard scheme handling fails when the scheme name is
// incorrect.
TEST(SchemeHandlerTest, CustomNonStandardNameNotHandled)
{
TEST(SchemeHandlerTest, CustomNonStandardNameNotHandled) {
RegisterTestScheme("customnonstd", std::string());
g_TestResults.url = "customnonstd2:some%20value";
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -637,11 +612,10 @@ TEST(SchemeHandlerTest, CustomNonStandardNameNotHandled)
// Test that custom standard scheme handling fails when the domain name is
// incorrect.
TEST(SchemeHandlerTest, CustomStandardDomainNotHandled)
{
TEST(SchemeHandlerTest, CustomStandardDomainNotHandled) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://noexist/run.html";
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -653,11 +627,10 @@ TEST(SchemeHandlerTest, CustomStandardDomainNotHandled)
}
// Test that a custom standard scheme can return no response.
TEST(SchemeHandlerTest, CustomStandardNoResponse)
{
TEST(SchemeHandlerTest, CustomStandardNoResponse) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://test/run.html";
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -669,11 +642,10 @@ TEST(SchemeHandlerTest, CustomStandardNoResponse)
}
// Test that a custom nonstandard scheme can return no response.
TEST(SchemeHandlerTest, CustomNonStandardNoResponse)
{
TEST(SchemeHandlerTest, CustomNonStandardNoResponse) {
RegisterTestScheme("customnonstd", std::string());
g_TestResults.url = "customnonstd:some%20value";
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -685,14 +657,13 @@ TEST(SchemeHandlerTest, CustomNonStandardNoResponse)
}
// Test that a custom standard scheme can generate redirects.
TEST(SchemeHandlerTest, CustomStandardRedirect)
{
TEST(SchemeHandlerTest, CustomStandardRedirect) {
RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://test/run.html";
g_TestResults.redirect_url = "customstd://test/redirect.html";
g_TestResults.html =
"<html><head></head><body><h1>Redirected</h1></body></html>";
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -705,14 +676,13 @@ TEST(SchemeHandlerTest, CustomStandardRedirect)
}
// Test that a custom nonstandard scheme can generate redirects.
TEST(SchemeHandlerTest, CustomNonStandardRedirect)
{
TEST(SchemeHandlerTest, CustomNonStandardRedirect) {
RegisterTestScheme("customnonstd", std::string());
g_TestResults.url = "customnonstd:some%20value";
g_TestResults.redirect_url = "customnonstd:some%20other%20value";
g_TestResults.html =
"<html><head></head><body><h1>Redirected</h1></body></html>";
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -725,12 +695,11 @@ TEST(SchemeHandlerTest, CustomNonStandardRedirect)
}
// Test that a custom standard scheme can generate same origin XHR requests.
TEST(SchemeHandlerTest, CustomStandardXHRSameOrigin)
{
TEST(SchemeHandlerTest, CustomStandardXHRSameOrigin) {
RegisterTestScheme("customstd", "test");
SetUpXHR("customstd://test/run.html",
"customstd://test/xhr.html");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -745,12 +714,11 @@ TEST(SchemeHandlerTest, CustomStandardXHRSameOrigin)
}
// Test that a custom nonstandard scheme can generate same origin XHR requests.
TEST(SchemeHandlerTest, CustomNonStandardXHRSameOrigin)
{
TEST(SchemeHandlerTest, CustomNonStandardXHRSameOrigin) {
RegisterTestScheme("customnonstd", std::string());
SetUpXHR("customnonstd:some%20value",
"customnonstd:xhr%20value");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -764,12 +732,11 @@ TEST(SchemeHandlerTest, CustomNonStandardXHRSameOrigin)
ClearTestSchemes();
}
// Test that a custom standard scheme can generate same origin XSS requests.
TEST(SchemeHandlerTest, CustomStandardXSSSameOrigin)
{
TEST(SchemeHandlerTest, CustomStandardXSSSameOrigin) {
RegisterTestScheme("customstd", "test");
SetUpXSS("customstd://test/run.html",
"customstd://test/iframe.html");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -784,12 +751,11 @@ TEST(SchemeHandlerTest, CustomStandardXSSSameOrigin)
}
// Test that a custom nonstandard scheme can generate same origin XSS requests.
TEST(SchemeHandlerTest, CustomNonStandardXSSSameOrigin)
{
TEST(SchemeHandlerTest, CustomNonStandardXSSSameOrigin) {
RegisterTestScheme("customnonstd", std::string());
SetUpXSS("customnonstd:some%20value",
"customnonstd:xhr%20value");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -805,13 +771,12 @@ TEST(SchemeHandlerTest, CustomNonStandardXSSSameOrigin)
// Test that a custom standard scheme cannot generate cross-domain XHR requests
// by default.
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOrigin)
{
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOrigin) {
RegisterTestScheme("customstd", "test1");
RegisterTestScheme("customstd", "test2");
SetUpXHR("customstd://test1/run.html",
"customstd://test2/xhr.html");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -827,13 +792,12 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOrigin)
// Test that a custom standard scheme cannot generate cross-domain XSS requests
// by default.
TEST(SchemeHandlerTest, CustomStandardXSSDifferentOrigin)
{
TEST(SchemeHandlerTest, CustomStandardXSSDifferentOrigin) {
RegisterTestScheme("customstd", "test1");
RegisterTestScheme("customstd", "test2");
SetUpXSS("customstd://test1/run.html",
"customstd://test2/iframe.html");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -849,13 +813,12 @@ TEST(SchemeHandlerTest, CustomStandardXSSDifferentOrigin)
// Test that an HTTP scheme cannot generate cross-domain XHR requests by
// default.
TEST(SchemeHandlerTest, HttpXHRDifferentOrigin)
{
TEST(SchemeHandlerTest, HttpXHRDifferentOrigin) {
RegisterTestScheme("http", "test1");
RegisterTestScheme("http", "test2");
SetUpXHR("http://test1/run.html",
"http://test2/xhr.html");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -871,13 +834,12 @@ TEST(SchemeHandlerTest, HttpXHRDifferentOrigin)
// Test that an HTTP scheme cannot generate cross-domain XSS requests by
// default.
TEST(SchemeHandlerTest, HttpXSSDifferentOrigin)
{
TEST(SchemeHandlerTest, HttpXSSDifferentOrigin) {
RegisterTestScheme("http", "test1");
RegisterTestScheme("http", "test2");
SetUpXHR("http://test1/run.html",
"http://test2/xhr.html");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -893,14 +855,13 @@ TEST(SchemeHandlerTest, HttpXSSDifferentOrigin)
// Test that a custom standard scheme cannot generate cross-domain XHR requests
// even when setting the Access-Control-Allow-Origin header.
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithHeader)
{
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithHeader) {
RegisterTestScheme("customstd", "test1");
RegisterTestScheme("customstd", "test2");
SetUpXHR("customstd://test1/run.html",
"customstd://test2/xhr.html",
"customstd://test1");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -916,8 +877,7 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithHeader)
// Test that a custom standard scheme can generate cross-domain XHR requests
// when using the cross-origin whitelist.
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelist)
{
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelist) {
RegisterTestScheme("customstd", "test1");
RegisterTestScheme("customstd", "test2");
SetUpXHR("customstd://test1/run.html",
@@ -926,7 +886,7 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelist)
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
"test2", false));
WaitForUIThread();
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -945,14 +905,13 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelist)
// Test that an HTTP scheme can generate cross-domain XHR requests when setting
// the Access-Control-Allow-Origin header.
TEST(SchemeHandlerTest, HttpXHRDifferentOriginWithHeader)
{
TEST(SchemeHandlerTest, HttpXHRDifferentOriginWithHeader) {
RegisterTestScheme("http", "test1");
RegisterTestScheme("http", "test2");
SetUpXHR("http://test1/run.html",
"http://test2/xhr.html",
"http://test1");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -968,14 +927,13 @@ TEST(SchemeHandlerTest, HttpXHRDifferentOriginWithHeader)
// Test that a custom standard scheme can generate cross-domain XSS requests
// when using document.domain.
TEST(SchemeHandlerTest, CustomStandardXSSDifferentOriginWithDomain)
{
TEST(SchemeHandlerTest, CustomStandardXSSDifferentOriginWithDomain) {
RegisterTestScheme("customstd", "a.test");
RegisterTestScheme("customstd", "b.test");
SetUpXSS("customstd://a.test/run.html",
"customstd://b.test/iframe.html",
"test");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();
@@ -991,14 +949,13 @@ TEST(SchemeHandlerTest, CustomStandardXSSDifferentOriginWithDomain)
// Test that an HTTP scheme can generate cross-domain XSS requests when using
// document.domain.
TEST(SchemeHandlerTest, HttpXSSDifferentOriginWithDomain)
{
TEST(SchemeHandlerTest, HttpXSSDifferentOriginWithDomain) {
RegisterTestScheme("http", "a.test");
RegisterTestScheme("http", "b.test");
SetUpXSS("http://a.test/run.html",
"http://b.test/iframe.html",
"test");
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest();

View File

@@ -4,10 +4,10 @@
#include "include/cef_storage.h"
#include "include/cef_v8.h"
#include "tests/unittests/test_handler.h"
#include "tests/unittests/test_suite.h"
#include "base/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
#include "test_suite.h"
namespace {
@@ -20,21 +20,18 @@ static const char* kVal1 = "bar";
static const char* kKey2 = "choo";
static const char* kVal2 = "whatzit";
class StorageTestHandler : public TestHandler
{
public:
class V8Handler : public CefV8Handler
{
class StorageTestHandler : public TestHandler {
public:
class V8Handler : public CefV8Handler {
public:
V8Handler(CefRefPtr<StorageTestHandler> tester)
explicit V8Handler(CefRefPtr<StorageTestHandler> tester)
: tester_(tester) {}
virtual bool Execute(const CefString& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception) OVERRIDE
{
CefString& exception) OVERRIDE {
if (arguments.size() != 2)
return false;
@@ -54,9 +51,8 @@ public:
IMPLEMENT_REFCOUNTING(V8Handler);
};
class StorageVisitor : public CefStorageVisitor
{
public:
class StorageVisitor : public CefStorageVisitor {
public:
enum Mode {
VisitKey,
DeleteKey1,
@@ -69,18 +65,15 @@ public:
int expected_total)
: tester_(tester), description_(description), mode_(mode),
callback1_(callback1), callback2_(callback2),
expected_total_(expected_total), actual_total_(0)
{
expected_total_(expected_total), actual_total_(0) {
}
virtual ~StorageVisitor()
{
virtual ~StorageVisitor() {
EXPECT_EQ(expected_total_, actual_total_) << "test = "<< description_;
}
virtual bool Visit(CefStorageType type, const CefString& origin,
const CefString& key, const CefString& value, int count,
int total, bool& deleteData) OVERRIDE
{
int total, bool& deleteData) OVERRIDE {
EXPECT_EQ(type, tester_->type_);
std::string originStr = origin;
EXPECT_EQ(originStr, kOrigin);
@@ -89,13 +82,13 @@ public:
std::string valueStr = value;
if (keyStr == kKey1 && valueStr == kVal1)
callback1_->yes();
else if(keyStr == kKey2 && valueStr == kVal2)
else if (keyStr == kKey2 && valueStr == kVal2)
callback2_->yes();
EXPECT_EQ(expected_total_, total) << "test = "<< description_;
if((mode_ == DeleteKey1 && keyStr == kKey1) ||
(mode_ == DeleteKey2 && keyStr == kKey2))
if ((mode_ == DeleteKey1 && keyStr == kKey1) ||
(mode_ == DeleteKey2 && keyStr == kKey2))
deleteData = true;
actual_total_++;
@@ -120,8 +113,7 @@ public:
leave_keys_set_(leaveKeysSet),
nav_(0) {}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
// Verify the key status.
CefVisitStorage(type_, kOrigin, "",
new StorageVisitor(this, "startupvisit",
@@ -132,7 +124,8 @@ public:
std::stringstream ss;
std::string func = (type_==ST_LOCALSTORAGE?"localStorage":"sessionStorage");
std::string func =
(type_ == ST_LOCALSTORAGE?"localStorage":"sessionStorage");
// Values will be set vis JS on page load.
ss << "<html><head><script language=\"JavaScript\">" <<
@@ -160,8 +153,7 @@ public:
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
int httpStatusCode) OVERRIDE {
if (nav_ == 0) {
// Verify read all.
CefVisitStorage(type_, "", "",
@@ -239,7 +231,7 @@ public:
StorageVisitor::VisitKey,
&got_cpp_afterdeleteall_fail_,
&got_cpp_afterdeleteall_fail_, 0));
// Reset all values.
CefSetStorage(type_, kOrigin, kKey1, kVal1);
CefSetStorage(type_, kOrigin, kKey2, kVal2);
@@ -326,8 +318,7 @@ public:
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) OVERRIDE
{
CefRefPtr<CefV8Context> context) OVERRIDE {
// Retrieve the 'window' object.
CefRefPtr<CefV8Value> object = context->GetGlobal();
@@ -377,8 +368,7 @@ public:
TrackCallback got_cpp_shutdownvisit_fail_;
};
void StorageTest(CefStorageType type, bool expectKeysSet, bool leaveKeysSet)
{
void StorageTest(CefStorageType type, bool expectKeysSet, bool leaveKeysSet) {
CefRefPtr<StorageTestHandler> handler =
new StorageTestHandler(type, expectKeysSet, leaveKeysSet);
handler->ExecuteTest();
@@ -425,23 +415,20 @@ void StorageTest(CefStorageType type, bool expectKeysSet, bool leaveKeysSet)
EXPECT_FALSE(handler->got_cpp_shutdownvisit_fail_);
}
} // namespace
} // namespace
// Test localStorage.
TEST(StorageTest, Local)
{
TEST(StorageTest, Local) {
StorageTest(ST_LOCALSTORAGE, false, false);
}
// Test sessionStorage.
TEST(StorageTest, Session)
{
TEST(StorageTest, Session) {
StorageTest(ST_SESSIONSTORAGE, false, false);
}
// Test changing the localStorage directory.
TEST(StorageTest, LocalChangeDirectory)
{
TEST(StorageTest, LocalChangeDirectory) {
std::string cache_path;
CefTestSuite::GetCachePath(cache_path);

View File

@@ -6,8 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h"
static void VerifyStreamReadBehavior(CefRefPtr<CefStreamReader> stream,
const std::string& contents)
{
const std::string& contents) {
int contentSize = static_cast<int>(contents.size());
const char* contentStr = contents.c_str();
@@ -27,12 +26,12 @@ static void VerifyStreamReadBehavior(CefRefPtr<CefStreamReader> stream,
char buff[10];
int res, read, offset = 0;
do {
read = std::min((int)sizeof(buff), contentSize-offset);
read = std::min(static_cast<int>(sizeof(buff)), contentSize-offset);
res = stream->Read(buff, 1, read);
ASSERT_EQ(read, res);
ASSERT_TRUE(!memcmp(contentStr+offset, buff, res));
offset += res;
} while(offset < contentSize);
} while (offset < contentSize);
// Read past the end of the file
stream->Read(buff, 1, 1);
@@ -40,8 +39,7 @@ static void VerifyStreamReadBehavior(CefRefPtr<CefStreamReader> stream,
}
static void VerifyStreamWriteBehavior(CefRefPtr<CefStreamWriter> stream,
const std::string& contents)
{
const std::string& contents) {
int contentSize = static_cast<int>(contents.size());
const char* contentStr = contents.c_str();
@@ -53,7 +51,7 @@ static void VerifyStreamWriteBehavior(CefRefPtr<CefStreamWriter> stream,
ASSERT_EQ(write, res);
offset += res;
ASSERT_EQ(offset, stream->Tell());
} while(offset < contentSize);
} while (offset < contentSize);
// Move to the beginning of the stream
ASSERT_EQ(0, stream->Seek(-contentSize, SEEK_CUR));
@@ -68,12 +66,11 @@ static void VerifyStreamWriteBehavior(CefRefPtr<CefStreamWriter> stream,
ASSERT_EQ(0, stream->Tell());
}
TEST(StreamTest, ReadFile)
{
TEST(StreamTest, ReadFile) {
const char* fileName = "StreamTest.VerifyReadFile.txt";
CefString fileNameStr = "StreamTest.VerifyReadFile.txt";
std::string contents = "This is my test\ncontents for the file";
// Create the file
FILE* f = NULL;
#ifdef _WIN32
@@ -102,19 +99,19 @@ TEST(StreamTest, ReadFile)
#endif
}
TEST(StreamTest, ReadData)
{
TEST(StreamTest, ReadData) {
std::string contents = "This is my test\ncontents for the file";
// Test the stream
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData((void*)contents.c_str(), contents.size()));
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(contents.c_str())),
contents.size()));
ASSERT_TRUE(stream.get() != NULL);
VerifyStreamReadBehavior(stream, contents);
}
TEST(StreamTest, WriteFile)
{
TEST(StreamTest, WriteFile) {
const char* fileName = "StreamTest.VerifyWriteFile.txt";
CefString fileNameStr = "StreamTest.VerifyWriteFile.txt";
std::string contents = "This is my test\ncontents for the file";
@@ -158,45 +155,44 @@ TEST(StreamTest, WriteFile)
bool g_ReadHandlerTesterDeleted = false;
class ReadHandlerTester : public CefReadHandler
{
public:
class ReadHandlerTester : public CefReadHandler {
public:
ReadHandlerTester()
: read_called_(false), read_ptr_(NULL), read_size_(0), read_n_(0),
seek_called_(false), seek_offset_(0), seek_whence_(0),
tell_called_(false), eof_called_(false)
{
: read_called_(false),
read_ptr_(NULL),
read_size_(0),
read_n_(0),
seek_called_(false),
seek_offset_(0),
seek_whence_(0),
tell_called_(false),
eof_called_(false) {
}
virtual ~ReadHandlerTester()
{
virtual ~ReadHandlerTester() {
g_ReadHandlerTesterDeleted = true;
}
virtual size_t Read(void* ptr, size_t size, size_t n)
{
virtual size_t Read(void* ptr, size_t size, size_t n) {
read_called_ = true;
read_ptr_ = ptr;
read_size_ = size;
read_n_ = n;
return 10;
}
virtual int Seek(long offset, int whence)
{
virtual int Seek(int64 offset, int whence) {
seek_called_ = true;
seek_offset_ = offset;
seek_whence_ = whence;
return 10;
}
virtual long Tell()
{
virtual int64 Tell() {
tell_called_ = true;
return 10;
}
virtual int Eof()
{
virtual int Eof() {
eof_called_ = true;
return 10;
}
@@ -207,21 +203,20 @@ public:
size_t read_n_;
bool seek_called_;
long seek_offset_;
int64 seek_offset_;
int seek_whence_;
bool tell_called_;
bool eof_called_;
IMPLEMENT_REFCOUNTING(ReadHandlerTester);
};
TEST(StreamTest, ReadHandler)
{
TEST(StreamTest, ReadHandler) {
ReadHandlerTester* handler = new ReadHandlerTester();
ASSERT_TRUE(handler != NULL);
CefRefPtr<CefStreamReader> stream(CefStreamReader::CreateForHandler(handler));
ASSERT_TRUE(stream.get() != NULL);
@@ -229,7 +224,8 @@ TEST(StreamTest, ReadHandler)
const char* read_ptr = "My data";
size_t read_size = sizeof(read_ptr);
size_t read_n = 1;
size_t read_res = stream->Read((void*)read_ptr, read_size, read_n);
size_t read_res = stream->Read(
static_cast<void*>(const_cast<char*>(read_ptr)), read_size, read_n);
ASSERT_TRUE(handler->read_called_);
ASSERT_EQ((size_t)10, read_res);
ASSERT_EQ(read_ptr, handler->read_ptr_);
@@ -237,7 +233,7 @@ TEST(StreamTest, ReadHandler)
ASSERT_EQ(read_n, handler->read_n_);
// CefReadHandler Seek
long seek_offset = 10;
int64 seek_offset = 10;
int seek_whence = SEEK_CUR;
int seek_res = stream->Seek(seek_offset, seek_whence);
ASSERT_TRUE(handler->seek_called_);
@@ -246,10 +242,10 @@ TEST(StreamTest, ReadHandler)
ASSERT_EQ(seek_whence, handler->seek_whence_);
// CefReadHandler Tell
long tell_res = stream->Tell();
int64 tell_res = stream->Tell();
ASSERT_TRUE(handler->tell_called_);
ASSERT_EQ(10, tell_res);
// CefReadHandler Eof
int eof_res = stream->Eof();
ASSERT_TRUE(handler->eof_called_);
@@ -264,22 +260,24 @@ TEST(StreamTest, ReadHandler)
bool g_WriteHandlerTesterDeleted = false;
class WriteHandlerTester : public CefWriteHandler
{
public:
class WriteHandlerTester : public CefWriteHandler {
public:
WriteHandlerTester()
: write_called_(false), write_ptr_(NULL), write_size_(0), write_n_(0),
seek_called_(false), seek_offset_(0), seek_whence_(0),
tell_called_(false), flush_called_(false)
{
: write_called_(false),
write_ptr_(NULL),
write_size_(0),
write_n_(0),
seek_called_(false),
seek_offset_(0),
seek_whence_(0),
tell_called_(false),
flush_called_(false) {
}
virtual ~WriteHandlerTester()
{
virtual ~WriteHandlerTester() {
g_WriteHandlerTesterDeleted = true;
}
virtual size_t Write(const void* ptr, size_t size, size_t n)
{
virtual size_t Write(const void* ptr, size_t size, size_t n) {
write_called_ = true;
write_ptr_ = ptr;
write_size_ = size;
@@ -287,22 +285,19 @@ public:
return 10;
}
virtual int Seek(long offset, int whence)
{
virtual int Seek(int64 offset, int whence) {
seek_called_ = true;
seek_offset_ = offset;
seek_whence_ = whence;
return 10;
}
virtual long Tell()
{
virtual int64 Tell() {
tell_called_ = true;
return 10;
}
virtual int Flush()
{
virtual int Flush() {
flush_called_ = true;
return 10;
}
@@ -313,21 +308,20 @@ public:
size_t write_n_;
bool seek_called_;
long seek_offset_;
int64 seek_offset_;
int seek_whence_;
bool tell_called_;
bool flush_called_;
IMPLEMENT_REFCOUNTING(WriteHandlerTester);
};
TEST(StreamTest, WriteHandler)
{
TEST(StreamTest, WriteHandler) {
WriteHandlerTester* handler = new WriteHandlerTester();
ASSERT_TRUE(handler != NULL);
CefRefPtr<CefStreamWriter> stream(CefStreamWriter::CreateForHandler(handler));
ASSERT_TRUE(stream.get() != NULL);
@@ -343,7 +337,7 @@ TEST(StreamTest, WriteHandler)
ASSERT_EQ(write_n, handler->write_n_);
// CefWriteHandler Seek
long seek_offset = 10;
int64 seek_offset = 10;
int seek_whence = SEEK_CUR;
int seek_res = stream->Seek(seek_offset, seek_whence);
ASSERT_TRUE(handler->seek_called_);
@@ -352,10 +346,10 @@ TEST(StreamTest, WriteHandler)
ASSERT_EQ(seek_whence, handler->seek_whence_);
// CefWriteHandler Tell
long tell_res = stream->Tell();
int64 tell_res = stream->Tell();
ASSERT_TRUE(handler->tell_called_);
ASSERT_EQ(10, tell_res);
// CefWriteHandler Flush
int flush_res = stream->Flush();
ASSERT_TRUE(handler->flush_called_);

View File

@@ -2,17 +2,16 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include <map>
#include <vector>
#include "include/internal/cef_string.h"
#include "include/internal/cef_string_list.h"
#include "include/internal/cef_string_map.h"
#include "include/internal/cef_string_multimap.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <map>
#include <vector>
// Test UTF8 strings.
TEST(StringTest, UTF8)
{
TEST(StringTest, UTF8) {
CefStringUTF8 str1("Test String");
ASSERT_EQ(str1.length(), (size_t)11);
ASSERT_FALSE(str1.empty());
@@ -50,8 +49,7 @@ TEST(StringTest, UTF8)
}
// Test UTF16 strings.
TEST(StringTest, UTF16)
{
TEST(StringTest, UTF16) {
CefStringUTF16 str1("Test String");
ASSERT_EQ(str1.length(), (size_t)11);
ASSERT_FALSE(str1.empty());
@@ -89,8 +87,7 @@ TEST(StringTest, UTF16)
}
// Test wide strings.
TEST(StringTest, Wide)
{
TEST(StringTest, Wide) {
CefStringWide str1("Test String");
ASSERT_EQ(str1.length(), (size_t)11);
ASSERT_FALSE(str1.empty());
@@ -128,8 +125,7 @@ TEST(StringTest, Wide)
}
// Test string lists.
TEST(StringTest, List)
{
TEST(StringTest, List) {
typedef std::vector<CefString> ListType;
ListType list;
list.push_back("String 1");
@@ -143,14 +139,14 @@ TEST(StringTest, List)
cef_string_list_t listPtr = cef_string_list_alloc();
ASSERT_TRUE(listPtr != NULL);
ListType::const_iterator it = list.begin();
for(; it != list.end(); ++it)
for (; it != list.end(); ++it)
cef_string_list_append(listPtr, it->GetStruct());
CefString str;
int ret;
ASSERT_EQ(cef_string_list_size(listPtr), 3);
ret = cef_string_list_value(listPtr, 0, str.GetWritableStruct());
ASSERT_TRUE(ret);
ASSERT_EQ(str, "String 1");
@@ -182,16 +178,15 @@ TEST(StringTest, List)
}
// Test string maps.
TEST(StringTest, Map)
{
typedef std::map<CefString,CefString> MapType;
TEST(StringTest, Map) {
typedef std::map<CefString, CefString> MapType;
MapType map;
map.insert(std::make_pair("Key 1", "String 1"));
map.insert(std::make_pair("Key 2", "String 2"));
map.insert(std::make_pair("Key 3", "String 3"));
MapType::const_iterator it;
it = map.find("Key 2");
ASSERT_TRUE(it != map.end());
ASSERT_EQ(it->first, "Key 2");
@@ -207,9 +202,9 @@ TEST(StringTest, Map)
ASSERT_EQ(map["Key 3"], "String 3");
cef_string_map_t mapPtr = cef_string_map_alloc();
it = map.begin();
for(; it != map.end(); ++it) {
for (; it != map.end(); ++it) {
cef_string_map_append(mapPtr, it->first.GetStruct(),
it->second.GetStruct());
}
@@ -218,7 +213,7 @@ TEST(StringTest, Map)
int ret;
ASSERT_EQ(cef_string_map_size(mapPtr), 3);
ret = cef_string_map_key(mapPtr, 0, str.GetWritableStruct());
ASSERT_TRUE(ret);
ASSERT_EQ(str, "Key 1");
@@ -253,9 +248,8 @@ TEST(StringTest, Map)
}
// Test string maps.
TEST(StringTest, Multimap)
{
typedef std::multimap<CefString,CefString> MapType;
TEST(StringTest, Multimap) {
typedef std::multimap<CefString, CefString> MapType;
MapType map;
map.insert(std::make_pair("Key 1", "String 1"));
map.insert(std::make_pair("Key 2", "String 2"));
@@ -286,7 +280,7 @@ TEST(StringTest, Multimap)
cef_string_multimap_t mapPtr = cef_string_multimap_alloc();
it = map.begin();
for(; it != map.end(); ++it) {
for (; it != map.end(); ++it) {
cef_string_multimap_append(mapPtr, it->first.GetStruct(),
it->second.GetStruct());
}

View File

@@ -2,47 +2,40 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "test_handler.h"
#include "tests/unittests/test_handler.h"
#include "include/cef_runnable.h"
namespace {
void NotifyEvent(base::WaitableEvent* event)
{
void NotifyEvent(base::WaitableEvent* event) {
event->Signal();
}
} // namespace
} // namespace
// TestHandler
TestHandler::TestHandler()
: browser_hwnd_(NULL),
completion_event_(true, false)
{
completion_event_(true, false) {
}
TestHandler::~TestHandler()
{
TestHandler::~TestHandler() {
}
void TestHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
void TestHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
AutoLock lock_scope(this);
if(!browser->IsPopup())
{
if (!browser->IsPopup()) {
// Keep the main child window, but not popup windows
browser_ = browser;
browser_hwnd_ = browser->GetWindowHandle();
}
}
void TestHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
void TestHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
AutoLock lock_scope(this);
if(browser_hwnd_ == browser->GetWindowHandle())
{
if (browser_hwnd_ == browser->GetWindowHandle()) {
// Free the browser pointer so that the browser can be destroyed
browser_ = NULL;
browser_hwnd_ = NULL;
@@ -57,16 +50,16 @@ bool TestHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefString& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
CefRefPtr<CefResponse> response,
int loadFlags)
{
int loadFlags) {
AutoLock lock_scope(this);
if(resource_map_.size() > 0) {
if (resource_map_.size() > 0) {
CefString url = request->GetURL();
ResourceMap::const_iterator it = resource_map_.find(url);
if(it != resource_map_.end()) {
if (it != resource_map_.end()) {
// Return the previously mapped resource
resourceStream = CefStreamReader::CreateForData(
(void*)it->second.first.c_str(), it->second.first.length());
static_cast<void*>(const_cast<char*>(it->second.first.c_str())),
it->second.first.length());
response->SetMimeType(it->second.second);
response->SetStatus(200);
}
@@ -75,8 +68,7 @@ bool TestHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
return false;
}
void TestHandler::ExecuteTest()
{
void TestHandler::ExecuteTest() {
// Run the test
RunTest();
@@ -87,15 +79,13 @@ void TestHandler::ExecuteTest()
completion_event_.Reset();
}
void TestHandler::DestroyTest()
{
void TestHandler::DestroyTest() {
AutoLock lock_scope(this);
if(browser_hwnd_ != NULL)
if (browser_hwnd_ != NULL)
browser_->CloseBrowser();
}
void TestHandler::CreateBrowser(const CefString& url)
{
void TestHandler::CreateBrowser(const CefString& url) {
CefWindowInfo windowInfo;
CefBrowserSettings settings;
#if defined(OS_WIN)
@@ -106,21 +96,18 @@ void TestHandler::CreateBrowser(const CefString& url)
}
void TestHandler::AddResource(const CefString& key, const std::string& value,
const CefString& mimeType)
{
const CefString& mimeType) {
resource_map_.insert(std::make_pair(key, std::make_pair(value, mimeType)));
}
void TestHandler::ClearResources()
{
void TestHandler::ClearResources() {
resource_map_.clear();
}
// global functions
void WaitForThread(CefThreadId thread_id)
{
void WaitForThread(CefThreadId thread_id) {
base::WaitableEvent event(true, false);
CefPostTask(thread_id, NewCefRunnableFunction(&NotifyEvent, &event));
event.Wait();

View File

@@ -2,8 +2,13 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _TEST_HANDLER_H
#define _TEST_HANDLER_H
#ifndef CEF_TESTS_UNITTESTS_TEST_HANDLER_H_
#define CEF_TESTS_UNITTESTS_TEST_HANDLER_H_
#pragma once
#include <map>
#include <string>
#include <utility>
#include "include/cef_browser.h"
#include "include/cef_client.h"
@@ -12,15 +17,14 @@
#include "base/synchronization/waitable_event.h"
#include "testing/gtest/include/gtest/gtest.h"
class TrackCallback
{
public:
class TrackCallback {
public:
TrackCallback(): gotit_(false) {}
void yes() { gotit_ = true; }
bool isSet() { return gotit_; }
void reset() { gotit_ = false; }
operator bool() const { return gotit_; }
protected:
protected:
bool gotit_;
};
@@ -32,9 +36,8 @@ class TestHandler : public CefClient,
public CefLoadHandler,
public CefRequestHandler,
public CefV8ContextHandler,
public CefPermissionHandler
{
public:
public CefPermissionHandler {
public:
TestHandler();
virtual ~TestHandler();
@@ -42,18 +45,24 @@ public:
virtual void RunTest() =0;
// CefClient methods. Add new methods as needed by test cases.
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE
{ return this; }
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE {
return this;
}
// CefLifeSpanHandler methods
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
@@ -75,7 +84,7 @@ public:
// returns.
void ExecuteTest();
protected:
protected:
// Destroy the browser window. Once the window is destroyed test completion
// will be signaled.
void DestroyTest();
@@ -86,7 +95,7 @@ protected:
const CefString& mimeType);
void ClearResources();
private:
private:
// The child browser window
CefRefPtr<CefBrowser> browser_;
@@ -114,4 +123,4 @@ void WaitForThread(CefThreadId thread_id);
#define WaitForIOThread() WaitForThread(TID_IO)
#define WaitForUIThread() WaitForThread(TID_UI)
#endif // _TEST_HANDLER_H
#endif // CEF_TESTS_UNITTESTS_TEST_HANDLER_H_

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.
#include "test_suite.h"
#include "../cefclient/cefclient_switches.h"
#include "tests/unittests/test_suite.h"
#include "tests/cefclient/cefclient_switches.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/test/test_suite.h"
@@ -23,8 +23,7 @@ CefTestSuite::CefTestSuite(int argc, char** argv)
}
// static
void CefTestSuite::InitCommandLine(int argc, const char* const* argv)
{
void CefTestSuite::InitCommandLine(int argc, const char* const* argv) {
if (commandline_) {
// If this is intentional, Reset() must be called first. If we are using
// the shared build mode, we have to share a single object across multiple
@@ -130,7 +129,7 @@ bool CefTestSuite::GetCachePath(std::string& path) {
void CefTestSuite::Initialize() {
// The below code is copied from base/test/test_suite.cc to avoid calling
// RegisterMockCrApp() on Mac.
// Initialize logging.
FilePath exe;
PathService::Get(base::FILE_EXE, &exe);
@@ -144,9 +143,9 @@ void CefTestSuite::Initialize() {
// We want process and thread IDs because we may have multiple processes.
// Note: temporarily enabled timestamps in an effort to catch bug 6361.
logging::SetLogItems(true, true, true, true);
CHECK(base::EnableInProcessStackDumping());
// In some cases, we do not want to see standard error dialogs.
if (!base::debug::BeingDebugged() &&
!CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) {
@@ -154,12 +153,12 @@ void CefTestSuite::Initialize() {
base::debug::SetSuppressDebugUI(true);
logging::SetLogAssertHandler(UnitTestAssertHandler);
}
icu_util::Initialize();
CatchMaybeTests();
ResetCommandLine();
TestTimeouts::Initialize();
}
#endif // defined(OS_MACOSX)
#endif // defined(OS_MACOSX)

View File

@@ -2,16 +2,18 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEF_TEST_SUITE_H
#define _CEF_TEST_SUITE_H
#ifndef CEF_TESTS_UNITTESTS_TEST_SUITE_H_
#define CEF_TESTS_UNITTESTS_TEST_SUITE_H_
#pragma once
#include <string>
#include "include/internal/cef_types_wrappers.h"
#include "base/test/test_suite.h"
class CommandLine;
class CefTestSuite : public TestSuite {
public:
public:
CefTestSuite(int argc, char** argv);
// Initialize the current process CommandLine singleton. On Windows, ignores
@@ -23,13 +25,13 @@ public:
static void GetSettings(CefSettings& settings);
static bool GetCachePath(std::string& path);
protected:
protected:
#if defined(OS_MACOSX)
virtual void Initialize();
#endif
// The singleton CommandLine representing the current process's command line.
static CommandLine* commandline_;
};
#endif // _CEF_TEST_SUITE_H
#endif // CEF_TESTS_UNITTESTS_TEST_SUITE_H_

View File

@@ -5,8 +5,7 @@
#include "include/cef_url.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(URLTest, CreateURL)
{
TEST(URLTest, CreateURL) {
// Create the URL using the spec.
{
CefURLParts parts;
@@ -82,8 +81,7 @@ TEST(URLTest, CreateURL)
}
}
TEST(URLTest, ParseURL)
{
TEST(URLTest, ParseURL) {
// Parse the URL using scheme and host.
{
CefURLParts parts;

File diff suppressed because it is too large Load Diff

View File

@@ -3,16 +3,17 @@
// can be found in the LICENSE file.
#include "include/cef_web_urlrequest.h"
#include "test_handler.h"
#include "tests/unittests/test_handler.h"
//#define WEB_URLREQUEST_DEBUG
// #define WEB_URLREQUEST_DEBUG
class TestResults
{
public:
class TestResults {
public:
TestResults()
: errorCode(0), contentLength(0), statusCode(0), redirectCount(0)
{
: errorCode(0),
contentLength(0),
statusCode(0),
redirectCount(0) {
}
int errorCode;
@@ -25,29 +26,29 @@ public:
int redirectCount;
TrackCallback
TrackCallback
got_redirect,
got_deleted,
got_started,
got_headers,
got_loading,
got_started,
got_headers,
got_loading,
got_done,
got_progress,
got_progress,
got_abort,
got_error;
};
class BrowserTestHandler : public TestHandler
{
public:
// Cancel at state WUR_STATE_UNSENT means that no cancellation
class BrowserTestHandler : public TestHandler {
public:
// Cancel at state WUR_STATE_UNSENT means that no cancellation
// will occur since that state change is never fired.
BrowserTestHandler(TestResults &tr,
cef_weburlrequest_state_t cancelAtState = WUR_STATE_UNSENT):
cancelAtState_(cancelAtState), test_results_(tr) { }
BrowserTestHandler(TestResults &tr,
cef_weburlrequest_state_t cancelAtState = WUR_STATE_UNSENT)
: cancelAtState_(cancelAtState),
test_results_(tr) {
}
virtual void RunTest() OVERRIDE
{
virtual void RunTest() OVERRIDE {
std::stringstream testHtml;
testHtml <<
"<html><body>"
@@ -60,16 +61,14 @@ public:
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode)
{
int httpStatusCode) {
StartTest();
}
void TestCompleted()
{
void TestCompleted() {
DestroyTest();
}
virtual void StartTest() = 0;
cef_weburlrequest_state_t cancelAtState_;
@@ -77,22 +76,20 @@ public:
TestResults& test_results_;
};
class TestWebURLRequestClient : public CefWebURLRequestClient
{
public:
TestWebURLRequestClient(TestResults& tr, BrowserTestHandler* browser):
test_results_(tr), cancelAtState_(WUR_STATE_UNSENT), browser_(browser)
{
class TestWebURLRequestClient : public CefWebURLRequestClient {
public:
TestWebURLRequestClient(TestResults& tr, BrowserTestHandler* browser)
: test_results_(tr),
cancelAtState_(WUR_STATE_UNSENT),
browser_(browser) {
}
virtual ~TestWebURLRequestClient()
{
virtual ~TestWebURLRequestClient() {
test_results_.got_deleted.yes();
}
bool MaybeCancelRequest(CefRefPtr<CefWebURLRequest> requester,
RequestState state)
{
bool MaybeCancelRequest(CefRefPtr<CefWebURLRequest> requester,
RequestState state) {
if (cancelAtState_ == state) {
#ifdef WEB_URLREQUEST_DEBUG
printf(" Cancelling at state %d\n", cancelAtState_);
@@ -103,14 +100,13 @@ public:
return false;
}
void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
RequestState state)
{
void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
RequestState state) {
#ifdef WEB_URLREQUEST_DEBUG
printf("OnStateChange(0x%p, %d)\n", requester.get(), state);
#endif
if (MaybeCancelRequest(requester, state))
if (MaybeCancelRequest(requester, state))
return;
switch (state) {
@@ -143,12 +139,11 @@ public:
}
}
void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response)
{
void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response) {
#ifdef WEB_URLREQUEST_DEBUG
printf("OnRedirect(0x%p, 0x%p, 0x%p)\n",
printf("OnRedirect(0x%p, 0x%p, 0x%p)\n",
requester.get(), request.get(), response.get());
#endif
test_results_.got_redirect.yes();
@@ -160,42 +155,38 @@ public:
#endif
}
void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefResponse> response)
{
void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
CefRefPtr<CefResponse> response) {
#ifdef WEB_URLREQUEST_DEBUG
printf("OnHeadersReceived(0x%p, 0x%p)\n", requester.get(), response.get());
#endif
test_results_.statusCode = response->GetStatus();
test_results_.statusText = response->GetStatusText();
test_results_.contentLengthHeader = response->GetHeader( "Content-Length" );
test_results_.contentLengthHeader = response->GetHeader("Content-Length");
response->GetHeaderMap(test_results_.headerMap);
}
void OnData(CefRefPtr<CefWebURLRequest> requester, const void *data,
int dataLength)
{
void OnData(CefRefPtr<CefWebURLRequest> requester, const void *data,
int dataLength) {
#ifdef WEB_URLREQUEST_DEBUG
printf("OnData(0x%p, 0x%p, %d)\n", requester.get(), data, dataLength);
#endif
// Add data to buffer, create if not already
contents_.append( (const char *) data, dataLength);
contents_.append(static_cast<const char*>(data), dataLength);
}
void TestCompleted()
{
void TestCompleted() {
browser_->TestCompleted();
browser_ = NULL;
requester_ = NULL;
Release();
}
void OnProgress(CefRefPtr<CefWebURLRequest> requester,
uint64 bytesSent,
uint64 totalBytesToBeSent)
{
void OnProgress(CefRefPtr<CefWebURLRequest> requester,
uint64 bytesSent,
uint64 totalBytesToBeSent) {
#ifdef WEB_URLREQUEST_DEBUG
printf("OnProgress(0x%p, %d, %d)\n", requester.get(),
(unsigned int)bytesSent, (unsigned int)totalBytesToBeSent);
@@ -203,9 +194,8 @@ public:
test_results_.got_progress.yes();
}
void OnError(CefRefPtr<CefWebURLRequest> requester,
CefWebURLRequestClient::ErrorCode errorCode)
{
void OnError(CefRefPtr<CefWebURLRequest> requester,
CefWebURLRequestClient::ErrorCode errorCode) {
#ifdef WEB_URLREQUEST_DEBUG
printf("Error(0x%p, %d)\n", requester.get(), errorCode);
#endif
@@ -214,9 +204,8 @@ public:
TestCompleted();
}
bool Run(CefRefPtr<CefRequest> req, RequestState
cancelAtState=WUR_STATE_UNSENT)
{
bool Run(CefRefPtr<CefRequest> req, RequestState
cancelAtState = WUR_STATE_UNSENT) {
if ( requester_.get() )
return false;
@@ -226,7 +215,7 @@ public:
// Keep ourselves alive... blanced in TestCompleted() when done.
AddRef();
requester_ = CefWebURLRequest::CreateWebURLRequest(request_, this);
requester_ = CefWebURLRequest::CreateWebURLRequest(request_, this);
#ifdef WEB_URLREQUEST_DEBUG
printf("Created requester at address 0x%p\n", requester_.get());
#endif
@@ -234,8 +223,8 @@ public:
return requester_.get() != NULL;
}
protected:
TestResults &test_results_;
protected:
TestResults& test_results_;
RequestState cancelAtState_;
CefRefPtr<BrowserTestHandler> browser_;
@@ -246,33 +235,30 @@ protected:
IMPLEMENT_REFCOUNTING(TestWebURLRequestClient);
};
TEST(WebURLRequestTest, GET)
{
class BrowserForTest : public BrowserTestHandler
{
public:
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
TEST(WebURLRequestTest, GET) {
class BrowserForTest : public BrowserTestHandler {
public:
explicit BrowserForTest(TestResults &tr) : BrowserTestHandler(tr) { }
void StartTest()
{
void StartTest() {
CefRefPtr<CefRequest> req;
CefRefPtr<CefPostData> postdata;
CefRequest::HeaderMap headers;
req = CefRequest::CreateRequest();
CefString url(
"http://search.twitter.com/search.json?result_type=popular&q=webkit");
CefString method("GET");
req->Set(url, method, postdata, headers);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
req->SetFlags((CefRequest::RequestFlags)(
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_REPORT_RAW_HEADERS |
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
@@ -293,29 +279,26 @@ TEST(WebURLRequestTest, GET)
EXPECT_FALSE(tr.got_error);
EXPECT_FALSE(tr.got_redirect);
EXPECT_FALSE(tr.got_progress);
EXPECT_GT((int)tr.contentLength, 0);
EXPECT_GT(tr.contentLength, static_cast<size_t>(0));
EXPECT_EQ(200, tr.statusCode);
}
TEST(WebURLRequestTest, POST)
{
class BrowserForTest : public BrowserTestHandler
{
public:
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
TEST(WebURLRequestTest, POST) {
class BrowserForTest : public BrowserTestHandler {
public:
explicit BrowserForTest(TestResults &tr) : BrowserTestHandler(tr) { }
void StartTest()
{
void StartTest() {
CefRefPtr<CefRequest> req;
CefRefPtr<CefPostData> postdata;
CefRefPtr<CefPostDataElement> postitem;
CefRequest::HeaderMap headers;
headers.insert(std::make_pair("Content-Type",
headers.insert(std::make_pair("Content-Type",
"application/x-www-form-urlencoded"));
req = CefRequest::CreateRequest();
CefString url("http://pastebin.com/api_public.php");
CefString method("POST");
@@ -323,23 +306,24 @@ TEST(WebURLRequestTest, POST)
postitem = CefPostDataElement::CreatePostDataElement();
static char posttext[] =
"paste_name=CEF%20Test%20Post&paste_code=testing a post call.&paste_expire_date=10M";
"paste_name=CEF%20Test%20Post&paste_code=testing a post call."
"&paste_expire_date=10M";
postitem->SetToBytes(strlen(posttext), posttext);
postdata->AddElement(postitem);
req->Set(url, method, postdata, headers);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
req->SetFlags((CefRequest::RequestFlags)(
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_REPORT_RAW_HEADERS |
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
ASSERT_TRUE(handler->Run(req));
ASSERT_TRUE(handler->Run(req));
}
};
@@ -356,37 +340,34 @@ TEST(WebURLRequestTest, POST)
EXPECT_TRUE(tr.got_progress);
EXPECT_FALSE(tr.got_error);
EXPECT_FALSE(tr.got_abort);
EXPECT_GT((int)tr.contentLength, 0);
EXPECT_GT(tr.contentLength, static_cast<size_t>(0));
EXPECT_EQ(200, tr.statusCode);
}
TEST(WebURLRequestTest, BADHOST)
{
class BrowserForTest : public BrowserTestHandler
{
public:
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
TEST(WebURLRequestTest, BADHOST) {
class BrowserForTest : public BrowserTestHandler {
public:
explicit BrowserForTest(TestResults &tr) : BrowserTestHandler(tr) { }
void StartTest()
{
void StartTest() {
CefRefPtr<CefRequest> req;
CefRefPtr<CefPostData> postdata;
CefRefPtr<CefPostDataElement> postitem;
CefRequest::HeaderMap headers;
req = CefRequest::CreateRequest();
CefString url("http://this.host.does.not.exist/not/really/here");
CefString method("GET");
req->Set(url, method, postdata, headers);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
req->SetFlags((CefRequest::RequestFlags)(
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_REPORT_RAW_HEADERS |
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
@@ -398,7 +379,7 @@ TEST(WebURLRequestTest, BADHOST)
CefRefPtr<BrowserTestHandler> browser = new BrowserForTest(tr);
browser->ExecuteTest();
// NOTE: THIS TEST WILL FAIL IF YOUR ISP REDIRECTS YOU TO
// NOTE: THIS TEST WILL FAIL IF YOUR ISP REDIRECTS YOU TO
// THEIR SEARCH PAGE ON NXDOMAIN ERRORS.
EXPECT_TRUE(tr.got_started);
EXPECT_FALSE(tr.got_headers);
@@ -410,43 +391,39 @@ TEST(WebURLRequestTest, BADHOST)
EXPECT_FALSE(tr.got_abort);
EXPECT_TRUE(tr.got_error);
EXPECT_EQ(ERR_NAME_NOT_RESOLVED, tr.errorCode);
EXPECT_EQ(0, (int)tr.contentLength);
EXPECT_EQ(static_cast<size_t>(0), tr.contentLength);
EXPECT_EQ(0, tr.statusCode);
}
#define COUNTOF_(ar) (sizeof(ar)/sizeof(ar[0]))
TEST(WebURLRequestTest, CANCEL)
{
class BrowserForTest : public BrowserTestHandler
{
public:
TEST(WebURLRequestTest, CANCEL) {
class BrowserForTest : public BrowserTestHandler {
public:
BrowserForTest(TestResults &tr, cef_weburlrequest_state_t cancelAtState)
: BrowserTestHandler(tr, cancelAtState)
{
: BrowserTestHandler(tr, cancelAtState) {
}
void StartTest()
{
void StartTest() {
CefRefPtr<CefRequest> req;
CefRefPtr<CefPostData> postdata;
CefRefPtr<CefPostDataElement> postitem;
CefRequest::HeaderMap headers;
req = CefRequest::CreateRequest();
CefString url(
"http://search.twitter.com/search.json?result_type=popular&q=webkit");
CefString method("GET");
req->Set(url, method, postdata, headers);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
req->SetFlags((CefRequest::RequestFlags)(
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_REPORT_RAW_HEADERS |
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
@@ -455,25 +432,23 @@ TEST(WebURLRequestTest, CANCEL)
};
cef_weburlrequest_state_t cancelAt[] = {
WUR_STATE_STARTED,
WUR_STATE_HEADERS_RECEIVED
WUR_STATE_STARTED,
WUR_STATE_HEADERS_RECEIVED
};
for (unsigned int i=0; i < COUNTOF_(cancelAt); ++i) {
for (unsigned int i = 0; i < COUNTOF_(cancelAt); ++i) {
TestResults tr;
CefRefPtr<BrowserTestHandler> browser = new BrowserForTest(tr, cancelAt[i]);
browser->ExecuteTest();
EXPECT_TRUE(tr.got_abort) << "i = " << i;
EXPECT_TRUE(tr.got_deleted);
}
}
// Enable this test if you have installed the php test page.
#if 0
TEST(WebURLRequestTest, REDIRECT)
{
TEST(WebURLRequestTest, REDIRECT) {
/* // PHP Script for a local server to test this:
// You can run a zwamp server on windows to run this.
// http://sourceforge.net/projects/zwamp/
@@ -498,33 +473,31 @@ else
*/
class BrowserForTest : public BrowserTestHandler
{
class BrowserForTest : public BrowserTestHandler {
public:
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
explicit BrowserForTest(TestResults &tr) : BrowserTestHandler(tr) { }
void StartTest()
{
void StartTest() {
CefRefPtr<CefRequest> req;
CefRefPtr<CefPostData> postdata;
CefRefPtr<CefPostDataElement> postitem;
CefRequest::HeaderMap headers;
req = CefRequest::CreateRequest();
CefString url("http://localhost/cef/redirect.php?max=4");
CefString method("GET");
req->Set(url, method, postdata, headers);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
CefRefPtr<TestWebURLRequestClient> handler =
new TestWebURLRequestClient(test_results_, this);
req->SetFlags((CefRequest::RequestFlags)(
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_REPORT_RAW_HEADERS |
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
WUR_FLAG_SKIP_CACHE |
WUR_FLAG_REPORT_LOAD_TIMING |
WUR_FLAG_REPORT_RAW_HEADERS |
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
ASSERT_TRUE(handler->Run(req, cancelAtState_));
}
@@ -542,9 +515,9 @@ else
EXPECT_FALSE(tr.got_progress);
EXPECT_FALSE(tr.got_error);
EXPECT_FALSE(tr.got_abort);
EXPECT_GT((int)tr.contentLength, 0);
EXPECT_GT(tr.contentLength, static_cast<size_t>(0));
EXPECT_EQ(200, tr.statusCode);
EXPECT_EQ(3, tr.redirectCount);
}
#endif // 0
#endif // 0

View File

@@ -25,14 +25,14 @@ char g_test_xml[] =
" <ns:objB_3>&EB;</ns:objB_3>\n"
" <ns:objB_4><b>this is</b> mixed content &EA;</ns:objB_4>\n"
" </ns:objB>\n"
" <ns:objC ns:attr1=\"value C1\" ns:attr2=\"value C2\"/><ns:objD></ns:objD>\n"
" <ns:objC ns:attr1=\"value C1\" ns:attr2=\"value C2\"/><ns:objD>"
"</ns:objD>\n"
"</ns:obj>\n";
} // namespace
} // namespace
// Test XML reading
TEST(XmlReaderTest, Read)
{
TEST(XmlReaderTest, Read) {
// Create the stream reader.
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData(g_test_xml, sizeof(g_test_xml) - 1));
@@ -126,7 +126,7 @@ TEST(XmlReaderTest, Read)
ASSERT_EQ(reader->GetQualifiedName(), "#comment");
ASSERT_TRUE(reader->HasValue());
ASSERT_EQ(reader->GetValue(), " my comment ");
// Move to the whitespace node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
@@ -237,7 +237,7 @@ TEST(XmlReaderTest, Read)
ASSERT_EQ(reader->GetQualifiedName(), "EB");
ASSERT_TRUE(reader->HasValue());
ASSERT_EQ(reader->GetValue(), "EB Value");
// Move to the ns:objB_3 element ending node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetDepth(), 2);
@@ -279,7 +279,7 @@ TEST(XmlReaderTest, Read)
ASSERT_FALSE(reader->IsEmptyElement());
ASSERT_FALSE(reader->HasAttributes());
ASSERT_FALSE(reader->HasValue());
// Move to the text node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetDepth(), 4);
@@ -288,14 +288,14 @@ TEST(XmlReaderTest, Read)
ASSERT_EQ(reader->GetQualifiedName(), "#text");
ASSERT_TRUE(reader->HasValue());
ASSERT_EQ(reader->GetValue(), "this is");
// Move to the </b> element node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetDepth(), 3);
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
ASSERT_EQ(reader->GetLocalName(), "b");
ASSERT_EQ(reader->GetQualifiedName(), "b");
// Move to the text node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetDepth(), 3);
@@ -304,7 +304,7 @@ TEST(XmlReaderTest, Read)
ASSERT_EQ(reader->GetQualifiedName(), "#text");
ASSERT_TRUE(reader->HasValue());
ASSERT_EQ(reader->GetValue(), " mixed content ");
// Move to the EA entity reference node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetDepth(), 3);
@@ -313,7 +313,7 @@ TEST(XmlReaderTest, Read)
ASSERT_EQ(reader->GetQualifiedName(), "EA");
ASSERT_TRUE(reader->HasValue());
ASSERT_EQ(reader->GetValue(), "EA Value");
// Move to the ns:objB_4 element ending node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetDepth(), 2);
@@ -366,7 +366,7 @@ TEST(XmlReaderTest, Read)
ASSERT_EQ(reader->GetAttribute("ns:attr2"), "value C2");
ASSERT_EQ(reader->GetAttribute("attr2", "http://www.example.org/ns"),
"value C2");
// Move to the ns:attr1 attribute.
ASSERT_TRUE(reader->MoveToFirstAttribute());
ASSERT_EQ(reader->GetDepth(), 2);
@@ -379,7 +379,7 @@ TEST(XmlReaderTest, Read)
ASSERT_FALSE(reader->IsEmptyElement());
ASSERT_FALSE(reader->HasAttributes());
ASSERT_EQ(reader->GetValue(), "value C1");
// Move to the ns:attr2 attribute.
ASSERT_TRUE(reader->MoveToNextAttribute());
ASSERT_EQ(reader->GetDepth(), 2);
@@ -401,7 +401,7 @@ TEST(XmlReaderTest, Read)
ASSERT_EQ(reader->GetDepth(), 1);
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
// Move to the ns:attr1 attribute.
ASSERT_TRUE(reader->MoveToAttribute(0));
ASSERT_EQ(reader->GetDepth(), 2);
@@ -414,13 +414,13 @@ TEST(XmlReaderTest, Read)
ASSERT_FALSE(reader->IsEmptyElement());
ASSERT_FALSE(reader->HasAttributes());
ASSERT_EQ(reader->GetValue(), "value C1");
// Return to the ns:objC element start node.
ASSERT_TRUE(reader->MoveToCarryingElement());
ASSERT_EQ(reader->GetDepth(), 1);
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
// Move to the ns:attr2 attribute.
ASSERT_TRUE(reader->MoveToAttribute("ns:attr2"));
ASSERT_EQ(reader->GetDepth(), 2);
@@ -433,7 +433,7 @@ TEST(XmlReaderTest, Read)
ASSERT_FALSE(reader->IsEmptyElement());
ASSERT_FALSE(reader->HasAttributes());
ASSERT_EQ(reader->GetValue(), "value C2");
// Move to the ns:attr1 attribute without returning to the ns:objC element.
ASSERT_TRUE(reader->MoveToAttribute("attr1", "http://www.example.org/ns"));
ASSERT_EQ(reader->GetDepth(), 2);
@@ -446,7 +446,7 @@ TEST(XmlReaderTest, Read)
ASSERT_FALSE(reader->IsEmptyElement());
ASSERT_FALSE(reader->HasAttributes());
ASSERT_EQ(reader->GetValue(), "value C1");
// Move to the ns:objD element start node.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetDepth(), 1);
@@ -468,7 +468,7 @@ TEST(XmlReaderTest, Read)
ASSERT_FALSE(reader->IsEmptyElement());
ASSERT_FALSE(reader->HasAttributes());
ASSERT_FALSE(reader->HasValue());
// Move to the whitespace node without returning to the ns:objC element.
ASSERT_TRUE(reader->MoveToNextNode());
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
@@ -496,8 +496,7 @@ TEST(XmlReaderTest, Read)
}
// Test XML read error handling.
TEST(XmlReaderTest, ReadError)
{
TEST(XmlReaderTest, ReadError) {
char test_str[] =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
"<!ATTRIBUTE foo bar>\n";
@@ -519,8 +518,7 @@ TEST(XmlReaderTest, ReadError)
}
// Test XmlObject load behavior.
TEST(XmlReaderTest, ObjectLoad)
{
TEST(XmlReaderTest, ObjectLoad) {
// Create the stream reader.
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData(g_test_xml, sizeof(g_test_xml) - 1));
@@ -603,19 +601,18 @@ TEST(XmlReaderTest, ObjectLoad)
}
// Test XmlObject load error handling behavior.
TEST(XmlReaderTest, ObjectLoadError)
{
TEST(XmlReaderTest, ObjectLoadError) {
// Test start/end tag mismatch error.
{
char error_xml[] = "<obj>\n<foo>\n</obj>\n</foo>";
// Create the stream reader.
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData(error_xml, sizeof(error_xml) - 1));
ASSERT_TRUE(stream.get() != NULL);
CefString error_str;
// Create the XML reader.
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
ASSERT_FALSE(object->Load(stream, XML_ENCODING_NONE,
@@ -627,14 +624,14 @@ TEST(XmlReaderTest, ObjectLoadError)
// Test value following child error.
{
char error_xml[] = "<obj>\n<foo>\n</foo>disallowed value\n</obj>";
// Create the stream reader.
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData(error_xml, sizeof(error_xml) - 1));
ASSERT_TRUE(stream.get() != NULL);
CefString error_str;
// Create the XML reader.
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
ASSERT_FALSE(object->Load(stream, XML_ENCODING_NONE,

View File

@@ -122,11 +122,10 @@ namespace {
0x00, 0x00, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
};
} // namespace
} // namespace
// Test Zip reading.
TEST(ZipReaderTest, Read)
{
TEST(ZipReaderTest, Read) {
// Create the stream reader.
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData(g_test_zip, sizeof(g_test_zip) - 1));
@@ -196,7 +195,7 @@ TEST(ZipReaderTest, Read)
ASSERT_TRUE(!strncmp(buff, "Contents of file 2A.", 20));
ASSERT_FALSE(reader->MoveToNextFile());
// Try seeking a particular file
ASSERT_TRUE(reader->MoveToFile("TEST_ARCHIVE/FOLDER 1/FILE 1B.TXT", false));
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 1/file 1b.txt");
@@ -208,13 +207,12 @@ TEST(ZipReaderTest, Read)
ASSERT_TRUE(reader->MoveToFile("test_archive/folder 1/file 1b.txt", true));
ASSERT_FALSE(reader->MoveToFile("test_archive/folder 1/FILE 1B.txt", true));
ASSERT_TRUE(reader->Close());
}
// Test CefZipArchive object.
TEST(ZipReaderTest, ReadArchive)
{
TEST(ZipReaderTest, ReadArchive) {
// Create the stream reader.
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData(g_test_zip, sizeof(g_test_zip) - 1));
@@ -230,7 +228,7 @@ TEST(ZipReaderTest, ReadArchive)
ASSERT_TRUE(archive->HasFile("test_archive/FOLDER 1/file 1b.txt"));
ASSERT_TRUE(archive->HasFile("test_archive/folder 1/folder 1a/file 1a1.txt"));
ASSERT_TRUE(archive->HasFile("test_archive/folder 2/file 2a.txt"));
// Test content retrieval.
CefRefPtr<CefZipArchive::File> file;
file = archive->GetFile("test_archive/folder 2/file 2a.txt");