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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_browsertest.cc

Issue 2797473005: Fix interstitials on OOPIF-based guests. (Closed)
Patch Set: null check webcontents 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <queue> 5 #include <queue>
6 #include <set> 6 #include <set>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "chrome/browser/ui/tabs/tab_strip_model.h" 44 #include "chrome/browser/ui/tabs/tab_strip_model.h"
45 #include "chrome/test/base/ui_test_utils.h" 45 #include "chrome/test/base/ui_test_utils.h"
46 #include "components/content_settings/core/browser/host_content_settings_map.h" 46 #include "components/content_settings/core/browser/host_content_settings_map.h"
47 #include "components/guest_view/browser/guest_view_manager.h" 47 #include "components/guest_view/browser/guest_view_manager.h"
48 #include "components/guest_view/browser/guest_view_manager_delegate.h" 48 #include "components/guest_view/browser/guest_view_manager_delegate.h"
49 #include "components/guest_view/browser/guest_view_manager_factory.h" 49 #include "components/guest_view/browser/guest_view_manager_factory.h"
50 #include "components/guest_view/browser/test_guest_view_manager.h" 50 #include "components/guest_view/browser/test_guest_view_manager.h"
51 #include "content/public/browser/ax_event_notification_details.h" 51 #include "content/public/browser/ax_event_notification_details.h"
52 #include "content/public/browser/gpu_data_manager.h" 52 #include "content/public/browser/gpu_data_manager.h"
53 #include "content/public/browser/interstitial_page.h" 53 #include "content/public/browser/interstitial_page.h"
54 #include "content/public/browser/interstitial_page_delegate.h"
55 #include "content/public/browser/notification_service.h" 54 #include "content/public/browser/notification_service.h"
56 #include "content/public/browser/render_process_host.h" 55 #include "content/public/browser/render_process_host.h"
57 #include "content/public/browser/render_widget_host.h" 56 #include "content/public/browser/render_widget_host.h"
58 #include "content/public/browser/render_widget_host_view.h" 57 #include "content/public/browser/render_widget_host_view.h"
59 #include "content/public/browser/web_contents_delegate.h" 58 #include "content/public/browser/web_contents_delegate.h"
60 #include "content/public/common/child_process_host.h" 59 #include "content/public/common/child_process_host.h"
61 #include "content/public/common/content_features.h" 60 #include "content/public/common/content_features.h"
62 #include "content/public/common/content_switches.h" 61 #include "content/public/common/content_switches.h"
63 #include "content/public/test/browser_test_utils.h" 62 #include "content/public/test/browser_test_utils.h"
64 #include "content/public/test/download_test_observer.h" 63 #include "content/public/test/download_test_observer.h"
65 #include "content/public/test/fake_speech_recognition_manager.h" 64 #include "content/public/test/fake_speech_recognition_manager.h"
66 #include "content/public/test/test_navigation_observer.h" 65 #include "content/public/test/test_navigation_observer.h"
67 #include "content/public/test/test_renderer_host.h" 66 #include "content/public/test/test_renderer_host.h"
68 #include "content/public/test/test_utils.h" 67 #include "content/public/test/test_utils.h"
69 #include "extensions/browser/api/declarative/rules_registry.h" 68 #include "extensions/browser/api/declarative/rules_registry.h"
70 #include "extensions/browser/api/declarative/rules_registry_service.h" 69 #include "extensions/browser/api/declarative/rules_registry_service.h"
71 #include "extensions/browser/api/declarative/test_rules_registry.h" 70 #include "extensions/browser/api/declarative/test_rules_registry.h"
72 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 71 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
73 #include "extensions/browser/api/extensions_api_client.h" 72 #include "extensions/browser/api/extensions_api_client.h"
74 #include "extensions/browser/app_window/native_app_window.h" 73 #include "extensions/browser/app_window/native_app_window.h"
75 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 74 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
76 #include "extensions/common/extension.h" 75 #include "extensions/common/extension.h"
77 #include "extensions/common/extensions_client.h" 76 #include "extensions/common/extensions_client.h"
78 #include "extensions/test/extension_test_message_listener.h" 77 #include "extensions/test/extension_test_message_listener.h"
79 #include "media/base/media_switches.h" 78 #include "media/base/media_switches.h"
80 #include "net/test/embedded_test_server/embedded_test_server.h" 79 #include "net/test/embedded_test_server/embedded_test_server.h"
81 #include "net/test/embedded_test_server/http_request.h" 80 #include "net/test/embedded_test_server/http_request.h"
82 #include "net/test/embedded_test_server/http_response.h" 81 #include "net/test/embedded_test_server/http_response.h"
83 #include "ppapi/features/features.h" 82 #include "ppapi/features/features.h"
83 #include "third_party/WebKit/public/platform/WebMouseEvent.h"
84 #include "ui/aura/env.h" 84 #include "ui/aura/env.h"
85 #include "ui/aura/window.h" 85 #include "ui/aura/window.h"
86 #include "ui/compositor/compositor.h" 86 #include "ui/compositor/compositor.h"
87 #include "ui/compositor/compositor_observer.h" 87 #include "ui/compositor/compositor_observer.h"
88 #include "ui/display/display_switches.h" 88 #include "ui/display/display_switches.h"
89 #include "ui/events/gesture_detection/gesture_configuration.h" 89 #include "ui/events/gesture_detection/gesture_configuration.h"
90 #include "ui/gl/gl_switches.h" 90 #include "ui/gl/gl_switches.h"
91 #include "ui/views/view.h" 91 #include "ui/views/view.h"
92 #include "ui/views/widget/widget.h" 92 #include "ui/views/widget/widget.h"
93 93
(...skipping 23 matching lines...) Expand all
117 using ui::MenuModel; 117 using ui::MenuModel;
118 118
119 namespace { 119 namespace {
120 const char kEmptyResponsePath[] = "/close-socket"; 120 const char kEmptyResponsePath[] = "/close-socket";
121 const char kRedirectResponsePath[] = "/server-redirect"; 121 const char kRedirectResponsePath[] = "/server-redirect";
122 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent"; 122 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent";
123 const char kCacheResponsePath[] = "/cache-control-response"; 123 const char kCacheResponsePath[] = "/cache-control-response";
124 const char kRedirectResponseFullPath[] = 124 const char kRedirectResponseFullPath[] =
125 "/extensions/platform_apps/web_view/shim/guest_redirect.html"; 125 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
126 126
127 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
128 public:
129 TestInterstitialPageDelegate() {
130 }
131 ~TestInterstitialPageDelegate() override {}
132 std::string GetHTMLContents() override { return std::string(); }
133 };
134
135 class WebContentsHiddenObserver : public content::WebContentsObserver { 127 class WebContentsHiddenObserver : public content::WebContentsObserver {
136 public: 128 public:
137 WebContentsHiddenObserver(content::WebContents* web_contents, 129 WebContentsHiddenObserver(content::WebContents* web_contents,
138 const base::Closure& hidden_callback) 130 const base::Closure& hidden_callback)
139 : WebContentsObserver(web_contents), 131 : WebContentsObserver(web_contents),
140 hidden_callback_(hidden_callback), 132 hidden_callback_(hidden_callback),
141 hidden_observed_(false) { 133 hidden_observed_(false) {
142 } 134 }
143 135
144 // WebContentsObserver. 136 // WebContentsObserver.
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 content::Source<content::NavigationController> source = 676 content::Source<content::NavigationController> source =
685 guest_observer.source(); 677 guest_observer.source();
686 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()-> 678 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
687 IsForGuestsOnly()); 679 IsForGuestsOnly());
688 680
689 content::WebContents* guest_web_contents = source->GetWebContents(); 681 content::WebContents* guest_web_contents = source->GetWebContents();
690 return guest_web_contents; 682 return guest_web_contents;
691 } 683 }
692 684
693 // Helper to load interstitial page in a <webview>. 685 // Helper to load interstitial page in a <webview>.
694 void InterstitialTeardownTestHelper() { 686 void InterstitialTestHelper() {
695 // Start a HTTPS server so we can load an interstitial page inside guest. 687 // Start a HTTPS server so we can load an interstitial page inside guest.
696 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); 688 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
697 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); 689 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME);
698 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); 690 https_server.ServeFilesFromSourceDirectory("chrome/test/data");
699 ASSERT_TRUE(https_server.Start()); 691 ASSERT_TRUE(https_server.Start());
700 692
701 net::HostPortPair host_and_port = https_server.host_port_pair(); 693 net::HostPortPair host_and_port = https_server.host_port_pair();
702 694
703 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", 695 LoadAndLaunchPlatformApp("web_view/interstitial_teardown",
704 "EmbedderLoaded"); 696 "EmbedderLoaded");
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 "web_view/shim", 1689 "web_view/shim",
1698 NO_TEST_SERVER); 1690 NO_TEST_SERVER);
1699 } 1691 }
1700 1692
1701 IN_PROC_BROWSER_TEST_P(WebViewSizeTest, Shim_TestResizeWebviewResizesContent) { 1693 IN_PROC_BROWSER_TEST_P(WebViewSizeTest, Shim_TestResizeWebviewResizesContent) {
1702 TestHelper("testResizeWebviewResizesContent", 1694 TestHelper("testResizeWebviewResizesContent",
1703 "web_view/shim", 1695 "web_view/shim",
1704 NO_TEST_SERVER); 1696 NO_TEST_SERVER);
1705 } 1697 }
1706 1698
1699 // Test makes sure that interstitial pages renders in <webview>.
1700 IN_PROC_BROWSER_TEST_P(WebViewTest, InterstitialPage) {
1701 // This test tests that a inner WebContents' InterstitialPage is properly
1702 // connected to an outer WebContents through a CrossProcessFrameConnector, it
1703 // doesn't make sense for BrowserPlugin based guests.
1704 if (!base::FeatureList::IsEnabled(::features::kGuestViewCrossProcessFrames))
1705 return;
1706
1707 InterstitialTestHelper();
1708
1709 content::WebContents* guest_web_contents =
1710 GetGuestViewManager()->WaitForSingleGuestCreated();
1711
1712 EXPECT_TRUE(guest_web_contents->ShowingInterstitialPage());
1713 EXPECT_TRUE(guest_web_contents->GetInterstitialPage()
1714 ->GetMainFrame()
1715 ->GetView()
1716 ->IsShowing());
1717 EXPECT_TRUE(content::IsInnerInterstitialPageConnected(
1718 guest_web_contents->GetInterstitialPage()));
1719 }
1720
1721 // Test makes sure that interstitial pages are registered in the
1722 // RenderWidgetHostInputEventRouter when inside a <webview>.
1723 IN_PROC_BROWSER_TEST_P(WebViewTest, InterstitialPageRouteEvents) {
1724 // This test tests that a inner WebContents' InterstitialPage is properly
1725 // connected to an outer WebContents through a CrossProcessFrameConnector, it
1726 // doesn't make sense for BrowserPlugin based guests.
1727 if (!base::FeatureList::IsEnabled(::features::kGuestViewCrossProcessFrames))
1728 return;
1729
1730 InterstitialTestHelper();
1731
1732 content::WebContents* outer_web_contents = GetFirstAppWindowWebContents();
1733 content::WebContents* guest_web_contents =
1734 GetGuestViewManager()->WaitForSingleGuestCreated();
1735 content::InterstitialPage* interstitial_page =
1736 guest_web_contents->GetInterstitialPage();
1737
1738 std::vector<content::RenderWidgetHostView*> hosts =
1739 content::GetInputEventRouterRenderWidgetHostViews(outer_web_contents);
1740 EXPECT_TRUE(std::find(hosts.begin(), hosts.end(),
1741 interstitial_page->GetMainFrame()->GetView()) !=
1742 hosts.end());
1743 }
1744
1745 // Test makes sure that interstitial pages will receive input events and can be
1746 // focused.
1747 IN_PROC_BROWSER_TEST_P(WebViewTest, InterstitialPageFocusedWidget) {
1748 // This test tests that a inner WebContents' InterstitialPage is properly
1749 // connected to an outer WebContents through a CrossProcessFrameConnector, it
1750 // doesn't make sense for BrowserPlugin based guests.
1751 if (!base::FeatureList::IsEnabled(::features::kGuestViewCrossProcessFrames))
1752 return;
1753
1754 InterstitialTestHelper();
1755
1756 content::WebContents* outer_web_contents = GetFirstAppWindowWebContents();
1757 content::WebContents* guest_web_contents =
1758 GetGuestViewManager()->WaitForSingleGuestCreated();
1759 content::InterstitialPage* interstitial_page =
1760 guest_web_contents->GetInterstitialPage();
1761 content::RenderFrameHost* interstitial_main_frame =
1762 interstitial_page->GetMainFrame();
1763 content::RenderWidgetHost* interstitial_widget =
1764 interstitial_main_frame->GetRenderViewHost()->GetWidget();
1765
1766 content::WaitForChildFrameSurfaceReady(interstitial_main_frame);
1767
1768 EXPECT_NE(interstitial_widget,
1769 content::GetFocusedRenderWidgetHost(guest_web_contents));
1770 EXPECT_NE(interstitial_widget,
1771 content::GetFocusedRenderWidgetHost(outer_web_contents));
1772
1773 // Send mouse down.
1774 blink::WebMouseEvent event;
1775 event.button = blink::WebPointerProperties::Button::Left;
1776 event.setType(blink::WebInputEvent::MouseDown);
1777 event.setPositionInWidget(10, 10);
1778 content::RouteMouseEvent(outer_web_contents, &event);
1779
1780 // Wait a frame.
1781 content::MainThreadFrameObserver observer(interstitial_widget);
1782 observer.Wait();
1783
1784 // Send mouse up.
1785 event.setType(blink::WebInputEvent::MouseUp);
1786 event.setPositionInWidget(10, 10);
1787 content::RouteMouseEvent(outer_web_contents, &event);
1788
1789 // Wait another frame.
1790 observer.Wait();
1791
1792 EXPECT_EQ(interstitial_widget,
1793 content::GetFocusedRenderWidgetHost(guest_web_contents));
1794 EXPECT_EQ(interstitial_widget,
1795 content::GetFocusedRenderWidgetHost(outer_web_contents));
1796 }
1797
1707 // This test makes sure the browser process does not crash if app is closed 1798 // This test makes sure the browser process does not crash if app is closed
1708 // while an interstitial page is being shown in guest. 1799 // while an interstitial page is being shown in guest.
1709 IN_PROC_BROWSER_TEST_P(WebViewTest, InterstitialTeardown) { 1800 IN_PROC_BROWSER_TEST_P(WebViewTest, InterstitialTeardown) {
1710 InterstitialTeardownTestHelper(); 1801 InterstitialTestHelper();
1711 1802
1712 // Now close the app while interstitial page being shown in guest. 1803 // Now close the app while interstitial page being shown in guest.
1713 extensions::AppWindow* window = GetFirstAppWindow(); 1804 extensions::AppWindow* window = GetFirstAppWindow();
1714 window->GetBaseWindow()->Close(); 1805 window->GetBaseWindow()->Close();
1715 } 1806 }
1716 1807
1717 // This test makes sure the browser process does not crash if browser is shut 1808 // This test makes sure the browser process does not crash if browser is shut
1718 // down while an interstitial page is being shown in guest. 1809 // down while an interstitial page is being shown in guest.
1719 // Flaky. http://crbug.com/627962. 1810 // Flaky. http://crbug.com/627962.
1720 IN_PROC_BROWSER_TEST_P(WebViewTest, 1811 IN_PROC_BROWSER_TEST_P(WebViewTest,
1721 DISABLED_InterstitialTeardownOnBrowserShutdown) { 1812 DISABLED_InterstitialTeardownOnBrowserShutdown) {
1722 InterstitialTeardownTestHelper(); 1813 InterstitialTestHelper();
1723 1814
1724 // Now close the app while interstitial page being shown in guest. 1815 // Now close the app while interstitial page being shown in guest.
1725 extensions::AppWindow* window = GetFirstAppWindow(); 1816 extensions::AppWindow* window = GetFirstAppWindow();
1726 window->GetBaseWindow()->Close(); 1817 window->GetBaseWindow()->Close();
1727 1818
1728 // InterstitialPage is not destroyed immediately, so the 1819 // InterstitialPage is not destroyed immediately, so the
1729 // RenderWidgetHostViewGuest for it is still there, closing all 1820 // RenderWidgetHostViewGuest for it is still there, closing all
1730 // renderer processes will cause the RWHVGuest's RenderProcessGone() 1821 // renderer processes will cause the RWHVGuest's RenderProcessGone()
1731 // shutdown path to be exercised. 1822 // shutdown path to be exercised.
1732 chrome::CloseAllBrowsers(); 1823 chrome::CloseAllBrowsers();
(...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after
4032 ClosingChromeSignInShouldNotCrash) { 4123 ClosingChromeSignInShouldNotCrash) {
4033 GURL signin_url{"chrome://chrome-signin"}; 4124 GURL signin_url{"chrome://chrome-signin"};
4034 4125
4035 AddTabAtIndex(0, signin_url, ui::PAGE_TRANSITION_TYPED); 4126 AddTabAtIndex(0, signin_url, ui::PAGE_TRANSITION_TYPED);
4036 AddTabAtIndex(1, signin_url, ui::PAGE_TRANSITION_TYPED); 4127 AddTabAtIndex(1, signin_url, ui::PAGE_TRANSITION_TYPED);
4037 WaitForWebViewInDom(); 4128 WaitForWebViewInDom();
4038 4129
4039 chrome::CloseTab(browser()); 4130 chrome::CloseTab(browser());
4040 } 4131 }
4041 #endif 4132 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698