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

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

Issue 2792063003: Factor out RenderWidgetHostConnector (Closed)
Patch Set: test 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->rwhva_for_testing());
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->rwhva_for_testing());
53 }
54
55 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
56 RestoreRWHVAInConnectorAfterInterstitial) {
57 EXPECT_TRUE(
58 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
59
60 RenderWidgetHostViewAndroid* old_rwhva = render_widget_host_view_android();
61 RenderWidgetHostConnector* connector = render_widget_host_connector();
62 EXPECT_EQ(old_rwhva, connector->rwhva_for_testing());
63
64 // Show an interstitial and then hide. Then the old RWHVA reference should be
65 // restored in RenderWidgetHostConnector instance.
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(old_rwhva, connector->rwhva_for_testing());
74
75 interstitial->Hide();
76 EXPECT_EQ(old_rwhva, connector->rwhva_for_testing());
77 }
78
79 IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
80 CleanUpConnectorReferenceAtWebContentsDestroyed) {
81 GURL http_url(embedded_test_server()->GetURL("/title1.html"));
82
83 EXPECT_TRUE(NavigateToURL(shell(), http_url));
84 RenderWidgetHostViewAndroid* rwhva = render_widget_host_view_android();
85 RenderWidgetHostConnector* connector = render_widget_host_connector();
86 EXPECT_EQ(connector, connector_in_rwhva(rwhva));
87
88 // Generate WebContentsObserver::WebContentsDestroyed by closing the contents.
89 web_contents()->Close();
90 EXPECT_EQ(nullptr, connector_in_rwhva(rwhva));
91 }
92
93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698