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

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

Issue 903043002: Skip BeforeUnload on cross-site navigations when there are no handlers Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 193 EXPECT_FALSE(node->render_manager()->pending_frame_host());
194 } 194 }
195 195
196 // PlzNavigate: Test that a beforeUnload denial cancels the navigation. 196 // PlzNavigate: Test that a beforeUnload denial cancels the navigation.
197 TEST_F(NavigatorTestWithBrowserSideNavigation, 197 TEST_F(NavigatorTestWithBrowserSideNavigation,
198 BeforeUnloadDenialCancelNavigation) { 198 BeforeUnloadDenialCancelNavigation) {
199 const GURL kUrl1("http://www.google.com/"); 199 const GURL kUrl1("http://www.google.com/");
200 const GURL kUrl2("http://www.chromium.org/"); 200 const GURL kUrl2("http://www.chromium.org/");
201 201
202 contents()->NavigateAndCommit(kUrl1); 202 contents()->NavigateAndCommit(kUrl1);
203 main_test_rfh()->SendBeforeUnloadHandlersPresent(true);
203 204
204 // Start a new navigation. 205 // Start a new navigation.
205 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 206 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
206 RequestNavigation(node, kUrl2); 207 RequestNavigation(node, kUrl2);
207 NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node); 208 NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node);
208 ASSERT_TRUE(request); 209 ASSERT_TRUE(request);
209 EXPECT_TRUE(request->browser_initiated()); 210 EXPECT_TRUE(request->browser_initiated());
210 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state()); 211 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state());
211 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 212 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
212 213
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 261 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
261 } else { 262 } else {
262 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); 263 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
263 } 264 }
264 265
265 // Now start a navigation at the root node. 266 // Now start a navigation at the root node.
266 RequestNavigation(root_node, kUrl3); 267 RequestNavigation(root_node, kUrl3);
267 NavigationRequest* main_request = 268 NavigationRequest* main_request =
268 GetNavigationRequestForFrameTreeNode(root_node); 269 GetNavigationRequestForFrameTreeNode(root_node);
269 ASSERT_TRUE(main_request); 270 ASSERT_TRUE(main_request);
270 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, 271 EXPECT_EQ(NavigationRequest::STARTED, main_request->state());
271 main_request->state());
272 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
273
274 // Simulate a BeforeUnloadACK IPC on the main frame.
275 main_test_rfh()->SendBeforeUnloadACK(true);
Charlie Reis 2015/02/17 23:04:31 We should include a PlzNavigate test for the case
clamy 2015/02/18 13:27:23 I added a test to check that we properly wait befo
Charlie Reis 2015/02/19 00:33:44 Acknowledged.
276 TestNavigationURLLoader* main_loader = 272 TestNavigationURLLoader* main_loader =
277 GetLoaderForNavigationRequest(main_request); 273 GetLoaderForNavigationRequest(main_request);
278 EXPECT_EQ(kUrl3, main_request->common_params().url); 274 EXPECT_EQ(kUrl3, main_request->common_params().url);
279 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); 275 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url);
280 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); 276 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
281 EXPECT_TRUE(main_loader->request_info()->is_main_frame); 277 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
282 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); 278 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
283 EXPECT_TRUE(main_request->browser_initiated()); 279 EXPECT_TRUE(main_request->browser_initiated());
284 // BeforeUnloadACK was received from the renderer so the navigation should
285 // have started.
286 EXPECT_EQ(NavigationRequest::STARTED, main_request->state());
287 280
288 // Main frame navigation to a different site should use a speculative 281 // Main frame navigation to a different site should use a speculative
289 // RenderFrameHost. 282 // RenderFrameHost.
290 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); 283 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node));
291 284
292 // As the main frame hasn't yet committed the subframe still exists. Thus, the 285 // As the main frame hasn't yet committed the subframe still exists. Thus, the
293 // above situation regarding subframe navigations is valid here. 286 // above situation regarding subframe navigations is valid here.
294 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 287 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
295 switches::kSitePerProcess)) { 288 switches::kSitePerProcess)) {
296 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 289 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); 684 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
692 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1)); 685 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1));
693 686
694 // Now go back to the initial site so that the swapped out RenderFrameHost 687 // Now go back to the initial site so that the swapped out RenderFrameHost
695 // should be reused. 688 // should be reused.
696 process()->sink().ClearMessages(); 689 process()->sink().ClearMessages();
697 static_cast<MockRenderProcessHost*>(rfh1->GetProcess()) 690 static_cast<MockRenderProcessHost*>(rfh1->GetProcess())
698 ->sink() 691 ->sink()
699 .ClearMessages(); 692 .ClearMessages();
700 RequestNavigation(node, kUrl1); 693 RequestNavigation(node, kUrl1);
701 main_test_rfh()->SendBeforeUnloadACK(true);
702 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); 694 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
703 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, 695 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT,
704 GetSpeculativeRenderFrameHost(node)->rfh_state()); 696 GetSpeculativeRenderFrameHost(node)->rfh_state());
705 697
706 scoped_refptr<ResourceResponse> response(new ResourceResponse); 698 scoped_refptr<ResourceResponse> response(new ResourceResponse);
707 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node)) 699 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
708 ->CallOnResponseStarted(response, MakeEmptyStream()); 700 ->CallOnResponseStarted(response, MakeEmptyStream());
709 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); 701 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
710 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, 702 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT,
711 GetSpeculativeRenderFrameHost(node)->rfh_state()); 703 GetSpeculativeRenderFrameHost(node)->rfh_state());
712 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1)); 704 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1));
713 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); 705 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
714 706
715 rfh1->SendNavigate(1, kUrl1); 707 rfh1->SendNavigate(1, kUrl1);
716 EXPECT_EQ(rfh1, main_test_rfh()); 708 EXPECT_EQ(rfh1, main_test_rfh());
717 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 709 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
718 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1)); 710 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1));
719 } 711 }
720 712
721 } // namespace content 713 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698