Commit 8e2f722d authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Cleanup] Use WebContentsConsoleObserver in //content/browser/portal

Update remaining tests under //content/browser/portal to use
WebContentsConsoleObserver instead of ConsoleObserverDelegate.
This allows us to observe console messages added without overriding
the existing delegate of the WebContents.

Bug: 1034150
Change-Id: I7618db78b2d55c9919e91ab4c2c7ff7f9589e827
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316449Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791923}
parent 84236c34
......@@ -295,20 +295,17 @@ IN_PROC_BROWSER_TEST_F(PortalNavigationThrottleBrowserTest,
GetWebContents(),
embedded_test_server()->GetURL("portal.test", "/title1.html")));
auto* old_delegate = GetWebContents()->GetDelegate();
ConsoleObserverDelegate console_delegate(GetWebContents(),
"*portal*cross-origin*");
GetWebContents()->SetDelegate(&console_delegate);
WebContentsConsoleObserver console_observer(GetWebContents());
console_observer.SetPattern("*portal*cross-origin*");
Portal* portal = InsertAndWaitForPortal(
embedded_test_server()->GetURL("not.portal.test", "/title2.html"),
/*expected_to_succeed=*/false);
EXPECT_NE(portal, nullptr);
console_delegate.Wait();
EXPECT_THAT(console_delegate.message(),
console_observer.Wait();
EXPECT_THAT(console_observer.GetMessageAt(0u),
::testing::HasSubstr("http://not.portal.test"));
GetWebContents()->SetDelegate(old_delegate);
}
// Ensure navigating while a portal is orphaned does not bypass cross-origin
......@@ -372,30 +369,26 @@ IN_PROC_BROWSER_TEST_F(PortalNavigationThrottleBrowserTestCrossOrigin,
// should only be flaky if there is a bug.
{
auto* old_delegate = portal->GetPortalContents()->GetDelegate();
ConsoleObserverDelegate console_delegate(portal->GetPortalContents(),
"*avigat*");
portal->GetPortalContents()->SetDelegate(&console_delegate);
WebContentsConsoleObserver console_observer(portal->GetPortalContents());
console_observer.SetPattern("*avigat*");
EXPECT_TRUE(ExecJs(portal->GetPortalContents(),
"location.href = 'data:text/html,hello world';"));
console_delegate.Wait();
EXPECT_THAT(console_delegate.message(), ::testing::HasSubstr("data"));
console_observer.Wait();
EXPECT_THAT(console_observer.GetMessageAt(0u),
::testing::HasSubstr("data"));
SleepWithRunLoop(base::TimeDelta::FromSeconds(3), FROM_HERE);
EXPECT_EQ(portal->GetPortalContents()->GetLastCommittedURL(), referrer_url);
portal->GetPortalContents()->SetDelegate(old_delegate);
}
{
auto* old_delegate = GetWebContents()->GetDelegate();
ConsoleObserverDelegate console_delegate(GetWebContents(), "*avigat*");
GetWebContents()->SetDelegate(&console_delegate);
WebContentsConsoleObserver console_observer(GetWebContents());
console_observer.SetPattern("*avigat*");
EXPECT_TRUE(ExecJs(portal->GetPortalContents(),
"location.href = 'ftp://user:pass@example.com/';"));
console_delegate.Wait();
EXPECT_THAT(console_delegate.message(), ::testing::HasSubstr("ftp"));
console_observer.Wait();
EXPECT_THAT(console_observer.GetMessageAt(0u), ::testing::HasSubstr("ftp"));
SleepWithRunLoop(base::TimeDelta::FromSeconds(3), FROM_HERE);
EXPECT_EQ(portal->GetPortalContents()->GetLastCommittedURL(), referrer_url);
GetWebContents()->SetDelegate(old_delegate);
}
}
......
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