cefclient: Use HTTPS for test URLs

Some features that we wish to test require HTTPS. Also, Chrome runtime is
redirecting HTTP URLs to HTTPS due to HSTS.
This commit is contained in:
Marshall Greenblatt 2023-09-26 16:12:32 -04:00
parent 27c6a4eabc
commit 262ed72348
7 changed files with 23 additions and 18 deletions

View File

@ -7,6 +7,7 @@
#include <algorithm>
#include "include/cef_parser.h"
#include "tests/cefclient/browser/test_runner.h"
#include "tests/shared/browser/client_app_browser.h"
#include "tests/shared/common/client_switches.h"
#include "tests/shared/common/string_util.h"
@ -128,7 +129,7 @@ MainContextImpl::MainContextImpl(CefRefPtr<CefCommandLine> command_line,
if (use_views_ && command_line->HasSwitch(switches::kHideFrame) &&
!command_line_->HasSwitch(switches::kUrl)) {
// Use the draggable regions test as the default URL for frameless windows.
main_url_ = "http://tests/draggable";
main_url_ = test_runner::GetTestURL("draggable");
}
if (command_line_->HasSwitch(switches::kBackgroundColor)) {

View File

@ -31,9 +31,6 @@ const char kPortKey[] = "port";
const char kStatusKey[] = "status";
const char kMessageKey[] = "message";
// Required URL for cefQuery execution.
const char kTestUrl[] = "http://tests/server";
// Server default values.
const char kServerAddress[] = "127.0.0.1";
const int kServerPortDefault = 8099;
@ -234,7 +231,7 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (url.find(kTestUrl) != 0) {
if (url.find(test_runner::GetTestURL("server")) != 0) {
return false;
}

View File

@ -39,7 +39,7 @@ namespace {
const char kTestHost[] = "tests";
const char kLocalHost[] = "localhost";
const char kTestOrigin[] = "http://tests/";
const char kTestOrigin[] = "https://tests/";
// Pages handled via StringResourceProvider.
const char kTestGetSourcePage[] = "get_source.html";
@ -102,18 +102,18 @@ void RunRequestTest(CefRefPtr<CefBrowser> browser) {
// Create a new request
CefRefPtr<CefRequest> request(CefRequest::Create());
if (browser->GetMainFrame()->GetURL().ToString().find("http://tests/") != 0) {
if (browser->GetMainFrame()->GetURL().ToString().find(kTestOrigin) != 0) {
// The LoadRequest method will fail with "bad IPC message" reason
// INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the
// request origin using some other mechanism (LoadURL, link click, etc).
Alert(browser,
"Please first navigate to a http://tests/ URL. "
"For example, first load Tests > Other Tests.");
Alert(browser, "Please first navigate to a " + std::string(kTestOrigin) +
" URL. "
"For example, first load Tests > Other Tests.");
return;
}
// Set the request URL
request->SetURL("http://tests/request");
request->SetURL(GetTestURL("request"));
// Add post data to the request. The correct method and content-
// type headers will be set by CEF.
@ -419,7 +419,7 @@ void MuteAudio(CefRefPtr<CefBrowser> browser, bool mute) {
}
void RunOtherTests(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://tests/other_tests");
browser->GetMainFrame()->LoadURL(GetTestURL("other_tests"));
}
// Provider that dumps the request contents.
@ -679,7 +679,7 @@ CefRefPtr<CefStreamReader> GetDumpResponse(
}
if (!origin.empty() &&
(origin.find("http://" + std::string(kTestHost)) == 0 ||
(origin.find("https://" + std::string(kTestHost)) == 0 ||
origin.find("http://" + std::string(kLocalHost)) == 0)) {
// Allow cross-origin XMLHttpRequests from test origins.
response_headers.insert(
@ -832,6 +832,10 @@ void Alert(CefRefPtr<CefBrowser> browser, const std::string& message) {
frame->ExecuteJavaScript("alert('" + msg + "');", frame->GetURL(), 0);
}
std::string GetTestURL(const std::string& path) {
return kTestOrigin + path;
}
bool IsTestURL(const std::string& url, const std::string& path) {
CefURLParts parts;
CefParseURL(url, parts);

View File

@ -44,8 +44,11 @@ void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager,
// Show a JS alert message.
void Alert(CefRefPtr<CefBrowser> browser, const std::string& message);
// Returns "https://tests/<path>".
std::string GetTestURL(const std::string& path);
// Returns true if |url| is a test URL with the specified |path|. This matches
// both http://tests/<path> and http://localhost:xxxx/<path>.
// both "https://tests/<path>" and "http://localhost:xxxx/<path>".
bool IsTestURL(const std::string& url, const std::string& path);
// Create all CefMessageRouterBrowserSide::Handler objects. They will be

View File

@ -24,7 +24,7 @@ function setButtonState(start_enabled, stop_enabled) {
}
function setup() {
if (location.origin != 'http://tests') {
if (location.origin != 'https://tests') {
document.getElementById('warning').style.display = 'block';
return;
}
@ -84,7 +84,7 @@ function openServer() {
</head>
<body bgcolor="white" onload="setup()">
<div id="warning" style="display:none;color:red;font-weight:bold;">
This page can only be run from the http://tests origin.
This page can only be run from the https://tests origin.
</div>
<p>
This page starts an HTTP/WebSocket server on localhost with the specified port number.

View File

@ -87,7 +87,7 @@ function doSend() {
<body bgcolor="white" onload="setup()">
<div id="warning" style="display:none;color:red;font-weight:bold;">
This page is most useful when loaded from localhost.
You should first create a server using the <a href="http://tests/server">HTTP/WebSocket Server test</a>.
You should first create a server using the <a href="https://tests/server">HTTP/WebSocket Server test</a>.
</div>
<p>
This page tests a WebSocket connection.

View File

@ -30,7 +30,7 @@ function execXMLHttpRequest()
}
</script>
<form>
URL: <input type="text" id="url" value="http://tests/request">
URL: <input type="text" id="url" value="https://tests/request">
<br/><input type="button" onclick="execXMLHttpRequest();" value="Execute XMLHttpRequest">
<br/><textarea rows="10" cols="40" id="ta"></textarea>
</form>