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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 1352813006: Move WebUI ownership from the RenderFrameHostManager to the RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed header comments. Created 5 years, 1 month 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h " 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} 74 ~RenderFrameHostManagerTestWebUIControllerFactory() override {}
75 75
76 void set_should_create_webui(bool should_create_webui) { 76 void set_should_create_webui(bool should_create_webui) {
77 should_create_webui_ = should_create_webui; 77 should_create_webui_ = should_create_webui;
78 } 78 }
79 79
80 // WebUIFactory implementation. 80 // WebUIFactory implementation.
81 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, 81 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui,
82 const GURL& url) const override { 82 const GURL& url) const override {
83 if (!(should_create_webui_ && HasWebUIScheme(url))) 83 // If WebUI creation is enabled for the test and this is a WebUI URL,
84 return NULL; 84 // returns a new instance.
85 return new WebUIController(web_ui); 85 if (should_create_webui_ && HasWebUIScheme(url))
86 return new WebUIController(web_ui);
87 return nullptr;
86 } 88 }
87 89
88 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, 90 WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
89 const GURL& url) const override { 91 const GURL& url) const override {
92 // If WebUI creation is enabled for the test and this is a WebUI URL,
93 // returns a mock WebUI type.
94 if (should_create_webui_ && HasWebUIScheme(url)) {
95 return const_cast<RenderFrameHostManagerTestWebUIControllerFactory*>(
96 this);
97 }
90 return WebUI::kNoWebUI; 98 return WebUI::kNoWebUI;
91 } 99 }
92 100
93 bool UseWebUIForURL(BrowserContext* browser_context, 101 bool UseWebUIForURL(BrowserContext* browser_context,
94 const GURL& url) const override { 102 const GURL& url) const override {
95 return HasWebUIScheme(url); 103 return HasWebUIScheme(url);
96 } 104 }
97 105
98 bool UseWebUIBindingsForURL(BrowserContext* browser_context, 106 bool UseWebUIBindingsForURL(BrowserContext* browser_context,
99 const GURL& url) const override { 107 const GURL& url) const override {
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1116
1109 // It's important that the SiteInstance get set on the Web UI page as soon 1117 // It's important that the SiteInstance get set on the Web UI page as soon
1110 // as the navigation starts, rather than lazily after it commits, so we don't 1118 // as the navigation starts, rather than lazily after it commits, so we don't
1111 // try to re-use the SiteInstance/process for non Web UI things that may 1119 // try to re-use the SiteInstance/process for non Web UI things that may
1112 // get loaded in between. 1120 // get loaded in between.
1113 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); 1121 EXPECT_TRUE(host->GetSiteInstance()->HasSite());
1114 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); 1122 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL());
1115 1123
1116 // The Web UI is committed immediately because the RenderViewHost has not been 1124 // The Web UI is committed immediately because the RenderViewHost has not been
1117 // used yet. UpdateStateForNavigate() took the short cut path. 1125 // used yet. UpdateStateForNavigate() took the short cut path.
1118 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1126 EXPECT_FALSE(manager->GetNavigatingWebUI());
1119 switches::kEnableBrowserSideNavigation)) {
1120 EXPECT_FALSE(manager->speculative_web_ui());
1121 } else {
1122 EXPECT_FALSE(manager->pending_web_ui());
1123 }
1124 EXPECT_TRUE(manager->web_ui()); 1127 EXPECT_TRUE(manager->web_ui());
1125 1128
1126 // Commit. 1129 // Commit.
1127 manager->DidNavigateFrame(host, true); 1130 manager->DidNavigateFrame(host, true);
1128 EXPECT_TRUE( 1131 EXPECT_TRUE(
1129 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1132 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1130 } 1133 }
1131 1134
1132 // Tests that we can open a WebUI link in a new tab from a WebUI page and still 1135 // Tests that we can open a WebUI link in a new tab from a WebUI page and still
1133 // grant the correct bindings. http://crbug.com/189101. 1136 // grant the correct bindings. http://crbug.com/189101.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 const GURL kUrl2("chrome://foo/bar"); 1186 const GURL kUrl2("chrome://foo/bar");
1184 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 1187 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
1185 Referrer(), base::string16() /* title */, 1188 Referrer(), base::string16() /* title */,
1186 ui::PAGE_TRANSITION_LINK, 1189 ui::PAGE_TRANSITION_LINK,
1187 true /* is_renderer_init */); 1190 true /* is_renderer_init */);
1188 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); 1191 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2);
1189 1192
1190 // No cross-process transition happens because we are already in the right 1193 // No cross-process transition happens because we are already in the right
1191 // SiteInstance. We should grant bindings immediately. 1194 // SiteInstance. We should grant bindings immediately.
1192 EXPECT_EQ(host2, manager2->current_frame_host()); 1195 EXPECT_EQ(host2, manager2->current_frame_host());
1193 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1196 EXPECT_TRUE(manager2->GetNavigatingWebUI());
1194 switches::kEnableBrowserSideNavigation)) {
1195 EXPECT_TRUE(manager2->speculative_web_ui());
1196 } else {
1197 EXPECT_TRUE(manager2->pending_web_ui());
1198 }
1199 EXPECT_TRUE( 1197 EXPECT_TRUE(
1200 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1198 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1201 1199
1202 manager2->DidNavigateFrame(host2, true); 1200 manager2->DidNavigateFrame(host2, true);
1203 } 1201 }
1204 1202
1205 // Tests that a WebUI is correctly reused between chrome:// pages. 1203 // Tests that a WebUI is correctly reused between chrome:// pages.
1206 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { 1204 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) {
1207 set_should_create_webui(true); 1205 set_should_create_webui(true);
1208 1206
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
2649 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); 2647 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance());
2650 EXPECT_TRUE(proxy); 2648 EXPECT_TRUE(proxy);
2651 2649
2652 // Since the B->C navigation happened while the current page was focused, 2650 // Since the B->C navigation happened while the current page was focused,
2653 // page focus should propagate to the new subframe process. Check that 2651 // page focus should propagate to the new subframe process. Check that
2654 // process C received the proper focus message. 2652 // process C received the proper focus message.
2655 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); 2653 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID());
2656 } 2654 }
2657 2655
2658 } // namespace content 2656 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698