Commit 8557acd3 authored by Nasko Oskov's avatar Nasko Oskov Committed by Commit Bot

Add a test for navigation away from error page.

This CL adds a test case to verify that navigating away from an error
page properly swaps SiteInstance when error page isolation is enabled.

Bug: 838161
Change-Id: Ibe16bf39b24dd1d18666c4383bfba5777f8c965e
Reviewed-on: https://chromium-review.googlesource.com/1122840Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Commit-Queue: Nasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571935}
parent 58eee872
......@@ -4388,6 +4388,76 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ErrorPageNavigationReload) {
shell()->web_contents()->GetSiteInstance()->GetProcess()->GetID()));
}
// Test to verify that navigating away from an error page results in correct
// change in SiteInstance.
IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
ErrorPageNavigationAfterError) {
// This test is only valid if error page isolation is enabled.
if (!SiteIsolationPolicy::IsErrorPageIsolationEnabled(true))
return;
StartEmbeddedServer();
GURL url(embedded_test_server()->GetURL("/title1.html"));
GURL error_url(embedded_test_server()->GetURL("/empty.html"));
std::unique_ptr<URLLoaderInterceptor> url_interceptor =
SetupRequestFailForURL(error_url);
NavigationControllerImpl& nav_controller =
static_cast<NavigationControllerImpl&>(
shell()->web_contents()->GetController());
// Start with a successful navigation to a document.
EXPECT_TRUE(NavigateToURL(shell(), url));
scoped_refptr<SiteInstance> success_site_instance =
shell()->web_contents()->GetMainFrame()->GetSiteInstance();
EXPECT_EQ(1, nav_controller.GetEntryCount());
// Navigate to an url resulting in an error page.
EXPECT_FALSE(NavigateToURL(shell(), error_url));
EXPECT_EQ(
GURL(kUnreachableWebDataURL),
shell()->web_contents()->GetMainFrame()->GetSiteInstance()->GetSiteURL());
EXPECT_EQ(
GURL(kUnreachableWebDataURL),
ChildProcessSecurityPolicyImpl::GetInstance()->GetOriginLock(
shell()->web_contents()->GetSiteInstance()->GetProcess()->GetID()));
EXPECT_EQ(2, nav_controller.GetEntryCount());
// Navigate again to the initial successful document, expecting a new
// navigation and new SiteInstance.
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_NE(
GURL(kUnreachableWebDataURL),
shell()->web_contents()->GetMainFrame()->GetSiteInstance()->GetSiteURL());
EXPECT_EQ(
success_site_instance->GetSiteURL(),
shell()->web_contents()->GetMainFrame()->GetSiteInstance()->GetSiteURL());
EXPECT_NE(success_site_instance,
shell()->web_contents()->GetMainFrame()->GetSiteInstance());
EXPECT_EQ(3, nav_controller.GetEntryCount());
// Repeat again using a renderer-initiated navigation for the successful one.
EXPECT_FALSE(NavigateToURL(shell(), error_url));
EXPECT_EQ(
GURL(kUnreachableWebDataURL),
shell()->web_contents()->GetMainFrame()->GetSiteInstance()->GetSiteURL());
EXPECT_EQ(
GURL(kUnreachableWebDataURL),
ChildProcessSecurityPolicyImpl::GetInstance()->GetOriginLock(
shell()->web_contents()->GetSiteInstance()->GetProcess()->GetID()));
EXPECT_EQ(4, nav_controller.GetEntryCount());
{
TestNavigationObserver observer(shell()->web_contents());
EXPECT_TRUE(
ExecuteScript(shell(), "location.href = '" + url.spec() + "';"));
observer.Wait();
EXPECT_TRUE(observer.last_navigation_succeeded());
}
EXPECT_EQ(5, nav_controller.GetEntryCount());
EXPECT_NE(
GURL(kUnreachableWebDataURL),
shell()->web_contents()->GetMainFrame()->GetSiteInstance()->GetSiteURL());
}
// A NavigationThrottle implementation that blocks all outgoing navigation
// requests for a specific WebContents. It is used to block navigations to
// WebUI URLs in the following test.
......
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