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

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

Issue 1066823004: PlzNavigate: improve tracking of improper subframe swap-out. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/macros.h" 6 #include "base/macros.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/frame_host/navigation_request.h" 10 #include "content/browser/frame_host/navigation_request.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 267 }
268 268
269 // PlzNavigate: Test that a proper NavigationRequest is created by 269 // PlzNavigate: Test that a proper NavigationRequest is created by
270 // RequestNavigation. 270 // RequestNavigation.
271 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { 271 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
272 const GURL kUrl1("http://www.google.com/"); 272 const GURL kUrl1("http://www.google.com/");
273 const GURL kUrl2("http://www.chromium.org/"); 273 const GURL kUrl2("http://www.chromium.org/");
274 const GURL kUrl3("http://www.gmail.com/"); 274 const GURL kUrl3("http://www.gmail.com/");
275 275
276 contents()->NavigateAndCommit(kUrl1); 276 contents()->NavigateAndCommit(kUrl1);
277 process()->sink().ClearMessages();
277 278
278 // Add a subframe. 279 // Add a subframe.
279 FrameTreeNode* root_node = contents()->GetFrameTree()->root(); 280 FrameTreeNode* root_node = contents()->GetFrameTree()->root();
281 NavigatorImpl* navigator =
282 static_cast<NavigatorImpl*>(root_node->navigator());
280 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); 283 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child");
281 ASSERT_TRUE(subframe_rfh); 284 ASSERT_TRUE(subframe_rfh);
282 285
283 // Start a navigation at the subframe. 286 // Start a navigation at the subframe.
284 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); 287 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
285 RequestNavigation(subframe_node, kUrl2); 288 RequestNavigation(subframe_node, kUrl2);
286 NavigationRequest* subframe_request = 289 NavigationRequest* subframe_request =
287 GetNavigationRequestForFrameTreeNode(subframe_node); 290 navigator->GetNavigationRequestForNodeForTesting(subframe_node);
288 TestNavigationURLLoader* subframe_loader = 291 TestNavigationURLLoader* subframe_loader =
289 GetLoaderForNavigationRequest(subframe_request); 292 GetLoaderForNavigationRequest(subframe_request);
290 293
291 // Subframe navigations should start right away as they don't have to request 294 // Subframe navigations should start right away as they don't have to request
292 // beforeUnload to run at the renderer. 295 // beforeUnload to run at the renderer.
293 ASSERT_TRUE(subframe_request); 296 ASSERT_TRUE(subframe_request);
294 ASSERT_TRUE(subframe_loader); 297 ASSERT_TRUE(subframe_loader);
295 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); 298 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state());
296 EXPECT_EQ(kUrl2, subframe_request->common_params().url); 299 EXPECT_EQ(kUrl2, subframe_request->common_params().url);
297 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); 300 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url);
(...skipping 10 matching lines...) Expand all
308 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 311 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
309 switches::kSitePerProcess)) { 312 switches::kSitePerProcess)) {
310 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 313 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
311 } else { 314 } else {
312 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); 315 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
313 } 316 }
314 317
315 // Now start a navigation at the root node. 318 // Now start a navigation at the root node.
316 RequestNavigation(root_node, kUrl3); 319 RequestNavigation(root_node, kUrl3);
317 NavigationRequest* main_request = 320 NavigationRequest* main_request =
318 GetNavigationRequestForFrameTreeNode(root_node); 321 navigator->GetNavigationRequestForNodeForTesting(root_node);
319 ASSERT_TRUE(main_request); 322 ASSERT_TRUE(main_request);
320 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, 323 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE,
321 main_request->state()); 324 main_request->state());
322 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); 325 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
323 326
324 // Simulate a BeforeUnloadACK IPC on the main frame. 327 // Simulate a BeforeUnloadACK IPC on the main frame.
325 main_test_rfh()->SendBeforeUnloadACK(true); 328 main_test_rfh()->SendBeforeUnloadACK(true);
326 TestNavigationURLLoader* main_loader = 329 TestNavigationURLLoader* main_loader =
327 GetLoaderForNavigationRequest(main_request); 330 GetLoaderForNavigationRequest(main_request);
328 EXPECT_EQ(kUrl3, main_request->common_params().url); 331 EXPECT_EQ(kUrl3, main_request->common_params().url);
329 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); 332 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url);
330 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); 333 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
331 EXPECT_TRUE(main_loader->request_info()->is_main_frame); 334 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
332 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); 335 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
333 EXPECT_TRUE(main_request->browser_initiated()); 336 EXPECT_TRUE(main_request->browser_initiated());
334 // BeforeUnloadACK was received from the renderer so the navigation should 337 // BeforeUnloadACK was received from the renderer so the navigation should
335 // have started. 338 // have started.
336 EXPECT_EQ(NavigationRequest::STARTED, main_request->state()); 339 EXPECT_EQ(NavigationRequest::STARTED, main_request->state());
337 340
338 // Main frame navigation to a different site should use a speculative 341 // Main frame navigation to a different site should use a speculative
339 // RenderFrameHost. 342 // RenderFrameHost.
340 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); 343 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node));
341 344
342 // As the main frame hasn't yet committed the subframe still exists. Thus, the 345 // As the main frame hasn't yet committed the subframe still exists. Thus, the
343 // above situation regarding subframe navigations is valid here. 346 // above situation regarding subframe navigations is valid here.
347 ASSERT_TRUE(navigator->GetNavigationRequestForNodeForTesting(subframe_node));
344 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 348 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
345 switches::kSitePerProcess)) { 349 switches::kSitePerProcess)) {
346 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 350 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
347 } else { 351 } else {
348 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); 352 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
349 } 353 }
354
355 // Have the root node's speculative RenderFrameHost commit the navigation.
356 scoped_refptr<ResourceResponse> response(new ResourceResponse);
357 main_loader->CallOnResponseStarted(response, MakeEmptyStream());
358 TestRenderFrameHost* speculative_root_rfh =
359 GetSpeculativeRenderFrameHost(root_node);
360 ASSERT_TRUE(speculative_root_rfh);
361 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_root_rfh));
362 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
363
364 // The subframe request is still there as the subframe still exists.
365 ASSERT_TRUE(navigator->GetNavigationRequestForNodeForTesting(subframe_node));
366
367 // Commit the navigation.
368 speculative_root_rfh->SendNavigate(1, kUrl3);
369
370 // The subframe request should have been cleaned up with the subframe.
371 ASSERT_FALSE(navigator->GetNavigationRequestForNodeForTesting(subframe_node));
carlosk 2015/04/08 09:01:48 As I removed the N::CancelNavigation from FTN::~Fr
clamy 2015/04/08 11:29:11 Well since it's failing they are not.
carlosk 2015/04/08 16:05:39 Yeah. It did pass on my workstation but I only tes
350 } 372 }
351 373
352 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels 374 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels
353 // the navigation. 375 // the navigation.
354 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { 376 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
355 const GURL kUrl1("http://www.chromium.org/"); 377 const GURL kUrl1("http://www.chromium.org/");
356 const GURL kUrl2("http://www.google.com/"); 378 const GURL kUrl2("http://www.google.com/");
357 379
358 // Load a URL. 380 // Load a URL.
359 contents()->NavigateAndCommit(kUrl1); 381 contents()->NavigateAndCommit(kUrl1);
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 1152
1131 SiteInstance* converted_instance_2 = 1153 SiteInstance* converted_instance_2 =
1132 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get()); 1154 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get());
1133 // Should return |unrelated_instance| because its site matches and it is 1155 // Should return |unrelated_instance| because its site matches and it is
1134 // unrelated to the current SiteInstance. 1156 // unrelated to the current SiteInstance.
1135 EXPECT_EQ(unrelated_instance.get(), converted_instance_2); 1157 EXPECT_EQ(unrelated_instance.get(), converted_instance_2);
1136 } 1158 }
1137 } 1159 }
1138 1160
1139 } // namespace content 1161 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698