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

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

Issue 2803633004: Revert of Keep track in the browser of which frames have onunload and onbeforeunload handlers. (Closed)
Patch Set: Created 3 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 EXPECT_EQ(site_instance_id_1, main_test_rfh()->GetSiteInstance()->GetId()); 262 EXPECT_EQ(site_instance_id_1, main_test_rfh()->GetSiteInstance()->GetId());
263 } 263 }
264 264
265 // PlzNavigate: Test that a beforeUnload denial cancels the navigation. 265 // PlzNavigate: Test that a beforeUnload denial cancels the navigation.
266 TEST_F(NavigatorTestWithBrowserSideNavigation, 266 TEST_F(NavigatorTestWithBrowserSideNavigation,
267 BeforeUnloadDenialCancelNavigation) { 267 BeforeUnloadDenialCancelNavigation) {
268 const GURL kUrl1("http://www.google.com/"); 268 const GURL kUrl1("http://www.google.com/");
269 const GURL kUrl2("http://www.chromium.org/"); 269 const GURL kUrl2("http://www.chromium.org/");
270 270
271 contents()->NavigateAndCommit(kUrl1); 271 contents()->NavigateAndCommit(kUrl1);
272 main_test_rfh()->set_has_beforeunload_handlers();
273 272
274 // Start a new navigation. 273 // Start a new navigation.
275 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 274 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
276 RequestNavigation(node, kUrl2); 275 RequestNavigation(node, kUrl2);
277 NavigationRequest* request = node->navigation_request(); 276 NavigationRequest* request = node->navigation_request();
278 ASSERT_TRUE(request); 277 ASSERT_TRUE(request);
279 EXPECT_TRUE(request->browser_initiated()); 278 EXPECT_TRUE(request->browser_initiated());
280 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state()); 279 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state());
281 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); 280 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
282 RenderFrameDeletedObserver rfh_deleted_observer( 281 RenderFrameDeletedObserver rfh_deleted_observer(
(...skipping 18 matching lines...) Expand all
301 // Add a subframe. 300 // Add a subframe.
302 FrameTreeNode* root_node = contents()->GetFrameTree()->root(); 301 FrameTreeNode* root_node = contents()->GetFrameTree()->root();
303 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); 302 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child");
304 ASSERT_TRUE(subframe_rfh); 303 ASSERT_TRUE(subframe_rfh);
305 304
306 // Start a navigation at the subframe. 305 // Start a navigation at the subframe.
307 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); 306 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
308 RequestNavigation(subframe_node, kUrl2); 307 RequestNavigation(subframe_node, kUrl2);
309 NavigationRequest* subframe_request = subframe_node->navigation_request(); 308 NavigationRequest* subframe_request = subframe_node->navigation_request();
310 309
310 // We should be waiting for the BeforeUnload event to execute in the subframe.
311 ASSERT_TRUE(subframe_request); 311 ASSERT_TRUE(subframe_request);
312 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE,
313 subframe_request->state());
314 EXPECT_TRUE(subframe_rfh->is_waiting_for_beforeunload_ack());
312 315
316 // Simulate the BeforeUnload ACK. The navigation should start.
317 subframe_rfh->SendBeforeUnloadACK(true);
313 TestNavigationURLLoader* subframe_loader = 318 TestNavigationURLLoader* subframe_loader =
314 GetLoaderForNavigationRequest(subframe_request); 319 GetLoaderForNavigationRequest(subframe_request);
315 ASSERT_TRUE(subframe_loader); 320 ASSERT_TRUE(subframe_loader);
316 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); 321 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state());
317 EXPECT_EQ(kUrl2, subframe_request->common_params().url); 322 EXPECT_EQ(kUrl2, subframe_request->common_params().url);
318 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); 323 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url);
319 // First party for cookies url should be that of the main frame. 324 // First party for cookies url should be that of the main frame.
320 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); 325 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies);
321 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); 326 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
322 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); 327 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
323 EXPECT_TRUE(subframe_request->browser_initiated()); 328 EXPECT_TRUE(subframe_request->browser_initiated());
324 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); 329 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
325 330
326 // Subframe navigations should never create a speculative RenderFrameHost, 331 // Subframe navigations should never create a speculative RenderFrameHost,
327 // unless site-per-process is enabled. In that case, as the subframe 332 // unless site-per-process is enabled. In that case, as the subframe
328 // navigation is to a different site and is still ongoing, it should have one. 333 // navigation is to a different site and is still ongoing, it should have one.
329 if (AreAllSitesIsolatedForTesting()) { 334 if (AreAllSitesIsolatedForTesting()) {
330 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 335 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
331 } else { 336 } else {
332 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); 337 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
333 } 338 }
334 339
335 // Now start a navigation at the root node. 340 // Now start a navigation at the root node.
336 RequestNavigation(root_node, kUrl3); 341 RequestNavigation(root_node, kUrl3);
337 NavigationRequest* main_request = root_node->navigation_request(); 342 NavigationRequest* main_request = root_node->navigation_request();
338 ASSERT_TRUE(main_request); 343 ASSERT_TRUE(main_request);
344 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE,
345 main_request->state());
339 346
340 // Main frame navigation to a different site should use a speculative 347 // Main frame navigation to a different site should use a speculative
341 // RenderFrameHost. 348 // RenderFrameHost.
342 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); 349 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node));
343 350
351 // Simulate a BeforeUnloadACK IPC on the main frame.
352 main_test_rfh()->SendBeforeUnloadACK(true);
344 TestNavigationURLLoader* main_loader = 353 TestNavigationURLLoader* main_loader =
345 GetLoaderForNavigationRequest(main_request); 354 GetLoaderForNavigationRequest(main_request);
346 EXPECT_EQ(kUrl3, main_request->common_params().url); 355 EXPECT_EQ(kUrl3, main_request->common_params().url);
347 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); 356 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url);
348 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); 357 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
349 EXPECT_TRUE(main_loader->request_info()->is_main_frame); 358 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
350 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); 359 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
351 EXPECT_TRUE(main_request->browser_initiated()); 360 EXPECT_TRUE(main_request->browser_initiated());
352 // BeforeUnloadACK was received from the renderer so the navigation should 361 // BeforeUnloadACK was received from the renderer so the navigation should
353 // have started. 362 // have started.
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1280
1272 // Navigate to the new URL. 1281 // Navigate to the new URL.
1273 contents()->NavigateAndCommit(kUrl2); 1282 contents()->NavigateAndCommit(kUrl2);
1274 1283
1275 // Check the feature policy after navigation. 1284 // Check the feature policy after navigation.
1276 FeaturePolicy* final_feature_policy = main_test_rfh()->get_feature_policy(); 1285 FeaturePolicy* final_feature_policy = main_test_rfh()->get_feature_policy();
1277 ASSERT_EQ(original_feature_policy, final_feature_policy); 1286 ASSERT_EQ(original_feature_policy, final_feature_policy);
1278 } 1287 }
1279 1288
1280 } // namespace content 1289 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.cc ('k') | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698