Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: content/browser/android/render_widget_host_connector_browsertest.cc

Issue 2792063003: Factor out RenderWidgetHostConnector (Closed)
Patch Set: base::ObserverList Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/android/render_widget_host_connector_browsertest.h"
6
7 #include "content/browser/frame_host/interstitial_page_impl.h"
8 #include "content/public/browser/interstitial_page_delegate.h"
9 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test_utils.h"
11 #include "net/dns/mock_host_resolver.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "url/gurl.h"
14
15 namespace content {
16
17 namespace {
18
19 class TestInterstitialDelegate : public InterstitialPageDelegate {
20 private:
21 // InterstitialPageDelegate implementation.
22 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; }
23 };
24
25 } // namespace
26
27 RenderWidgetHostConnectorTest::RenderWidgetHostConnectorTest() {}
28
29 void RenderWidgetHostConnectorTest::SetUpOnMainThread() {
30 host_resolver()->AddRule("*", "127.0.0.1");
31 SetupCrossSiteRedirector(embedded_test_server());
32 ASSERT_TRUE(embedded_test_server()->Start());
33 }
34
35 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
36 UpdateRWHVAInConnectorAtRenderViewHostSwapping) {
37 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
38 https_server.ServeFilesFromSourceDirectory("content/test/data");
39 ASSERT_TRUE(https_server.Start());
40
41 GURL http_url(embedded_test_server()->GetURL("/title1.html"));
42
43 EXPECT_TRUE(NavigateToURL(shell(), http_url));
44 RenderWidgetHostViewAndroid* old_rwhva = render_widget_host_view_android();
45 RenderWidgetHostConnector* connector = render_widget_host_connector();
46 EXPECT_EQ(old_rwhva, connector->GetRWHVAForTesting());
47
48 // Forces RVH change within |web_contents| by navigating to an https page.
49 GURL https_url(https_server.GetURL("/title1.html"));
50 EXPECT_TRUE(NavigateToURL(shell(), https_url));
51 RenderWidgetHostViewAndroid* new_rwhva = render_widget_host_view_android();
52 EXPECT_EQ(new_rwhva, connector->GetRWHVAForTesting());
53 }
54
55 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
56 RestoreMainRWHVAAfterInterstitial) {
57 EXPECT_TRUE(
58 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
59
60 RenderWidgetHostViewAndroid* main_rwhva = render_widget_host_view_android();
61 RenderWidgetHostConnector* connector = render_widget_host_connector();
62 EXPECT_EQ(main_rwhva, connector->GetRWHVAForTesting());
63
64 // Show an interstitial and then hide. Then interstitial RWHVA should be
65 // updated accordingly, and the old main RWHVA reference should be restored.
66 WebContentsImpl* contents = web_contents();
67 GURL interstitial_url("http://interstitial");
68 InterstitialPageImpl* interstitial = new InterstitialPageImpl(
69 contents, static_cast<RenderWidgetHostDelegate*>(contents), true,
70 interstitial_url, new TestInterstitialDelegate);
71 interstitial->Show();
72 WaitForInterstitialAttach(contents);
73 EXPECT_NE(main_rwhva, connector->GetRWHVAForTesting());
74
75 interstitial->Hide();
76 EXPECT_EQ(main_rwhva, connector->GetRWHVAForTesting());
77 }
78
79 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
80 MainPageDestroyedWhileInBackground) {
81 EXPECT_TRUE(
82 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
83
84 RenderWidgetHostViewAndroid* main_rwhva = render_widget_host_view_android();
85 RenderWidgetHostConnector* connector = render_widget_host_connector();
86 EXPECT_EQ(main_rwhva, connector->GetRWHVAForTesting());
87
88 // Show an interstitial and destroy the main page in the background.
89 WebContentsImpl* contents = web_contents();
90 GURL interstitial_url("http://interstitial");
91 InterstitialPageImpl* interstitial = new InterstitialPageImpl(
92 contents, static_cast<RenderWidgetHostDelegate*>(contents), true,
93 interstitial_url, new TestInterstitialDelegate);
94 interstitial->Show();
95 WaitForInterstitialAttach(contents);
96 main_rwhva->Destroy();
97
98 // Ensure active RWHVA set to null even when the main one is destroyed first.
99 interstitial->Hide();
100 EXPECT_EQ(nullptr, connector->GetRWHVAForTesting());
101 }
102
103 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
104 CleanUpConnectorReferenceAtWebContentsDestroyed) {
105 GURL http_url(embedded_test_server()->GetURL("/title1.html"));
106
107 EXPECT_TRUE(NavigateToURL(shell(), http_url));
108 RenderWidgetHostViewAndroid* rwhva = render_widget_host_view_android();
109 RenderWidgetHostConnector* connector = render_widget_host_connector();
110 EXPECT_EQ(connector, connector_in_rwhva(rwhva));
111
112 // Generate WebContentsObserver::WebContentsDestroyed by closing the contents.
113 web_contents()->Close();
114 EXPECT_EQ(nullptr, connector_in_rwhva(rwhva));
115 }
116
117 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698