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

Cleanup. Use RenderFrameHostBrowserTest::web_contents().

RenderFrameHostImplBrowserTest defines: web_contents().
Tests can uses it, this is shorter and avoid doing many
static_cast everywhere.

This patch updates all the tests. This removes a lot of noise.
This is 97 line shorter and ~50 static_cast are removed.

By updating the whole file, goal is to make others start using it,
instead of copy-pasting the old lines over and over.

Bug: NONE
Change-Id: Id06e69150ace6d9ba70983411c4830cfa4012a43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2396117
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805247}
parent ecd3ac70
...@@ -226,8 +226,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_AtLoad) { ...@@ -226,8 +226,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_AtLoad) {
NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html"))); NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
// The main frame should be focused. // The main frame should be focused.
WebContents* web_contents = shell()->web_contents(); EXPECT_EQ(web_contents()->GetMainFrame(), web_contents()->GetFocusedFrame());
EXPECT_EQ(web_contents->GetMainFrame(), web_contents->GetFocusedFrame());
} }
// Test that if the content changes the focused frame, it is correctly exposed. // Test that if the content changes the focused frame, it is correctly exposed.
...@@ -235,19 +234,18 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_Change) { ...@@ -235,19 +234,18 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_Change) {
EXPECT_TRUE( EXPECT_TRUE(
NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html"))); NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
WebContents* web_contents = shell()->web_contents();
std::string frames[2] = {"frame1", "frame2"}; std::string frames[2] = {"frame1", "frame2"};
for (const std::string& frame : frames) { for (const std::string& frame : frames) {
ExecuteScriptAndGetValue(web_contents->GetMainFrame(), ExecuteScriptAndGetValue(web_contents()->GetMainFrame(),
"focus" + frame + "()"); "focus" + frame + "()");
// The main frame is not the focused frame in the frame tree but the main // The main frame is not the focused frame in the frame tree but the main
// frame is focused per RFHI rules because one of its descendant is focused. // frame is focused per RFHI rules because one of its descendant is focused.
// TODO(mlamouri): we should check the frame focus state per RFHI, see the // TODO(mlamouri): we should check the frame focus state per RFHI, see the
// general comment at the beginning of this test file. // general comment at the beginning of this test file.
EXPECT_NE(web_contents->GetMainFrame(), web_contents->GetFocusedFrame()); EXPECT_NE(web_contents()->GetMainFrame(),
EXPECT_EQ(frame, web_contents->GetFocusedFrame()->GetFrameName()); web_contents()->GetFocusedFrame());
EXPECT_EQ(frame, web_contents()->GetFocusedFrame()->GetFrameName());
} }
} }
...@@ -256,29 +254,26 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, RemoveFocusedFrame) { ...@@ -256,29 +254,26 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, RemoveFocusedFrame) {
EXPECT_TRUE( EXPECT_TRUE(
NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html"))); NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
WebContentsImpl* web_contents = ExecuteScriptAndGetValue(web_contents()->GetMainFrame(), "focusframe4()");
static_cast<WebContentsImpl*>(shell()->web_contents());
ExecuteScriptAndGetValue(web_contents->GetMainFrame(), "focusframe4()");
EXPECT_NE(web_contents->GetMainFrame(), web_contents->GetFocusedFrame()); EXPECT_NE(web_contents()->GetMainFrame(), web_contents()->GetFocusedFrame());
EXPECT_EQ("frame4", web_contents->GetFocusedFrame()->GetFrameName()); EXPECT_EQ("frame4", web_contents()->GetFocusedFrame()->GetFrameName());
EXPECT_EQ("frame3", EXPECT_EQ("frame3",
web_contents->GetFocusedFrame()->GetParent()->GetFrameName()); web_contents()->GetFocusedFrame()->GetParent()->GetFrameName());
EXPECT_NE(-1, web_contents->GetFrameTree()->focused_frame_tree_node_id_); EXPECT_NE(-1, web_contents()->GetFrameTree()->focused_frame_tree_node_id_);
ExecuteScriptAndGetValue(web_contents->GetMainFrame(), "detachframe(3)"); ExecuteScriptAndGetValue(web_contents()->GetMainFrame(), "detachframe(3)");
EXPECT_EQ(nullptr, web_contents->GetFocusedFrame()); EXPECT_EQ(nullptr, web_contents()->GetFocusedFrame());
EXPECT_EQ(-1, web_contents->GetFrameTree()->focused_frame_tree_node_id_); EXPECT_EQ(-1, web_contents()->GetFrameTree()->focused_frame_tree_node_id_);
ExecuteScriptAndGetValue(web_contents->GetMainFrame(), "focusframe2()"); ExecuteScriptAndGetValue(web_contents()->GetMainFrame(), "focusframe2()");
EXPECT_NE(nullptr, web_contents->GetFocusedFrame()); EXPECT_NE(nullptr, web_contents()->GetFocusedFrame());
EXPECT_NE(web_contents->GetMainFrame(), web_contents->GetFocusedFrame()); EXPECT_NE(web_contents()->GetMainFrame(), web_contents()->GetFocusedFrame());
EXPECT_NE(-1, web_contents->GetFrameTree()->focused_frame_tree_node_id_); EXPECT_NE(-1, web_contents()->GetFrameTree()->focused_frame_tree_node_id_);
ExecuteScriptAndGetValue(web_contents->GetMainFrame(), "detachframe(2)"); ExecuteScriptAndGetValue(web_contents()->GetMainFrame(), "detachframe(2)");
EXPECT_EQ(nullptr, web_contents->GetFocusedFrame()); EXPECT_EQ(nullptr, web_contents()->GetFocusedFrame());
EXPECT_EQ(-1, web_contents->GetFrameTree()->focused_frame_tree_node_id_); EXPECT_EQ(-1, web_contents()->GetFrameTree()->focused_frame_tree_node_id_);
} }
// Test that a frame is visible/hidden depending on its WebContents visibility // Test that a frame is visible/hidden depending on its WebContents visibility
...@@ -286,33 +281,31 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, RemoveFocusedFrame) { ...@@ -286,33 +281,31 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, RemoveFocusedFrame) {
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GetVisibilityState_Basic) { GetVisibilityState_Basic) {
EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,foo"))); EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,foo")));
WebContents* web_contents = shell()->web_contents();
web_contents->WasShown(); web_contents()->WasShown();
EXPECT_EQ(PageVisibilityState::kVisible, EXPECT_EQ(PageVisibilityState::kVisible,
web_contents->GetMainFrame()->GetVisibilityState()); web_contents()->GetMainFrame()->GetVisibilityState());
web_contents->WasHidden(); web_contents()->WasHidden();
EXPECT_EQ(PageVisibilityState::kHidden, EXPECT_EQ(PageVisibilityState::kHidden,
web_contents->GetMainFrame()->GetVisibilityState()); web_contents()->GetMainFrame()->GetVisibilityState());
} }
// Test that a frame visibility can be overridden by the ContentBrowserClient. // Test that a frame visibility can be overridden by the ContentBrowserClient.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GetVisibilityState_Override) { GetVisibilityState_Override) {
EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,foo"))); EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,foo")));
WebContents* web_contents = shell()->web_contents();
PrerenderTestContentBrowserClient new_client; PrerenderTestContentBrowserClient new_client;
ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
web_contents->WasShown(); web_contents()->WasShown();
EXPECT_EQ(PageVisibilityState::kVisible, EXPECT_EQ(PageVisibilityState::kVisible,
web_contents->GetMainFrame()->GetVisibilityState()); web_contents()->GetMainFrame()->GetVisibilityState());
new_client.EnableVisibilityOverride(PageVisibilityState::kHiddenButPainting); new_client.EnableVisibilityOverride(PageVisibilityState::kHiddenButPainting);
EXPECT_EQ(PageVisibilityState::kHiddenButPainting, EXPECT_EQ(PageVisibilityState::kHiddenButPainting,
web_contents->GetMainFrame()->GetVisibilityState()); web_contents()->GetMainFrame()->GetVisibilityState());
SetBrowserClientForTesting(old_client); SetBrowserClientForTesting(old_client);
} }
...@@ -323,7 +316,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -323,7 +316,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
URLLoaderFactoryNotTrusted) { URLLoaderFactoryNotTrusted) {
EXPECT_TRUE(NavigateToURL(shell(), embedded_test_server()->GetURL("/echo"))); EXPECT_TRUE(NavigateToURL(shell(), embedded_test_server()->GetURL("/echo")));
mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory; mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory;
shell()->web_contents()->GetMainFrame()->CreateNetworkServiceDefaultFactory( web_contents()->GetMainFrame()->CreateNetworkServiceDefaultFactory(
url_loader_factory.BindNewPipeAndPassReceiver()); url_loader_factory.BindNewPipeAndPassReceiver());
std::unique_ptr<network::ResourceRequest> request = std::unique_ptr<network::ResourceRequest> request =
...@@ -501,9 +494,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -501,9 +494,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
MAYBE_IframeBeforeUnloadParentHang) { MAYBE_IframeBeforeUnloadParentHang) {
RenderFrameHostFactoryForBeforeUnloadInterceptor interceptor; RenderFrameHostFactoryForBeforeUnloadInterceptor interceptor;
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestJavaScriptDialogManager dialog_manager; TestJavaScriptDialogManager dialog_manager;
wc->SetDelegate(&dialog_manager); web_contents()->SetDelegate(&dialog_manager);
EXPECT_TRUE(NavigateToURL(shell(), GURL("about:blank"))); EXPECT_TRUE(NavigateToURL(shell(), GURL("about:blank")));
// Make an iframe with a beforeunload handler. // Make an iframe with a beforeunload handler.
...@@ -511,10 +503,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -511,10 +503,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
"var iframe = document.createElement('iframe');" "var iframe = document.createElement('iframe');"
"document.body.appendChild(iframe);" "document.body.appendChild(iframe);"
"iframe.contentWindow.onbeforeunload=function(e){return 'x'};"; "iframe.contentWindow.onbeforeunload=function(e){return 'x'};";
EXPECT_TRUE(content::ExecuteScript(wc, script)); EXPECT_TRUE(content::ExecuteScript(web_contents(), script));
EXPECT_TRUE(WaitForLoadStop(wc)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// JavaScript onbeforeunload dialogs require a user gesture. // JavaScript onbeforeunload dialogs require a user gesture.
for (auto* frame : wc->GetAllFrames()) for (auto* frame : web_contents()->GetAllFrames())
frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
// Force a process switch by going to a privileged page. The beforeunload // Force a process switch by going to a privileged page. The beforeunload
...@@ -525,8 +517,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -525,8 +517,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
shell()->LoadURL(web_ui_page); shell()->LoadURL(web_ui_page);
dialog_manager.Wait(); dialog_manager.Wait();
RenderFrameHostImpl* main_frame = RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
EXPECT_TRUE(main_frame->is_waiting_for_beforeunload_completion()); EXPECT_TRUE(main_frame->is_waiting_for_beforeunload_completion());
// Answer the dialog. // Answer the dialog.
...@@ -536,63 +527,61 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -536,63 +527,61 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// beforeunload completion callback timer isn't functioning then the // beforeunload completion callback timer isn't functioning then the
// navigation will hang forever and this test will time out. If this waiting // navigation will hang forever and this test will time out. If this waiting
// for the load stop works, this test won't time out. // for the load stop works, this test won't time out.
EXPECT_TRUE(WaitForLoadStop(wc)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_EQ(web_ui_page, wc->GetLastCommittedURL()); EXPECT_EQ(web_ui_page, web_contents()->GetLastCommittedURL());
wc->SetDelegate(nullptr); web_contents()->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr); web_contents()->SetJavaScriptDialogManagerForTesting(nullptr);
} }
// Tests that a gesture is required in a frame before it can request a // Tests that a gesture is required in a frame before it can request a
// beforeunload dialog. // beforeunload dialog.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
BeforeUnloadDialogRequiresGesture) { BeforeUnloadDialogRequiresGesture) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestJavaScriptDialogManager dialog_manager; TestJavaScriptDialogManager dialog_manager;
wc->SetDelegate(&dialog_manager); web_contents()->SetDelegate(&dialog_manager);
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GetTestUrl("render_frame_host", "beforeunload.html"))); shell(), GetTestUrl("render_frame_host", "beforeunload.html")));
// Disable the hang monitor, otherwise there will be a race between the // Disable the hang monitor, otherwise there will be a race between the
// beforeunload dialog and the beforeunload hang timer. // beforeunload dialog and the beforeunload hang timer.
wc->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); web_contents()->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting();
// Reload. There should be no beforeunload dialog because there was no gesture // Reload. There should be no beforeunload dialog because there was no gesture
// on the page. If there was, this WaitForLoadStop call will hang. // on the page. If there was, this WaitForLoadStop call will hang.
wc->GetController().Reload(ReloadType::NORMAL, false); web_contents()->GetController().Reload(ReloadType::NORMAL, false);
EXPECT_TRUE(WaitForLoadStop(wc)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// Give the page a user gesture and try reloading again. This time there // Give the page a user gesture and try reloading again. This time there
// should be a dialog. If there is no dialog, the call to Wait will hang. // should be a dialog. If there is no dialog, the call to Wait will hang.
wc->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests( web_contents()->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
base::string16()); base::string16());
wc->GetController().Reload(ReloadType::NORMAL, false); web_contents()->GetController().Reload(ReloadType::NORMAL, false);
dialog_manager.Wait(); dialog_manager.Wait();
// Answer the dialog. // Answer the dialog.
dialog_manager.Run(true, base::string16()); dialog_manager.Run(true, base::string16());
EXPECT_TRUE(WaitForLoadStop(wc)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// The reload should have cleared the user gesture bit, so upon leaving again // The reload should have cleared the user gesture bit, so upon leaving again
// there should be no beforeunload dialog. // there should be no beforeunload dialog.
shell()->LoadURL(GURL("about:blank")); shell()->LoadURL(GURL("about:blank"));
EXPECT_TRUE(WaitForLoadStop(wc)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
wc->SetDelegate(nullptr); web_contents()->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr); web_contents()->SetJavaScriptDialogManagerForTesting(nullptr);
} }
// Test for crbug.com/80401. Canceling a beforeunload dialog should reset // Test for crbug.com/80401. Canceling a beforeunload dialog should reset
// the URL to the previous page's URL. // the URL to the previous page's URL.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
CancelBeforeUnloadResetsURL) { CancelBeforeUnloadResetsURL) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestJavaScriptDialogManager dialog_manager; TestJavaScriptDialogManager dialog_manager;
wc->SetDelegate(&dialog_manager); web_contents()->SetDelegate(&dialog_manager);
GURL url(GetTestUrl("render_frame_host", "beforeunload.html")); GURL url(GetTestUrl("render_frame_host", "beforeunload.html"));
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
PrepContentsForBeforeUnloadTest(wc); PrepContentsForBeforeUnloadTest(web_contents());
// Navigate to a page that triggers a cross-site transition. // Navigate to a page that triggers a cross-site transition.
GURL url2(embedded_test_server()->GetURL("foo.com", "/title1.html")); GURL url2(embedded_test_server()->GetURL("foo.com", "/title1.html"));
...@@ -602,21 +591,21 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -602,21 +591,21 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// Cancel the dialog. // Cancel the dialog.
dialog_manager.reset_url_invalidate_count(); dialog_manager.reset_url_invalidate_count();
dialog_manager.Run(false, base::string16()); dialog_manager.Run(false, base::string16());
EXPECT_FALSE(wc->IsLoading()); EXPECT_FALSE(web_contents()->IsLoading());
// Verify there are no pending history items after the dialog is cancelled. // Verify there are no pending history items after the dialog is cancelled.
// (see crbug.com/93858) // (see crbug.com/93858)
NavigationEntry* entry = wc->GetController().GetPendingEntry(); NavigationEntry* entry = web_contents()->GetController().GetPendingEntry();
EXPECT_EQ(nullptr, entry); EXPECT_EQ(nullptr, entry);
EXPECT_EQ(url, wc->GetVisibleURL()); EXPECT_EQ(url, web_contents()->GetVisibleURL());
// There should have been at least one NavigationStateChange event for // There should have been at least one NavigationStateChange event for
// invalidating the URL in the address bar, to avoid leaving the stale URL // invalidating the URL in the address bar, to avoid leaving the stale URL
// visible. // visible.
EXPECT_GE(dialog_manager.url_invalidate_count(), 1); EXPECT_GE(dialog_manager.url_invalidate_count(), 1);
wc->SetDelegate(nullptr); web_contents()->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr); web_contents()->SetJavaScriptDialogManagerForTesting(nullptr);
} }
// Helper class for beforunload tests. Sets up a custom dialog manager for the // Helper class for beforunload tests. Sets up a custom dialog manager for the
...@@ -630,10 +619,6 @@ class RenderFrameHostImplBeforeUnloadBrowserTest ...@@ -630,10 +619,6 @@ class RenderFrameHostImplBeforeUnloadBrowserTest
public: public:
RenderFrameHostImplBeforeUnloadBrowserTest() {} RenderFrameHostImplBeforeUnloadBrowserTest() {}
WebContentsImpl* web_contents() {
return static_cast<WebContentsImpl*>(shell()->web_contents());
}
TestJavaScriptDialogManager* dialog_manager() { TestJavaScriptDialogManager* dialog_manager() {
return dialog_manager_.get(); return dialog_manager_.get();
} }
...@@ -1239,7 +1224,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, POSTNavigation) { ...@@ -1239,7 +1224,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, POSTNavigation) {
GURL post_url = http_server.GetURL("/echotitle"); GURL post_url = http_server.GetURL("/echotitle");
// Navigate to a page with a form. // Navigate to a page with a form.
TestNavigationObserver observer(shell()->web_contents()); TestNavigationObserver observer(web_contents());
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());
...@@ -1250,9 +1235,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, POSTNavigation) { ...@@ -1250,9 +1235,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, POSTNavigation) {
NavigateToURL(shell(), submit_url, post_url /* expected_commit_url */)); NavigateToURL(shell(), submit_url, post_url /* expected_commit_url */));
// Check that a proper POST navigation was done. // Check that a proper POST navigation was done.
EXPECT_EQ("text=&select=a", EXPECT_EQ("text=&select=a", base::UTF16ToASCII(web_contents()->GetTitle()));
base::UTF16ToASCII(shell()->web_contents()->GetTitle())); EXPECT_EQ(post_url, web_contents()->GetLastCommittedURL());
EXPECT_EQ(post_url, shell()->web_contents()->GetLastCommittedURL());
EXPECT_TRUE(shell() EXPECT_TRUE(shell()
->web_contents() ->web_contents()
->GetController() ->GetController()
...@@ -1260,10 +1244,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, POSTNavigation) { ...@@ -1260,10 +1244,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, POSTNavigation) {
->GetHasPostData()); ->GetHasPostData());
// Reload and verify the form was submitted. // Reload and verify the form was submitted.
shell()->web_contents()->GetController().Reload(ReloadType::NORMAL, false); web_contents()->GetController().Reload(ReloadType::NORMAL, false);
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
EXPECT_EQ("text=&select=a", EXPECT_EQ("text=&select=a", base::UTF16ToASCII(web_contents()->GetTitle()));
base::UTF16ToASCII(shell()->web_contents()->GetTitle()));
CHECK_EQ(2, post_counter); CHECK_EQ(2, post_counter);
} }
...@@ -1321,22 +1304,21 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FastNavigationAbort) { ...@@ -1321,22 +1304,21 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FastNavigationAbort) {
// ensure that we won't trigger a same-site cross-RFH navigation. // ensure that we won't trigger a same-site cross-RFH navigation.
// TODO(crbug.com/1099193): This should also work on cross-RFH same-site // TODO(crbug.com/1099193): This should also work on cross-RFH same-site
// navigations. // navigations.
DisableProactiveBrowsingInstanceSwapFor( DisableProactiveBrowsingInstanceSwapFor(web_contents()->GetMainFrame());
shell()->web_contents()->GetMainFrame());
// Now make a navigation. |observer| will make a document.open() call at // Now make a navigation. |observer| will make a document.open() call at
// ReadyToCommit time - see // ReadyToCommit time - see
// NavigationHandleGrabber::SendingNavigationCommitted(). The navigation // NavigationHandleGrabber::SendingNavigationCommitted(). The navigation
// should get aborted because of the document.open() in the navigating RFH. // should get aborted because of the document.open() in the navigating RFH.
NavigationHandleGrabber observer(shell()->web_contents()); NavigationHandleGrabber observer(web_contents());
const base::string16 title = base::ASCIIToUTF16("done"); const base::string16 title = base::ASCIIToUTF16("done");
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), EXPECT_TRUE(
"window.location.href='/title2.html'")); ExecuteScript(web_contents(), "window.location.href='/title2.html'"));
observer.WaitForTitle2(); observer.WaitForTitle2();
// Flush IPCs to make sure the renderer didn't tell us to navigate. Need to // Flush IPCs to make sure the renderer didn't tell us to navigate. Need to
// make two round trips. // make two round trips.
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), "")); EXPECT_TRUE(ExecuteScript(web_contents(), ""));
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), "")); EXPECT_TRUE(ExecuteScript(web_contents(), ""));
EXPECT_FALSE(observer.committed_title2()); EXPECT_FALSE(observer.committed_title2());
} }
...@@ -1344,11 +1326,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -1344,11 +1326,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
TerminationDisablersClearedOnRendererCrash) { TerminationDisablersClearedOnRendererCrash) {
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GetTestUrl("render_frame_host", "beforeunload.html"))); shell(), GetTestUrl("render_frame_host", "beforeunload.html")));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); RenderFrameHostImpl* main_rfh1 = web_contents()->GetMainFrame();
RenderFrameHostImpl* main_rfh1 =
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
EXPECT_TRUE(main_rfh1->GetSuddenTerminationDisablerState( EXPECT_TRUE(main_rfh1->GetSuddenTerminationDisablerState(
blink::mojom::SuddenTerminationDisablerType::kBeforeUnloadHandler)); blink::mojom::SuddenTerminationDisablerType::kBeforeUnloadHandler));
...@@ -1365,11 +1345,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -1365,11 +1345,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// This should not trigger a DCHECK once the renderer sends up the termination // This should not trigger a DCHECK once the renderer sends up the termination
// disabler flags. // disabler flags.
shell()->web_contents()->GetController().Reload(ReloadType::NORMAL, false); web_contents()->GetController().Reload(ReloadType::NORMAL, false);
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
RenderFrameHostImpl* main_rfh2 = RenderFrameHostImpl* main_rfh2 = web_contents()->GetMainFrame();
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
EXPECT_TRUE(main_rfh2->GetSuddenTerminationDisablerState( EXPECT_TRUE(main_rfh2->GetSuddenTerminationDisablerState(
blink::mojom::SuddenTerminationDisablerType::kBeforeUnloadHandler)); blink::mojom::SuddenTerminationDisablerType::kBeforeUnloadHandler));
} }
...@@ -1617,10 +1596,10 @@ class ScopedFakeInterfaceBrokerRequestInjector ...@@ -1617,10 +1596,10 @@ class ScopedFakeInterfaceBrokerRequestInjector
class ScopedInterfaceRequestMonitor class ScopedInterfaceRequestMonitor
: public blink::mojom::BrowserInterfaceBrokerInterceptorForTesting { : public blink::mojom::BrowserInterfaceBrokerInterceptorForTesting {
public: public:
ScopedInterfaceRequestMonitor(RenderFrameHost* render_frame_host, ScopedInterfaceRequestMonitor(RenderFrameHostImpl* render_frame_host,
base::StringPiece interface_name, base::StringPiece interface_name,
base::RepeatingClosure callback) base::RepeatingClosure callback)
: rfhi_(static_cast<RenderFrameHostImpl*>(render_frame_host)), : rfhi_(render_frame_host),
impl_(receiver().SwapImplForTesting(this)), impl_(receiver().SwapImplForTesting(this)),
interface_name_(interface_name), interface_name_(interface_name),
request_callback_(callback) {} request_callback_(callback) {}
...@@ -1694,7 +1673,6 @@ class DidFinishNavigationObserver : public WebContentsObserver { ...@@ -1694,7 +1673,6 @@ class DidFinishNavigationObserver : public WebContentsObserver {
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
RenderFrameHostImplBrowserTest, RenderFrameHostImplBrowserTest,
EarlyInterfaceRequestsFromNewDocumentDispatchedAfterNavigationFinished) { EarlyInterfaceRequestsFromNewDocumentDispatchedAfterNavigationFinished) {
WebContents* web_contents = shell()->web_contents();
const GURL first_url(embedded_test_server()->GetURL("/title1.html")); const GURL first_url(embedded_test_server()->GetURL("/title1.html"));
const GURL second_url(embedded_test_server()->GetURL("/title2.html")); const GURL second_url(embedded_test_server()->GetURL("/title2.html"));
...@@ -1716,7 +1694,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1716,7 +1694,7 @@ IN_PROC_BROWSER_TEST_F(
// Replace the |interface_broker_receiver| argument in the next // Replace the |interface_broker_receiver| argument in the next
// DidCommitProvisionalLoad message coming from the renderer with the // DidCommitProvisionalLoad message coming from the renderer with the
// rigged |interface_broker_with_pending_requests| from above. // rigged |interface_broker_with_pending_requests| from above.
ScopedFakeInterfaceBrokerRequestInjector injector(web_contents); ScopedFakeInterfaceBrokerRequestInjector injector(web_contents());
injector.set_fake_receiver_for_next_commit( injector.set_fake_receiver_for_next_commit(
std::move(interface_broker_receiver_with_pending_receiver)); std::move(interface_broker_receiver_with_pending_receiver));
...@@ -1726,11 +1704,12 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1726,11 +1704,12 @@ IN_PROC_BROWSER_TEST_F(
bool did_finish_navigation = false; bool did_finish_navigation = false;
// Start the same-process navigation. // Start the same-process navigation.
TestNavigationManager navigation_manager(web_contents, second_url); TestNavigationManager navigation_manager(web_contents(), second_url);
shell()->LoadURL(second_url); shell()->LoadURL(second_url);
EXPECT_TRUE(navigation_manager.WaitForResponse()); EXPECT_TRUE(navigation_manager.WaitForResponse());
auto* committing_rfh = auto* committing_rfh =
navigation_manager.GetNavigationHandle()->GetRenderFrameHost(); NavigationRequest::From(navigation_manager.GetNavigationHandle())
->GetRenderFrameHost();
DidFinishNavigationObserver navigation_finish_observer( DidFinishNavigationObserver navigation_finish_observer(
committing_rfh, base::BindLambdaForTesting([&did_finish_navigation]() { committing_rfh, base::BindLambdaForTesting([&did_finish_navigation]() {
...@@ -1780,7 +1759,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -1780,7 +1759,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// |interface_broker_receiver| from above, whose client end is controlled by // |interface_broker_receiver| from above, whose client end is controlled by
// this test; then trigger a navigation. // this test; then trigger a navigation.
{ {
ScopedFakeInterfaceBrokerRequestInjector injector(shell()->web_contents()); ScopedFakeInterfaceBrokerRequestInjector injector(web_contents());
injector.set_fake_receiver_for_next_commit( injector.set_fake_receiver_for_next_commit(
std::move(interface_broker_receiver)); std::move(interface_broker_receiver));
...@@ -1791,8 +1770,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -1791,8 +1770,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// The test below only works for same-RFH navigations, so we need to ensure // The test below only works for same-RFH navigations, so we need to ensure
// that we won't trigger a same-site cross-RFH navigation. // that we won't trigger a same-site cross-RFH navigation.
DisableProactiveBrowsingInstanceSwapFor( DisableProactiveBrowsingInstanceSwapFor(web_contents()->GetMainFrame());
shell()->web_contents()->GetMainFrame());
// Prepare an interface receiver for FrameHostTestInterface. // Prepare an interface receiver for FrameHostTestInterface.
mojo::Remote<mojom::FrameHostTestInterface> test_interface; mojo::Remote<mojom::FrameHostTestInterface> test_interface;
...@@ -1803,7 +1781,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -1803,7 +1781,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// RenderFrameHostImpl. // RenderFrameHostImpl.
base::MockCallback<base::RepeatingClosure> base::MockCallback<base::RepeatingClosure>
dispatched_interface_request_callback; dispatched_interface_request_callback;
auto* main_rfh = shell()->web_contents()->GetMainFrame(); auto* main_rfh = web_contents()->GetMainFrame();
ScopedInterfaceRequestMonitor monitor( ScopedInterfaceRequestMonitor monitor(
main_rfh, mojom::FrameHostTestInterface::Name_, main_rfh, mojom::FrameHostTestInterface::Name_,
dispatched_interface_request_callback.Get()); dispatched_interface_request_callback.Get());
...@@ -1871,7 +1849,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -1871,7 +1849,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
ASSERT_TRUE(NavigateToURL(shell(), main_frame_url)); ASSERT_TRUE(NavigateToURL(shell(), main_frame_url));
ScopedFakeInterfaceBrokerRequestInjector injector(shell()->web_contents()); ScopedFakeInterfaceBrokerRequestInjector injector(web_contents());
injector.set_fake_receiver_for_next_commit( injector.set_fake_receiver_for_next_commit(
std::move(*interface_broker_receiver)); std::move(*interface_broker_receiver));
...@@ -1888,11 +1866,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -1888,11 +1866,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
subframe_url.spec().c_str()); subframe_url.spec().c_str());
ASSERT_TRUE(ExecuteScript(shell(), script)); ASSERT_TRUE(ExecuteScript(shell(), script));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* root = web_contents()->GetFrameTree()->root();
->GetFrameTree()
->root();
ASSERT_EQ(1u, root->child_count()); ASSERT_EQ(1u, root->child_count());
FrameTreeNode* child = root->child_at(0u); FrameTreeNode* child = root->child_at(0u);
...@@ -1943,11 +1919,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1943,11 +1919,9 @@ IN_PROC_BROWSER_TEST_F(
// empty document regardless of when/how/if the `src` attribute is set. // empty document regardless of when/how/if the `src` attribute is set.
ASSERT_TRUE(ExecuteScript(shell(), kNavigateToOneThenTwoScript)); ASSERT_TRUE(ExecuteScript(shell(), kNavigateToOneThenTwoScript));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* root = web_contents()->GetFrameTree()->root();
->GetFrameTree()
->root();
ASSERT_EQ(1u, root->child_count()); ASSERT_EQ(1u, root->child_count());
FrameTreeNode* child = root->child_at(0u); FrameTreeNode* child = root->child_at(0u);
...@@ -1958,7 +1932,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1958,7 +1932,7 @@ IN_PROC_BROWSER_TEST_F(
// Set the `src` attribute again to trigger navigation (3). // Set the `src` attribute again to trigger navigation (3).
TestFrameNavigationObserver commit_observer(child->current_frame_host()); TestFrameNavigationObserver commit_observer(child->current_frame_host());
ScopedFakeInterfaceBrokerRequestInjector injector(shell()->web_contents()); ScopedFakeInterfaceBrokerRequestInjector injector(web_contents());
injector.set_fake_receiver_for_next_commit(mojo::NullReceiver()); injector.set_fake_receiver_for_next_commit(mojo::NullReceiver());
ASSERT_TRUE(ExecuteScript(shell(), kNavigateToThreeScript)); ASSERT_TRUE(ExecuteScript(shell(), kNavigateToThreeScript));
...@@ -2001,9 +1975,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2001,9 +1975,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// Main frame navigation. // Main frame navigation.
ASSERT_TRUE(NavigateToURL(shell(), main_frame_url)); ASSERT_TRUE(NavigateToURL(shell(), main_frame_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* root = web_contents()->GetFrameTree()->root();
->GetFrameTree()
->root();
CheckURLOriginAndNetworkIsolationKey(root, main_frame_url, main_frame_origin, CheckURLOriginAndNetworkIsolationKey(root, main_frame_url, main_frame_origin,
expected_main_frame_key); expected_main_frame_key);
...@@ -2013,7 +1985,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2013,7 +1985,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
f.id = 'myiframe'; f.id = 'myiframe';
document.body.append(f); document.body.append(f);
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
ASSERT_EQ(1u, root->child_count()); ASSERT_EQ(1u, root->child_count());
FrameTreeNode* child = root->child_at(0u); FrameTreeNode* child = root->child_at(0u);
...@@ -2028,7 +2000,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2028,7 +2000,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
iframe.contentWindow.location.hash = 'foo'; iframe.contentWindow.location.hash = 'foo';
)")); )"));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
CheckURLOriginAndNetworkIsolationKey( CheckURLOriginAndNetworkIsolationKey(
child, subframe_url_two, main_frame_origin, expected_main_frame_key); child, subframe_url_two, main_frame_origin, expected_main_frame_key);
...@@ -2071,20 +2043,17 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2071,20 +2043,17 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// Main frame navigation. // Main frame navigation.
ASSERT_TRUE(NavigateToURL(shell(), main_frame_url)); ASSERT_TRUE(NavigateToURL(shell(), main_frame_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* root = web_contents()->GetFrameTree()->root();
->GetFrameTree()
->root();
CheckURLOriginAndNetworkIsolationKey(root, main_frame_url, main_frame_origin, CheckURLOriginAndNetworkIsolationKey(root, main_frame_url, main_frame_origin,
expected_main_frame_key); expected_main_frame_key);
// Create popup. // Create popup.
WebContentsAddedObserver popup_observer; WebContentsAddedObserver popup_observer;
ASSERT_TRUE(ExecuteScript(shell(), "var w = window.open('');")); ASSERT_TRUE(ExecuteScript(shell(), "var w = window.open('');"));
WebContents* popup = popup_observer.GetWebContents(); WebContentsImpl* popup =
static_cast<WebContentsImpl*>(popup_observer.GetWebContents());
FrameTreeNode* popup_frame = FrameTreeNode* popup_frame = popup->GetMainFrame()->frame_tree_node();
static_cast<RenderFrameHostImpl*>(popup->GetMainFrame())
->frame_tree_node();
CheckURLOriginAndNetworkIsolationKey( CheckURLOriginAndNetworkIsolationKey(
popup_frame, popup_url_one, main_frame_origin, expected_main_frame_key); popup_frame, popup_url_one, main_frame_origin, expected_main_frame_key);
EXPECT_EQ(root->current_frame_host()->GetProcess(), EXPECT_EQ(root->current_frame_host()->GetProcess(),
...@@ -2125,9 +2094,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2125,9 +2094,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
net::NetworkIsolationKey(origin, origin); net::NetworkIsolationKey(origin, origin);
ASSERT_TRUE(NavigateToURL(shell(), main_frame_url)); ASSERT_TRUE(NavigateToURL(shell(), main_frame_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* root = web_contents()->GetFrameTree()->root();
->GetFrameTree()
->root();
CheckURLOriginAndNetworkIsolationKey(root, main_frame_url, origin, CheckURLOriginAndNetworkIsolationKey(root, main_frame_url, origin,
expected_network_isolation_key); expected_network_isolation_key);
ASSERT_EQ(1u, root->child_count()); ASSERT_EQ(1u, root->child_count());
...@@ -2186,9 +2153,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2186,9 +2153,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
main_frame_origin, main_frame_origin); main_frame_origin, main_frame_origin);
ASSERT_TRUE(NavigateToURL(shell(), main_frame_url)); ASSERT_TRUE(NavigateToURL(shell(), main_frame_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* root = web_contents()->GetFrameTree()->root();
->GetFrameTree()
->root();
CheckURLOriginAndNetworkIsolationKey( CheckURLOriginAndNetworkIsolationKey(
root, main_frame_url, main_frame_origin, root, main_frame_url, main_frame_origin,
expected_main_frame_network_isolation_key); expected_main_frame_network_isolation_key);
...@@ -2253,9 +2218,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2253,9 +2218,7 @@ IN_PROC_BROWSER_TEST_F(
main_frame_origin, main_frame_origin); main_frame_origin, main_frame_origin);
ASSERT_TRUE(NavigateToURL(shell(), main_frame_url)); ASSERT_TRUE(NavigateToURL(shell(), main_frame_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) FrameTreeNode* root = web_contents()->GetFrameTree()->root();
->GetFrameTree()
->root();
CheckURLOriginAndNetworkIsolationKey( CheckURLOriginAndNetworkIsolationKey(
root, main_frame_url, main_frame_origin, root, main_frame_url, main_frame_origin,
expected_main_frame_network_isolation_key); expected_main_frame_network_isolation_key);
...@@ -2280,7 +2243,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2280,7 +2243,7 @@ IN_PROC_BROWSER_TEST_F(
// The middle iframe navigates the innermost iframe to about:blank. It should // The middle iframe navigates the innermost iframe to about:blank. It should
// then have the same NetworkIsolationKey as the middle iframe. // then have the same NetworkIsolationKey as the middle iframe.
TestNavigationObserver nav_observer1(shell()->web_contents()); TestNavigationObserver nav_observer1(web_contents());
ASSERT_TRUE(ExecJs( ASSERT_TRUE(ExecJs(
middle_iframe->current_frame_host(), middle_iframe->current_frame_host(),
"var iframe = " "var iframe = "
...@@ -2295,7 +2258,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2295,7 +2258,7 @@ IN_PROC_BROWSER_TEST_F(
// The innermost iframe, now at about:blank, navigates itself back its // The innermost iframe, now at about:blank, navigates itself back its
// original location, which should make it use c.test's NIK again. // original location, which should make it use c.test's NIK again.
TestNavigationObserver nav_observer2(shell()->web_contents()); TestNavigationObserver nav_observer2(web_contents());
ASSERT_TRUE( ASSERT_TRUE(
ExecJs(innermost_iframe->current_frame_host(), "window.history.back();")); ExecJs(innermost_iframe->current_frame_host(), "window.history.back();"));
nav_observer2.WaitForNavigationFinished(); nav_observer2.WaitForNavigationFinished();
...@@ -2310,7 +2273,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2310,7 +2273,7 @@ IN_PROC_BROWSER_TEST_F(
// Despite c.test initiating the navigation, the iframe should be using // Despite c.test initiating the navigation, the iframe should be using
// b.test's NIK, since the navigation entry was created by a navigation // b.test's NIK, since the navigation entry was created by a navigation
// initiated by b.test. // initiated by b.test.
TestNavigationObserver nav_observer3(shell()->web_contents()); TestNavigationObserver nav_observer3(web_contents());
ASSERT_TRUE(ExecJs(innermost_iframe->current_frame_host(), ASSERT_TRUE(ExecJs(innermost_iframe->current_frame_host(),
"window.history.forward();")); "window.history.forward();"));
nav_observer3.WaitForNavigationFinished(); nav_observer3.WaitForNavigationFinished();
...@@ -2344,7 +2307,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2344,7 +2307,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
base::RunLoop wait_until_connection_error_loop_2; base::RunLoop wait_until_connection_error_loop_2;
{ {
ScopedFakeInterfaceBrokerRequestInjector injector(shell()->web_contents()); ScopedFakeInterfaceBrokerRequestInjector injector(web_contents());
injector.set_fake_receiver_for_next_commit( injector.set_fake_receiver_for_next_commit(
interface_broker_1.BindNewPipeAndPassReceiver()); interface_broker_1.BindNewPipeAndPassReceiver());
interface_broker_1.set_disconnect_handler( interface_broker_1.set_disconnect_handler(
...@@ -2354,11 +2317,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2354,11 +2317,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// The test below only makes sense for same-RFH navigations, so we need to // The test below only makes sense for same-RFH navigations, so we need to
// ensure that we won't trigger a same-site cross-RFH navigation. // ensure that we won't trigger a same-site cross-RFH navigation.
DisableProactiveBrowsingInstanceSwapFor( DisableProactiveBrowsingInstanceSwapFor(web_contents()->GetMainFrame());
shell()->web_contents()->GetMainFrame());
{ {
ScopedFakeInterfaceBrokerRequestInjector injector(shell()->web_contents()); ScopedFakeInterfaceBrokerRequestInjector injector(web_contents());
injector.set_fake_receiver_for_next_commit( injector.set_fake_receiver_for_next_commit(
interface_broker_2.BindNewPipeAndPassReceiver()); interface_broker_2.BindNewPipeAndPassReceiver());
interface_broker_2.set_disconnect_handler( interface_broker_2.set_disconnect_handler(
...@@ -2424,11 +2386,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2424,11 +2386,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GetCanonicalUrlAfterRendererCrash) { GetCanonicalUrlAfterRendererCrash) {
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GetTestUrl("render_frame_host", "beforeunload.html"))); shell(), GetTestUrl("render_frame_host", "beforeunload.html")));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
RenderFrameHostImpl* main_frame =
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
// Make the renderer crash. // Make the renderer crash.
RenderProcessHost* renderer_process = main_frame->GetProcess(); RenderProcessHost* renderer_process = main_frame->GetProcess();
...@@ -2451,9 +2411,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2451,9 +2411,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GURL blocked_url(embedded_test_server()->GetURL( GURL blocked_url(embedded_test_server()->GetURL(
"blocked.com", "/frame-ancestors-none.html")); "blocked.com", "/frame-ancestors-none.html"));
WebContents* web_contents = shell()->web_contents(); NavigationHandleObserver navigation_observer(web_contents(), blocked_url);
NavigationHandleObserver navigation_observer(web_contents, blocked_url); EXPECT_TRUE(NavigateIframeToURL(web_contents(), "child0", blocked_url));
EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", blocked_url));
// Verify that the NavigationHandle / NavigationRequest didn't leak. // Verify that the NavigationHandle / NavigationRequest didn't leak.
RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(
...@@ -2479,53 +2438,51 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2479,53 +2438,51 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
BeforeUnloadDialogSuppressedForDiscard) { BeforeUnloadDialogSuppressedForDiscard) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestJavaScriptDialogManager dialog_manager; TestJavaScriptDialogManager dialog_manager;
wc->SetDelegate(&dialog_manager); web_contents()->SetDelegate(&dialog_manager);
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GetTestUrl("render_frame_host", "beforeunload.html"))); shell(), GetTestUrl("render_frame_host", "beforeunload.html")));
// Disable the hang monitor, otherwise there will be a race between the // Disable the hang monitor, otherwise there will be a race between the
// beforeunload dialog and the beforeunload hang timer. // beforeunload dialog and the beforeunload hang timer.
wc->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); web_contents()->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting();
// Give the page a user gesture so javascript beforeunload works, and then // Give the page a user gesture so javascript beforeunload works, and then
// dispatch a before unload with discard as a reason. This should return // dispatch a before unload with discard as a reason. This should return
// without any dialog being seen. // without any dialog being seen.
wc->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests( web_contents()->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
base::string16()); base::string16());
wc->GetMainFrame()->DispatchBeforeUnload( web_contents()->GetMainFrame()->DispatchBeforeUnload(
RenderFrameHostImpl::BeforeUnloadType::DISCARD, false); RenderFrameHostImpl::BeforeUnloadType::DISCARD, false);
dialog_manager.Wait(); dialog_manager.Wait();
EXPECT_EQ(0, dialog_manager.num_beforeunload_dialogs_seen()); EXPECT_EQ(0, dialog_manager.num_beforeunload_dialogs_seen());
EXPECT_EQ(1, dialog_manager.num_beforeunload_fired_seen()); EXPECT_EQ(1, dialog_manager.num_beforeunload_fired_seen());
EXPECT_FALSE(dialog_manager.proceed()); EXPECT_FALSE(dialog_manager.proceed());
wc->SetDelegate(nullptr); web_contents()->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr); web_contents()->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
PendingDialogMakesDiscardUnloadReturnFalse) { PendingDialogMakesDiscardUnloadReturnFalse) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestJavaScriptDialogManager dialog_manager; TestJavaScriptDialogManager dialog_manager;
wc->SetDelegate(&dialog_manager); web_contents()->SetDelegate(&dialog_manager);
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GetTestUrl("render_frame_host", "beforeunload.html"))); shell(), GetTestUrl("render_frame_host", "beforeunload.html")));
// Disable the hang monitor, otherwise there will be a race between the // Disable the hang monitor, otherwise there will be a race between the
// beforeunload dialog and the beforeunload hang timer. // beforeunload dialog and the beforeunload hang timer.
wc->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); web_contents()->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting();
// Give the page a user gesture so javascript beforeunload works, and then // Give the page a user gesture so javascript beforeunload works, and then
// dispatch a before unload with discard as a reason. This should return // dispatch a before unload with discard as a reason. This should return
// without any dialog being seen. // without any dialog being seen.
wc->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests( web_contents()->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
base::string16()); base::string16());
// Launch an alert javascript dialog. This pending dialog should block a // Launch an alert javascript dialog. This pending dialog should block a
// subsequent discarding before unload request. // subsequent discarding before unload request.
wc->GetMainFrame()->ExecuteJavaScriptForTests( web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
base::ASCIIToUTF16("setTimeout(function(){alert('hello');}, 10);"), base::ASCIIToUTF16("setTimeout(function(){alert('hello');}, 10);"),
base::NullCallback()); base::NullCallback());
dialog_manager.Wait(); dialog_manager.Wait();
...@@ -2534,7 +2491,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2534,7 +2491,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// Dispatch a before unload request while the first is still blocked // Dispatch a before unload request while the first is still blocked
// on the dialog, and expect it to return false immediately (synchronously). // on the dialog, and expect it to return false immediately (synchronously).
wc->GetMainFrame()->DispatchBeforeUnload( web_contents()->GetMainFrame()->DispatchBeforeUnload(
RenderFrameHostImpl::BeforeUnloadType::DISCARD, false); RenderFrameHostImpl::BeforeUnloadType::DISCARD, false);
dialog_manager.Wait(); dialog_manager.Wait();
EXPECT_EQ(0, dialog_manager.num_beforeunload_dialogs_seen()); EXPECT_EQ(0, dialog_manager.num_beforeunload_dialogs_seen());
...@@ -2545,8 +2502,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2545,8 +2502,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// doesn't leak. // doesn't leak.
dialog_manager.Run(true, base::string16()); dialog_manager.Run(true, base::string16());
wc->SetDelegate(nullptr); web_contents()->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr); web_contents()->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
...@@ -2562,10 +2519,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2562,10 +2519,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// renderer. Any document will do. // renderer. Any document will do.
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GetTestUrl("render_frame_host", "beforeunload.html"))); shell(), GetTestUrl("render_frame_host", "beforeunload.html")));
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); EXPECT_TRUE(WaitForLoadStop(web_contents()));
auto* frame = static_cast<RenderFrameHostImpl*>( auto* frame = web_contents()->GetMainFrame();
shell()->web_contents()->GetMainFrame());
auto* process = static_cast<RenderProcessHostImpl*>(frame->GetProcess()); auto* process = static_cast<RenderProcessHostImpl*>(frame->GetProcess());
ASSERT_EQ(0, process->get_media_stream_count_for_testing()); ASSERT_EQ(0, process->get_media_stream_count_for_testing());
...@@ -2602,15 +2558,12 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2602,15 +2558,12 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// state. // state.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
MAYBE_VisibilityScrolledOutOfView) { MAYBE_VisibilityScrolledOutOfView) {
WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());
GURL main_frame(embedded_test_server()->GetURL("/iframe_out_of_view.html")); GURL main_frame(embedded_test_server()->GetURL("/iframe_out_of_view.html"));
GURL child_url(embedded_test_server()->GetURL("/hello.html")); GURL child_url(embedded_test_server()->GetURL("/hello.html"));
// This will set up the page frame tree as A(A1()). // This will set up the page frame tree as A(A1()).
ASSERT_TRUE(NavigateToURL(shell(), main_frame)); ASSERT_TRUE(NavigateToURL(shell(), main_frame));
FrameTreeNode* root = web_contents->GetFrameTree()->root(); FrameTreeNode* root = web_contents()->GetFrameTree()->root();
FrameTreeNode* nested_iframe_node = root->child_at(0); FrameTreeNode* nested_iframe_node = root->child_at(0);
NavigateFrameToURL(nested_iframe_node, child_url); NavigateFrameToURL(nested_iframe_node, child_url);
...@@ -2621,15 +2574,12 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2621,15 +2574,12 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// Test that a frame is visible/hidden depending on its WebContents visibility // Test that a frame is visible/hidden depending on its WebContents visibility
// state. // state.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, VisibilityChildInView) { IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, VisibilityChildInView) {
WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());
GURL main_frame(embedded_test_server()->GetURL("/iframe_clipped.html")); GURL main_frame(embedded_test_server()->GetURL("/iframe_clipped.html"));
GURL child_url(embedded_test_server()->GetURL("/hello.html")); GURL child_url(embedded_test_server()->GetURL("/hello.html"));
// This will set up the page frame tree as A(A1()). // This will set up the page frame tree as A(A1()).
ASSERT_TRUE(NavigateToURL(shell(), main_frame)); ASSERT_TRUE(NavigateToURL(shell(), main_frame));
FrameTreeNode* root = web_contents->GetFrameTree()->root(); FrameTreeNode* root = web_contents()->GetFrameTree()->root();
FrameTreeNode* nested_iframe_node = root->child_at(0); FrameTreeNode* nested_iframe_node = root->child_at(0);
NavigateFrameToURL(nested_iframe_node, child_url); NavigateFrameToURL(nested_iframe_node, child_url);
...@@ -2639,8 +2589,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, VisibilityChildInView) { ...@@ -2639,8 +2589,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, VisibilityChildInView) {
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
OriginOfFreshFrame_Subframe_NavCancelledByDocWrite) { OriginOfFreshFrame_Subframe_NavCancelledByDocWrite) {
WebContents* web_contents = shell()->web_contents(); NavigationController& controller = web_contents()->GetController();
NavigationController& controller = web_contents->GetController();
GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
ASSERT_TRUE(NavigateToURL(shell(), main_url)); ASSERT_TRUE(NavigateToURL(shell(), main_url));
EXPECT_EQ(1, controller.GetEntryCount()); EXPECT_EQ(1, controller.GetEntryCount());
...@@ -2663,7 +2612,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2663,7 +2612,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
)"; )";
GURL cross_site_url(embedded_test_server()->GetURL("bar.com", "/hung")); GURL cross_site_url(embedded_test_server()->GetURL("bar.com", "/hung"));
std::string script = JsReplace(kScriptTemplate, cross_site_url); std::string script = JsReplace(kScriptTemplate, cross_site_url);
EXPECT_EQ(main_origin.Serialize(), EvalJs(web_contents, script)); EXPECT_EQ(main_origin.Serialize(), EvalJs(web_contents(), script));
// The subframe navigation should be cancelled and therefore shouldn't // The subframe navigation should be cancelled and therefore shouldn't
// contribute an extra history entry. // contribute an extra history entry.
...@@ -2671,8 +2620,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2671,8 +2620,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// Browser-side origin should match the renderer-side origin. // Browser-side origin should match the renderer-side origin.
// See also https://crbug.com/932067. // See also https://crbug.com/932067.
ASSERT_EQ(2u, web_contents->GetAllFrames().size()); ASSERT_EQ(2u, web_contents()->GetAllFrames().size());
RenderFrameHost* subframe = web_contents->GetAllFrames()[1]; RenderFrameHost* subframe = web_contents()->GetAllFrames()[1];
EXPECT_EQ(main_origin, subframe->GetLastCommittedOrigin()); EXPECT_EQ(main_origin, subframe->GetLastCommittedOrigin());
} }
...@@ -2702,15 +2651,14 @@ class RenderFrameHostCreatedObserver : public WebContentsObserver { ...@@ -2702,15 +2651,14 @@ class RenderFrameHostCreatedObserver : public WebContentsObserver {
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
OriginOfFreshFrame_SandboxedSubframe) { OriginOfFreshFrame_SandboxedSubframe) {
WebContents* web_contents = shell()->web_contents(); NavigationController& controller = web_contents()->GetController();
NavigationController& controller = web_contents->GetController();
GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
ASSERT_TRUE(NavigateToURL(shell(), main_url)); ASSERT_TRUE(NavigateToURL(shell(), main_url));
EXPECT_EQ(1, controller.GetEntryCount()); EXPECT_EQ(1, controller.GetEntryCount());
url::Origin main_origin = url::Origin::Create(main_url); url::Origin main_origin = url::Origin::Create(main_url);
// Navigate a sandboxed frame to a cross-origin '/hung'. // Navigate a sandboxed frame to a cross-origin '/hung'.
RenderFrameHostCreatedObserver subframe_observer(web_contents); RenderFrameHostCreatedObserver subframe_observer(web_contents());
const char kScriptTemplate[] = R"( const char kScriptTemplate[] = R"(
const frame = document.createElement('iframe'); const frame = document.createElement('iframe');
frame.sandbox = 'allow-scripts'; frame.sandbox = 'allow-scripts';
...@@ -2719,13 +2667,13 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2719,13 +2667,13 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
)"; )";
GURL cross_site_url(embedded_test_server()->GetURL("bar.com", "/hung")); GURL cross_site_url(embedded_test_server()->GetURL("bar.com", "/hung"));
std::string script = JsReplace(kScriptTemplate, cross_site_url); std::string script = JsReplace(kScriptTemplate, cross_site_url);
EXPECT_TRUE(ExecJs(web_contents, script)); EXPECT_TRUE(ExecJs(web_contents(), script));
// Wait for a new subframe, but ignore the frame returned by // Wait for a new subframe, but ignore the frame returned by
// |subframe_observer| (it might be the speculative one, not the current one). // |subframe_observer| (it might be the speculative one, not the current one).
subframe_observer.Wait(); subframe_observer.Wait();
ASSERT_EQ(2u, web_contents->GetAllFrames().size()); ASSERT_EQ(2u, web_contents()->GetAllFrames().size());
RenderFrameHost* subframe = web_contents->GetAllFrames()[1]; RenderFrameHost* subframe = web_contents()->GetAllFrames()[1];
// The browser-side origin of the *sandboxed* subframe should be set to an // The browser-side origin of the *sandboxed* subframe should be set to an
// *opaque* origin (with the parent's origin as the precursor origin). // *opaque* origin (with the parent's origin as the precursor origin).
...@@ -2741,16 +2689,15 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2741,16 +2689,15 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
OriginOfFreshFrame_Subframe_AboutBlankAndThenDocWrite) { OriginOfFreshFrame_Subframe_AboutBlankAndThenDocWrite) {
WebContents* web_contents = shell()->web_contents(); NavigationController& controller = web_contents()->GetController();
NavigationController& controller = web_contents->GetController();
GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
ASSERT_TRUE(NavigateToURL(shell(), main_url)); ASSERT_TRUE(NavigateToURL(shell(), main_url));
EXPECT_EQ(1, controller.GetEntryCount()); EXPECT_EQ(1, controller.GetEntryCount());
url::Origin main_origin = url::Origin::Create(main_url); url::Origin main_origin = url::Origin::Create(main_url);
// Create a new about:blank subframe and document.write into it. // Create a new about:blank subframe and document.write into it.
TestNavigationObserver load_observer(web_contents); TestNavigationObserver load_observer(web_contents());
RenderFrameHostCreatedObserver subframe_observer(web_contents); RenderFrameHostCreatedObserver subframe_observer(web_contents());
const char kScript[] = R"( const char kScript[] = R"(
const frame = document.createElement('iframe'); const frame = document.createElement('iframe');
// Don't set |frame.src| - have the frame commit an initial about:blank. // Don't set |frame.src| - have the frame commit an initial about:blank.
...@@ -2762,7 +2709,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2762,7 +2709,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
doc.write(html); doc.write(html);
doc.close(); doc.close();
)"; )";
ExecuteScriptAsync(web_contents, kScript); ExecuteScriptAsync(web_contents(), kScript);
// Wait for the new subframe to be created - this will be still before the // Wait for the new subframe to be created - this will be still before the
// commit of about:blank. // commit of about:blank.
...@@ -2778,8 +2725,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2778,8 +2725,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// Browser-side origin should match the renderer-side origin. // Browser-side origin should match the renderer-side origin.
// See also https://crbug.com/932067. // See also https://crbug.com/932067.
ASSERT_EQ(2u, web_contents->GetAllFrames().size()); ASSERT_EQ(2u, web_contents()->GetAllFrames().size());
RenderFrameHost* subframe2 = web_contents->GetAllFrames()[1]; RenderFrameHost* subframe2 = web_contents()->GetAllFrames()[1];
EXPECT_EQ(subframe, subframe2); // No swaps are expected. EXPECT_EQ(subframe, subframe2); // No swaps are expected.
EXPECT_EQ(main_origin, subframe2->GetLastCommittedOrigin()); EXPECT_EQ(main_origin, subframe2->GetLastCommittedOrigin());
EXPECT_EQ(main_origin.Serialize(), EvalJs(subframe2, "window.origin")); EXPECT_EQ(main_origin.Serialize(), EvalJs(subframe2, "window.origin"));
...@@ -2787,7 +2734,6 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2787,7 +2734,6 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
OriginOfFreshFrame_Popup_NavCancelledByDocWrite) { OriginOfFreshFrame_Popup_NavCancelledByDocWrite) {
WebContents* web_contents = shell()->web_contents();
GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
ASSERT_TRUE(NavigateToURL(shell(), main_url)); ASSERT_TRUE(NavigateToURL(shell(), main_url));
url::Origin main_origin = url::Origin::Create(main_url); url::Origin main_origin = url::Origin::Create(main_url);
...@@ -2808,7 +2754,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2808,7 +2754,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
)"; )";
GURL cross_site_url(embedded_test_server()->GetURL("bar.com", "/hung")); GURL cross_site_url(embedded_test_server()->GetURL("bar.com", "/hung"));
std::string script = JsReplace(kScriptTemplate, cross_site_url); std::string script = JsReplace(kScriptTemplate, cross_site_url);
EXPECT_EQ(main_origin.Serialize(), EvalJs(web_contents, script)); EXPECT_EQ(main_origin.Serialize(), EvalJs(web_contents(), script));
// Browser-side origin should match the renderer-side origin. // Browser-side origin should match the renderer-side origin.
// See also https://crbug.com/932067. // See also https://crbug.com/932067.
...@@ -2822,14 +2768,13 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2822,14 +2768,13 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
OriginOfFreshFrame_Popup_AboutBlankAndThenDocWrite) { OriginOfFreshFrame_Popup_AboutBlankAndThenDocWrite) {
WebContents* web_contents = shell()->web_contents();
GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); GURL main_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
ASSERT_TRUE(NavigateToURL(shell(), main_url)); ASSERT_TRUE(NavigateToURL(shell(), main_url));
url::Origin main_origin = url::Origin::Create(main_url); url::Origin main_origin = url::Origin::Create(main_url);
// Create a new about:blank popup and document.write into it. // Create a new about:blank popup and document.write into it.
WebContentsAddedObserver popup_observer; WebContentsAddedObserver popup_observer;
TestNavigationObserver load_observer(web_contents); TestNavigationObserver load_observer(web_contents());
const char kScript[] = R"( const char kScript[] = R"(
// Empty |url| argument means that the popup will commit an initial // Empty |url| argument means that the popup will commit an initial
// about:blank. // about:blank.
...@@ -2841,7 +2786,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2841,7 +2786,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
doc.write(html); doc.write(html);
doc.close(); doc.close();
)"; )";
ExecuteScriptAsync(web_contents, kScript); ExecuteScriptAsync(web_contents(), kScript);
// Wait for the new popup to be created (this will be before the popup commits // Wait for the new popup to be created (this will be before the popup commits
// the initial about:blank page). // the initial about:blank page).
...@@ -2865,8 +2810,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2865,8 +2810,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
embedded_test_server()->GetURL("foo.com", "/page_with_iframe.html")); embedded_test_server()->GetURL("foo.com", "/page_with_iframe.html"));
ASSERT_TRUE(NavigateToURL(shell(), main_url)); ASSERT_TRUE(NavigateToURL(shell(), main_url));
RenderFrameHostImpl* main_frame = static_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
shell()->web_contents()->GetMainFrame());
EXPECT_TRUE(main_frame->AccessibilityIsMainFrame()); EXPECT_TRUE(main_frame->AccessibilityIsMainFrame());
ASSERT_EQ(1u, main_frame->child_count()); ASSERT_EQ(1u, main_frame->child_count());
...@@ -2877,8 +2821,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2877,8 +2821,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
RequestSnapshotAXTreeAfterRenderProcessHostDeath) { RequestSnapshotAXTreeAfterRenderProcessHostDeath) {
EXPECT_TRUE(NavigateToURL(shell(), GURL(url::kAboutBlankURL))); EXPECT_TRUE(NavigateToURL(shell(), GURL(url::kAboutBlankURL)));
auto* rfh = static_cast<RenderFrameHostImpl*>( auto* rfh = web_contents()->GetMainFrame();
shell()->web_contents()->GetMainFrame());
// Kill the renderer process. // Kill the renderer process.
RenderProcessHostWatcher crash_observer( RenderProcessHostWatcher crash_observer(
...@@ -2909,14 +2852,12 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2909,14 +2852,12 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
URLLoaderInterceptor::SetupRequestFailForURL(object_url, URLLoaderInterceptor::SetupRequestFailForURL(object_url,
net::ERR_BLOCKED_BY_CLIENT); net::ERR_BLOCKED_BY_CLIENT);
auto* rfh = static_cast<RenderFrameHostImpl*>( auto* rfh = web_contents()->GetMainFrame();
shell()->web_contents()->GetMainFrame()); TestNavigationObserver observer(web_contents());
TestNavigationObserver observer(shell()->web_contents()); EXPECT_TRUE(ExecJs(rfh, JsReplace("setUrl($1, true);", object_url)));
EXPECT_TRUE(ExecJs(shell()->web_contents(),
JsReplace("setUrl($1, true);", object_url)));
observer.Wait(); observer.Wait();
EXPECT_EQ(rfh->GetLastCommittedOrigin().Serialize(), EXPECT_EQ(rfh->GetLastCommittedOrigin().Serialize(),
EvalJs(shell()->web_contents(), "window.origin")); EvalJs(web_contents(), "window.origin"));
} }
// Regression test for crbug.com/953934. It shouldn't crash if we quickly remove // Regression test for crbug.com/953934. It shouldn't crash if we quickly remove
...@@ -2927,8 +2868,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2927,8 +2868,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
FILE_PATH_LITERAL("remove_object_element_with_invalid_data.html")); FILE_PATH_LITERAL("remove_object_element_with_invalid_data.html"));
RenderProcessHostWatcher crash_observer( RenderProcessHostWatcher crash_observer(
shell()->web_contents(), web_contents(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
// This navigates to a page with an object element that will fail to load. // This navigates to a page with an object element that will fail to load.
// When document load event hits, it'll attempt to remove that object element. // When document load event hits, it'll attempt to remove that object element.
...@@ -2937,8 +2877,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2937,8 +2877,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// soon, let's wait until the document.readyState finalizes. We don't really // soon, let's wait until the document.readyState finalizes. We don't really
// care if that succeeds since, in the failing case, the renderer is crashing. // care if that succeeds since, in the failing case, the renderer is crashing.
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
ignore_result( ignore_result(WaitForRenderFrameReady(web_contents()->GetMainFrame()));
WaitForRenderFrameReady(shell()->web_contents()->GetMainFrame()));
EXPECT_TRUE(crash_observer.did_exit_normally()); EXPECT_TRUE(crash_observer.did_exit_normally());
} }
...@@ -2947,8 +2886,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2947,8 +2886,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
SchedulerTrackedFeatures) { SchedulerTrackedFeatures) {
EXPECT_TRUE( EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"))); NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
RenderFrameHostImpl* main_frame = reinterpret_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
shell()->web_contents()->GetMainFrame());
// Simulate getting 0b1 as a feature vector from the renderer. // Simulate getting 0b1 as a feature vector from the renderer.
static_cast<blink::mojom::LocalFrameHost*>(main_frame) static_cast<blink::mojom::LocalFrameHost*>(main_frame)
->DidChangeActiveSchedulerTrackedFeatures(0b1u); ->DidChangeActiveSchedulerTrackedFeatures(0b1u);
...@@ -2968,10 +2906,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2968,10 +2906,8 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// like "document loaded" will show up here. // like "document loaded" will show up here.
EXPECT_TRUE( EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/title2.html"))); NavigateToURL(shell(), embedded_test_server()->GetURL("/title2.html")));
main_frame = reinterpret_cast<RenderFrameHostImpl*>( main_frame = web_contents()->GetMainFrame();
shell()->web_contents()->GetMainFrame()); main_frame->DidChangeActiveSchedulerTrackedFeatures(0b0u);
static_cast<blink::mojom::LocalFrameHost*>(main_frame)
->DidChangeActiveSchedulerTrackedFeatures(0b0u);
} }
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
...@@ -2992,9 +2928,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -2992,9 +2928,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
{ {
WebContentsImpl* wc = RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderFrameHostImpl* main_frame = wc->GetMainFrame();
EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host()); EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host());
ASSERT_EQ(2u, main_frame->child_count()); ASSERT_EQ(2u, main_frame->child_count());
...@@ -3085,10 +3019,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3085,10 +3019,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GURL trusty_url(kTrustMeUrl); GURL trusty_url(kTrustMeUrl);
EXPECT_TRUE(NavigateToURL(shell(), trusty_url)); EXPECT_TRUE(NavigateToURL(shell(), trusty_url));
{ {
WebContentsImpl* wc = RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderFrameHostImpl* main_frame =
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
EXPECT_EQ(trusty_url.GetOrigin(), EXPECT_EQ(trusty_url.GetOrigin(),
main_frame->GetLastCommittedURL().GetOrigin()); main_frame->GetLastCommittedURL().GetOrigin());
...@@ -3150,10 +3081,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3150,10 +3081,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GURL trusty_if_secure_url(kTrustMeIfEmbeddingSecureUrl); GURL trusty_if_secure_url(kTrustMeIfEmbeddingSecureUrl);
EXPECT_TRUE(NavigateToURL(shell(), trusty_if_secure_url)); EXPECT_TRUE(NavigateToURL(shell(), trusty_if_secure_url));
{ {
WebContentsImpl* wc = RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderFrameHostImpl* main_frame =
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
EXPECT_EQ(trusty_if_secure_url.GetOrigin(), EXPECT_EQ(trusty_if_secure_url.GetOrigin(),
main_frame->GetLastCommittedURL().GetOrigin()); main_frame->GetLastCommittedURL().GetOrigin());
...@@ -3233,9 +3161,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3233,9 +3161,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GURL other_url = https_server()->GetURL("c.test", "/"); GURL other_url = https_server()->GetURL("c.test", "/");
EXPECT_TRUE(NavigateToURL(shell(), insecure_url)); EXPECT_TRUE(NavigateToURL(shell(), insecure_url));
{ {
WebContentsImpl* wc = RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderFrameHostImpl* main_frame = wc->GetMainFrame();
EXPECT_EQ("a.test", main_frame->GetLastCommittedURL().host()); EXPECT_EQ("a.test", main_frame->GetLastCommittedURL().host());
EXPECT_EQ("http", main_frame->frame_tree_node()->current_origin().scheme()); EXPECT_EQ("http", main_frame->frame_tree_node()->current_origin().scheme());
...@@ -3311,9 +3237,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3311,9 +3237,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
WebContentsImpl* wc = RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderFrameHostImpl* main_frame = wc->GetMainFrame();
EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host()); EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host());
...@@ -3361,9 +3285,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3361,9 +3285,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
embedded_test_server()->GetURL("a.com", "/csp_sandboxed_frame.html"); embedded_test_server()->GetURL("a.com", "/csp_sandboxed_frame.html");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
WebContentsImpl* wc = RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderFrameHostImpl* main_frame = wc->GetMainFrame();
EXPECT_EQ(url, main_frame->GetLastCommittedURL()); EXPECT_EQ(url, main_frame->GetLastCommittedURL());
EXPECT_TRUE(main_frame->GetLastCommittedOrigin().opaque()); EXPECT_TRUE(main_frame->GetLastCommittedOrigin().opaque());
...@@ -3388,8 +3310,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -3388,8 +3310,7 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
RenderFrameHostImpl* main_frame = wc->GetMainFrame();
EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host()); EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host());
...@@ -3421,9 +3342,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3421,9 +3342,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
RenderFrameHostImpl* main_frame =
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host()); EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host());
ASSERT_EQ(1u, main_frame->child_count()); ASSERT_EQ(1u, main_frame->child_count());
...@@ -3476,9 +3395,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3476,9 +3395,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
GURL subframe_url = GetFileURL(FILE_PATH_LITERAL("title1.html")); GURL subframe_url = GetFileURL(FILE_PATH_LITERAL("title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), main_frame_url)); EXPECT_TRUE(NavigateToURL(shell(), main_frame_url));
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
RenderFrameHostImpl* main_frame =
static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
EXPECT_EQ(main_frame_url, main_frame->GetLastCommittedURL()); EXPECT_EQ(main_frame_url, main_frame->GetLastCommittedURL());
EXPECT_TRUE(net::SiteForCookies::FromUrl(GURL("file:///")) EXPECT_TRUE(net::SiteForCookies::FromUrl(GURL("file:///"))
.IsEquivalent(main_frame->ComputeSiteForCookies())); .IsEquivalent(main_frame->ComputeSiteForCookies()));
...@@ -3499,8 +3416,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3499,8 +3416,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); RenderFrameHostImpl* main_frame = web_contents()->GetMainFrame();
RenderFrameHostImpl* main_frame = wc->GetMainFrame();
EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host()); EXPECT_EQ("a.com", main_frame->GetLastCommittedURL().host());
...@@ -3547,7 +3463,6 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3547,7 +3463,6 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// particular, after https://crbug.com/981339, a different RenderFrameHost will // particular, after https://crbug.com/981339, a different RenderFrameHost will
// be used for reloading the file. File access must be correctly granted. // be used for reloading the file. File access must be correctly granted.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FileReloadAfterCrash) { IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FileReloadAfterCrash) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
// 1. Navigate a local file with an iframe. // 1. Navigate a local file with an iframe.
GURL main_frame_url = GetFileURL(FILE_PATH_LITERAL("page_with_iframe.html")); GURL main_frame_url = GetFileURL(FILE_PATH_LITERAL("page_with_iframe.html"));
...@@ -3555,18 +3470,18 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FileReloadAfterCrash) { ...@@ -3555,18 +3470,18 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FileReloadAfterCrash) {
EXPECT_TRUE(NavigateToURL(shell(), main_frame_url)); EXPECT_TRUE(NavigateToURL(shell(), main_frame_url));
// 2. Crash. // 2. Crash.
RenderProcessHost* process = wc->GetMainFrame()->GetProcess(); RenderProcessHost* process = web_contents()->GetMainFrame()->GetProcess();
RenderProcessHostWatcher crash_observer( RenderProcessHostWatcher crash_observer(
process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
process->Shutdown(0); process->Shutdown(0);
crash_observer.Wait(); crash_observer.Wait();
// 3. Reload. // 3. Reload.
wc->GetController().Reload(ReloadType::NORMAL, false); web_contents()->GetController().Reload(ReloadType::NORMAL, false);
EXPECT_TRUE(WaitForLoadStop(wc)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// Check the document is correctly reloaded. // Check the document is correctly reloaded.
RenderFrameHostImpl* main_document = wc->GetMainFrame(); RenderFrameHostImpl* main_document = web_contents()->GetMainFrame();
ASSERT_EQ(1u, main_document->child_count()); ASSERT_EQ(1u, main_document->child_count());
RenderFrameHostImpl* sub_document = RenderFrameHostImpl* sub_document =
main_document->child_at(0)->current_frame_host(); main_document->child_at(0)->current_frame_host();
...@@ -3580,26 +3495,24 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FileReloadAfterCrash) { ...@@ -3580,26 +3495,24 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, FileReloadAfterCrash) {
// Make sure a webui can be reloaded after a crash. // Make sure a webui can be reloaded after a crash.
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, WebUiReloadAfterCrash) { IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, WebUiReloadAfterCrash) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
// 1. Navigate a local file with an iframe. // 1. Navigate a local file with an iframe.
GURL main_frame_url(std::string(kChromeUIScheme) + "://" + GURL main_frame_url(std::string(kChromeUIScheme) + "://" +
std::string(kChromeUIGpuHost)); std::string(kChromeUIGpuHost));
EXPECT_TRUE(NavigateToURL(shell(), main_frame_url)); EXPECT_TRUE(NavigateToURL(shell(), main_frame_url));
// 2. Crash. // 2. Crash.
RenderProcessHost* process = wc->GetMainFrame()->GetProcess(); RenderProcessHost* process = web_contents()->GetMainFrame()->GetProcess();
RenderProcessHostWatcher crash_observer( RenderProcessHostWatcher crash_observer(
process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
process->Shutdown(0); process->Shutdown(0);
crash_observer.Wait(); crash_observer.Wait();
// 3. Reload. // 3. Reload.
wc->GetController().Reload(ReloadType::NORMAL, false); web_contents()->GetController().Reload(ReloadType::NORMAL, false);
EXPECT_TRUE(WaitForLoadStop(wc)); EXPECT_TRUE(WaitForLoadStop(web_contents()));
// Check the document is correctly reloaded. // Check the document is correctly reloaded.
RenderFrameHostImpl* main_document = wc->GetMainFrame(); RenderFrameHostImpl* main_document = web_contents()->GetMainFrame();
EXPECT_EQ(main_frame_url, main_document->GetLastCommittedURL()); EXPECT_EQ(main_frame_url, main_document->GetLastCommittedURL());
// Execute script in an isolated world to avoid causing a Trusted Types // Execute script in an isolated world to avoid causing a Trusted Types
// violation due to eval. // violation due to eval.
...@@ -3670,7 +3583,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3670,7 +3583,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
LeaveInPendingDeletionState(rfh_a); LeaveInPendingDeletionState(rfh_a);
// 3) Start navigation to B, but don't commit yet. // 3) Start navigation to B, but don't commit yet.
TestNavigationManager manager(shell()->web_contents(), url_b); TestNavigationManager manager(web_contents(), url_b);
shell()->LoadURL(url_b); shell()->LoadURL(url_b);
EXPECT_TRUE(manager.WaitForRequestStart()); EXPECT_TRUE(manager.WaitForRequestStart());
...@@ -3782,7 +3695,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3782,7 +3695,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
crash_observer.Wait(); crash_observer.Wait();
// 3) Start navigation to B, but don't commit yet. // 3) Start navigation to B, but don't commit yet.
TestNavigationManager manager(shell()->web_contents(), url_b); TestNavigationManager manager(web_contents(), url_b);
shell()->LoadURL(url_b); shell()->LoadURL(url_b);
EXPECT_TRUE(manager.WaitForRequestStart()); EXPECT_TRUE(manager.WaitForRequestStart());
...@@ -3813,8 +3726,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -3813,8 +3726,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
// sure the second navigation will not be cross-process. // sure the second navigation will not be cross-process.
ASSERT_TRUE(NavigateToURL(shell(), first_url)); ASSERT_TRUE(NavigateToURL(shell(), first_url));
RenderFrameHostImpl* main_rfh = RenderFrameHostImpl* main_rfh = web_contents()->GetMainFrame();
static_cast<RenderFrameHostImpl*>(web_contents()->GetMainFrame());
EXPECT_TRUE(main_rfh->DocumentUsedWebOTP()); EXPECT_TRUE(main_rfh->DocumentUsedWebOTP());
ASSERT_TRUE(NavigateToURL(shell(), second_url)); ASSERT_TRUE(NavigateToURL(shell(), second_url));
...@@ -3878,8 +3790,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -3878,8 +3790,7 @@ IN_PROC_BROWSER_TEST_F(
for (auto test : test_cases) { for (auto test : test_cases) {
SCOPED_TRACE(test.url); SCOPED_TRACE(test.url);
EXPECT_TRUE(NavigateToURL(shell(), test.url)); EXPECT_TRUE(NavigateToURL(shell(), test.url));
RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>( RenderFrameHostImpl* rfhi = web_contents()->GetMainFrame();
shell()->web_contents()->GetMainFrame());
EXPECT_EQ(test.expected_internal, EXPECT_EQ(test.expected_internal,
rfhi->last_committed_client_security_state()->ip_address_space); rfhi->last_committed_client_security_state()->ip_address_space);
EXPECT_EQ(test.expected_web_facing, EvalJs(rfhi, "document.addressSpace")); EXPECT_EQ(test.expected_web_facing, EvalJs(rfhi, "document.addressSpace"));
...@@ -3891,7 +3802,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -3891,7 +3802,7 @@ IN_PROC_BROWSER_TEST_F(
ComputeIFrameLoopbackIPAddressSpace) { ComputeIFrameLoopbackIPAddressSpace) {
{ {
base::string16 expected_title(base::UTF8ToUTF16("LOADED")); base::string16 expected_title(base::UTF8ToUTF16("LOADED"));
TitleWatcher title_watcher(shell()->web_contents(), expected_title); TitleWatcher title_watcher(web_contents(), expected_title);
EXPECT_TRUE( EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL( NavigateToURL(shell(), embedded_test_server()->GetURL(
"/do-not-treat-as-public-address.html"))); "/do-not-treat-as-public-address.html")));
...@@ -3940,13 +3851,12 @@ IN_PROC_BROWSER_TEST_F( ...@@ -3940,13 +3851,12 @@ IN_PROC_BROWSER_TEST_F(
// `filesystem:`, `about:blank`, and `about:srcdoc` all inherit the assertion. // `filesystem:`, `about:blank`, and `about:srcdoc` all inherit the assertion.
{ {
base::string16 expected_title(base::UTF8ToUTF16("LOADED")); base::string16 expected_title(base::UTF8ToUTF16("LOADED"));
TitleWatcher title_watcher(shell()->web_contents(), expected_title); TitleWatcher title_watcher(web_contents(), expected_title);
EXPECT_TRUE(NavigateToURL(shell(), embedded_test_server()->GetURL( EXPECT_TRUE(NavigateToURL(shell(), embedded_test_server()->GetURL(
"/treat-as-public-address.html"))); "/treat-as-public-address.html")));
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
std::vector<RenderFrameHost*> frames = std::vector<RenderFrameHost*> frames = web_contents()->GetAllFrames();
shell()->web_contents()->GetAllFrames();
for (auto* frame : frames) { for (auto* frame : frames) {
auto* rfhi = static_cast<RenderFrameHostImpl*>(frame); auto* rfhi = static_cast<RenderFrameHostImpl*>(frame);
if (frame->GetLastCommittedURL().IsAboutBlank()) { if (frame->GetLastCommittedURL().IsAboutBlank()) {
...@@ -4389,8 +4299,7 @@ IN_PROC_BROWSER_TEST_F(ContentBrowserTest, LoadingStateResetOnNavigation) { ...@@ -4389,8 +4299,7 @@ IN_PROC_BROWSER_TEST_F(ContentBrowserTest, LoadingStateResetOnNavigation) {
"Content-Type: text/html; charset=utf-8\r\n" "Content-Type: text/html; charset=utf-8\r\n"
"\r\n"); "\r\n");
navigation_observer.WaitForNavigationFinished(); navigation_observer.WaitForNavigationFinished();
EXPECT_FALSE(static_cast<RenderFrameHostImpl*>(web_contents->GetMainFrame()) EXPECT_FALSE(web_contents->GetMainFrame()->IsDOMContentLoaded());
->IsDOMContentLoaded());
EXPECT_FALSE(web_contents->IsDocumentOnLoadCompletedInMainFrame()); EXPECT_FALSE(web_contents->IsDocumentOnLoadCompletedInMainFrame());
} }
...@@ -4597,12 +4506,11 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -4597,12 +4506,11 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
RemoteObjectEnumerateProperties) { RemoteObjectEnumerateProperties) {
GURL url(embedded_test_server()->GetURL("/empty.html")); GURL url(embedded_test_server()->GetURL("/empty.html"));
WebContents* web_contents = shell()->web_contents(); RemoteObjectInjector injector(web_contents());
RemoteObjectInjector injector(web_contents);
SetupRemoteObjectInvocation(shell(), url); SetupRemoteObjectInvocation(shell(), url);
std::string kScript = "Object.keys(testObject).join(' ');"; std::string kScript = "Object.keys(testObject).join(' ');";
auto result = EvalJs(web_contents, kScript); auto result = EvalJs(web_contents(), kScript);
EXPECT_EQ(base::JoinString(kMainObject.methods, " "), EXPECT_EQ(base::JoinString(kMainObject.methods, " "),
result.value.GetString()); result.value.GetString());
} }
...@@ -4611,36 +4519,33 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -4611,36 +4519,33 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
RemoteObjectInvokeNonexistentMethod) { RemoteObjectInvokeNonexistentMethod) {
GURL url(embedded_test_server()->GetURL("/empty.html")); GURL url(embedded_test_server()->GetURL("/empty.html"));
WebContents* web_contents = shell()->web_contents(); RemoteObjectInjector injector(web_contents());
RemoteObjectInjector injector(web_contents);
SetupRemoteObjectInvocation(shell(), url); SetupRemoteObjectInvocation(shell(), url);
std::string kScript = "testObject.getInnerId();"; std::string kScript = "testObject.getInnerId();";
EXPECT_FALSE(EvalJs(web_contents, kScript).error.empty()); EXPECT_FALSE(EvalJs(web_contents(), kScript).error.empty());
} }
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
RemoteObjectInvokeMethodReturningNumber) { RemoteObjectInvokeMethodReturningNumber) {
GURL url(embedded_test_server()->GetURL("/empty.html")); GURL url(embedded_test_server()->GetURL("/empty.html"));
WebContents* web_contents = shell()->web_contents(); RemoteObjectInjector injector(web_contents());
RemoteObjectInjector injector(web_contents);
SetupRemoteObjectInvocation(shell(), url); SetupRemoteObjectInvocation(shell(), url);
std::string kScript = "testObject.getId();"; std::string kScript = "testObject.getId();";
EXPECT_EQ(kMainObject.id, EvalJs(web_contents, kScript)); EXPECT_EQ(kMainObject.id, EvalJs(web_contents(), kScript));
} }
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
RemoteObjectInvokeMethodTakingArray) { RemoteObjectInvokeMethodTakingArray) {
GURL url(embedded_test_server()->GetURL("/empty.html")); GURL url(embedded_test_server()->GetURL("/empty.html"));
WebContents* web_contents = shell()->web_contents(); RemoteObjectInjector injector(web_contents());
RemoteObjectInjector injector(web_contents);
SetupRemoteObjectInvocation(shell(), url); SetupRemoteObjectInvocation(shell(), url);
std::string kScript = "testObject.readArray([6, 8, 2]);"; std::string kScript = "testObject.readArray([6, 8, 2]);";
EXPECT_TRUE(EvalJs(web_contents, kScript).error.empty()); EXPECT_TRUE(EvalJs(web_contents(), kScript).error.empty());
EXPECT_EQ( EXPECT_EQ(
3, injector.GetObjectHost().GetMockObject()->get_num_elements_received()); 3, injector.GetObjectHost().GetMockObject()->get_num_elements_received());
} }
...@@ -4649,20 +4554,18 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -4649,20 +4554,18 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
RemoteObjectInvokeMethodReturningObject) { RemoteObjectInvokeMethodReturningObject) {
GURL url(embedded_test_server()->GetURL("/empty.html")); GURL url(embedded_test_server()->GetURL("/empty.html"));
WebContents* web_contents = shell()->web_contents(); RemoteObjectInjector injector(web_contents());
RemoteObjectInjector injector(web_contents);
SetupRemoteObjectInvocation(shell(), url); SetupRemoteObjectInvocation(shell(), url);
std::string kScript = "testObject.getInnerObject().getInnerId();"; std::string kScript = "testObject.getInnerObject().getInnerId();";
EXPECT_EQ(kInnerObject.id, EvalJs(web_contents, kScript)); EXPECT_EQ(kInnerObject.id, EvalJs(web_contents(), kScript));
} }
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
RemoteObjectInvokeMethodException) { RemoteObjectInvokeMethodException) {
GURL url(embedded_test_server()->GetURL("/empty.html")); GURL url(embedded_test_server()->GetURL("/empty.html"));
WebContents* web_contents = shell()->web_contents(); RemoteObjectInjector injector(web_contents());
RemoteObjectInjector injector(web_contents);
SetupRemoteObjectInvocation(shell(), url); SetupRemoteObjectInvocation(shell(), url);
std::string error_message = "hahaha"; std::string error_message = "hahaha";
...@@ -4675,7 +4578,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -4675,7 +4578,7 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
testObject.readArray(array); testObject.readArray(array);
)", )",
error_message); error_message);
auto error = EvalJs(web_contents, kScript).error; auto error = EvalJs(web_contents(), kScript).error;
EXPECT_NE(error.find(error_message), std::string::npos); EXPECT_NE(error.find(error_message), std::string::npos);
} }
...@@ -4683,24 +4586,23 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, ...@@ -4683,24 +4586,23 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, RemoteObjectRelease) { IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, RemoteObjectRelease) {
GURL url(embedded_test_server()->GetURL("/empty.html")); GURL url(embedded_test_server()->GetURL("/empty.html"));
WebContents* web_contents = shell()->web_contents(); RemoteObjectInjector injector(web_contents());
RemoteObjectInjector injector(web_contents);
SetupRemoteObjectInvocation(shell(), url); SetupRemoteObjectInvocation(shell(), url);
EXPECT_EQ( EXPECT_EQ(
"object", "object",
EvalJs( EvalJs(
web_contents, web_contents(),
"globalInner = testObject.getInnerObject(); typeof globalInner; ")); "globalInner = testObject.getInnerObject(); typeof globalInner; "));
EXPECT_FALSE(injector.GetObjectHost().release_object_called_for_object( EXPECT_FALSE(injector.GetObjectHost().release_object_called_for_object(
kInnerObject.id)); kInnerObject.id));
EXPECT_EQ("object", EvalJs(web_contents, "gc(); typeof globalInner;")); EXPECT_EQ("object", EvalJs(web_contents(), "gc(); typeof globalInner;"));
EXPECT_FALSE(injector.GetObjectHost().release_object_called_for_object( EXPECT_FALSE(injector.GetObjectHost().release_object_called_for_object(
kInnerObject.id)); kInnerObject.id));
EXPECT_EQ( EXPECT_EQ(
"undefined", "undefined",
EvalJs(web_contents, "delete globalInner; gc(); typeof globalInner;")); EvalJs(web_contents(), "delete globalInner; gc(); typeof globalInner;"));
EXPECT_TRUE(injector.GetObjectHost().release_object_called_for_object( EXPECT_TRUE(injector.GetObjectHost().release_object_called_for_object(
kInnerObject.id)); kInnerObject.id));
} }
......
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