Skip to content

Commit

Permalink
Test resume delayed loading for popup window.
Browse files Browse the repository at this point in the history
When the opener is not suppressed, the popup window's loading will
not be delayed. This CL add a test for resume delayed loading  for  popup window whose openner is suppressed.

BUG: None
Change-Id: I539e22f7cb1013a246ec24e014dd945a2a1e6967
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4159734
Reviewed-by: Bo Liu <boliu@chromium.org>
Commit-Queue: Hui Wang <wanghui210@huawei.com>
Cr-Commit-Position: refs/heads/main@{#1107300}
  • Loading branch information
Wang Hui authored and Chromium LUCI CQ committed Feb 20, 2023
1 parent 9ced435 commit 9f7884a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
4 changes: 4 additions & 0 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
FRIEND_TEST_ALL_PREFIXES(PointerLockBrowserTest,
PointerLockInnerContentsCrashes);
FRIEND_TEST_ALL_PREFIXES(PointerLockBrowserTest, PointerLockOopifCrashes);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
PopupWindowBrowserNavResumeLoad);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
SuppressedPopupWindowBrowserNavResumeLoad);

// So |find_request_manager_| can be accessed for testing.
friend class FindRequestManagerTest;
Expand Down
51 changes: 49 additions & 2 deletions content/browser/web_contents/web_contents_impl_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3655,12 +3655,54 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, FrozenAndUnfrozenIPC) {
EXPECT_TRUE(delete_rfh_c.deleted());
}

IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
SuppressedPopupWindowBrowserNavResumeLoad) {
// This test verifies a suppressed pop up that requires navigation from
// browser side works with a delegate that delays navigations of pop ups.
base::FilePath test_data_dir;
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
base::FilePath simple_links_path =
test_data_dir.Append(GetTestDataFilePath())
.Append(FILE_PATH_LITERAL("simple_links.html"));
GURL url("file://" + simple_links_path.AsUTF8Unsafe());

shell()->set_delay_popup_contents_delegate_for_testing(true);
EXPECT_TRUE(NavigateToURL(shell(), url));

Shell* new_shell = nullptr;
WebContents* new_contents = nullptr;
{
ShellAddedObserver new_shell_observer;
bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell(),
"window.domAutomationController.send(clickLinkToSelfNoOpener());",
&success));
new_shell = new_shell_observer.GetShell();
new_contents = new_shell->web_contents();
// Delaying popup holds the initial load of |url|.
EXPECT_TRUE(WaitForLoadStop(new_contents));
EXPECT_TRUE(new_contents->GetController()
.GetLastCommittedEntry()
->IsInitialEntry());
EXPECT_NE(url, new_contents->GetLastCommittedURL());
}

EXPECT_FALSE(new_contents->GetDelegate());
new_contents->SetDelegate(new_shell);
EXPECT_TRUE(
static_cast<WebContentsImpl*>(new_contents)->delayed_load_url_params_);
new_contents->ResumeLoadingCreatedWebContents();
EXPECT_TRUE(WaitForLoadStop(new_contents));
EXPECT_EQ(url, new_contents->GetLastCommittedURL());
}

IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
PopupWindowBrowserNavResumeLoad) {
// This test verifies a pop up that requires navigation from browser side
// works with a delegate that delays navigations of pop ups.
// Create a file: scheme pop up from a file: scheme page, which requires
// requires an OpenURL IPC to the browser process.
// Create a file: scheme non-suppressed pop up from a file: scheme page will
// be blocked and wait for the renderer to signal.
base::FilePath test_data_dir;
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
base::FilePath simple_links_path =
Expand Down Expand Up @@ -3691,6 +3733,11 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,

EXPECT_FALSE(new_contents->GetDelegate());
new_contents->SetDelegate(new_shell);
EXPECT_FALSE(
static_cast<WebContentsImpl*>(new_contents)->delayed_load_url_params_);
EXPECT_FALSE(
static_cast<WebContentsImpl*>(new_contents)->delayed_open_url_params_);
EXPECT_TRUE(static_cast<WebContentsImpl*>(new_contents)->is_resume_pending_);
new_contents->ResumeLoadingCreatedWebContents();
EXPECT_TRUE(WaitForLoadStop(new_contents));
EXPECT_EQ(url, new_contents->GetLastCommittedURL());
Expand Down
12 changes: 9 additions & 3 deletions content/test/data/simple_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
}

function clickLinkToSelf() {
return simulateClick(document.getElementById("linkToSelf"));
return simulateClick(document.getElementById("link_to_self_opener"));
}

function clickLinkToSelfNoOpener() {
return simulateClick(document.getElementById("link_to_self_no_opener"));
}

function clickGoogleChromeLink() {
Expand All @@ -73,9 +77,11 @@
<a href="title2.html" id="same_site_new_window_with_opener_link" rel="opener" target="_blank">same-site new window with opener</a>
<a href="http://foo.com/title2.html" id="cross_site_new_window_link" rel="opener" target="_blank">cross-site new window</a>
<a href="http://foo.com/title2.html" id="cross_site_new_window_no_opener_link" rel="noopener" target="_blank">cross-site new window no opener</a>
<a href="" id="linkToSelf" rel="opener" target="_blank">self new window</a>
<a href="" id="link_to_self_opener" rel="opener" target="_blank">self new window_opener</a>
<a href="" id="link_to_self_no_opener" rel="noopener" target="_blank">self new window_noopener</a>
<script>
document.getElementById("linkToSelf").href = window.location.toString();
document.getElementById("link_to_self_opener").href = window.location.toString();
document.getElementById("link_to_self_no_opener").href = window.location.toString();
</script>
<a href="googlechrome://" id="google_chrome_link">googlechrome:</a></br>
</html>

0 comments on commit 9f7884a

Please sign in to comment.