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

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

Issue 1472703004: Reland #2 of: Move WebUI ownership from the RenderFrameHostManager to the RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests simulatneous navigation involving WebUIs; minor test improvements. Created 5 years 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 20 matching lines...) Expand all
31 #include "content/public/browser/web_contents_observer.h" 31 #include "content/public/browser/web_contents_observer.h"
32 #include "content/public/browser/web_ui_controller.h" 32 #include "content/public/browser/web_ui_controller.h"
33 #include "content/public/common/bindings_policy.h" 33 #include "content/public/common/bindings_policy.h"
34 #include "content/public/common/content_switches.h" 34 #include "content/public/common/content_switches.h"
35 #include "content/public/common/javascript_message_type.h" 35 #include "content/public/common/javascript_message_type.h"
36 #include "content/public/common/url_constants.h" 36 #include "content/public/common/url_constants.h"
37 #include "content/public/common/url_utils.h" 37 #include "content/public/common/url_utils.h"
38 #include "content/public/test/mock_render_process_host.h" 38 #include "content/public/test/mock_render_process_host.h"
39 #include "content/public/test/test_notification_tracker.h" 39 #include "content/public/test/test_notification_tracker.h"
40 #include "content/public/test/test_utils.h" 40 #include "content/public/test/test_utils.h"
41 #include "content/test/browser_side_navigation_test_utils.h"
41 #include "content/test/test_content_browser_client.h" 42 #include "content/test/test_content_browser_client.h"
42 #include "content/test/test_content_client.h" 43 #include "content/test/test_content_client.h"
43 #include "content/test/test_render_frame_host.h" 44 #include "content/test/test_render_frame_host.h"
44 #include "content/test/test_render_view_host.h" 45 #include "content/test/test_render_view_host.h"
45 #include "content/test/test_web_contents.h" 46 #include "content/test/test_web_contents.h"
46 #include "net/base/load_flags.h" 47 #include "net/base/load_flags.h"
47 #include "testing/gtest/include/gtest/gtest.h" 48 #include "testing/gtest/include/gtest/gtest.h"
48 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" 49 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h"
49 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 50 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
50 #include "ui/base/page_transition_types.h" 51 #include "ui/base/page_transition_types.h"
(...skipping 12 matching lines...) Expand all
63 EXPECT_EQ(expected_routing_id, message->routing_id()); 64 EXPECT_EQ(expected_routing_id, message->routing_id());
64 InputMsg_SetFocus::Param params; 65 InputMsg_SetFocus::Param params;
65 EXPECT_TRUE(InputMsg_SetFocus::Read(message, &params)); 66 EXPECT_TRUE(InputMsg_SetFocus::Read(message, &params));
66 EXPECT_EQ(expected_focus, base::get<0>(params)); 67 EXPECT_EQ(expected_focus, base::get<0>(params));
67 } 68 }
68 69
69 class RenderFrameHostManagerTestWebUIControllerFactory 70 class RenderFrameHostManagerTestWebUIControllerFactory
70 : public WebUIControllerFactory { 71 : public WebUIControllerFactory {
71 public: 72 public:
72 RenderFrameHostManagerTestWebUIControllerFactory() 73 RenderFrameHostManagerTestWebUIControllerFactory()
73 : should_create_webui_(false) { 74 : should_create_webui_(false), type_(1) {
75 CHECK_NE(reinterpret_cast<WebUI::TypeID>(type_), WebUI::kNoWebUI);
74 } 76 }
75 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} 77 ~RenderFrameHostManagerTestWebUIControllerFactory() override {}
76 78
77 void set_should_create_webui(bool should_create_webui) { 79 void set_should_create_webui(bool should_create_webui) {
78 should_create_webui_ = should_create_webui; 80 should_create_webui_ = should_create_webui;
79 } 81 }
80 82
83 // This method simulates the expectation that different WebUI instance types
84 // would be created. The |type| value will be returned by GetWebUIType casted
85 // to WebUI::TypeID.
86 // As WebUI::TypeID is a typedef to void pointer, factory implementations
87 // return values that they know to be unique to their respective cases. So
88 // values set here should be safe if kept very low (just above zero).
89 void set_webui_type(uintptr_t type) {
90 CHECK_NE(reinterpret_cast<WebUI::TypeID>(type), WebUI::kNoWebUI);
91 type_ = type;
92 }
93
81 // WebUIFactory implementation. 94 // WebUIFactory implementation.
82 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, 95 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui,
83 const GURL& url) const override { 96 const GURL& url) const override {
84 if (!(should_create_webui_ && HasWebUIScheme(url))) 97 // If WebUI creation is enabled for the test and this is a WebUI URL,
85 return NULL; 98 // returns a new instance.
86 return new WebUIController(web_ui); 99 if (should_create_webui_ && HasWebUIScheme(url))
100 return new WebUIController(web_ui);
101 return nullptr;
87 } 102 }
88 103
89 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, 104 WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
90 const GURL& url) const override { 105 const GURL& url) const override {
106 // If WebUI creation is enabled for the test and this is a WebUI URL,
107 // returns a mock WebUI type.
108 if (should_create_webui_ && HasWebUIScheme(url)) {
109 return reinterpret_cast<WebUI::TypeID>(type_);
110 }
91 return WebUI::kNoWebUI; 111 return WebUI::kNoWebUI;
92 } 112 }
93 113
94 bool UseWebUIForURL(BrowserContext* browser_context, 114 bool UseWebUIForURL(BrowserContext* browser_context,
95 const GURL& url) const override { 115 const GURL& url) const override {
96 return HasWebUIScheme(url); 116 return HasWebUIScheme(url);
97 } 117 }
98 118
99 bool UseWebUIBindingsForURL(BrowserContext* browser_context, 119 bool UseWebUIBindingsForURL(BrowserContext* browser_context,
100 const GURL& url) const override { 120 const GURL& url) const override {
101 return HasWebUIScheme(url); 121 return HasWebUIScheme(url);
102 } 122 }
103 123
104 private: 124 private:
105 bool should_create_webui_; 125 bool should_create_webui_;
126 uintptr_t type_;
106 127
107 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); 128 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory);
108 }; 129 };
109 130
110 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { 131 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate {
111 public: 132 public:
112 BeforeUnloadFiredWebContentsDelegate() {} 133 BeforeUnloadFiredWebContentsDelegate() {}
113 ~BeforeUnloadFiredWebContentsDelegate() override {} 134 ~BeforeUnloadFiredWebContentsDelegate() override {}
114 135
115 void BeforeUnloadFired(WebContents* web_contents, 136 void BeforeUnloadFired(WebContents* web_contents,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it 294 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it
274 // must be shut down before the ImageTransportFactory. 295 // must be shut down before the ImageTransportFactory.
275 ImageTransportFactory::Terminate(); 296 ImageTransportFactory::Terminate();
276 #endif 297 #endif
277 } 298 }
278 299
279 void set_should_create_webui(bool should_create_webui) { 300 void set_should_create_webui(bool should_create_webui) {
280 factory_.set_should_create_webui(should_create_webui); 301 factory_.set_should_create_webui(should_create_webui);
281 } 302 }
282 303
304 void set_webui_type(int type) { factory_.set_webui_type(type); }
305
283 void NavigateActiveAndCommit(const GURL& url) { 306 void NavigateActiveAndCommit(const GURL& url) {
284 // Note: we navigate the active RenderFrameHost because previous navigations 307 // Note: we navigate the active RenderFrameHost because previous navigations
285 // won't have committed yet, so NavigateAndCommit does the wrong thing 308 // won't have committed yet, so NavigateAndCommit does the wrong thing
286 // for us. 309 // for us.
287 controller().LoadURL( 310 controller().LoadURL(
288 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 311 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
289 int entry_id = controller().GetPendingEntry()->GetUniqueID(); 312 int entry_id = controller().GetPendingEntry()->GetUniqueID();
290 313
291 // Simulate the BeforeUnload_ACK that is received from the current renderer 314 // Simulate the BeforeUnload_ACK that is received from the current renderer
292 // for a cross-site navigation. 315 // for a cross-site navigation.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 427
405 // Returns the RenderFrameHost that should be used in the navigation to 428 // Returns the RenderFrameHost that should be used in the navigation to
406 // |entry|. 429 // |entry|.
407 RenderFrameHostImpl* NavigateToEntry( 430 RenderFrameHostImpl* NavigateToEntry(
408 RenderFrameHostManager* manager, 431 RenderFrameHostManager* manager,
409 const NavigationEntryImpl& entry) { 432 const NavigationEntryImpl& entry) {
410 // Tests currently only navigate using main frame FrameNavigationEntries. 433 // Tests currently only navigate using main frame FrameNavigationEntries.
411 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); 434 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
412 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 435 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
413 switches::kEnableBrowserSideNavigation)) { 436 switches::kEnableBrowserSideNavigation)) {
437 NavigationControllerImpl* controller =
438 static_cast<NavigationControllerImpl*>(manager->current_frame_host()
439 ->frame_tree_node()
440 ->navigator()
441 ->GetController());
442 // TODO(carlosk): This implementation below will not work with restore
443 // navigations. Method GetNavigationType should be exposed from
444 // navigator_impl.cc and used here to determine FrameMsg_Navigate_Type.
445 CHECK(entry.restore_type() == NavigationEntryImpl::RESTORE_NONE);
414 scoped_ptr<NavigationRequest> navigation_request = 446 scoped_ptr<NavigationRequest> navigation_request =
415 NavigationRequest::CreateBrowserInitiated( 447 NavigationRequest::CreateBrowserInitiated(
416 manager->frame_tree_node_, frame_entry->url(), 448 manager->frame_tree_node_, frame_entry->url(),
417 frame_entry->referrer(), *frame_entry, entry, 449 frame_entry->referrer(), *frame_entry, entry,
418 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), 450 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
419 static_cast<NavigationControllerImpl*>(&controller())); 451 controller);
452
453 // Simulates request creation that triggers the 1st internal call to
454 // GetFrameHostForNavigation.
455 manager->DidCreateNavigationRequest(*navigation_request);
456
457 // And also simulates the 2nd and final call to GetFrameHostForNavigation
458 // that determines the final frame that will commit the navigation.
420 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( 459 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>(
421 manager->GetFrameHostForNavigation(*navigation_request)); 460 manager->GetFrameHostForNavigation(*navigation_request));
422 CHECK(frame_host); 461 CHECK(frame_host);
423 frame_host->set_pending_commit(true); 462 frame_host->set_pending_commit(true);
424 return frame_host; 463 return frame_host;
425 } 464 }
426 465
427 return manager->Navigate(frame_entry->url(), *frame_entry, entry); 466 return manager->Navigate(frame_entry->url(), *frame_entry, entry);
428 } 467 }
429 468
(...skipping 10 matching lines...) Expand all
440 479
441 // Exposes RenderFrameHostManager::CollectOpenerFrameTrees for testing. 480 // Exposes RenderFrameHostManager::CollectOpenerFrameTrees for testing.
442 void CollectOpenerFrameTrees( 481 void CollectOpenerFrameTrees(
443 FrameTreeNode* node, 482 FrameTreeNode* node,
444 std::vector<FrameTree*>* opener_frame_trees, 483 std::vector<FrameTree*>* opener_frame_trees,
445 base::hash_set<FrameTreeNode*>* nodes_with_back_links) { 484 base::hash_set<FrameTreeNode*>* nodes_with_back_links) {
446 node->render_manager()->CollectOpenerFrameTrees(opener_frame_trees, 485 node->render_manager()->CollectOpenerFrameTrees(opener_frame_trees,
447 nodes_with_back_links); 486 nodes_with_back_links);
448 } 487 }
449 488
489 void BaseSimultaneousNavigationWithOneWebUI(RenderFrameHostImpl*& host1,
490 RenderFrameHostImpl*& host2,
491 WebUIImpl*& web_ui,
492 RenderFrameHostManager*& manager);
493
494 void BaseSimultaneousNavigationWithTwoWebUIs(
495 RenderFrameHostImpl*& host1,
496 RenderFrameHostImpl*& host2,
497 WebUIImpl*& web_ui1,
498 WebUIImpl*& web_ui2,
499 RenderFrameHostManager*& manager);
500
450 private: 501 private:
451 RenderFrameHostManagerTestWebUIControllerFactory factory_; 502 RenderFrameHostManagerTestWebUIControllerFactory factory_;
452 }; 503 };
453 504
454 // Tests that when you navigate from a chrome:// url to another page, and 505 // Tests that when you navigate from a chrome:// url to another page, and
455 // then do that same thing in another tab, that the two resulting pages have 506 // then do that same thing in another tab, that the two resulting pages have
456 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 507 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
457 // a regression test for bug 9364. 508 // a regression test for bug 9364.
458 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { 509 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
459 set_should_create_webui(true); 510 set_should_create_webui(true);
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 TEST_F(RenderFrameHostManagerTest, WebUI) { 1133 TEST_F(RenderFrameHostManagerTest, WebUI) {
1083 set_should_create_webui(true); 1134 set_should_create_webui(true);
1084 SiteInstance* instance = SiteInstance::Create(browser_context()); 1135 SiteInstance* instance = SiteInstance::Create(browser_context());
1085 1136
1086 scoped_ptr<TestWebContents> web_contents( 1137 scoped_ptr<TestWebContents> web_contents(
1087 TestWebContents::Create(browser_context(), instance)); 1138 TestWebContents::Create(browser_context(), instance));
1088 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); 1139 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1089 RenderFrameHostImpl* initial_rfh = manager->current_frame_host(); 1140 RenderFrameHostImpl* initial_rfh = manager->current_frame_host();
1090 1141
1091 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); 1142 EXPECT_FALSE(manager->current_host()->IsRenderViewLive());
1092 EXPECT_FALSE(manager->web_ui()); 1143 EXPECT_FALSE(manager->current_frame_host()->web_ui());
1093 EXPECT_TRUE(initial_rfh); 1144 EXPECT_TRUE(initial_rfh);
1094 1145
1095 const GURL kUrl("chrome://foo"); 1146 const GURL kUrl("chrome://foo");
1096 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, 1147 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
1097 Referrer(), base::string16() /* title */, 1148 Referrer(), base::string16() /* title */,
1098 ui::PAGE_TRANSITION_TYPED, 1149 ui::PAGE_TRANSITION_TYPED,
1099 false /* is_renderer_init */); 1150 false /* is_renderer_init */);
1100 RenderFrameHostImpl* host = NavigateToEntry(manager, entry); 1151 RenderFrameHostImpl* host = NavigateToEntry(manager, entry);
1101 1152
1102 // We commit the pending RenderFrameHost immediately because the previous 1153 // We commit the pending RenderFrameHost immediately because the previous
1103 // RenderFrameHost was not live. We test a case where it is live in 1154 // RenderFrameHost was not live. We test a case where it is live in
1104 // WebUIInNewTab. 1155 // WebUIInNewTab.
1105 EXPECT_TRUE(host); 1156 EXPECT_TRUE(host);
1106 EXPECT_NE(initial_rfh, host); 1157 EXPECT_NE(initial_rfh, host);
1107 EXPECT_EQ(host, manager->current_frame_host()); 1158 EXPECT_EQ(host, manager->current_frame_host());
1108 EXPECT_FALSE(GetPendingFrameHost(manager)); 1159 EXPECT_FALSE(GetPendingFrameHost(manager));
1109 1160
1110 // It's important that the SiteInstance get set on the Web UI page as soon 1161 // It's important that the SiteInstance get set on the Web UI page as soon
1111 // as the navigation starts, rather than lazily after it commits, so we don't 1162 // as the navigation starts, rather than lazily after it commits, so we don't
1112 // try to re-use the SiteInstance/process for non Web UI things that may 1163 // try to re-use the SiteInstance/process for non Web UI things that may
1113 // get loaded in between. 1164 // get loaded in between.
1114 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); 1165 EXPECT_TRUE(host->GetSiteInstance()->HasSite());
1115 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); 1166 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL());
1116 1167
1117 // The Web UI is committed immediately because the RenderViewHost has not been 1168 // The Web UI is committed immediately because the RenderViewHost has not been
1118 // used yet. UpdateStateForNavigate() took the short cut path. 1169 // used yet. UpdateStateForNavigate() took the short cut path.
1119 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1170 EXPECT_FALSE(manager->GetNavigatingWebUI());
1120 switches::kEnableBrowserSideNavigation)) { 1171 EXPECT_TRUE(manager->current_frame_host()->web_ui());
1121 EXPECT_FALSE(manager->speculative_web_ui());
1122 } else {
1123 EXPECT_FALSE(manager->pending_web_ui());
1124 }
1125 EXPECT_TRUE(manager->web_ui());
1126 1172
1127 // Commit. 1173 // Commit.
1128 manager->DidNavigateFrame(host, true); 1174 manager->DidNavigateFrame(host, true);
1129 EXPECT_TRUE( 1175 EXPECT_TRUE(
1130 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1176 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1131 } 1177 }
1132 1178
1133 // Tests that we can open a WebUI link in a new tab from a WebUI page and still 1179 // Tests that we can open a WebUI link in a new tab from a WebUI page and still
1134 // grant the correct bindings. http://crbug.com/189101. 1180 // grant the correct bindings. http://crbug.com/189101.
1135 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { 1181 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 const GURL kUrl2("chrome://foo/bar"); 1230 const GURL kUrl2("chrome://foo/bar");
1185 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 1231 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
1186 Referrer(), base::string16() /* title */, 1232 Referrer(), base::string16() /* title */,
1187 ui::PAGE_TRANSITION_LINK, 1233 ui::PAGE_TRANSITION_LINK,
1188 true /* is_renderer_init */); 1234 true /* is_renderer_init */);
1189 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); 1235 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2);
1190 1236
1191 // No cross-process transition happens because we are already in the right 1237 // No cross-process transition happens because we are already in the right
1192 // SiteInstance. We should grant bindings immediately. 1238 // SiteInstance. We should grant bindings immediately.
1193 EXPECT_EQ(host2, manager2->current_frame_host()); 1239 EXPECT_EQ(host2, manager2->current_frame_host());
1194 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1240 EXPECT_TRUE(manager2->GetNavigatingWebUI());
1195 switches::kEnableBrowserSideNavigation)) { 1241 EXPECT_FALSE(host2->web_ui());
1196 EXPECT_TRUE(manager2->speculative_web_ui());
1197 } else {
1198 EXPECT_TRUE(manager2->pending_web_ui());
1199 }
1200 EXPECT_TRUE( 1242 EXPECT_TRUE(
1201 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1243 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1202 1244
1203 manager2->DidNavigateFrame(host2, true); 1245 manager2->DidNavigateFrame(host2, true);
1204 } 1246 }
1205 1247
1206 // Tests that a WebUI is correctly reused between chrome:// pages. 1248 // Tests that a WebUI is correctly reused between chrome:// pages.
1207 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { 1249 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) {
1208 set_should_create_webui(true); 1250 set_should_create_webui(true);
1209 1251
1210 // Navigate to a WebUI page. 1252 // Navigate to a WebUI page.
1211 const GURL kUrl1("chrome://foo"); 1253 const GURL kUrl1("chrome://foo");
1212 contents()->NavigateAndCommit(kUrl1); 1254 contents()->NavigateAndCommit(kUrl1);
1213 RenderFrameHostManager* manager = 1255 WebUIImpl* web_ui = main_test_rfh()->web_ui();
1214 main_test_rfh()->frame_tree_node()->render_manager();
1215 WebUIImpl* web_ui = manager->web_ui();
1216 EXPECT_TRUE(web_ui); 1256 EXPECT_TRUE(web_ui);
1217 1257
1218 // Navigate to another WebUI page which should be same-site and keep the 1258 // Navigate to another WebUI page which should be same-site and keep the
1219 // current WebUI. 1259 // current WebUI.
1220 const GURL kUrl2("chrome://foo/bar"); 1260 const GURL kUrl2("chrome://foo/bar");
1221 contents()->NavigateAndCommit(kUrl2); 1261 contents()->NavigateAndCommit(kUrl2);
1222 EXPECT_EQ(web_ui, manager->web_ui()); 1262 EXPECT_EQ(web_ui, main_test_rfh()->web_ui());
1223 } 1263 }
1224 1264
1225 // Tests that a WebUI is correctly cleaned up when navigating from a chrome:// 1265 // Tests that a WebUI is correctly cleaned up when navigating from a chrome://
1226 // page to a non-chrome:// page. 1266 // page to a non-chrome:// page.
1227 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) { 1267 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) {
1228 set_should_create_webui(true); 1268 set_should_create_webui(true);
1229 1269
1230 // Navigate to a WebUI page. 1270 // Navigate to a WebUI page.
1231 const GURL kUrl1("chrome://foo"); 1271 const GURL kUrl1("chrome://foo");
1232 contents()->NavigateAndCommit(kUrl1); 1272 contents()->NavigateAndCommit(kUrl1);
1233 EXPECT_TRUE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui()); 1273 EXPECT_TRUE(main_test_rfh()->web_ui());
1234 1274
1235 // Navigate to a non-WebUI page. 1275 // Navigate to a non-WebUI page.
1236 const GURL kUrl2("http://www.google.com"); 1276 const GURL kUrl2("http://www.google.com");
1237 contents()->NavigateAndCommit(kUrl2); 1277 contents()->NavigateAndCommit(kUrl2);
1238 EXPECT_FALSE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui()); 1278 EXPECT_FALSE(main_test_rfh()->web_ui());
1239 } 1279 }
1240 1280
1241 // Tests that we don't end up in an inconsistent state if a page does a back and 1281 // Tests that we don't end up in an inconsistent state if a page does a back and
1242 // then reload. http://crbug.com/51680 1282 // then reload. http://crbug.com/51680
1243 // Also tests that only user-gesture navigations can interrupt cross-process 1283 // Also tests that only user-gesture navigations can interrupt cross-process
1244 // navigations. http://crbug.com/75195 1284 // navigations. http://crbug.com/75195
1245 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { 1285 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) {
1246 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1286 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1247 switches::kEnableBrowserSideNavigation)) { 1287 switches::kEnableBrowserSideNavigation)) {
1248 // PlzNavigate uses a significantly different logic for renderer initiated 1288 // PlzNavigate uses a significantly different logic for renderer initiated
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 RenderFrameProxyHost* proxy = 2695 RenderFrameProxyHost* proxy =
2656 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); 2696 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance());
2657 EXPECT_TRUE(proxy); 2697 EXPECT_TRUE(proxy);
2658 2698
2659 // Since the B->C navigation happened while the current page was focused, 2699 // Since the B->C navigation happened while the current page was focused,
2660 // page focus should propagate to the new subframe process. Check that 2700 // page focus should propagate to the new subframe process. Check that
2661 // process C received the proper focus message. 2701 // process C received the proper focus message.
2662 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); 2702 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID());
2663 } 2703 }
2664 2704
2705 // Checks that a restore navigation to a WebUI works.
2706 TEST_F(RenderFrameHostManagerTest, RestoreNavigationToWebUI) {
2707 set_should_create_webui(true);
2708
2709 const GURL kInitUrl("chrome://foo/");
2710 SiteInstanceImpl* initial_instance =
2711 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context()));
2712 initial_instance->SetSite(kInitUrl);
2713 scoped_ptr<TestWebContents> web_contents(
2714 TestWebContents::Create(browser_context(), initial_instance));
2715 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
2716 NavigationControllerImpl& controller = web_contents->GetController();
2717
2718 // Setup a restored entry.
2719 std::vector<scoped_ptr<NavigationEntry>> entries;
2720 scoped_ptr<NavigationEntry> new_entry =
2721 NavigationControllerImpl::CreateNavigationEntry(
2722 kInitUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, false, std::string(),
2723 browser_context());
2724 new_entry->SetPageID(0);
2725 entries.push_back(new_entry.Pass());
2726 controller.Restore(
2727 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries);
2728 ASSERT_EQ(0u, entries.size());
2729 ASSERT_EQ(1, controller.GetEntryCount());
2730
2731 RenderFrameHostImpl* initial_host = manager->current_frame_host();
2732 ASSERT_TRUE(initial_host);
2733 EXPECT_FALSE(initial_host->IsRenderFrameLive());
2734 EXPECT_FALSE(initial_host->web_ui());
2735
2736 // Navigation request to an entry from a previous browsing session.
2737 NavigationEntryImpl entry(nullptr /* instance */, 0 /* page_id */, kInitUrl,
2738 Referrer(), base::string16() /* title */,
2739 ui::PAGE_TRANSITION_RELOAD,
2740 false /* is_renderer_init */);
2741 entry.set_restore_type(
2742 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY);
2743 NavigateToEntry(manager, entry);
2744
2745 // As the initial renderer was not live, the new RenderFrameHost should be
2746 // made immediately active at request time.
2747 EXPECT_FALSE(GetPendingFrameHost(manager));
2748 RenderFrameHostImpl* current_host = manager->current_frame_host();
2749 ASSERT_TRUE(current_host);
2750 EXPECT_EQ(current_host, initial_host);
2751 EXPECT_TRUE(current_host->IsRenderFrameLive());
2752 WebUIImpl* web_ui = manager->GetNavigatingWebUI();
2753 EXPECT_TRUE(web_ui);
2754 EXPECT_EQ(web_ui, current_host->pending_web_ui());
2755 EXPECT_FALSE(current_host->web_ui());
2756
2757 // The RenderFrameHost committed.
2758 manager->DidNavigateFrame(current_host, true);
2759 EXPECT_EQ(current_host, manager->current_frame_host());
2760 EXPECT_EQ(web_ui, current_host->web_ui());
2761 EXPECT_FALSE(current_host->pending_web_ui());
2762 }
2763
2764 // Shared code for the SimultaneousNavigationWithOneWebUI* tests, going until
2765 // right before commit.
2766 void RenderFrameHostManagerTest::BaseSimultaneousNavigationWithOneWebUI(
2767 RenderFrameHostImpl*& host1,
nasko 2015/11/25 22:15:50 This is a strange parameter convention and disallo
Charlie Reis 2015/11/26 07:02:51 Agreed that this is awkward. You might consider u
carlosk 2015/11/26 10:58:02 Done. And lambdas are sweet! :)
2768 RenderFrameHostImpl*& host2,
2769 WebUIImpl*& web_ui,
2770 RenderFrameHostManager*& manager) {
2771 set_should_create_webui(true);
2772 NavigateActiveAndCommit(GURL("chrome://foo/"));
2773
2774 manager = contents()->GetRenderManagerForTesting();
2775 host1 = manager->current_frame_host();
2776 EXPECT_TRUE(host1->IsRenderFrameLive());
2777 web_ui = host1->web_ui();
2778 EXPECT_TRUE(web_ui);
2779
2780 // Starts a reload of the WebUI page.
2781 contents()->GetController().Reload(true);
2782
2783 // It should be a same-site navigation reusing the same WebUI.
2784 EXPECT_EQ(web_ui, manager->GetNavigatingWebUI());
2785 EXPECT_EQ(web_ui, host1->web_ui());
2786 EXPECT_EQ(web_ui, host1->pending_web_ui());
2787 EXPECT_FALSE(GetPendingFrameHost(manager));
2788
2789 // Navigation request to a non-WebUI page.
2790 const GURL kUrl("http://google.com");
2791 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
2792 Referrer(), base::string16() /* title */,
2793 ui::PAGE_TRANSITION_TYPED,
2794 false /* is_renderer_init */);
2795 host2 = NavigateToEntry(manager, entry);
2796 ASSERT_TRUE(host2);
2797
2798 // The previous navigation should still be ongoing along with the new,
2799 // cross-site one.
2800 // Note: simultaneous navigations are weird: there are two ongoing
nasko 2015/11/25 22:15:50 nit: The note is a sentence, so it should start wi
carlosk 2015/11/26 10:58:02 Done.
2801 // navigations, a same-site using a WebUI and a cross-site not using one. So
2802 // it's unclear what GetNavigatingWebUI should return in this case. As it
2803 // currently favors the cross-site navigation it returns null.
2804 EXPECT_FALSE(manager->GetNavigatingWebUI());
2805 EXPECT_EQ(web_ui, host1->web_ui());
2806 EXPECT_EQ(web_ui, host1->pending_web_ui());
2807
2808 EXPECT_NE(host2, host1);
2809 EXPECT_EQ(host2, GetPendingFrameHost(manager));
2810 EXPECT_FALSE(host2->web_ui());
2811 EXPECT_FALSE(host2->pending_web_ui());
2812 EXPECT_NE(web_ui, host2->web_ui());
2813 }
2814
2815 // Simulates two simultaneous navigations involving one WebUI where the current
2816 // RenderFrameHost commits.
2817 TEST_F(RenderFrameHostManagerTest, SimultaneousNavigationWithOneWebUI1) {
2818 RenderFrameHostImpl* host1 = nullptr;
2819 RenderFrameHostImpl* host2 = nullptr;
2820 WebUIImpl* web_ui = nullptr;
2821 RenderFrameHostManager* manager = nullptr;
2822 BaseSimultaneousNavigationWithOneWebUI(host1, host2, web_ui, manager);
2823 ASSERT_TRUE(host1 && host2 && web_ui && manager);
2824
2825 // The current RenderFrameHost commits; its WebUI should still be in place.
2826 manager->DidNavigateFrame(host1, true);
2827 EXPECT_EQ(host1, manager->current_frame_host());
2828 EXPECT_EQ(web_ui, host1->web_ui());
2829 EXPECT_FALSE(host1->pending_web_ui());
2830 EXPECT_FALSE(manager->GetNavigatingWebUI());
2831 EXPECT_FALSE(GetPendingFrameHost(manager));
2832 }
2833
2834 // Simulates two simultaneous navigations involving one WebUI where the new,
2835 // cross-site RenderFrameHost commits.
2836 TEST_F(RenderFrameHostManagerTest, SimultaneousNavigationWithOneWebUI2) {
2837 RenderFrameHostImpl* host1 = nullptr;
2838 RenderFrameHostImpl* host2 = nullptr;
2839 WebUIImpl* web_ui = nullptr;
2840 RenderFrameHostManager* manager = nullptr;
2841 BaseSimultaneousNavigationWithOneWebUI(host1, host2, web_ui, manager);
2842 ASSERT_TRUE(host1 && host2 && web_ui && manager);
2843
2844 // The new RenderFrameHost commits; there should be no active WebUI.
2845 manager->DidNavigateFrame(host2, true);
2846 EXPECT_EQ(host2, manager->current_frame_host());
2847 EXPECT_FALSE(host2->web_ui());
2848 EXPECT_FALSE(host2->pending_web_ui());
2849 EXPECT_FALSE(manager->GetNavigatingWebUI());
2850 EXPECT_FALSE(GetPendingFrameHost(manager));
2851 }
2852
2853 // Shared code for the SimultaneousNavigationWithTwoWebUIs* tests, going until
2854 // right before commit.
2855 void RenderFrameHostManagerTest::BaseSimultaneousNavigationWithTwoWebUIs(
2856 RenderFrameHostImpl*& host1,
nasko 2015/11/25 22:15:50 Same comment as the other method.
carlosk 2015/11/26 10:58:03 Done.
2857 RenderFrameHostImpl*& host2,
2858 WebUIImpl*& web_ui1,
2859 WebUIImpl*& web_ui2,
2860 RenderFrameHostManager*& manager) {
2861 set_should_create_webui(true);
2862 set_webui_type(1);
2863 NavigateActiveAndCommit(GURL("chrome://foo/"));
2864
2865 manager = contents()->GetRenderManagerForTesting();
2866 host1 = manager->current_frame_host();
2867 EXPECT_TRUE(host1->IsRenderFrameLive());
2868 web_ui1 = host1->web_ui();
2869 EXPECT_TRUE(web_ui1);
2870
2871 // Starts a reload of the WebUI page.
2872 contents()->GetController().Reload(true);
2873
2874 // It should be a same-site navigation reusing the same WebUI.
2875 EXPECT_EQ(web_ui1, manager->GetNavigatingWebUI());
2876 EXPECT_EQ(web_ui1, host1->web_ui());
2877 EXPECT_EQ(web_ui1, host1->pending_web_ui());
2878 EXPECT_FALSE(GetPendingFrameHost(manager));
2879
2880 // Navigation another WebUI page, with a different type.
2881 set_webui_type(2);
2882 const GURL kUrl("chrome://bar/");
2883 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
2884 Referrer(), base::string16() /* title */,
2885 ui::PAGE_TRANSITION_TYPED,
2886 false /* is_renderer_init */);
2887 host2 = NavigateToEntry(manager, entry);
2888 ASSERT_TRUE(host2);
2889
2890 // The previous navigation should still be ongoing along with the new,
2891 // cross-site one.
2892 // Note: simultaneous navigations are weird: there are two ongoing
2893 // navigations, a same-site and a cross-site both going to WebUIs. So it's
2894 // unclear what GetNavigatingWebUI should return in this case. As it currently
2895 // favors the cross-site navigation it returns the speculative/pending
2896 // RenderFrameHost's WebUI instance.
2897 EXPECT_EQ(web_ui1, host1->web_ui());
2898 EXPECT_EQ(web_ui1, host1->pending_web_ui());
2899 web_ui2 = manager->GetNavigatingWebUI();
2900 EXPECT_TRUE(web_ui2);
2901 EXPECT_NE(web_ui2, web_ui1);
2902
2903 EXPECT_NE(host2, host1);
2904 EXPECT_EQ(host2, GetPendingFrameHost(manager));
2905 EXPECT_EQ(web_ui2, host2->web_ui());
2906 EXPECT_FALSE(host2->pending_web_ui());
2907 }
2908
2909 // Simulates two simultaneous navigations involving two WebUIs where the current
2910 // RenderFrameHost commits.
2911 TEST_F(RenderFrameHostManagerTest, SimultaneousNavigationWithTwoWebUIs1) {
2912 RenderFrameHostImpl* host1 = nullptr;
2913 RenderFrameHostImpl* host2 = nullptr;
2914 WebUIImpl* web_ui1 = nullptr;
2915 WebUIImpl* web_ui2 = nullptr;
2916 RenderFrameHostManager* manager = nullptr;
2917 BaseSimultaneousNavigationWithTwoWebUIs(host1, host2, web_ui1, web_ui2,
2918 manager);
2919 ASSERT_TRUE(host1 && host2 && web_ui1 && web_ui2 && manager);
2920
2921 // The current RenderFrameHost commits; its WebUI should still be active.
2922 manager->DidNavigateFrame(host1, true);
2923 EXPECT_EQ(host1, manager->current_frame_host());
2924 EXPECT_EQ(web_ui1, host1->web_ui());
2925 EXPECT_FALSE(host1->pending_web_ui());
2926 EXPECT_FALSE(manager->GetNavigatingWebUI());
2927 EXPECT_FALSE(GetPendingFrameHost(manager));
2928 }
2929
2930 // Simulates two simultaneous navigations involving two WebUIs where the new,
2931 // cross-site RenderFrameHost commits.
2932 TEST_F(RenderFrameHostManagerTest, SimultaneousNavigationWithTwoWebUIs2) {
2933 RenderFrameHostImpl* host1 = nullptr;
2934 RenderFrameHostImpl* host2 = nullptr;
2935 WebUIImpl* web_ui1 = nullptr;
2936 WebUIImpl* web_ui2 = nullptr;
2937 RenderFrameHostManager* manager = nullptr;
2938 BaseSimultaneousNavigationWithTwoWebUIs(host1, host2, web_ui1, web_ui2,
2939 manager);
2940 ASSERT_TRUE(host1 && host2 && web_ui1 && web_ui2 && manager);
2941
2942 // The new RenderFrameHost commits; its WebUI should now be active.
2943 manager->DidNavigateFrame(host2, true);
2944 EXPECT_EQ(host2, manager->current_frame_host());
2945 EXPECT_EQ(web_ui2, host2->web_ui());
2946 EXPECT_FALSE(host2->pending_web_ui());
2947 EXPECT_FALSE(manager->GetNavigatingWebUI());
2948 EXPECT_FALSE(GetPendingFrameHost(manager));
2949 }
2950
2951 // RenderFrameHostManagerTest extension for PlzNavigate enabled tests.
2952 class RenderFrameHostManagerTestWithBrowserSideNavigation
2953 : public RenderFrameHostManagerTest {
2954 public:
2955 void SetUp() override {
2956 EnableBrowserSideNavigation();
2957 RenderFrameHostManagerTest::SetUp();
2958 }
2959 };
2960
2961 // PlzNavigate: Tests that the correct intermediary and final navigation states
2962 // are reached when navigating from a renderer that is not live to a WebUI URL.
2963 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
2964 NavigateFromDeadRendererToWebUI) {
2965 set_should_create_webui(true);
2966 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
2967
2968 RenderFrameHostImpl* initial_host = manager->current_frame_host();
2969 ASSERT_TRUE(initial_host);
2970 EXPECT_FALSE(initial_host->IsRenderFrameLive());
2971
2972 // Navigation request.
2973 const GURL kUrl("chrome://foo");
2974 NavigationEntryImpl entry(nullptr /* instance */, -1 /* page_id */, kUrl,
2975 Referrer(), base::string16() /* title */,
2976 ui::PAGE_TRANSITION_TYPED,
2977 false /* is_renderer_init */);
2978 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
2979 scoped_ptr<NavigationRequest> navigation_request =
2980 NavigationRequest::CreateBrowserInitiated(
2981 contents()->GetFrameTree()->root(), frame_entry->url(),
2982 frame_entry->referrer(), *frame_entry, entry,
2983 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
2984 static_cast<NavigationControllerImpl*>(&controller()));
2985 manager->DidCreateNavigationRequest(*navigation_request);
2986
2987 // As the initial RenderFrame was not live, the new RenderFrameHost should be
2988 // made as active/current immediately along with its WebUI at request time.
2989 RenderFrameHostImpl* host = manager->current_frame_host();
2990 ASSERT_TRUE(host);
2991 EXPECT_NE(host, initial_host);
2992 EXPECT_TRUE(host->IsRenderFrameLive());
2993 WebUIImpl* web_ui = host->web_ui();
2994 EXPECT_TRUE(web_ui);
2995 EXPECT_FALSE(host->pending_web_ui());
2996 EXPECT_FALSE(manager->GetNavigatingWebUI());
2997 EXPECT_FALSE(GetPendingFrameHost(manager));
2998
2999 // Prepare to commit, update the navigating RenderFrameHost.
3000 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request));
3001
3002 // There should be a pending WebUI set to reuse the current one.
3003 EXPECT_EQ(web_ui, host->web_ui());
3004 EXPECT_EQ(web_ui, host->pending_web_ui());
3005 EXPECT_EQ(web_ui, manager->GetNavigatingWebUI());
3006
3007 // No pending RenderFrameHost as the current one should be reused.
3008 EXPECT_FALSE(GetPendingFrameHost(manager));
3009
3010 // The RenderFrameHost committed.
3011 manager->DidNavigateFrame(host, true);
3012 EXPECT_EQ(host, manager->current_frame_host());
3013 EXPECT_FALSE(GetPendingFrameHost(manager));
3014 EXPECT_EQ(web_ui, host->web_ui());
3015 EXPECT_FALSE(host->pending_web_ui());
3016 EXPECT_FALSE(manager->GetNavigatingWebUI());
3017 }
3018
3019 // PlzNavigate: Tests that the correct intermediary and final navigation states
3020 // are reached when navigating same-site between two WebUIs of the same type.
3021 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
3022 NavigateSameSiteBetweenWebUIs) {
3023 set_should_create_webui(true);
3024 NavigateActiveAndCommit(GURL("chrome://foo"));
3025
3026 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
3027 RenderFrameHostImpl* host = manager->current_frame_host();
3028 EXPECT_TRUE(host->IsRenderFrameLive());
3029 WebUIImpl* web_ui = host->web_ui();
3030 EXPECT_TRUE(web_ui);
3031
3032 // Navigation request. No change in the returned WebUI type.
3033 const GURL kUrl("chrome://foo/bar");
3034 NavigationEntryImpl entry(nullptr /* instance */, -1 /* page_id */, kUrl,
3035 Referrer(), base::string16() /* title */,
3036 ui::PAGE_TRANSITION_TYPED,
3037 false /* is_renderer_init */);
3038 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
3039 scoped_ptr<NavigationRequest> navigation_request =
3040 NavigationRequest::CreateBrowserInitiated(
3041 contents()->GetFrameTree()->root(), frame_entry->url(),
3042 frame_entry->referrer(), *frame_entry, entry,
3043 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
3044 static_cast<NavigationControllerImpl*>(&controller()));
3045 manager->DidCreateNavigationRequest(*navigation_request);
3046
3047 // The current WebUI should still be in place and the pending WebUI should be
3048 // set to reuse it.
3049 EXPECT_EQ(web_ui, manager->GetNavigatingWebUI());
3050 EXPECT_EQ(web_ui, host->web_ui());
3051 EXPECT_EQ(web_ui, host->pending_web_ui());
3052 EXPECT_FALSE(GetPendingFrameHost(manager));
3053
3054 // Prepare to commit, update the navigating RenderFrameHost.
3055 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request));
3056
3057 EXPECT_EQ(web_ui, manager->GetNavigatingWebUI());
3058 EXPECT_EQ(web_ui, host->web_ui());
3059 EXPECT_EQ(web_ui, host->pending_web_ui());
3060 EXPECT_FALSE(GetPendingFrameHost(manager));
3061
3062 // The RenderFrameHost committed.
3063 manager->DidNavigateFrame(host, true);
3064 EXPECT_EQ(web_ui, host->web_ui());
3065 EXPECT_FALSE(manager->GetNavigatingWebUI());
3066 EXPECT_FALSE(host->pending_web_ui());
3067 }
3068
3069 // PlzNavigate: Tests that the correct intermediary and final navigation states
3070 // are reached when navigating cross-site between two different WebUI types.
3071 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
3072 NavigateCrossSiteBetweenWebUIs) {
3073 // Cross-site navigations will always cause the change of the WebUI instance
3074 // but for consistency sake different types will be set for each navigation.
3075 set_should_create_webui(true);
3076 set_webui_type(1);
3077 NavigateActiveAndCommit(GURL("chrome://foo"));
3078
3079 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
3080 RenderFrameHostImpl* host = manager->current_frame_host();
3081 EXPECT_TRUE(host->IsRenderFrameLive());
3082 EXPECT_TRUE(host->web_ui());
3083
3084 // Set the WebUI controller to return a different WebUIType value. This will
3085 // cause the next navigation to "chrome://bar" to require a different WebUI
3086 // than the current one, forcing it to be treated as cross-site.
3087 set_webui_type(2);
3088
3089 // Navigation request.
3090 const GURL kUrl("chrome://bar");
3091 NavigationEntryImpl entry(nullptr /* instance */, -1 /* page_id */, kUrl,
3092 Referrer(), base::string16() /* title */,
3093 ui::PAGE_TRANSITION_TYPED,
3094 false /* is_renderer_init */);
3095 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
3096 scoped_ptr<NavigationRequest> navigation_request =
3097 NavigationRequest::CreateBrowserInitiated(
3098 contents()->GetFrameTree()->root(), frame_entry->url(),
3099 frame_entry->referrer(), *frame_entry, entry,
3100 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
3101 static_cast<NavigationControllerImpl*>(&controller()));
3102 manager->DidCreateNavigationRequest(*navigation_request);
3103
3104 // The current WebUI should still be in place and there should be a new
3105 // active WebUI instance in the speculative RenderFrameHost.
3106 EXPECT_TRUE(manager->current_frame_host()->web_ui());
3107 EXPECT_FALSE(manager->current_frame_host()->pending_web_ui());
3108 RenderFrameHostImpl* speculative_host = GetPendingFrameHost(manager);
3109 EXPECT_TRUE(speculative_host);
3110 WebUIImpl* next_web_ui = manager->GetNavigatingWebUI();
3111 EXPECT_TRUE(next_web_ui);
3112 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
3113 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
3114 EXPECT_FALSE(speculative_host->pending_web_ui());
3115
3116 // Prepare to commit, update the navigating RenderFrameHost.
3117 EXPECT_EQ(speculative_host,
3118 manager->GetFrameHostForNavigation(*navigation_request));
3119
3120 EXPECT_TRUE(manager->current_frame_host()->web_ui());
3121 EXPECT_FALSE(manager->current_frame_host()->pending_web_ui());
3122 EXPECT_EQ(speculative_host, GetPendingFrameHost(manager));
3123 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
3124 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
3125 EXPECT_EQ(next_web_ui, manager->GetNavigatingWebUI());
3126 EXPECT_FALSE(speculative_host->pending_web_ui());
3127
3128 // The RenderFrameHost committed.
3129 manager->DidNavigateFrame(speculative_host, true);
3130 EXPECT_EQ(speculative_host, manager->current_frame_host());
3131 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui());
3132 EXPECT_FALSE(GetPendingFrameHost(manager));
3133 EXPECT_FALSE(speculative_host->pending_web_ui());
3134 EXPECT_FALSE(manager->GetNavigatingWebUI());
3135 }
3136
2665 } // namespace content 3137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698