2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2011 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.
|
|
|
|
|
2014-01-14 20:57:17 +01:00
|
|
|
#include <algorithm>
|
2020-08-14 21:28:23 +02:00
|
|
|
#include <vector>
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_callback.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "include/cef_origin_whitelist.h"
|
2023-10-05 22:54:42 +02:00
|
|
|
#include "include/cef_request_context.h"
|
|
|
|
#include "include/cef_request_context_handler.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_scheme.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
|
|
|
#include "tests/ceftests/test_suite.h"
|
2019-04-24 04:50:25 +02:00
|
|
|
#include "tests/ceftests/test_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TestResults {
|
|
|
|
public:
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
// Used for running tests in a custom request context.
|
|
|
|
CefRefPtr<CefRequestContext> request_context;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string url;
|
|
|
|
std::string html;
|
2023-05-03 13:38:48 +02:00
|
|
|
int status_code = 200;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-05-11 20:20:07 +02:00
|
|
|
// Error code set on the response.
|
2023-05-03 13:38:48 +02:00
|
|
|
cef_errorcode_t response_error_code = ERR_NONE;
|
2016-05-11 20:20:07 +02:00
|
|
|
// Error code expected in OnLoadError.
|
2023-05-03 13:38:48 +02:00
|
|
|
cef_errorcode_t expected_error_code = ERR_NONE;
|
2016-05-11 20:20:07 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Used for testing redirects
|
|
|
|
std::string redirect_url;
|
|
|
|
|
|
|
|
// Used for testing XHR requests
|
|
|
|
std::string sub_url;
|
|
|
|
std::string sub_html;
|
2023-05-03 13:38:48 +02:00
|
|
|
int sub_status_code = 200;
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string sub_allow_origin;
|
2013-04-18 19:58:23 +02:00
|
|
|
std::string sub_redirect_url;
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string exit_url;
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
// Used for testing XSS requests
|
|
|
|
bool needs_same_origin_policy_relaxation = false;
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
// Used for testing Accept-Language.
|
2015-02-18 18:28:56 +01:00
|
|
|
std::string accept_language;
|
|
|
|
|
2020-08-14 21:28:23 +02:00
|
|
|
// Used for testing received console messages.
|
|
|
|
std::vector<std::string> console_messages;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Delay for returning scheme handler results.
|
2023-05-03 13:38:48 +02:00
|
|
|
int delay = 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-07-16 19:59:21 +02:00
|
|
|
TrackCallback got_request, got_read, got_output, got_sub_output, got_redirect,
|
|
|
|
got_error, got_sub_error, got_sub_redirect, got_sub_request, got_sub_read,
|
2023-10-05 22:54:42 +02:00
|
|
|
git_exit_success, got_exit_request;
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Current scheme handler object. Used when destroying the test from
|
|
|
|
// ClientSchemeHandler::ProcessRequest().
|
|
|
|
class TestSchemeHandler;
|
2020-01-15 14:34:01 +01:00
|
|
|
TestSchemeHandler* g_current_handler = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
class TestSchemeHandler : public TestHandler {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit TestSchemeHandler(TestResults* tr) : test_results_(tr) {
|
2012-04-03 03:34:16 +02:00
|
|
|
g_current_handler = this;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2023-10-05 22:54:42 +02:00
|
|
|
CreateBrowser(test_results_->url, test_results_->request_context);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Necessary to make the method public in order to destroy the test from
|
|
|
|
// ClientSchemeHandler::ProcessRequest().
|
2020-08-14 21:28:23 +02:00
|
|
|
void DestroyTest() override {
|
|
|
|
EXPECT_TRUE(test_results_->console_messages.empty())
|
|
|
|
<< "Did not receive expected console message: "
|
|
|
|
<< test_results_->console_messages.front();
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-07-16 19:59:21 +02:00
|
|
|
void DestroyTestIfDone() {
|
|
|
|
if (!test_results_->exit_url.empty() && !test_results_->got_exit_request) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!test_results_->sub_url.empty() &&
|
|
|
|
!(test_results_->got_sub_output || test_results_->got_sub_error ||
|
|
|
|
test_results_->got_exit_request)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(test_results_->got_output || test_results_->got_error)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsExitURL(const std::string& url) const {
|
|
|
|
return !test_results_->exit_url.empty() &&
|
|
|
|
url.find(test_results_->exit_url) != std::string::npos;
|
|
|
|
}
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
cef_return_value_t OnBeforeResourceLoad(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2021-09-27 11:09:45 +02:00
|
|
|
CefRefPtr<CefCallback> callback) override {
|
2020-09-25 03:40:47 +02:00
|
|
|
if (IsChromeRuntimeEnabled() && request->GetResourceType() == RT_FAVICON) {
|
|
|
|
// Ignore favicon requests.
|
|
|
|
return RV_CANCEL;
|
|
|
|
}
|
|
|
|
|
2019-07-16 19:59:21 +02:00
|
|
|
const std::string& newUrl = request->GetURL();
|
|
|
|
if (IsExitURL(newUrl)) {
|
|
|
|
test_results_->got_exit_request.yes();
|
2012-04-03 03:34:16 +02:00
|
|
|
// XHR tests use an exit URL to destroy the test.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (newUrl.find("SUCCESS") != std::string::npos) {
|
2023-10-05 22:54:42 +02:00
|
|
|
test_results_->git_exit_success.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-07-16 19:59:21 +02:00
|
|
|
DestroyTestIfDone();
|
2015-04-02 17:21:46 +02:00
|
|
|
return RV_CANCEL;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
if (!test_results_->sub_redirect_url.empty() &&
|
|
|
|
newUrl == test_results_->sub_redirect_url) {
|
|
|
|
test_results_->got_sub_redirect.yes();
|
|
|
|
// Redirect to the sub URL.
|
|
|
|
request->SetURL(test_results_->sub_url);
|
|
|
|
} else if (newUrl == test_results_->redirect_url) {
|
2012-04-03 03:34:16 +02:00
|
|
|
test_results_->got_redirect.yes();
|
|
|
|
|
|
|
|
// No read should have occurred for the redirect.
|
|
|
|
EXPECT_TRUE(test_results_->got_request);
|
|
|
|
EXPECT_FALSE(test_results_->got_read);
|
|
|
|
|
|
|
|
// Now loading the redirect URL.
|
|
|
|
test_results_->url = test_results_->redirect_url;
|
|
|
|
test_results_->redirect_url.clear();
|
|
|
|
}
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
return RV_CONTINUE;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2019-07-16 19:59:21 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url == test_results_->url) {
|
2012-04-03 03:34:16 +02:00
|
|
|
test_results_->got_output.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (url == test_results_->sub_url) {
|
2019-07-16 19:59:21 +02:00
|
|
|
test_results_->got_sub_output.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (IsExitURL(url)) {
|
2019-07-16 19:59:21 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-07-16 19:59:21 +02:00
|
|
|
if (url == test_results_->url || test_results_->status_code != 200) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that the status code is correct.
|
2012-11-21 23:11:22 +01:00
|
|
|
EXPECT_EQ(httpStatusCode, test_results_->status_code);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2019-07-16 19:59:21 +02:00
|
|
|
|
|
|
|
DestroyTestIfDone();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
2019-07-16 19:59:21 +02:00
|
|
|
const std::string& url = failedUrl;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url == test_results_->url) {
|
2019-07-16 19:59:21 +02:00
|
|
|
test_results_->got_error.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (url == test_results_->sub_url) {
|
2019-07-16 19:59:21 +02:00
|
|
|
test_results_->got_sub_error.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (IsExitURL(url)) {
|
2019-07-16 19:59:21 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-07-16 19:59:21 +02:00
|
|
|
|
2021-06-25 02:55:29 +02:00
|
|
|
// Tests sometimes also fail with ERR_ABORTED or ERR_UNKNOWN_URL_SCHEME.
|
2017-08-04 00:55:19 +02:00
|
|
|
if (!(test_results_->expected_error_code == 0 &&
|
2021-06-25 02:55:29 +02:00
|
|
|
(errorCode == ERR_ABORTED || errorCode == ERR_UNKNOWN_URL_SCHEME))) {
|
2019-04-24 04:50:25 +02:00
|
|
|
EXPECT_EQ(test_results_->expected_error_code, errorCode)
|
|
|
|
<< failedUrl.ToString();
|
2017-08-11 18:56:52 +02:00
|
|
|
}
|
2019-07-16 19:59:21 +02:00
|
|
|
|
|
|
|
DestroyTestIfDone();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-08-14 21:28:23 +02:00
|
|
|
bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
|
|
|
cef_log_severity_t level,
|
|
|
|
const CefString& message,
|
|
|
|
const CefString& source,
|
|
|
|
int line) override {
|
|
|
|
bool expected = false;
|
|
|
|
if (!test_results_->console_messages.empty()) {
|
|
|
|
std::vector<std::string>::iterator it =
|
|
|
|
test_results_->console_messages.begin();
|
|
|
|
for (; it != test_results_->console_messages.end(); ++it) {
|
|
|
|
const std::string& possible = *it;
|
|
|
|
const std::string& actual = message.ToString();
|
|
|
|
if (actual.find(possible) == 0U) {
|
|
|
|
expected = true;
|
|
|
|
test_results_->console_messages.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_TRUE(expected) << "Unexpected console message: "
|
|
|
|
<< message.ToString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
protected:
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults* const test_results_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(TestSchemeHandler);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
class ClientSchemeHandlerOld : public CefResourceHandler {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
explicit ClientSchemeHandlerOld(TestResults* tr) : test_results_(tr) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool ProcessRequest(CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
std::string url = request->GetURL();
|
2017-05-17 11:29:28 +02:00
|
|
|
is_sub_ =
|
|
|
|
(!test_results_->sub_url.empty() && test_results_->sub_url == url);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (is_sub_) {
|
|
|
|
test_results_->got_sub_request.yes();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!test_results_->sub_html.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
handled = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(url, test_results_->url);
|
|
|
|
|
|
|
|
test_results_->got_request.yes();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!test_results_->html.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
handled = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-18 18:28:56 +01:00
|
|
|
std::string accept_language;
|
|
|
|
CefRequest::HeaderMap headerMap;
|
|
|
|
CefRequest::HeaderMap::iterator headerIter;
|
|
|
|
request->GetHeaderMap(headerMap);
|
|
|
|
headerIter = headerMap.find("Accept-Language");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (headerIter != headerMap.end()) {
|
2015-02-18 18:28:56 +01:00
|
|
|
accept_language = headerIter->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-02-18 18:28:56 +01:00
|
|
|
EXPECT_TRUE(!accept_language.empty());
|
|
|
|
|
|
|
|
if (!test_results_->accept_language.empty()) {
|
2023-10-05 22:54:42 +02:00
|
|
|
// Value from CefRequestContextSettings.accept_language_list.
|
2015-02-18 18:28:56 +01:00
|
|
|
EXPECT_STREQ(test_results_->accept_language.data(),
|
|
|
|
accept_language.data());
|
|
|
|
} else {
|
2019-05-11 00:14:48 +02:00
|
|
|
// CEF_SETTINGS_ACCEPT_LANGUAGE value from
|
|
|
|
// CefSettings.accept_language_list set in CefTestSuite::GetSettings()
|
|
|
|
// and expanded internally by ComputeAcceptLanguageFromPref.
|
2019-07-29 23:27:12 +02:00
|
|
|
EXPECT_STREQ("en-GB,en;q=0.9", accept_language.data());
|
2015-02-18 18:28:56 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if (handled) {
|
|
|
|
if (test_results_->delay > 0) {
|
|
|
|
// Continue after the delay.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostDelayedTask(
|
|
|
|
TID_IO, base::BindOnce(&CefCallback::Continue, callback.get()),
|
|
|
|
test_results_->delay);
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
// Continue immediately.
|
|
|
|
callback->Continue();
|
|
|
|
}
|
|
|
|
return true;
|
2016-05-11 20:20:07 +02:00
|
|
|
} else if (test_results_->response_error_code != ERR_NONE) {
|
|
|
|
// Propagate the error code.
|
|
|
|
callback->Continue();
|
|
|
|
return true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Response was canceled.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (g_current_handler) {
|
2012-04-03 03:34:16 +02:00
|
|
|
g_current_handler->DestroyTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t& response_length,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefString& redirectUrl) override {
|
2023-05-03 13:38:48 +02:00
|
|
|
CefResponse::HeaderMap headers;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if (is_sub_) {
|
|
|
|
response->SetStatus(test_results_->sub_status_code);
|
|
|
|
|
|
|
|
if (!test_results_->sub_allow_origin.empty()) {
|
|
|
|
// Set the Access-Control-Allow-Origin header to allow cross-domain
|
|
|
|
// scripting.
|
|
|
|
headers.insert(std::make_pair("Access-Control-Allow-Origin",
|
|
|
|
test_results_->sub_allow_origin));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!test_results_->sub_html.empty()) {
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response_length = test_results_->sub_html.size();
|
|
|
|
}
|
|
|
|
} else if (!test_results_->redirect_url.empty()) {
|
|
|
|
redirectUrl = test_results_->redirect_url;
|
2016-05-11 20:20:07 +02:00
|
|
|
} else if (test_results_->response_error_code != ERR_NONE) {
|
|
|
|
response->SetError(test_results_->response_error_code);
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
response->SetStatus(test_results_->status_code);
|
|
|
|
|
|
|
|
if (!test_results_->html.empty()) {
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response_length = test_results_->html.size();
|
|
|
|
}
|
|
|
|
}
|
2023-05-03 13:38:48 +02:00
|
|
|
|
|
|
|
if (test_results_->needs_same_origin_policy_relaxation) {
|
|
|
|
// Apply same-origin policy relaxation for document.domain.
|
|
|
|
headers.insert(std::make_pair("Origin-Agent-Cluster", "?0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!headers.empty()) {
|
|
|
|
response->SetHeaderMap(headers);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void Cancel() override { EXPECT_TRUE(CefCurrentlyOn(TID_IO)); }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool ReadResponse(void* data_out,
|
|
|
|
int bytes_to_read,
|
|
|
|
int& bytes_read,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
if (test_results_->delay > 0) {
|
|
|
|
if (!has_delayed_) {
|
|
|
|
// Continue after a delay.
|
2019-12-31 13:24:10 +01:00
|
|
|
CefPostDelayedTask(
|
|
|
|
TID_IO,
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&ClientSchemeHandlerOld::ContinueAfterDelay, this,
|
|
|
|
callback),
|
2019-12-31 13:24:10 +01:00
|
|
|
test_results_->delay);
|
2017-05-17 11:29:28 +02:00
|
|
|
bytes_read = 0;
|
|
|
|
return true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
has_delayed_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string* data;
|
|
|
|
|
|
|
|
if (is_sub_) {
|
|
|
|
test_results_->got_sub_read.yes();
|
|
|
|
data = &test_results_->sub_html;
|
|
|
|
} else {
|
|
|
|
test_results_->got_read.yes();
|
|
|
|
data = &test_results_->html;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_data = false;
|
|
|
|
bytes_read = 0;
|
|
|
|
|
|
|
|
size_t size = data->size();
|
|
|
|
if (offset_ < size) {
|
|
|
|
int transfer_size =
|
|
|
|
std::min(bytes_to_read, static_cast<int>(size - offset_));
|
|
|
|
memcpy(data_out, data->c_str() + offset_, transfer_size);
|
|
|
|
offset_ += transfer_size;
|
|
|
|
|
|
|
|
bytes_read = transfer_size;
|
|
|
|
has_data = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return has_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ContinueAfterDelay(CefRefPtr<CefCallback> callback) {
|
|
|
|
has_delayed_ = true;
|
|
|
|
callback->Continue();
|
|
|
|
}
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults* const test_results_;
|
2024-01-20 18:00:09 +01:00
|
|
|
size_t offset_ = 0;
|
|
|
|
bool is_sub_ = false;
|
|
|
|
bool has_delayed_ = false;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
IMPLEMENT_REFCOUNTING(ClientSchemeHandlerOld);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ClientSchemeHandlerOld);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClientSchemeHandler : public CefResourceHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
explicit ClientSchemeHandler(TestResults* tr) : test_results_(tr) {}
|
2019-12-31 13:24:10 +01:00
|
|
|
|
|
|
|
bool Open(CefRefPtr<CefRequest> request,
|
|
|
|
bool& handle_request,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
if (IsChromeRuntimeEnabled() && request->GetResourceType() == RT_FAVICON) {
|
|
|
|
// Ignore favicon requests.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
std::string url = request->GetURL();
|
|
|
|
is_sub_ =
|
|
|
|
(!test_results_->sub_url.empty() && test_results_->sub_url == url);
|
|
|
|
|
|
|
|
if (is_sub_) {
|
|
|
|
test_results_->got_sub_request.yes();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!test_results_->sub_html.empty()) {
|
2019-12-31 13:24:10 +01:00
|
|
|
handled = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-12-31 13:24:10 +01:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(url, test_results_->url);
|
|
|
|
|
|
|
|
test_results_->got_request.yes();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!test_results_->html.empty()) {
|
2019-12-31 13:24:10 +01:00
|
|
|
handled = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-12-31 13:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string accept_language;
|
|
|
|
CefRequest::HeaderMap headerMap;
|
|
|
|
CefRequest::HeaderMap::iterator headerIter;
|
|
|
|
request->GetHeaderMap(headerMap);
|
|
|
|
headerIter = headerMap.find("Accept-Language");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (headerIter != headerMap.end()) {
|
2019-12-31 13:24:10 +01:00
|
|
|
accept_language = headerIter->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-12-31 13:24:10 +01:00
|
|
|
EXPECT_TRUE(!accept_language.empty());
|
|
|
|
|
|
|
|
if (!test_results_->accept_language.empty()) {
|
2023-10-05 22:54:42 +02:00
|
|
|
// Value from CefRequestContextSettings.accept_language_list.
|
2019-12-31 13:24:10 +01:00
|
|
|
EXPECT_STREQ(test_results_->accept_language.data(),
|
|
|
|
accept_language.data());
|
|
|
|
} else {
|
|
|
|
// CEF_SETTINGS_ACCEPT_LANGUAGE value from
|
|
|
|
// CefSettings.accept_language_list set in CefTestSuite::GetSettings()
|
|
|
|
// and expanded internally by ComputeAcceptLanguageFromPref.
|
|
|
|
EXPECT_STREQ("en-GB,en;q=0.9", accept_language.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue or cancel the request immediately based on the return value.
|
|
|
|
handle_request = true;
|
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
if (test_results_->delay > 0) {
|
|
|
|
// Continue after the delay.
|
|
|
|
handle_request = false;
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostDelayedTask(
|
|
|
|
TID_FILE_USER_BLOCKING,
|
|
|
|
base::BindOnce(&CefCallback::Continue, callback.get()),
|
|
|
|
test_results_->delay);
|
2019-12-31 13:24:10 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (test_results_->response_error_code != ERR_NONE) {
|
|
|
|
// Propagate the error code.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Response was canceled.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (g_current_handler) {
|
2019-12-31 13:24:10 +01:00
|
|
|
g_current_handler->DestroyTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-12-31 13:24:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessRequest(CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
2020-09-25 03:40:47 +02:00
|
|
|
if (IsChromeRuntimeEnabled() && request->GetResourceType() == RT_FAVICON) {
|
|
|
|
// Ignore favicon requests.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
EXPECT_TRUE(false); // Not reached.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t& response_length,
|
2019-12-31 13:24:10 +01:00
|
|
|
CefString& redirectUrl) override {
|
2023-05-03 13:38:48 +02:00
|
|
|
CefResponse::HeaderMap headers;
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
if (is_sub_) {
|
|
|
|
response->SetStatus(test_results_->sub_status_code);
|
|
|
|
|
|
|
|
if (!test_results_->sub_allow_origin.empty()) {
|
|
|
|
// Set the Access-Control-Allow-Origin header to allow cross-domain
|
|
|
|
// scripting.
|
|
|
|
headers.insert(std::make_pair("Access-Control-Allow-Origin",
|
|
|
|
test_results_->sub_allow_origin));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!test_results_->sub_html.empty()) {
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response_length = test_results_->sub_html.size();
|
|
|
|
}
|
|
|
|
} else if (!test_results_->redirect_url.empty()) {
|
|
|
|
redirectUrl = test_results_->redirect_url;
|
|
|
|
} else if (test_results_->response_error_code != ERR_NONE) {
|
|
|
|
response->SetError(test_results_->response_error_code);
|
|
|
|
} else {
|
|
|
|
response->SetStatus(test_results_->status_code);
|
|
|
|
|
|
|
|
if (!test_results_->html.empty()) {
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response_length = test_results_->html.size();
|
|
|
|
}
|
|
|
|
}
|
2023-05-03 13:38:48 +02:00
|
|
|
|
|
|
|
if (test_results_->needs_same_origin_policy_relaxation) {
|
|
|
|
// Apply same-origin policy relaxation for document.domain.
|
|
|
|
headers.insert(std::make_pair("Origin-Agent-Cluster", "?0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!headers.empty()) {
|
|
|
|
response->SetHeaderMap(headers);
|
|
|
|
}
|
2019-12-31 13:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() override { EXPECT_TRUE(CefCurrentlyOn(TID_IO)); }
|
|
|
|
|
|
|
|
bool Read(void* data_out,
|
|
|
|
int bytes_to_read,
|
|
|
|
int& bytes_read,
|
|
|
|
CefRefPtr<CefResourceReadCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
if (test_results_->delay > 0) {
|
|
|
|
if (!has_delayed_) {
|
|
|
|
// Continue after a delay.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostDelayedTask(
|
|
|
|
TID_FILE_USER_BLOCKING,
|
|
|
|
base::BindOnce(&ClientSchemeHandler::ContinueAfterDelay, this,
|
|
|
|
data_out, bytes_to_read, callback),
|
|
|
|
test_results_->delay);
|
2019-12-31 13:24:10 +01:00
|
|
|
bytes_read = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
has_delayed_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetData(data_out, bytes_to_read, bytes_read);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReadResponse(void* data_out,
|
|
|
|
int bytes_to_read,
|
|
|
|
int& bytes_read,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
|
|
|
EXPECT_TRUE(false); // Not reached.
|
|
|
|
bytes_read = -2;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ContinueAfterDelay(void* data_out,
|
|
|
|
int bytes_to_read,
|
|
|
|
CefRefPtr<CefResourceReadCallback> callback) {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
has_delayed_ = true;
|
|
|
|
|
|
|
|
int bytes_read = 0;
|
|
|
|
GetData(data_out, bytes_to_read, bytes_read);
|
|
|
|
callback->Continue(bytes_read);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetData(void* data_out, int bytes_to_read, int& bytes_read) {
|
|
|
|
std::string* data;
|
|
|
|
|
|
|
|
if (is_sub_) {
|
|
|
|
test_results_->got_sub_read.yes();
|
|
|
|
data = &test_results_->sub_html;
|
|
|
|
} else {
|
|
|
|
test_results_->got_read.yes();
|
|
|
|
data = &test_results_->html;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default to response complete.
|
|
|
|
bool has_data = false;
|
|
|
|
bytes_read = 0;
|
|
|
|
|
|
|
|
size_t size = data->size();
|
|
|
|
if (offset_ < size) {
|
|
|
|
int transfer_size =
|
|
|
|
std::min(bytes_to_read, static_cast<int>(size - offset_));
|
|
|
|
memcpy(data_out, data->c_str() + offset_, transfer_size);
|
|
|
|
offset_ += transfer_size;
|
|
|
|
|
|
|
|
bytes_read = transfer_size;
|
|
|
|
has_data = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return has_data;
|
|
|
|
}
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults* const test_results_;
|
2024-01-20 18:00:09 +01:00
|
|
|
size_t offset_ = 0;
|
|
|
|
bool is_sub_ = false;
|
|
|
|
bool has_delayed_ = false;
|
2019-12-31 13:24:10 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(ClientSchemeHandler);
|
2019-12-31 13:24:10 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ClientSchemeHandler);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit ClientSchemeHandlerFactory(TestResults* tr) : test_results_(tr) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& scheme_name,
|
|
|
|
CefRefPtr<CefRequest> request) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
2019-12-31 13:24:10 +01:00
|
|
|
if (TestOldResourceAPI()) {
|
|
|
|
return new ClientSchemeHandlerOld(test_results_);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return new ClientSchemeHandler(test_results_);
|
|
|
|
}
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults* const test_results_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(ClientSchemeHandlerFactory);
|
2019-12-31 13:24:10 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ClientSchemeHandlerFactory);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// If |domain| is empty the scheme will be registered as non-standard.
|
2023-05-03 13:38:48 +02:00
|
|
|
void RegisterTestScheme(TestResults* test_results,
|
|
|
|
const std::string& scheme,
|
|
|
|
const std::string& domain) {
|
2023-10-05 22:54:42 +02:00
|
|
|
if (test_results->request_context) {
|
|
|
|
EXPECT_TRUE(test_results->request_context->RegisterSchemeHandlerFactory(
|
|
|
|
scheme, domain, new ClientSchemeHandlerFactory(test_results)));
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(CefRegisterSchemeHandlerFactory(
|
|
|
|
scheme, domain, new ClientSchemeHandlerFactory(test_results)));
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
WaitForIOThread();
|
|
|
|
}
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
void ClearTestSchemes(TestResults* test_results) {
|
|
|
|
if (test_results->request_context) {
|
|
|
|
EXPECT_TRUE(test_results->request_context->ClearSchemeHandlerFactories());
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(CefClearSchemeHandlerFactories());
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
WaitForIOThread();
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
struct XHRTestSettings {
|
2023-05-03 13:38:48 +02:00
|
|
|
XHRTestSettings() = default;
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
std::string url;
|
|
|
|
std::string sub_url;
|
|
|
|
std::string sub_allow_origin;
|
|
|
|
std::string sub_redirect_url;
|
2023-05-03 13:38:48 +02:00
|
|
|
bool synchronous = true;
|
2013-04-18 19:58:23 +02:00
|
|
|
};
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
void SetUpXHR(TestResults* test_results, const XHRTestSettings& settings) {
|
|
|
|
test_results->sub_url = settings.sub_url;
|
|
|
|
test_results->sub_html = "SUCCESS";
|
|
|
|
test_results->sub_allow_origin = settings.sub_allow_origin;
|
|
|
|
test_results->sub_redirect_url = settings.sub_redirect_url;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
std::string request_url;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!settings.sub_redirect_url.empty()) {
|
2013-04-18 19:58:23 +02:00
|
|
|
request_url = settings.sub_redirect_url;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-04-18 19:58:23 +02:00
|
|
|
request_url = settings.sub_url;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->url = settings.url;
|
2012-04-03 03:34:16 +02:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << "<html><head>"
|
|
|
|
"<script language=\"JavaScript\">"
|
2013-04-18 19:58:23 +02:00
|
|
|
"function onResult(val) {"
|
2023-04-29 00:17:03 +02:00
|
|
|
" document.location = \"https://tests/exit?result=\"+val;"
|
2012-04-03 03:34:16 +02:00
|
|
|
"}"
|
2013-04-18 19:58:23 +02:00
|
|
|
"function execXMLHttpRequest() {";
|
|
|
|
if (settings.synchronous) {
|
|
|
|
ss << "var result = 'FAILURE';"
|
|
|
|
"try {"
|
|
|
|
" xhr = new XMLHttpRequest();"
|
2017-05-17 11:29:28 +02:00
|
|
|
" xhr.open(\"GET\", \""
|
|
|
|
<< request_url.c_str()
|
|
|
|
<< "\", false);"
|
2013-04-18 19:58:23 +02:00
|
|
|
" xhr.send();"
|
|
|
|
" result = xhr.responseText;"
|
|
|
|
"} catch(e) {}"
|
|
|
|
"onResult(result)";
|
|
|
|
} else {
|
|
|
|
ss << "xhr = new XMLHttpRequest();"
|
2017-05-17 11:29:28 +02:00
|
|
|
"xhr.open(\"GET\", \""
|
|
|
|
<< request_url.c_str()
|
|
|
|
<< "\", true);"
|
2013-04-18 19:58:23 +02:00
|
|
|
"xhr.onload = function(e) {"
|
|
|
|
" if (xhr.readyState === 4) {"
|
|
|
|
" if (xhr.status === 200) {"
|
|
|
|
" onResult(xhr.responseText);"
|
|
|
|
" } else {"
|
2017-05-17 11:29:28 +02:00
|
|
|
" console.log('XMLHttpRequest failed with status ' + "
|
|
|
|
"xhr.status);"
|
2013-04-18 19:58:23 +02:00
|
|
|
" onResult('FAILURE');"
|
|
|
|
" }"
|
|
|
|
" }"
|
|
|
|
"};"
|
|
|
|
"xhr.onerror = function(e) {"
|
|
|
|
" onResult('FAILURE');"
|
|
|
|
"};"
|
|
|
|
"xhr.send()";
|
|
|
|
}
|
|
|
|
ss << "}"
|
2012-04-03 03:34:16 +02:00
|
|
|
"</script>"
|
|
|
|
"</head><body onload=\"execXMLHttpRequest();\">"
|
|
|
|
"Running execXMLHttpRequest..."
|
|
|
|
"</body></html>";
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->html = ss.str();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->exit_url = "https://tests/exit";
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
struct FetchTestSettings {
|
2023-05-03 13:38:48 +02:00
|
|
|
FetchTestSettings() = default;
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
std::string url;
|
|
|
|
std::string sub_url;
|
|
|
|
std::string sub_allow_origin;
|
|
|
|
std::string sub_redirect_url;
|
|
|
|
};
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
void SetUpFetch(TestResults* test_results, const FetchTestSettings& settings) {
|
|
|
|
test_results->sub_url = settings.sub_url;
|
|
|
|
test_results->sub_html = "SUCCESS";
|
|
|
|
test_results->sub_allow_origin = settings.sub_allow_origin;
|
|
|
|
test_results->sub_redirect_url = settings.sub_redirect_url;
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
std::string request_url;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!settings.sub_redirect_url.empty()) {
|
2019-02-04 23:31:31 +01:00
|
|
|
request_url = settings.sub_redirect_url;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2019-02-04 23:31:31 +01:00
|
|
|
request_url = settings.sub_url;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->url = settings.url;
|
2019-02-04 23:31:31 +01:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << "<html><head>"
|
|
|
|
"<script language=\"JavaScript\">"
|
|
|
|
"function onResult(val) {"
|
2023-04-29 00:17:03 +02:00
|
|
|
" document.location = \"https://tests/exit?result=\"+val;"
|
2019-02-04 23:31:31 +01:00
|
|
|
"}"
|
|
|
|
"function execFetchHttpRequest() {";
|
|
|
|
ss << "fetch('" << request_url.c_str()
|
|
|
|
<< "')"
|
|
|
|
".then(function(response) {"
|
|
|
|
" if (response.status === 200) {"
|
|
|
|
" response.text().then(function(text) {"
|
|
|
|
" onResult(text);"
|
|
|
|
" }).catch(function(e) {"
|
|
|
|
" onResult('FAILURE'); "
|
|
|
|
" });"
|
|
|
|
" } else {"
|
|
|
|
" onResult('FAILURE');"
|
|
|
|
" }"
|
|
|
|
"}).catch(function(e) {"
|
|
|
|
" onResult('FAILURE');"
|
|
|
|
"});"
|
|
|
|
<< "}"
|
|
|
|
"</script>"
|
|
|
|
"</head><body onload=\"execFetchHttpRequest();\">"
|
|
|
|
"Running execFetchHttpRequest..."
|
|
|
|
"</body></html>";
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->html = ss.str();
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->exit_url = "https://tests/exit";
|
2019-02-04 23:31:31 +01:00
|
|
|
} // namespace
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
void SetUpXSS(TestResults* test_results,
|
|
|
|
const std::string& url,
|
2017-05-17 11:29:28 +02:00
|
|
|
const std::string& sub_url,
|
2012-04-03 03:34:16 +02:00
|
|
|
const std::string& domain = std::string()) {
|
|
|
|
// 1. Load |url| which contains an iframe.
|
2018-10-02 14:14:11 +02:00
|
|
|
// 2. The iframe loads |sub_url|.
|
|
|
|
// 3. |sub_url| tries to call a JS function in |url|.
|
|
|
|
// 4. |url| tries to call a JS function in |sub_url|.
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
std::string domain_line;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!domain.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
domain_line = "document.domain = '" + domain + "';";
|
2023-05-03 13:38:48 +02:00
|
|
|
if (url.find("http") == 0 && sub_url.find("http") == 0) {
|
|
|
|
test_results->needs_same_origin_policy_relaxation = true;
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->sub_url = sub_url;
|
2012-04-03 03:34:16 +02:00
|
|
|
ss << "<html><head>"
|
2017-05-17 11:29:28 +02:00
|
|
|
"<script language=\"JavaScript\">"
|
|
|
|
<< domain_line
|
|
|
|
<< "function getResult() {"
|
2012-04-03 03:34:16 +02:00
|
|
|
" return 'SUCCESS';"
|
|
|
|
"}"
|
|
|
|
"function execXSSRequest() {"
|
|
|
|
" var result = 'FAILURE';"
|
|
|
|
" try {"
|
|
|
|
" result = parent.getResult();"
|
2018-10-02 14:14:11 +02:00
|
|
|
" } catch(e) { console.log(e.stack); }"
|
2023-04-29 00:17:03 +02:00
|
|
|
" document.location = \"https://tests/exit?result=\"+result;"
|
2012-04-03 03:34:16 +02:00
|
|
|
"}"
|
|
|
|
"</script>"
|
|
|
|
"</head><body onload=\"execXSSRequest();\">"
|
|
|
|
"Running execXSSRequest..."
|
|
|
|
"</body></html>";
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->sub_html = ss.str();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->url = url;
|
2012-04-03 03:34:16 +02:00
|
|
|
ss.str("");
|
|
|
|
ss << "<html><head>"
|
2017-05-17 11:29:28 +02:00
|
|
|
"<script language=\"JavaScript\">"
|
|
|
|
<< domain_line
|
|
|
|
<< ""
|
2012-04-03 03:34:16 +02:00
|
|
|
"function getResult() {"
|
|
|
|
" try {"
|
|
|
|
" return document.getElementById('s').contentWindow.getResult();"
|
2018-10-02 14:14:11 +02:00
|
|
|
" } catch(e) { console.log(e.stack); }"
|
2012-04-03 03:34:16 +02:00
|
|
|
" return 'FAILURE';"
|
|
|
|
"}"
|
|
|
|
"</script>"
|
|
|
|
"</head><body>"
|
2017-05-17 11:29:28 +02:00
|
|
|
"<iframe src=\""
|
|
|
|
<< sub_url.c_str()
|
|
|
|
<< "\" id=\"s\">"
|
2012-04-03 03:34:16 +02:00
|
|
|
"</body></html>";
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->html = ss.str();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results->exit_url = "https://tests/exit";
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that scheme registration/unregistration works as expected.
|
|
|
|
TEST(SchemeHandlerTest, Registration) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
|
|
|
test_results.html =
|
2012-04-03 03:34:16 +02:00
|
|
|
"<html><head></head><body><h1>Success!</h1></body></html>";
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Unregister the handler.
|
2020-01-15 14:34:01 +01:00
|
|
|
EXPECT_TRUE(CefRegisterSchemeHandlerFactory("customstd", "test", nullptr));
|
2012-04-03 03:34:16 +02:00
|
|
|
WaitForIOThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.got_request.reset();
|
|
|
|
test_results.got_read.reset();
|
|
|
|
test_results.got_output.reset();
|
|
|
|
test_results.expected_error_code = ERR_UNKNOWN_URL_SCHEME;
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_error);
|
|
|
|
EXPECT_FALSE(test_results.got_request);
|
|
|
|
EXPECT_FALSE(test_results.got_read);
|
|
|
|
EXPECT_FALSE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Re-register the handler.
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_TRUE(CefRegisterSchemeHandlerFactory(
|
2023-05-03 13:38:48 +02:00
|
|
|
"customstd", "test", new ClientSchemeHandlerFactory(&test_results)));
|
2012-04-03 03:34:16 +02:00
|
|
|
WaitForIOThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.got_error.reset();
|
|
|
|
test_results.expected_error_code = ERR_NONE;
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_FALSE(test_results.got_error);
|
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can return normal results.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardNormalResponse) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
|
|
|
test_results.html =
|
2012-04-03 03:34:16 +02:00
|
|
|
"<html><head></head><body><h1>Success!</h1></body></html>";
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can return normal results with delayed
|
|
|
|
// responses.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardNormalResponseDelayed) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
|
|
|
test_results.html =
|
2012-04-03 03:34:16 +02:00
|
|
|
"<html><head></head><body><h1>Success!</h1></body></html>";
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.delay = 100;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom nonstandard scheme can return normal results.
|
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardNormalResponse) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
test_results.url = "customnonstd:some%20value";
|
|
|
|
test_results.html =
|
2012-04-03 03:34:16 +02:00
|
|
|
"<html><head></head><body><h1>Success!</h1></body></html>";
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can return an error code.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardErrorResponse) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
|
|
|
test_results.html = "<html><head></head><body><h1>404</h1></body></html>";
|
|
|
|
test_results.status_code = 404;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
// Test that a custom standard scheme can return a CEF error code in the
|
|
|
|
// response.
|
2016-05-11 20:20:07 +02:00
|
|
|
TEST(SchemeHandlerTest, CustomStandardErrorCodeResponse) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
|
|
|
test_results.response_error_code = ERR_FILE_TOO_BIG;
|
|
|
|
test_results.expected_error_code = ERR_FILE_TOO_BIG;
|
2016-05-11 20:20:07 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2016-05-11 20:20:07 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_FALSE(test_results.got_read);
|
|
|
|
EXPECT_FALSE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_error);
|
2016-05-11 20:20:07 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2016-05-11 20:20:07 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that a custom nonstandard scheme can return an error code.
|
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardErrorResponse) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
test_results.url = "customnonstd:some%20value";
|
|
|
|
test_results.html = "<html><head></head><body><h1>404</h1></body></html>";
|
|
|
|
test_results.status_code = 404;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that custom standard scheme handling fails when the scheme name is
|
|
|
|
// incorrect.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardNameNotHandled) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd2://test/run.html";
|
|
|
|
test_results.expected_error_code = ERR_UNKNOWN_URL_SCHEME;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_FALSE(test_results.got_request);
|
|
|
|
EXPECT_FALSE(test_results.got_read);
|
|
|
|
EXPECT_FALSE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_error);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that custom nonstandard scheme handling fails when the scheme name is
|
|
|
|
// incorrect.
|
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardNameNotHandled) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
test_results.url = "customnonstd2:some%20value";
|
|
|
|
test_results.expected_error_code = ERR_UNKNOWN_URL_SCHEME;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_FALSE(test_results.got_request);
|
|
|
|
EXPECT_FALSE(test_results.got_read);
|
|
|
|
EXPECT_FALSE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_error);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that custom standard scheme handling fails when the domain name is
|
|
|
|
// incorrect.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardDomainNotHandled) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://noexist/run.html";
|
|
|
|
test_results.expected_error_code = ERR_UNKNOWN_URL_SCHEME;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_FALSE(test_results.got_request);
|
|
|
|
EXPECT_FALSE(test_results.got_read);
|
|
|
|
EXPECT_FALSE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_error);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can return no response.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardNoResponse) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_FALSE(test_results.got_read);
|
|
|
|
EXPECT_FALSE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom nonstandard scheme can return no response.
|
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardNoResponse) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
test_results.url = "customnonstd:some%20value";
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_FALSE(test_results.got_read);
|
|
|
|
EXPECT_FALSE(test_results.got_output);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can generate redirects.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardRedirect) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
|
|
|
test_results.redirect_url = "customstd://test/redirect.html";
|
|
|
|
test_results.html =
|
2012-04-03 03:34:16 +02:00
|
|
|
"<html><head></head><body><h1>Redirected</h1></body></html>";
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_redirect);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom nonstandard scheme can generate redirects.
|
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardRedirect) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
test_results.url = "customnonstd:some%20value";
|
|
|
|
test_results.redirect_url = "customnonstd:some%20other%20value";
|
|
|
|
test_results.html =
|
2012-04-03 03:34:16 +02:00
|
|
|
"<html><head></head><body><h1>Redirected</h1></body></html>";
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_redirect);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can generate same origin XHR requests.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRSameOriginSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test/run.html";
|
|
|
|
settings.sub_url = "customstd://test/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can generate same origin XHR requests.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRSameOriginAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test/run.html";
|
|
|
|
settings.sub_url = "customstd://test/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Test that custom nonstandard schemes are treated as unique origins that
|
|
|
|
// cannot generate XHR requests.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardXHRSameOriginSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customnonstd:some%20value";
|
|
|
|
settings.sub_url = "customnonstd:xhr%20value";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to XMLHttpRequest at 'customnonstd:xhr%20value' from origin "
|
|
|
|
"'null' has been blocked by CORS policy: Cross origin requests are only "
|
|
|
|
"supported for protocol schemes:");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_request);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Test that custom nonstandard schemes are treated as unique origins that
|
|
|
|
// cannot generate XHR requests.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardXHRSameOriginAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customnonstd:some%20value";
|
|
|
|
settings.sub_url = "customnonstd:xhr%20value";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to XMLHttpRequest at 'customnonstd:xhr%20value' from origin "
|
|
|
|
"'null' has been blocked by CORS policy: Cross origin requests are only "
|
|
|
|
"supported for protocol schemes:");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_request);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that a non fetch enabled custom standard scheme can't generate same
|
|
|
|
// origin Fetch requests.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardFetchSameOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstd://test/run.html";
|
|
|
|
settings.sub_url = "customstd://test/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Fetch API cannot load customstd://test/fetch.html. URL scheme "
|
|
|
|
"\"customstd\" is not supported.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_request);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a fetch enabled custom standard scheme can generate same origin
|
|
|
|
// Fetch requests.
|
|
|
|
TEST(SchemeHandlerTest, FetchCustomStandardFetchSameOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that custom nonstandard schemes are treated as unique origins that
|
|
|
|
// cannot generate Fetch requests.
|
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardFetchSameOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customnonstd:some%20value";
|
|
|
|
settings.sub_url = "customnonstd:xhr%20value";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2021-06-04 03:34:56 +02:00
|
|
|
"Fetch API cannot load customnonstd:xhr%20value. URL scheme "
|
|
|
|
"\"customnonstd\" is not supported.");
|
2020-08-14 21:28:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_request);
|
|
|
|
EXPECT_FALSE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that a custom standard scheme can generate same origin XSS requests.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXSSSameOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
SetUpXSS(&test_results, "customstd://test/run.html",
|
|
|
|
"customstd://test/iframe.html");
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Test that custom nonstandard schemes are treated as unique origins that
|
|
|
|
// cannot generate XSS requests.
|
2012-04-03 03:34:16 +02:00
|
|
|
TEST(SchemeHandlerTest, CustomNonStandardXSSSameOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
SetUpXSS(&test_results, "customnonstd:some%20value",
|
|
|
|
"customnonstd:xhr%20value");
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-10-19 20:08:48 +02:00
|
|
|
"Error: Failed to read a named property 'getResult' from 'Window': "
|
|
|
|
"Blocked a frame with origin \"null\" from accessing a "
|
2020-08-14 21:28:23 +02:00
|
|
|
"cross-origin frame.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme cannot generate cross-domain XHR requests
|
2013-04-18 19:58:23 +02:00
|
|
|
// by default. Behavior should be the same as with HTTP.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to XMLHttpRequest at 'customstd://test2/xhr.html' from origin "
|
|
|
|
"'customstd://test1' has been blocked by CORS policy: No "
|
|
|
|
"'Access-Control-Allow-Origin' header is present on the requested "
|
|
|
|
"resource.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme cannot generate cross-domain XHR requests
|
|
|
|
// by default. Behavior should be the same as with HTTP.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to XMLHttpRequest at 'customstd://test2/xhr.html' from origin "
|
|
|
|
"'customstd://test1' has been blocked by CORS policy: No "
|
|
|
|
"'Access-Control-Allow-Origin' header is present on the requested "
|
|
|
|
"resource.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that a custom standard scheme cannot generate cross-domain Fetch
|
|
|
|
// requests by default. Behavior should be the same as with HTTP.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardFetchDifferentOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test2/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to fetch at 'customstdfetch://test2/fetch.html' from origin "
|
|
|
|
"'customstdfetch://test1' has been blocked by CORS policy: No "
|
|
|
|
"'Access-Control-Allow-Origin' header is present on the requested "
|
|
|
|
"resource. If an opaque response serves your needs, set the request's "
|
|
|
|
"mode to 'no-cors' to fetch the resource with CORS disabled.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that a custom standard scheme cannot generate cross-domain XSS requests
|
|
|
|
// by default.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXSSDifferentOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
|
|
|
SetUpXSS(&test_results, "customstd://test1/run.html",
|
|
|
|
"customstd://test2/iframe.html");
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-10-19 20:08:48 +02:00
|
|
|
"Error: Failed to read a named property 'getResult' from 'Window': "
|
|
|
|
"Blocked a frame with origin \"customstd://test2\" from accessing "
|
2020-08-14 21:28:23 +02:00
|
|
|
"a cross-origin frame.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-05-12 00:11:53 +02:00
|
|
|
// Test that a cross-protocol iframe load succeeds, and that the custom
|
|
|
|
// standard scheme cannot generate XSS requests to the HTTP protocol by default.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXSSDifferentProtocolHttp) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
|
|
|
SetUpXSS(&test_results, "customstd://test1/run.html",
|
|
|
|
"https://test2/iframe.html");
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-10-19 20:08:48 +02:00
|
|
|
"Error: Failed to read a named property 'getResult' from 'Window': "
|
|
|
|
"Blocked a frame with origin \"https://test2\" from accessing a "
|
2020-08-14 21:28:23 +02:00
|
|
|
"cross-origin frame.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a cross-protocol iframe load succeeds, and that the custom
|
|
|
|
// standard scheme cannot generate XSS requests to a non-standard scheme by
|
|
|
|
// default.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXSSDifferentProtocolCustomNonStandard) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
SetUpXSS(&test_results, "customstd://test1/run.html",
|
|
|
|
"customnonstd:some%20value");
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-10-19 20:08:48 +02:00
|
|
|
"Error: Failed to read a named property 'getResult' from 'Window': "
|
|
|
|
"Blocked a frame with origin \"null\" from accessing a "
|
2020-08-14 21:28:23 +02:00
|
|
|
"cross-origin frame.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a cross-protocol iframe load succeeds, and that the HTTP protocol
|
|
|
|
// cannot generate XSS requests to the custom standard scheme by default.
|
|
|
|
TEST(SchemeHandlerTest, HttpXSSDifferentProtocolCustomStandard) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
|
|
|
SetUpXSS(&test_results, "https://test1/run.html",
|
|
|
|
"customstd://test2/iframe.html");
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-10-19 20:08:48 +02:00
|
|
|
"Error: Failed to read a named property 'getResult' from 'Window': "
|
|
|
|
"Blocked a frame with origin \"customstd://test2\" from accessing "
|
2020-08-14 21:28:23 +02:00
|
|
|
"a cross-origin frame.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a cross-protocol iframe load succeeds, and that the HTTP protocol
|
|
|
|
// cannot generate XSS requests to the custom non-standard scheme by default.
|
|
|
|
TEST(SchemeHandlerTest, HttpXSSDifferentProtocolCustomNonStandard) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customnonstd", std::string());
|
|
|
|
SetUpXSS(&test_results, "https://test1/run.html",
|
|
|
|
"customnonstd:some%20value");
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-10-19 20:08:48 +02:00
|
|
|
"Error: Failed to read a named property 'getResult' from 'Window': "
|
|
|
|
"Blocked a frame with origin \"null\" from accessing a "
|
2020-08-14 21:28:23 +02:00
|
|
|
"cross-origin frame.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2020-05-12 00:11:53 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2020-05-12 00:11:53 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that an HTTP scheme cannot generate cross-domain XHR requests by
|
|
|
|
// default.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest, HttpXHRDifferentOriginSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
2023-04-29 00:17:03 +02:00
|
|
|
settings.url = "https://test1/run.html";
|
|
|
|
settings.sub_url = "https://test2/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-04-29 00:17:03 +02:00
|
|
|
"Access to XMLHttpRequest at 'https://test2/xhr.html' from origin "
|
|
|
|
"'https://test1' has been blocked by CORS policy: No "
|
2020-08-14 21:28:23 +02:00
|
|
|
"'Access-Control-Allow-Origin' header is present on the requested "
|
|
|
|
"resource.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that an HTTP scheme cannot generate cross-domain XHR requests by
|
|
|
|
// default.
|
|
|
|
TEST(SchemeHandlerTest, HttpXHRDifferentOriginAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
2023-04-29 00:17:03 +02:00
|
|
|
settings.url = "https://test1/run.html";
|
|
|
|
settings.sub_url = "https://test2/xhr.html";
|
2013-04-18 19:58:23 +02:00
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-04-29 00:17:03 +02:00
|
|
|
"Access to XMLHttpRequest at 'https://test2/xhr.html' from origin "
|
|
|
|
"'https://test1' has been blocked by CORS policy: No "
|
2020-08-14 21:28:23 +02:00
|
|
|
"'Access-Control-Allow-Origin' header is present on the requested "
|
|
|
|
"resource.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that an HTTP scheme cannot generate cross-domain Fetch requests by
|
|
|
|
// default.
|
|
|
|
TEST(SchemeHandlerTest, HttpFetchDifferentOriginAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
2023-04-29 00:17:03 +02:00
|
|
|
settings.url = "https://test1/run.html";
|
|
|
|
settings.sub_url = "https://test2/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-04-29 00:17:03 +02:00
|
|
|
"Access to fetch at 'https://test2/fetch.html' from origin "
|
|
|
|
"'https://test1' "
|
2020-08-14 21:28:23 +02:00
|
|
|
"has been blocked by CORS policy: No 'Access-Control-Allow-Origin' "
|
|
|
|
"header is present on the requested resource. If an opaque response "
|
|
|
|
"serves your needs, set the request's mode to 'no-cors' to fetch the "
|
|
|
|
"resource with CORS disabled.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that an HTTP scheme cannot generate cross-domain XSS requests by
|
|
|
|
// default.
|
|
|
|
TEST(SchemeHandlerTest, HttpXSSDifferentOrigin) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
|
|
|
SetUpXSS(&test_results, "https://test1/run.html", "https://test2/xss.html");
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2023-10-19 20:08:48 +02:00
|
|
|
"Error: Failed to read a named property 'getResult' from 'Window': "
|
|
|
|
"Blocked a frame with origin \"https://test2\" from accessing a "
|
2020-08-14 21:28:23 +02:00
|
|
|
"cross-origin frame.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
// Test that a custom standard scheme can generate cross-domain XHR requests
|
|
|
|
// when setting the Access-Control-Allow-Origin header. Should behave the same
|
|
|
|
// as HTTP.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithHeaderSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.sub_allow_origin = "customstd://test1";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can generate cross-domain XHR requests
|
|
|
|
// when setting the Access-Control-Allow-Origin header. Should behave the same
|
|
|
|
// as HTTP.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithHeaderAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.sub_allow_origin = "customstd://test1";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that a custom standard scheme can generate cross-domain Fetch requests
|
|
|
|
// when setting the Access-Control-Allow-Origin header. Should behave the same
|
|
|
|
// as HTTP.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithHeader) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test2/fetch.html";
|
|
|
|
settings.sub_allow_origin = "customstdfetch://test1";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
// Test that a custom standard scheme can generate cross-domain XHR requests
|
|
|
|
// when using the cross-origin whitelist.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistSync1) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
"test2", false));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches any domain.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistSync2) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
CefString(), true));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches sub-domains.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistSync3) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "a.test2.foo");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://a.test2.foo/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
"test2.foo", true));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can generate cross-domain XHR requests
|
|
|
|
// when using the cross-origin whitelist.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistAsync1) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
"test2", false));
|
2012-04-03 03:34:16 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
// Same as above but origin whitelist matches any domain.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistAsync2) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
CefString(), true));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches sub-domains.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistAsync3) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "a.test2.foo");
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://a.test2.foo/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
"test2.foo", true));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that a custom standard scheme can generate cross-domain Fetch requests
|
|
|
|
// when using the cross-origin whitelist.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithWhitelist1) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test2/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry(
|
|
|
|
"customstdfetch://test1", "customstdfetch", "test2", false));
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches any domain.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithWhitelist2) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test2/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry(
|
|
|
|
"customstdfetch://test1", "customstdfetch", CefString(), true));
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches sub-domains.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithWhitelist3) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "a.test2.foo");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://a.test2.foo/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry(
|
|
|
|
"customstdfetch://test1", "customstdfetch", "test2.foo", true));
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
// Test that an HTTP scheme can generate cross-domain XHR requests when setting
|
|
|
|
// the Access-Control-Allow-Origin header.
|
|
|
|
TEST(SchemeHandlerTest, HttpXHRDifferentOriginWithHeaderSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
2023-04-29 00:17:03 +02:00
|
|
|
settings.url = "https://test1/run.html";
|
|
|
|
settings.sub_url = "https://test2/xhr.html";
|
|
|
|
settings.sub_allow_origin = "https://test1";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that an HTTP scheme can generate cross-domain XHR requests when setting
|
|
|
|
// the Access-Control-Allow-Origin header.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest, HttpXHRDifferentOriginWithHeaderAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
2023-04-29 00:17:03 +02:00
|
|
|
settings.url = "https://test1/run.html";
|
|
|
|
settings.sub_url = "https://test2/xhr.html";
|
|
|
|
settings.sub_allow_origin = "https://test1";
|
2013-04-18 19:58:23 +02:00
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that an HTTP scheme can generate cross-domain XHR requests when setting
|
|
|
|
// the Access-Control-Allow-Origin header.
|
|
|
|
TEST(SchemeHandlerTest, HttpFetchDifferentOriginWithHeader) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "https", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
2023-04-29 00:17:03 +02:00
|
|
|
settings.url = "https://test1/run.html";
|
|
|
|
settings.sub_url = "https://test2/fetch.html";
|
|
|
|
settings.sub_allow_origin = "https://test1";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Test that a custom standard scheme can generate cross-domain XSS requests
|
|
|
|
// when using document.domain.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXSSDifferentOriginWithDomain) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "a.test.com");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "b.test.com");
|
|
|
|
SetUpXSS(&test_results, "customstd://a.test.com/run.html",
|
2017-05-17 11:29:28 +02:00
|
|
|
"customstd://b.test.com/iframe.html", "test.com");
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that an HTTP scheme can generate cross-domain XSS requests when using
|
|
|
|
// document.domain.
|
|
|
|
TEST(SchemeHandlerTest, HttpXSSDifferentOriginWithDomain) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "https", "a.test.com");
|
|
|
|
RegisterTestScheme(&test_results, "https", "b.test.com");
|
|
|
|
SetUpXSS(&test_results, "https://a.test.com/run.html",
|
|
|
|
"https://b.test.com/iframe.html", "test.com");
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2013-04-18 19:58:23 +02:00
|
|
|
// Test that a custom standard scheme cannot generate cross-domain XHR requests
|
|
|
|
// that perform redirects.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginRedirectSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.sub_redirect_url = "customstd://test1/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to XMLHttpRequest at 'customstd://test2/xhr.html' (redirected "
|
|
|
|
"from 'customstd://test1/xhr.html') from origin 'customstd://test1' has "
|
|
|
|
"been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is "
|
|
|
|
"present on the requested resource.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme cannot generate cross-domain XHR requests
|
|
|
|
// that perform redirects.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginRedirectAsync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.sub_redirect_url = "customstd://test1/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to XMLHttpRequest at 'customstd://test2/xhr.html' (redirected "
|
|
|
|
"from 'customstd://test1/xhr.html') from origin 'customstd://test1' has "
|
|
|
|
"been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is "
|
|
|
|
"present on the requested resource.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that a custom standard scheme cannot generate cross-domain Fetch
|
|
|
|
// requests that perform redirects.
|
|
|
|
TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginRedirect) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test2/fetch.html";
|
|
|
|
settings.sub_redirect_url = "customstdfetch://test1/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
test_results.console_messages.push_back(
|
2020-08-14 21:28:23 +02:00
|
|
|
"Access to fetch at 'customstdfetch://test2/fetch.html' (redirected from "
|
|
|
|
"'customstdfetch://test1/fetch.html') from origin "
|
|
|
|
"'customstdfetch://test1' has been blocked by CORS policy: No "
|
|
|
|
"'Access-Control-Allow-Origin' header is present on the requested "
|
|
|
|
"resource. If an opaque response serves your needs, set the request's "
|
|
|
|
"mode to 'no-cors' to fetch the resource with CORS disabled.");
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_FALSE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
// Test that a custom standard scheme can generate cross-domain XHR requests
|
|
|
|
// that perform redirects when using the cross-origin whitelist.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest,
|
|
|
|
CustomStandardXHRDifferentOriginRedirectWithWhitelistSync) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.sub_redirect_url = "customstd://test1/xhr.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
"test2", false));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a custom standard scheme can generate cross-domain XHR requests
|
2019-07-29 23:27:12 +02:00
|
|
|
// that perform redirects when using the cross-origin whitelist.
|
2013-04-18 19:58:23 +02:00
|
|
|
TEST(SchemeHandlerTest,
|
|
|
|
CustomStandardXHRDifferentOriginRedirectWithWhitelistAsync1) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.sub_redirect_url = "customstd://test1/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
"test2", false));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches any domain.
|
|
|
|
TEST(SchemeHandlerTest,
|
|
|
|
CustomStandardXHRDifferentOriginRedirectWithWhitelistAsync2) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test2");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://test2/xhr.html";
|
|
|
|
settings.sub_redirect_url = "customstd://test1/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
CefString(), true));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches sub-domains.
|
|
|
|
TEST(SchemeHandlerTest,
|
|
|
|
CustomStandardXHRDifferentOriginRedirectWithWhitelistAsync3) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstd", "a.test2.foo");
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
XHRTestSettings settings;
|
|
|
|
settings.url = "customstd://test1/run.html";
|
|
|
|
settings.sub_url = "customstd://a.test2.foo/xhr.html";
|
|
|
|
settings.sub_redirect_url = "customstd://test1/xhr.html";
|
|
|
|
settings.synchronous = false;
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpXHR(&test_results, settings);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry("customstd://test1", "customstd",
|
2017-05-17 11:29:28 +02:00
|
|
|
"test2.foo", true));
|
2013-04-18 19:58:23 +02:00
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2013-04-18 19:58:23 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2013-04-18 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:31:31 +01:00
|
|
|
// Test that a custom standard scheme can generate cross-domain Fetch requests
|
2019-07-29 23:27:12 +02:00
|
|
|
// that perform redirects when using the cross-origin whitelist.
|
2019-02-04 23:31:31 +01:00
|
|
|
TEST(SchemeHandlerTest,
|
|
|
|
CustomStandardFetchDifferentOriginRedirectWithWhitelist1) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test2/fetch.html";
|
|
|
|
settings.sub_redirect_url = "customstdfetch://test1/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry(
|
|
|
|
"customstdfetch://test1", "customstdfetch", "test2", false));
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches any domain.
|
|
|
|
TEST(SchemeHandlerTest,
|
|
|
|
CustomStandardFetchDifferentOriginRedirectWithWhitelist2) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test2");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://test2/fetch.html";
|
|
|
|
settings.sub_redirect_url = "customstdfetch://test1/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry(
|
|
|
|
"customstdfetch://test1", "customstdfetch", CefString(), true));
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but origin whitelist matches sub-domains.
|
|
|
|
TEST(SchemeHandlerTest,
|
|
|
|
CustomStandardFetchDifferentOriginRedirectWithWhitelist3) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "test1");
|
|
|
|
RegisterTestScheme(&test_results, "customstdfetch", "a.test2.foo");
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
FetchTestSettings settings;
|
|
|
|
settings.url = "customstdfetch://test1/run.html";
|
|
|
|
settings.sub_url = "customstdfetch://a.test2.foo/fetch.html";
|
|
|
|
settings.sub_redirect_url = "customstdfetch://test1/fetch.html";
|
2023-05-03 13:38:48 +02:00
|
|
|
SetUpFetch(&test_results, settings);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefAddCrossOriginWhitelistEntry(
|
|
|
|
"customstdfetch://test1", "customstdfetch", "test2.foo", true));
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_redirect);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_request);
|
|
|
|
EXPECT_TRUE(test_results.got_sub_read);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2019-02-04 23:31:31 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(CefClearCrossOriginWhitelist());
|
|
|
|
WaitForUIThread();
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2019-02-04 23:31:31 +01:00
|
|
|
}
|
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
// Test that CefRequestContextSettings.accept_language_list configures both
|
|
|
|
// the Accept-Language request header and `navigator.language` JS attribute.
|
2015-02-18 18:28:56 +01:00
|
|
|
TEST(SchemeHandlerTest, AcceptLanguage) {
|
2023-05-03 13:38:48 +02:00
|
|
|
TestResults test_results;
|
2023-10-05 22:54:42 +02:00
|
|
|
|
|
|
|
// Value that will be set via CefRequestContextSettings.accept_language_list.
|
|
|
|
test_results.accept_language = "uk";
|
|
|
|
|
|
|
|
// Create an in-memory request context with custom settings.
|
|
|
|
CefRequestContextSettings settings;
|
|
|
|
CefString(&settings.accept_language_list) = test_results.accept_language;
|
|
|
|
test_results.request_context =
|
|
|
|
CefRequestContext::CreateContext(settings, nullptr);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
RegisterTestScheme(&test_results, "customstd", "test");
|
|
|
|
test_results.url = "customstd://test/run.html";
|
|
|
|
test_results.html =
|
2023-10-05 22:54:42 +02:00
|
|
|
"<html><head></head><body>"
|
|
|
|
"<script>"
|
|
|
|
"if (navigator.language == 'uk') {"
|
|
|
|
" result = 'SUCCESS';"
|
|
|
|
"} else {"
|
|
|
|
" result = 'FAILURE';"
|
|
|
|
" console.log('navigator.language: '+navigator.language+' != uk');"
|
|
|
|
"}"
|
|
|
|
"document.location = 'https://tests/exit?result='+result;"
|
|
|
|
"</script>"
|
|
|
|
"</body></html>";
|
|
|
|
test_results.exit_url = "https://tests/exit";
|
2015-02-18 18:28:56 +01:00
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&test_results);
|
2015-02-18 18:28:56 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
|
2023-05-03 13:38:48 +02:00
|
|
|
EXPECT_TRUE(test_results.got_request);
|
|
|
|
EXPECT_TRUE(test_results.got_read);
|
|
|
|
EXPECT_TRUE(test_results.got_output);
|
2023-10-05 22:54:42 +02:00
|
|
|
EXPECT_TRUE(test_results.git_exit_success);
|
2015-02-18 18:28:56 +01:00
|
|
|
|
2023-10-05 22:54:42 +02:00
|
|
|
ClearTestSchemes(&test_results);
|
2015-02-18 18:28:56 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// Entry point for registering custom schemes.
|
|
|
|
// Called from client_app_delegates.cc.
|
2012-04-24 20:01:48 +02:00
|
|
|
void RegisterSchemeHandlerCustomSchemes(
|
2021-04-09 20:34:45 +02:00
|
|
|
CefRawPtr<CefSchemeRegistrar> registrar) {
|
2021-03-04 23:36:57 +01:00
|
|
|
// Registering the custom standard schemes as secure because requests from
|
|
|
|
// non-secure origins to the loopback address will be blocked by
|
|
|
|
// https://chromestatus.com/feature/5436853517811712.
|
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
// Add a custom standard scheme.
|
2021-03-04 23:36:57 +01:00
|
|
|
registrar->AddCustomScheme("customstd", CEF_SCHEME_OPTION_STANDARD |
|
|
|
|
CEF_SCHEME_OPTION_SECURE |
|
|
|
|
CEF_SCHEME_OPTION_CORS_ENABLED);
|
2020-08-14 21:28:23 +02:00
|
|
|
// Also used in cors_unittest.cc.
|
2021-03-04 23:36:57 +01:00
|
|
|
registrar->AddCustomScheme(
|
|
|
|
"customstdfetch", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_SECURE |
|
|
|
|
CEF_SCHEME_OPTION_CORS_ENABLED |
|
|
|
|
CEF_SCHEME_OPTION_FETCH_ENABLED);
|
2019-02-04 23:31:31 +01:00
|
|
|
// Add a custom non-standard scheme.
|
2019-02-26 17:45:12 +01:00
|
|
|
registrar->AddCustomScheme("customnonstd", CEF_SCHEME_OPTION_NONE);
|
|
|
|
registrar->AddCustomScheme("customnonstdfetch",
|
|
|
|
CEF_SCHEME_OPTION_FETCH_ENABLED);
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
2021-04-09 20:34:45 +02:00
|
|
|
|
|
|
|
// Entry point for registering cookieable schemes.
|
|
|
|
// Called from client_app_delegates.cc.
|
|
|
|
void RegisterSchemeHandlerCookieableSchemes(
|
|
|
|
std::vector<std::string>& cookieable_schemes) {
|
|
|
|
cookieable_schemes.push_back("customstd");
|
|
|
|
// Also used in cors_unittest.cc.
|
|
|
|
cookieable_schemes.push_back("customstdfetch");
|
|
|
|
}
|