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

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

Issue 1426403006: Reland #1 of: Move WebUI ownership from the RenderFrameHostManager to the RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address CR 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 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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 TEST_F(RenderFrameHostManagerTest, WebUI) { 1121 TEST_F(RenderFrameHostManagerTest, WebUI) {
1083 set_should_create_webui(true); 1122 set_should_create_webui(true);
1084 SiteInstance* instance = SiteInstance::Create(browser_context()); 1123 SiteInstance* instance = SiteInstance::Create(browser_context());
1085 1124
1086 scoped_ptr<TestWebContents> web_contents( 1125 scoped_ptr<TestWebContents> web_contents(
1087 TestWebContents::Create(browser_context(), instance)); 1126 TestWebContents::Create(browser_context(), instance));
1088 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); 1127 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1089 RenderFrameHostImpl* initial_rfh = manager->current_frame_host(); 1128 RenderFrameHostImpl* initial_rfh = manager->current_frame_host();
1090 1129
1091 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); 1130 EXPECT_FALSE(manager->current_host()->IsRenderViewLive());
1092 EXPECT_FALSE(manager->web_ui()); 1131 EXPECT_FALSE(manager->current_frame_host()->web_ui());
1093 EXPECT_TRUE(initial_rfh); 1132 EXPECT_TRUE(initial_rfh);
1094 1133
1095 const GURL kUrl("chrome://foo"); 1134 const GURL kUrl("chrome://foo");
1096 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, 1135 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
1097 Referrer(), base::string16() /* title */, 1136 Referrer(), base::string16() /* title */,
1098 ui::PAGE_TRANSITION_TYPED, 1137 ui::PAGE_TRANSITION_TYPED,
1099 false /* is_renderer_init */); 1138 false /* is_renderer_init */);
1100 RenderFrameHostImpl* host = NavigateToEntry(manager, entry); 1139 RenderFrameHostImpl* host = NavigateToEntry(manager, entry);
1101 1140
1102 // We commit the pending RenderFrameHost immediately because the previous 1141 // We commit the pending RenderFrameHost immediately because the previous
1103 // RenderFrameHost was not live. We test a case where it is live in 1142 // RenderFrameHost was not live. We test a case where it is live in
1104 // WebUIInNewTab. 1143 // WebUIInNewTab.
1105 EXPECT_TRUE(host); 1144 EXPECT_TRUE(host);
1106 EXPECT_NE(initial_rfh, host); 1145 EXPECT_NE(initial_rfh, host);
1107 EXPECT_EQ(host, manager->current_frame_host()); 1146 EXPECT_EQ(host, manager->current_frame_host());
1108 EXPECT_FALSE(GetPendingFrameHost(manager)); 1147 EXPECT_FALSE(GetPendingFrameHost(manager));
1109 1148
1110 // It's important that the SiteInstance get set on the Web UI page as soon 1149 // 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 1150 // 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 1151 // try to re-use the SiteInstance/process for non Web UI things that may
1113 // get loaded in between. 1152 // get loaded in between.
1114 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); 1153 EXPECT_TRUE(host->GetSiteInstance()->HasSite());
1115 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); 1154 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL());
1116 1155
1117 // The Web UI is committed immediately because the RenderViewHost has not been 1156 // The Web UI is committed immediately because the RenderViewHost has not been
1118 // used yet. UpdateStateForNavigate() took the short cut path. 1157 // used yet. UpdateStateForNavigate() took the short cut path.
1119 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1158 EXPECT_FALSE(manager->GetNavigatingWebUI());
1120 switches::kEnableBrowserSideNavigation)) { 1159 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 1160
1127 // Commit. 1161 // Commit.
1128 manager->DidNavigateFrame(host, true); 1162 manager->DidNavigateFrame(host, true);
1129 EXPECT_TRUE( 1163 EXPECT_TRUE(
1130 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1164 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1131 } 1165 }
1132 1166
1133 // Tests that we can open a WebUI link in a new tab from a WebUI page and still 1167 // 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. 1168 // grant the correct bindings. http://crbug.com/189101.
1135 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { 1169 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 const GURL kUrl2("chrome://foo/bar"); 1218 const GURL kUrl2("chrome://foo/bar");
1185 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 1219 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
1186 Referrer(), base::string16() /* title */, 1220 Referrer(), base::string16() /* title */,
1187 ui::PAGE_TRANSITION_LINK, 1221 ui::PAGE_TRANSITION_LINK,
1188 true /* is_renderer_init */); 1222 true /* is_renderer_init */);
1189 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); 1223 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2);
1190 1224
1191 // No cross-process transition happens because we are already in the right 1225 // No cross-process transition happens because we are already in the right
1192 // SiteInstance. We should grant bindings immediately. 1226 // SiteInstance. We should grant bindings immediately.
1193 EXPECT_EQ(host2, manager2->current_frame_host()); 1227 EXPECT_EQ(host2, manager2->current_frame_host());
1194 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1228 EXPECT_TRUE(manager2->GetNavigatingWebUI());
1195 switches::kEnableBrowserSideNavigation)) { 1229 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( 1230 EXPECT_TRUE(
1201 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1231 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1202 1232
1203 manager2->DidNavigateFrame(host2, true); 1233 manager2->DidNavigateFrame(host2, true);
1204 } 1234 }
1205 1235
1206 // Tests that a WebUI is correctly reused between chrome:// pages. 1236 // Tests that a WebUI is correctly reused between chrome:// pages.
1207 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { 1237 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) {
1208 set_should_create_webui(true); 1238 set_should_create_webui(true);
1209 1239
1210 // Navigate to a WebUI page. 1240 // Navigate to a WebUI page.
1211 const GURL kUrl1("chrome://foo"); 1241 const GURL kUrl1("chrome://foo");
1212 contents()->NavigateAndCommit(kUrl1); 1242 contents()->NavigateAndCommit(kUrl1);
1213 RenderFrameHostManager* manager = 1243 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); 1244 EXPECT_TRUE(web_ui);
1217 1245
1218 // Navigate to another WebUI page which should be same-site and keep the 1246 // Navigate to another WebUI page which should be same-site and keep the
1219 // current WebUI. 1247 // current WebUI.
1220 const GURL kUrl2("chrome://foo/bar"); 1248 const GURL kUrl2("chrome://foo/bar");
1221 contents()->NavigateAndCommit(kUrl2); 1249 contents()->NavigateAndCommit(kUrl2);
1222 EXPECT_EQ(web_ui, manager->web_ui()); 1250 EXPECT_EQ(web_ui, main_test_rfh()->web_ui());
1223 } 1251 }
1224 1252
1225 // Tests that a WebUI is correctly cleaned up when navigating from a chrome:// 1253 // Tests that a WebUI is correctly cleaned up when navigating from a chrome://
1226 // page to a non-chrome:// page. 1254 // page to a non-chrome:// page.
1227 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) { 1255 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) {
1228 set_should_create_webui(true); 1256 set_should_create_webui(true);
1229 1257
1230 // Navigate to a WebUI page. 1258 // Navigate to a WebUI page.
1231 const GURL kUrl1("chrome://foo"); 1259 const GURL kUrl1("chrome://foo");
1232 contents()->NavigateAndCommit(kUrl1); 1260 contents()->NavigateAndCommit(kUrl1);
1233 EXPECT_TRUE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui()); 1261 EXPECT_TRUE(main_test_rfh()->web_ui());
1234 1262
1235 // Navigate to a non-WebUI page. 1263 // Navigate to a non-WebUI page.
1236 const GURL kUrl2("http://www.google.com"); 1264 const GURL kUrl2("http://www.google.com");
1237 contents()->NavigateAndCommit(kUrl2); 1265 contents()->NavigateAndCommit(kUrl2);
1238 EXPECT_FALSE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui()); 1266 EXPECT_FALSE(main_test_rfh()->web_ui());
1239 } 1267 }
1240 1268
1241 // Tests that we don't end up in an inconsistent state if a page does a back and 1269 // 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 1270 // then reload. http://crbug.com/51680
1243 // Also tests that only user-gesture navigations can interrupt cross-process 1271 // Also tests that only user-gesture navigations can interrupt cross-process
1244 // navigations. http://crbug.com/75195 1272 // navigations. http://crbug.com/75195
1245 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { 1273 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) {
1246 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1274 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1247 switches::kEnableBrowserSideNavigation)) { 1275 switches::kEnableBrowserSideNavigation)) {
1248 // PlzNavigate uses a significantly different logic for renderer initiated 1276 // PlzNavigate uses a significantly different logic for renderer initiated
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 RenderFrameProxyHost* proxy = 2683 RenderFrameProxyHost* proxy =
2656 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); 2684 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance());
2657 EXPECT_TRUE(proxy); 2685 EXPECT_TRUE(proxy);
2658 2686
2659 // Since the B->C navigation happened while the current page was focused, 2687 // Since the B->C navigation happened while the current page was focused,
2660 // page focus should propagate to the new subframe process. Check that 2688 // page focus should propagate to the new subframe process. Check that
2661 // process C received the proper focus message. 2689 // process C received the proper focus message.
2662 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); 2690 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID());
2663 } 2691 }
2664 2692
2693 // Checks that a restore navigation to a WebUI works.
2694 TEST_F(RenderFrameHostManagerTest, RestoreNavigationToWebUI) {
2695 set_should_create_webui(true);
2696
2697 const GURL kInitUrl("chrome://foo/");
2698 SiteInstanceImpl* initial_instance =
2699 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context()));
2700 initial_instance->SetSite(kInitUrl);
2701 scoped_ptr<TestWebContents> web_contents(
2702 TestWebContents::Create(browser_context(), initial_instance));
2703 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
2704 NavigationControllerImpl& controller = web_contents->GetController();
2705
2706 // Setup a restored entry.
2707 std::vector<scoped_ptr<NavigationEntry>> entries;
2708 scoped_ptr<NavigationEntry> new_entry =
2709 NavigationControllerImpl::CreateNavigationEntry(
2710 kInitUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, false, std::string(),
2711 browser_context());
2712 new_entry->SetPageID(0);
2713 entries.push_back(new_entry.Pass());
2714 controller.Restore(
2715 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries);
2716 ASSERT_EQ(0u, entries.size());
2717 ASSERT_EQ(1, controller.GetEntryCount());
2718
2719 RenderFrameHostImpl* initial_host = manager->current_frame_host();
2720 ASSERT_TRUE(initial_host);
2721 EXPECT_FALSE(initial_host->IsRenderFrameLive());
2722 EXPECT_FALSE(initial_host->web_ui());
2723
2724 // Navigation request to an entry from a previous browsing session.
2725 NavigationEntryImpl entry(nullptr /* instance */, 0 /* page_id */, kInitUrl,
2726 Referrer(), base::string16() /* title */,
2727 ui::PAGE_TRANSITION_RELOAD,
2728 false /* is_renderer_init */);
2729 entry.set_restore_type(
2730 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY);
2731 NavigateToEntry(manager, entry);
2732
2733 // As the initial renderer was not live, the new RenderFrameHost should be
2734 // made immediately active at request time.
2735 EXPECT_FALSE(GetPendingFrameHost(manager));
2736 TestRenderFrameHost* current_host =
2737 static_cast<TestRenderFrameHost*>(manager->current_frame_host());
2738 ASSERT_TRUE(current_host);
2739 EXPECT_EQ(current_host, initial_host);
2740 EXPECT_TRUE(current_host->IsRenderFrameLive());
2741 WebUIImpl* web_ui = manager->GetNavigatingWebUI();
2742 EXPECT_TRUE(web_ui);
2743 EXPECT_EQ(web_ui, current_host->pending_web_ui());
2744 EXPECT_FALSE(current_host->web_ui());
2745
2746 // The RenderFrameHost committed.
2747 manager->DidNavigateFrame(current_host, true);
2748 EXPECT_EQ(current_host, manager->current_frame_host());
2749 EXPECT_EQ(web_ui, current_host->web_ui());
2750 EXPECT_FALSE(current_host->pending_web_ui());
2751 }
2752
2753 // RenderFrameHostManagerTest extension for PlzNavigate enabled tests.
2754 class RenderFrameHostManagerTestWithBrowserSideNavigation
2755 : public RenderFrameHostManagerTest {
2756 public:
2757 void SetUp() override {
2758 EnableBrowserSideNavigation();
2759 RenderFrameHostManagerTest::SetUp();
2760 }
2761 };
2762
2763 // PlzNavigate: Tests that the correct intermediary and final navigation states
2764 // are reached when navigating from a renderer that is not live to a WebUI URL.
2765 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
2766 NavigateFromDeadRendererToWebUI) {
2767 set_should_create_webui(true);
2768 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
2769
2770 RenderFrameHostImpl* initial_host = manager->current_frame_host();
2771 ASSERT_TRUE(initial_host);
2772 EXPECT_FALSE(initial_host->IsRenderFrameLive());
2773
2774 // Navigation request.
2775 const GURL kUrl("chrome://foo");
2776 NavigationEntryImpl entry(nullptr /* instance */, -1 /* page_id */, kUrl,
2777 Referrer(), base::string16() /* title */,
2778 ui::PAGE_TRANSITION_TYPED,
2779 false /* is_renderer_init */);
2780 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
2781 scoped_ptr<NavigationRequest> navigation_request =
2782 NavigationRequest::CreateBrowserInitiated(
2783 contents()->GetFrameTree()->root(), frame_entry->url(),
2784 frame_entry->referrer(), *frame_entry, entry,
2785 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
2786 static_cast<NavigationControllerImpl*>(&controller()));
2787 manager->DidCreateNavigationRequest(*navigation_request);
2788
2789 // As the initial renderer was not live, the new RenderFrameHost should be
nasko 2015/11/19 19:45:24 nit: "renderer" should be either "renderer process
carlosk 2015/11/20 12:21:11 Done.
2790 // made as active/current immediately along with its WebUI at request time.
2791 TestRenderFrameHost* host =
2792 static_cast<TestRenderFrameHost*>(manager->current_frame_host());
2793 ASSERT_TRUE(host);
2794 EXPECT_NE(host, initial_host);
2795 EXPECT_TRUE(host->IsRenderFrameLive());
2796 WebUIImpl* web_ui = host->web_ui();
2797 EXPECT_TRUE(web_ui);
2798 EXPECT_FALSE(host->pending_web_ui());
2799 EXPECT_FALSE(manager->GetNavigatingWebUI());
2800 EXPECT_FALSE(GetPendingFrameHost(manager));
2801
2802 // Prepare to commit, update the navigating RenderFrameHost.
2803 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request));
2804
2805 // There should be a pending WebUI set to reuse the current one.
2806 EXPECT_EQ(web_ui, host->web_ui());
2807 EXPECT_EQ(web_ui, host->pending_web_ui());
2808 EXPECT_EQ(web_ui, manager->GetNavigatingWebUI());
2809
2810 // No pending RenderFrameHost as the current one should be reused.
2811 EXPECT_FALSE(GetPendingFrameHost(manager));
2812
2813 // The RenderFrameHost committed.
2814 manager->DidNavigateFrame(host, true);
2815 EXPECT_EQ(host, manager->current_frame_host());
2816 EXPECT_FALSE(GetPendingFrameHost(manager));
2817 EXPECT_EQ(web_ui, host->web_ui());
2818 EXPECT_FALSE(host->pending_web_ui());
2819 EXPECT_FALSE(manager->GetNavigatingWebUI());
2820 }
2821
2822 // PlzNavigate: Tests that the correct intermediary and final navigation states
2823 // are reached when navigating same-site between two WebUIs of the same type.
2824 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
2825 NavigateSameSiteBetweenWebUIs) {
2826 set_should_create_webui(true);
2827 NavigateActiveAndCommit(GURL("chrome://foo"));
2828
2829 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
2830 TestRenderFrameHost* host =
2831 static_cast<TestRenderFrameHost*>(manager->current_frame_host());
2832 EXPECT_TRUE(host->IsRenderFrameLive());
2833 WebUIImpl* web_ui = host->web_ui();
2834 EXPECT_TRUE(web_ui);
2835
2836 // Navigation request. No change in the returned WebUI type.
2837 const GURL kUrl("chrome://foo/bar");
2838 NavigationEntryImpl entry(nullptr /* instance */, -1 /* page_id */, kUrl,
2839 Referrer(), base::string16() /* title */,
2840 ui::PAGE_TRANSITION_TYPED,
2841 false /* is_renderer_init */);
2842 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
2843 scoped_ptr<NavigationRequest> navigation_request =
2844 NavigationRequest::CreateBrowserInitiated(
2845 contents()->GetFrameTree()->root(), frame_entry->url(),
2846 frame_entry->referrer(), *frame_entry, entry,
2847 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
2848 static_cast<NavigationControllerImpl*>(&controller()));
2849 manager->DidCreateNavigationRequest(*navigation_request);
2850
2851 // The current WebUI should still be in place and the pending WebUI should be
2852 // set to reuse it.
2853 EXPECT_EQ(web_ui, manager->GetNavigatingWebUI());
2854 EXPECT_EQ(web_ui, host->web_ui());
2855 EXPECT_EQ(web_ui, host->pending_web_ui());
2856 EXPECT_FALSE(GetPendingFrameHost(manager));
2857
2858 // Prepare to commit, update the navigating RenderFrameHost.
2859 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request));
2860
2861 EXPECT_EQ(web_ui, manager->GetNavigatingWebUI());
2862 EXPECT_EQ(web_ui, host->web_ui());
2863 EXPECT_EQ(web_ui, host->pending_web_ui());
2864 EXPECT_FALSE(GetPendingFrameHost(manager));
2865
2866 // The RenderFrameHost committed.
2867 manager->DidNavigateFrame(host, true);
2868 EXPECT_EQ(web_ui, host->web_ui());
2869 EXPECT_FALSE(manager->GetNavigatingWebUI());
2870 EXPECT_FALSE(host->pending_web_ui());
2871 }
2872
2873 // PlzNavigate: Tests that the correct intermediary and final navigation states
2874 // are reached when navigating cross-site between two different WebUI types.
2875 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
2876 NavigateCrossSiteBetweenWebUIs) {
2877 // Cross-site navigations will always cause the change of the WebUI instance
2878 // but for consistency sake different types will be set for each navigation.
2879 set_should_create_webui(true);
2880 set_webui_type(1);
2881 NavigateActiveAndCommit(GURL("chrome://foo"));
2882
2883 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
2884 TestRenderFrameHost* host =
2885 static_cast<TestRenderFrameHost*>(manager->current_frame_host());
2886 EXPECT_TRUE(host->IsRenderFrameLive());
2887 EXPECT_TRUE(host->web_ui());
2888
2889 // Set the WebUI controller to return a different WebUIType value.
nasko 2015/11/19 19:45:24 I'd suggest adding a bit more detail - This will c
carlosk 2015/11/20 12:21:11 Done.
2890 set_webui_type(2);
2891
2892 // Navigation request.
2893 const GURL kUrl("chrome://bar");
2894 NavigationEntryImpl entry(nullptr /* instance */, -1 /* page_id */, kUrl,
2895 Referrer(), base::string16() /* title */,
2896 ui::PAGE_TRANSITION_TYPED,
2897 false /* is_renderer_init */);
2898 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
2899 scoped_ptr<NavigationRequest> navigation_request =
2900 NavigationRequest::CreateBrowserInitiated(
2901 contents()->GetFrameTree()->root(), frame_entry->url(),
2902 frame_entry->referrer(), *frame_entry, entry,
2903 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
2904 static_cast<NavigationControllerImpl*>(&controller()));
2905 manager->DidCreateNavigationRequest(*navigation_request);
2906
2907 // The current WebUI should still be in place and there should be a new
2908 // active WebUI instance in the speculative RenderFrameHost.
2909 EXPECT_TRUE(manager->current_frame_host()->web_ui());
2910 EXPECT_FALSE(manager->current_frame_host()->pending_web_ui());
2911 TestRenderFrameHost* speculative_host =
2912 static_cast<TestRenderFrameHost*>(GetPendingFrameHost(manager));
2913 EXPECT_TRUE(speculative_host);
2914 WebUIImpl* next_web_ui = manager->GetNavigatingWebUI();
2915 EXPECT_TRUE(next_web_ui);
2916 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
2917 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
2918 EXPECT_FALSE(speculative_host->pending_web_ui());
2919
2920 // Prepare to commit, update the navigating RenderFrameHost.
2921 EXPECT_EQ(speculative_host,
2922 manager->GetFrameHostForNavigation(*navigation_request));
2923
2924 EXPECT_TRUE(manager->current_frame_host()->web_ui());
2925 EXPECT_FALSE(manager->current_frame_host()->pending_web_ui());
2926 EXPECT_EQ(speculative_host, GetPendingFrameHost(manager));
2927 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
2928 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
2929 EXPECT_EQ(next_web_ui, manager->GetNavigatingWebUI());
2930 EXPECT_FALSE(speculative_host->pending_web_ui());
2931
2932 // The RenderFrameHost committed.
2933 manager->DidNavigateFrame(speculative_host, true);
2934 EXPECT_EQ(speculative_host, manager->current_frame_host());
2935 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui());
2936 EXPECT_FALSE(GetPendingFrameHost(manager));
2937 EXPECT_FALSE(speculative_host->pending_web_ui());
2938 EXPECT_FALSE(manager->GetNavigatingWebUI());
2939 }
2940
2665 } // namespace content 2941 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager_browsertest.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698