Commit 360847dd authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Clean up WebContentsImpl browsertests.

BUG=none

Change-Id: I5f6812ff98f8a54aae9f538b95c361dd184d25a5
Reviewed-on: https://chromium-review.googlesource.com/c/1311254
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Reviewed-by: default avatarSidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605077}
parent 6aba1673
...@@ -97,6 +97,8 @@ class SavePackage; ...@@ -97,6 +97,8 @@ class SavePackage;
class ScreenOrientationProvider; class ScreenOrientationProvider;
class SiteInstance; class SiteInstance;
class TestWCBeforeUnloadDelegate; // site_per_process_browsertest.cc class TestWCBeforeUnloadDelegate; // site_per_process_browsertest.cc
class
TestWCDelegateForDialogsAndFullscreen; // web_contents_impl_browsertest.cc
class TestWebContents; class TestWebContents;
class TextInputManager; class TextInputManager;
class WebContentsAudioMuter; class WebContentsAudioMuter;
...@@ -1000,6 +1002,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -1000,6 +1002,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
friend class RenderFrameHostImplBeforeUnloadBrowserTest; friend class RenderFrameHostImplBeforeUnloadBrowserTest;
friend class WebContentsImplBrowserTest; friend class WebContentsImplBrowserTest;
friend class TestWCBeforeUnloadDelegate; friend class TestWCBeforeUnloadDelegate;
friend class TestWCDelegateForDialogsAndFullscreen;
FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials); FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle); FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
...@@ -1035,20 +1038,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -1035,20 +1038,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
TwoSubframesCreatePopupMenuWidgetsSimultaneously); TwoSubframesCreatePopupMenuWidgetsSimultaneously);
FRIEND_TEST_ALL_PREFIXES(SitePerProcessAccessibilityBrowserTest, FRIEND_TEST_ALL_PREFIXES(SitePerProcessAccessibilityBrowserTest,
CrossSiteIframeAccessibility); CrossSiteIframeAccessibility);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
JavaScriptDialogsInMainAndSubframes);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
JavaScriptDialogsNormalizeText);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
DialogsFromJavaScriptEndFullscreen);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
DialogsFromJavaScriptEndFullscreenEvenInInnerWC);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
FileChooserEndsFullscreen);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
PopupsFromJavaScriptEndFullscreen);
FRIEND_TEST_ALL_PREFIXES(WebContentsImplBrowserTest,
FocusFromJavaScriptEndsFullscreen);
FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplBrowserTest, FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplBrowserTest,
IframeBeforeUnloadParentHang); IframeBeforeUnloadParentHang);
FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplBrowserTest, FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplBrowserTest,
......
...@@ -1519,13 +1519,18 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -1519,13 +1519,18 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
shell(), UNLOAD_AND_BEFORE_UNLOAD_HTML, true, true); shell(), UNLOAD_AND_BEFORE_UNLOAD_HTML, true, true);
} }
namespace {
class TestWCDelegateForDialogsAndFullscreen : public JavaScriptDialogManager, class TestWCDelegateForDialogsAndFullscreen : public JavaScriptDialogManager,
public WebContentsDelegate { public WebContentsDelegate {
public: public:
TestWCDelegateForDialogsAndFullscreen() = default; explicit TestWCDelegateForDialogsAndFullscreen(WebContentsImpl* web_contents)
~TestWCDelegateForDialogsAndFullscreen() override = default; : web_contents_(web_contents) {
old_delegate_ = web_contents_->GetDelegate();
web_contents_->SetDelegate(this);
}
~TestWCDelegateForDialogsAndFullscreen() override {
web_contents_->SetJavaScriptDialogManagerForTesting(nullptr);
web_contents_->SetDelegate(old_delegate_);
}
void WillWaitForDialog() { waiting_for_ = kDialog; } void WillWaitForDialog() { waiting_for_ = kDialog; }
void WillWaitForNewContents() { waiting_for_ = kNewContents; } void WillWaitForNewContents() { waiting_for_ = kNewContents; }
...@@ -1620,6 +1625,9 @@ class TestWCDelegateForDialogsAndFullscreen : public JavaScriptDialogManager, ...@@ -1620,6 +1625,9 @@ class TestWCDelegateForDialogsAndFullscreen : public JavaScriptDialogManager,
bool reset_state) override {} bool reset_state) override {}
private: private:
WebContentsImpl* web_contents_;
WebContentsDelegate* old_delegate_;
enum { enum {
kNothing, kNothing,
kDialog, kDialog,
...@@ -1646,13 +1654,10 @@ class MockFileSelectListener : public FileSelectListener { ...@@ -1646,13 +1654,10 @@ class MockFileSelectListener : public FileSelectListener {
void FileSelectionCanceled() override {} void FileSelectionCanceled() override {}
}; };
} // namespace
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
JavaScriptDialogsInMainAndSubframes) { JavaScriptDialogsInMainAndSubframes) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(wc);
wc->SetDelegate(&test_delegate);
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
...@@ -1733,16 +1738,12 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -1733,16 +1738,12 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
test_delegate.Wait(); test_delegate.Wait();
EXPECT_EQ(GURL("http://a.com/title1.html"), EXPECT_EQ(GURL("http://a.com/title1.html"),
GURL(test_delegate.last_message()).ReplaceComponents(clear_port)); GURL(test_delegate.last_message()).ReplaceComponents(clear_port));
wc->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
JavaScriptDialogsNormalizeText) { JavaScriptDialogsNormalizeText) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(wc);
wc->SetDelegate(&test_delegate);
GURL url("about:blank"); GURL url("about:blank");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
...@@ -1753,9 +1754,6 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -1753,9 +1754,6 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
EXPECT_TRUE(content::ExecuteScript(wc, alert)); EXPECT_TRUE(content::ExecuteScript(wc, alert));
test_delegate.Wait(); test_delegate.Wait();
EXPECT_EQ("1\n2\n3\n4", test_delegate.last_message()); EXPECT_EQ("1\n2\n3\n4", test_delegate.last_message());
wc->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
...@@ -2117,8 +2115,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, UserAgentOverride) { ...@@ -2117,8 +2115,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, UserAgentOverride) {
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
DialogsFromJavaScriptEndFullscreen) { DialogsFromJavaScriptEndFullscreen) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(wc);
wc->SetDelegate(&test_delegate);
GURL url("about:blank"); GURL url("about:blank");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
...@@ -2165,17 +2162,13 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -2165,17 +2162,13 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
test_delegate.Wait(); test_delegate.Wait();
EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); EXPECT_FALSE(wc->IsFullscreenForCurrentTab());
wc->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
DialogsFromJavaScriptEndFullscreenEvenInInnerWC) { DialogsFromJavaScriptEndFullscreenEvenInInnerWC) {
WebContentsImpl* top_contents = WebContentsImpl* top_contents =
static_cast<WebContentsImpl*>(shell()->web_contents()); static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen top_test_delegate; TestWCDelegateForDialogsAndFullscreen top_test_delegate(top_contents);
top_contents->SetDelegate(&top_test_delegate);
GURL url("about:blank"); GURL url("about:blank");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
...@@ -2195,8 +2188,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -2195,8 +2188,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
WebContentsImpl* inner_contents = WebContentsImpl* inner_contents =
static_cast<WebContentsImpl*>(CreateAndAttachInnerContents(frame)); static_cast<WebContentsImpl*>(CreateAndAttachInnerContents(frame));
TestWCDelegateForDialogsAndFullscreen inner_test_delegate; TestWCDelegateForDialogsAndFullscreen inner_test_delegate(inner_contents);
inner_contents->SetDelegate(&inner_test_delegate);
// A dialog from the inner WebContents should make the outer contents lose // A dialog from the inner WebContents should make the outer contents lose
// fullscreen. // fullscreen.
...@@ -2207,18 +2199,11 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -2207,18 +2199,11 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
EXPECT_TRUE(content::ExecuteScript(inner_contents, script)); EXPECT_TRUE(content::ExecuteScript(inner_contents, script));
inner_test_delegate.Wait(); inner_test_delegate.Wait();
EXPECT_FALSE(top_contents->IsFullscreenForCurrentTab()); EXPECT_FALSE(top_contents->IsFullscreenForCurrentTab());
inner_contents->SetDelegate(nullptr);
inner_contents->SetJavaScriptDialogManagerForTesting(nullptr);
top_contents->SetDelegate(nullptr);
top_contents->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, FileChooserEndsFullscreen) { IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, FileChooserEndsFullscreen) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(wc);
wc->SetDelegate(&test_delegate);
GURL url("about:blank"); GURL url("about:blank");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
...@@ -2229,16 +2214,12 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, FileChooserEndsFullscreen) { ...@@ -2229,16 +2214,12 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, FileChooserEndsFullscreen) {
std::make_unique<MockFileSelectListener>(), std::make_unique<MockFileSelectListener>(),
blink::mojom::FileChooserParams()); blink::mojom::FileChooserParams());
EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); EXPECT_FALSE(wc->IsFullscreenForCurrentTab());
wc->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
PopupsFromJavaScriptEndFullscreen) { PopupsFromJavaScriptEndFullscreen) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(wc);
wc->SetDelegate(&test_delegate);
GURL url("about:blank"); GURL url("about:blank");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
...@@ -2251,16 +2232,12 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -2251,16 +2232,12 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
EXPECT_TRUE(content::ExecuteScript(wc, script)); EXPECT_TRUE(content::ExecuteScript(wc, script));
test_delegate.Wait(); test_delegate.Wait();
EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); EXPECT_FALSE(wc->IsFullscreenForCurrentTab());
wc->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
FocusFromJavaScriptEndsFullscreen) { FocusFromJavaScriptEndsFullscreen) {
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(wc);
wc->SetDelegate(&test_delegate);
GURL url("about:blank"); GURL url("about:blank");
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
...@@ -2284,9 +2261,6 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -2284,9 +2261,6 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
EXPECT_TRUE(content::ExecuteScript(wc, script)); EXPECT_TRUE(content::ExecuteScript(wc, script));
test_delegate.Wait(); test_delegate.Wait();
EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); EXPECT_FALSE(wc->IsFullscreenForCurrentTab());
wc->SetDelegate(nullptr);
wc->SetJavaScriptDialogManagerForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
...@@ -2680,8 +2654,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NotifyFullscreenAcquired) { ...@@ -2680,8 +2654,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NotifyFullscreenAcquired) {
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
WebContentsImpl* web_contents = WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents()); static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(web_contents);
web_contents->SetDelegate(&test_delegate);
GURL url = embedded_test_server()->GetURL( GURL url = embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(b{allowfullscreen})"); "a.com", "/cross_site_iframe_factory.html?a(b{allowfullscreen})");
...@@ -2774,9 +2747,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -2774,9 +2747,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
WebContentsImpl* web_contents = WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents()); static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(web_contents);
test_delegate.WillWaitForFullscreenExit(); test_delegate.WillWaitForFullscreenExit();
web_contents->SetDelegate(&test_delegate);
GURL url = embedded_test_server()->GetURL( GURL url = embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(b{allowfullscreen})"); "a.com", "/cross_site_iframe_factory.html?a(b{allowfullscreen})");
...@@ -2826,8 +2798,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -2826,8 +2798,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
WebContentsImpl* web_contents = WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents()); static_cast<WebContentsImpl*>(shell()->web_contents());
TestWCDelegateForDialogsAndFullscreen test_delegate; TestWCDelegateForDialogsAndFullscreen test_delegate(web_contents);
web_contents->SetDelegate(&test_delegate);
GURL url = embedded_test_server()->GetURL( GURL url = embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(a{allowfullscreen})"); "a.com", "/cross_site_iframe_factory.html?a(a{allowfullscreen})");
......
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