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

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

Issue 2840443002: Add a test for RenderWidgetHostConnector (Closed)
Patch Set: 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/render_widget_host_connector_browsertest.h" 5 #include "content/browser/android/render_widget_host_connector_browsertest.h"
6 6
7 #include "content/browser/frame_host/interstitial_page_impl.h" 7 #include "content/browser/frame_host/interstitial_page_impl.h"
8 #include "content/public/browser/interstitial_page_delegate.h" 8 #include "content/public/browser/interstitial_page_delegate.h"
9 #include "content/public/test/browser_test_utils.h" 9 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test_utils.h" 10 #include "content/public/test/content_browser_test_utils.h"
11 #include "content/test/content_browser_test_utils_internal.h"
11 #include "net/dns/mock_host_resolver.h" 12 #include "net/dns/mock_host_resolver.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h" 13 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 namespace { 18 namespace {
18 19
19 class TestInterstitialDelegate : public InterstitialPageDelegate { 20 class TestInterstitialDelegate : public InterstitialPageDelegate {
20 private: 21 private:
21 // InterstitialPageDelegate implementation. 22 // InterstitialPageDelegate implementation.
22 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } 23 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; }
23 }; 24 };
24 25
25 } // namespace 26 } // namespace
26 27
27 RenderWidgetHostConnectorTest::RenderWidgetHostConnectorTest() {} 28 RenderWidgetHostConnectorTest::RenderWidgetHostConnectorTest() {}
28 29
29 void RenderWidgetHostConnectorTest::SetUpOnMainThread() { 30 void RenderWidgetHostConnectorTest::SetUpOnMainThread() {
30 host_resolver()->AddRule("*", "127.0.0.1"); 31 host_resolver()->AddRule("*", "127.0.0.1");
31 SetupCrossSiteRedirector(embedded_test_server()); 32 SetupCrossSiteRedirector(embedded_test_server());
32 ASSERT_TRUE(embedded_test_server()->Start()); 33 ASSERT_TRUE(embedded_test_server()->Start());
33 } 34 }
34 35
35 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest, 36 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
37 RenderViewCreatedBeforeConnector) {
38 GURL main_url(embedded_test_server()->GetURL("/page_with_popup.html"));
39 EXPECT_TRUE(NavigateToURL(shell(), main_url));
40
41 // Navigate to the enclosed <iframe>.
42 FrameTreeNode* iframe = web_contents()->GetFrameTree()->root()->child_at(0);
43 GURL frame_url(embedded_test_server()->GetURL("/title1.html"));
44 NavigateFrameToURL(iframe, frame_url);
45
46 // Open a popup from the iframe. This creates a render widget host view
47 // view before the corresponding web contents. Tests if rwhva gets connected.
48 Shell* new_shell = OpenPopup(iframe, GURL(url::kAboutBlankURL), "");
49 EXPECT_TRUE(new_shell);
50
51 auto* rwhva_popup = static_cast<RenderWidgetHostViewAndroid*>(
52 new_shell->web_contents()->GetRenderWidgetHostView());
53 EXPECT_TRUE(connector_in_rwhva(rwhva_popup) != nullptr);
54 }
55
56 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
36 UpdateRWHVAInConnectorAtRenderViewHostSwapping) { 57 UpdateRWHVAInConnectorAtRenderViewHostSwapping) {
37 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); 58 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
38 https_server.ServeFilesFromSourceDirectory("content/test/data"); 59 https_server.ServeFilesFromSourceDirectory("content/test/data");
39 ASSERT_TRUE(https_server.Start()); 60 ASSERT_TRUE(https_server.Start());
40 61
41 GURL http_url(embedded_test_server()->GetURL("/title1.html")); 62 GURL http_url(embedded_test_server()->GetURL("/title1.html"));
42 63
43 EXPECT_TRUE(NavigateToURL(shell(), http_url)); 64 EXPECT_TRUE(NavigateToURL(shell(), http_url));
44 RenderWidgetHostViewAndroid* old_rwhva = render_widget_host_view_android(); 65 RenderWidgetHostViewAndroid* old_rwhva = render_widget_host_view_android();
45 RenderWidgetHostConnector* connector = render_widget_host_connector(); 66 RenderWidgetHostConnector* connector = render_widget_host_connector();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 RenderWidgetHostViewAndroid* rwhva = render_widget_host_view_android(); 129 RenderWidgetHostViewAndroid* rwhva = render_widget_host_view_android();
109 RenderWidgetHostConnector* connector = render_widget_host_connector(); 130 RenderWidgetHostConnector* connector = render_widget_host_connector();
110 EXPECT_EQ(connector, connector_in_rwhva(rwhva)); 131 EXPECT_EQ(connector, connector_in_rwhva(rwhva));
111 132
112 // Generate WebContentsObserver::WebContentsDestroyed by closing the contents. 133 // Generate WebContentsObserver::WebContentsDestroyed by closing the contents.
113 web_contents()->Close(); 134 web_contents()->Close();
114 EXPECT_EQ(nullptr, connector_in_rwhva(rwhva)); 135 EXPECT_EQ(nullptr, connector_in_rwhva(rwhva));
115 } 136 }
116 137
117 } // namespace content 138 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698