| Index: content/browser/android/render_widget_host_connector_browsertest.cc
|
| diff --git a/content/browser/android/render_widget_host_connector_browsertest.cc b/content/browser/android/render_widget_host_connector_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bfa29e40cc2977a9fed87893a926139fc68fed1e
|
| --- /dev/null
|
| +++ b/content/browser/android/render_widget_host_connector_browsertest.cc
|
| @@ -0,0 +1,117 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/android/render_widget_host_connector_browsertest.h"
|
| +
|
| +#include "content/browser/frame_host/interstitial_page_impl.h"
|
| +#include "content/public/browser/interstitial_page_delegate.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "content/public/test/content_browser_test_utils.h"
|
| +#include "net/dns/mock_host_resolver.h"
|
| +#include "net/test/embedded_test_server/embedded_test_server.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +class TestInterstitialDelegate : public InterstitialPageDelegate {
|
| + private:
|
| + // InterstitialPageDelegate implementation.
|
| + std::string GetHTMLContents() override { return "<p>Interstitial</p>"; }
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +RenderWidgetHostConnectorTest::RenderWidgetHostConnectorTest() {}
|
| +
|
| +void RenderWidgetHostConnectorTest::SetUpOnMainThread() {
|
| + host_resolver()->AddRule("*", "127.0.0.1");
|
| + SetupCrossSiteRedirector(embedded_test_server());
|
| + ASSERT_TRUE(embedded_test_server()->Start());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
|
| + UpdateRWHVAInConnectorAtRenderViewHostSwapping) {
|
| + net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
|
| + https_server.ServeFilesFromSourceDirectory("content/test/data");
|
| + ASSERT_TRUE(https_server.Start());
|
| +
|
| + GURL http_url(embedded_test_server()->GetURL("/title1.html"));
|
| +
|
| + EXPECT_TRUE(NavigateToURL(shell(), http_url));
|
| + RenderWidgetHostViewAndroid* old_rwhva = render_widget_host_view_android();
|
| + RenderWidgetHostConnector* connector = render_widget_host_connector();
|
| + EXPECT_EQ(old_rwhva, connector->GetRWHVAForTesting());
|
| +
|
| + // Forces RVH change within |web_contents| by navigating to an https page.
|
| + GURL https_url(https_server.GetURL("/title1.html"));
|
| + EXPECT_TRUE(NavigateToURL(shell(), https_url));
|
| + RenderWidgetHostViewAndroid* new_rwhva = render_widget_host_view_android();
|
| + EXPECT_EQ(new_rwhva, connector->GetRWHVAForTesting());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
|
| + RestoreMainRWHVAAfterInterstitial) {
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
|
| +
|
| + RenderWidgetHostViewAndroid* main_rwhva = render_widget_host_view_android();
|
| + RenderWidgetHostConnector* connector = render_widget_host_connector();
|
| + EXPECT_EQ(main_rwhva, connector->GetRWHVAForTesting());
|
| +
|
| + // Show an interstitial and then hide. Then interstitial RWHVA should be
|
| + // updated accordingly, and the old main RWHVA reference should be restored.
|
| + WebContentsImpl* contents = web_contents();
|
| + GURL interstitial_url("http://interstitial");
|
| + InterstitialPageImpl* interstitial = new InterstitialPageImpl(
|
| + contents, static_cast<RenderWidgetHostDelegate*>(contents), true,
|
| + interstitial_url, new TestInterstitialDelegate);
|
| + interstitial->Show();
|
| + WaitForInterstitialAttach(contents);
|
| + EXPECT_NE(main_rwhva, connector->GetRWHVAForTesting());
|
| +
|
| + interstitial->Hide();
|
| + EXPECT_EQ(main_rwhva, connector->GetRWHVAForTesting());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
|
| + MainPageDestroyedWhileInBackground) {
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
|
| +
|
| + RenderWidgetHostViewAndroid* main_rwhva = render_widget_host_view_android();
|
| + RenderWidgetHostConnector* connector = render_widget_host_connector();
|
| + EXPECT_EQ(main_rwhva, connector->GetRWHVAForTesting());
|
| +
|
| + // Show an interstitial and destroy the main page in the background.
|
| + WebContentsImpl* contents = web_contents();
|
| + GURL interstitial_url("http://interstitial");
|
| + InterstitialPageImpl* interstitial = new InterstitialPageImpl(
|
| + contents, static_cast<RenderWidgetHostDelegate*>(contents), true,
|
| + interstitial_url, new TestInterstitialDelegate);
|
| + interstitial->Show();
|
| + WaitForInterstitialAttach(contents);
|
| + main_rwhva->Destroy();
|
| +
|
| + // Ensure active RWHVA set to null even when the main one is destroyed first.
|
| + interstitial->Hide();
|
| + EXPECT_EQ(nullptr, connector->GetRWHVAForTesting());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(RenderWidgetHostConnectorTest,
|
| + CleanUpConnectorReferenceAtWebContentsDestroyed) {
|
| + GURL http_url(embedded_test_server()->GetURL("/title1.html"));
|
| +
|
| + EXPECT_TRUE(NavigateToURL(shell(), http_url));
|
| + RenderWidgetHostViewAndroid* rwhva = render_widget_host_view_android();
|
| + RenderWidgetHostConnector* connector = render_widget_host_connector();
|
| + EXPECT_EQ(connector, connector_in_rwhva(rwhva));
|
| +
|
| + // Generate WebContentsObserver::WebContentsDestroyed by closing the contents.
|
| + web_contents()->Close();
|
| + EXPECT_EQ(nullptr, connector_in_rwhva(rwhva));
|
| +}
|
| +
|
| +} // namespace content
|
|
|