OLD | NEW |
---|---|
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 Loading... | |
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(); | |
272 | 273 |
273 // Start a new navigation. | 274 // Start a new navigation. |
274 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 275 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
275 RequestNavigation(node, kUrl2); | 276 RequestNavigation(node, kUrl2); |
276 NavigationRequest* request = node->navigation_request(); | 277 NavigationRequest* request = node->navigation_request(); |
277 ASSERT_TRUE(request); | 278 ASSERT_TRUE(request); |
278 EXPECT_TRUE(request->browser_initiated()); | 279 EXPECT_TRUE(request->browser_initiated()); |
279 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state()); | 280 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state()); |
280 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); | 281 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); |
281 RenderFrameDeletedObserver rfh_deleted_observer( | 282 RenderFrameDeletedObserver rfh_deleted_observer( |
(...skipping 18 matching lines...) Expand all Loading... | |
300 // Add a subframe. | 301 // Add a subframe. |
301 FrameTreeNode* root_node = contents()->GetFrameTree()->root(); | 302 FrameTreeNode* root_node = contents()->GetFrameTree()->root(); |
302 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); | 303 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); |
303 ASSERT_TRUE(subframe_rfh); | 304 ASSERT_TRUE(subframe_rfh); |
304 | 305 |
305 // Start a navigation at the subframe. | 306 // Start a navigation at the subframe. |
306 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); | 307 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); |
307 RequestNavigation(subframe_node, kUrl2); | 308 RequestNavigation(subframe_node, kUrl2); |
308 NavigationRequest* subframe_request = subframe_node->navigation_request(); | 309 NavigationRequest* subframe_request = subframe_node->navigation_request(); |
309 | 310 |
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()); | |
315 | 312 |
316 // Simulate the BeforeUnload ACK. The navigation should start. | |
317 subframe_rfh->SendBeforeUnloadACK(true); | |
nasko
2017/03/29 23:31:26
Aren't we losing coverage for a beforeunload handl
jam
2017/03/30 14:53:22
we already have test cases for this, i.e. all the
| |
318 TestNavigationURLLoader* subframe_loader = | 313 TestNavigationURLLoader* subframe_loader = |
319 GetLoaderForNavigationRequest(subframe_request); | 314 GetLoaderForNavigationRequest(subframe_request); |
320 ASSERT_TRUE(subframe_loader); | 315 ASSERT_TRUE(subframe_loader); |
321 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); | 316 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); |
322 EXPECT_EQ(kUrl2, subframe_request->common_params().url); | 317 EXPECT_EQ(kUrl2, subframe_request->common_params().url); |
323 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); | 318 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); |
324 // First party for cookies url should be that of the main frame. | 319 // First party for cookies url should be that of the main frame. |
325 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); | 320 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); |
326 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); | 321 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); |
327 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); | 322 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); |
328 EXPECT_TRUE(subframe_request->browser_initiated()); | 323 EXPECT_TRUE(subframe_request->browser_initiated()); |
329 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); | 324 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); |
330 | 325 |
331 // Subframe navigations should never create a speculative RenderFrameHost, | 326 // Subframe navigations should never create a speculative RenderFrameHost, |
332 // unless site-per-process is enabled. In that case, as the subframe | 327 // unless site-per-process is enabled. In that case, as the subframe |
333 // navigation is to a different site and is still ongoing, it should have one. | 328 // navigation is to a different site and is still ongoing, it should have one. |
334 if (AreAllSitesIsolatedForTesting()) { | 329 if (AreAllSitesIsolatedForTesting()) { |
335 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); | 330 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); |
336 } else { | 331 } else { |
337 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); | 332 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); |
338 } | 333 } |
339 | 334 |
340 // Now start a navigation at the root node. | 335 // Now start a navigation at the root node. |
341 RequestNavigation(root_node, kUrl3); | 336 RequestNavigation(root_node, kUrl3); |
342 NavigationRequest* main_request = root_node->navigation_request(); | 337 NavigationRequest* main_request = root_node->navigation_request(); |
343 ASSERT_TRUE(main_request); | 338 ASSERT_TRUE(main_request); |
344 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, | |
345 main_request->state()); | |
346 | 339 |
347 // Main frame navigation to a different site should use a speculative | 340 // Main frame navigation to a different site should use a speculative |
348 // RenderFrameHost. | 341 // RenderFrameHost. |
349 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); | 342 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); |
350 | 343 |
351 // Simulate a BeforeUnloadACK IPC on the main frame. | |
352 main_test_rfh()->SendBeforeUnloadACK(true); | |
353 TestNavigationURLLoader* main_loader = | 344 TestNavigationURLLoader* main_loader = |
354 GetLoaderForNavigationRequest(main_request); | 345 GetLoaderForNavigationRequest(main_request); |
355 EXPECT_EQ(kUrl3, main_request->common_params().url); | 346 EXPECT_EQ(kUrl3, main_request->common_params().url); |
356 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); | 347 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); |
357 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); | 348 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); |
358 EXPECT_TRUE(main_loader->request_info()->is_main_frame); | 349 EXPECT_TRUE(main_loader->request_info()->is_main_frame); |
359 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); | 350 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); |
360 EXPECT_TRUE(main_request->browser_initiated()); | 351 EXPECT_TRUE(main_request->browser_initiated()); |
361 // BeforeUnloadACK was received from the renderer so the navigation should | 352 // BeforeUnloadACK was received from the renderer so the navigation should |
362 // have started. | 353 // have started. |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1280 | 1271 |
1281 // Navigate to the new URL. | 1272 // Navigate to the new URL. |
1282 contents()->NavigateAndCommit(kUrl2); | 1273 contents()->NavigateAndCommit(kUrl2); |
1283 | 1274 |
1284 // Check the feature policy after navigation. | 1275 // Check the feature policy after navigation. |
1285 FeaturePolicy* final_feature_policy = main_test_rfh()->get_feature_policy(); | 1276 FeaturePolicy* final_feature_policy = main_test_rfh()->get_feature_policy(); |
1286 ASSERT_EQ(original_feature_policy, final_feature_policy); | 1277 ASSERT_EQ(original_feature_policy, final_feature_policy); |
1287 } | 1278 } |
1288 | 1279 |
1289 } // namespace content | 1280 } // namespace content |
OLD | NEW |