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

Unified Diff: content/browser/site_per_process_browsertest.cc

Issue 1224363002: OOPIF: Fix window.open to work from frames with remote parent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Charlie's comments Created 5 years, 5 months 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/site_per_process_browsertest.cc
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc
index c5514f65877f626e21c0a2542325bd26ee9a9310..373b9392def20b1feb24ea13f8752cbaee6ea11f 100644
--- a/content/browser/site_per_process_browsertest.cc
+++ b/content/browser/site_per_process_browsertest.cc
@@ -76,6 +76,21 @@ int GetReceivedMessages(FrameTreeNode* ftn) {
return received_messages;
}
+Shell* OpenPopup(const internal::ToRenderFrameHost& opener,
Charlie Reis 2015/07/10 21:44:49 Move to content_browser_test_utils_internal (and s
alexmos 2015/07/10 23:03:02 Done. Also refactored slightly to remove the EXPE
+ const GURL& url,
+ const std::string& name) {
+ ShellAddedObserver new_shell_observer;
+ bool success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ opener,
+ "window.domAutomationController.send("
+ " !!window.open('" + url.spec() + "', '" + name + "'));",
+ &success));
+ EXPECT_TRUE(success);
+ Shell* new_shell = new_shell_observer.GetShell();
+ return new_shell;
+}
+
class RedirectNotificationObserver : public NotificationObserver {
public:
// Register to listen for notifications of the given type from either a
@@ -2715,4 +2730,68 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, RFPHDestruction) {
DepictFrameTree(root));
}
+IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OpenPopupWithRemoteParent) {
+ GURL main_url(
+ embedded_test_server()->GetURL("a.com", "/site_per_process_main.html"));
+ NavigateToURL(shell(), main_url);
+
+ // It is safe to obtain the root frame tree node here, as it doesn't change.
+ FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
+ ->GetFrameTree()
+ ->root();
+
+ // Navigate first child cross-site.
+ GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html"));
+ NavigateFrameToURL(root->child_at(0), frame_url);
+
+ // Open a popup from the first child.
+ Shell* new_shell = OpenPopup(root->child_at(0)->current_frame_host(),
+ GURL("about:blank"), "");
+
+ // Check that the popup's opener is correct on both the browser and renderer
+ // sides.
+ FrameTreeNode* popup_root =
+ static_cast<WebContentsImpl*>(new_shell->web_contents())
+ ->GetFrameTree()
+ ->root();
+ EXPECT_EQ(root->child_at(0), popup_root->opener());
+
+ std::string opener_url;
+ EXPECT_TRUE(ExecuteScriptAndExtractString(
+ popup_root->current_frame_host(),
+ "window.domAutomationController.send(window.opener.location.href);",
+ &opener_url));
+ EXPECT_EQ(frame_url.spec(), opener_url);
+
+ // Now try the same with a cross-site popup and make sure it ends up in a new
+ // process and with a correct opener.
+ GURL popup_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
+ Shell* cross_site_popup =
+ OpenPopup(root->child_at(0)->current_frame_host(), popup_url, "");
+ WaitForLoadStop(cross_site_popup->web_contents());
+
+ FrameTreeNode* cross_site_popup_root =
+ static_cast<WebContentsImpl*>(cross_site_popup->web_contents())
+ ->GetFrameTree()
+ ->root();
+ EXPECT_EQ(cross_site_popup_root->current_url(), popup_url);
+
+ EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
+ cross_site_popup->web_contents()->GetSiteInstance());
+ EXPECT_NE(root->child_at(0)->current_frame_host()->GetSiteInstance(),
+ cross_site_popup->web_contents()->GetSiteInstance());
+
+ EXPECT_EQ(root->child_at(0), cross_site_popup_root->opener());
+
+ // Ensure the popup's window.opener points to the right subframe. Note that
+ // we can't check the opener's location as above since it's cross-origin.
+ bool success = false;
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(
+ cross_site_popup_root->current_frame_host(),
+ "window.domAutomationController.send("
+ " window.opener === window.opener.top.frames[0]);",
+ &success));
+ EXPECT_TRUE(success);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698