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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 1129123004: Don't treat http://gpu as a WebUI url (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DEPS and another rebase Created 5 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/cross_site_transferring_request.h" 8 #include "content/browser/frame_host/cross_site_transferring_request.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h" 9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
11 #include "content/browser/frame_host/render_frame_host_impl.h" 11 #include "content/browser/frame_host/render_frame_host_impl.h"
12 #include "content/browser/media/audio_state_provider.h" 12 #include "content/browser/media/audio_state_provider.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/site_instance_impl.h" 14 #include "content/browser/site_instance_impl.h"
15 #include "content/browser/webui/content_web_ui_controller_factory.h"
15 #include "content/browser/webui/web_ui_controller_factory_registry.h" 16 #include "content/browser/webui/web_ui_controller_factory_registry.h"
16 #include "content/common/frame_messages.h" 17 #include "content/common/frame_messages.h"
17 #include "content/common/input/synthetic_web_input_event_builders.h" 18 #include "content/common/input/synthetic_web_input_event_builders.h"
18 #include "content/common/view_messages.h" 19 #include "content/common/view_messages.h"
19 #include "content/public/browser/global_request_id.h" 20 #include "content/public/browser/global_request_id.h"
20 #include "content/public/browser/interstitial_page_delegate.h" 21 #include "content/public/browser/interstitial_page_delegate.h"
21 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
22 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
24 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
(...skipping 10 matching lines...) Expand all
35 #include "content/test/test_content_browser_client.h" 36 #include "content/test/test_content_browser_client.h"
36 #include "content/test/test_content_client.h" 37 #include "content/test/test_content_client.h"
37 #include "content/test/test_render_frame_host.h" 38 #include "content/test/test_render_frame_host.h"
38 #include "content/test/test_render_view_host.h" 39 #include "content/test/test_render_view_host.h"
39 #include "content/test/test_web_contents.h" 40 #include "content/test/test_web_contents.h"
40 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
41 42
42 namespace content { 43 namespace content {
43 namespace { 44 namespace {
44 45
45 const char kTestWebUIUrl[] = "chrome://blah";
46
47 class WebContentsImplTestWebUIControllerFactory
48 : public WebUIControllerFactory {
49 public:
50 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui,
51 const GURL& url) const override {
52 if (!UseWebUI(url))
53 return nullptr;
54 return new WebUIController(web_ui);
55 }
56
57 WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
58 const GURL& url) const override {
59 return WebUI::kNoWebUI;
60 }
61
62 bool UseWebUIForURL(BrowserContext* browser_context,
63 const GURL& url) const override {
64 return UseWebUI(url);
65 }
66
67 bool UseWebUIBindingsForURL(BrowserContext* browser_context,
68 const GURL& url) const override {
69 return UseWebUI(url);
70 }
71
72 private:
73 bool UseWebUI(const GURL& url) const {
74 return url == GURL(kTestWebUIUrl);
75 }
76 };
77
78 class TestInterstitialPage; 46 class TestInterstitialPage;
79 47
80 class TestInterstitialPageDelegate : public InterstitialPageDelegate { 48 class TestInterstitialPageDelegate : public InterstitialPageDelegate {
81 public: 49 public:
82 explicit TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) 50 explicit TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page)
83 : interstitial_page_(interstitial_page) {} 51 : interstitial_page_(interstitial_page) {}
84 void CommandReceived(const std::string& command) override; 52 void CommandReceived(const std::string& command) override;
85 std::string GetHTMLContents() override { return std::string(); } 53 std::string GetHTMLContents() override { return std::string(); }
86 void OnDontProceed() override; 54 void OnDontProceed() override;
87 void OnProceed() override; 55 void OnProceed() override;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 219 }
252 220
253 private: 221 private:
254 bool assign_site_for_url_; 222 bool assign_site_for_url_;
255 }; 223 };
256 224
257 class WebContentsImplTest : public RenderViewHostImplTestHarness { 225 class WebContentsImplTest : public RenderViewHostImplTestHarness {
258 public: 226 public:
259 void SetUp() override { 227 void SetUp() override {
260 RenderViewHostImplTestHarness::SetUp(); 228 RenderViewHostImplTestHarness::SetUp();
261 WebUIControllerFactory::RegisterFactory(&factory_); 229 WebUIControllerFactory::RegisterFactory(
230 ContentWebUIControllerFactory::GetInstance());
davidben 2015/05/09 00:31:05 It does seem slightly off that we're pulling in th
262 } 231 }
263 232
264 void TearDown() override { 233 void TearDown() override {
265 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); 234 WebUIControllerFactory::UnregisterFactoryForTesting(
235 ContentWebUIControllerFactory::GetInstance());
266 RenderViewHostImplTestHarness::TearDown(); 236 RenderViewHostImplTestHarness::TearDown();
267 } 237 }
268
269 private:
270 WebContentsImplTestWebUIControllerFactory factory_;
271 }; 238 };
272 239
273 class TestWebContentsObserver : public WebContentsObserver { 240 class TestWebContentsObserver : public WebContentsObserver {
274 public: 241 public:
275 explicit TestWebContentsObserver(WebContents* contents) 242 explicit TestWebContentsObserver(WebContents* contents)
276 : WebContentsObserver(contents) { 243 : WebContentsObserver(contents) {
277 } 244 }
278 ~TestWebContentsObserver() override {} 245 ~TestWebContentsObserver() override {}
279 246
280 void DidFinishLoad(RenderFrameHost* render_frame_host, 247 void DidFinishLoad(RenderFrameHost* render_frame_host,
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1008 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1042 SiteInstance* instance2 = contents()->GetSiteInstance(); 1009 SiteInstance* instance2 = contents()->GetSiteInstance();
1043 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1010 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1044 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1011 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1045 EXPECT_EQ(instance1, instance2); 1012 EXPECT_EQ(instance1, instance2);
1046 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); 1013 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame());
1047 } 1014 }
1048 1015
1049 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1016 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1050 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1017 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1051 const GURL url1("chrome://blah"); 1018 const GURL url1("chrome://gpu");
1052 controller().LoadURL( 1019 controller().LoadURL(
1053 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1020 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1054 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); 1021 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame();
1055 ntp_rfh->PrepareForCommit(); 1022 ntp_rfh->PrepareForCommit();
1056 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED); 1023 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED);
1057 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1024 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1058 SiteInstance* instance1 = contents()->GetSiteInstance(); 1025 SiteInstance* instance1 = contents()->GetSiteInstance();
1059 1026
1060 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1027 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1061 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); 1028 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 orig_rfh->PrepareForCommit(); 1147 orig_rfh->PrepareForCommit();
1181 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1148 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1182 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1149 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1183 } 1150 }
1184 1151
1185 // Test that a cross-site navigation is not preempted if the previous 1152 // Test that a cross-site navigation is not preempted if the previous
1186 // renderer sends a FrameNavigate message just before being told to stop. 1153 // renderer sends a FrameNavigate message just before being told to stop.
1187 // We should only preempt the cross-site navigation if the previous renderer 1154 // We should only preempt the cross-site navigation if the previous renderer
1188 // has started a new navigation. See http://crbug.com/79176. 1155 // has started a new navigation. See http://crbug.com/79176.
1189 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1156 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1190 // Navigate to NTP URL. 1157 // Navigate to WebUI URL.
1191 const GURL url("chrome://blah"); 1158 const GURL url("chrome://gpu");
1192 controller().LoadURL( 1159 controller().LoadURL(
1193 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1160 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1194 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1161 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1195 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1162 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1196 1163
1197 // Navigate to new site, with the beforeunload request in flight. 1164 // Navigate to new site, with the beforeunload request in flight.
1198 const GURL url2("http://www.yahoo.com"); 1165 const GURL url2("http://www.yahoo.com");
1199 controller().LoadURL( 1166 controller().LoadURL(
1200 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1167 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1201 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1168 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
1202 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1169 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1203 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1170 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1204 1171
1205 // Suppose the first navigation tries to commit now, with a 1172 // Suppose the first navigation tries to commit now, with a
1206 // FrameMsg_Stop in flight. This should not cancel the pending navigation, 1173 // FrameMsg_Stop in flight. This should not cancel the pending navigation,
1207 // but it should act as if the beforeunload ack arrived. 1174 // but it should act as if the beforeunload ack arrived.
1208 orig_rfh->SendNavigate(1, GURL("chrome://blah")); 1175 orig_rfh->SendNavigate(1, GURL("chrome://gpu"));
1209 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1176 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1210 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1177 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1211 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1178 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1212 1179
1213 // The pending navigation should be able to commit successfully. 1180 // The pending navigation should be able to commit successfully.
1214 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1181 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1215 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1182 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1216 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1183 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
1217 } 1184 }
1218 1185
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2659 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2693 2660
2694 scoped_ptr<TestWebContents> contents( 2661 scoped_ptr<TestWebContents> contents(
2695 TestWebContents::Create(browser_context(), instance.get())); 2662 TestWebContents::Create(browser_context(), instance.get()));
2696 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2663 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2697 2664
2698 // Navigate to a URL. 2665 // Navigate to a URL.
2699 contents->NavigateAndCommit(GURL("http://a.com")); 2666 contents->NavigateAndCommit(GURL("http://a.com"));
2700 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2667 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2701 2668
2669 // Navigate to a URL which sort of looks like a chrome:// url.
2670 contents->NavigateAndCommit(GURL("http://gpu"));
2671 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2672
2702 // Navigate to a URL with WebUI. This will change BrowsingInstances. 2673 // Navigate to a URL with WebUI. This will change BrowsingInstances.
2703 const GURL kWebUIUrl = GURL(kTestWebUIUrl); 2674 const GURL kWebUIUrl = GURL("chrome://gpu");
2704 contents->GetController().LoadURL(kWebUIUrl, 2675 contents->GetController().LoadURL(kWebUIUrl,
2705 Referrer(), 2676 Referrer(),
2706 ui::PAGE_TRANSITION_TYPED, 2677 ui::PAGE_TRANSITION_TYPED,
2707 std::string()); 2678 std::string());
2708 contents->GetMainFrame()->PrepareForCommit(); 2679 contents->GetMainFrame()->PrepareForCommit();
2709 EXPECT_TRUE(contents->CrossProcessNavigationPending()); 2680 EXPECT_TRUE(contents->CrossProcessNavigationPending());
2710 scoped_refptr<SiteInstance> instance_webui( 2681 scoped_refptr<SiteInstance> instance_webui(
2711 contents->GetPendingMainFrame()->GetSiteInstance()); 2682 contents->GetPendingMainFrame()->GetSiteInstance());
2712 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); 2683 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get()));
2713 2684
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
3029 3000
3030 // Crash the renderer. 3001 // Crash the renderer.
3031 contents()->GetMainFrame()->GetProcess()->SimulateCrash(); 3002 contents()->GetMainFrame()->GetProcess()->SimulateCrash();
3032 3003
3033 // Verify that all the power save blockers have been released. 3004 // Verify that all the power save blockers have been released.
3034 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3005 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3035 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3006 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3036 } 3007 }
3037 3008
3038 } // namespace content 3009 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698