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

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

Issue 1454883006: Revert of 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: 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"
42 #include "content/test/test_content_browser_client.h" 41 #include "content/test/test_content_browser_client.h"
43 #include "content/test/test_content_client.h" 42 #include "content/test/test_content_client.h"
44 #include "content/test/test_render_frame_host.h" 43 #include "content/test/test_render_frame_host.h"
45 #include "content/test/test_render_view_host.h" 44 #include "content/test/test_render_view_host.h"
46 #include "content/test/test_web_contents.h" 45 #include "content/test/test_web_contents.h"
47 #include "net/base/load_flags.h" 46 #include "net/base/load_flags.h"
48 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
49 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" 48 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h"
50 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 49 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
51 #include "ui/base/page_transition_types.h" 50 #include "ui/base/page_transition_types.h"
(...skipping 12 matching lines...) Expand all
64 EXPECT_EQ(expected_routing_id, message->routing_id()); 63 EXPECT_EQ(expected_routing_id, message->routing_id());
65 InputMsg_SetFocus::Param params; 64 InputMsg_SetFocus::Param params;
66 EXPECT_TRUE(InputMsg_SetFocus::Read(message, &params)); 65 EXPECT_TRUE(InputMsg_SetFocus::Read(message, &params));
67 EXPECT_EQ(expected_focus, base::get<0>(params)); 66 EXPECT_EQ(expected_focus, base::get<0>(params));
68 } 67 }
69 68
70 class RenderFrameHostManagerTestWebUIControllerFactory 69 class RenderFrameHostManagerTestWebUIControllerFactory
71 : public WebUIControllerFactory { 70 : public WebUIControllerFactory {
72 public: 71 public:
73 RenderFrameHostManagerTestWebUIControllerFactory() 72 RenderFrameHostManagerTestWebUIControllerFactory()
74 : should_create_webui_(false), type_(1) { 73 : should_create_webui_(false) {
75 CHECK_NE(reinterpret_cast<WebUI::TypeID>(type_), WebUI::kNoWebUI);
76 } 74 }
77 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} 75 ~RenderFrameHostManagerTestWebUIControllerFactory() override {}
78 76
79 void set_should_create_webui(bool should_create_webui) { 77 void set_should_create_webui(bool should_create_webui) {
80 should_create_webui_ = should_create_webui; 78 should_create_webui_ = should_create_webui;
81 } 79 }
82 80
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
94 // WebUIFactory implementation. 81 // WebUIFactory implementation.
95 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, 82 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui,
96 const GURL& url) const override { 83 const GURL& url) const override {
97 // If WebUI creation is enabled for the test and this is a WebUI URL, 84 if (!(should_create_webui_ && HasWebUIScheme(url)))
98 // returns a new instance. 85 return NULL;
99 if (should_create_webui_ && HasWebUIScheme(url)) 86 return new WebUIController(web_ui);
100 return new WebUIController(web_ui);
101 return nullptr;
102 } 87 }
103 88
104 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, 89 WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
105 const GURL& url) const override { 90 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 }
111 return WebUI::kNoWebUI; 91 return WebUI::kNoWebUI;
112 } 92 }
113 93
114 bool UseWebUIForURL(BrowserContext* browser_context, 94 bool UseWebUIForURL(BrowserContext* browser_context,
115 const GURL& url) const override { 95 const GURL& url) const override {
116 return HasWebUIScheme(url); 96 return HasWebUIScheme(url);
117 } 97 }
118 98
119 bool UseWebUIBindingsForURL(BrowserContext* browser_context, 99 bool UseWebUIBindingsForURL(BrowserContext* browser_context,
120 const GURL& url) const override { 100 const GURL& url) const override {
121 return HasWebUIScheme(url); 101 return HasWebUIScheme(url);
122 } 102 }
123 103
124 private: 104 private:
125 bool should_create_webui_; 105 bool should_create_webui_;
126 uintptr_t type_;
127 106
128 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); 107 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory);
129 }; 108 };
130 109
131 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { 110 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate {
132 public: 111 public:
133 BeforeUnloadFiredWebContentsDelegate() {} 112 BeforeUnloadFiredWebContentsDelegate() {}
134 ~BeforeUnloadFiredWebContentsDelegate() override {} 113 ~BeforeUnloadFiredWebContentsDelegate() override {}
135 114
136 void BeforeUnloadFired(WebContents* web_contents, 115 void BeforeUnloadFired(WebContents* web_contents,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it 273 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it
295 // must be shut down before the ImageTransportFactory. 274 // must be shut down before the ImageTransportFactory.
296 ImageTransportFactory::Terminate(); 275 ImageTransportFactory::Terminate();
297 #endif 276 #endif
298 } 277 }
299 278
300 void set_should_create_webui(bool should_create_webui) { 279 void set_should_create_webui(bool should_create_webui) {
301 factory_.set_should_create_webui(should_create_webui); 280 factory_.set_should_create_webui(should_create_webui);
302 } 281 }
303 282
304 void set_webui_type(int type) { factory_.set_webui_type(type); }
305
306 void NavigateActiveAndCommit(const GURL& url) { 283 void NavigateActiveAndCommit(const GURL& url) {
307 // Note: we navigate the active RenderFrameHost because previous navigations 284 // Note: we navigate the active RenderFrameHost because previous navigations
308 // won't have committed yet, so NavigateAndCommit does the wrong thing 285 // won't have committed yet, so NavigateAndCommit does the wrong thing
309 // for us. 286 // for us.
310 controller().LoadURL( 287 controller().LoadURL(
311 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 288 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
312 int entry_id = controller().GetPendingEntry()->GetUniqueID(); 289 int entry_id = controller().GetPendingEntry()->GetUniqueID();
313 290
314 // Simulate the BeforeUnload_ACK that is received from the current renderer 291 // Simulate the BeforeUnload_ACK that is received from the current renderer
315 // for a cross-site navigation. 292 // for a cross-site navigation.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 404
428 // Returns the RenderFrameHost that should be used in the navigation to 405 // Returns the RenderFrameHost that should be used in the navigation to
429 // |entry|. 406 // |entry|.
430 RenderFrameHostImpl* NavigateToEntry( 407 RenderFrameHostImpl* NavigateToEntry(
431 RenderFrameHostManager* manager, 408 RenderFrameHostManager* manager,
432 const NavigationEntryImpl& entry) { 409 const NavigationEntryImpl& entry) {
433 // Tests currently only navigate using main frame FrameNavigationEntries. 410 // Tests currently only navigate using main frame FrameNavigationEntries.
434 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); 411 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
435 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 412 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
436 switches::kEnableBrowserSideNavigation)) { 413 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);
446 scoped_ptr<NavigationRequest> navigation_request = 414 scoped_ptr<NavigationRequest> navigation_request =
447 NavigationRequest::CreateBrowserInitiated( 415 NavigationRequest::CreateBrowserInitiated(
448 manager->frame_tree_node_, frame_entry->url(), 416 manager->frame_tree_node_, frame_entry->url(),
449 frame_entry->referrer(), *frame_entry, entry, 417 frame_entry->referrer(), *frame_entry, entry,
450 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), 418 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
451 controller); 419 static_cast<NavigationControllerImpl*>(&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.
459 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( 420 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>(
460 manager->GetFrameHostForNavigation(*navigation_request)); 421 manager->GetFrameHostForNavigation(*navigation_request));
461 CHECK(frame_host); 422 CHECK(frame_host);
462 frame_host->set_pending_commit(true); 423 frame_host->set_pending_commit(true);
463 return frame_host; 424 return frame_host;
464 } 425 }
465 426
466 return manager->Navigate(frame_entry->url(), *frame_entry, entry); 427 return manager->Navigate(frame_entry->url(), *frame_entry, entry);
467 } 428 }
468 429
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 TEST_F(RenderFrameHostManagerTest, WebUI) { 1082 TEST_F(RenderFrameHostManagerTest, WebUI) {
1122 set_should_create_webui(true); 1083 set_should_create_webui(true);
1123 SiteInstance* instance = SiteInstance::Create(browser_context()); 1084 SiteInstance* instance = SiteInstance::Create(browser_context());
1124 1085
1125 scoped_ptr<TestWebContents> web_contents( 1086 scoped_ptr<TestWebContents> web_contents(
1126 TestWebContents::Create(browser_context(), instance)); 1087 TestWebContents::Create(browser_context(), instance));
1127 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); 1088 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1128 RenderFrameHostImpl* initial_rfh = manager->current_frame_host(); 1089 RenderFrameHostImpl* initial_rfh = manager->current_frame_host();
1129 1090
1130 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); 1091 EXPECT_FALSE(manager->current_host()->IsRenderViewLive());
1131 EXPECT_FALSE(manager->current_frame_host()->web_ui()); 1092 EXPECT_FALSE(manager->web_ui());
1132 EXPECT_TRUE(initial_rfh); 1093 EXPECT_TRUE(initial_rfh);
1133 1094
1134 const GURL kUrl("chrome://foo"); 1095 const GURL kUrl("chrome://foo");
1135 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, 1096 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
1136 Referrer(), base::string16() /* title */, 1097 Referrer(), base::string16() /* title */,
1137 ui::PAGE_TRANSITION_TYPED, 1098 ui::PAGE_TRANSITION_TYPED,
1138 false /* is_renderer_init */); 1099 false /* is_renderer_init */);
1139 RenderFrameHostImpl* host = NavigateToEntry(manager, entry); 1100 RenderFrameHostImpl* host = NavigateToEntry(manager, entry);
1140 1101
1141 // We commit the pending RenderFrameHost immediately because the previous 1102 // We commit the pending RenderFrameHost immediately because the previous
1142 // RenderFrameHost was not live. We test a case where it is live in 1103 // RenderFrameHost was not live. We test a case where it is live in
1143 // WebUIInNewTab. 1104 // WebUIInNewTab.
1144 EXPECT_TRUE(host); 1105 EXPECT_TRUE(host);
1145 EXPECT_NE(initial_rfh, host); 1106 EXPECT_NE(initial_rfh, host);
1146 EXPECT_EQ(host, manager->current_frame_host()); 1107 EXPECT_EQ(host, manager->current_frame_host());
1147 EXPECT_FALSE(GetPendingFrameHost(manager)); 1108 EXPECT_FALSE(GetPendingFrameHost(manager));
1148 1109
1149 // It's important that the SiteInstance get set on the Web UI page as soon 1110 // It's important that the SiteInstance get set on the Web UI page as soon
1150 // as the navigation starts, rather than lazily after it commits, so we don't 1111 // as the navigation starts, rather than lazily after it commits, so we don't
1151 // try to re-use the SiteInstance/process for non Web UI things that may 1112 // try to re-use the SiteInstance/process for non Web UI things that may
1152 // get loaded in between. 1113 // get loaded in between.
1153 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); 1114 EXPECT_TRUE(host->GetSiteInstance()->HasSite());
1154 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); 1115 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL());
1155 1116
1156 // The Web UI is committed immediately because the RenderViewHost has not been 1117 // The Web UI is committed immediately because the RenderViewHost has not been
1157 // used yet. UpdateStateForNavigate() took the short cut path. 1118 // used yet. UpdateStateForNavigate() took the short cut path.
1158 EXPECT_FALSE(manager->GetNavigatingWebUI()); 1119 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1159 EXPECT_TRUE(manager->current_frame_host()->web_ui()); 1120 switches::kEnableBrowserSideNavigation)) {
1121 EXPECT_FALSE(manager->speculative_web_ui());
1122 } else {
1123 EXPECT_FALSE(manager->pending_web_ui());
1124 }
1125 EXPECT_TRUE(manager->web_ui());
1160 1126
1161 // Commit. 1127 // Commit.
1162 manager->DidNavigateFrame(host, true); 1128 manager->DidNavigateFrame(host, true);
1163 EXPECT_TRUE( 1129 EXPECT_TRUE(
1164 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1130 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1165 } 1131 }
1166 1132
1167 // Tests that we can open a WebUI link in a new tab from a WebUI page and still 1133 // Tests that we can open a WebUI link in a new tab from a WebUI page and still
1168 // grant the correct bindings. http://crbug.com/189101. 1134 // grant the correct bindings. http://crbug.com/189101.
1169 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { 1135 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 const GURL kUrl2("chrome://foo/bar"); 1184 const GURL kUrl2("chrome://foo/bar");
1219 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 1185 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
1220 Referrer(), base::string16() /* title */, 1186 Referrer(), base::string16() /* title */,
1221 ui::PAGE_TRANSITION_LINK, 1187 ui::PAGE_TRANSITION_LINK,
1222 true /* is_renderer_init */); 1188 true /* is_renderer_init */);
1223 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); 1189 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2);
1224 1190
1225 // No cross-process transition happens because we are already in the right 1191 // No cross-process transition happens because we are already in the right
1226 // SiteInstance. We should grant bindings immediately. 1192 // SiteInstance. We should grant bindings immediately.
1227 EXPECT_EQ(host2, manager2->current_frame_host()); 1193 EXPECT_EQ(host2, manager2->current_frame_host());
1228 EXPECT_TRUE(manager2->GetNavigatingWebUI()); 1194 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1229 EXPECT_FALSE(host2->web_ui()); 1195 switches::kEnableBrowserSideNavigation)) {
1196 EXPECT_TRUE(manager2->speculative_web_ui());
1197 } else {
1198 EXPECT_TRUE(manager2->pending_web_ui());
1199 }
1230 EXPECT_TRUE( 1200 EXPECT_TRUE(
1231 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1201 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1232 1202
1233 manager2->DidNavigateFrame(host2, true); 1203 manager2->DidNavigateFrame(host2, true);
1234 } 1204 }
1235 1205
1236 // Tests that a WebUI is correctly reused between chrome:// pages. 1206 // Tests that a WebUI is correctly reused between chrome:// pages.
1237 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { 1207 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) {
1238 set_should_create_webui(true); 1208 set_should_create_webui(true);
1239 1209
1240 // Navigate to a WebUI page. 1210 // Navigate to a WebUI page.
1241 const GURL kUrl1("chrome://foo"); 1211 const GURL kUrl1("chrome://foo");
1242 contents()->NavigateAndCommit(kUrl1); 1212 contents()->NavigateAndCommit(kUrl1);
1243 WebUIImpl* web_ui = main_test_rfh()->web_ui(); 1213 RenderFrameHostManager* manager =
1214 main_test_rfh()->frame_tree_node()->render_manager();
1215 WebUIImpl* web_ui = manager->web_ui();
1244 EXPECT_TRUE(web_ui); 1216 EXPECT_TRUE(web_ui);
1245 1217
1246 // Navigate to another WebUI page which should be same-site and keep the 1218 // Navigate to another WebUI page which should be same-site and keep the
1247 // current WebUI. 1219 // current WebUI.
1248 const GURL kUrl2("chrome://foo/bar"); 1220 const GURL kUrl2("chrome://foo/bar");
1249 contents()->NavigateAndCommit(kUrl2); 1221 contents()->NavigateAndCommit(kUrl2);
1250 EXPECT_EQ(web_ui, main_test_rfh()->web_ui()); 1222 EXPECT_EQ(web_ui, manager->web_ui());
1251 } 1223 }
1252 1224
1253 // Tests that a WebUI is correctly cleaned up when navigating from a chrome:// 1225 // Tests that a WebUI is correctly cleaned up when navigating from a chrome://
1254 // page to a non-chrome:// page. 1226 // page to a non-chrome:// page.
1255 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) { 1227 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) {
1256 set_should_create_webui(true); 1228 set_should_create_webui(true);
1257 1229
1258 // Navigate to a WebUI page. 1230 // Navigate to a WebUI page.
1259 const GURL kUrl1("chrome://foo"); 1231 const GURL kUrl1("chrome://foo");
1260 contents()->NavigateAndCommit(kUrl1); 1232 contents()->NavigateAndCommit(kUrl1);
1261 EXPECT_TRUE(main_test_rfh()->web_ui()); 1233 EXPECT_TRUE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui());
1262 1234
1263 // Navigate to a non-WebUI page. 1235 // Navigate to a non-WebUI page.
1264 const GURL kUrl2("http://www.google.com"); 1236 const GURL kUrl2("http://www.google.com");
1265 contents()->NavigateAndCommit(kUrl2); 1237 contents()->NavigateAndCommit(kUrl2);
1266 EXPECT_FALSE(main_test_rfh()->web_ui()); 1238 EXPECT_FALSE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui());
1267 } 1239 }
1268 1240
1269 // Tests that we don't end up in an inconsistent state if a page does a back and 1241 // Tests that we don't end up in an inconsistent state if a page does a back and
1270 // then reload. http://crbug.com/51680 1242 // then reload. http://crbug.com/51680
1271 // Also tests that only user-gesture navigations can interrupt cross-process 1243 // Also tests that only user-gesture navigations can interrupt cross-process
1272 // navigations. http://crbug.com/75195 1244 // navigations. http://crbug.com/75195
1273 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { 1245 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) {
1274 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1246 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1275 switches::kEnableBrowserSideNavigation)) { 1247 switches::kEnableBrowserSideNavigation)) {
1276 // PlzNavigate uses a significantly different logic for renderer initiated 1248 // PlzNavigate uses a significantly different logic for renderer initiated
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 RenderFrameProxyHost* proxy = 2655 RenderFrameProxyHost* proxy =
2684 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); 2656 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance());
2685 EXPECT_TRUE(proxy); 2657 EXPECT_TRUE(proxy);
2686 2658
2687 // Since the B->C navigation happened while the current page was focused, 2659 // Since the B->C navigation happened while the current page was focused,
2688 // page focus should propagate to the new subframe process. Check that 2660 // page focus should propagate to the new subframe process. Check that
2689 // process C received the proper focus message. 2661 // process C received the proper focus message.
2690 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); 2662 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID());
2691 } 2663 }
2692 2664
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 RenderFrame was not live, the new RenderFrameHost should be
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. This will
2890 // cause the next navigation to "chrome://bar" to require a different WebUI
2891 // than the current one, forcing it to be treated as cross-site.
2892 set_webui_type(2);
2893
2894 // Navigation request.
2895 const GURL kUrl("chrome://bar");
2896 NavigationEntryImpl entry(nullptr /* instance */, -1 /* page_id */, kUrl,
2897 Referrer(), base::string16() /* title */,
2898 ui::PAGE_TRANSITION_TYPED,
2899 false /* is_renderer_init */);
2900 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
2901 scoped_ptr<NavigationRequest> navigation_request =
2902 NavigationRequest::CreateBrowserInitiated(
2903 contents()->GetFrameTree()->root(), frame_entry->url(),
2904 frame_entry->referrer(), *frame_entry, entry,
2905 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
2906 static_cast<NavigationControllerImpl*>(&controller()));
2907 manager->DidCreateNavigationRequest(*navigation_request);
2908
2909 // The current WebUI should still be in place and there should be a new
2910 // active WebUI instance in the speculative RenderFrameHost.
2911 EXPECT_TRUE(manager->current_frame_host()->web_ui());
2912 EXPECT_FALSE(manager->current_frame_host()->pending_web_ui());
2913 TestRenderFrameHost* speculative_host =
2914 static_cast<TestRenderFrameHost*>(GetPendingFrameHost(manager));
2915 EXPECT_TRUE(speculative_host);
2916 WebUIImpl* next_web_ui = manager->GetNavigatingWebUI();
2917 EXPECT_TRUE(next_web_ui);
2918 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
2919 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
2920 EXPECT_FALSE(speculative_host->pending_web_ui());
2921
2922 // Prepare to commit, update the navigating RenderFrameHost.
2923 EXPECT_EQ(speculative_host,
2924 manager->GetFrameHostForNavigation(*navigation_request));
2925
2926 EXPECT_TRUE(manager->current_frame_host()->web_ui());
2927 EXPECT_FALSE(manager->current_frame_host()->pending_web_ui());
2928 EXPECT_EQ(speculative_host, GetPendingFrameHost(manager));
2929 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
2930 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
2931 EXPECT_EQ(next_web_ui, manager->GetNavigatingWebUI());
2932 EXPECT_FALSE(speculative_host->pending_web_ui());
2933
2934 // The RenderFrameHost committed.
2935 manager->DidNavigateFrame(speculative_host, true);
2936 EXPECT_EQ(speculative_host, manager->current_frame_host());
2937 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui());
2938 EXPECT_FALSE(GetPendingFrameHost(manager));
2939 EXPECT_FALSE(speculative_host->pending_web_ui());
2940 EXPECT_FALSE(manager->GetNavigatingWebUI());
2941 }
2942
2943 } // namespace content 2665 } // 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