Commit a26fa9a7 authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Cleanup NavigationBrowserTest, use shorthand instead of static_cast.

Most tests about navigation defines web_contents() to avoid doing some
static_cast<WebContentsImpl>(shell->web_contents()) every times the
tests want to access anything. Similarly, they also define
current_frame_host() for getting the current main document.

For instance, see RenderFrameHostImplBrowserTest.

This patch introduce the same shorthand. It makes every tests to use them.
(File size reduced by ~3.5% overall).


Bug: None
Change-Id: I76b196ad4da8d3ce12a4fe82c076fd59f31016ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2506048
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823490}
parent 7b3f48dd
...@@ -245,6 +245,16 @@ class NavigationBaseBrowserTest : public ContentBrowserTest { ...@@ -245,6 +245,16 @@ class NavigationBaseBrowserTest : public ContentBrowserTest {
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1"); host_resolver()->AddRule("*", "127.0.0.1");
} }
WebContentsImpl* web_contents() const {
return static_cast<WebContentsImpl*>(shell()->web_contents());
}
FrameTreeNode* main_frame() { return web_contents()->GetFrameTree()->root(); }
RenderFrameHostImpl* current_frame_host() {
return main_frame()->current_frame_host();
}
}; };
class NavigationBrowserTest : public NavigationBaseBrowserTest { class NavigationBrowserTest : public NavigationBaseBrowserTest {
...@@ -260,7 +270,7 @@ class NavigationGoToEntryAtOffsetBrowserTest : public NavigationBrowserTest { ...@@ -260,7 +270,7 @@ class NavigationGoToEntryAtOffsetBrowserTest : public NavigationBrowserTest {
void SetQuitHandlerForGoToEntryAtOffset(base::OnceClosure handler) { void SetQuitHandlerForGoToEntryAtOffset(base::OnceClosure handler) {
RenderFrameHostImplForHistoryBackInterceptor* render_frame_host = RenderFrameHostImplForHistoryBackInterceptor* render_frame_host =
static_cast<RenderFrameHostImplForHistoryBackInterceptor*>( static_cast<RenderFrameHostImplForHistoryBackInterceptor*>(
shell()->web_contents()->GetMainFrame()); current_frame_host());
render_frame_host->set_quit_handler(std::move(handler)); render_frame_host->set_quit_handler(std::move(handler));
} }
...@@ -296,14 +306,9 @@ INSTANTIATE_TEST_SUITE_P(All, ...@@ -296,14 +306,9 @@ INSTANTIATE_TEST_SUITE_P(All,
::testing::Bool()); ::testing::Bool());
class NavigationBrowserTestReferrerPolicy class NavigationBrowserTestReferrerPolicy
: public ContentBrowserTest, : public NavigationBrowserTest,
public ::testing::WithParamInterface<network::mojom::ReferrerPolicy> { public ::testing::WithParamInterface<network::mojom::ReferrerPolicy> {
protected: protected:
void SetUpOnMainThread() override {
ASSERT_TRUE(embedded_test_server()->Start());
ContentBrowserTest::SetUpOnMainThread();
}
network::mojom::ReferrerPolicy GetReferrerPolicy() const { network::mojom::ReferrerPolicy GetReferrerPolicy() const {
return GetParam(); return GetParam();
} }
...@@ -327,7 +332,7 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -327,7 +332,7 @@ INSTANTIATE_TEST_SUITE_P(
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) { IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) {
// Perform a navigation with no live renderer. // Perform a navigation with no live renderer.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url(embedded_test_server()->GetURL("/title1.html")); GURL url(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
...@@ -336,15 +341,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) { ...@@ -336,15 +341,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) {
EXPECT_FALSE(observer.last_initiator_routing_id()); EXPECT_FALSE(observer.last_initiator_routing_id());
} }
RenderFrameHost* initial_rfh = RenderFrameHost* initial_rfh = current_frame_host();
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root()
->current_frame_host();
// Perform a same site navigation. // Perform a same site navigation.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url(embedded_test_server()->GetURL("/title2.html")); GURL url(embedded_test_server()->GetURL("/title2.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
...@@ -353,11 +354,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) { ...@@ -353,11 +354,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) {
EXPECT_FALSE(observer.last_initiator_routing_id()); EXPECT_FALSE(observer.last_initiator_routing_id());
} }
RenderFrameHost* second_rfh = RenderFrameHost* second_rfh = current_frame_host();
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root()
->current_frame_host();
if (CanSameSiteMainFrameNavigationsChangeRenderFrameHosts()) { if (CanSameSiteMainFrameNavigationsChangeRenderFrameHosts()) {
// If same-site ProactivelySwapBrowsingInstance or main-frame RenderDocument // If same-site ProactivelySwapBrowsingInstance or main-frame RenderDocument
...@@ -369,7 +366,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) { ...@@ -369,7 +366,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) {
// Perform a cross-site navigation. // Perform a cross-site navigation.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url = embedded_test_server()->GetURL("foo.com", "/title3.html"); GURL url = embedded_test_server()->GetURL("foo.com", "/title3.html");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
...@@ -379,10 +376,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) { ...@@ -379,10 +376,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BrowserInitiatedNavigations) {
} }
// The RenderFrameHost should have changed. // The RenderFrameHost should have changed.
EXPECT_NE(second_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) EXPECT_NE(second_rfh, current_frame_host());
->GetFrameTree()
->root()
->current_frame_host());
} }
// Ensure that renderer initiated same-site navigations work. // Ensure that renderer initiated same-site navigations work.
...@@ -390,7 +384,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -390,7 +384,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
RendererInitiatedSameSiteNavigation) { RendererInitiatedSameSiteNavigation) {
// Perform a navigation with no live renderer. // Perform a navigation with no live renderer.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url(embedded_test_server()->GetURL("/simple_links.html")); GURL url(embedded_test_server()->GetURL("/simple_links.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
...@@ -399,51 +393,43 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -399,51 +393,43 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
EXPECT_FALSE(observer.last_initiator_routing_id()); EXPECT_FALSE(observer.last_initiator_routing_id());
} }
RenderFrameHost* initial_rfh = RenderFrameHost* initial_rfh = current_frame_host();
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root()
->current_frame_host();
auto initial_rfh_routing_id = GlobalFrameRoutingId( auto initial_rfh_routing_id = GlobalFrameRoutingId(
initial_rfh->GetProcess()->GetID(), initial_rfh->GetRoutingID()); initial_rfh->GetProcess()->GetID(), initial_rfh->GetRoutingID());
// Simulate clicking on a same-site link. // Simulate clicking on a same-site link.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url(embedded_test_server()->GetURL("/title2.html")); GURL url(embedded_test_server()->GetURL("/title2.html"));
bool success = false; bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool( EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell(), "window.domAutomationController.send(clickSameSiteLink());", shell(), "window.domAutomationController.send(clickSameSiteLink());",
&success)); &success));
EXPECT_TRUE(success); EXPECT_TRUE(success);
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
EXPECT_TRUE(observer.last_navigation_succeeded()); EXPECT_TRUE(observer.last_navigation_succeeded());
RenderFrameHost* main_rfh = shell()->web_contents()->GetMainFrame(); EXPECT_EQ(current_frame_host()->GetLastCommittedOrigin(),
EXPECT_EQ(main_rfh->GetLastCommittedOrigin(),
observer.last_initiator_origin()); observer.last_initiator_origin());
if (CanSameSiteMainFrameNavigationsChangeRenderFrameHosts()) { if (CanSameSiteMainFrameNavigationsChangeRenderFrameHosts()) {
// If same-site ProactivelySwapBrowsingInstance or main-frame // If same-site ProactivelySwapBrowsingInstance or main-frame
// RenderDocument is enabled, the navigation will result in a new RFH, so // RenderDocument is enabled, the navigation will result in a new RFH, so
// we need to compare with |initial_rfh|. // we need to compare with |initial_rfh|.
EXPECT_NE(main_rfh, initial_rfh); EXPECT_NE(current_frame_host(), initial_rfh);
EXPECT_EQ(initial_rfh_routing_id, observer.last_initiator_routing_id()); EXPECT_EQ(initial_rfh_routing_id, observer.last_initiator_routing_id());
} else { } else {
EXPECT_EQ(main_rfh, initial_rfh); EXPECT_EQ(current_frame_host(), initial_rfh);
EXPECT_EQ(GlobalFrameRoutingId(main_rfh->GetProcess()->GetID(), EXPECT_EQ(
main_rfh->GetRoutingID()), GlobalFrameRoutingId(current_frame_host()->GetProcess()->GetID(),
current_frame_host()->GetRoutingID()),
observer.last_initiator_routing_id()); observer.last_initiator_routing_id());
} }
} }
RenderFrameHost* second_rfh = RenderFrameHost* second_rfh = current_frame_host();
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root()
->current_frame_host();
if (CanSameSiteMainFrameNavigationsChangeRenderFrameHosts()) { if (CanSameSiteMainFrameNavigationsChangeRenderFrameHosts()) {
// If same-site ProactivelySwapBrowsingInstance or main-frame RenderDocument // If same-site ProactivelySwapBrowsingInstance or main-frame RenderDocument
...@@ -459,25 +445,21 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -459,25 +445,21 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
RendererInitiatedCrossSiteNavigation) { RendererInitiatedCrossSiteNavigation) {
// Perform a navigation with no live renderer. // Perform a navigation with no live renderer.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url(embedded_test_server()->GetURL("/simple_links.html")); GURL url(embedded_test_server()->GetURL("/simple_links.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
EXPECT_TRUE(observer.last_navigation_succeeded()); EXPECT_TRUE(observer.last_navigation_succeeded());
} }
RenderFrameHost* initial_rfh = RenderFrameHost* initial_rfh = current_frame_host();
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root()
->current_frame_host();
url::Origin initial_origin = initial_rfh->GetLastCommittedOrigin(); url::Origin initial_origin = initial_rfh->GetLastCommittedOrigin();
GlobalFrameRoutingId initiator_routing_id(initial_rfh->GetProcess()->GetID(), GlobalFrameRoutingId initiator_routing_id(initial_rfh->GetProcess()->GetID(),
initial_rfh->GetRoutingID()); initial_rfh->GetRoutingID());
// Simulate clicking on a cross-site link. // Simulate clicking on a cross-site link.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
const char kReplacePortNumber[] = const char kReplacePortNumber[] =
"window.domAutomationController.send(setPortNumber(%d));"; "window.domAutomationController.send(setPortNumber(%d));";
uint16_t port_number = embedded_test_server()->port(); uint16_t port_number = embedded_test_server()->port();
...@@ -491,7 +473,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -491,7 +473,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
shell(), "window.domAutomationController.send(clickCrossSiteLink());", shell(), "window.domAutomationController.send(clickCrossSiteLink());",
&success)); &success));
EXPECT_TRUE(success); EXPECT_TRUE(success);
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
EXPECT_TRUE(observer.last_navigation_succeeded()); EXPECT_TRUE(observer.last_navigation_succeeded());
EXPECT_EQ(initial_origin, observer.last_initiator_origin().value()); EXPECT_EQ(initial_origin, observer.last_initiator_origin().value());
...@@ -502,17 +484,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -502,17 +484,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// proactive BrowsingInstance swap is enabled. // proactive BrowsingInstance swap is enabled.
if (AreAllSitesIsolatedForTesting() || if (AreAllSitesIsolatedForTesting() ||
CanCrossSiteNavigationsProactivelySwapBrowsingInstances()) { CanCrossSiteNavigationsProactivelySwapBrowsingInstances()) {
EXPECT_NE(initial_rfh, EXPECT_NE(initial_rfh, current_frame_host());
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root()
->current_frame_host());
} else { } else {
EXPECT_EQ(initial_rfh, EXPECT_EQ(initial_rfh, current_frame_host());
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root()
->current_frame_host());
} }
} }
...@@ -520,7 +494,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -520,7 +494,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FailedNavigation) { IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FailedNavigation) {
// Perform a navigation with no live renderer. // Perform a navigation with no live renderer.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url(embedded_test_server()->GetURL("/title1.html")); GURL url(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
...@@ -529,14 +503,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FailedNavigation) { ...@@ -529,14 +503,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FailedNavigation) {
// Now navigate to an unreachable url. // Now navigate to an unreachable url.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL error_url(embedded_test_server()->GetURL("/close-socket")); GURL error_url(embedded_test_server()->GetURL("/close-socket"));
GetIOThreadTaskRunner({})->PostTask( GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&net::URLRequestFailedJob::AddUrlHandler)); FROM_HERE, base::BindOnce(&net::URLRequestFailedJob::AddUrlHandler));
EXPECT_FALSE(NavigateToURL(shell(), error_url)); EXPECT_FALSE(NavigateToURL(shell(), error_url));
EXPECT_EQ(error_url, observer.last_navigation_url()); EXPECT_EQ(error_url, observer.last_navigation_url());
NavigationEntry* entry = NavigationEntry* entry =
shell()->web_contents()->GetController().GetLastCommittedEntry(); web_contents()->GetController().GetLastCommittedEntry();
EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType());
} }
} }
...@@ -544,7 +518,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FailedNavigation) { ...@@ -544,7 +518,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FailedNavigation) {
// Ensure that browser initiated navigations to view-source URLs works. // Ensure that browser initiated navigations to view-source URLs works.
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
ViewSourceNavigation_BrowserInitiated) { ViewSourceNavigation_BrowserInitiated) {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url(embedded_test_server()->GetURL("/title1.html")); GURL url(embedded_test_server()->GetURL("/title1.html"));
GURL view_source_url(content::kViewSourceScheme + std::string(":") + GURL view_source_url(content::kViewSourceScheme + std::string(":") +
url.spec()); url.spec());
...@@ -556,24 +530,24 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -556,24 +530,24 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// Ensure that content initiated navigations to view-sources URLs are blocked. // Ensure that content initiated navigations to view-sources URLs are blocked.
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
ViewSourceNavigation_RendererInitiated) { ViewSourceNavigation_RendererInitiated) {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL kUrl(embedded_test_server()->GetURL("/simple_links.html")); GURL kUrl(embedded_test_server()->GetURL("/simple_links.html"));
EXPECT_TRUE(NavigateToURL(shell(), kUrl)); EXPECT_TRUE(NavigateToURL(shell(), kUrl));
EXPECT_EQ(kUrl, observer.last_navigation_url()); EXPECT_EQ(kUrl, observer.last_navigation_url());
EXPECT_TRUE(observer.last_navigation_succeeded()); EXPECT_TRUE(observer.last_navigation_succeeded());
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"Not allowed to load local resource: view-source:about:blank"); "Not allowed to load local resource: view-source:about:blank");
bool success = false; bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool( EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell()->web_contents(), web_contents(),
"window.domAutomationController.send(clickViewSourceLink());", &success)); "window.domAutomationController.send(clickViewSourceLink());", &success));
EXPECT_TRUE(success); EXPECT_TRUE(success);
console_observer.Wait(); console_observer.Wait();
// Original page shouldn't navigate away. // Original page shouldn't navigate away.
EXPECT_EQ(kUrl, shell()->web_contents()->GetURL()); EXPECT_EQ(kUrl, web_contents()->GetURL());
EXPECT_FALSE(shell() EXPECT_FALSE(shell()
->web_contents() ->web_contents()
->GetController() ->GetController()
...@@ -584,25 +558,25 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -584,25 +558,25 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// Ensure that content initiated navigations to googlechrome: URLs are blocked. // Ensure that content initiated navigations to googlechrome: URLs are blocked.
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
GoogleChromeNavigation_RendererInitiated) { GoogleChromeNavigation_RendererInitiated) {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL kUrl(embedded_test_server()->GetURL("/simple_links.html")); GURL kUrl(embedded_test_server()->GetURL("/simple_links.html"));
EXPECT_TRUE(NavigateToURL(shell(), kUrl)); EXPECT_TRUE(NavigateToURL(shell(), kUrl));
EXPECT_EQ(kUrl, observer.last_navigation_url()); EXPECT_EQ(kUrl, observer.last_navigation_url());
EXPECT_TRUE(observer.last_navigation_succeeded()); EXPECT_TRUE(observer.last_navigation_succeeded());
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"Not allowed to load local resource: googlechrome://"); "Not allowed to load local resource: googlechrome://");
bool success = false; bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool( EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell()->web_contents(), web_contents(),
"window.domAutomationController.send(clickGoogleChromeLink());", "window.domAutomationController.send(clickGoogleChromeLink());",
&success)); &success));
EXPECT_TRUE(success); EXPECT_TRUE(success);
console_observer.Wait(); console_observer.Wait();
// Original page shouldn't navigate away. // Original page shouldn't navigate away.
EXPECT_EQ(kUrl, shell()->web_contents()->GetURL()); EXPECT_EQ(kUrl, web_contents()->GetURL());
} }
// Ensure that closing a page by running its beforeunload handler doesn't hang // Ensure that closing a page by running its beforeunload handler doesn't hang
...@@ -610,11 +584,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -610,11 +584,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, UnloadDuringNavigation) { IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, UnloadDuringNavigation) {
content::WindowedNotificationObserver close_observer( content::WindowedNotificationObserver close_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(shell()->web_contents())); content::Source<content::WebContents>(web_contents()));
GURL url("chrome://resources/css/tabs.css"); GURL url("chrome://resources/css/tabs.css");
NavigationHandleObserver handle_observer(shell()->web_contents(), url); NavigationHandleObserver handle_observer(web_contents(), url);
shell()->LoadURL(url); shell()->LoadURL(url);
shell()->web_contents()->DispatchBeforeUnload(false /* auto_cancel */); web_contents()->DispatchBeforeUnload(false /* auto_cancel */);
close_observer.Wait(); close_observer.Wait();
EXPECT_EQ(net::ERR_ABORTED, handle_observer.net_error_code()); EXPECT_EQ(net::ERR_ABORTED, handle_observer.net_error_code());
} }
...@@ -630,21 +604,18 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, SanitizeReferrer) { ...@@ -630,21 +604,18 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, SanitizeReferrer) {
// referrer on downgrades. The referrer url should be rewritten right away. // referrer on downgrades. The referrer url should be rewritten right away.
NavigationController::LoadURLParams load_params(kInsecureUrl); NavigationController::LoadURLParams load_params(kInsecureUrl);
load_params.referrer = kSecureReferrer; load_params.referrer = kSecureReferrer;
TestNavigationManager manager(shell()->web_contents(), kInsecureUrl); TestNavigationManager manager(web_contents(), kInsecureUrl);
shell()->web_contents()->GetController().LoadURLWithParams(load_params); web_contents()->GetController().LoadURLWithParams(load_params);
EXPECT_TRUE(manager.WaitForRequestStart()); EXPECT_TRUE(manager.WaitForRequestStart());
// The referrer should have been sanitized. // The referrer should have been sanitized.
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) ASSERT_TRUE(main_frame()->navigation_request());
->GetMainFrame() EXPECT_EQ(GURL(), main_frame()->navigation_request()->GetReferrer().url);
->frame_tree_node();
ASSERT_TRUE(root->navigation_request());
EXPECT_EQ(GURL(), root->navigation_request()->GetReferrer().url);
// The navigation should commit without being blocked. // The navigation should commit without being blocked.
EXPECT_TRUE(manager.WaitForResponse()); EXPECT_TRUE(manager.WaitForResponse());
manager.WaitForNavigationFinished(); manager.WaitForNavigationFinished();
EXPECT_EQ(kInsecureUrl, shell()->web_contents()->GetLastCommittedURL()); EXPECT_EQ(kInsecureUrl, web_contents()->GetLastCommittedURL());
} }
// Ensure the correctness of a navigation request's referrer. This is a // Ensure the correctness of a navigation request's referrer. This is a
...@@ -663,15 +634,12 @@ IN_PROC_BROWSER_TEST_P(NavigationBrowserTestReferrerPolicy, ReferrerPolicy) { ...@@ -663,15 +634,12 @@ IN_PROC_BROWSER_TEST_P(NavigationBrowserTestReferrerPolicy, ReferrerPolicy) {
// navigation's referrer. The final referrer should be generated correctly. // navigation's referrer. The final referrer should be generated correctly.
NavigationController::LoadURLParams load_params(kDestination); NavigationController::LoadURLParams load_params(kDestination);
load_params.referrer = referrer; load_params.referrer = referrer;
TestNavigationManager manager(shell()->web_contents(), kDestination); TestNavigationManager manager(web_contents(), kDestination);
shell()->web_contents()->GetController().LoadURLWithParams(load_params); web_contents()->GetController().LoadURLWithParams(load_params);
EXPECT_TRUE(manager.WaitForRequestStart()); EXPECT_TRUE(manager.WaitForRequestStart());
// The referrer should have been sanitized. // The referrer should have been sanitized.
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) ASSERT_TRUE(main_frame()->navigation_request());
->GetMainFrame()
->frame_tree_node();
ASSERT_TRUE(root->navigation_request());
switch (GetReferrerPolicy()) { switch (GetReferrerPolicy()) {
case network::mojom::ReferrerPolicy::kAlways: case network::mojom::ReferrerPolicy::kAlways:
case network::mojom::ReferrerPolicy::kDefault: case network::mojom::ReferrerPolicy::kDefault:
...@@ -679,22 +647,23 @@ IN_PROC_BROWSER_TEST_P(NavigationBrowserTestReferrerPolicy, ReferrerPolicy) { ...@@ -679,22 +647,23 @@ IN_PROC_BROWSER_TEST_P(NavigationBrowserTestReferrerPolicy, ReferrerPolicy) {
case network::mojom::ReferrerPolicy::kOriginWhenCrossOrigin: case network::mojom::ReferrerPolicy::kOriginWhenCrossOrigin:
case network::mojom::ReferrerPolicy::kStrictOriginWhenCrossOrigin: case network::mojom::ReferrerPolicy::kStrictOriginWhenCrossOrigin:
case network::mojom::ReferrerPolicy::kSameOrigin: case network::mojom::ReferrerPolicy::kSameOrigin:
EXPECT_EQ(kReferrerURL, root->navigation_request()->GetReferrer().url); EXPECT_EQ(kReferrerURL,
main_frame()->navigation_request()->GetReferrer().url);
break; break;
case network::mojom::ReferrerPolicy::kNever: case network::mojom::ReferrerPolicy::kNever:
EXPECT_EQ(GURL(), root->navigation_request()->GetReferrer().url); EXPECT_EQ(GURL(), main_frame()->navigation_request()->GetReferrer().url);
break; break;
case network::mojom::ReferrerPolicy::kOrigin: case network::mojom::ReferrerPolicy::kOrigin:
case network::mojom::ReferrerPolicy::kStrictOrigin: case network::mojom::ReferrerPolicy::kStrictOrigin:
EXPECT_EQ(kReferrerOrigin.GetURL(), EXPECT_EQ(kReferrerOrigin.GetURL(),
root->navigation_request()->GetReferrer().url); main_frame()->navigation_request()->GetReferrer().url);
break; break;
} }
// The navigation should commit without being blocked. // The navigation should commit without being blocked.
EXPECT_TRUE(manager.WaitForResponse()); EXPECT_TRUE(manager.WaitForResponse());
manager.WaitForNavigationFinished(); manager.WaitForNavigationFinished();
EXPECT_EQ(kDestination, shell()->web_contents()->GetLastCommittedURL()); EXPECT_EQ(kDestination, web_contents()->GetLastCommittedURL());
} }
// Test to verify that an exploited renderer process trying to upload a file // Test to verify that an exploited renderer process trying to upload a file
...@@ -704,9 +673,6 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, PostUploadIllegalFilePath) { ...@@ -704,9 +673,6 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, PostUploadIllegalFilePath) {
embedded_test_server()->GetURL("/form_that_posts_to_echoall.html")); embedded_test_server()->GetURL("/form_that_posts_to_echoall.html"));
EXPECT_TRUE(NavigateToURL(shell(), form_url)); EXPECT_TRUE(NavigateToURL(shell(), form_url));
RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
shell()->web_contents()->GetMainFrame());
// Prepare a file for the upload form. // Prepare a file for the upload form.
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
base::ScopedTempDir temp_dir; base::ScopedTempDir temp_dir;
...@@ -720,23 +686,24 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, PostUploadIllegalFilePath) { ...@@ -720,23 +686,24 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, PostUploadIllegalFilePath) {
// Fill out the form to refer to the test file. // Fill out the form to refer to the test file.
std::unique_ptr<FileChooserDelegate> delegate( std::unique_ptr<FileChooserDelegate> delegate(
new FileChooserDelegate(file_path, run_loop.QuitClosure())); new FileChooserDelegate(file_path, run_loop.QuitClosure()));
shell()->web_contents()->SetDelegate(delegate.get()); web_contents()->SetDelegate(delegate.get());
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), EXPECT_TRUE(ExecuteScript(web_contents(),
"document.getElementById('file').click();")); "document.getElementById('file').click();"));
run_loop.Run(); run_loop.Run();
// Ensure that the process is allowed to access to the chosen file and // Ensure that the process is allowed to access to the chosen file and
// does not have access to the other file name. // does not have access to the other file name.
EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
rfh->GetProcess()->GetID(), file_path)); current_frame_host()->GetProcess()->GetID(), file_path));
// Revoke the access to the file and submit the form. The renderer process // Revoke the access to the file and submit the form. The renderer process
// should be terminated. // should be terminated.
RenderProcessHostBadIpcMessageWaiter process_kill_waiter(rfh->GetProcess()); RenderProcessHostBadIpcMessageWaiter process_kill_waiter(
current_frame_host()->GetProcess());
ChildProcessSecurityPolicyImpl* security_policy = ChildProcessSecurityPolicyImpl* security_policy =
ChildProcessSecurityPolicyImpl::GetInstance(); ChildProcessSecurityPolicyImpl::GetInstance();
security_policy->RevokeAllPermissionsForFile(rfh->GetProcess()->GetID(), security_policy->RevokeAllPermissionsForFile(
file_path); current_frame_host()->GetProcess()->GetID(), file_path);
// Use ExecuteScriptAndExtractBool and respond back to the browser process // Use ExecuteScriptAndExtractBool and respond back to the browser process
// before doing the actual submission. This will ensure that the process // before doing the actual submission. This will ensure that the process
...@@ -757,8 +724,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, PostUploadIllegalFilePath) { ...@@ -757,8 +724,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, PostUploadIllegalFilePath) {
// See https://crbug.com/723796. // See https://crbug.com/723796.
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
VerifyBlockedErrorPageURL_Reload) { VerifyBlockedErrorPageURL_Reload) {
NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( NavigationControllerImpl& controller = web_contents()->GetController();
shell()->web_contents()->GetController());
GURL start_url(embedded_test_server()->GetURL("/title1.html")); GURL start_url(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), start_url)); EXPECT_TRUE(NavigateToURL(shell(), start_url));
...@@ -772,7 +738,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -772,7 +738,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
EXPECT_EQ(PAGE_TYPE_ERROR, controller.GetLastCommittedEntry()->GetPageType()); EXPECT_EQ(PAGE_TYPE_ERROR, controller.GetLastCommittedEntry()->GetPageType());
TestNavigationObserver reload_observer(shell()->web_contents()); TestNavigationObserver reload_observer(web_contents());
EXPECT_TRUE(ExecuteScript(shell(), "location.reload()")); EXPECT_TRUE(ExecuteScript(shell(), "location.reload()"));
reload_observer.Wait(); reload_observer.Wait();
...@@ -795,14 +761,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BackFollowedByReload) { ...@@ -795,14 +761,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BackFollowedByReload) {
EXPECT_TRUE(NavigateToURL(shell(), url2)); EXPECT_TRUE(NavigateToURL(shell(), url2));
// Then execute a back navigation in Javascript followed by a reload. // Then execute a back navigation in Javascript followed by a reload.
TestNavigationObserver navigation_observer(shell()->web_contents()); TestNavigationObserver navigation_observer(web_contents());
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), EXPECT_TRUE(
"history.back(); location.reload();")); ExecuteScript(web_contents(), "history.back(); location.reload();"));
navigation_observer.Wait(); navigation_observer.Wait();
// The reload should have cancelled the back navigation, and the last // The reload should have cancelled the back navigation, and the last
// committed URL should still be the second URL. // committed URL should still be the second URL.
EXPECT_EQ(url2, shell()->web_contents()->GetLastCommittedURL()); EXPECT_EQ(url2, web_contents()->GetLastCommittedURL());
} }
// Test that a navigation response can be entirely fetched, even after the // Test that a navigation response can be entirely fetched, even after the
...@@ -815,7 +781,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -815,7 +781,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
// Load a new document. // Load a new document.
GURL url(embedded_test_server()->GetURL("/main_document")); GURL url(embedded_test_server()->GetURL("/main_document"));
TestNavigationManager navigation_manager(shell()->web_contents(), url); TestNavigationManager navigation_manager(web_contents(), url);
shell()->LoadURL(url); shell()->LoadURL(url);
// The navigation starts. // The navigation starts.
...@@ -823,10 +789,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -823,10 +789,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
navigation_manager.ResumeNavigation(); navigation_manager.ResumeNavigation();
// A NavigationRequest exists at this point. // A NavigationRequest exists at this point.
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) EXPECT_TRUE(main_frame()->navigation_request());
->GetMainFrame()
->frame_tree_node();
EXPECT_TRUE(root->navigation_request());
// The response's headers are received. // The response's headers are received.
response.WaitForRequest(); response.WaitForRequest();
...@@ -841,12 +804,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -841,12 +804,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
// The renderer commits the navigation and the browser deletes its // The renderer commits the navigation and the browser deletes its
// NavigationRequest. // NavigationRequest.
navigation_manager.WaitForNavigationFinished(); navigation_manager.WaitForNavigationFinished();
EXPECT_FALSE(root->navigation_request()); EXPECT_FALSE(main_frame()->navigation_request());
// The NavigationURLLoader has been deleted by now. Check that the renderer // The NavigationURLLoader has been deleted by now. Check that the renderer
// can still receive more bytes. // can still receive more bytes.
DOMMessageQueue dom_message_queue(WebContents::FromRenderFrameHost( DOMMessageQueue dom_message_queue(web_contents());
shell()->web_contents()->GetMainFrame()));
response.Send( response.Send(
"<script>window.domAutomationController.send('done');</script>"); "<script>window.domAutomationController.send('done');</script>");
std::string done; std::string done;
...@@ -963,16 +925,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, SubFrameJsNavigationInitiator) { ...@@ -963,16 +925,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, SubFrameJsNavigationInitiator) {
GURL starting_page(embedded_test_server()->GetURL("/frame_tree/top.html")); GURL starting_page(embedded_test_server()->GetURL("/frame_tree/top.html"));
EXPECT_TRUE(NavigateToURL(shell(), starting_page)); EXPECT_TRUE(NavigateToURL(shell(), starting_page));
// It is safe to obtain the root frame tree node here, as it doesn't change. // The main_frame() and subframe should each have a live RenderFrame.
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) EXPECT_TRUE(main_frame()
->GetFrameTree() ->current_frame_host()
->root(); ->render_view_host()
->IsRenderViewLive());
// The root and subframe should each have a live RenderFrame. EXPECT_TRUE(main_frame()->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE( EXPECT_TRUE(
root->current_frame_host()->render_view_host()->IsRenderViewLive()); main_frame()->child_at(0)->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive());
GURL url(embedded_test_server()->GetURL("a.com", "/title1.html")); GURL url(embedded_test_server()->GetURL("a.com", "/title1.html"));
...@@ -980,12 +940,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, SubFrameJsNavigationInitiator) { ...@@ -980,12 +940,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, SubFrameJsNavigationInitiator) {
std::string script = "location.href='" + url.spec() + "'"; std::string script = "location.href='" + url.spec() + "'";
// Perform the actual navigation. // Perform the actual navigation.
EXPECT_TRUE(ExecJs(root->child_at(0)->current_frame_host(), script)); EXPECT_TRUE(ExecJs(main_frame()->child_at(0)->current_frame_host(), script));
EXPECT_TRUE(main_frame()
->current_frame_host()
->render_view_host()
->IsRenderViewLive());
EXPECT_TRUE(main_frame()->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE( EXPECT_TRUE(
root->current_frame_host()->render_view_host()->IsRenderViewLive()); main_frame()->child_at(0)->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive());
url::Origin starting_page_origin; url::Origin starting_page_origin;
starting_page_origin = starting_page_origin.Create(starting_page); starting_page_origin = starting_page_origin.Create(starting_page);
...@@ -1006,28 +969,29 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1006,28 +969,29 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
"a.com", "/cross_site_iframe_factory.html?a(b)")); "a.com", "/cross_site_iframe_factory.html?a(b)"));
EXPECT_TRUE(NavigateToURL(shell(), starting_page)); EXPECT_TRUE(NavigateToURL(shell(), starting_page));
// It is safe to obtain the root frame tree node here, as it doesn't change. // The main_frame and subframe should each have a live RenderFrame.
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) EXPECT_TRUE(main_frame()
->GetFrameTree() ->current_frame_host()
->root(); ->render_view_host()
->IsRenderViewLive());
// The root and subframe should each have a live RenderFrame. EXPECT_TRUE(main_frame()->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE( EXPECT_TRUE(
root->current_frame_host()->render_view_host()->IsRenderViewLive()); main_frame()->child_at(0)->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive());
GURL url(embedded_test_server()->GetURL("c.com", "/title1.html")); GURL url(embedded_test_server()->GetURL("c.com", "/title1.html"));
URLLoaderMonitor monitor; URLLoaderMonitor monitor;
// Perform the actual navigation. // Perform the actual navigation.
NavigateIframeToURL(shell()->web_contents(), "child-0", url); NavigateIframeToURL(web_contents(), "child-0", url);
EXPECT_TRUE(main_frame()
->current_frame_host()
->render_view_host()
->IsRenderViewLive());
EXPECT_TRUE(main_frame()->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE( EXPECT_TRUE(
root->current_frame_host()->render_view_host()->IsRenderViewLive()); main_frame()->child_at(0)->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive());
url::Origin starting_page_origin; url::Origin starting_page_origin;
starting_page_origin = starting_page_origin.Create(starting_page); starting_page_origin = starting_page_origin.Create(starting_page);
...@@ -1043,13 +1007,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1043,13 +1007,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
GURL url(embedded_test_server()->GetURL("/simple_links.html")); GURL url(embedded_test_server()->GetURL("/simple_links.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
RenderFrameHost* initial_rfh = GlobalFrameRoutingId initiator_routing_id(
static_cast<WebContentsImpl*>(shell()->web_contents()) current_frame_host()->GetProcess()->GetID(),
->GetFrameTree() current_frame_host()->GetRoutingID());
->root()
->current_frame_host();
GlobalFrameRoutingId initiator_routing_id(initial_rfh->GetProcess()->GetID(),
initial_rfh->GetRoutingID());
// Simulate clicking on a cross-site link. // Simulate clicking on a cross-site link.
{ {
...@@ -1087,14 +1047,10 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1087,14 +1047,10 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
GURL subframe_url = GURL subframe_url =
embedded_test_server()->GetURL("a.com", "/simple_links.html"); embedded_test_server()->GetURL("a.com", "/simple_links.html");
FrameTreeNode* main_frame = NavigateFrameToURL(main_frame()->child_at(0), subframe_url);
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root();
NavigateFrameToURL(main_frame->child_at(0), subframe_url);
RenderFrameHostImpl* subframe_rfh = RenderFrameHostImpl* subframe_rfh =
main_frame->child_at(0)->current_frame_host(); current_frame_host()->child_at(0)->current_frame_host();
GlobalFrameRoutingId initiator_routing_id(subframe_rfh->GetProcess()->GetID(), GlobalFrameRoutingId initiator_routing_id(subframe_rfh->GetProcess()->GetID(),
subframe_rfh->GetRoutingID()); subframe_rfh->GetRoutingID());
...@@ -1139,7 +1095,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1139,7 +1095,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
form_action_url))); form_action_url)));
// Open a new window that can be targeted by the form submission. // Open a new window that can be targeted by the form submission.
WebContents* form_contents = shell()->web_contents(); WebContents* form_contents = web_contents();
ShellAddedObserver new_shell_observer; ShellAddedObserver new_shell_observer;
EXPECT_TRUE(ExecJs(shell(), "window.open('about:blank', 'target_frame');")); EXPECT_TRUE(ExecJs(shell(), "window.open('about:blank', 'target_frame');"));
WebContents* popup_contents = new_shell_observer.GetShell()->web_contents(); WebContents* popup_contents = new_shell_observer.GetShell()->web_contents();
...@@ -1174,13 +1130,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1174,13 +1130,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
GURL url(embedded_test_server()->GetURL("/simple_links.html")); GURL url(embedded_test_server()->GetURL("/simple_links.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
RenderFrameHost* initial_rfh = GlobalFrameRoutingId initiator_routing_id(
static_cast<WebContentsImpl*>(shell()->web_contents()) current_frame_host()->GetProcess()->GetID(),
->GetFrameTree() current_frame_host()->GetRoutingID());
->root()
->current_frame_host();
GlobalFrameRoutingId initiator_routing_id(initial_rfh->GetProcess()->GetID(),
initial_rfh->GetRoutingID());
// Simulate middle-clicking on a cross-site link. // Simulate middle-clicking on a cross-site link.
{ {
...@@ -1251,8 +1203,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1251,8 +1203,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// 2) Create an iframe and call history.pushState at the same time. // 2) Create an iframe and call history.pushState at the same time.
{ {
TestNavigationManager iframe_navigation(shell()->web_contents(), TestNavigationManager iframe_navigation(web_contents(), iframe_url);
iframe_url);
ExecuteScriptAsync(shell(), ExecuteScriptAsync(shell(),
"let iframe = document.createElement('iframe');" "let iframe = document.createElement('iframe');"
"iframe.src = '/hello.html';" "iframe.src = '/hello.html';"
...@@ -1261,8 +1212,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1261,8 +1212,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// The iframe navigation is paused. In the meantime, a pushState navigation // The iframe navigation is paused. In the meantime, a pushState navigation
// begins and ends. // begins and ends.
TestNavigationManager push_state_navigation(shell()->web_contents(), TestNavigationManager push_state_navigation(web_contents(), main_url);
main_url);
ExecuteScriptAsync(shell(), "window.history.pushState({}, null);"); ExecuteScriptAsync(shell(), "window.history.pushState({}, null);");
push_state_navigation.WaitForNavigationFinished(); push_state_navigation.WaitForNavigationFinished();
...@@ -1272,8 +1222,8 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1272,8 +1222,8 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// 3) history.back() must work. // 3) history.back() must work.
{ {
TestNavigationObserver navigation_observer(shell()->web_contents()); TestNavigationObserver navigation_observer(web_contents());
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), "history.back();")); EXPECT_TRUE(ExecuteScript(web_contents(), "history.back();"));
navigation_observer.Wait(); navigation_observer.Wait();
} }
} }
...@@ -1291,8 +1241,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -1291,8 +1241,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
GURL url(embedded_test_server()->GetURL("/title1.html")); GURL url(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
DOMMessageQueue dom_message_queue(WebContents::FromRenderFrameHost( DOMMessageQueue dom_message_queue(web_contents());
shell()->web_contents()->GetMainFrame()));
std::string message; std::string message;
// 1) Send an XHR. // 1) Send an XHR.
...@@ -1440,10 +1389,7 @@ class NavigationDownloadBrowserTest : public NavigationBaseBrowserTest { ...@@ -1440,10 +1389,7 @@ class NavigationDownloadBrowserTest : public NavigationBaseBrowserTest {
ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());
ShellDownloadManagerDelegate* delegate = ShellDownloadManagerDelegate* delegate =
static_cast<ShellDownloadManagerDelegate*>( static_cast<ShellDownloadManagerDelegate*>(
shell() web_contents()->GetBrowserContext()->GetDownloadManagerDelegate());
->web_contents()
->GetBrowserContext()
->GetDownloadManagerDelegate());
delegate->SetDownloadBehaviorForTesting(downloads_directory_.GetPath()); delegate->SetDownloadBehaviorForTesting(downloads_directory_.GetPath());
} }
...@@ -1492,7 +1438,7 @@ IN_PROC_BROWSER_TEST_F(NavigationDownloadBrowserTest, ...@@ -1492,7 +1438,7 @@ IN_PROC_BROWSER_TEST_F(NavigationDownloadBrowserTest,
main_response.Send(headers + navigate_to_download + mix_of_script_and_div); main_response.Send(headers + navigate_to_download + mix_of_script_and_div);
main_response.Done(); main_response.Done();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
} }
// Renderer initiated back/forward navigation in beforeunload should not prevent // Renderer initiated back/forward navigation in beforeunload should not prevent
...@@ -1503,7 +1449,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, HistoryBackInBeforeUnload) { ...@@ -1503,7 +1449,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, HistoryBackInBeforeUnload) {
EXPECT_TRUE(NavigateToURL(shell(), url_1)); EXPECT_TRUE(NavigateToURL(shell(), url_1));
EXPECT_TRUE( EXPECT_TRUE(
ExecuteScriptWithoutUserGesture(shell()->web_contents(), ExecuteScriptWithoutUserGesture(web_contents(),
"onbeforeunload = function() {" "onbeforeunload = function() {"
" history.pushState({}, null, '/');" " history.pushState({}, null, '/');"
" history.back();" " history.back();"
...@@ -1522,12 +1468,12 @@ IN_PROC_BROWSER_TEST_F(NavigationGoToEntryAtOffsetBrowserTest, ...@@ -1522,12 +1468,12 @@ IN_PROC_BROWSER_TEST_F(NavigationGoToEntryAtOffsetBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url_1)); EXPECT_TRUE(NavigateToURL(shell(), url_1));
EXPECT_TRUE( EXPECT_TRUE(
ExecuteScriptWithoutUserGesture(shell()->web_contents(), ExecuteScriptWithoutUserGesture(web_contents(),
"onbeforeunload = function() {" "onbeforeunload = function() {"
" history.pushState({}, null, '/');" " history.pushState({}, null, '/');"
" setTimeout(()=>history.back());" " setTimeout(()=>history.back());"
"};")); "};"));
TestNavigationManager navigation(shell()->web_contents(), url_2); TestNavigationManager navigation(web_contents(), url_2);
base::RunLoop run_loop; base::RunLoop run_loop;
SetQuitHandlerForGoToEntryAtOffset(run_loop.QuitClosure()); SetQuitHandlerForGoToEntryAtOffset(run_loop.QuitClosure());
...@@ -1548,13 +1494,13 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1548,13 +1494,13 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url_1)); EXPECT_TRUE(NavigateToURL(shell(), url_1));
// 1) A pending browser initiated navigation (omnibox, ...) starts. // 1) A pending browser initiated navigation (omnibox, ...) starts.
TestNavigationManager navigation(shell()->web_contents(), url_2); TestNavigationManager navigation(web_contents(), url_2);
shell()->LoadURL(url_2); shell()->LoadURL(url_2);
EXPECT_TRUE(navigation.WaitForRequestStart()); EXPECT_TRUE(navigation.WaitForRequestStart());
// 2) history.back() is sent but is not user initiated. // 2) history.back() is sent but is not user initiated.
EXPECT_TRUE( EXPECT_TRUE(
ExecuteScriptWithoutUserGesture(shell()->web_contents(), ExecuteScriptWithoutUserGesture(web_contents(),
"history.pushState({}, null, '/');" "history.pushState({}, null, '/');"
"history.back();")); "history.back();"));
...@@ -1572,12 +1518,12 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1572,12 +1518,12 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url_1)); EXPECT_TRUE(NavigateToURL(shell(), url_1));
// 1) A pending browser initiated navigation (omnibox, ...) starts. // 1) A pending browser initiated navigation (omnibox, ...) starts.
TestNavigationManager navigation(shell()->web_contents(), url_2); TestNavigationManager navigation(web_contents(), url_2);
shell()->LoadURL(url_2); shell()->LoadURL(url_2);
EXPECT_TRUE(navigation.WaitForRequestStart()); EXPECT_TRUE(navigation.WaitForRequestStart());
// 2) history.back() is sent and is user initiated. // 2) history.back() is sent and is user initiated.
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), EXPECT_TRUE(ExecuteScript(web_contents(),
"history.pushState({}, null, '/');" "history.pushState({}, null, '/');"
"history.back();")); "history.back();"));
...@@ -1698,7 +1644,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IPCFlood_GoToEntryAtOffset) { ...@@ -1698,7 +1644,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IPCFlood_GoToEntryAtOffset) {
GURL url(embedded_test_server()->GetURL("/title1.html")); GURL url(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"Throttling navigation to prevent the browser from hanging. See " "Throttling navigation to prevent the browser from hanging. See "
"https://crbug.com/882238. Command line switch " "https://crbug.com/882238. Command line switch "
...@@ -1725,7 +1671,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IPCFlood_Navigation) { ...@@ -1725,7 +1671,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IPCFlood_Navigation) {
GURL url(embedded_test_server()->GetURL("/title1.html")); GURL url(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"Throttling navigation to prevent the browser from hanging. See " "Throttling navigation to prevent the browser from hanging. See "
"https://crbug.com/882238. Command line switch " "https://crbug.com/882238. Command line switch "
...@@ -1751,19 +1697,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, OpenerNavigation_DownloadPolicy) { ...@@ -1751,19 +1697,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, OpenerNavigation_DownloadPolicy) {
ASSERT_TRUE(download_dir.CreateUniqueTempDir()); ASSERT_TRUE(download_dir.CreateUniqueTempDir());
ShellDownloadManagerDelegate* delegate = ShellDownloadManagerDelegate* delegate =
static_cast<ShellDownloadManagerDelegate*>( static_cast<ShellDownloadManagerDelegate*>(
shell() web_contents()->GetBrowserContext()->GetDownloadManagerDelegate());
->web_contents()
->GetBrowserContext()
->GetDownloadManagerDelegate());
delegate->SetDownloadBehaviorForTesting(download_dir.GetPath()); delegate->SetDownloadBehaviorForTesting(download_dir.GetPath());
EXPECT_TRUE( EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"))); NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
WebContents* opener = shell()->web_contents();
// Open a popup. // Open a popup.
bool opened = false; bool opened = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool( EXPECT_TRUE(ExecuteScriptAndExtractBool(
opener, "window.domAutomationController.send(!!window.open());", web_contents(), "window.domAutomationController.send(!!window.open());",
&opened)); &opened));
EXPECT_TRUE(opened); EXPECT_TRUE(opened);
EXPECT_EQ(2u, Shell::windows().size()); EXPECT_EQ(2u, Shell::windows().size());
...@@ -1771,9 +1713,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, OpenerNavigation_DownloadPolicy) { ...@@ -1771,9 +1713,9 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, OpenerNavigation_DownloadPolicy) {
// Using the popup, navigate its opener to a download. // Using the popup, navigate its opener to a download.
base::HistogramTester histograms; base::HistogramTester histograms;
WebContents* popup = Shell::windows()[1]->web_contents(); WebContents* popup = Shell::windows()[1]->web_contents();
EXPECT_NE(popup, opener); EXPECT_NE(popup, web_contents());
DownloadTestObserverInProgress observer( DownloadTestObserverInProgress observer(
BrowserContext::GetDownloadManager(opener->GetBrowserContext()), BrowserContext::GetDownloadManager(web_contents()->GetBrowserContext()),
1 /* wait_count */); 1 /* wait_count */);
EXPECT_TRUE(ExecuteScriptWithoutUserGesture( EXPECT_TRUE(ExecuteScriptWithoutUserGesture(
popup, popup,
...@@ -1794,18 +1736,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1794,18 +1736,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
ASSERT_TRUE(download_dir.CreateUniqueTempDir()); ASSERT_TRUE(download_dir.CreateUniqueTempDir());
ShellDownloadManagerDelegate* delegate = ShellDownloadManagerDelegate* delegate =
static_cast<ShellDownloadManagerDelegate*>( static_cast<ShellDownloadManagerDelegate*>(
shell() web_contents()->GetBrowserContext()->GetDownloadManagerDelegate());
->web_contents()
->GetBrowserContext()
->GetDownloadManagerDelegate());
delegate->SetDownloadBehaviorForTesting(download_dir.GetPath()); delegate->SetDownloadBehaviorForTesting(download_dir.GetPath());
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); shell(), embedded_test_server()->GetURL("a.com", "/title1.html")));
WebContents* opener = shell()->web_contents();
// Open a popup. // Open a popup.
ShellAddedObserver shell_observer; ShellAddedObserver shell_observer;
EXPECT_TRUE(EvalJs(opener, JsReplace("!!window.open($1);", EXPECT_TRUE(EvalJs(web_contents(), JsReplace("!!window.open($1);",
embedded_test_server()->GetURL( embedded_test_server()->GetURL(
"bar.com", "/title1.html"))) "bar.com", "/title1.html")))
.ExtractBool()); .ExtractBool());
...@@ -1815,13 +1753,13 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -1815,13 +1753,13 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// Wait for the navigation in the popup to complete, so the origin of the // Wait for the navigation in the popup to complete, so the origin of the
// document will be correct. // document will be correct.
WebContents* popup = new_shell->web_contents(); WebContents* popup = new_shell->web_contents();
EXPECT_NE(popup, opener); EXPECT_NE(popup, web_contents());
EXPECT_TRUE(WaitForLoadStop(popup)); EXPECT_TRUE(WaitForLoadStop(popup));
// Using the popup, navigate its opener to a download. // Using the popup, navigate its opener to a download.
base::HistogramTester histograms; base::HistogramTester histograms;
const GURL data_url("data:html/text;base64,cGF5bG9hZA=="); const GURL data_url("data:html/text;base64,cGF5bG9hZA==");
TestNavigationManager manager(shell()->web_contents(), data_url); TestNavigationManager manager(web_contents(), data_url);
EXPECT_TRUE( EXPECT_TRUE(
ExecuteScript(popup, base::StringPrintf("window.opener.location ='%s'", ExecuteScript(popup, base::StringPrintf("window.opener.location ='%s'",
data_url.spec().c_str()))); data_url.spec().c_str())));
...@@ -1846,7 +1784,7 @@ IN_PROC_BROWSER_TEST_F(NavigationDownloadBrowserTest, ...@@ -1846,7 +1784,7 @@ IN_PROC_BROWSER_TEST_F(NavigationDownloadBrowserTest,
// Block every iframe in WillProcessResponse. // Block every iframe in WillProcessResponse.
content::TestNavigationThrottleInserter throttle_inserter( content::TestNavigationThrottleInserter throttle_inserter(
shell()->web_contents(), web_contents(),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> { [&](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> {
auto throttle = std::make_unique<TestNavigationThrottle>(handle); auto throttle = std::make_unique<TestNavigationThrottle>(handle);
...@@ -1869,7 +1807,7 @@ IN_PROC_BROWSER_TEST_F(NavigationDownloadBrowserTest, ...@@ -1869,7 +1807,7 @@ IN_PROC_BROWSER_TEST_F(NavigationDownloadBrowserTest,
} }
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
} }
// Add header on redirect. // Add header on redirect.
...@@ -1881,7 +1819,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, AddRequestHeaderOnRedirect) { ...@@ -1881,7 +1819,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, AddRequestHeaderOnRedirect) {
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
content::TestNavigationThrottleInserter throttle_inserter( content::TestNavigationThrottleInserter throttle_inserter(
shell()->web_contents(), web_contents(),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> { [](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> {
auto throttle = std::make_unique<TestNavigationThrottle>(handle); auto throttle = std::make_unique<TestNavigationThrottle>(handle);
...@@ -1919,7 +1857,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -1919,7 +1857,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
content::TestNavigationThrottleInserter throttle_inserter( content::TestNavigationThrottleInserter throttle_inserter(
shell()->web_contents(), web_contents(),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> { [](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> {
auto throttle = std::make_unique<TestNavigationThrottle>(handle); auto throttle = std::make_unique<TestNavigationThrottle>(handle);
...@@ -1962,7 +1900,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -1962,7 +1900,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
content::TestNavigationThrottleInserter throttle_inserter( content::TestNavigationThrottleInserter throttle_inserter(
shell()->web_contents(), web_contents(),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> { [](NavigationHandle* handle) -> std::unique_ptr<NavigationThrottle> {
NavigationRequest* request = NavigationRequest::From(handle); NavigationRequest* request = NavigationRequest::From(handle);
...@@ -2086,7 +2024,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCorsExemptBrowserTest, ...@@ -2086,7 +2024,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCorsExemptBrowserTest,
const std::string header_value = "value"; const std::string header_value = "value";
content::TestNavigationThrottleInserter throttle_inserter( content::TestNavigationThrottleInserter throttle_inserter(
shell()->web_contents(), web_contents(),
base::BindLambdaForTesting([header_value](NavigationHandle* handle) base::BindLambdaForTesting([header_value](NavigationHandle* handle)
-> std::unique_ptr<NavigationThrottle> { -> std::unique_ptr<NavigationThrottle> {
NavigationRequest* request = NavigationRequest::From(handle); NavigationRequest* request = NavigationRequest::From(handle);
...@@ -2163,23 +2101,22 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, WebViewRendererKillReload) { ...@@ -2163,23 +2101,22 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, WebViewRendererKillReload) {
RenderProcessHost::SetMaxRendererProcessCount(1u); RenderProcessHost::SetMaxRendererProcessCount(1u);
// Load a page into first webview. // Load a page into first webview.
auto* web_contents = shell()->web_contents();
GURL url(embedded_test_server()->GetURL("/simple_links.html")); GURL url(embedded_test_server()->GetURL("/simple_links.html"));
{ {
TestNavigationObserver observer(web_contents); TestNavigationObserver observer(web_contents());
EXPECT_TRUE(NavigateToURL(web_contents, url)); EXPECT_TRUE(NavigateToURL(web_contents(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
} }
// Install a crash observer that synchronously creates and loads a new // Install a crash observer that synchronously creates and loads a new
// WebContents. Then crash the renderer which triggers the observer. // WebContents. Then crash the renderer which triggers the observer.
CreateWebContentsOnCrashObserver crash_observer(url, web_contents); CreateWebContentsOnCrashObserver crash_observer(url, web_contents());
content::NotificationRegistrar notification_registrar; content::NotificationRegistrar notification_registrar;
notification_registrar.Add(&crash_observer, notification_registrar.Add(&crash_observer,
content::NOTIFICATION_RENDERER_PROCESS_CLOSED, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
NavigateToURLBlockUntilNavigationsComplete(web_contents, GetWebUIURL("crash"), NavigateToURLBlockUntilNavigationsComplete(web_contents(),
1); GetWebUIURL("crash"), 1);
// Wait for navigation in new WebContents to finish. // Wait for navigation in new WebContents to finish.
NewWebContentsData data = crash_observer.TakeNewWebContentsData(); NewWebContentsData data = crash_observer.TakeNewWebContentsData();
...@@ -2197,8 +2134,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocBrowserInitiated) { ...@@ -2197,8 +2134,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocBrowserInitiated) {
"about:srcdoc#foo"}; "about:srcdoc#foo"};
// 1. Main frame navigations to about:srcdoc and its variations are blocked. // 1. Main frame navigations to about:srcdoc and its variations are blocked.
for (const char* url : about_srcdoc_urls) { for (const char* url : about_srcdoc_urls) {
NavigationHandleObserver handle_observer(shell()->web_contents(), NavigationHandleObserver handle_observer(web_contents(), GURL(url));
GURL(url));
EXPECT_FALSE(NavigateToURL(shell(), GURL(url))); EXPECT_FALSE(NavigateToURL(shell(), GURL(url)));
EXPECT_TRUE(handle_observer.has_committed()); EXPECT_TRUE(handle_observer.has_committed());
EXPECT_TRUE(handle_observer.is_error()); EXPECT_TRUE(handle_observer.is_error());
...@@ -2211,11 +2147,10 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocBrowserInitiated) { ...@@ -2211,11 +2147,10 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocBrowserInitiated) {
embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html"); embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html");
EXPECT_TRUE(NavigateToURL(shell(), main_url)); EXPECT_TRUE(NavigateToURL(shell(), main_url));
NavigationHandleObserver handle_observer(shell()->web_contents(), NavigationHandleObserver handle_observer(web_contents(), GURL(url));
GURL(url));
shell()->LoadURLForFrame(GURL(url), "child-name-0", shell()->LoadURLForFrame(GURL(url), "child-name-0",
ui::PAGE_TRANSITION_FORWARD_BACK); ui::PAGE_TRANSITION_FORWARD_BACK);
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(handle_observer.has_committed()); EXPECT_TRUE(handle_observer.has_committed());
EXPECT_FALSE(handle_observer.is_error()); EXPECT_FALSE(handle_observer.is_error());
EXPECT_EQ(net::OK, handle_observer.net_error_code()); EXPECT_EQ(net::OK, handle_observer.net_error_code());
...@@ -2226,24 +2161,19 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocBrowserInitiated) { ...@@ -2226,24 +2161,19 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocBrowserInitiated) {
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocRendererInitiated) { IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocRendererInitiated) {
EXPECT_TRUE( EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"))); NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
FrameTreeNode* main_frame =
static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root();
const char* about_srcdoc_urls[] = {"about:srcdoc", "about:srcdoc?foo", const char* about_srcdoc_urls[] = {"about:srcdoc", "about:srcdoc?foo",
"about:srcdoc#foo"}; "about:srcdoc#foo"};
// 1. Main frame navigations to about:srcdoc and its variations are blocked. // 1. Main frame navigations to about:srcdoc and its variations are blocked.
for (const char* url : about_srcdoc_urls) { for (const char* url : about_srcdoc_urls) {
DidStartNavigationObserver start_observer(shell()->web_contents()); DidStartNavigationObserver start_observer(web_contents());
NavigationHandleObserver handle_observer(shell()->web_contents(), NavigationHandleObserver handle_observer(web_contents(), GURL(url));
GURL(url));
// TODO(arthursonzogni): It shouldn't be possible to navigate to // TODO(arthursonzogni): It shouldn't be possible to navigate to
// about:srcdoc by executing location.href= "about:srcdoc". Other web // about:srcdoc by executing location.href= "about:srcdoc". Other web
// browsers like Firefox aren't allowing this. // browsers like Firefox aren't allowing this.
EXPECT_TRUE(ExecJs(main_frame, JsReplace("location.href = $1", url))); EXPECT_TRUE(ExecJs(main_frame(), JsReplace("location.href = $1", url)));
start_observer.Wait(); start_observer.Wait();
WaitForLoadStop(shell()->web_contents()); WaitForLoadStop(web_contents());
EXPECT_TRUE(handle_observer.has_committed()); EXPECT_TRUE(handle_observer.has_committed());
EXPECT_TRUE(handle_observer.is_error()); EXPECT_TRUE(handle_observer.is_error());
EXPECT_EQ(net::ERR_INVALID_URL, handle_observer.net_error_code()); EXPECT_EQ(net::ERR_INVALID_URL, handle_observer.net_error_code());
...@@ -2255,16 +2185,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocRendererInitiated) { ...@@ -2255,16 +2185,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, BlockedSrcDocRendererInitiated) {
embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html"); embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html");
EXPECT_TRUE(NavigateToURL(shell(), main_url)); EXPECT_TRUE(NavigateToURL(shell(), main_url));
DidStartNavigationObserver start_observer(shell()->web_contents()); DidStartNavigationObserver start_observer(web_contents());
NavigationHandleObserver handle_observer(shell()->web_contents(), NavigationHandleObserver handle_observer(web_contents(), GURL(url));
GURL(url)); FrameTreeNode* subframe = main_frame()->child_at(0);
FrameTreeNode* subframe = main_frame->child_at(0);
// TODO(arthursonzogni): It shouldn't be possible to navigate to // TODO(arthursonzogni): It shouldn't be possible to navigate to
// about:srcdoc by executing location.href= "about:srcdoc". Other web // about:srcdoc by executing location.href= "about:srcdoc". Other web
// browsers like Firefox aren't allowing this. // browsers like Firefox aren't allowing this.
EXPECT_TRUE(ExecJs(subframe, JsReplace("location.href = $1", url))); EXPECT_TRUE(ExecJs(subframe, JsReplace("location.href = $1", url)));
start_observer.Wait(); start_observer.Wait();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(handle_observer.has_committed()); EXPECT_TRUE(handle_observer.has_committed());
EXPECT_FALSE(handle_observer.is_error()); EXPECT_FALSE(handle_observer.is_error());
...@@ -2281,9 +2210,8 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, AboutSrcDocUsesBeginNavigation) { ...@@ -2281,9 +2210,8 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, AboutSrcDocUsesBeginNavigation) {
// If DidStartNavigation is called before DidCommitProvisionalLoad, then it // If DidStartNavigation is called before DidCommitProvisionalLoad, then it
// means the navigation was driven by the browser process, otherwise by the // means the navigation was driven by the browser process, otherwise by the
// renderer process. This tests it was driven by the browser process: // renderer process. This tests it was driven by the browser process:
InterceptAndCancelDidCommitProvisionalLoad interceptor( InterceptAndCancelDidCommitProvisionalLoad interceptor(web_contents());
shell()->web_contents()); DidStartNavigationObserver observer(web_contents());
DidStartNavigationObserver observer(shell()->web_contents());
EXPECT_TRUE(ExecJs(shell(), R"( EXPECT_TRUE(ExecJs(shell(), R"(
let iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
...@@ -2324,8 +2252,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2324,8 +2252,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
)")); )"));
// Inspect the session history. // Inspect the session history.
NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( NavigationControllerImpl& controller = web_contents()->GetController();
shell()->web_contents()->GetController());
ASSERT_EQ(3, controller.GetEntryCount()); ASSERT_EQ(3, controller.GetEntryCount());
ASSERT_EQ(2, controller.GetCurrentEntryIndex()); ASSERT_EQ(2, controller.GetCurrentEntryIndex());
...@@ -2370,8 +2297,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2370,8 +2297,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// 2) Cross-document navigation to about:srcdoc?1. // 2) Cross-document navigation to about:srcdoc?1.
{ {
TestNavigationManager commit_waiter(shell()->web_contents(), TestNavigationManager commit_waiter(web_contents(), GURL("about:srcdoc?1"));
GURL("about:srcdoc?1"));
EXPECT_TRUE(ExecJs(shell(), R"( EXPECT_TRUE(ExecJs(shell(), R"(
let subwindow = document.querySelector('iframe').contentWindow; let subwindow = document.querySelector('iframe').contentWindow;
subwindow.location.search = "1"; subwindow.location.search = "1";
...@@ -2381,8 +2307,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2381,8 +2307,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// 3) Cross-document navigation to about:srcdoc?2. // 3) Cross-document navigation to about:srcdoc?2.
{ {
TestNavigationManager commit_waiter(shell()->web_contents(), TestNavigationManager commit_waiter(web_contents(), GURL("about:srcdoc?2"));
GURL("about:srcdoc?2"));
EXPECT_TRUE(ExecJs(shell(), R"( EXPECT_TRUE(ExecJs(shell(), R"(
let subwindow = document.querySelector('iframe').contentWindow; let subwindow = document.querySelector('iframe').contentWindow;
subwindow.location.search = "2"; subwindow.location.search = "2";
...@@ -2391,8 +2316,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2391,8 +2316,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
} }
// Inspect the session history. // Inspect the session history.
NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( NavigationControllerImpl& controller = web_contents()->GetController();
shell()->web_contents()->GetController());
ASSERT_EQ(3, controller.GetEntryCount()); ASSERT_EQ(3, controller.GetEntryCount());
ASSERT_EQ(2, controller.GetCurrentEntryIndex()); ASSERT_EQ(2, controller.GetCurrentEntryIndex());
...@@ -2430,11 +2354,8 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2430,11 +2354,8 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
// not happening with back-forward cache enabled. // not happening with back-forward cache enabled.
// See BackForwardCacheBrowserTest.RestoreWhilePendingCommit which covers the // See BackForwardCacheBrowserTest.RestoreWhilePendingCommit which covers the
// same scenario for back-forward cache. // same scenario for back-forward cache.
shell() web_contents()->GetController().GetBackForwardCache().DisableForTesting(
->web_contents() BackForwardCacheImpl::TEST_ASSUMES_NO_CACHING);
->GetController()
.GetBackForwardCache()
.DisableForTesting(BackForwardCacheImpl::TEST_ASSUMES_NO_CACHING);
using Response = net::test_server::ControllableHttpResponse; using Response = net::test_server::ControllableHttpResponse;
Response response_A1(embedded_test_server(), "/A"); Response response_A1(embedded_test_server(), "/A");
...@@ -2449,31 +2370,31 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2449,31 +2370,31 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
GURL url_c = embedded_test_server()->GetURL("c.com", "/C"); GURL url_c = embedded_test_server()->GetURL("c.com", "/C");
EmbedderVisibleUrlTracker embedder_url_tracker; EmbedderVisibleUrlTracker embedder_url_tracker;
shell()->web_contents()->SetDelegate(&embedder_url_tracker); web_contents()->SetDelegate(&embedder_url_tracker);
// 1. Navigate to A. // 1. Navigate to A.
shell()->LoadURL(url_a); shell()->LoadURL(url_a);
response_A1.WaitForRequest(); response_A1.WaitForRequest();
response_A1.Send(non_cacheable_html_response); response_A1.Send(non_cacheable_html_response);
response_A1.Done(); response_A1.Done();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// 2. Navigate to B. // 2. Navigate to B.
shell()->LoadURL(url_b); shell()->LoadURL(url_b);
response_B1.WaitForRequest(); response_B1.WaitForRequest();
response_B1.Send(non_cacheable_html_response); response_B1.Send(non_cacheable_html_response);
response_B1.Done(); response_B1.Done();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// 3. Add a forward entry in the history for later (same-document). // 3. Add a forward entry in the history for later (same-document).
EXPECT_TRUE(ExecJs(shell()->web_contents(), R"( EXPECT_TRUE(ExecJs(web_contents(), R"(
history.pushState({},''); history.pushState({},'');
history.back(); history.back();
)")); )"));
// 4. Start navigation to C. // 4. Start navigation to C.
{ {
EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_b, web_contents()->GetVisibleURL());
EXPECT_EQ(url_b, embedder_url_tracker.url()); EXPECT_EQ(url_b, embedder_url_tracker.url());
} }
shell()->LoadURL(url_c); shell()->LoadURL(url_c);
...@@ -2483,37 +2404,37 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2483,37 +2404,37 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
// progress. The browser is still waiting on the same-document // progress. The browser is still waiting on the same-document
// "history.back()" to complete. // "history.back()" to complete.
{ {
EXPECT_EQ(url_c, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_c, web_contents()->GetVisibleURL());
EXPECT_EQ(url_b, embedder_url_tracker.url()); EXPECT_EQ(url_b, embedder_url_tracker.url());
} }
embedder_url_tracker.WaitUntilUrlInvalidated(); embedder_url_tracker.WaitUntilUrlInvalidated();
{ {
EXPECT_EQ(url_c, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_c, web_contents()->GetVisibleURL());
EXPECT_EQ(url_c, embedder_url_tracker.url()); EXPECT_EQ(url_c, embedder_url_tracker.url());
} }
response_C1.WaitForRequest(); response_C1.WaitForRequest();
// 5. Start history cross-document navigation, cancelling 4. // 5. Start history cross-document navigation, cancelling 4.
EXPECT_TRUE(ExecJs(shell()->web_contents(), "history.back()")); EXPECT_TRUE(ExecJs(web_contents(), "history.back()"));
{ {
EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_b, web_contents()->GetVisibleURL());
EXPECT_EQ(url_b, embedder_url_tracker.url()); EXPECT_EQ(url_b, embedder_url_tracker.url());
} }
response_A2.WaitForRequest(); response_A2.WaitForRequest();
{ {
EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_b, web_contents()->GetVisibleURL());
EXPECT_EQ(url_b, embedder_url_tracker.url()); EXPECT_EQ(url_b, embedder_url_tracker.url());
} }
// 6. Start history same-document navigation, cancelling 5. // 6. Start history same-document navigation, cancelling 5.
EXPECT_TRUE(ExecJs(shell()->web_contents(), "history.forward()")); EXPECT_TRUE(ExecJs(web_contents(), "history.forward()"));
{ {
EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_b, web_contents()->GetVisibleURL());
EXPECT_EQ(url_b, embedder_url_tracker.url()); EXPECT_EQ(url_b, embedder_url_tracker.url());
} }
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
{ {
EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_b, web_contents()->GetVisibleURL());
EXPECT_EQ(url_b, embedder_url_tracker.url()); EXPECT_EQ(url_b, embedder_url_tracker.url());
} }
} }
...@@ -2535,22 +2456,22 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, CanceledNavigationBug999932) { ...@@ -2535,22 +2456,22 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, CanceledNavigationBug999932) {
response_A1.WaitForRequest(); response_A1.WaitForRequest();
response_A1.Send(non_cacheable_html_response); response_A1.Send(non_cacheable_html_response);
response_A1.Done(); response_A1.Done();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// 2. Start pending navigation to B. // 2. Start pending navigation to B.
shell()->LoadURL(url_b); shell()->LoadURL(url_b);
EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_b, web_contents()->GetVisibleURL());
EXPECT_TRUE(shell()->web_contents()->GetController().GetPendingEntry()); EXPECT_TRUE(web_contents()->GetController().GetPendingEntry());
// 3. Cancel (2) with renderer-initiated reload with a UserGesture. // 3. Cancel (2) with renderer-initiated reload with a UserGesture.
EXPECT_TRUE(ExecJs(shell()->web_contents(), "location.reload()")); EXPECT_TRUE(ExecJs(web_contents(), "location.reload()"));
EXPECT_EQ(url_a, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_a, web_contents()->GetVisibleURL());
EXPECT_FALSE(shell()->web_contents()->GetController().GetPendingEntry()); EXPECT_FALSE(web_contents()->GetController().GetPendingEntry());
// 4. Cancel (3) using document.open(); // 4. Cancel (3) using document.open();
EXPECT_TRUE(ExecJs(shell()->web_contents(), "document.open()")); EXPECT_TRUE(ExecJs(web_contents(), "document.open()"));
EXPECT_EQ(url_a, shell()->web_contents()->GetVisibleURL()); EXPECT_EQ(url_a, web_contents()->GetVisibleURL());
EXPECT_FALSE(shell()->web_contents()->GetController().GetPendingEntry()); EXPECT_FALSE(web_contents()->GetController().GetPendingEntry());
} }
// Regression test for https://crbug.com/1001283 // Regression test for https://crbug.com/1001283
...@@ -2570,7 +2491,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2570,7 +2491,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
GURL url_b = embedded_test_server()->GetURL("a.com", "/title1.html"); GURL url_b = embedded_test_server()->GetURL("a.com", "/title1.html");
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern("Refused to execute inline script *"); console_observer.SetPattern("Refused to execute inline script *");
// 1) Load main document with CSP: script-src 'none' // 1) Load main document with CSP: script-src 'none'
...@@ -2589,7 +2510,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2589,7 +2510,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
"'>" "'>"
"</iframe>"); "</iframe>");
main_document_response.Done(); main_document_response.Done();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// Check Javascript was blocked the first time. // Check Javascript was blocked the first time.
console_observer.Wait(); console_observer.Wait();
...@@ -2598,15 +2519,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2598,15 +2519,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
// 3) The iframe navigates elsewhere. // 3) The iframe navigates elsewhere.
shell()->LoadURLForFrame(url_b, "theiframe", shell()->LoadURLForFrame(url_b, "theiframe",
ui::PAGE_TRANSITION_MANUAL_SUBFRAME); ui::PAGE_TRANSITION_MANUAL_SUBFRAME);
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern("Refused to execute inline script *"); console_observer.SetPattern("Refused to execute inline script *");
// 4) The iframe navigates back to about:srcdoc. // 4) The iframe navigates back to about:srcdoc.
shell()->web_contents()->GetController().GoBack(); web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// Check Javascript was blocked the second time. // Check Javascript was blocked the second time.
console_observer.Wait(); console_observer.Wait();
...@@ -2624,7 +2545,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2624,7 +2545,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
GURL url_b = embedded_test_server()->GetURL("b.com", "/title1.html"); GURL url_b = embedded_test_server()->GetURL("b.com", "/title1.html");
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern("Refused to execute inline script *"); console_observer.SetPattern("Refused to execute inline script *");
// 1) Load main document with CSP: script-src 'none' // 1) Load main document with CSP: script-src 'none'
...@@ -2643,7 +2564,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2643,7 +2564,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
"'>" "'>"
"</iframe>"); "</iframe>");
main_document_response.Done(); main_document_response.Done();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// Check Javascript was blocked the first time. // Check Javascript was blocked the first time.
console_observer.Wait(); console_observer.Wait();
...@@ -2652,15 +2573,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2652,15 +2573,15 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
// 3) The iframe navigates elsewhere. // 3) The iframe navigates elsewhere.
shell()->LoadURLForFrame(url_b, "theiframe", shell()->LoadURLForFrame(url_b, "theiframe",
ui::PAGE_TRANSITION_MANUAL_SUBFRAME); ui::PAGE_TRANSITION_MANUAL_SUBFRAME);
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern("Refused to execute inline script *"); console_observer.SetPattern("Refused to execute inline script *");
// 4) The iframe navigates back to about:srcdoc. // 4) The iframe navigates back to about:srcdoc.
shell()->web_contents()->GetController().GoBack(); web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// Check Javascript was blocked the second time. // Check Javascript was blocked the second time.
console_observer.Wait(); console_observer.Wait();
...@@ -2673,22 +2594,18 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest, ...@@ -2673,22 +2594,18 @@ IN_PROC_BROWSER_TEST_F(NavigationBaseBrowserTest,
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
NavigationRequest_GetNextPageUkmSourceId_Basic) { NavigationRequest_GetNextPageUkmSourceId_Basic) {
const GURL kUrl(embedded_test_server()->GetURL("/title1.html")); const GURL kUrl(embedded_test_server()->GetURL("/title1.html"));
TestNavigationManager manager(shell()->web_contents(), kUrl); TestNavigationManager manager(web_contents(), kUrl);
shell()->LoadURL(kUrl); shell()->LoadURL(kUrl);
EXPECT_TRUE(manager.WaitForRequestStart()); EXPECT_TRUE(manager.WaitForRequestStart());
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) ASSERT_TRUE(main_frame()->navigation_request());
->GetMainFrame()
->frame_tree_node();
ASSERT_TRUE(root->navigation_request());
ukm::SourceId nav_request_id = ukm::SourceId nav_request_id =
root->navigation_request()->GetNextPageUkmSourceId(); main_frame()->navigation_request()->GetNextPageUkmSourceId();
EXPECT_TRUE(manager.WaitForResponse()); EXPECT_TRUE(manager.WaitForResponse());
manager.WaitForNavigationFinished(); manager.WaitForNavigationFinished();
EXPECT_EQ(shell()->web_contents()->GetMainFrame()->GetPageUkmSourceId(), EXPECT_EQ(current_frame_host()->GetPageUkmSourceId(), nav_request_id);
nav_request_id);
} }
// Test that NavigationRequest::GetNextPageUkmSourceId returns the eventual // Test that NavigationRequest::GetNextPageUkmSourceId returns the eventual
...@@ -2699,13 +2616,10 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2699,13 +2616,10 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html"));
const GURL kDestUrl(embedded_test_server()->GetURL("/title1.html")); const GURL kDestUrl(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), kUrl)); EXPECT_TRUE(NavigateToURL(shell(), kUrl));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* subframe = main_frame()->child_at(0);
->GetMainFrame()
->frame_tree_node();
FrameTreeNode* subframe = root->child_at(0);
ASSERT_TRUE(subframe); ASSERT_TRUE(subframe);
TestNavigationManager manager(shell()->web_contents(), kDestUrl); TestNavigationManager manager(web_contents(), kDestUrl);
EXPECT_TRUE( EXPECT_TRUE(
ExecJs(subframe, JsReplace("location.href = $1", kDestUrl.spec()))); ExecJs(subframe, JsReplace("location.href = $1", kDestUrl.spec())));
EXPECT_TRUE(manager.WaitForRequestStart()); EXPECT_TRUE(manager.WaitForRequestStart());
...@@ -2719,8 +2633,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2719,8 +2633,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
// Should have the same page UKM ID in navigation as page post commit, and as // Should have the same page UKM ID in navigation as page post commit, and as
// the top-level frame. // the top-level frame.
EXPECT_EQ(shell()->web_contents()->GetMainFrame()->GetPageUkmSourceId(), EXPECT_EQ(current_frame_host()->GetPageUkmSourceId(), nav_request_id);
nav_request_id);
EXPECT_EQ(subframe->current_frame_host()->GetPageUkmSourceId(), EXPECT_EQ(subframe->current_frame_host()->GetPageUkmSourceId(),
nav_request_id); nav_request_id);
} }
...@@ -2732,16 +2645,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2732,16 +2645,14 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
const GURL kUrl(embedded_test_server()->GetURL("/title1.html")); const GURL kUrl(embedded_test_server()->GetURL("/title1.html"));
const GURL kFragment(kUrl.Resolve("#here")); const GURL kFragment(kUrl.Resolve("#here"));
EXPECT_TRUE(NavigateToURL(shell(), kUrl)); EXPECT_TRUE(NavigateToURL(shell(), kUrl));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetMainFrame()
->frame_tree_node();
NavigationHandleObserver handle_observer(shell()->web_contents(), kFragment); NavigationHandleObserver handle_observer(web_contents(), kFragment);
EXPECT_TRUE(ExecJs(root, JsReplace("location.href = $1", kFragment.spec()))); EXPECT_TRUE(
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); ExecJs(main_frame(), JsReplace("location.href = $1", kFragment.spec())));
EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(handle_observer.is_same_document()); EXPECT_TRUE(handle_observer.is_same_document());
EXPECT_EQ(shell()->web_contents()->GetMainFrame()->GetPageUkmSourceId(), EXPECT_EQ(current_frame_host()->GetPageUkmSourceId(),
handle_observer.next_page_ukm_source_id()); handle_observer.next_page_ukm_source_id());
} }
...@@ -2755,11 +2666,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -2755,11 +2666,11 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), kUrl1)); EXPECT_TRUE(NavigateToURL(shell(), kUrl1));
EXPECT_TRUE(NavigateToURL(shell(), kUrl2)); EXPECT_TRUE(NavigateToURL(shell(), kUrl2));
NavigationHandleObserver handle_observer(shell()->web_contents(), kUrl1); NavigationHandleObserver handle_observer(web_contents(), kUrl1);
shell()->web_contents()->GetController().GoBack(); web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_EQ(shell()->web_contents()->GetMainFrame()->GetPageUkmSourceId(), EXPECT_EQ(current_frame_host()->GetPageUkmSourceId(),
handle_observer.next_page_ukm_source_id()); handle_observer.next_page_ukm_source_id());
} }
...@@ -2807,10 +2718,9 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedSrcDoc) { ...@@ -2807,10 +2718,9 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedSrcDoc) {
iframe.srcdoc = "foo"; iframe.srcdoc = "foo";
document.body.appendChild(iframe); document.body.appendChild(iframe);
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* main_document = static_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* main_document = current_frame_host();
shell()->web_contents()->GetMainFrame());
RenderFrameHostImpl* sub_document_1 = RenderFrameHostImpl* sub_document_1 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
EXPECT_EQ(url::kAboutSrcdocURL, sub_document_1->GetLastCommittedURL()); EXPECT_EQ(url::kAboutSrcdocURL, sub_document_1->GetLastCommittedURL());
...@@ -2842,7 +2752,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedSrcDoc) { ...@@ -2842,7 +2752,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedSrcDoc) {
// 4. Navigate the iframe elsewhere. // 4. Navigate the iframe elsewhere.
EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b))); EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b)));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* sub_document_2 = RenderFrameHostImpl* sub_document_2 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
...@@ -2868,8 +2778,8 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedSrcDoc) { ...@@ -2868,8 +2778,8 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedSrcDoc) {
EXPECT_EQ("d=0", response_2.http_request()->headers.at("Cookie")); EXPECT_EQ("d=0", response_2.http_request()->headers.at("Cookie"));
// 8. Navigate the iframe back to about:srcdoc. // 8. Navigate the iframe back to about:srcdoc.
shell()->web_contents()->GetController().GoBack(); web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* sub_document_3 = RenderFrameHostImpl* sub_document_3 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
EXPECT_EQ(url_a, main_document->GetLastCommittedURL()); EXPECT_EQ(url_a, main_document->GetLastCommittedURL());
...@@ -2926,14 +2836,13 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, ...@@ -2926,14 +2836,13 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest,
"iframe.src = $1;" "iframe.src = $1;"
"document.body.appendChild(iframe);", "document.body.appendChild(iframe);",
url_b))); url_b)));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(ExecJs(shell(), R"( EXPECT_TRUE(ExecJs(shell(), R"(
document.querySelector('iframe').src = "about:blank" document.querySelector('iframe').src = "about:blank"
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* main_document = static_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* main_document = current_frame_host();
shell()->web_contents()->GetMainFrame());
RenderFrameHostImpl* sub_document_1 = RenderFrameHostImpl* sub_document_1 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
...@@ -2967,7 +2876,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, ...@@ -2967,7 +2876,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest,
// 4. Navigate the iframe elsewhere. // 4. Navigate the iframe elsewhere.
EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b))); EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b)));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* sub_document_2 = RenderFrameHostImpl* sub_document_2 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
...@@ -2993,8 +2902,8 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, ...@@ -2993,8 +2902,8 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest,
EXPECT_EQ("d=0", response_2.http_request()->headers.at("Cookie")); EXPECT_EQ("d=0", response_2.http_request()->headers.at("Cookie"));
// 8. Navigate the iframe back to about:blank. // 8. Navigate the iframe back to about:blank.
shell()->web_contents()->GetController().GoBack(); web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* sub_document_3 = RenderFrameHostImpl* sub_document_3 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
EXPECT_EQ(url_a, main_document->GetLastCommittedURL()); EXPECT_EQ(url_a, main_document->GetLastCommittedURL());
...@@ -3055,14 +2964,13 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, ...@@ -3055,14 +2964,13 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest,
"iframe.src = $1;" "iframe.src = $1;"
"document.body.appendChild(iframe);", "document.body.appendChild(iframe);",
url_b))); url_b)));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(ExecJs(shell(), R"( EXPECT_TRUE(ExecJs(shell(), R"(
document.querySelector('iframe').src = "about:blank" document.querySelector('iframe').src = "about:blank"
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* main_document = static_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* main_document = current_frame_host();
shell()->web_contents()->GetMainFrame());
RenderFrameHostImpl* sub_document_1 = RenderFrameHostImpl* sub_document_1 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
EXPECT_EQ(url::kAboutBlankURL, sub_document_1->GetLastCommittedURL()); EXPECT_EQ(url::kAboutBlankURL, sub_document_1->GetLastCommittedURL());
...@@ -3094,7 +3002,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, ...@@ -3094,7 +3002,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest,
// 4. Navigate the iframe elsewhere. // 4. Navigate the iframe elsewhere.
EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b))); EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b)));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* sub_document_2 = RenderFrameHostImpl* sub_document_2 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
...@@ -3123,7 +3031,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, ...@@ -3123,7 +3031,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest,
EXPECT_TRUE(ExecJs(shell(), R"( EXPECT_TRUE(ExecJs(shell(), R"(
document.querySelector('iframe').src = "about:blank"; document.querySelector('iframe').src = "about:blank";
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* sub_document_3 = RenderFrameHostImpl* sub_document_3 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
EXPECT_EQ(url::kAboutBlankURL, sub_document_3->GetLastCommittedURL()); EXPECT_EQ(url::kAboutBlankURL, sub_document_3->GetLastCommittedURL());
...@@ -3174,10 +3082,9 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) { ...@@ -3174,10 +3082,9 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) {
iframe.src = "data:text/html,"; iframe.src = "data:text/html,";
document.body.appendChild(iframe); document.body.appendChild(iframe);
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* main_document = static_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* main_document = current_frame_host();
shell()->web_contents()->GetMainFrame());
RenderFrameHostImpl* sub_document_1 = RenderFrameHostImpl* sub_document_1 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
EXPECT_EQ("data:text/html,", sub_document_1->GetLastCommittedURL()); EXPECT_EQ("data:text/html,", sub_document_1->GetLastCommittedURL());
...@@ -3187,7 +3094,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) { ...@@ -3187,7 +3094,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) {
// 1. Writing a cookie inside a data-URL document is forbidden. // 1. Writing a cookie inside a data-URL document is forbidden.
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"*Failed to set the 'cookie' property on 'Document': Cookies are " "*Failed to set the 'cookie' property on 'Document': Cookies are "
"disabled inside 'data:' URLs.*"); "disabled inside 'data:' URLs.*");
...@@ -3197,7 +3104,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) { ...@@ -3197,7 +3104,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) {
// 2. Reading a cookie inside a data-URL document is forbidden. // 2. Reading a cookie inside a data-URL document is forbidden.
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"*Failed to read the 'cookie' property from 'Document': Cookies are " "*Failed to read the 'cookie' property from 'Document': Cookies are "
"disabled inside 'data:' URLs.*"); "disabled inside 'data:' URLs.*");
...@@ -3216,9 +3123,9 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) { ...@@ -3216,9 +3123,9 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) {
// 4. Navigate the iframe elsewhere and back using history navigation. // 4. Navigate the iframe elsewhere and back using history navigation.
EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b))); EXPECT_TRUE(ExecJs(sub_document_1, JsReplace("location.href = $1", url_b)));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
shell()->web_contents()->GetController().GoBack(); web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* sub_document_2 = RenderFrameHostImpl* sub_document_2 =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
EXPECT_EQ(url_a, main_document->GetLastCommittedURL()); EXPECT_EQ(url_a, main_document->GetLastCommittedURL());
...@@ -3229,7 +3136,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) { ...@@ -3229,7 +3136,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) {
// 5. Writing a cookie inside a data-URL document is still forbidden. // 5. Writing a cookie inside a data-URL document is still forbidden.
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"*Failed to set the 'cookie' property on 'Document': Cookies are " "*Failed to set the 'cookie' property on 'Document': Cookies are "
"disabled inside 'data:' URLs.*"); "disabled inside 'data:' URLs.*");
...@@ -3239,7 +3146,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) { ...@@ -3239,7 +3146,7 @@ IN_PROC_BROWSER_TEST_F(NavigationCookiesBrowserTest, CookiesInheritedDataUrl) {
// 6. Reading a cookie inside a data-URL document is still forbidden. // 6. Reading a cookie inside a data-URL document is still forbidden.
{ {
WebContentsConsoleObserver console_observer(shell()->web_contents()); WebContentsConsoleObserver console_observer(web_contents());
console_observer.SetPattern( console_observer.SetPattern(
"*Failed to read the 'cookie' property from 'Document': Cookies are " "*Failed to read the 'cookie' property from 'Document': Cookies are "
"disabled inside 'data:' URLs.*"); "disabled inside 'data:' URLs.*");
...@@ -3343,7 +3250,7 @@ IN_PROC_BROWSER_TEST_F(NavigationUrlRewriteBrowserTest, ...@@ -3343,7 +3250,7 @@ IN_PROC_BROWSER_TEST_F(NavigationUrlRewriteBrowserTest,
DISABLE_ON_ANDROID(RewriteToNoAccess)) { DISABLE_ON_ANDROID(RewriteToNoAccess)) {
// Perform an initial navigation. // Perform an initial navigation.
{ {
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
GURL url = embedded_test_server()->GetURL("a.com", "/title1.html"); GURL url = embedded_test_server()->GetURL("a.com", "/title1.html");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ(url, observer.last_navigation_url()); EXPECT_EQ(url, observer.last_navigation_url());
...@@ -3353,16 +3260,14 @@ IN_PROC_BROWSER_TEST_F(NavigationUrlRewriteBrowserTest, ...@@ -3353,16 +3260,14 @@ IN_PROC_BROWSER_TEST_F(NavigationUrlRewriteBrowserTest,
// Navigate to the URL that will get rewritten to a "no access" URL. // Navigate to the URL that will get rewritten to a "no access" URL.
{ {
auto* web_contents = shell()->web_contents(); TestNavigationObserver observer(web_contents());
TestNavigationObserver observer(web_contents);
// Note: We are using LoadURLParams here because we need to have the // Note: We are using LoadURLParams here because we need to have the
// initiator_origin set and NavigateToURL() does not do that. // initiator_origin set and NavigateToURL() does not do that.
NavigationController::LoadURLParams params(GetRewriteToNoAccessURL()); NavigationController::LoadURLParams params(GetRewriteToNoAccessURL());
params.initiator_origin = params.initiator_origin = current_frame_host()->GetLastCommittedOrigin();
web_contents->GetMainFrame()->GetLastCommittedOrigin(); web_contents()->GetController().LoadURLWithParams(params);
web_contents->GetController().LoadURLWithParams(params); web_contents()->Focus();
web_contents->Focus();
observer.Wait(); observer.Wait();
EXPECT_EQ(GURL(kNoAccessURL), observer.last_navigation_url()); EXPECT_EQ(GURL(kNoAccessURL), observer.last_navigation_url());
...@@ -3375,9 +3280,10 @@ IN_PROC_BROWSER_TEST_F(NavigationUrlRewriteBrowserTest, ...@@ -3375,9 +3280,10 @@ IN_PROC_BROWSER_TEST_F(NavigationUrlRewriteBrowserTest,
// page. Regression test https://crbug.com/1018385 // page. Regression test https://crbug.com/1018385
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
SameDocumentNavigationInErrorPage) { SameDocumentNavigationInErrorPage) {
WebContents* wc = shell()->web_contents(); NavigationHandleCommitObserver navigation_0(web_contents(),
NavigationHandleCommitObserver navigation_0(wc, GURL("about:srcdoc#0")); GURL("about:srcdoc#0"));
NavigationHandleCommitObserver navigation_1(wc, GURL("about:srcdoc#1")); NavigationHandleCommitObserver navigation_1(web_contents(),
GURL("about:srcdoc#1"));
// Big warning: about:srcdoc is not supposed to be valid browser-initiated // Big warning: about:srcdoc is not supposed to be valid browser-initiated
// main-frame navigation, it is currently blocked by the NavigationRequest. // main-frame navigation, it is currently blocked by the NavigationRequest.
...@@ -3415,7 +3321,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -3415,7 +3321,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
BrowserURLHandler::GetInstance()->AddHandlerPair( BrowserURLHandler::GetInstance()->AddHandlerPair(
handler_method, BrowserURLHandler::null_handler()); handler_method, BrowserURLHandler::null_handler());
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GURL(embedded_test_server()->GetURL("/virtual-url.html")))); shell(), GURL(embedded_test_server()->GetURL("/virtual-url.html"))));
EXPECT_EQ("/title2.html", observer.last_navigation_url().path()); EXPECT_EQ("/title2.html", observer.last_navigation_url().path());
...@@ -3454,8 +3360,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, ...@@ -3454,8 +3360,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
openee_rfh->GetRoutingID()); openee_rfh->GetRoutingID());
base::RunLoop loop; base::RunLoop loop;
DidStartNavigationCallback callback( DidStartNavigationCallback callback(
shell()->web_contents(), web_contents(), base::BindLambdaForTesting([&](NavigationHandle* handle) {
base::BindLambdaForTesting([&](NavigationHandle* handle) {
auto* request = NavigationRequest::From(handle); auto* request = NavigationRequest::From(handle);
GlobalFrameRoutingId initiator_id = request->GetInitiatorRoutingId(); GlobalFrameRoutingId initiator_id = request->GetInitiatorRoutingId();
ASSERT_EQ(openee_routing_id, initiator_id); ASSERT_EQ(openee_routing_id, initiator_id);
...@@ -3517,8 +3422,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FormSubmissionThenDeleteFrame) { ...@@ -3517,8 +3422,7 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, FormSubmissionThenDeleteFrame) {
initiator_rfh->GetRoutingID()); initiator_rfh->GetRoutingID());
base::RunLoop loop; base::RunLoop loop;
DidStartNavigationCallback callback( DidStartNavigationCallback callback(
shell()->web_contents(), web_contents(), base::BindLambdaForTesting([&](NavigationHandle* handle) {
base::BindLambdaForTesting([&](NavigationHandle* handle) {
auto* request = NavigationRequest::From(handle); auto* request = NavigationRequest::From(handle);
ASSERT_TRUE(request->IsPost()); ASSERT_TRUE(request->IsPost());
...@@ -3578,10 +3482,9 @@ IN_PROC_BROWSER_TEST_F(MediaNavigationBrowserTest, FailedNavigation) { ...@@ -3578,10 +3482,9 @@ IN_PROC_BROWSER_TEST_F(MediaNavigationBrowserTest, FailedNavigation) {
const GURL error_url(embedded_test_server()->GetURL("/moo.mp4")); const GURL error_url(embedded_test_server()->GetURL("/moo.mp4"));
EXPECT_FALSE(NavigateToURL(shell(), error_url)); EXPECT_FALSE(NavigateToURL(shell(), error_url));
EXPECT_EQ(error_url, EXPECT_EQ(error_url, current_frame_host()->GetLastCommittedURL());
shell()->web_contents()->GetMainFrame()->GetLastCommittedURL());
NavigationEntry* entry = NavigationEntry* entry =
shell()->web_contents()->GetController().GetLastCommittedEntry(); web_contents()->GetController().GetLastCommittedEntry();
EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType());
} }
...@@ -3603,9 +3506,8 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3603,9 +3506,8 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
"/target.html"); "/target.html");
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/target.html")); GURL url(embedded_test_server()->GetURL("/target.html"));
WebContents* main_contents = shell()->web_contents(); RenderFrameSubmissionObserver frame_observer(web_contents());
RenderFrameSubmissionObserver frame_observer(main_contents); TestNavigationManager navigation_manager(web_contents(), url);
TestNavigationManager navigation_manager(main_contents, url);
// Load the document with document policy force-load-at-top // Load the document with document policy force-load-at-top
shell()->LoadURL(url); shell()->LoadURL(url);
...@@ -3623,22 +3525,22 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3623,22 +3525,22 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
EXPECT_TRUE(navigation_manager.WaitForResponse()); EXPECT_TRUE(navigation_manager.WaitForResponse());
navigation_manager.ResumeNavigation(); navigation_manager.ResumeNavigation();
navigation_manager.WaitForNavigationFinished(); navigation_manager.WaitForNavigationFinished();
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
// Scroll down the page a bit // Scroll down the page a bit
EXPECT_TRUE(ExecuteScript(main_contents, "window.scrollTo(0, 1000)")); EXPECT_TRUE(ExecuteScript(web_contents(), "window.scrollTo(0, 1000)"));
frame_observer.WaitForScrollOffsetAtTop(false); frame_observer.WaitForScrollOffsetAtTop(false);
// Navigate away // Navigate away
EXPECT_TRUE(ExecuteScript(main_contents, "window.location = 'about:blank'")); EXPECT_TRUE(ExecuteScript(web_contents(), "window.location = 'about:blank'"));
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
// Navigate back // Navigate back
EXPECT_TRUE(ExecuteScript(main_contents, "history.back()")); EXPECT_TRUE(ExecuteScript(web_contents(), "history.back()"));
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
// Wait a short amount of time to ensure the page does not scroll. // Wait a short amount of time to ensure the page does not scroll.
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -3646,9 +3548,9 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3646,9 +3548,9 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
run_loop.Run(); run_loop.Run();
RunUntilInputProcessed(RenderWidgetHostImpl::From( RunUntilInputProcessed(RenderWidgetHostImpl::From(
main_contents->GetRenderViewHost()->GetWidget())); web_contents()->GetRenderViewHost()->GetWidget()));
const cc::RenderFrameMetadata& last_metadata = const cc::RenderFrameMetadata& last_metadata =
RenderFrameSubmissionObserver(main_contents).LastRenderFrameMetadata(); RenderFrameSubmissionObserver(web_contents()).LastRenderFrameMetadata();
EXPECT_TRUE(last_metadata.is_scroll_offset_at_top); EXPECT_TRUE(last_metadata.is_scroll_offset_at_top);
} }
...@@ -3660,9 +3562,8 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3660,9 +3562,8 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
"/target.html"); "/target.html");
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/target.html")); GURL url(embedded_test_server()->GetURL("/target.html"));
WebContents* main_contents = shell()->web_contents(); RenderFrameSubmissionObserver frame_observer(web_contents());
RenderFrameSubmissionObserver frame_observer(main_contents); TestNavigationManager navigation_manager(web_contents(), url);
TestNavigationManager navigation_manager(main_contents, url);
// Load the document with document policy force-load-at-top set to false. // Load the document with document policy force-load-at-top set to false.
shell()->LoadURL(url); shell()->LoadURL(url);
...@@ -3680,27 +3581,27 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3680,27 +3581,27 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
EXPECT_TRUE(navigation_manager.WaitForResponse()); EXPECT_TRUE(navigation_manager.WaitForResponse());
navigation_manager.ResumeNavigation(); navigation_manager.ResumeNavigation();
navigation_manager.WaitForNavigationFinished(); navigation_manager.WaitForNavigationFinished();
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
// Scroll down the page a bit // Scroll down the page a bit
EXPECT_TRUE(ExecuteScript(main_contents, "window.scrollTo(0, 1000)")); EXPECT_TRUE(ExecuteScript(web_contents(), "window.scrollTo(0, 1000)"));
frame_observer.WaitForScrollOffsetAtTop(false); frame_observer.WaitForScrollOffsetAtTop(false);
// Navigate away // Navigate away
EXPECT_TRUE(ExecuteScript(main_contents, "window.location = 'about:blank'")); EXPECT_TRUE(ExecuteScript(web_contents(), "window.location = 'about:blank'"));
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
// Navigate back // Navigate back
EXPECT_TRUE(ExecuteScript(main_contents, "history.back()")); EXPECT_TRUE(ExecuteScript(web_contents(), "history.back()"));
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
// Ensure scroll restoration activated // Ensure scroll restoration activated
frame_observer.WaitForScrollOffsetAtTop(false); frame_observer.WaitForScrollOffsetAtTop(false);
const cc::RenderFrameMetadata& last_metadata = const cc::RenderFrameMetadata& last_metadata =
RenderFrameSubmissionObserver(main_contents).LastRenderFrameMetadata(); RenderFrameSubmissionObserver(web_contents()).LastRenderFrameMetadata();
EXPECT_FALSE(last_metadata.is_scroll_offset_at_top); EXPECT_FALSE(last_metadata.is_scroll_offset_at_top);
} }
...@@ -3713,10 +3614,9 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3713,10 +3614,9 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/target.html#text")); GURL url(embedded_test_server()->GetURL("/target.html#text"));
WebContents* main_contents = shell()->web_contents();
// Load the target document // Load the target document
TestNavigationManager navigation_manager(main_contents, url); TestNavigationManager navigation_manager(web_contents(), url);
shell()->LoadURL(url); shell()->LoadURL(url);
// Start navigation // Start navigation
...@@ -3737,17 +3637,17 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3737,17 +3637,17 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
navigation_manager.ResumeNavigation(); navigation_manager.ResumeNavigation();
navigation_manager.WaitForNavigationFinished(); navigation_manager.WaitForNavigationFinished();
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
// Wait a short amount of time to ensure the page does not scroll. // Wait a short amount of time to ensure the page does not scroll.
base::RunLoop run_loop; base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
run_loop.Run(); run_loop.Run();
RunUntilInputProcessed(RenderWidgetHostImpl::From( RunUntilInputProcessed(RenderWidgetHostImpl::From(
main_contents->GetRenderViewHost()->GetWidget())); web_contents()->GetRenderViewHost()->GetWidget()));
const cc::RenderFrameMetadata& last_metadata = const cc::RenderFrameMetadata& last_metadata =
RenderFrameSubmissionObserver(main_contents).LastRenderFrameMetadata(); RenderFrameSubmissionObserver(web_contents()).LastRenderFrameMetadata();
EXPECT_TRUE(last_metadata.is_scroll_offset_at_top); EXPECT_TRUE(last_metadata.is_scroll_offset_at_top);
} }
...@@ -3760,11 +3660,10 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3760,11 +3660,10 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/target.html#text")); GURL url(embedded_test_server()->GetURL("/target.html#text"));
WebContents* main_contents = shell()->web_contents(); RenderFrameSubmissionObserver frame_observer(web_contents());
RenderFrameSubmissionObserver frame_observer(main_contents);
// Load the target document // Load the target document
TestNavigationManager navigation_manager(main_contents, url); TestNavigationManager navigation_manager(web_contents(), url);
shell()->LoadURL(url); shell()->LoadURL(url);
// Start navigation // Start navigation
...@@ -3785,12 +3684,12 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest, ...@@ -3785,12 +3684,12 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
navigation_manager.ResumeNavigation(); navigation_manager.ResumeNavigation();
navigation_manager.WaitForNavigationFinished(); navigation_manager.WaitForNavigationFinished();
EXPECT_TRUE(WaitForLoadStop(main_contents)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_TRUE(WaitForRenderFrameReady(main_contents->GetMainFrame())); EXPECT_TRUE(WaitForRenderFrameReady(current_frame_host()));
frame_observer.WaitForScrollOffsetAtTop( frame_observer.WaitForScrollOffsetAtTop(
/*expected_scroll_offset_at_top=*/false); /*expected_scroll_offset_at_top=*/false);
const cc::RenderFrameMetadata& last_metadata = const cc::RenderFrameMetadata& last_metadata =
RenderFrameSubmissionObserver(main_contents).LastRenderFrameMetadata(); RenderFrameSubmissionObserver(web_contents()).LastRenderFrameMetadata();
EXPECT_FALSE(last_metadata.is_scroll_offset_at_top); EXPECT_FALSE(last_metadata.is_scroll_offset_at_top);
} }
......
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