2015-01-22 21:21:21 +01:00
|
|
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/test_runner.h"
|
2015-01-22 21:21:21 +01:00
|
|
|
|
2021-06-20 18:08:10 +02:00
|
|
|
#include <algorithm>
|
2019-10-15 17:34:13 +02:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2015-02-11 19:15:04 +01:00
|
|
|
#include <sstream>
|
2024-03-12 20:47:10 +01:00
|
|
|
#include <string>
|
2015-02-11 19:15:04 +01:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2024-07-02 20:08:16 +02:00
|
|
|
#include "include/base/cef_dump_without_crashing.h"
|
2015-04-09 16:59:34 +02:00
|
|
|
#include "include/cef_parser.h"
|
2015-01-22 21:21:21 +01:00
|
|
|
#include "include/cef_task.h"
|
|
|
|
#include "include/cef_trace.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "include/views/cef_browser_view.h"
|
2015-01-22 21:21:21 +01:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
|
|
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
2024-03-12 20:47:10 +01:00
|
|
|
#include "tests/cefclient/browser/base_client_handler.h"
|
2023-10-25 20:20:55 +02:00
|
|
|
#include "tests/cefclient/browser/binary_transfer_test.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/binding_test.h"
|
|
|
|
#include "tests/cefclient/browser/dialog_test.h"
|
2024-03-12 20:47:10 +01:00
|
|
|
#include "tests/cefclient/browser/hang_test.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/main_context.h"
|
2020-03-19 16:34:15 +01:00
|
|
|
#include "tests/cefclient/browser/media_router_test.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/preferences_test.h"
|
|
|
|
#include "tests/cefclient/browser/resource.h"
|
|
|
|
#include "tests/cefclient/browser/response_filter_test.h"
|
|
|
|
#include "tests/cefclient/browser/root_window_manager.h"
|
|
|
|
#include "tests/cefclient/browser/scheme_test.h"
|
2017-11-09 20:00:47 +01:00
|
|
|
#include "tests/cefclient/browser/server_test.h"
|
2024-07-18 17:09:19 +02:00
|
|
|
#include "tests/cefclient/browser/task_manager_test.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/urlrequest_test.h"
|
|
|
|
#include "tests/cefclient/browser/window_test.h"
|
|
|
|
#include "tests/shared/browser/resource_util.h"
|
2022-08-02 22:30:37 +02:00
|
|
|
#include "tests/shared/common/string_util.h"
|
2015-01-22 21:21:21 +01:00
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
namespace client::test_runner {
|
2015-01-22 21:21:21 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
const char kTestHost[] = "tests";
|
|
|
|
const char kLocalHost[] = "localhost";
|
2023-09-26 22:12:32 +02:00
|
|
|
const char kTestOrigin[] = "https://tests/";
|
2015-01-22 21:21:21 +01:00
|
|
|
|
2019-10-15 17:34:13 +02:00
|
|
|
// Pages handled via StringResourceProvider.
|
|
|
|
const char kTestGetSourcePage[] = "get_source.html";
|
|
|
|
const char kTestGetTextPage[] = "get_text.html";
|
|
|
|
|
|
|
|
// Set page data and navigate the browser. Used in combination with
|
|
|
|
// StringResourceProvider.
|
|
|
|
void LoadStringResourcePage(CefRefPtr<CefBrowser> browser,
|
|
|
|
const std::string& page,
|
|
|
|
const std::string& data) {
|
2024-03-12 20:47:10 +01:00
|
|
|
BaseClientHandler::GetForBrowser(browser)->SetStringResource(page, data);
|
2019-10-15 17:34:13 +02:00
|
|
|
browser->GetMainFrame()->LoadURL(kTestOrigin + page);
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
|
|
|
|
class Visitor : public CefStringVisitor {
|
|
|
|
public:
|
|
|
|
explicit Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
|
2024-01-20 03:22:56 +01:00
|
|
|
void Visit(const CefString& string) override {
|
2022-08-02 22:30:37 +02:00
|
|
|
std::string source = AsciiStrReplace(string, "<", "<");
|
|
|
|
source = AsciiStrReplace(source, ">", ">");
|
2015-01-22 21:21:21 +01:00
|
|
|
std::stringstream ss;
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << "<html><body bgcolor=\"white\">Source:<pre>" << source
|
|
|
|
<< "</pre></body></html>";
|
2019-10-15 17:34:13 +02:00
|
|
|
LoadStringResourcePage(browser_, kTestGetSourcePage, ss.str());
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
private:
|
|
|
|
CefRefPtr<CefBrowser> browser_;
|
|
|
|
IMPLEMENT_REFCOUNTING(Visitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
browser->GetMainFrame()->GetSource(new Visitor(browser));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunGetTextTest(CefRefPtr<CefBrowser> browser) {
|
|
|
|
class Visitor : public CefStringVisitor {
|
|
|
|
public:
|
|
|
|
explicit Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
|
2024-01-20 03:22:56 +01:00
|
|
|
void Visit(const CefString& string) override {
|
2022-08-02 22:30:37 +02:00
|
|
|
std::string text = AsciiStrReplace(string, "<", "<");
|
|
|
|
text = AsciiStrReplace(text, ">", ">");
|
2015-01-22 21:21:21 +01:00
|
|
|
std::stringstream ss;
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << "<html><body bgcolor=\"white\">Text:<pre>" << text
|
|
|
|
<< "</pre></body></html>";
|
2019-10-15 17:34:13 +02:00
|
|
|
LoadStringResourcePage(browser_, kTestGetTextPage, ss.str());
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
private:
|
|
|
|
CefRefPtr<CefBrowser> browser_;
|
|
|
|
IMPLEMENT_REFCOUNTING(Visitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
browser->GetMainFrame()->GetText(new Visitor(browser));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunRequestTest(CefRefPtr<CefBrowser> browser) {
|
|
|
|
// Create a new request
|
|
|
|
CefRefPtr<CefRequest> request(CefRequest::Create());
|
|
|
|
|
2023-09-26 22:12:32 +02:00
|
|
|
if (browser->GetMainFrame()->GetURL().ToString().find(kTestOrigin) != 0) {
|
2019-10-15 15:06:09 +02:00
|
|
|
// The LoadRequest method will fail with "bad IPC message" reason
|
|
|
|
// INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the
|
|
|
|
// request origin using some other mechanism (LoadURL, link click, etc).
|
2023-09-26 22:12:32 +02:00
|
|
|
Alert(browser, "Please first navigate to a " + std::string(kTestOrigin) +
|
|
|
|
" URL. "
|
|
|
|
"For example, first load Tests > Other Tests.");
|
2019-10-15 15:06:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
// Set the request URL
|
2023-09-26 22:12:32 +02:00
|
|
|
request->SetURL(GetTestURL("request"));
|
2015-01-22 21:21:21 +01:00
|
|
|
|
|
|
|
// Add post data to the request. The correct method and content-
|
|
|
|
// type headers will be set by CEF.
|
|
|
|
CefRefPtr<CefPostDataElement> postDataElement(CefPostDataElement::Create());
|
|
|
|
std::string data = "arg1=val1&arg2=val2";
|
|
|
|
postDataElement->SetToBytes(data.length(), data.c_str());
|
|
|
|
CefRefPtr<CefPostData> postData(CefPostData::Create());
|
|
|
|
postData->AddElement(postDataElement);
|
|
|
|
request->SetPostData(postData);
|
|
|
|
|
|
|
|
// Add a custom header
|
|
|
|
CefRequest::HeaderMap headerMap;
|
2017-05-17 11:29:28 +02:00
|
|
|
headerMap.insert(std::make_pair("X-My-Header", "My Header Value"));
|
2015-01-22 21:21:21 +01:00
|
|
|
request->SetHeaderMap(headerMap);
|
|
|
|
|
|
|
|
// Load the request
|
|
|
|
browser->GetMainFrame()->LoadRequest(request);
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void RunNewWindowTest(CefRefPtr<CefBrowser> browser) {
|
2021-06-19 21:54:45 +02:00
|
|
|
auto config = std::make_unique<RootWindowConfig>();
|
|
|
|
config->with_controls = true;
|
|
|
|
config->with_osr = browser->GetHost()->IsWindowRenderingDisabled();
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
|
|
|
|
std::move(config));
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunPopupWindowTest(CefRefPtr<CefBrowser> browser) {
|
2015-01-22 21:21:21 +01:00
|
|
|
browser->GetMainFrame()->ExecuteJavaScript(
|
2023-01-03 19:53:40 +01:00
|
|
|
"window.open('https://www.google.com');", "about:blank", 0);
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
void RunDialogWindowTest(CefRefPtr<CefBrowser> browser) {
|
|
|
|
auto browser_view = CefBrowserView::GetForBrowser(browser);
|
|
|
|
if (!browser_view) {
|
|
|
|
LOG(ERROR) << "Dialog windows require Views";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto config = std::make_unique<RootWindowConfig>();
|
|
|
|
config->window_type = WindowType::DIALOG;
|
|
|
|
config->parent_window = browser_view->GetWindow();
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
|
|
|
|
std::move(config));
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
const char kPrompt[] = "Prompt.";
|
|
|
|
const char kPromptFPS[] = "FPS";
|
|
|
|
const char kPromptDSF[] = "DSF";
|
|
|
|
|
|
|
|
// Handles execution of prompt results.
|
|
|
|
class PromptHandler : public CefMessageRouterBrowserSide::Handler {
|
|
|
|
public:
|
2024-01-20 03:22:56 +01:00
|
|
|
PromptHandler() = default;
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
// Called due to cefQuery execution.
|
2024-01-20 03:22:56 +01:00
|
|
|
bool OnQuery(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int64_t query_id,
|
|
|
|
const CefString& request,
|
|
|
|
bool persistent,
|
|
|
|
CefRefPtr<Callback> callback) override {
|
2015-08-10 22:49:45 +02:00
|
|
|
// Parse |request| which takes the form "Prompt.[type]:[value]".
|
|
|
|
const std::string& request_str = request;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (request_str.find(kPrompt) != 0) {
|
2015-08-10 22:49:45 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
std::string type = request_str.substr(sizeof(kPrompt) - 1);
|
|
|
|
size_t delim = type.find(':');
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delim == std::string::npos) {
|
2015-08-10 22:49:45 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
const std::string& value = type.substr(delim + 1);
|
|
|
|
type = type.substr(0, delim);
|
|
|
|
|
|
|
|
// Canceling the prompt dialog returns a value of "null".
|
|
|
|
if (value != "null") {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type == kPromptFPS) {
|
2015-08-10 22:49:45 +02:00
|
|
|
SetFPS(browser, atoi(value.c_str()));
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (type == kPromptDSF) {
|
2015-08-10 22:49:45 +02:00
|
|
|
SetDSF(browser, static_cast<float>(atof(value.c_str())));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing is done with the response.
|
|
|
|
callback->Success(CefString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetFPS(CefRefPtr<CefBrowser> browser, int fps) {
|
|
|
|
if (fps <= 0) {
|
|
|
|
// Reset to the default value.
|
|
|
|
CefBrowserSettings settings;
|
|
|
|
MainContext::Get()->PopulateBrowserSettings(&settings);
|
|
|
|
fps = settings.windowless_frame_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
browser->GetHost()->SetWindowlessFrameRate(fps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDSF(CefRefPtr<CefBrowser> browser, float dsf) {
|
|
|
|
MainMessageLoop::Get()->PostClosure(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&PromptHandler::SetDSFOnMainThread, browser, dsf));
|
2015-08-10 22:49:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SetDSFOnMainThread(CefRefPtr<CefBrowser> browser, float dsf) {
|
2017-05-17 11:29:28 +02:00
|
|
|
RootWindow::GetForBrowser(browser->GetIdentifier())
|
|
|
|
->SetDeviceScaleFactor(dsf);
|
2015-08-10 22:49:45 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void Prompt(CefRefPtr<CefBrowser> browser,
|
|
|
|
const std::string& type,
|
|
|
|
const std::string& label,
|
|
|
|
const std::string& default_value) {
|
|
|
|
// Prompt the user for a new value. Works as follows:
|
|
|
|
// 1. Show a prompt() dialog via JavaScript.
|
|
|
|
// 2. Pass the result to window.cefQuery().
|
|
|
|
// 3. Handle the result in PromptHandler::OnQuery.
|
2017-05-17 11:29:28 +02:00
|
|
|
const std::string& code = "window.cefQuery({'request': '" +
|
|
|
|
std::string(kPrompt) + type + ":' + prompt('" +
|
|
|
|
label + "', '" + default_value + "')});";
|
2015-08-10 22:49:45 +02:00
|
|
|
browser->GetMainFrame()->ExecuteJavaScript(
|
|
|
|
code, browser->GetMainFrame()->GetURL(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PromptFPS(CefRefPtr<CefBrowser> browser) {
|
2015-05-13 17:43:50 +02:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&PromptFPS, browser));
|
2015-05-13 17:43:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Format the default value string.
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << browser->GetHost()->GetWindowlessFrameRate();
|
|
|
|
|
|
|
|
Prompt(browser, kPromptFPS, "Enter FPS", ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PromptDSF(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!MainMessageLoop::Get()->RunsTasksOnCurrentThread()) {
|
|
|
|
// Execute on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MainMessageLoop::Get()->PostClosure(base::BindOnce(&PromptDSF, browser));
|
2015-08-10 22:49:45 +02:00
|
|
|
return;
|
2015-05-13 17:43:50 +02:00
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
// Format the default value string.
|
|
|
|
std::stringstream ss;
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << RootWindow::GetForBrowser(browser->GetIdentifier())
|
|
|
|
->GetDeviceScaleFactor();
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
Prompt(browser, kPromptDSF, "Enter Device Scale Factor", ss.str());
|
2015-05-13 17:43:50 +02:00
|
|
|
}
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
void BeginTracing() {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&BeginTracing));
|
2015-01-22 21:21:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-15 15:28:12 +01:00
|
|
|
CefBeginTracing(CefString(), nullptr);
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EndTracing(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&EndTracing, browser));
|
2015-01-22 21:21:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class Client : public CefEndTracingCallback, public CefRunFileDialogCallback {
|
2015-01-22 21:21:21 +01:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit Client(CefRefPtr<CefBrowser> browser) : browser_(browser) {
|
2015-01-22 21:21:21 +01:00
|
|
|
RunDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunDialog() {
|
|
|
|
static const char kDefaultFileName[] = "trace.txt";
|
2015-01-23 20:09:34 +01:00
|
|
|
std::string path = MainContext::Get()->GetDownloadPath(kDefaultFileName);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (path.empty()) {
|
2015-01-22 21:21:21 +01:00
|
|
|
path = kDefaultFileName;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-22 21:21:21 +01:00
|
|
|
|
|
|
|
// Results in a call to OnFileDialogDismissed.
|
|
|
|
browser_->GetHost()->RunFileDialog(
|
2022-04-15 21:55:23 +02:00
|
|
|
FILE_DIALOG_SAVE,
|
|
|
|
/*title=*/CefString(), path,
|
|
|
|
/*accept_filters=*/std::vector<CefString>(), this);
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 16:40:08 +01:00
|
|
|
void OnFileDialogDismissed(
|
2021-06-17 21:43:06 +02:00
|
|
|
const std::vector<CefString>& file_paths) override {
|
2015-01-22 21:21:21 +01:00
|
|
|
if (!file_paths.empty()) {
|
|
|
|
// File selected. Results in a call to OnEndTracingComplete.
|
|
|
|
CefEndTracing(file_paths.front(), this);
|
|
|
|
} else {
|
|
|
|
// No file selected. Discard the trace data.
|
2020-01-15 15:28:12 +01:00
|
|
|
CefEndTracing(CefString(), nullptr);
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnEndTracingComplete(const CefString& tracing_file) override {
|
2015-01-22 21:21:21 +01:00
|
|
|
Alert(browser_,
|
|
|
|
"File \"" + tracing_file.ToString() + "\" saved successfully.");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRefPtr<CefBrowser> browser_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(Client);
|
|
|
|
};
|
|
|
|
|
|
|
|
new Client(browser);
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:40:08 +01:00
|
|
|
void PrintToPDF(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&PrintToPDF, browser));
|
2015-03-24 16:40:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class Client : public CefPdfPrintCallback, public CefRunFileDialogCallback {
|
2015-03-24 16:40:08 +01:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit Client(CefRefPtr<CefBrowser> browser) : browser_(browser) {
|
2015-03-24 16:40:08 +01:00
|
|
|
RunDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunDialog() {
|
|
|
|
static const char kDefaultFileName[] = "output.pdf";
|
|
|
|
std::string path = MainContext::Get()->GetDownloadPath(kDefaultFileName);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (path.empty()) {
|
2015-03-24 16:40:08 +01:00
|
|
|
path = kDefaultFileName;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-24 16:40:08 +01:00
|
|
|
|
|
|
|
std::vector<CefString> accept_filters;
|
|
|
|
accept_filters.push_back(".pdf");
|
|
|
|
|
|
|
|
// Results in a call to OnFileDialogDismissed.
|
2022-04-15 21:55:23 +02:00
|
|
|
browser_->GetHost()->RunFileDialog(FILE_DIALOG_SAVE,
|
|
|
|
/*title=*/CefString(), path,
|
|
|
|
accept_filters, this);
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnFileDialogDismissed(
|
2021-06-17 21:43:06 +02:00
|
|
|
const std::vector<CefString>& file_paths) override {
|
2015-03-24 16:40:08 +01:00
|
|
|
if (!file_paths.empty()) {
|
|
|
|
CefPdfPrintSettings settings;
|
|
|
|
|
2022-10-12 23:53:06 +02:00
|
|
|
// Display a header and footer.
|
|
|
|
settings.display_header_footer = true;
|
|
|
|
CefString(&settings.header_template) =
|
|
|
|
"<div style=\"width: 100%; font-size: 9px; position: relative;\">"
|
|
|
|
"<div style=\"position: absolute; left: 5px;\">"
|
|
|
|
"<span class=\"title\"></span></div>"
|
|
|
|
"</div>";
|
|
|
|
CefString(&settings.footer_template) =
|
|
|
|
"<div style=\"width: 100%; font-size: 9px; position: relative;\">"
|
|
|
|
"<div style=\"position: absolute; left: 5px;\">"
|
|
|
|
"<span class=\"date\"></span></div>"
|
|
|
|
"<div style=\"position: absolute; right: 5px;\">"
|
|
|
|
"<span class=\"pageNumber\"></span>/"
|
|
|
|
"<span class=\"totalPages\"></span></div>"
|
|
|
|
"</div>";
|
2015-03-24 16:40:08 +01:00
|
|
|
|
|
|
|
// Print to the selected PDF file.
|
|
|
|
browser_->GetHost()->PrintToPDF(file_paths[0], settings, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnPdfPrintFinished(const CefString& path, bool ok) override {
|
2017-05-17 11:29:28 +02:00
|
|
|
Alert(browser_, "File \"" + path.ToString() + "\" " +
|
|
|
|
(ok ? "saved successfully." : "failed to save."));
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRefPtr<CefBrowser> browser_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(Client);
|
|
|
|
};
|
|
|
|
|
|
|
|
new Client(browser);
|
|
|
|
}
|
|
|
|
|
2019-02-26 17:44:17 +01:00
|
|
|
void MuteAudio(CefRefPtr<CefBrowser> browser, bool mute) {
|
|
|
|
CefRefPtr<CefBrowserHost> host = browser->GetHost();
|
|
|
|
host->SetAudioMuted(mute);
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
void RunOtherTests(CefRefPtr<CefBrowser> browser) {
|
2023-09-26 22:12:32 +02:00
|
|
|
browser->GetMainFrame()->LoadURL(GetTestURL("other_tests"));
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
2015-05-23 03:57:31 +02:00
|
|
|
// Provider that dumps the request contents.
|
|
|
|
class RequestDumpResourceProvider : public CefResourceManager::Provider {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit RequestDumpResourceProvider(const std::string& url) : url_(url) {
|
2015-05-23 03:57:31 +02:00
|
|
|
DCHECK(!url.empty());
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) override {
|
2015-05-23 03:57:31 +02:00
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
|
|
|
const std::string& url = request->url();
|
|
|
|
if (url != url_) {
|
|
|
|
// Not handled by this provider.
|
2015-01-22 21:21:21 +01:00
|
|
|
return false;
|
2015-05-23 03:57:31 +02:00
|
|
|
}
|
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
CefResponse::HeaderMap response_headers;
|
|
|
|
CefRefPtr<CefStreamReader> response =
|
|
|
|
GetDumpResponse(request->request(), response_headers);
|
|
|
|
|
|
|
|
request->Continue(new CefStreamResourceHandler(200, "OK", "text/html",
|
|
|
|
response_headers, response));
|
2015-05-23 03:57:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string url_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RequestDumpResourceProvider);
|
|
|
|
};
|
|
|
|
|
2019-10-15 17:34:13 +02:00
|
|
|
// Provider that returns string data for specific pages. Used in combination
|
|
|
|
// with LoadStringResourcePage().
|
|
|
|
class StringResourceProvider : public CefResourceManager::Provider {
|
|
|
|
public:
|
2019-10-18 15:30:53 +02:00
|
|
|
StringResourceProvider(const std::set<std::string>& pages,
|
|
|
|
StringResourceMap* string_resource_map)
|
|
|
|
: pages_(pages), string_resource_map_(string_resource_map) {
|
2019-10-15 17:34:13 +02:00
|
|
|
DCHECK(!pages.empty());
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) override {
|
2019-10-15 17:34:13 +02:00
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
|
|
|
const std::string& url = request->url();
|
|
|
|
if (url.find(kTestOrigin) != 0U) {
|
|
|
|
// Not handled by this provider.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& page = url.substr(strlen(kTestOrigin));
|
|
|
|
if (pages_.find(page) == pages_.end()) {
|
|
|
|
// Not handled by this provider.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string value;
|
2019-10-18 15:30:53 +02:00
|
|
|
StringResourceMap::const_iterator it = string_resource_map_->find(page);
|
|
|
|
if (it != string_resource_map_->end()) {
|
2019-10-15 17:34:13 +02:00
|
|
|
value = it->second;
|
|
|
|
} else {
|
|
|
|
value = "<html><body>No data available</body></html>";
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefStreamReader> response = CefStreamReader::CreateForData(
|
|
|
|
static_cast<void*>(const_cast<char*>(value.c_str())), value.size());
|
|
|
|
|
|
|
|
request->Continue(new CefStreamResourceHandler(
|
|
|
|
200, "OK", "text/html", CefResponse::HeaderMap(), response));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::set<std::string> pages_;
|
|
|
|
|
|
|
|
// Only accessed on the IO thread.
|
2019-10-18 15:30:53 +02:00
|
|
|
StringResourceMap* string_resource_map_;
|
2019-10-15 17:34:13 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(StringResourceProvider);
|
|
|
|
};
|
|
|
|
|
2015-05-23 03:57:31 +02:00
|
|
|
// Add a file extension to |url| if none is currently specified.
|
|
|
|
std::string RequestUrlFilter(const std::string& url) {
|
|
|
|
if (url.find(kTestOrigin) != 0U) {
|
|
|
|
// Don't filter anything outside of the test origin.
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Identify where the query or fragment component, if any, begins.
|
|
|
|
size_t suffix_pos = url.find('?');
|
2023-01-02 23:59:03 +01:00
|
|
|
if (suffix_pos == std::string::npos) {
|
2015-05-23 03:57:31 +02:00
|
|
|
suffix_pos = url.find('#');
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-05-23 03:57:31 +02:00
|
|
|
|
|
|
|
std::string url_base, url_suffix;
|
|
|
|
if (suffix_pos == std::string::npos) {
|
|
|
|
url_base = url;
|
2015-01-22 21:21:21 +01:00
|
|
|
} else {
|
2015-05-23 03:57:31 +02:00
|
|
|
url_base = url.substr(0, suffix_pos);
|
|
|
|
url_suffix = url.substr(suffix_pos);
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
2015-05-23 03:57:31 +02:00
|
|
|
// Identify the last path component.
|
|
|
|
size_t path_pos = url_base.rfind('/');
|
2023-01-02 23:59:03 +01:00
|
|
|
if (path_pos == std::string::npos) {
|
2015-05-23 03:57:31 +02:00
|
|
|
return url;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-05-23 03:57:31 +02:00
|
|
|
|
|
|
|
const std::string& path_component = url_base.substr(path_pos);
|
|
|
|
|
|
|
|
// Identify if a file extension is currently specified.
|
|
|
|
size_t ext_pos = path_component.rfind(".");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (ext_pos != std::string::npos) {
|
2015-05-23 03:57:31 +02:00
|
|
|
return url;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-05-23 03:57:31 +02:00
|
|
|
|
|
|
|
// Rebuild the URL with a file extension.
|
|
|
|
return url_base + ".html" + url_suffix;
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void RunTest(CefRefPtr<CefBrowser> browser, int id) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser) {
|
2015-01-22 21:21:21 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-22 21:21:21 +01:00
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case ID_TESTS_GETSOURCE:
|
2017-05-17 11:29:28 +02:00
|
|
|
RunGetSourceTest(browser);
|
2015-01-22 21:21:21 +01:00
|
|
|
break;
|
|
|
|
case ID_TESTS_GETTEXT:
|
|
|
|
RunGetTextTest(browser);
|
|
|
|
break;
|
2015-03-02 21:25:14 +01:00
|
|
|
case ID_TESTS_WINDOW_NEW:
|
|
|
|
RunNewWindowTest(browser);
|
|
|
|
break;
|
|
|
|
case ID_TESTS_WINDOW_POPUP:
|
|
|
|
RunPopupWindowTest(browser);
|
2015-01-22 21:21:21 +01:00
|
|
|
break;
|
2023-06-14 10:20:02 +02:00
|
|
|
case ID_TESTS_WINDOW_DIALOG:
|
|
|
|
RunDialogWindowTest(browser);
|
|
|
|
break;
|
2015-01-22 21:21:21 +01:00
|
|
|
case ID_TESTS_REQUEST:
|
|
|
|
RunRequestTest(browser);
|
|
|
|
break;
|
|
|
|
case ID_TESTS_ZOOM_IN:
|
2023-10-05 01:46:45 +02:00
|
|
|
browser->GetHost()->Zoom(CEF_ZOOM_COMMAND_IN);
|
2015-01-22 21:21:21 +01:00
|
|
|
break;
|
|
|
|
case ID_TESTS_ZOOM_OUT:
|
2023-10-05 01:46:45 +02:00
|
|
|
browser->GetHost()->Zoom(CEF_ZOOM_COMMAND_OUT);
|
2015-01-22 21:21:21 +01:00
|
|
|
break;
|
|
|
|
case ID_TESTS_ZOOM_RESET:
|
2023-10-05 01:46:45 +02:00
|
|
|
browser->GetHost()->Zoom(CEF_ZOOM_COMMAND_RESET);
|
2015-01-22 21:21:21 +01:00
|
|
|
break;
|
2015-08-10 22:49:45 +02:00
|
|
|
case ID_TESTS_OSR_FPS:
|
|
|
|
PromptFPS(browser);
|
2015-05-13 17:43:50 +02:00
|
|
|
break;
|
2015-08-10 22:49:45 +02:00
|
|
|
case ID_TESTS_OSR_DSF:
|
|
|
|
PromptDSF(browser);
|
2015-05-13 17:43:50 +02:00
|
|
|
break;
|
2015-01-22 21:21:21 +01:00
|
|
|
case ID_TESTS_TRACING_BEGIN:
|
|
|
|
BeginTracing();
|
|
|
|
break;
|
|
|
|
case ID_TESTS_TRACING_END:
|
|
|
|
EndTracing(browser);
|
|
|
|
break;
|
|
|
|
case ID_TESTS_PRINT:
|
|
|
|
browser->GetHost()->Print();
|
|
|
|
break;
|
2015-03-24 16:40:08 +01:00
|
|
|
case ID_TESTS_PRINT_TO_PDF:
|
|
|
|
PrintToPDF(browser);
|
|
|
|
break;
|
2019-02-26 17:44:17 +01:00
|
|
|
case ID_TESTS_MUTE_AUDIO:
|
|
|
|
MuteAudio(browser, true);
|
|
|
|
break;
|
|
|
|
case ID_TESTS_UNMUTE_AUDIO:
|
|
|
|
MuteAudio(browser, false);
|
|
|
|
break;
|
2015-01-22 21:21:21 +01:00
|
|
|
case ID_TESTS_OTHER_TESTS:
|
|
|
|
RunOtherTests(browser);
|
|
|
|
break;
|
2024-07-02 20:08:16 +02:00
|
|
|
case ID_TESTS_DUMP_WITHOUT_CRASHING:
|
|
|
|
CefDumpWithoutCrashing();
|
|
|
|
break;
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
std::string DumpRequestContents(CefRefPtr<CefRequest> request) {
|
2015-01-22 21:21:21 +01:00
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
ss << "URL: " << std::string(request->GetURL());
|
|
|
|
ss << "\nMethod: " << std::string(request->GetMethod());
|
|
|
|
|
|
|
|
CefRequest::HeaderMap headerMap;
|
|
|
|
request->GetHeaderMap(headerMap);
|
|
|
|
if (headerMap.size() > 0) {
|
|
|
|
ss << "\nHeaders:";
|
|
|
|
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
|
|
|
|
for (; it != headerMap.end(); ++it) {
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << "\n\t" << std::string((*it).first) << ": "
|
|
|
|
<< std::string((*it).second);
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefPostData> postData = request->GetPostData();
|
|
|
|
if (postData.get()) {
|
|
|
|
CefPostData::ElementVector elements;
|
|
|
|
postData->GetElements(elements);
|
|
|
|
if (elements.size() > 0) {
|
|
|
|
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 << "\n\tBytes: ";
|
|
|
|
if (element->GetBytesCount() == 0) {
|
|
|
|
ss << "(empty)";
|
|
|
|
} else {
|
|
|
|
// retrieve the data.
|
|
|
|
size_t size = element->GetBytesCount();
|
|
|
|
char* bytes = new char[size];
|
|
|
|
element->GetBytes(size, bytes);
|
|
|
|
ss << std::string(bytes, size);
|
2017-05-17 11:29:28 +02:00
|
|
|
delete[] bytes;
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
} else if (element->GetType() == PDE_TYPE_FILE) {
|
|
|
|
ss << "\n\tFile: " << std::string(element->GetFile());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
CefRefPtr<CefStreamReader> GetDumpResponse(
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefResponse::HeaderMap& response_headers) {
|
|
|
|
std::string origin;
|
|
|
|
|
|
|
|
// Extract the origin request header, if any. It will be specified for
|
|
|
|
// cross-origin requests.
|
|
|
|
{
|
|
|
|
CefRequest::HeaderMap requestMap;
|
|
|
|
request->GetHeaderMap(requestMap);
|
|
|
|
|
|
|
|
CefRequest::HeaderMap::const_iterator it = requestMap.begin();
|
|
|
|
for (; it != requestMap.end(); ++it) {
|
2022-08-02 22:30:37 +02:00
|
|
|
const std::string& key = AsciiStrToLower(it->first);
|
2017-11-09 20:00:47 +01:00
|
|
|
if (key == "origin") {
|
|
|
|
origin = it->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!origin.empty() &&
|
2023-09-26 22:12:32 +02:00
|
|
|
(origin.find("https://" + std::string(kTestHost)) == 0 ||
|
2017-11-09 20:00:47 +01:00
|
|
|
origin.find("http://" + std::string(kLocalHost)) == 0)) {
|
|
|
|
// Allow cross-origin XMLHttpRequests from test origins.
|
|
|
|
response_headers.insert(
|
|
|
|
std::make_pair("Access-Control-Allow-Origin", origin));
|
|
|
|
|
|
|
|
// Allow the custom header from the xmlhttprequest.html example.
|
|
|
|
response_headers.insert(
|
|
|
|
std::make_pair("Access-Control-Allow-Headers", "My-Custom-Header"));
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& dump = DumpRequestContents(request);
|
|
|
|
std::string str =
|
|
|
|
"<html><body bgcolor=\"white\"><pre>" + dump + "</pre></body></html>";
|
|
|
|
CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData(
|
|
|
|
static_cast<void*>(const_cast<char*>(str.c_str())), str.size());
|
|
|
|
DCHECK(stream);
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::string GetDataURI(const std::string& data, const std::string& mime_type) {
|
2015-02-11 19:15:04 +01:00
|
|
|
return "data:" + mime_type + ";base64," +
|
2017-05-17 11:29:28 +02:00
|
|
|
CefURIEncode(CefBase64Encode(data.data(), data.size()), false)
|
|
|
|
.ToString();
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
std::string GetErrorString(cef_errorcode_t code) {
|
2017-05-17 11:29:28 +02:00
|
|
|
// Case condition that returns |code| as a string.
|
|
|
|
#define CASE(code) \
|
|
|
|
case code: \
|
|
|
|
return #code
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
CASE(ERR_NONE);
|
|
|
|
CASE(ERR_FAILED);
|
|
|
|
CASE(ERR_ABORTED);
|
|
|
|
CASE(ERR_INVALID_ARGUMENT);
|
|
|
|
CASE(ERR_INVALID_HANDLE);
|
|
|
|
CASE(ERR_FILE_NOT_FOUND);
|
|
|
|
CASE(ERR_TIMED_OUT);
|
|
|
|
CASE(ERR_FILE_TOO_BIG);
|
|
|
|
CASE(ERR_UNEXPECTED);
|
|
|
|
CASE(ERR_ACCESS_DENIED);
|
|
|
|
CASE(ERR_NOT_IMPLEMENTED);
|
|
|
|
CASE(ERR_CONNECTION_CLOSED);
|
|
|
|
CASE(ERR_CONNECTION_RESET);
|
|
|
|
CASE(ERR_CONNECTION_REFUSED);
|
|
|
|
CASE(ERR_CONNECTION_ABORTED);
|
|
|
|
CASE(ERR_CONNECTION_FAILED);
|
|
|
|
CASE(ERR_NAME_NOT_RESOLVED);
|
|
|
|
CASE(ERR_INTERNET_DISCONNECTED);
|
|
|
|
CASE(ERR_SSL_PROTOCOL_ERROR);
|
|
|
|
CASE(ERR_ADDRESS_INVALID);
|
|
|
|
CASE(ERR_ADDRESS_UNREACHABLE);
|
|
|
|
CASE(ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
|
|
|
|
CASE(ERR_TUNNEL_CONNECTION_FAILED);
|
|
|
|
CASE(ERR_NO_SSL_VERSIONS_ENABLED);
|
|
|
|
CASE(ERR_SSL_VERSION_OR_CIPHER_MISMATCH);
|
|
|
|
CASE(ERR_SSL_RENEGOTIATION_REQUESTED);
|
|
|
|
CASE(ERR_CERT_COMMON_NAME_INVALID);
|
|
|
|
CASE(ERR_CERT_DATE_INVALID);
|
|
|
|
CASE(ERR_CERT_AUTHORITY_INVALID);
|
|
|
|
CASE(ERR_CERT_CONTAINS_ERRORS);
|
|
|
|
CASE(ERR_CERT_NO_REVOCATION_MECHANISM);
|
|
|
|
CASE(ERR_CERT_UNABLE_TO_CHECK_REVOCATION);
|
|
|
|
CASE(ERR_CERT_REVOKED);
|
|
|
|
CASE(ERR_CERT_INVALID);
|
|
|
|
CASE(ERR_CERT_END);
|
|
|
|
CASE(ERR_INVALID_URL);
|
|
|
|
CASE(ERR_DISALLOWED_URL_SCHEME);
|
|
|
|
CASE(ERR_UNKNOWN_URL_SCHEME);
|
|
|
|
CASE(ERR_TOO_MANY_REDIRECTS);
|
|
|
|
CASE(ERR_UNSAFE_REDIRECT);
|
|
|
|
CASE(ERR_UNSAFE_PORT);
|
|
|
|
CASE(ERR_INVALID_RESPONSE);
|
|
|
|
CASE(ERR_INVALID_CHUNKED_ENCODING);
|
|
|
|
CASE(ERR_METHOD_NOT_SUPPORTED);
|
|
|
|
CASE(ERR_UNEXPECTED_PROXY_AUTH);
|
|
|
|
CASE(ERR_EMPTY_RESPONSE);
|
|
|
|
CASE(ERR_RESPONSE_HEADERS_TOO_BIG);
|
|
|
|
CASE(ERR_CACHE_MISS);
|
|
|
|
CASE(ERR_INSECURE_RESPONSE);
|
|
|
|
default:
|
2024-03-12 20:47:10 +01:00
|
|
|
return std::to_string(static_cast<int>(code));
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
std::string GetErrorString(cef_termination_status_t status) {
|
|
|
|
switch (status) {
|
|
|
|
case TS_ABNORMAL_TERMINATION:
|
|
|
|
return "ABNORMAL_TERMINATION";
|
|
|
|
case TS_PROCESS_WAS_KILLED:
|
|
|
|
return "PROCESS_WAS_KILLED";
|
|
|
|
case TS_PROCESS_CRASHED:
|
|
|
|
return "PROCESS_CRASHED";
|
|
|
|
case TS_PROCESS_OOM:
|
|
|
|
return "PROCESS_OOM";
|
|
|
|
case TS_LAUNCH_FAILED:
|
|
|
|
return "LAUNCH_FAILED";
|
|
|
|
case TS_INTEGRITY_FAILURE:
|
|
|
|
return "INTEGRITY_FAILURE";
|
|
|
|
}
|
|
|
|
NOTREACHED();
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2019-10-18 15:30:53 +02:00
|
|
|
void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager,
|
|
|
|
StringResourceMap* string_resource_map) {
|
2015-10-03 01:03:16 +02:00
|
|
|
if (!CefCurrentlyOn(TID_IO)) {
|
|
|
|
// Execute on the browser IO thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_IO, base::BindOnce(SetupResourceManager, resource_manager,
|
|
|
|
string_resource_map));
|
2015-10-03 01:03:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-23 03:57:31 +02:00
|
|
|
const std::string& test_origin = kTestOrigin;
|
|
|
|
|
|
|
|
// Add the URL filter.
|
2021-06-19 21:54:45 +02:00
|
|
|
resource_manager->SetUrlFilter(base::BindRepeating(RequestUrlFilter));
|
2015-05-23 03:57:31 +02:00
|
|
|
|
|
|
|
// Add provider for resource dumps.
|
|
|
|
resource_manager->AddProvider(
|
2017-05-17 11:29:28 +02:00
|
|
|
new RequestDumpResourceProvider(test_origin + "request.html"), 0,
|
|
|
|
std::string());
|
2015-05-23 03:57:31 +02:00
|
|
|
|
2019-10-15 17:34:13 +02:00
|
|
|
// Set of supported string pages.
|
|
|
|
std::set<std::string> string_pages;
|
|
|
|
string_pages.insert(kTestGetSourcePage);
|
|
|
|
string_pages.insert(kTestGetTextPage);
|
|
|
|
|
2023-02-17 21:55:12 +01:00
|
|
|
if (string_resource_map) {
|
|
|
|
// Add provider for string resources.
|
|
|
|
resource_manager->AddProvider(
|
|
|
|
new StringResourceProvider(string_pages, string_resource_map), 0,
|
|
|
|
std::string());
|
|
|
|
}
|
2019-10-15 17:34:13 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
// Add provider for bundled resource files.
|
2015-05-23 03:57:31 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Read resources from the binary.
|
2017-08-04 00:55:19 +02:00
|
|
|
resource_manager->AddProvider(
|
|
|
|
CreateBinaryResourceProvider(test_origin, std::string()), 100,
|
|
|
|
std::string());
|
2015-05-23 03:57:31 +02:00
|
|
|
#elif defined(OS_POSIX)
|
|
|
|
// Read resources from a directory on disk.
|
|
|
|
std::string resource_dir;
|
|
|
|
if (GetResourceDir(resource_dir)) {
|
2017-05-17 11:29:28 +02:00
|
|
|
resource_manager->AddDirectoryProvider(test_origin, resource_dir, 100,
|
|
|
|
std::string());
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
2015-05-23 03:57:31 +02:00
|
|
|
#endif
|
2015-01-22 21:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Alert(CefRefPtr<CefBrowser> browser, const std::string& message) {
|
|
|
|
// Escape special characters in the message.
|
2022-08-02 22:30:37 +02:00
|
|
|
std::string msg = AsciiStrReplace(message, "\\", "\\\\");
|
|
|
|
msg = AsciiStrReplace(msg, "'", "\\'");
|
2015-01-22 21:21:21 +01:00
|
|
|
|
|
|
|
// Execute a JavaScript alert().
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
|
|
|
|
frame->ExecuteJavaScript("alert('" + msg + "');", frame->GetURL(), 0);
|
|
|
|
}
|
|
|
|
|
2023-09-26 22:12:32 +02:00
|
|
|
std::string GetTestURL(const std::string& path) {
|
|
|
|
return kTestOrigin + path;
|
|
|
|
}
|
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
bool IsTestURL(const std::string& url, const std::string& path) {
|
|
|
|
CefURLParts parts;
|
|
|
|
CefParseURL(url, parts);
|
|
|
|
|
|
|
|
const std::string& url_host = CefString(&parts.host);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url_host != kTestHost && url_host != kLocalHost) {
|
2017-11-09 20:00:47 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-11-09 20:00:47 +01:00
|
|
|
|
|
|
|
const std::string& url_path = CefString(&parts.path);
|
|
|
|
return url_path.find(path) == 0;
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
void CreateMessageHandlers(MessageHandlerSet& handlers) {
|
2015-08-10 22:49:45 +02:00
|
|
|
handlers.insert(new PromptHandler);
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
// Create the binary trasfer test handlers.
|
|
|
|
binary_transfer_test::CreateMessageHandlers(handlers);
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
// Create the binding test handlers.
|
|
|
|
binding_test::CreateMessageHandlers(handlers);
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
// Create the dialog test handlers.
|
|
|
|
dialog_test::CreateMessageHandlers(handlers);
|
2024-03-12 20:47:10 +01:00
|
|
|
|
|
|
|
// Create the hang test handlers.
|
|
|
|
hang_test::CreateMessageHandlers(handlers);
|
2016-10-14 17:56:41 +02:00
|
|
|
|
2020-03-19 16:34:15 +01:00
|
|
|
// Create the media router test handlers.
|
|
|
|
media_router_test::CreateMessageHandlers(handlers);
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
// Create the preferences test handlers.
|
|
|
|
preferences_test::CreateMessageHandlers(handlers);
|
2015-01-22 21:21:21 +01:00
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
// Create the server test handlers.
|
|
|
|
server_test::CreateMessageHandlers(handlers);
|
|
|
|
|
2024-07-18 17:09:19 +02:00
|
|
|
// Create the task manager handlers.
|
|
|
|
task_manager_test::CreateMessageHandlers(handlers);
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
// Create the urlrequest test handlers.
|
|
|
|
urlrequest_test::CreateMessageHandlers(handlers);
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
// Create the window test handlers.
|
|
|
|
window_test::CreateMessageHandlers(handlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterSchemeHandlers() {
|
|
|
|
// Register the scheme handler.
|
|
|
|
scheme_test::RegisterSchemeHandlers();
|
|
|
|
}
|
|
|
|
|
2015-12-05 03:58:56 +01:00
|
|
|
CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefResponse> response) {
|
|
|
|
// Create the response filter.
|
|
|
|
return response_filter_test::GetResourceResponseFilter(browser, frame,
|
|
|
|
request, response);
|
|
|
|
}
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
} // namespace client::test_runner
|