Commit bcc444a7 authored by Arthur Hemery's avatar Arthur Hemery Committed by Commit Bot

Add tests for process reuse and COOP+COEP

This CL adds two tests that exercise the interaction between COOP+COEP
and the process reuse mechanism. Currently, the process used to commit a
COOP+COEP page is included in the process reuse mechanism. We'd like to
take it out of the mechanism, to ensure that no document are ever placed
in a COOP+COEP process.

Bug: 922191
Change-Id: I2055b20676350cf13c24328ac2bc019a6adcdcbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063005
Commit-Queue: Camille Lamy <clamy@chromium.org>
Reviewed-by: default avatarPâris Meuleman <pmeuleman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753171}
parent 6e2e16d4
......@@ -6,6 +6,7 @@
#include "components/network_session_configurator/common/network_switches.h"
#include "content/browser/frame_host/navigation_request.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
......@@ -17,6 +18,8 @@
namespace content {
namespace {
class CrossOriginOpenerPolicyBrowserTest : public ContentBrowserTest {
public:
CrossOriginOpenerPolicyBrowserTest()
......@@ -39,10 +42,14 @@ class CrossOriginOpenerPolicyBrowserTest : public ContentBrowserTest {
https_server()->ServeFilesFromSourceDirectory(GetTestDataFilePath());
SetupCrossSiteRedirector(https_server());
https_server()->SetSSLConfig(net::EmbeddedTestServer::CERT_OK);
ASSERT_TRUE(https_server()->Start());
}
void SetUpCommandLine(base::CommandLine* command_line) override {
ContentBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
}
WebContentsImpl* web_contents() const {
return static_cast<WebContentsImpl*>(shell()->web_contents());
}
......@@ -723,4 +730,68 @@ IN_PROC_BROWSER_TEST_F(CrossOriginOpenerPolicyBrowserTest,
1u);
}
IN_PROC_BROWSER_TEST_F(CrossOriginOpenerPolicyBrowserTest,
IsolateInNewProcessDespiteLimitReached) {
// Set a process limit of 1 for testing.
RenderProcessHostImpl::SetMaxRendererProcessCount(1);
// Navigate to a starting page.
GURL starting_page(https_server()->GetURL("a.com", "/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), starting_page));
// Open a popup with CrossOriginOpenerPolicy and CrossOriginEmbedderPolicy
// set.
ShellAddedObserver shell_observer;
EXPECT_TRUE(ExecJs(current_frame_host(),
"window.open('/page_with_coop_and_coep.html')"));
auto* popup_webcontents =
static_cast<WebContentsImpl*>(shell_observer.GetShell()->web_contents());
WaitForLoadStop(popup_webcontents);
// The page and its popup should be in different processes even though the
// process limit was reached.
// TODO(clamy, pmeuleman, ahemery): The assert below should be false once we
// fix the process reuse for COOP.
EXPECT_EQ(current_frame_host()->GetProcess(),
popup_webcontents->GetMainFrame()->GetProcess());
}
IN_PROC_BROWSER_TEST_F(CrossOriginOpenerPolicyBrowserTest,
NoProcessReuseForCOOPProcesses) {
// Set a process limit of 1 for testing.
RenderProcessHostImpl::SetMaxRendererProcessCount(1);
// Navigate to a starting page with CrossOriginOpenerPolicy and
// CrossOriginEmbedderPolicy set.
GURL starting_page(
https_server()->GetURL("a.com", "/page_with_coop_and_coep.html"));
EXPECT_TRUE(NavigateToURL(shell(), starting_page));
// Open a popup without CrossOriginOpenerPolicy and CrossOriginEmbedderPolicy
// set.
ShellAddedObserver shell_observer;
EXPECT_TRUE(ExecJs(current_frame_host(), "window.open('/title1.html')"));
auto* popup_webcontents =
static_cast<WebContentsImpl*>(shell_observer.GetShell()->web_contents());
WaitForLoadStop(popup_webcontents);
// The page and its popup should be in different processes even though the
// process limit was reached.
// TODO(clamy, pmeuleman, ahemery): The assert below should be false once we
// fix the process reuse for COOP.
EXPECT_EQ(current_frame_host()->GetProcess(),
popup_webcontents->GetMainFrame()->GetProcess());
// Navigate to a new page without COOP and COEP. Because of process reuse, it
// is placed in the popup process.
GURL final_page(https_server()->GetURL("a.com", "/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), final_page));
EXPECT_EQ(current_frame_host()->GetProcess(),
popup_webcontents->GetMainFrame()->GetProcess());
}
} // namespace
} // namespace content
<html>
<head></head>
<body>This is a basic page returned with the COOP and COEP headers.</body>
</html>
HTTP/1.1 200 OK
Content-Type: text/html
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment