mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Introduce CefString and cef_string_t implementations that support string type conversions and customization of the API string type (issue #146).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@145 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -16,30 +16,30 @@ public:
|
||||
|
||||
// Execute with the specified argument list and return value. Return true if
|
||||
// the method was handled.
|
||||
virtual bool Execute(const std::wstring& name,
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
std::wstring& exception)
|
||||
CefString& exception)
|
||||
{
|
||||
if(name == L"Dump")
|
||||
if(name == "Dump")
|
||||
{
|
||||
// The "Dump" function will return a human-readable dump of the input
|
||||
// arguments.
|
||||
std::wstringstream stream;
|
||||
std::stringstream stream;
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
stream << L"arg[" << i << L"] = ";
|
||||
stream << "arg[" << i << "] = ";
|
||||
PrintValue(arguments[i], stream, 0);
|
||||
stream << L"\n";
|
||||
stream << "\n";
|
||||
}
|
||||
|
||||
retval = CefV8Value::CreateString(stream.str());
|
||||
return true;
|
||||
}
|
||||
else if(name == L"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
|
||||
@ -80,46 +80,46 @@ public:
|
||||
}
|
||||
|
||||
// Simple function for formatted output of a V8 value.
|
||||
void PrintValue(CefRefPtr<CefV8Value> value, std::wstringstream &stream,
|
||||
void PrintValue(CefRefPtr<CefV8Value> value, std::stringstream &stream,
|
||||
int indent)
|
||||
{
|
||||
std::wstringstream indent_stream;
|
||||
std::stringstream indent_stream;
|
||||
for(int i = 0; i < indent; ++i)
|
||||
indent_stream << L" ";
|
||||
std::wstring indent_str = indent_stream.str();
|
||||
indent_stream << " ";
|
||||
std::string indent_str = indent_stream.str();
|
||||
|
||||
if(value->IsUndefined())
|
||||
stream << L"(undefined)";
|
||||
stream << "(undefined)";
|
||||
else if(value->IsNull())
|
||||
stream << L"(null)";
|
||||
stream << "(null)";
|
||||
else if(value->IsBool())
|
||||
stream << L"(bool) " << (value->GetBoolValue() ? L"true" : L"false");
|
||||
stream << "(bool) " << (value->GetBoolValue() ? "true" : "false");
|
||||
else if(value->IsInt())
|
||||
stream << L"(int) " << value->GetIntValue();
|
||||
stream << "(int) " << value->GetIntValue();
|
||||
else if(value->IsDouble())
|
||||
stream << L"(double) " << value->GetDoubleValue();
|
||||
stream << "(double) " << value->GetDoubleValue();
|
||||
else if(value->IsString())
|
||||
stream << L"(string) " << value->GetStringValue().c_str();
|
||||
stream << "(string) " << std::string(value->GetStringValue());
|
||||
else if(value->IsFunction())
|
||||
stream << L"(function) " << value->GetFunctionName().c_str();
|
||||
stream << "(function) " << std::string(value->GetFunctionName());
|
||||
else if(value->IsArray()) {
|
||||
stream << L"(array) [";
|
||||
stream << "(array) [";
|
||||
int len = value->GetArrayLength();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
stream << L"\n " << indent_str.c_str() << i << L" = ";
|
||||
stream << "\n " << indent_str.c_str() << i << " = ";
|
||||
PrintValue(value->GetValue(i), stream, indent+1);
|
||||
}
|
||||
stream << L"\n" << indent_str.c_str() << L"]";
|
||||
stream << "\n" << indent_str.c_str() << "]";
|
||||
} else if(value->IsObject()) {
|
||||
stream << L"(object) [";
|
||||
std::vector<std::wstring> keys;
|
||||
stream << "(object) [";
|
||||
std::vector<CefString> keys;
|
||||
if(value->GetKeys(keys)) {
|
||||
for(size_t i = 0; i < keys.size(); ++i) {
|
||||
stream << L"\n " << indent_str.c_str() << keys[i].c_str() << L" = ";
|
||||
stream << "\n " << indent_str.c_str() << keys[i].c_str() << " = ";
|
||||
PrintValue(value->GetValue(keys[i]), stream, indent+1);
|
||||
}
|
||||
}
|
||||
stream << L"\n" << indent_str.c_str() << L"]";
|
||||
stream << "\n" << indent_str.c_str() << "]";
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -133,41 +133,41 @@ void InitBindingTest(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefV8Value> testObjPtr = CefV8Value::CreateObject(NULL);
|
||||
// Add the new V8 object to the global window object with the name
|
||||
// "cef_test".
|
||||
object->SetValue(L"cef_test", testObjPtr);
|
||||
object->SetValue("cef_test", testObjPtr);
|
||||
|
||||
// Create an instance of ClientV8FunctionHandler as the V8 handler.
|
||||
CefRefPtr<CefV8Handler> handlerPtr = new ClientV8FunctionHandler();
|
||||
|
||||
// Add a new V8 function to the cef_test object with the name "Dump".
|
||||
testObjPtr->SetValue(L"Dump",
|
||||
CefV8Value::CreateFunction(L"Dump", handlerPtr));
|
||||
testObjPtr->SetValue("Dump",
|
||||
CefV8Value::CreateFunction("Dump", handlerPtr));
|
||||
// Add a new V8 function to the cef_test object with the name "Call".
|
||||
testObjPtr->SetValue(L"Call",
|
||||
CefV8Value::CreateFunction(L"Call", handlerPtr));
|
||||
testObjPtr->SetValue("Call",
|
||||
CefV8Value::CreateFunction("Call", handlerPtr));
|
||||
}
|
||||
|
||||
void RunBindingTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
std::wstring html =
|
||||
L"<html><body>ClientV8FunctionHandler says:<br><pre>"
|
||||
L"<script language=\"JavaScript\">"
|
||||
L"document.writeln(window.cef_test.Dump(false, 1, 7.6654,'bar',"
|
||||
L" [false,true],[5, 7.654, 1, 'foo', [true, 'bar'], 8]));"
|
||||
L"document.writeln(window.cef_test.Dump(cef));"
|
||||
L"document.writeln("
|
||||
L" window.cef_test.Call(cef.test.test_object, 'GetMessage'));"
|
||||
L"function my_object() {"
|
||||
L" var obj = {};"
|
||||
L" (function() {"
|
||||
L" obj.GetMessage = function(a) {"
|
||||
L" return 'Calling a function with value '+a+' on a user object succeeded.';"
|
||||
L" };"
|
||||
L" })();"
|
||||
L" return obj;"
|
||||
L"};"
|
||||
L"document.writeln("
|
||||
L" window.cef_test.Call(my_object, 'GetMessage', 'foobar'));"
|
||||
L"</script>"
|
||||
L"</pre></body></html>";
|
||||
browser->GetMainFrame()->LoadString(html, L"about:blank");
|
||||
std::string html =
|
||||
"<html><body>ClientV8FunctionHandler says:<br><pre>"
|
||||
"<script language=\"JavaScript\">"
|
||||
"document.writeln(window.cef_test.Dump(false, 1, 7.6654,'bar',"
|
||||
" [false,true],[5, 7.654, 1, 'foo', [true, 'bar'], 8]));"
|
||||
"document.writeln(window.cef_test.Dump(cef));"
|
||||
"document.writeln("
|
||||
" window.cef_test.Call(cef.test.test_object, 'GetMessage'));"
|
||||
"function my_object() {"
|
||||
" var obj = {};"
|
||||
" (function() {"
|
||||
" obj.GetMessage = function(a) {"
|
||||
" return 'Calling a function with value '+a+' on a user object succeeded.';"
|
||||
" };"
|
||||
" })();"
|
||||
" return obj;"
|
||||
"};"
|
||||
"document.writeln("
|
||||
" window.cef_test.Call(my_object, 'GetMessage', 'foobar'));"
|
||||
"</script>"
|
||||
"</pre></body></html>";
|
||||
browser->GetMainFrame()->LoadString(html, "about:blank");
|
||||
}
|
||||
|
@ -16,14 +16,14 @@
|
||||
// ClientHandler::ClientDownloadListener implementation
|
||||
|
||||
void ClientHandler::ClientDownloadListener::NotifyDownloadComplete(
|
||||
const std::wstring& fileName)
|
||||
const CefString& fileName)
|
||||
{
|
||||
handler_->SetLastDownloadFile(fileName);
|
||||
handler_->SendNotification(NOTIFY_DOWNLOAD_COMPLETE);
|
||||
}
|
||||
|
||||
void ClientHandler::ClientDownloadListener::NotifyDownloadError(
|
||||
const std::wstring& fileName)
|
||||
const CefString& fileName)
|
||||
{
|
||||
handler_->SetLastDownloadFile(fileName);
|
||||
handler_->SendNotification(NOTIFY_DOWNLOAD_ERROR);
|
||||
@ -90,36 +90,36 @@ CefHandler::RetVal ClientHandler::HandleLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, ErrorCode errorCode,
|
||||
const std::wstring& failedUrl, std::wstring& errorText)
|
||||
const CefString& failedUrl, CefString& errorText)
|
||||
{
|
||||
if(errorCode == ERR_CACHE_MISS)
|
||||
{
|
||||
// Usually caused by navigating to a page with POST data via back or
|
||||
// forward buttons.
|
||||
errorText = L"<html><head><title>Expired Form Data</title></head>"
|
||||
L"<body><h1>Expired Form Data</h1>"
|
||||
L"<h2>Your form request has expired. "
|
||||
L"Click reload to re-submit the form data.</h2></body>"
|
||||
L"</html>";
|
||||
errorText = "<html><head><title>Expired Form Data</title></head>"
|
||||
"<body><h1>Expired Form Data</h1>"
|
||||
"<h2>Your form request has expired. "
|
||||
"Click reload to re-submit the form data.</h2></body>"
|
||||
"</html>";
|
||||
}
|
||||
else
|
||||
{
|
||||
// All other messages.
|
||||
std::wstringstream ss;
|
||||
ss << L"<html><head><title>Load Failed</title></head>"
|
||||
L"<body><h1>Load Failed</h1>"
|
||||
L"<h2>Load of URL " << failedUrl <<
|
||||
L" failed with error code " << static_cast<int>(errorCode) <<
|
||||
L".</h2></body>"
|
||||
L"</html>";
|
||||
std::stringstream ss;
|
||||
ss << "<html><head><title>Load Failed</title></head>"
|
||||
"<body><h1>Load Failed</h1>"
|
||||
"<h2>Load of URL " << std::string(failedUrl) <<
|
||||
" failed with error code " << static_cast<int>(errorCode) <<
|
||||
".</h2></body>"
|
||||
"</html>";
|
||||
errorText = ss.str();
|
||||
}
|
||||
return RV_HANDLED;
|
||||
}
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleDownloadResponse(
|
||||
CefRefPtr<CefBrowser> browser, const std::wstring& mimeType,
|
||||
const std::wstring& fileName, int64 contentLength,
|
||||
CefRefPtr<CefBrowser> browser, const CefString& mimeType,
|
||||
const CefString& fileName, int64 contentLength,
|
||||
CefRefPtr<CefDownloadHandler>& handler)
|
||||
{
|
||||
// Create the handler for the file download.
|
||||
@ -129,10 +129,10 @@ CefHandler::RetVal ClientHandler::HandleDownloadResponse(
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandlePrintHeaderFooter(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
CefPrintInfo& printInfo, const std::wstring& url, const std::wstring& title,
|
||||
int currentPage, int maxPages, std::wstring& topLeft,
|
||||
std::wstring& topCenter, std::wstring& topRight, std::wstring& bottomLeft,
|
||||
std::wstring& bottomCenter, std::wstring& bottomRight)
|
||||
CefPrintInfo& printInfo, const CefString& url, const CefString& title,
|
||||
int currentPage, int maxPages, CefString& topLeft,
|
||||
CefString& topCenter, CefString& topRight, CefString& bottomLeft,
|
||||
CefString& bottomCenter, CefString& bottomRight)
|
||||
{
|
||||
// Place the page title at top left
|
||||
topLeft = title;
|
||||
@ -140,8 +140,8 @@ CefHandler::RetVal ClientHandler::HandlePrintHeaderFooter(
|
||||
topRight = url;
|
||||
|
||||
// Place "Page X of Y" at bottom center
|
||||
std::wstringstream strstream;
|
||||
strstream << L"Page " << currentPage << L" of " << maxPages;
|
||||
std::stringstream strstream;
|
||||
strstream << "Page " << currentPage << " of " << maxPages;
|
||||
bottomCenter = strstream.str();
|
||||
|
||||
return RV_CONTINUE;
|
||||
@ -168,37 +168,32 @@ CefHandler::RetVal ClientHandler::HandleBeforeWindowClose(
|
||||
}
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleConsoleMessage(
|
||||
CefRefPtr<CefBrowser> browser, const std::wstring& message,
|
||||
const std::wstring& source, int line)
|
||||
CefRefPtr<CefBrowser> browser, const CefString& message,
|
||||
const CefString& source, int line)
|
||||
{
|
||||
Lock();
|
||||
bool first_message = m_LogFile.empty();
|
||||
if(first_message) {
|
||||
std::wstringstream ss;
|
||||
std::stringstream ss;
|
||||
ss << AppGetWorkingDirectory();
|
||||
#ifdef _WIN32
|
||||
ss << L"\\";
|
||||
ss << "\\";
|
||||
#else
|
||||
ss << L"/";
|
||||
ss << "/";
|
||||
#endif
|
||||
ss << L"console.log";
|
||||
ss << "console.log";
|
||||
m_LogFile = ss.str();
|
||||
}
|
||||
std::wstring logFile = m_LogFile;
|
||||
std::string logFile = m_LogFile;
|
||||
Unlock();
|
||||
|
||||
FILE* file = NULL;
|
||||
#ifdef _WIN32
|
||||
_wfopen_s(&file, logFile.c_str(), L"a, ccs=UTF-8");
|
||||
#else
|
||||
file = fopen(WStringToString(logFile).c_str(), "a");
|
||||
#endif
|
||||
|
||||
FILE* file = fopen(logFile.c_str(), "a");
|
||||
if(file) {
|
||||
std::wstringstream ss;
|
||||
ss << L"Message: " << message << L"\r\nSource: " << source <<
|
||||
L"\r\nLine: " << line << L"\r\n-----------------------\r\n";
|
||||
fputws(ss.str().c_str(), file);
|
||||
std::stringstream ss;
|
||||
ss << "Message: " << std::string(message) << "\r\nSource: " <<
|
||||
std::string(source) << "\r\nLine: " << line <<
|
||||
"\r\n-----------------------\r\n";
|
||||
fputs(ss.str().c_str(), file);
|
||||
fclose(file);
|
||||
|
||||
if(first_message)
|
||||
@ -232,24 +227,24 @@ void ClientHandler::SetEditHwnd(CefWindowHandle hwnd)
|
||||
Unlock();
|
||||
}
|
||||
|
||||
std::wstring ClientHandler::GetLogFile()
|
||||
std::string ClientHandler::GetLogFile()
|
||||
{
|
||||
Lock();
|
||||
std::wstring str = m_LogFile;
|
||||
std::string str = m_LogFile;
|
||||
Unlock();
|
||||
return str;
|
||||
}
|
||||
|
||||
void ClientHandler::SetLastDownloadFile(const std::wstring& fileName)
|
||||
void ClientHandler::SetLastDownloadFile(const std::string& fileName)
|
||||
{
|
||||
Lock();
|
||||
m_LastDownloadFile = fileName;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
std::wstring ClientHandler::GetLastDownloadFile()
|
||||
std::string ClientHandler::GetLastDownloadFile()
|
||||
{
|
||||
std::wstring str;
|
||||
std::string str;
|
||||
Lock();
|
||||
str = m_LastDownloadFile;
|
||||
Unlock();
|
||||
@ -278,25 +273,25 @@ CefWindowHandle AppGetMainHwnd()
|
||||
void RunGetSourceTest(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
// Retrieve the current page source and display.
|
||||
std::wstring source = frame->GetSource();
|
||||
source = StringReplace(source, L"<", L"<");
|
||||
source = StringReplace(source, L">", L">");
|
||||
std::wstringstream ss;
|
||||
ss << L"<html><body>Source:" << L"<pre>" << source
|
||||
<< L"</pre></body></html>";
|
||||
frame->LoadString(ss.str(), L"http://tests/getsource");
|
||||
std::string source = frame->GetSource();
|
||||
source = StringReplace(source, "<", "<");
|
||||
source = StringReplace(source, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Source:" << "<pre>" << source
|
||||
<< "</pre></body></html>";
|
||||
frame->LoadString(ss.str(), "http://tests/getsource");
|
||||
}
|
||||
|
||||
void RunGetTextTest(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
// Retrieve the current page text and display.
|
||||
std::wstring text = frame->GetText();
|
||||
text = StringReplace(text, L"<", L"<");
|
||||
text = StringReplace(text, L">", L">");
|
||||
std::wstringstream ss;
|
||||
ss << L"<html><body>Text:" << L"<pre>" << text
|
||||
<< L"</pre></body></html>";
|
||||
frame->LoadString(ss.str(), L"http://tests/gettext");
|
||||
std::string text = frame->GetText();
|
||||
text = StringReplace(text, "<", "<");
|
||||
text = StringReplace(text, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Text:" << "<pre>" << text
|
||||
<< "</pre></body></html>";
|
||||
frame->LoadString(ss.str(), "http://tests/gettext");
|
||||
}
|
||||
|
||||
void RunRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
@ -305,7 +300,7 @@ void RunRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
|
||||
|
||||
// Set the request URL
|
||||
request->SetURL(L"http://tests/request");
|
||||
request->SetURL("http://tests/request");
|
||||
|
||||
// Add post data to the request. The correct method and content-
|
||||
// type headers will be set by CEF.
|
||||
@ -320,7 +315,7 @@ void RunRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
// Add a custom header
|
||||
CefRequest::HeaderMap headerMap;
|
||||
headerMap.insert(
|
||||
std::make_pair(L"X-My-Header", L"My Header Value"));
|
||||
std::make_pair("X-My-Header", "My Header Value"));
|
||||
request->SetHeaderMap(headerMap);
|
||||
|
||||
// Load the request
|
||||
@ -330,16 +325,16 @@ void RunRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
browser->GetMainFrame()->ExecuteJavaScript(
|
||||
L"alert('JavaScript execute works!');", L"about:blank", 0);
|
||||
"alert('JavaScript execute works!');", "about:blank", 0);
|
||||
}
|
||||
|
||||
void RunPopupTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
browser->GetMainFrame()->ExecuteJavaScript(
|
||||
L"window.open('http://www.google.com');", L"about:blank", 0);
|
||||
"window.open('http://www.google.com');", "about:blank", 0);
|
||||
}
|
||||
|
||||
void RunLocalStorageTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
browser->GetMainFrame()->LoadURL(L"http://tests/localstorage");
|
||||
browser->GetMainFrame()->LoadURL("http://tests/localstorage");
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ public:
|
||||
ClientDownloadListener(ClientHandler* handler) : handler_(handler) {}
|
||||
|
||||
// Called when the download is complete.
|
||||
virtual void NotifyDownloadComplete(const std::wstring& fileName);
|
||||
virtual void NotifyDownloadComplete(const CefString& fileName);
|
||||
|
||||
// Called if the download fails.
|
||||
virtual void NotifyDownloadError(const std::wstring& fileName);
|
||||
virtual void NotifyDownloadError(const CefString& fileName);
|
||||
|
||||
private:
|
||||
ClientHandler* handler_;
|
||||
@ -44,7 +44,7 @@ public:
|
||||
CefWindowInfo& createInfo, bool popup,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefRefPtr<CefHandler>& handler,
|
||||
std::wstring& url,
|
||||
CefString& url,
|
||||
CefBrowserSettings& settings)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
@ -58,12 +58,12 @@ public:
|
||||
// ignored.
|
||||
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& url);
|
||||
const CefString& url);
|
||||
|
||||
// Event called when the page title changes. The return value is currently
|
||||
// ignored.
|
||||
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& title);
|
||||
const CefString& title);
|
||||
|
||||
// Event called before browser navigation. The client has an opportunity to
|
||||
// modify the |request| object if desired. Return RV_HANDLED to cancel
|
||||
@ -97,8 +97,8 @@ public:
|
||||
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
ErrorCode errorCode,
|
||||
const std::wstring& failedUrl,
|
||||
std::wstring& errorText);
|
||||
const CefString& failedUrl,
|
||||
CefString& errorText);
|
||||
|
||||
// Event called before a resource is loaded. To allow the resource to load
|
||||
// normally return RV_CONTINUE. To redirect the resource to a new url
|
||||
@ -108,9 +108,9 @@ public:
|
||||
// To cancel loading of the resource return RV_HANDLED.
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType,
|
||||
CefString& mimeType,
|
||||
int loadFlags);
|
||||
|
||||
// Called when a server indicates via the 'Content-Disposition' header that a
|
||||
@ -122,8 +122,8 @@ public:
|
||||
// or RV_HANDLED to cancel the file download.
|
||||
/*--cef()--*/
|
||||
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& mimeType,
|
||||
const std::wstring& fileName,
|
||||
const CefString& mimeType,
|
||||
const CefString& fileName,
|
||||
int64 contentLength,
|
||||
CefRefPtr<CefDownloadHandler>& handler);
|
||||
|
||||
@ -139,7 +139,7 @@ public:
|
||||
// item. |label| contains the default text and may be modified to substitute
|
||||
// alternate text. The return value is currently ignored.
|
||||
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId, std::wstring& label)
|
||||
MenuId menuId, CefString& label)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -177,21 +177,21 @@ public:
|
||||
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefPrintInfo& printInfo,
|
||||
const std::wstring& url,
|
||||
const std::wstring& title,
|
||||
const CefString& url,
|
||||
const CefString& title,
|
||||
int currentPage, int maxPages,
|
||||
std::wstring& topLeft,
|
||||
std::wstring& topCenter,
|
||||
std::wstring& topRight,
|
||||
std::wstring& bottomLeft,
|
||||
std::wstring& bottomCenter,
|
||||
std::wstring& bottomRight);
|
||||
CefString& topLeft,
|
||||
CefString& topCenter,
|
||||
CefString& topRight,
|
||||
CefString& bottomLeft,
|
||||
CefString& bottomCenter,
|
||||
CefString& bottomRight);
|
||||
|
||||
// Run a JS alert message. Return RV_CONTINUE to display the default alert
|
||||
// or RV_HANDLED if you displayed a custom alert.
|
||||
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& message)
|
||||
const CefString& message)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -201,7 +201,7 @@ public:
|
||||
// set |retval| to true if the user accepted the confirmation.
|
||||
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& message, bool& retval)
|
||||
const CefString& message, bool& retval)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -212,10 +212,10 @@ public:
|
||||
// |result| to the resulting value.
|
||||
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& message,
|
||||
const std::wstring& defaultValue,
|
||||
const CefString& message,
|
||||
const CefString& defaultValue,
|
||||
bool& retval,
|
||||
std::wstring& result)
|
||||
CefString& result)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -254,7 +254,7 @@ public:
|
||||
// you can optionally modify |text| and then return RV_CONTINUE to allow
|
||||
// the browser to display the tooltip.
|
||||
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||
std::wstring& text)
|
||||
CefString& text)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -279,8 +279,8 @@ public:
|
||||
// Called to display a console message. Return RV_HANDLED to stop the message
|
||||
// from being output to the console.
|
||||
RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& message,
|
||||
const std::wstring& source, int line);
|
||||
const CefString& message,
|
||||
const CefString& source, int line);
|
||||
|
||||
// Called to report find results returned by CefBrowser::Find(). |identifer|
|
||||
// is the identifier passed to CefBrowser::Find(), |count| is the number of
|
||||
@ -304,10 +304,10 @@ public:
|
||||
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
|
||||
CefWindowHandle GetBrowserHwnd() { return m_BrowserHwnd; }
|
||||
|
||||
std::wstring GetLogFile();
|
||||
std::string GetLogFile();
|
||||
|
||||
void SetLastDownloadFile(const std::wstring& fileName);
|
||||
std::wstring GetLastDownloadFile();
|
||||
void SetLastDownloadFile(const std::string& fileName);
|
||||
std::string GetLastDownloadFile();
|
||||
|
||||
// Send a notification to the application. Notifications should not block the
|
||||
// caller.
|
||||
@ -339,11 +339,11 @@ protected:
|
||||
// True if the user can navigate forwards
|
||||
bool m_bCanGoForward;
|
||||
|
||||
std::wstring m_LogFile;
|
||||
std::string m_LogFile;
|
||||
|
||||
// Support for downloading files.
|
||||
CefRefPtr<DownloadListener> m_DownloadListener;
|
||||
std::wstring m_LastDownloadFile;
|
||||
std::string m_LastDownloadFile;
|
||||
};
|
||||
|
||||
|
||||
@ -354,7 +354,7 @@ CefRefPtr<CefBrowser> AppGetBrowser();
|
||||
CefWindowHandle AppGetMainHwnd();
|
||||
|
||||
// Returns the application working directory.
|
||||
std::wstring AppGetWorkingDirectory();
|
||||
std::string AppGetWorkingDirectory();
|
||||
|
||||
// Implementations for various tests.
|
||||
void RunGetSourceTest(CefRefPtr<CefFrame> frame);
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "extension_test.h"
|
||||
#include "scheme_test.h"
|
||||
#include "string_util.h"
|
||||
#include "string_util_mac.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include <sstream>
|
||||
|
||||
@ -78,7 +77,7 @@ const int kWindowHeight = 600;
|
||||
if (tempUrl && ![tempUrl scheme])
|
||||
url = [@"http://" stringByAppendingString:url];
|
||||
|
||||
std::wstring urlStr = NSStringToWString(url);
|
||||
std::string urlStr = [url UTF8String];
|
||||
g_handler->GetBrowser()->GetMainFrame()->LoadURL(urlStr);
|
||||
}
|
||||
|
||||
@ -92,27 +91,27 @@ const int kWindowHeight = 600;
|
||||
}
|
||||
|
||||
- (void)notifyConsoleMessage:(id)object {
|
||||
std::wstringstream ss;
|
||||
ss << L"Console messages will be written to " << g_handler->GetLogFile();
|
||||
NSString* str = WStringToNSString(ss.str());
|
||||
std::stringstream ss;
|
||||
ss << "Console messages will be written to " << g_handler->GetLogFile();
|
||||
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
||||
[self alert:@"Console Messages" withMessage:str];
|
||||
[str release];
|
||||
}
|
||||
|
||||
- (void)notifyDownloadComplete:(id)object {
|
||||
std::wstringstream ss;
|
||||
ss << L"File \"" << g_handler->GetLastDownloadFile() <<
|
||||
L"\" downloaded successfully.";
|
||||
NSString* str = WStringToNSString(ss.str());
|
||||
std::stringstream ss;
|
||||
ss << "File \"" << g_handler->GetLastDownloadFile() <<
|
||||
"\" downloaded successfully.";
|
||||
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
||||
[self alert:@"File Download" withMessage:str];
|
||||
[str release];
|
||||
}
|
||||
|
||||
- (void)notifyDownloadError:(id)object {
|
||||
std::wstringstream ss;
|
||||
ss << L"File \"" << g_handler->GetLastDownloadFile() <<
|
||||
L"\" failed to download.";
|
||||
NSString* str = WStringToNSString(ss.str());
|
||||
std::stringstream ss;
|
||||
ss << "File \"" << g_handler->GetLastDownloadFile() <<
|
||||
"\" failed to download.";
|
||||
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
|
||||
[self alert:@"File Download" withMessage:str];
|
||||
[str release];
|
||||
}
|
||||
@ -373,13 +372,14 @@ int main(int argc, char* argv[])
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& url)
|
||||
const CefString& url)
|
||||
{
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
|
||||
{
|
||||
// Set the edit window text
|
||||
NSTextField* textField = (NSTextField*)m_EditHwnd;
|
||||
NSString* str = WStringToNSString(url);
|
||||
NSString* str =
|
||||
[NSString stringWithUTF8String:(std::string(url).c_str())];
|
||||
[textField setStringValue:str];
|
||||
[str release];
|
||||
}
|
||||
@ -387,11 +387,12 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
}
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleTitleChange(
|
||||
CefRefPtr<CefBrowser> browser, const std::wstring& title)
|
||||
CefRefPtr<CefBrowser> browser, const CefString& title)
|
||||
{
|
||||
// Set the frame window title bar
|
||||
NSWindow* window = (NSWindow*)m_MainHwnd;
|
||||
NSString* str = WStringToNSString(title);
|
||||
NSString* str =
|
||||
[NSString stringWithUTF8String:(std::string(title).c_str())];
|
||||
[window setTitle:str];
|
||||
[str release];
|
||||
return RV_CONTINUE;
|
||||
@ -399,17 +400,17 @@ CefHandler::RetVal ClientHandler::HandleTitleChange(
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType, int loadFlags)
|
||||
CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefString& mimeType, int loadFlags)
|
||||
{
|
||||
std::wstring url = request->GetURL();
|
||||
if(url == L"http://tests/request") {
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/request") {
|
||||
// Show the request contents
|
||||
std::wstring dump;
|
||||
std::string dump;
|
||||
DumpRequestContents(request, dump);
|
||||
resourceStream = CefStreamReader::CreateForData(
|
||||
(void*)dump.c_str(), dump.size() * sizeof(wchar_t));
|
||||
mimeType = L"text/plain";
|
||||
(void*)dump.c_str(), dump.size());
|
||||
mimeType = "text/plain";
|
||||
}
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -440,7 +441,7 @@ void ClientHandler::SendNotification(NotificationType type)
|
||||
|
||||
// Global functions
|
||||
|
||||
std::wstring AppGetWorkingDirectory()
|
||||
std::string AppGetWorkingDirectory()
|
||||
{
|
||||
return StringToWString(szWorkingDir);
|
||||
return szWorkingDir;
|
||||
}
|
||||
|
@ -13,8 +13,9 @@
|
||||
#include "scheme_test.h"
|
||||
#include "string_util.h"
|
||||
#include "uiplugin_test.h"
|
||||
#include <sstream>
|
||||
#include <commdlg.h>
|
||||
#include <direct.h>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
@ -30,7 +31,7 @@
|
||||
HINSTANCE hInst; // current instance
|
||||
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
|
||||
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
|
||||
TCHAR szWorkingDir[MAX_PATH]; // The current working directory
|
||||
char szWorkingDir[MAX_PATH]; // The current working directory
|
||||
UINT uFindMsg; // Message identifier for find events.
|
||||
HWND hFindDlg = NULL; // Handle for the find dialog.
|
||||
|
||||
@ -59,12 +60,15 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
// Retrieve the current working directory.
|
||||
if(_wgetcwd(szWorkingDir, MAX_PATH) == NULL)
|
||||
if(_getcwd(szWorkingDir, MAX_PATH) == NULL)
|
||||
szWorkingDir[0] = 0;
|
||||
|
||||
CefSettings settings;
|
||||
CefBrowserSettings browserDefaults;
|
||||
|
||||
// Specify a cache path value.
|
||||
//CefString(&settings.cache_path).FromASCII("c:\\temp\\cache");
|
||||
|
||||
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
// Initialize the CEF with messages processed using the current application's
|
||||
// message loop.
|
||||
@ -357,7 +361,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
// Creat the new child child browser window
|
||||
CefBrowser::CreateBrowser(info, false,
|
||||
static_cast<CefRefPtr<CefHandler> >(g_handler),
|
||||
L"http://www.google.com");
|
||||
"http://www.google.com");
|
||||
|
||||
// Start the timer that will be used to update child window state
|
||||
SetTimer(hWnd, 1, 250, NULL);
|
||||
@ -401,8 +405,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if(g_handler.get()) {
|
||||
std::wstringstream ss;
|
||||
ss << L"Console messages will be written to "
|
||||
<< g_handler->GetLogFile();
|
||||
MessageBoxW(hWnd, ss.str().c_str(), L"Console Messages",
|
||||
<< std::wstring(CefString(g_handler->GetLogFile()));
|
||||
MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
|
||||
MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
return 0;
|
||||
@ -410,14 +414,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case ID_WARN_DOWNLOADERROR:
|
||||
if(g_handler.get()) {
|
||||
std::wstringstream ss;
|
||||
ss << L"File \"" << g_handler->GetLastDownloadFile() << L"\" ";
|
||||
ss << L"File \"" <<
|
||||
std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
|
||||
L"\" ";
|
||||
|
||||
if(wmId == ID_WARN_DOWNLOADCOMPLETE)
|
||||
ss << L"downloaded successfully.";
|
||||
else
|
||||
ss << L"failed to download.";
|
||||
|
||||
MessageBoxW(hWnd, ss.str().c_str(), L"File Download",
|
||||
MessageBox(hWnd, ss.str().c_str(), L"File Download",
|
||||
MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
return 0;
|
||||
@ -625,18 +631,18 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& url)
|
||||
const CefString& url)
|
||||
{
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
|
||||
{
|
||||
// Set the edit window text
|
||||
SetWindowText(m_EditHwnd, url.c_str());
|
||||
SetWindowText(m_EditHwnd, std::wstring(url).c_str());
|
||||
}
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleTitleChange(
|
||||
CefRefPtr<CefBrowser> browser, const std::wstring& title)
|
||||
CefRefPtr<CefBrowser> browser, const CefString& title)
|
||||
{
|
||||
// Set the frame window title bar
|
||||
CefWindowHandle hwnd = browser->GetWindowHandle();
|
||||
@ -645,53 +651,53 @@ CefHandler::RetVal ClientHandler::HandleTitleChange(
|
||||
// The frame window will be the parent of the browser window
|
||||
hwnd = GetParent(hwnd);
|
||||
}
|
||||
SetWindowText(hwnd, title.c_str());
|
||||
SetWindowText(hwnd, std::wstring(title).c_str());
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType, int loadFlags)
|
||||
CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefString& mimeType, int loadFlags)
|
||||
{
|
||||
DWORD dwSize;
|
||||
LPBYTE pBytes;
|
||||
|
||||
std::wstring url = request->GetURL();
|
||||
if(url == L"http://tests/request") {
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/request") {
|
||||
// Show the request contents
|
||||
std::wstring dump;
|
||||
std::string dump;
|
||||
DumpRequestContents(request, dump);
|
||||
resourceStream = CefStreamReader::CreateForData(
|
||||
(void*)dump.c_str(), dump.size() * sizeof(wchar_t));
|
||||
mimeType = L"text/plain";
|
||||
} else if(url == L"http://tests/uiapp") {
|
||||
resourceStream = CefStreamReader::CreateForData((void*)dump.c_str(),
|
||||
dump.size());
|
||||
mimeType = "text/plain";
|
||||
} else if(url == "http://tests/uiapp") {
|
||||
// Show the uiapp contents
|
||||
if(LoadBinaryResource(IDS_UIPLUGIN, dwSize, pBytes)) {
|
||||
resourceStream = CefStreamReader::CreateForHandler(
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
mimeType = L"text/html";
|
||||
mimeType = "text/html";
|
||||
}
|
||||
} else if(url == L"http://tests/localstorage") {
|
||||
} else if(url == "http://tests/localstorage") {
|
||||
// Show the localstorage contents
|
||||
if(LoadBinaryResource(IDS_LOCALSTORAGE, dwSize, pBytes)) {
|
||||
resourceStream = CefStreamReader::CreateForHandler(
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
mimeType = L"text/html";
|
||||
mimeType = "text/html";
|
||||
}
|
||||
} else if(wcsstr(url.c_str(), L"/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
|
||||
if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
|
||||
resourceStream = CefStreamReader::CreateForHandler(
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
mimeType = L"image/png";
|
||||
mimeType = "image/png";
|
||||
}
|
||||
} else if(wcsstr(url.c_str(), L"/logoball.png") != NULL) {
|
||||
} else if(strstr(url.c_str(), "/logoball.png") != NULL) {
|
||||
// Load the "logoball.png" image resource.
|
||||
if(LoadBinaryResource(IDS_LOGOBALL, dwSize, pBytes)) {
|
||||
resourceStream = CefStreamReader::CreateForHandler(
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
mimeType = L"image/png";
|
||||
mimeType = "image/png";
|
||||
}
|
||||
}
|
||||
return RV_CONTINUE;
|
||||
@ -720,7 +726,7 @@ void ClientHandler::SendNotification(NotificationType type)
|
||||
|
||||
// Global functions
|
||||
|
||||
std::wstring AppGetWorkingDirectory()
|
||||
std::string AppGetWorkingDirectory()
|
||||
{
|
||||
return szWorkingDir;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class ClientDownloadHandler : public CefThreadSafeBase<CefDownloadHandler>
|
||||
{
|
||||
public:
|
||||
ClientDownloadHandler(CefRefPtr<DownloadListener> listener,
|
||||
const std::wstring& fileName)
|
||||
const CefString& fileName)
|
||||
: listener_(listener), filename_(fileName), file_(NULL)
|
||||
{
|
||||
// Open the file on the FILE thread.
|
||||
@ -140,8 +140,9 @@ public:
|
||||
// Save the file in the user's "My Documents" folder.
|
||||
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
|
||||
NULL, 0, szFolderPath))) {
|
||||
LPWSTR name = PathFindFileName(filename_.c_str());
|
||||
LPWSTR ext = PathFindExtension(filename_.c_str());
|
||||
std::wstring fileNameStr = filename_;
|
||||
LPWSTR name = PathFindFileName(fileNameStr.c_str());
|
||||
LPWSTR ext = PathFindExtension(fileNameStr.c_str());
|
||||
int ct = 0;
|
||||
std::wstringstream ss;
|
||||
|
||||
@ -222,13 +223,13 @@ public:
|
||||
|
||||
private:
|
||||
CefRefPtr<DownloadListener> listener_;
|
||||
std::wstring filename_;
|
||||
CefString filename_;
|
||||
FILE* file_;
|
||||
std::vector<std::vector<char>*> pending_data_;
|
||||
};
|
||||
|
||||
CefRefPtr<CefDownloadHandler> CreateDownloadHandler(
|
||||
CefRefPtr<DownloadListener> listener, const std::wstring& fileName)
|
||||
CefRefPtr<DownloadListener> listener, const CefString& fileName)
|
||||
{
|
||||
return new ClientDownloadHandler(listener, fileName);
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ class DownloadListener : public CefBase
|
||||
{
|
||||
public:
|
||||
// Called when the download is complete.
|
||||
virtual void NotifyDownloadComplete(const std::wstring& fileName) =0;
|
||||
virtual void NotifyDownloadComplete(const CefString& fileName) =0;
|
||||
|
||||
// Called if the download fails.
|
||||
virtual void NotifyDownloadError(const std::wstring& fileName) =0;
|
||||
virtual void NotifyDownloadError(const CefString& fileName) =0;
|
||||
};
|
||||
|
||||
// Create a new download handler to manage download of a single file.
|
||||
CefRefPtr<CefDownloadHandler> CreateDownloadHandler(
|
||||
CefRefPtr<DownloadListener> listener, const std::wstring& fileName);
|
||||
CefRefPtr<DownloadListener> listener, const CefString& fileName);
|
||||
|
||||
#endif // _CEFCLIENT_DOWNLOAD_HANDLER_H
|
||||
|
@ -9,18 +9,18 @@
|
||||
class ClientV8ExtensionHandler : public CefThreadSafeBase<CefV8Handler>
|
||||
{
|
||||
public:
|
||||
ClientV8ExtensionHandler() : test_param_(L"An initial string value.") {}
|
||||
ClientV8ExtensionHandler() : test_param_("An initial string value.") {}
|
||||
virtual ~ClientV8ExtensionHandler() {}
|
||||
|
||||
// Execute with the specified argument list and return value. Return true if
|
||||
// the method was handled.
|
||||
virtual bool Execute(const std::wstring& name,
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
std::wstring& exception)
|
||||
CefString& exception)
|
||||
{
|
||||
if(name == L"SetTestParam")
|
||||
if(name == "SetTestParam")
|
||||
{
|
||||
// Handle the SetTestParam native function by saving the string argument
|
||||
// into the local member.
|
||||
@ -30,38 +30,38 @@ public:
|
||||
test_param_ = arguments[0]->GetStringValue();
|
||||
return true;
|
||||
}
|
||||
else if(name == L"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 == L"GetTestObject")
|
||||
else if(name == "GetTestObject")
|
||||
{
|
||||
// Handle the GetTestObject native function by creating and returning a
|
||||
// new V8 object.
|
||||
retval = CefV8Value::CreateObject(NULL);
|
||||
// Add a string parameter to the new V8 object.
|
||||
retval->SetValue(L"param", CefV8Value::CreateString(
|
||||
L"Retrieving a parameter on a native object succeeded."));
|
||||
retval->SetValue("param", CefV8Value::CreateString(
|
||||
"Retrieving a parameter on a native object succeeded."));
|
||||
// Add a function to the new V8 object.
|
||||
retval->SetValue(L"GetMessage",
|
||||
CefV8Value::CreateFunction(L"GetMessage", this));
|
||||
retval->SetValue("GetMessage",
|
||||
CefV8Value::CreateFunction("GetMessage", this));
|
||||
return true;
|
||||
}
|
||||
else if(name == L"GetMessage")
|
||||
else if(name == "GetMessage")
|
||||
{
|
||||
// Handle the GetMessage object function by returning a string.
|
||||
retval = CefV8Value::CreateString(
|
||||
L"Calling a function on a native object succeeded.");
|
||||
"Calling a function on a native object succeeded.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::wstring test_param_;
|
||||
CefString test_param_;
|
||||
};
|
||||
|
||||
|
||||
@ -69,43 +69,43 @@ void InitExtensionTest()
|
||||
{
|
||||
// Register a V8 extension with the below JavaScript code that calls native
|
||||
// methods implemented in ClientV8ExtensionHandler.
|
||||
std::wstring code = L"var cef;"
|
||||
L"if (!cef)"
|
||||
L" cef = {};"
|
||||
L"if (!cef.test)"
|
||||
L" cef.test = {};"
|
||||
L"(function() {"
|
||||
L" cef.test.__defineGetter__('test_param', function() {"
|
||||
L" native function GetTestParam();"
|
||||
L" return GetTestParam();"
|
||||
L" });"
|
||||
L" cef.test.__defineSetter__('test_param', function(b) {"
|
||||
L" native function SetTestParam();"
|
||||
L" if(b) SetTestParam(b);"
|
||||
L" });"
|
||||
L" cef.test.test_object = function() {"
|
||||
L" native function GetTestObject();"
|
||||
L" return GetTestObject();"
|
||||
L" };"
|
||||
L"})();";
|
||||
CefRegisterExtension(L"v8/test", code, new ClientV8ExtensionHandler());
|
||||
std::string code = "var cef;"
|
||||
"if (!cef)"
|
||||
" cef = {};"
|
||||
"if (!cef.test)"
|
||||
" cef.test = {};"
|
||||
"(function() {"
|
||||
" cef.test.__defineGetter__('test_param', function() {"
|
||||
" native function GetTestParam();"
|
||||
" return GetTestParam();"
|
||||
" });"
|
||||
" cef.test.__defineSetter__('test_param', function(b) {"
|
||||
" native function SetTestParam();"
|
||||
" if(b) SetTestParam(b);"
|
||||
" });"
|
||||
" cef.test.test_object = function() {"
|
||||
" native function GetTestObject();"
|
||||
" return GetTestObject();"
|
||||
" };"
|
||||
"})();";
|
||||
CefRegisterExtension("v8/test", code, new ClientV8ExtensionHandler());
|
||||
}
|
||||
|
||||
void RunExtensionTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
std::wstring html =
|
||||
L"<html><body>ClientV8ExtensionHandler says:<br><pre>"
|
||||
L"<script language=\"JavaScript\">"
|
||||
L"cef.test.test_param ="
|
||||
L" 'Assign and retrieve a value succeeded the first time.';"
|
||||
L"document.writeln(cef.test.test_param);"
|
||||
L"cef.test.test_param ="
|
||||
L" 'Assign and retrieve a value succeeded the second time.';"
|
||||
L"document.writeln(cef.test.test_param);"
|
||||
L"var obj = cef.test.test_object();"
|
||||
L"document.writeln(obj.param);"
|
||||
L"document.writeln(obj.GetMessage());"
|
||||
L"</script>"
|
||||
L"</pre></body></html>";
|
||||
browser->GetMainFrame()->LoadString(html, L"about:blank");
|
||||
std::string html =
|
||||
"<html><body>ClientV8ExtensionHandler says:<br><pre>"
|
||||
"<script language=\"JavaScript\">"
|
||||
"cef.test.test_param ="
|
||||
" 'Assign and retrieve a value succeeded the first time.';"
|
||||
"document.writeln(cef.test.test_param);"
|
||||
"cef.test.test_param ="
|
||||
" 'Assign and retrieve a value succeeded the second time.';"
|
||||
"document.writeln(cef.test.test_param);"
|
||||
"var obj = cef.test.test_object();"
|
||||
"document.writeln(obj.param);"
|
||||
"document.writeln(obj.GetMessage());"
|
||||
"</script>"
|
||||
"</pre></body></html>";
|
||||
browser->GetMainFrame()->LoadString(html, "about:blank");
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ void InitPluginTest()
|
||||
{
|
||||
// Structure providing information about the client plugin.
|
||||
CefPluginInfo plugin_info;
|
||||
plugin_info.display_name = L"Client Plugin";
|
||||
plugin_info.unique_name = L"client_plugin";
|
||||
plugin_info.version = L"1, 0, 0, 1";
|
||||
plugin_info.description = L"My Example Client Plugin";
|
||||
plugin_info.display_name = "Client Plugin";
|
||||
plugin_info.unique_name = "client_plugin";
|
||||
plugin_info.version = "1, 0, 0, 1";
|
||||
plugin_info.description = "My Example Client Plugin";
|
||||
|
||||
CefPluginMimeType mime_type;
|
||||
mime_type.mime_type = L"application/x-client-plugin";
|
||||
mime_type.file_extensions.push_back(L"*");
|
||||
mime_type.mime_type = "application/x-client-plugin";
|
||||
mime_type.file_extensions.push_back("*");
|
||||
plugin_info.mime_types.push_back(mime_type);
|
||||
|
||||
plugin_info.np_getentrypoints = NP_GetEntryPoints;
|
||||
@ -29,10 +29,10 @@ void InitPluginTest()
|
||||
|
||||
void RunPluginTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
std::wstring html =
|
||||
L"<html><body>Client Plugin:<br>"
|
||||
L"<embed type=\"application/x-client-plugin\""
|
||||
L"width=600 height=40>"
|
||||
L"</body></html>";
|
||||
browser->GetMainFrame()->LoadString(html, L"about:blank");
|
||||
std::string html =
|
||||
"<html><body>Client Plugin:<br>"
|
||||
"<embed type=\"application/x-client-plugin\""
|
||||
"width=600 height=40>"
|
||||
"</body></html>";
|
||||
browser->GetMainFrame()->LoadString(html, "about:blank");
|
||||
}
|
||||
|
@ -28,13 +28,13 @@ public:
|
||||
// specified number of bytes have been read. If there is a response set
|
||||
// |mime_type| to the mime type for the response.
|
||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||
std::wstring& mime_type, int* response_length)
|
||||
CefString& mime_type, int* response_length)
|
||||
{
|
||||
bool handled = false;
|
||||
|
||||
Lock();
|
||||
std::wstring url = request->GetURL();
|
||||
if(wcsstr(url.c_str(), L"handler.html") != NULL) {
|
||||
std::string url = request->GetURL();
|
||||
if(strstr(url.c_str(), "handler.html") != NULL) {
|
||||
// Build the response html
|
||||
html_ = "<html><head><title>Client Scheme Handler</title></head><body>"
|
||||
"This contents of this page page are served by the "
|
||||
@ -48,9 +48,9 @@ public:
|
||||
html_.append("<pre>");
|
||||
|
||||
// Output a string representation of the request
|
||||
std::wstring dump;
|
||||
std::string dump;
|
||||
DumpRequestContents(request, dump);
|
||||
html_.append(WStringToString(dump));
|
||||
html_.append(dump);
|
||||
|
||||
html_.append("</pre><br/>Try the test form:"
|
||||
"<form method=\"POST\" action=\"handler.html\">"
|
||||
@ -64,10 +64,10 @@ public:
|
||||
bytes_ = html_.c_str();
|
||||
|
||||
// Set the resulting mime type
|
||||
mime_type = L"text/html";
|
||||
mime_type = "text/html";
|
||||
}
|
||||
#ifdef _WIN32
|
||||
else if(wcsstr(url.c_str(), L"client.gif") != NULL) {
|
||||
else if(strstr(url.c_str(), "client.gif") != NULL) {
|
||||
// Load the response image
|
||||
DWORD dwSize;
|
||||
LPBYTE pBytes;
|
||||
@ -76,7 +76,7 @@ public:
|
||||
bytes_ = reinterpret_cast<const char*>(pBytes);
|
||||
handled = true;
|
||||
// Set the resulting mime type
|
||||
mime_type = L"image/jpg";
|
||||
mime_type = "image/jpg";
|
||||
}
|
||||
}
|
||||
#endif // _WIN32
|
||||
@ -140,10 +140,10 @@ public:
|
||||
|
||||
void InitSchemeTest()
|
||||
{
|
||||
CefRegisterScheme(L"client", L"tests", new ClientSchemeHandlerFactory());
|
||||
CefRegisterScheme("client", "tests", new ClientSchemeHandlerFactory());
|
||||
}
|
||||
|
||||
void RunSchemeTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
browser->GetMainFrame()->LoadURL(L"client://tests/handler.html");
|
||||
browser->GetMainFrame()->LoadURL("client://tests/handler.html");
|
||||
}
|
||||
|
@ -5,20 +5,21 @@
|
||||
#include "string_util.h"
|
||||
#include <sstream>
|
||||
|
||||
void DumpRequestContents(CefRefPtr<CefRequest> request, std::wstring& str)
|
||||
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
std::stringstream ss;
|
||||
|
||||
ss << L"URL: " << request->GetURL();
|
||||
ss << L"\nMethod: " << request->GetMethod();
|
||||
ss << "URL: " << std::string(request->GetURL());
|
||||
ss << "\nMethod: " << std::string(request->GetMethod());
|
||||
|
||||
CefRequest::HeaderMap headerMap;
|
||||
request->GetHeaderMap(headerMap);
|
||||
if(headerMap.size() > 0) {
|
||||
ss << L"\nHeaders:";
|
||||
ss << "\nHeaders:";
|
||||
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
|
||||
for(; it != headerMap.end(); ++it) {
|
||||
ss << L"\n\t" << (*it).first << L": " << (*it).second;
|
||||
ss << "\n\t" << std::string((*it).first) << ": " <<
|
||||
std::string((*it).second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,26 +28,26 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::wstring& str)
|
||||
CefPostData::ElementVector elements;
|
||||
postData->GetElements(elements);
|
||||
if(elements.size() > 0) {
|
||||
ss << L"\nPost Data:";
|
||||
ss << "\nPost Data:";
|
||||
CefRefPtr<CefPostDataElement> element;
|
||||
CefPostData::ElementVector::const_iterator it = elements.begin();
|
||||
for(; it != elements.end(); ++it) {
|
||||
element = (*it);
|
||||
if(element->GetType() == PDE_TYPE_BYTES) {
|
||||
// the element is composed of bytes
|
||||
ss << L"\n\tBytes: ";
|
||||
ss << "\n\tBytes: ";
|
||||
if(element->GetBytesCount() == 0)
|
||||
ss << L"(empty)";
|
||||
ss << "(empty)";
|
||||
else {
|
||||
// retrieve the data.
|
||||
size_t size = element->GetBytesCount();
|
||||
char* bytes = new char[size];
|
||||
element->GetBytes(size, bytes);
|
||||
ss << StringToWString(std::string(bytes, size));
|
||||
ss << std::string(bytes, size);
|
||||
delete [] bytes;
|
||||
}
|
||||
} else if(element->GetType() == PDE_TYPE_FILE) {
|
||||
ss << L"\n\tFile: " << element->GetFile();
|
||||
ss << "\n\tFile: " << std::string(element->GetFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -55,19 +56,19 @@ void DumpRequestContents(CefRefPtr<CefRequest> request, std::wstring& str)
|
||||
str = ss.str();
|
||||
}
|
||||
|
||||
std::wstring StringReplace(const std::wstring& str, const std::wstring& from,
|
||||
const std::wstring& to)
|
||||
std::string StringReplace(const std::string& str, const std::string& from,
|
||||
const std::string& to)
|
||||
{
|
||||
std::wstring result = str;
|
||||
std::wstring::size_type pos = 0;
|
||||
std::wstring::size_type from_len = from.length();
|
||||
std::wstring::size_type to_len = to.length();
|
||||
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::wstring::npos) {
|
||||
if(pos != std::string::npos) {
|
||||
result.replace(pos, from_len, to);
|
||||
pos += to_len;
|
||||
}
|
||||
} while(pos != std::wstring::npos);
|
||||
} while(pos != std::string::npos);
|
||||
return result;
|
||||
}
|
||||
|
@ -6,20 +6,12 @@
|
||||
#define _CEFCLIENT_STRING_UTIL_H
|
||||
|
||||
#include "include/cef.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
// Convert a std::string to a std::wstring
|
||||
std::wstring StringToWString(const std::string& s);
|
||||
|
||||
// Convert a std::wstring to a std::string
|
||||
std::string WStringToString(const std::wstring& s);
|
||||
|
||||
// Dump the contents of the request into a string.
|
||||
void DumpRequestContents(CefRefPtr<CefRequest> request, std::wstring& str);
|
||||
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str);
|
||||
|
||||
// Replace all instances of |from| with |to| in |str|.
|
||||
std::wstring StringReplace(const std::wstring& str, const std::wstring& from,
|
||||
const std::wstring& to);
|
||||
std::string StringReplace(const std::string& str, const std::string& from,
|
||||
const std::string& to);
|
||||
|
||||
#endif // _CEFCLIENT_STRING_UTIL_H
|
||||
|
@ -1,22 +0,0 @@
|
||||
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _CEFCLIENT_STRING_UTIL_MAC_H
|
||||
#define _CEFCLIENT_STRING_UTIL_MAC_H
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include <string>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
// Convert a std::wstring to an NSString. The NSString must be released by the
|
||||
// caller.
|
||||
NSString* WStringToNSString(const std::wstring& str);
|
||||
|
||||
// Convert an NSString to a std::wstring.
|
||||
std::wstring NSStringToWString(NSString* str);
|
||||
|
||||
#endif // defined(__APPLE__)
|
||||
|
||||
#endif // _CEFCLIENT_STRING_UTIL_MAC_H
|
@ -1,47 +0,0 @@
|
||||
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "string_util.h"
|
||||
#include "string_util_mac.h"
|
||||
#include "util.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#if TARGET_RT_BIG_ENDIAN
|
||||
#define WCHAR_T_ENCODING NSUTF32BigEndianStringEncoding
|
||||
#else
|
||||
#define WCHAR_T_ENCODING NSUTF32LittleEndianStringEncoding
|
||||
#endif
|
||||
|
||||
std::wstring StringToWString(const std::string& s)
|
||||
{
|
||||
NSString* nsstr = [[NSString alloc] initWithCString:s.c_str()];
|
||||
std::wstring wstr = NSStringToWString(nsstr);
|
||||
[nsstr release];
|
||||
return wstr;
|
||||
}
|
||||
|
||||
std::string WStringToString(const std::wstring& s)
|
||||
{
|
||||
NSString* nsstr = WStringToNSString(s);
|
||||
std::string str = [nsstr UTF8String];
|
||||
[nsstr release];
|
||||
return str;
|
||||
}
|
||||
|
||||
NSString* WStringToNSString(const std::wstring& str)
|
||||
{
|
||||
return [[NSString alloc] initWithBytes:(void*)str.c_str()
|
||||
length:str.length()*4
|
||||
encoding:WCHAR_T_ENCODING];
|
||||
}
|
||||
|
||||
std::wstring NSStringToWString(NSString* str)
|
||||
{
|
||||
NSData* data = [str dataUsingEncoding:WCHAR_T_ENCODING];
|
||||
return std::wstring((wchar_t*)[data bytes],
|
||||
[data length] / sizeof(wchar_t));
|
||||
}
|
||||
|
||||
#endif // defined(__APPLE__)
|
@ -1,35 +0,0 @@
|
||||
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "string_util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
std::wstring StringToWString(const std::string& s)
|
||||
{
|
||||
wchar_t* wch;
|
||||
UINT bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0);
|
||||
wch = new wchar_t[bytes];
|
||||
if(wch)
|
||||
bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, wch, bytes);
|
||||
std::wstring str = wch;
|
||||
delete [] wch;
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string WStringToString(const std::wstring& s)
|
||||
{
|
||||
char* ch;
|
||||
UINT bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0,
|
||||
NULL, NULL);
|
||||
ch = new char[bytes];
|
||||
if(ch)
|
||||
bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, ch, bytes,
|
||||
NULL, NULL);
|
||||
std::string str = ch;
|
||||
delete [] ch;
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
@ -141,9 +141,9 @@ NPError API_CALL NP_UIShutdown(void)
|
||||
// Send the notification to the browser as a JavaScript function call.
|
||||
static void NotifyNewRotation(float value)
|
||||
{
|
||||
std::wstringstream buf;
|
||||
buf << L"notifyNewRotation(" << value << L");";
|
||||
AppGetBrowser()->GetMainFrame()->ExecuteJavaScript(buf.str(), std::wstring(),
|
||||
std::stringstream buf;
|
||||
buf << "notifyNewRotation(" << value << ");";
|
||||
AppGetBrowser()->GetMainFrame()->ExecuteJavaScript(buf.str(), CefString(),
|
||||
0);
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,13 @@ public:
|
||||
|
||||
// Execute with the specified argument list and return value. Return true if
|
||||
// the method was handled.
|
||||
virtual bool Execute(const std::wstring& name,
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
std::wstring& exception)
|
||||
CefString& exception)
|
||||
{
|
||||
if(name == L"modifyRotation") {
|
||||
if(name == "modifyRotation") {
|
||||
// This function requires one argument.
|
||||
if(arguments.size() != 1)
|
||||
return false;
|
||||
@ -40,11 +40,11 @@ public:
|
||||
ModifyRotation(increment);
|
||||
return true;
|
||||
}
|
||||
} else if(name == L"resetRotation") {
|
||||
} else if(name == "resetRotation") {
|
||||
// Reset the rotation value.
|
||||
ResetRotation();
|
||||
return true;
|
||||
} else if(name == L"viewSource") {
|
||||
} else if(name == "viewSource") {
|
||||
// View the page source.
|
||||
AppGetBrowser()->GetMainFrame()->ViewSource();
|
||||
return true;
|
||||
@ -58,14 +58,14 @@ void InitUIPluginTest()
|
||||
{
|
||||
// Structure providing information about the client plugin.
|
||||
CefPluginInfo plugin_info;
|
||||
plugin_info.display_name = L"Client UI Plugin";
|
||||
plugin_info.unique_name = L"client_ui_plugin";
|
||||
plugin_info.version = L"1, 0, 0, 1";
|
||||
plugin_info.description = L"My Example Client UI Plugin";
|
||||
plugin_info.display_name = "Client UI Plugin";
|
||||
plugin_info.unique_name = "client_ui_plugin";
|
||||
plugin_info.version = "1, 0, 0, 1";
|
||||
plugin_info.description = "My Example Client UI Plugin";
|
||||
|
||||
CefPluginMimeType mime_type;
|
||||
mime_type.mime_type = L"application/x-client-ui-plugin";
|
||||
mime_type.file_extensions.push_back(L"*");
|
||||
mime_type.mime_type = "application/x-client-ui-plugin";
|
||||
mime_type.file_extensions.push_back("*");
|
||||
plugin_info.mime_types.push_back(mime_type);
|
||||
|
||||
plugin_info.np_getentrypoints = NP_UIGetEntryPoints;
|
||||
@ -77,29 +77,29 @@ void InitUIPluginTest()
|
||||
|
||||
// Register a V8 extension with the below JavaScript code that calls native
|
||||
// methods implemented in ClientV8UIHandler.
|
||||
std::wstring code = L"var cef;"
|
||||
L"if (!cef)"
|
||||
L" cef = {};"
|
||||
L"if (!cef.uiapp)"
|
||||
L" cef.uiapp = {};"
|
||||
L"(function() {"
|
||||
L" cef.uiapp.modifyRotation = function(val) {"
|
||||
L" native function modifyRotation();"
|
||||
L" return modifyRotation(val);"
|
||||
L" };"
|
||||
L" cef.uiapp.resetRotation = function() {"
|
||||
L" native function resetRotation();"
|
||||
L" return resetRotation();"
|
||||
L" };"
|
||||
L" cef.uiapp.viewSource = function() {"
|
||||
L" native function viewSource();"
|
||||
L" return viewSource();"
|
||||
L" };"
|
||||
L"})();";
|
||||
CefRegisterExtension(L"uiplugin/test", code, new ClientV8UIHandler());
|
||||
std::string code = "var cef;"
|
||||
"if (!cef)"
|
||||
" cef = {};"
|
||||
"if (!cef.uiapp)"
|
||||
" cef.uiapp = {};"
|
||||
"(function() {"
|
||||
" cef.uiapp.modifyRotation = function(val) {"
|
||||
" native function modifyRotation();"
|
||||
" return modifyRotation(val);"
|
||||
" };"
|
||||
" cef.uiapp.resetRotation = function() {"
|
||||
" native function resetRotation();"
|
||||
" return resetRotation();"
|
||||
" };"
|
||||
" cef.uiapp.viewSource = function() {"
|
||||
" native function viewSource();"
|
||||
" return viewSource();"
|
||||
" };"
|
||||
"})();";
|
||||
CefRegisterExtension("uiplugin/test", code, new ClientV8UIHandler());
|
||||
}
|
||||
|
||||
void RunUIPluginTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
browser->GetMainFrame()->LoadURL(L"http://tests/uiapp");
|
||||
browser->GetMainFrame()->LoadURL("http://tests/uiapp");
|
||||
}
|
||||
|
@ -94,11 +94,11 @@ TEST(RequestTest, SetGet)
|
||||
CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
|
||||
ASSERT_TRUE(request.get() != NULL);
|
||||
|
||||
std::wstring url = L"http://tests/run.html";
|
||||
std::wstring method = L"POST";
|
||||
CefString url = "http://tests/run.html";
|
||||
CefString method = "POST";
|
||||
CefRequest::HeaderMap setHeaders, getHeaders;
|
||||
setHeaders.insert(std::make_pair(L"HeaderA", L"ValueA"));
|
||||
setHeaders.insert(std::make_pair(L"HeaderB", L"ValueB"));
|
||||
setHeaders.insert(std::make_pair("HeaderA", "ValueA"));
|
||||
setHeaders.insert(std::make_pair("HeaderB", "ValueB"));
|
||||
|
||||
// CefPostData CreatePostData
|
||||
CefRefPtr<CefPostData> postData(CefPostData::CreatePostData());
|
||||
@ -113,7 +113,7 @@ TEST(RequestTest, SetGet)
|
||||
ASSERT_TRUE(element2.get() != NULL);
|
||||
|
||||
// CefPostDataElement SetToFile
|
||||
std::wstring file = L"c:\\path\\to\\file.ext";
|
||||
CefString file = "c:\\path\\to\\file.ext";
|
||||
element1->SetToFile(file);
|
||||
ASSERT_EQ(PDE_TYPE_FILE, element1->GetType());
|
||||
ASSERT_EQ(file, element1->GetFile());
|
||||
@ -189,12 +189,12 @@ static void CreateRequest(CefRefPtr<CefRequest>& request)
|
||||
request = CefRequest::CreateRequest();
|
||||
ASSERT_TRUE(request.get() != NULL);
|
||||
|
||||
request->SetURL(L"http://tests/run.html");
|
||||
request->SetMethod(L"POST");
|
||||
request->SetURL("http://tests/run.html");
|
||||
request->SetMethod("POST");
|
||||
|
||||
CefRequest::HeaderMap headers;
|
||||
headers.insert(std::make_pair(L"HeaderA", L"ValueA"));
|
||||
headers.insert(std::make_pair(L"HeaderB", L"ValueB"));
|
||||
headers.insert(std::make_pair("HeaderA", "ValueA"));
|
||||
headers.insert(std::make_pair("HeaderB", "ValueB"));
|
||||
request->SetHeaderMap(headers);
|
||||
|
||||
CefRefPtr<CefPostData> postData(CefPostData::CreatePostData());
|
||||
@ -203,7 +203,7 @@ static void CreateRequest(CefRefPtr<CefRequest>& request)
|
||||
CefRefPtr<CefPostDataElement> element1(
|
||||
CefPostDataElement::CreatePostDataElement());
|
||||
ASSERT_TRUE(element1.get() != NULL);
|
||||
element1->SetToFile(L"c:\\path\\to\\file.ext");
|
||||
element1->SetToFile("c:\\path\\to\\file.ext");
|
||||
postData->AddElement(element1);
|
||||
|
||||
CefRefPtr<CefPostDataElement> element2(
|
||||
@ -230,7 +230,7 @@ public:
|
||||
CreateRequest(request_);
|
||||
|
||||
// Create the browser
|
||||
CreateBrowser(std::wstring());
|
||||
CreateBrowser(CefString());
|
||||
}
|
||||
|
||||
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser)
|
||||
@ -257,9 +257,9 @@ public:
|
||||
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType,
|
||||
CefString& mimeType,
|
||||
int loadFlags)
|
||||
{
|
||||
g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled = true;
|
||||
@ -310,10 +310,10 @@ public:
|
||||
CreateRequest(request_);
|
||||
|
||||
// Add the resource that we will navigate to/from
|
||||
AddResource(L"http://tests/goto.html", "<html>To</html>", L"text/html");
|
||||
AddResource("http://tests/goto.html", "<html>To</html>", "text/html");
|
||||
|
||||
// Create the browser
|
||||
CreateBrowser(std::wstring());
|
||||
CreateBrowser(CefString());
|
||||
}
|
||||
|
||||
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser)
|
||||
@ -330,8 +330,8 @@ public:
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavType navType, bool isRedirect)
|
||||
{
|
||||
std::wstring url = request->GetURL();
|
||||
if(url == L"http://tests/run.html")
|
||||
CefString url = request->GetURL();
|
||||
if(url == "http://tests/run.html")
|
||||
{
|
||||
// Verify that the request is the same
|
||||
VerifyRequestEqual(request_, request, true);
|
||||
@ -342,13 +342,13 @@ public:
|
||||
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType,
|
||||
CefString& mimeType,
|
||||
int loadFlags)
|
||||
{
|
||||
std::wstring url = request->GetURL();
|
||||
if(url == L"http://tests/run.html")
|
||||
CefString url = request->GetURL();
|
||||
if(url == "http://tests/run.html")
|
||||
{
|
||||
// Verify that the request is the same
|
||||
VerifyRequestEqual(request_, request, true);
|
||||
@ -368,7 +368,7 @@ public:
|
||||
std::string output = "<html>Request</html>";
|
||||
resourceStream = CefStreamReader::CreateForData((void*)output.c_str(),
|
||||
output.length());
|
||||
mimeType = L"text/html";
|
||||
mimeType = "text/html";
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
else
|
||||
@ -384,14 +384,14 @@ public:
|
||||
{
|
||||
if(!browser->IsPopup() && !frame.get())
|
||||
{
|
||||
std::wstring url = browser->GetMainFrame()->GetURL();
|
||||
if(url == L"http://tests/run.html")
|
||||
CefString url = browser->GetMainFrame()->GetURL();
|
||||
if(url == "http://tests/run.html")
|
||||
{
|
||||
if(!navigated_)
|
||||
{
|
||||
// First resource load, go to the next page
|
||||
navigated_ = true;
|
||||
browser->GetMainFrame()->LoadURL(L"http://tests/goto.html");
|
||||
browser->GetMainFrame()->LoadURL("http://tests/goto.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -71,7 +71,7 @@ static void VerifyStreamWriteBehavior(CefRefPtr<CefStreamWriter> stream,
|
||||
TEST(StreamTest, ReadFile)
|
||||
{
|
||||
const char* fileName = "StreamTest.VerifyReadFile.txt";
|
||||
std::wstring fileNameStr = L"StreamTest.VerifyReadFile.txt";
|
||||
CefString fileNameStr = "StreamTest.VerifyReadFile.txt";
|
||||
std::string contents = "This is my test\ncontents for the file";
|
||||
|
||||
// Create the file
|
||||
@ -116,7 +116,7 @@ TEST(StreamTest, ReadData)
|
||||
TEST(StreamTest, WriteFile)
|
||||
{
|
||||
const char* fileName = "StreamTest.VerifyWriteFile.txt";
|
||||
std::wstring fileNameStr = L"StreamTest.VerifyWriteFile.txt";
|
||||
CefString fileNameStr = "StreamTest.VerifyWriteFile.txt";
|
||||
std::string contents = "This is my test\ncontents for the file";
|
||||
|
||||
// Test the stream
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
CefWindowInfo& createInfo, bool popup,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefRefPtr<CefHandler>& handler,
|
||||
std::wstring& url,
|
||||
CefString& url,
|
||||
CefBrowserSettings& settings)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
@ -49,13 +49,13 @@ public:
|
||||
|
||||
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& url)
|
||||
const CefString& url)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& title)
|
||||
const CefString& title)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -83,22 +83,22 @@ public:
|
||||
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
ErrorCode errorCode,
|
||||
const std::wstring& failedUrl,
|
||||
std::wstring& errorText)
|
||||
const CefString& failedUrl,
|
||||
CefString& errorText)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType,
|
||||
CefString& mimeType,
|
||||
int loadFlags)
|
||||
{
|
||||
Lock();
|
||||
if(resource_map_.size() > 0) {
|
||||
std::wstring url = request->GetURL();
|
||||
CefString url = request->GetURL();
|
||||
ResourceMap::const_iterator it = resource_map_.find(url);
|
||||
if(it != resource_map_.end()) {
|
||||
// Return the previously mapped resource
|
||||
@ -113,8 +113,8 @@ public:
|
||||
}
|
||||
|
||||
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& mimeType,
|
||||
const std::wstring& fileName,
|
||||
const CefString& mimeType,
|
||||
const CefString& fileName,
|
||||
int64 contentLength,
|
||||
CefRefPtr<CefDownloadHandler>& handler)
|
||||
{
|
||||
@ -129,7 +129,7 @@ public:
|
||||
|
||||
|
||||
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId, std::wstring& label)
|
||||
MenuId menuId, CefString& label)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -149,39 +149,39 @@ public:
|
||||
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefPrintInfo& printInfo,
|
||||
const std::wstring& url,
|
||||
const std::wstring& title,
|
||||
const CefString& url,
|
||||
const CefString& title,
|
||||
int currentPage, int maxPages,
|
||||
std::wstring& topLeft,
|
||||
std::wstring& topCenter,
|
||||
std::wstring& topRight,
|
||||
std::wstring& bottomLeft,
|
||||
std::wstring& bottomCenter,
|
||||
std::wstring& bottomRight)
|
||||
CefString& topLeft,
|
||||
CefString& topCenter,
|
||||
CefString& topRight,
|
||||
CefString& bottomLeft,
|
||||
CefString& bottomCenter,
|
||||
CefString& bottomRight)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& message)
|
||||
const CefString& message)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& message, bool& retval)
|
||||
const CefString& message, bool& retval)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& message,
|
||||
const std::wstring& defaultValue,
|
||||
const CefString& message,
|
||||
const CefString& defaultValue,
|
||||
bool& retval,
|
||||
std::wstring& result)
|
||||
CefString& result)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -228,14 +228,14 @@ public:
|
||||
}
|
||||
|
||||
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||
std::wstring& text)
|
||||
CefString& text)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& message,
|
||||
const std::wstring& source, int line)
|
||||
const CefString& message,
|
||||
const CefString& source, int line)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
@ -283,18 +283,18 @@ protected:
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CreateBrowser(const std::wstring& url)
|
||||
void CreateBrowser(const CefString& url)
|
||||
{
|
||||
CefWindowInfo windowInfo;
|
||||
#if defined(OS_WIN)
|
||||
windowInfo.SetAsPopup(NULL, L"CefUnitTest");
|
||||
windowInfo.SetAsPopup(NULL, "CefUnitTest");
|
||||
windowInfo.m_dwStyle |= WS_VISIBLE;
|
||||
#endif
|
||||
CefBrowser::CreateBrowser(windowInfo, false, this, url);
|
||||
}
|
||||
|
||||
void AddResource(const std::wstring& key, const std::string& value,
|
||||
const std::wstring& mimeType)
|
||||
void AddResource(const CefString& key, const std::string& value,
|
||||
const CefString& mimeType)
|
||||
{
|
||||
resource_map_.insert(std::make_pair(key, std::make_pair(value, mimeType)));
|
||||
}
|
||||
@ -315,7 +315,7 @@ private:
|
||||
base::WaitableEvent completion_event_;
|
||||
|
||||
// Map of resources that can be automatically loaded
|
||||
typedef std::map<std::wstring, std::pair<std::string, std::wstring> > ResourceMap;
|
||||
typedef std::map<CefString, std::pair<std::string, CefString> > ResourceMap;
|
||||
ResourceMap resource_map_;
|
||||
};
|
||||
|
||||
|
@ -14,23 +14,23 @@ class V8TestV8Handler : public CefThreadSafeBase<CefV8Handler>
|
||||
public:
|
||||
V8TestV8Handler(bool bindingTest) { binding_test_ = bindingTest; }
|
||||
|
||||
virtual bool Execute(const std::wstring& name,
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
std::wstring& exception)
|
||||
CefString& exception)
|
||||
{
|
||||
TestExecute(name, object, arguments, retval, exception);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestExecute(const std::wstring& name,
|
||||
void TestExecute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
std::wstring& exception)
|
||||
CefString& exception)
|
||||
{
|
||||
if(name == L"execute") {
|
||||
if(name == "execute") {
|
||||
g_V8TestV8HandlerExecuteCalled = true;
|
||||
|
||||
ASSERT_EQ((size_t)8, arguments.size());
|
||||
@ -50,7 +50,7 @@ public:
|
||||
argct++;
|
||||
|
||||
ASSERT_TRUE(arguments[argct]->IsString());
|
||||
ASSERT_EQ(L"test string", arguments[argct]->GetStringValue());
|
||||
ASSERT_EQ(arguments[argct]->GetStringValue(), "test string");
|
||||
argct++;
|
||||
|
||||
CefRefPtr<CefV8Value> value;
|
||||
@ -81,7 +81,7 @@ public:
|
||||
value = arguments[argct]->GetValue(subargct);
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsString());
|
||||
ASSERT_EQ(L"another string", value->GetStringValue());
|
||||
ASSERT_EQ(value->GetStringValue(), "another string");
|
||||
subargct++;
|
||||
}
|
||||
argct++;
|
||||
@ -89,25 +89,25 @@ public:
|
||||
// object
|
||||
ASSERT_TRUE(arguments[argct]->IsObject());
|
||||
{
|
||||
value = arguments[argct]->GetValue(L"arg0");
|
||||
value = arguments[argct]->GetValue("arg0");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsInt());
|
||||
ASSERT_EQ(2, value->GetIntValue());
|
||||
|
||||
value = arguments[argct]->GetValue(L"arg1");
|
||||
value = arguments[argct]->GetValue("arg1");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsDouble());
|
||||
ASSERT_EQ(3.433, value->GetDoubleValue());
|
||||
|
||||
value = arguments[argct]->GetValue(L"arg2");
|
||||
value = arguments[argct]->GetValue("arg2");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsBool());
|
||||
ASSERT_EQ(true, value->GetBoolValue());
|
||||
|
||||
value = arguments[argct]->GetValue(L"arg3");
|
||||
value = arguments[argct]->GetValue("arg3");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsString());
|
||||
ASSERT_EQ(L"some string", value->GetStringValue());
|
||||
ASSERT_EQ(value->GetStringValue(), "some string");
|
||||
}
|
||||
argct++;
|
||||
|
||||
@ -118,9 +118,9 @@ public:
|
||||
args.push_back(CefV8Value::CreateInt(5));
|
||||
args.push_back(CefV8Value::CreateDouble(3.5));
|
||||
args.push_back(CefV8Value::CreateBool(true));
|
||||
args.push_back(CefV8Value::CreateString(L"10"));
|
||||
args.push_back(CefV8Value::CreateString("10"));
|
||||
CefRefPtr<CefV8Value> rv;
|
||||
std::wstring exception;
|
||||
CefString exception;
|
||||
ASSERT_TRUE(arguments[argct]->ExecuteFunction(
|
||||
arguments[argct], args, rv, exception));
|
||||
ASSERT_TRUE(rv.get() != NULL);
|
||||
@ -136,37 +136,37 @@ public:
|
||||
args.push_back(CefV8Value::CreateDouble(5));
|
||||
args.push_back(CefV8Value::CreateDouble(0));
|
||||
CefRefPtr<CefV8Value> rv;
|
||||
std::wstring exception;
|
||||
CefString exception;
|
||||
ASSERT_TRUE(arguments[argct]->ExecuteFunction(
|
||||
arguments[argct], args, rv, exception));
|
||||
ASSERT_EQ(L"Uncaught My Exception", exception);
|
||||
ASSERT_EQ(exception, "Uncaught My Exception");
|
||||
}
|
||||
argct++;
|
||||
|
||||
if(binding_test_)
|
||||
{
|
||||
// values
|
||||
value = object->GetValue(L"intVal");
|
||||
value = object->GetValue("intVal");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsInt());
|
||||
ASSERT_EQ(12, value->GetIntValue());
|
||||
|
||||
value = object->GetValue(L"doubleVal");
|
||||
value = object->GetValue("doubleVal");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsDouble());
|
||||
ASSERT_EQ(5.432, value->GetDoubleValue());
|
||||
|
||||
value = object->GetValue(L"boolVal");
|
||||
value = object->GetValue("boolVal");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsBool());
|
||||
ASSERT_EQ(true, value->GetBoolValue());
|
||||
|
||||
value = object->GetValue(L"stringVal");
|
||||
value = object->GetValue("stringVal");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsString());
|
||||
ASSERT_EQ(L"the string", value->GetStringValue());
|
||||
ASSERT_EQ(value->GetStringValue(), "the string");
|
||||
|
||||
value = object->GetValue(L"arrayVal");
|
||||
value = object->GetValue("arrayVal");
|
||||
ASSERT_TRUE(value.get() != NULL);
|
||||
ASSERT_TRUE(value->IsArray());
|
||||
{
|
||||
@ -193,13 +193,13 @@ public:
|
||||
value2 = value->GetValue(subargct);
|
||||
ASSERT_TRUE(value2.get() != NULL);
|
||||
ASSERT_TRUE(value2->IsString());
|
||||
ASSERT_EQ(L"a string", value2->GetStringValue());
|
||||
ASSERT_EQ(value2->GetStringValue(), "a string");
|
||||
subargct++;
|
||||
}
|
||||
}
|
||||
|
||||
retval = CefV8Value::CreateInt(5);
|
||||
} else if(name == L"execute2") {
|
||||
} else if(name == "execute2") {
|
||||
g_V8TestV8HandlerExecute2Called = true;
|
||||
|
||||
// check the result of calling the "execute" function
|
||||
@ -242,8 +242,8 @@ public:
|
||||
"</script>"
|
||||
"</body></html>";
|
||||
|
||||
AddResource(L"http://tests/run.html", testHtml.str(), L"text/html");
|
||||
CreateBrowser(L"http://tests/run.html");
|
||||
AddResource("http://tests/run.html", testHtml.str(), "text/html");
|
||||
CreateBrowser("http://tests/run.html");
|
||||
}
|
||||
|
||||
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
@ -272,7 +272,7 @@ public:
|
||||
// Create the new V8 object
|
||||
CefRefPtr<CefV8Value> testObj = CefV8Value::CreateObject(NULL);
|
||||
ASSERT_TRUE(testObj.get() != NULL);
|
||||
ASSERT_TRUE(object->SetValue(L"test", testObj));
|
||||
ASSERT_TRUE(object->SetValue("test", testObj));
|
||||
|
||||
// Create an instance of V8ExecuteV8Handler
|
||||
CefRefPtr<CefV8Handler> testHandler(new V8TestV8Handler(true));
|
||||
@ -280,30 +280,30 @@ public:
|
||||
|
||||
// Add the functions
|
||||
CefRefPtr<CefV8Value> testFunc;
|
||||
testFunc = CefV8Value::CreateFunction(L"execute", testHandler);
|
||||
testFunc = CefV8Value::CreateFunction("execute", testHandler);
|
||||
ASSERT_TRUE(testFunc.get() != NULL);
|
||||
ASSERT_TRUE(testObj->SetValue(L"execute", testFunc));
|
||||
testFunc = CefV8Value::CreateFunction(L"execute2", testHandler);
|
||||
ASSERT_TRUE(testObj->SetValue("execute", testFunc));
|
||||
testFunc = CefV8Value::CreateFunction("execute2", testHandler);
|
||||
ASSERT_TRUE(testFunc.get() != NULL);
|
||||
ASSERT_TRUE(testObj->SetValue(L"execute2", testFunc));
|
||||
ASSERT_TRUE(testObj->SetValue("execute2", testFunc));
|
||||
|
||||
// Add the values
|
||||
ASSERT_TRUE(testObj->SetValue(L"intVal",
|
||||
ASSERT_TRUE(testObj->SetValue("intVal",
|
||||
CefV8Value::CreateInt(12)));
|
||||
ASSERT_TRUE(testObj->SetValue(L"doubleVal",
|
||||
ASSERT_TRUE(testObj->SetValue("doubleVal",
|
||||
CefV8Value::CreateDouble(5.432)));
|
||||
ASSERT_TRUE(testObj->SetValue(L"boolVal",
|
||||
ASSERT_TRUE(testObj->SetValue("boolVal",
|
||||
CefV8Value::CreateBool(true)));
|
||||
ASSERT_TRUE(testObj->SetValue(L"stringVal",
|
||||
CefV8Value::CreateString(L"the string")));
|
||||
ASSERT_TRUE(testObj->SetValue("stringVal",
|
||||
CefV8Value::CreateString("the string")));
|
||||
|
||||
CefRefPtr<CefV8Value> testArray(CefV8Value::CreateArray());
|
||||
ASSERT_TRUE(testArray.get() != NULL);
|
||||
ASSERT_TRUE(testObj->SetValue(L"arrayVal", testArray));
|
||||
ASSERT_TRUE(testObj->SetValue("arrayVal", testArray));
|
||||
ASSERT_TRUE(testArray->SetValue(0, CefV8Value::CreateInt(4)));
|
||||
ASSERT_TRUE(testArray->SetValue(1, CefV8Value::CreateDouble(120.43)));
|
||||
ASSERT_TRUE(testArray->SetValue(2, CefV8Value::CreateBool(true)));
|
||||
ASSERT_TRUE(testArray->SetValue(3, CefV8Value::CreateString(L"a string")));
|
||||
ASSERT_TRUE(testArray->SetValue(3, CefV8Value::CreateString("a string")));
|
||||
}
|
||||
|
||||
bool binding_test_;
|
||||
@ -328,21 +328,21 @@ TEST(V8Test, Extension)
|
||||
g_V8TestV8HandlerExecuteCalled = false;
|
||||
g_V8TestV8HandlerExecute2Called = false;
|
||||
|
||||
std::wstring extensionCode =
|
||||
L"var test;"
|
||||
L"if (!test)"
|
||||
L" test = {};"
|
||||
L"(function() {"
|
||||
L" test.execute = function(a,b,c,d,e,f,g,h) {"
|
||||
L" native function execute();"
|
||||
L" return execute(a,b,c,d,e,f,g,h);"
|
||||
L" };"
|
||||
L" test.execute2 = function(a) {"
|
||||
L" native function execute2();"
|
||||
L" return execute2(a);"
|
||||
L" };"
|
||||
L"})();";
|
||||
CefRegisterExtension(L"v8/test", extensionCode, new V8TestV8Handler(false));
|
||||
std::string extensionCode =
|
||||
"var test;"
|
||||
"if (!test)"
|
||||
" test = {};"
|
||||
"(function() {"
|
||||
" test.execute = function(a,b,c,d,e,f,g,h) {"
|
||||
" native function execute();"
|
||||
" return execute(a,b,c,d,e,f,g,h);"
|
||||
" };"
|
||||
" test.execute2 = function(a) {"
|
||||
" native function execute2();"
|
||||
" return execute2(a);"
|
||||
" };"
|
||||
"})();";
|
||||
CefRegisterExtension("v8/test", extensionCode, new V8TestV8Handler(false));
|
||||
|
||||
CefRefPtr<V8TestHandler> handler = new V8TestHandler(false);
|
||||
handler->ExecuteTest();
|
||||
|
@ -40,40 +40,40 @@ TEST(XmlReaderTest, Read)
|
||||
// Create the XML reader.
|
||||
CefRefPtr<CefXmlReader> reader(
|
||||
CefXmlReader::Create(stream, XML_ENCODING_NONE,
|
||||
L"http://www.example.org/example.xml"));
|
||||
"http://www.example.org/example.xml"));
|
||||
ASSERT_TRUE(reader.get() != NULL);
|
||||
|
||||
// Move to the processing instruction node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 0);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_PROCESSING_INSTRUCTION);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"my_instruction");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"my_instruction");
|
||||
ASSERT_EQ(reader->GetLocalName(), "my_instruction");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "my_instruction");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L"my_value");
|
||||
ASSERT_EQ(reader->GetValue(), "my_value");
|
||||
|
||||
// Move to the DOCTYPE node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 0);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_DOCUMENT_TYPE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"my_document");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"my_document");
|
||||
ASSERT_EQ(reader->GetLocalName(), "my_document");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "my_document");
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
|
||||
// Move to ns:obj element start node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 0);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"obj");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:obj");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "obj");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:obj");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_TRUE(reader->HasAttributes());
|
||||
ASSERT_EQ(reader->GetAttributeCount(), (size_t)1);
|
||||
ASSERT_EQ(reader->GetAttribute(0), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetAttribute(L"xmlns:ns"), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetAttribute(L"ns", L"http://www.w3.org/2000/xmlns/"),
|
||||
L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetAttribute(0), "http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetAttribute("xmlns:ns"), "http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetAttribute("ns", "http://www.w3.org/2000/xmlns/"),
|
||||
"http://www.example.org/ns");
|
||||
|
||||
// Move to the whitespace node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
@ -83,10 +83,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objA");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objA");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objA");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objA");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -95,19 +95,19 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"#text");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"#text");
|
||||
ASSERT_EQ(reader->GetLocalName(), "#text");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "#text");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L"value A");
|
||||
ASSERT_EQ(reader->GetValue(), "value A");
|
||||
|
||||
// Move to the ns:objA element ending node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objA");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objA");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objA");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objA");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -121,10 +121,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_COMMENT);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"#comment");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"#comment");
|
||||
ASSERT_EQ(reader->GetLocalName(), "#comment");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "#comment");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L" my comment ");
|
||||
ASSERT_EQ(reader->GetValue(), " my comment ");
|
||||
|
||||
// Move to the whitespace node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
@ -134,10 +134,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -150,10 +150,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_1");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_1");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -163,16 +163,16 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_EQ(reader->GetDepth(), 3);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L"value B1");
|
||||
ASSERT_EQ(reader->GetValue(), "value B1");
|
||||
|
||||
// Move to the ns:objB_1 element ending node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_1");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_1");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -185,10 +185,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_2");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_2");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -198,16 +198,16 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_EQ(reader->GetDepth(), 3);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_CDATA);
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L"some <br/> data");
|
||||
ASSERT_EQ(reader->GetValue(), "some <br/> data");
|
||||
|
||||
// Move to the ns:objB_2 element ending node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_2");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_2");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -220,10 +220,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_3");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_3");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_3");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_3");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -232,19 +232,19 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 3);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ENTITY_REFERENCE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"EB");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"EB");
|
||||
ASSERT_EQ(reader->GetLocalName(), "EB");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "EB");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L"EB Value");
|
||||
ASSERT_EQ(reader->GetValue(), "EB Value");
|
||||
|
||||
// Move to the ns:objB_3 element ending node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_3");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_3");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_3");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_3");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -257,24 +257,24 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_4");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_4");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_4");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_4");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetInnerXml(), L"<b>this is</b> mixed content &EA;");
|
||||
ASSERT_EQ(reader->GetInnerXml(), "<b>this is</b> mixed content &EA;");
|
||||
ASSERT_EQ(reader->GetOuterXml(),
|
||||
L"<ns:objB_4 xmlns:ns=\"http://www.example.org/ns\">"
|
||||
L"<b>this is</b> mixed content &EA;</ns:objB_4>");
|
||||
"<ns:objB_4 xmlns:ns=\"http://www.example.org/ns\">"
|
||||
"<b>this is</b> mixed content &EA;</ns:objB_4>");
|
||||
|
||||
// Move to the <b> element node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 3);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"b");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"b");
|
||||
ASSERT_EQ(reader->GetLocalName(), "b");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "b");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -283,44 +283,44 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 4);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"#text");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"#text");
|
||||
ASSERT_EQ(reader->GetLocalName(), "#text");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "#text");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L"this is");
|
||||
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(), L"b");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"b");
|
||||
ASSERT_EQ(reader->GetLocalName(), "b");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "b");
|
||||
|
||||
// Move to the text node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 3);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"#text");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"#text");
|
||||
ASSERT_EQ(reader->GetLocalName(), "#text");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "#text");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L" mixed content ");
|
||||
ASSERT_EQ(reader->GetValue(), " mixed content ");
|
||||
|
||||
// Move to the EA entity reference node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 3);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ENTITY_REFERENCE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"EA");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"EA");
|
||||
ASSERT_EQ(reader->GetLocalName(), "EA");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "EA");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetValue(), L"EA Value");
|
||||
ASSERT_EQ(reader->GetValue(), "EA Value");
|
||||
|
||||
// Move to the ns:objB_4 element ending node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB_4");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB_4");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB_4");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_4");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -333,10 +333,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objB");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objB");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objB");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -349,48 +349,48 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objC");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objC");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objC");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_TRUE(reader->IsEmptyElement());
|
||||
ASSERT_TRUE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
ASSERT_EQ(reader->GetAttributeCount(), (size_t)2);
|
||||
ASSERT_EQ(reader->GetAttribute(0), L"value C1");
|
||||
ASSERT_EQ(reader->GetAttribute(L"ns:attr1"), L"value C1");
|
||||
ASSERT_EQ(reader->GetAttribute(L"attr1", L"http://www.example.org/ns"),
|
||||
L"value C1");
|
||||
ASSERT_EQ(reader->GetAttribute(1), L"value C2");
|
||||
ASSERT_EQ(reader->GetAttribute(L"ns:attr2"), L"value C2");
|
||||
ASSERT_EQ(reader->GetAttribute(L"attr2", L"http://www.example.org/ns"),
|
||||
L"value C2");
|
||||
ASSERT_EQ(reader->GetAttribute(0), "value C1");
|
||||
ASSERT_EQ(reader->GetAttribute("ns:attr1"), "value C1");
|
||||
ASSERT_EQ(reader->GetAttribute("attr1", "http://www.example.org/ns"),
|
||||
"value C1");
|
||||
ASSERT_EQ(reader->GetAttribute(1), "value C2");
|
||||
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);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"attr1");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:attr1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "attr1");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_EQ(reader->GetValue(), L"value C1");
|
||||
ASSERT_EQ(reader->GetValue(), "value C1");
|
||||
|
||||
// Move to the ns:attr2 attribute.
|
||||
ASSERT_TRUE(reader->MoveToNextAttribute());
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"attr2");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:attr2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "attr2");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_EQ(reader->GetValue(), L"value C2");
|
||||
ASSERT_EQ(reader->GetValue(), "value C2");
|
||||
|
||||
// No more attributes.
|
||||
ASSERT_FALSE(reader->MoveToNextAttribute());
|
||||
@ -399,60 +399,60 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToCarryingElement());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objC");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
|
||||
|
||||
// Move to the ns:attr1 attribute.
|
||||
ASSERT_TRUE(reader->MoveToAttribute(0));
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"attr1");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:attr1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "attr1");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_EQ(reader->GetValue(), L"value C1");
|
||||
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(), L"ns:objC");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
|
||||
|
||||
// Move to the ns:attr2 attribute.
|
||||
ASSERT_TRUE(reader->MoveToAttribute(L"ns:attr2"));
|
||||
ASSERT_TRUE(reader->MoveToAttribute("ns:attr2"));
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"attr2");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:attr2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "attr2");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr2");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_EQ(reader->GetValue(), L"value C2");
|
||||
ASSERT_EQ(reader->GetValue(), "value C2");
|
||||
|
||||
// Move to the ns:attr1 attribute without returning to the ns:objC element.
|
||||
ASSERT_TRUE(reader->MoveToAttribute(L"attr1", L"http://www.example.org/ns"));
|
||||
ASSERT_TRUE(reader->MoveToAttribute("attr1", "http://www.example.org/ns"));
|
||||
ASSERT_EQ(reader->GetDepth(), 2);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"attr1");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:attr1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "attr1");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr1");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_TRUE(reader->HasValue());
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_EQ(reader->GetValue(), L"value C1");
|
||||
ASSERT_EQ(reader->GetValue(), "value C1");
|
||||
|
||||
// Move to the ns:objD element start node.
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objD");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objD");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objD");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objD");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -461,9 +461,9 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 1);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"objD");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:objD");
|
||||
ASSERT_EQ(reader->GetLocalName(), "objD");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:objD");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_FALSE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -476,10 +476,10 @@ TEST(XmlReaderTest, Read)
|
||||
ASSERT_TRUE(reader->MoveToNextNode());
|
||||
ASSERT_EQ(reader->GetDepth(), 0);
|
||||
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
||||
ASSERT_EQ(reader->GetLocalName(), L"obj");
|
||||
ASSERT_EQ(reader->GetPrefix(), L"ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), L"ns:obj");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), L"http://www.example.org/ns");
|
||||
ASSERT_EQ(reader->GetLocalName(), "obj");
|
||||
ASSERT_EQ(reader->GetPrefix(), "ns");
|
||||
ASSERT_EQ(reader->GetQualifiedName(), "ns:obj");
|
||||
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
||||
ASSERT_FALSE(reader->IsEmptyElement());
|
||||
ASSERT_TRUE(reader->HasAttributes());
|
||||
ASSERT_FALSE(reader->HasValue());
|
||||
@ -509,7 +509,7 @@ TEST(XmlReaderTest, ReadError)
|
||||
// Create the XML reader.
|
||||
CefRefPtr<CefXmlReader> reader(
|
||||
CefXmlReader::Create(stream, XML_ENCODING_NONE,
|
||||
L"http://www.example.org/example.xml"));
|
||||
"http://www.example.org/example.xml"));
|
||||
ASSERT_TRUE(reader.get() != NULL);
|
||||
|
||||
// Move to the processing instruction node and generate parser error.
|
||||
@ -526,22 +526,22 @@ TEST(XmlReaderTest, ObjectLoad)
|
||||
ASSERT_TRUE(stream.get() != NULL);
|
||||
|
||||
// Create the XML reader.
|
||||
CefRefPtr<CefXmlObject> object(new CefXmlObject(L"object"));
|
||||
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
|
||||
ASSERT_TRUE(object->Load(stream, XML_ENCODING_NONE,
|
||||
L"http://www.example.org/example.xml", NULL));
|
||||
"http://www.example.org/example.xml", NULL));
|
||||
|
||||
ASSERT_FALSE(object->HasAttributes());
|
||||
ASSERT_TRUE(object->HasChildren());
|
||||
ASSERT_EQ(object->GetChildCount(), (size_t)1);
|
||||
|
||||
CefRefPtr<CefXmlObject> obj(object->FindChild(L"ns:obj"));
|
||||
CefRefPtr<CefXmlObject> obj(object->FindChild("ns:obj"));
|
||||
ASSERT_TRUE(obj.get());
|
||||
ASSERT_TRUE(obj->HasChildren());
|
||||
ASSERT_EQ(obj->GetChildCount(), (size_t)4);
|
||||
|
||||
CefRefPtr<CefXmlObject> obj_child(obj->FindChild(L"ns:objC"));
|
||||
CefRefPtr<CefXmlObject> obj_child(obj->FindChild("ns:objC"));
|
||||
ASSERT_TRUE(obj_child.get());
|
||||
ASSERT_EQ(obj_child->GetName(), L"ns:objC");
|
||||
ASSERT_EQ(obj_child->GetName(), "ns:objC");
|
||||
ASSERT_FALSE(obj_child->HasChildren());
|
||||
ASSERT_FALSE(obj_child->HasValue());
|
||||
ASSERT_TRUE(obj_child->HasAttributes());
|
||||
@ -556,26 +556,26 @@ TEST(XmlReaderTest, ObjectLoad)
|
||||
ASSERT_TRUE(obj_child.get());
|
||||
if (ct == 0) {
|
||||
// ns:objA
|
||||
ASSERT_EQ(obj_child->GetName(), L"ns:objA");
|
||||
ASSERT_EQ(obj_child->GetName(), "ns:objA");
|
||||
ASSERT_FALSE(obj_child->HasChildren());
|
||||
ASSERT_TRUE(obj_child->HasValue());
|
||||
ASSERT_FALSE(obj_child->HasAttributes());
|
||||
ASSERT_EQ(obj_child->GetValue(), L"value A");
|
||||
ASSERT_EQ(obj_child->GetValue(), "value A");
|
||||
} else if (ct == 1) {
|
||||
// ns:objB
|
||||
ASSERT_EQ(obj_child->GetName(), L"ns:objB");
|
||||
ASSERT_EQ(obj_child->GetName(), "ns:objB");
|
||||
ASSERT_TRUE(obj_child->HasChildren());
|
||||
ASSERT_FALSE(obj_child->HasValue());
|
||||
ASSERT_FALSE(obj_child->HasAttributes());
|
||||
ASSERT_EQ(obj_child->GetChildCount(), (size_t)4);
|
||||
obj_child = obj_child->FindChild(L"ns:objB_4");
|
||||
obj_child = obj_child->FindChild("ns:objB_4");
|
||||
ASSERT_TRUE(obj_child.get());
|
||||
ASSERT_TRUE(obj_child->HasValue());
|
||||
ASSERT_EQ(obj_child->GetValue(),
|
||||
L"<b>this is</b> mixed content EA Value");
|
||||
"<b>this is</b> mixed content EA Value");
|
||||
} else if (ct == 2) {
|
||||
// ns:objC
|
||||
ASSERT_EQ(obj_child->GetName(), L"ns:objC");
|
||||
ASSERT_EQ(obj_child->GetName(), "ns:objC");
|
||||
ASSERT_FALSE(obj_child->HasChildren());
|
||||
ASSERT_FALSE(obj_child->HasValue());
|
||||
ASSERT_TRUE(obj_child->HasAttributes());
|
||||
@ -583,17 +583,17 @@ TEST(XmlReaderTest, ObjectLoad)
|
||||
CefXmlObject::AttributeMap attribs;
|
||||
ASSERT_EQ(obj_child->GetAttributes(attribs), (size_t)2);
|
||||
ASSERT_EQ(attribs.size(), (size_t)2);
|
||||
ASSERT_EQ(attribs[L"ns:attr1"], L"value C1");
|
||||
ASSERT_EQ(attribs[L"ns:attr2"], L"value C2");
|
||||
ASSERT_EQ(attribs["ns:attr1"], "value C1");
|
||||
ASSERT_EQ(attribs["ns:attr2"], "value C2");
|
||||
|
||||
ASSERT_EQ(obj_child->GetAttributeCount(), (size_t)2);
|
||||
ASSERT_TRUE(obj_child->HasAttribute(L"ns:attr1"));
|
||||
ASSERT_EQ(obj_child->GetAttributeValue(L"ns:attr1"), L"value C1");
|
||||
ASSERT_TRUE(obj_child->HasAttribute(L"ns:attr2"));
|
||||
ASSERT_EQ(obj_child->GetAttributeValue(L"ns:attr2"), L"value C2");
|
||||
ASSERT_TRUE(obj_child->HasAttribute("ns:attr1"));
|
||||
ASSERT_EQ(obj_child->GetAttributeValue("ns:attr1"), "value C1");
|
||||
ASSERT_TRUE(obj_child->HasAttribute("ns:attr2"));
|
||||
ASSERT_EQ(obj_child->GetAttributeValue("ns:attr2"), "value C2");
|
||||
} else if (ct == 3) {
|
||||
// ns:objD
|
||||
ASSERT_EQ(obj_child->GetName(), L"ns:objD");
|
||||
ASSERT_EQ(obj_child->GetName(), "ns:objD");
|
||||
ASSERT_FALSE(obj_child->HasChildren());
|
||||
ASSERT_FALSE(obj_child->HasValue());
|
||||
ASSERT_FALSE(obj_child->HasAttributes());
|
||||
@ -613,14 +613,14 @@ TEST(XmlReaderTest, ObjectLoadError)
|
||||
CefStreamReader::CreateForData(error_xml, sizeof(error_xml) - 1));
|
||||
ASSERT_TRUE(stream.get() != NULL);
|
||||
|
||||
std::wstring error_str;
|
||||
CefString error_str;
|
||||
|
||||
// Create the XML reader.
|
||||
CefRefPtr<CefXmlObject> object(new CefXmlObject(L"object"));
|
||||
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
|
||||
ASSERT_FALSE(object->Load(stream, XML_ENCODING_NONE,
|
||||
L"http://www.example.org/example.xml", &error_str));
|
||||
"http://www.example.org/example.xml", &error_str));
|
||||
ASSERT_EQ(error_str,
|
||||
L"Opening and ending tag mismatch: foo line 2 and obj, line 3");
|
||||
"Opening and ending tag mismatch: foo line 2 and obj, line 3");
|
||||
}
|
||||
|
||||
// Test value following child error.
|
||||
@ -632,13 +632,13 @@ TEST(XmlReaderTest, ObjectLoadError)
|
||||
CefStreamReader::CreateForData(error_xml, sizeof(error_xml) - 1));
|
||||
ASSERT_TRUE(stream.get() != NULL);
|
||||
|
||||
std::wstring error_str;
|
||||
CefString error_str;
|
||||
|
||||
// Create the XML reader.
|
||||
CefRefPtr<CefXmlObject> object(new CefXmlObject(L"object"));
|
||||
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
|
||||
ASSERT_FALSE(object->Load(stream, XML_ENCODING_NONE,
|
||||
L"http://www.example.org/example.xml", &error_str));
|
||||
"http://www.example.org/example.xml", &error_str));
|
||||
ASSERT_EQ(error_str,
|
||||
L"Value following child element, line 4");
|
||||
"Value following child element, line 4");
|
||||
}
|
||||
}
|
||||
|
@ -139,57 +139,57 @@ TEST(ZipReaderTest, Read)
|
||||
|
||||
// Walk through the archive contents.
|
||||
ASSERT_TRUE(reader->MoveToFirstFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/file 1.txt");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/file 1.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 19);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_TRUE(reader->OpenFile(""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 19);
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1.", 19));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 1/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/file 1a.txt");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 1/file 1a.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_TRUE(reader->OpenFile(""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1A.", 20));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/file 1b.txt");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 1/file 1b.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_TRUE(reader->OpenFile(""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1B.", 20));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/folder 1a/");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 1/folder 1a/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(),
|
||||
L"test_archive/folder 1/folder 1a/file 1a1.txt");
|
||||
"test_archive/folder 1/folder 1a/file 1a1.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 21);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_TRUE(reader->OpenFile(""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 21);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1A1.", 21));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 2/");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 2/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 2/file 2a.txt");
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 2/file 2a.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_TRUE(reader->OpenFile(""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 2A.", 20));
|
||||
@ -197,16 +197,16 @@ TEST(ZipReaderTest, Read)
|
||||
ASSERT_FALSE(reader->MoveToNextFile());
|
||||
|
||||
// Try seeking a particular file
|
||||
ASSERT_TRUE(reader->MoveToFile(L"TEST_ARCHIVE/FOLDER 1/FILE 1B.TXT", false));
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/file 1b.txt");
|
||||
ASSERT_TRUE(reader->MoveToFile("TEST_ARCHIVE/FOLDER 1/FILE 1B.TXT", false));
|
||||
ASSERT_EQ(reader->GetFileName(), "test_archive/folder 1/file 1b.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_TRUE(reader->OpenFile(""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1B.", 20));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToFile(L"test_archive/folder 1/file 1b.txt", true));
|
||||
ASSERT_FALSE(reader->MoveToFile(L"test_archive/folder 1/FILE 1B.txt", true));
|
||||
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());
|
||||
}
|
||||
@ -224,15 +224,15 @@ TEST(ZipReaderTest, ReadArchive)
|
||||
|
||||
ASSERT_EQ(archive->Load(stream, false), (size_t)5);
|
||||
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/file 1.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/folder 1/file 1a.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/FOLDER 1/file 1b.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/folder 1/folder 1a/file 1a1.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/folder 2/file 2a.txt"));
|
||||
ASSERT_TRUE(archive->HasFile("test_archive/file 1.txt"));
|
||||
ASSERT_TRUE(archive->HasFile("test_archive/folder 1/file 1a.txt"));
|
||||
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(L"test_archive/folder 2/file 2a.txt");
|
||||
file = archive->GetFile("test_archive/folder 2/file 2a.txt");
|
||||
ASSERT_TRUE(file.get());
|
||||
|
||||
ASSERT_EQ(file->GetDataSize(), (size_t)20);
|
||||
|
Reference in New Issue
Block a user