| Index: content/browser/renderer_host/render_view_host_manager_browsertest.cc
|
| diff --git a/content/browser/renderer_host/render_view_host_manager_browsertest.cc b/content/browser/renderer_host/render_view_host_manager_browsertest.cc
|
| index fe220b28b85596003c3a99442f66b1f2610e6160..062a6e9527623cdf518ba825c1bcfa6310787fa2 100644
|
| --- a/content/browser/renderer_host/render_view_host_manager_browsertest.cc
|
| +++ b/content/browser/renderer_host/render_view_host_manager_browsertest.cc
|
| @@ -84,7 +84,7 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, NoScriptAccessAfterSwapOut) {
|
|
|
| // Wait for the navigation in the new tab to finish, if it hasn't.
|
| ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents());
|
| - EXPECT_EQ("/files/title2.html",
|
| + EXPECT_EQ("/files/navigate_opener.html",
|
| browser()->GetSelectedWebContents()->GetURL().path());
|
| EXPECT_EQ(1, browser()->active_index());
|
|
|
| @@ -337,6 +337,173 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest,
|
| EXPECT_EQ(orig_site_instance, noref_site_instance);
|
| }
|
|
|
| +// Test for crbug.com/116192. Targeted links should still work after the
|
| +// named target window has swapped processes.
|
| +IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest,
|
| + AllowTargetedNavigationsAfterSwap) {
|
| + // Start two servers with different sites.
|
| + ASSERT_TRUE(test_server()->Start());
|
| + net::TestServer https_server(
|
| + net::TestServer::TYPE_HTTPS,
|
| + net::TestServer::kLocalhost,
|
| + FilePath(FILE_PATH_LITERAL("chrome/test/data")));
|
| + ASSERT_TRUE(https_server.Start());
|
| +
|
| + // Load a page with links that open in a new window.
|
| + std::string replacement_path;
|
| + ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
|
| + "files/click-noreferrer-links.html",
|
| + https_server.host_port_pair(),
|
| + &replacement_path));
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + test_server()->GetURL(replacement_path));
|
| +
|
| + // Get the original SiteInstance for later comparison.
|
| + scoped_refptr<SiteInstance> orig_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_TRUE(orig_site_instance != NULL);
|
| +
|
| + // Test clicking a target=foo link.
|
| + ui_test_utils::WindowedNotificationObserver new_tab_observer(
|
| + content::NOTIFICATION_TAB_ADDED,
|
| + content::Source<content::WebContentsDelegate>(browser()));
|
| + bool success = false;
|
| + EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
|
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
|
| + L"window.domAutomationController.send(clickSameSiteTargetedLink());",
|
| + &success));
|
| + EXPECT_TRUE(success);
|
| + new_tab_observer.Wait();
|
| +
|
| + // Opens in new tab.
|
| + EXPECT_EQ(2, browser()->tab_count());
|
| + EXPECT_EQ(1, browser()->active_index());
|
| +
|
| + // Wait for the navigation in the new tab to finish, if it hasn't.
|
| + ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents());
|
| + EXPECT_EQ("/files/navigate_opener.html",
|
| + browser()->GetSelectedWebContents()->GetURL().path());
|
| + EXPECT_EQ(1, browser()->active_index());
|
| +
|
| + // Should have the same SiteInstance.
|
| + scoped_refptr<SiteInstance> blank_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_EQ(orig_site_instance, blank_site_instance);
|
| +
|
| + // Now navigate the new tab to a different site.
|
| + //browser()->ActivateTabAt(1, true);
|
| + content::WebContents* new_contents = browser()->GetSelectedWebContents();
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + https_server.GetURL("files/title1.html"));
|
| + scoped_refptr<SiteInstance> new_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_NE(orig_site_instance, new_site_instance);
|
| +
|
| + // Clicking the original link in the first tab should cause us to swap back.
|
| + browser()->ActivateTabAt(0, true);
|
| + ui_test_utils::WindowedNotificationObserver navigation_observer(
|
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED,
|
| + content::Source<content::NavigationController>(
|
| + &new_contents->GetController()));
|
| + EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
|
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
|
| + L"window.domAutomationController.send(clickSameSiteTargetedLink());",
|
| + &success));
|
| + EXPECT_TRUE(success);
|
| + navigation_observer.Wait();
|
| +
|
| + // Should have swapped back and shown the new tab again.
|
| + EXPECT_EQ(1, browser()->active_index());
|
| + scoped_refptr<SiteInstance> revisit_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_EQ(orig_site_instance, revisit_site_instance);
|
| +}
|
| +
|
| +// Test for crbug.com/116192. Navigations to a window's opener should
|
| +// still work after a process swap.
|
| +IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest,
|
| + AllowTargetedNavigationsInOpenerAfterSwap) {
|
| + // Start two servers with different sites.
|
| + ASSERT_TRUE(test_server()->Start());
|
| + net::TestServer https_server(
|
| + net::TestServer::TYPE_HTTPS,
|
| + net::TestServer::kLocalhost,
|
| + FilePath(FILE_PATH_LITERAL("chrome/test/data")));
|
| + ASSERT_TRUE(https_server.Start());
|
| +
|
| + // Load a page with links that open in a new window.
|
| + std::string replacement_path;
|
| + ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
|
| + "files/click-noreferrer-links.html",
|
| + https_server.host_port_pair(),
|
| + &replacement_path));
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + test_server()->GetURL(replacement_path));
|
| +
|
| + // Get the original tab and SiteInstance for later comparison.
|
| + content::WebContents* orig_contents = browser()->GetSelectedWebContents();
|
| + scoped_refptr<SiteInstance> orig_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_TRUE(orig_site_instance != NULL);
|
| +
|
| + // Test clicking a target=foo link.
|
| + ui_test_utils::WindowedNotificationObserver new_tab_observer(
|
| + content::NOTIFICATION_TAB_ADDED,
|
| + content::Source<content::WebContentsDelegate>(browser()));
|
| + bool success = false;
|
| + EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
|
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
|
| + L"window.domAutomationController.send(clickSameSiteTargetedLink());",
|
| + &success));
|
| + EXPECT_TRUE(success);
|
| + new_tab_observer.Wait();
|
| +
|
| + // Opens in new tab.
|
| + EXPECT_EQ(2, browser()->tab_count());
|
| + EXPECT_EQ(1, browser()->active_index());
|
| +
|
| + // Wait for the navigation in the new tab to finish, if it hasn't.
|
| + ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents());
|
| + EXPECT_EQ("/files/navigate_opener.html",
|
| + browser()->GetSelectedWebContents()->GetURL().path());
|
| + EXPECT_EQ(1, browser()->active_index());
|
| +
|
| + // Should have the same SiteInstance.
|
| + scoped_refptr<SiteInstance> blank_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_EQ(orig_site_instance, blank_site_instance);
|
| +
|
| + // Now navigate the original (opener) tab to a different site.
|
| + browser()->ActivateTabAt(0, true);
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + https_server.GetURL("files/title1.html"));
|
| + scoped_refptr<SiteInstance> new_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_NE(orig_site_instance, new_site_instance);
|
| +
|
| + // The opened tab should be able to navigate the opener back to its process.
|
| + browser()->ActivateTabAt(1, true);
|
| + ui_test_utils::WindowedNotificationObserver navigation_observer(
|
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED,
|
| + content::Source<content::NavigationController>(
|
| + &orig_contents->GetController()));
|
| + EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
|
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
|
| + L"window.domAutomationController.send(navigateOpener());",
|
| + &success));
|
| + EXPECT_TRUE(success);
|
| + navigation_observer.Wait();
|
| +
|
| + // Active tab should not have changed.
|
| + EXPECT_EQ(1, browser()->active_index());
|
| +
|
| + // Should have swapped back into this process.
|
| + browser()->ActivateTabAt(0, true);
|
| + scoped_refptr<SiteInstance> revisit_site_instance(
|
| + browser()->GetSelectedWebContents()->GetSiteInstance());
|
| + EXPECT_EQ(orig_site_instance, revisit_site_instance);
|
| +}
|
| +
|
| // Test for crbug.com/76666. A cross-site navigation that fails with a 204
|
| // error should not make us ignore future renderer-initiated navigations.
|
| IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) {
|
|
|