Hi, I tried to use net::EmbeddedTestServer in https, and have the following content browser test code:
net::EmbeddedTestServer https_embedded_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
https_embedded_test_server.ServeFilesFromSourceDirectory("content/test/data");
ASSERT_TRUE(https_embedded_test_server.Start());
GURL main_frame_url = https_embedded_test_server.GetURL("/device_sensors/cross_origin_iframe.html");
LOG(INFO) << "|main_frame_url| is: " << main_frame_url;
NavigateToURL(shell(), main_frame_url);
The cross_origin_iframe.html file looks like:
<html>
<head>
<title>cross-origin iframe</title>
<script>
function output() {
console.log("output() called.");
}
</script>
</head>
<body onload="output()">
<iframe id="cross_origin_iframe"></iframe>
</body>
</html>
This one works fine and the js code prints the "output() called". And the |main_frame_url| is:
Now I changed the code a bit by adding "
a.com" in the url:
net::EmbeddedTestServer https_embedded_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
https_embedded_test_server.ServeFilesFromSourceDirectory("content/test/data");
ASSERT_TRUE(https_embedded_test_server.Start());
GURL main_frame_url = https_embedded_test_server.GetURL("
a.com", "/device_sensors/cross_origin_iframe.html");
LOG(INFO) << "|main_frame_url| is: " << main_frame_url;
NavigateToURL(shell(), main_frame_url);
And call:
host_resolver()->AddRule("*", "127.0.0.1");
in:
void SetUpOnMainThread() override
The js code seems not be called since the "output() called" is not printed, the |main_frame_url| is:
However, using the default embedded_test_server() works:
ASSERT_TRUE(embedded_test_server()->Start());
GURL main_frame_url = embedded_test_server()->GetURL("
a.com", "/device_sensors/cross_origin_iframe.html");
LOG(INFO) << "|main_frame_url| is: " << main_frame_url;
NavigateToURL(shell(), main_frame_url);
I also need to add call:
host_resolver()->AddRule("*", "127.0.0.1");
in:
void SetUpOnMainThread() override;
The |main_frame_url| is:
Any suggestion how to make the second case work? Thanks!