Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Unified Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 1443663003: Implement the 'noopener' link relation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: browsertest Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/render_frame_host_manager_browsertest.cc
diff --git a/content/browser/frame_host/render_frame_host_manager_browsertest.cc b/content/browser/frame_host/render_frame_host_manager_browsertest.cc
index d06b2ff90bf93016c2dc38e9987dd57835be31d1..e558f3898d973d35ed24de6a098316eedfe945ed 100644
--- a/content/browser/frame_host/render_frame_host_manager_browsertest.cc
+++ b/content/browser/frame_host/render_frame_host_manager_browsertest.cc
@@ -232,6 +232,13 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
+ // Check that `window.opener` is not set.
+ success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ new_shell->web_contents(),
+ "window.domAutomationController.send(window.opener == null);", &success));
+ EXPECT_TRUE(success);
+
// Wait for the cross-site transition in the new tab to finish.
WaitForLoadStop(new_shell->web_contents());
WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
@@ -245,6 +252,52 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
EXPECT_NE(orig_site_instance, noref_blank_site_instance);
}
+// Same as above, but for 'noopener'
+IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
+ SwapProcessWithRelNopenerAndTargetBlank) {
+ StartEmbeddedServer();
+
+ NavigateToPageWithLinks(shell());
+
+ // Get the original SiteInstance for later comparison.
+ scoped_refptr<SiteInstance> orig_site_instance(
+ shell()->web_contents()->GetSiteInstance());
+ EXPECT_TRUE(orig_site_instance.get() != NULL);
+
+ // Test clicking a rel=noreferrer + target=blank link.
+ ShellAddedObserver new_shell_observer;
+ bool success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ shell()->web_contents(),
+ "window.domAutomationController.send(clickNoOpenerTargetBlankLink());",
+ &success));
+ EXPECT_TRUE(success);
+
+ // Wait for the window to open.
+ Shell* new_shell = new_shell_observer.GetShell();
+
+ EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
+
+ // Check that `window.opener` is not set.
+ success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ new_shell->web_contents(),
+ "window.domAutomationController.send(window.opener == null);", &success));
+ EXPECT_TRUE(success);
+
+ // Wait for the cross-site transition in the new tab to finish.
+ WaitForLoadStop(new_shell->web_contents());
+ WebContentsImpl* web_contents =
+ static_cast<WebContentsImpl*>(new_shell->web_contents());
+ EXPECT_FALSE(
+ web_contents->GetRenderManagerForTesting()->pending_render_view_host());
+
+ // Should have a new SiteInstance.
+ scoped_refptr<SiteInstance> noopener_blank_site_instance(
+ new_shell->web_contents()->GetSiteInstance());
+ EXPECT_NE(orig_site_instance, noopener_blank_site_instance);
+}
+
// As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance)
// for rel=noreferrer links in new windows, even to same site pages and named
// targets.
@@ -275,6 +328,62 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
// Opens in new window.
EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
+ // Check that `window.opener` is not set.
+ success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ new_shell->web_contents(),
+ "window.domAutomationController.send(window.opener == null);", &success));
+ EXPECT_TRUE(success);
+
+ // Wait for the cross-site transition in the new tab to finish.
+ WaitForLoadStop(new_shell->web_contents());
+ WebContentsImpl* web_contents =
+ static_cast<WebContentsImpl*>(new_shell->web_contents());
+ EXPECT_FALSE(
+ web_contents->GetRenderManagerForTesting()->pending_render_view_host());
+
+ // Should have a new SiteInstance (in a new BrowsingInstance).
+ scoped_refptr<SiteInstance> noref_blank_site_instance(
+ new_shell->web_contents()->GetSiteInstance());
+ EXPECT_NE(orig_site_instance, noref_blank_site_instance);
+}
+
+// Same as above, but for 'noopener'
+IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
+ SwapProcessWithSameSiteRelNoopener) {
+ StartEmbeddedServer();
+
+ // Load a page with links that open in a new window.
+ NavigateToPageWithLinks(shell());
+
+ // Get the original SiteInstance for later comparison.
+ scoped_refptr<SiteInstance> orig_site_instance(
+ shell()->web_contents()->GetSiteInstance());
+ EXPECT_TRUE(orig_site_instance.get() != NULL);
+
+ // Test clicking a same-site rel=noopener + target=foo link.
+ ShellAddedObserver new_shell_observer;
+ bool success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(),
+ "window.domAutomationController.send("
+ "clickSameSiteNoOpenerTargetedLink())"
+ ";",
+ &success));
+ EXPECT_TRUE(success);
+
+ // Wait for the window to open.
+ Shell* new_shell = new_shell_observer.GetShell();
+
+ // Opens in new window.
+ EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
+
+ // Check that `window.opener` is not set.
+ success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ new_shell->web_contents(),
+ "window.domAutomationController.send(window.opener == null);", &success));
+ EXPECT_TRUE(success);
+
// Wait for the cross-site transition in the new tab to finish.
WaitForLoadStop(new_shell->web_contents());
WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
@@ -347,6 +456,43 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell()->web_contents(),
+ "window.domAutomationController.send(clickNoRefLink());", &success));
+ EXPECT_TRUE(success);
+
+ // Wait for the cross-site transition in the current tab to finish.
+ WaitForLoadStop(shell()->web_contents());
+
+ // Opens in same window.
+ EXPECT_EQ(1u, Shell::windows().size());
+ EXPECT_EQ("/title2.html",
+ shell()->web_contents()->GetLastCommittedURL().path());
+
+ // Should have the same SiteInstance unless we're in site-per-process mode.
+ scoped_refptr<SiteInstance> noref_site_instance(
+ shell()->web_contents()->GetSiteInstance());
+ if (AreAllSitesIsolatedForTesting())
+ EXPECT_NE(orig_site_instance, noref_site_instance);
+ else
+ EXPECT_EQ(orig_site_instance, noref_site_instance);
+}
+
+// Same as above, but for 'noopener'
+IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
+ DontSwapProcessWithOnlyRelNoOpener) {
+ StartEmbeddedServer();
+
+ // Load a page with links that open in a new window.
+ NavigateToPageWithLinks(shell());
+
+ // Get the original SiteInstance for later comparison.
+ scoped_refptr<SiteInstance> orig_site_instance(
+ shell()->web_contents()->GetSiteInstance());
+ EXPECT_TRUE(orig_site_instance.get() != NULL);
+
+ // Test clicking a rel=noreferrer link.
+ bool success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ shell()->web_contents(),
"window.domAutomationController.send(clickNoRefLink());",
&success));
EXPECT_TRUE(success);
« no previous file with comments | « no previous file | content/test/data/click-noreferrer-links.html » ('j') | third_party/WebKit/Source/core/html/HTMLAnchorElement.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698