Commit 892d4174 authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

Update view_source tests to handle same-site BrowsingInstance swap

With crrev.com/c/2121522, some main-frame same-site navigations will
result in a new BrowsingInstance, SiteInstance, RenderFrameHost,
RenderView, etc. This CL updates expectations of view_source tests
that didn't expect a change of RenderFrameHosts etc. on same-site
navigations.

This CL does not include fixes for other tests in chrome/ content/,
components/, and layout tests (they're fixed in other CLs)

For more details, see doc: https://docs.google.com/document/d/1lHdkKLUe8H6ZP6ALwj-dsus7oYcuc93HkSCHCcerItg/edit?usp=sharing

Bug: 977562
Change-Id: Idc7b35c7cb01bacdcc0c13b083b2263b3a07dd14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212225
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775057}
parent 26eaf07d
...@@ -339,7 +339,18 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) { ...@@ -339,7 +339,18 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) {
"document.getElementById('form').submit();")); "document.getElementById('form').submit();"));
form_post_observer.Wait(); form_post_observer.Wait();
GURL target_url(embedded_test_server()->GetURL("a.com", "/echoall")); GURL target_url(embedded_test_server()->GetURL("a.com", "/echoall"));
EXPECT_EQ(target_url, original_main_frame->GetLastCommittedURL());
content::RenderFrameHost* current_main_frame =
original_contents->GetMainFrame();
if (content::CanSameSiteMainFrameNavigationsChangeRenderFrameHosts()) {
// When ProactivelySwapBrowsingInstance or RenderDocument is enabled on
// same-site main frame navigations, the form submission above will result
// in a change of RFH.
EXPECT_NE(current_main_frame, original_main_frame);
} else {
EXPECT_EQ(current_main_frame, original_main_frame);
}
EXPECT_EQ(target_url, current_main_frame->GetLastCommittedURL());
// Extract the response nonce. // Extract the response nonce.
std::string response_nonce; std::string response_nonce;
...@@ -347,13 +358,13 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) { ...@@ -347,13 +358,13 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) {
domAutomationController.send( domAutomationController.send(
document.getElementById('response-nonce').innerText); )"; document.getElementById('response-nonce').innerText); )";
EXPECT_TRUE(ExecuteScriptAndExtractString( EXPECT_TRUE(ExecuteScriptAndExtractString(
original_main_frame, response_nonce_extraction_script, &response_nonce)); current_main_frame, response_nonce_extraction_script, &response_nonce));
// Open view-source mode tab for the main frame. This tries to mimic the // Open view-source mode tab for the main frame. This tries to mimic the
// behavior of RenderViewContextMenu::ExecuteCommand when it handles // behavior of RenderViewContextMenu::ExecuteCommand when it handles
// IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE. // IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE.
content::WebContentsAddedObserver view_source_contents_observer; content::WebContentsAddedObserver view_source_contents_observer;
original_main_frame->ViewSource(); current_main_frame->ViewSource();
content::WebContents* view_source_contents = content::WebContents* view_source_contents =
view_source_contents_observer.GetWebContents(); view_source_contents_observer.GetWebContents();
EXPECT_TRUE(WaitForLoadStop(view_source_contents)); EXPECT_TRUE(WaitForLoadStop(view_source_contents));
...@@ -390,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) { ...@@ -390,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) {
// Verify that the original contents and the view-source contents are in a // Verify that the original contents and the view-source contents are in a
// different process - see https://crbug.com/699493. // different process - see https://crbug.com/699493.
EXPECT_NE(original_main_frame->GetSiteInstance(), EXPECT_NE(current_main_frame->GetSiteInstance(),
view_source_contents->GetMainFrame()->GetSiteInstance()); view_source_contents->GetMainFrame()->GetSiteInstance());
// Verify the title of view-source is derived from the URL (not from the title // Verify the title of view-source is derived from the URL (not from the title
...@@ -399,7 +410,7 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) { ...@@ -399,7 +410,7 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, HttpPostInMainframe) {
EXPECT_EQ("EmbeddedTestServer - EchoAll", EXPECT_EQ("EmbeddedTestServer - EchoAll",
base::UTF16ToUTF8(original_contents->GetTitle())); base::UTF16ToUTF8(original_contents->GetTitle()));
EXPECT_THAT(title, Not(HasSubstr("EmbeddedTestServer - EchoAll"))); EXPECT_THAT(title, Not(HasSubstr("EmbeddedTestServer - EchoAll")));
GURL original_url = original_main_frame->GetLastCommittedURL(); GURL original_url = current_main_frame->GetLastCommittedURL();
EXPECT_THAT(title, HasSubstr(content::kViewSourceScheme)); EXPECT_THAT(title, HasSubstr(content::kViewSourceScheme));
EXPECT_THAT(title, HasSubstr(original_url.host())); EXPECT_THAT(title, HasSubstr(original_url.host()));
EXPECT_THAT(title, HasSubstr(original_url.port())); EXPECT_THAT(title, HasSubstr(original_url.port()));
......
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