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

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

Issue 1002803002: Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: relax the dcheck Created 5 years, 7 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 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/frame_host/cross_site_transferring_request.h" 10 #include "content/browser/frame_host/cross_site_transferring_request.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void set_should_create_webui(bool should_create_webui) { 255 void set_should_create_webui(bool should_create_webui) {
256 factory_.set_should_create_webui(should_create_webui); 256 factory_.set_should_create_webui(should_create_webui);
257 } 257 }
258 258
259 void NavigateActiveAndCommit(const GURL& url) { 259 void NavigateActiveAndCommit(const GURL& url) {
260 // Note: we navigate the active RenderFrameHost because previous navigations 260 // Note: we navigate the active RenderFrameHost because previous navigations
261 // won't have committed yet, so NavigateAndCommit does the wrong thing 261 // won't have committed yet, so NavigateAndCommit does the wrong thing
262 // for us. 262 // for us.
263 controller().LoadURL( 263 controller().LoadURL(
264 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 264 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
265 int entry_id = controller().GetPendingEntry()->GetUniqueID();
265 266
266 // Simulate the BeforeUnload_ACK that is received from the current renderer 267 // Simulate the BeforeUnload_ACK that is received from the current renderer
267 // for a cross-site navigation. 268 // for a cross-site navigation.
268 // PlzNavigate: it is necessary to call PrepareForCommit before getting the 269 // PlzNavigate: it is necessary to call PrepareForCommit before getting the
269 // main and the pending frame because when we are trying to navigate to a 270 // main and the pending frame because when we are trying to navigate to a
270 // WebUI from a new tab, a RenderFrameHost is created to display it that is 271 // WebUI from a new tab, a RenderFrameHost is created to display it that is
271 // committed immediately (since it is a new tab). Therefore the main frame 272 // committed immediately (since it is a new tab). Therefore the main frame
272 // is replaced without a pending frame being created, and we don't get the 273 // is replaced without a pending frame being created, and we don't get the
273 // right values for the RFH to navigate: we try to use the old one that has 274 // right values for the RFH to navigate: we try to use the old one that has
274 // been deleted in the meantime. 275 // been deleted in the meantime.
275 contents()->GetMainFrame()->PrepareForCommit(); 276 contents()->GetMainFrame()->PrepareForCommit();
276 277
277 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); 278 TestRenderFrameHost* old_rfh = contents()->GetMainFrame();
278 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() 279 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame()
279 ? contents()->GetPendingMainFrame() 280 ? contents()->GetPendingMainFrame()
280 : old_rfh; 281 : old_rfh;
281 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); 282 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state());
282 283
283 // Commit the navigation with a new page ID. 284 // Commit the navigation with a new page ID.
284 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( 285 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
285 active_rfh->GetSiteInstance()); 286 active_rfh->GetSiteInstance());
286 287
287 // Use an observer to avoid accessing a deleted renderer later on when the 288 // Use an observer to avoid accessing a deleted renderer later on when the
288 // state is being checked. 289 // state is being checked.
289 RenderFrameHostDeletedObserver rfh_observer(old_rfh); 290 RenderFrameHostDeletedObserver rfh_observer(old_rfh);
290 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); 291 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost());
291 active_rfh->SendNavigate(max_page_id + 1, url); 292 active_rfh->SendNavigate(max_page_id + 1, entry_id, true, url);
292 293
293 // Make sure that we start to run the unload handler at the time of commit. 294 // Make sure that we start to run the unload handler at the time of commit.
294 bool expecting_rfh_shutdown = false; 295 bool expecting_rfh_shutdown = false;
295 if (old_rfh != active_rfh && !rfh_observer.deleted()) { 296 if (old_rfh != active_rfh && !rfh_observer.deleted()) {
296 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, 297 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT,
297 old_rfh->rfh_state()); 298 old_rfh->rfh_state());
298 if (!old_rfh->GetSiteInstance()->active_frame_count()) { 299 if (!old_rfh->GetSiteInstance()->active_frame_count()) {
299 expecting_rfh_shutdown = true; 300 expecting_rfh_shutdown = true;
300 EXPECT_TRUE( 301 EXPECT_TRUE(
301 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion( 302 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 const GURL kChromeURL("chrome://foo"); 345 const GURL kChromeURL("chrome://foo");
345 const GURL kDestUrl("http://www.google.com/"); 346 const GURL kDestUrl("http://www.google.com/");
346 347
347 // Navigate our first tab to a chrome url and then to the destination. 348 // Navigate our first tab to a chrome url and then to the destination.
348 NavigateActiveAndCommit(kChromeURL); 349 NavigateActiveAndCommit(kChromeURL);
349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); 350 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame();
350 351
351 // Navigate to a cross-site URL. 352 // Navigate to a cross-site URL.
352 contents()->GetController().LoadURL( 353 contents()->GetController().LoadURL(
353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 354 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
355 int entry_id = contents()->GetController().GetPendingEntry()->GetUniqueID();
354 contents()->GetMainFrame()->PrepareForCommit(); 356 contents()->GetMainFrame()->PrepareForCommit();
355 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 357 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
356 358
357 // Manually increase the number of active frames in the 359 // Manually increase the number of active frames in the
358 // SiteInstance that ntp_rfh belongs to, to prevent it from being 360 // SiteInstance that ntp_rfh belongs to, to prevent it from being
359 // destroyed when it gets swapped out. 361 // destroyed when it gets swapped out.
360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); 362 ntp_rfh->GetSiteInstance()->increment_active_frame_count();
361 363
362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); 364 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame();
363 CHECK(dest_rfh); 365 CHECK(dest_rfh);
364 EXPECT_NE(ntp_rfh, dest_rfh); 366 EXPECT_NE(ntp_rfh, dest_rfh);
365 367
366 // BeforeUnload finishes. 368 // BeforeUnload finishes.
367 ntp_rfh->SendBeforeUnloadACK(true); 369 ntp_rfh->SendBeforeUnloadACK(true);
368 370
369 dest_rfh->SendNavigate(101, kDestUrl); 371 dest_rfh->SendNavigate(101, entry_id, true, kDestUrl);
370 ntp_rfh->OnSwappedOut(); 372 ntp_rfh->OnSwappedOut();
371 373
372 EXPECT_TRUE(ntp_rfh->is_swapped_out()); 374 EXPECT_TRUE(ntp_rfh->is_swapped_out());
373 return ntp_rfh; 375 return ntp_rfh;
374 } 376 }
375 377
376 // Returns the RenderFrameHost that should be used in the navigation to 378 // Returns the RenderFrameHost that should be used in the navigation to
377 // |entry|. 379 // |entry|.
378 RenderFrameHostImpl* NavigateToEntry( 380 RenderFrameHostImpl* NavigateToEntry(
379 RenderFrameHostManager* manager, 381 RenderFrameHostManager* manager,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 430
429 // Make a second tab. 431 // Make a second tab.
430 scoped_ptr<TestWebContents> contents2( 432 scoped_ptr<TestWebContents> contents2(
431 TestWebContents::Create(browser_context(), NULL)); 433 TestWebContents::Create(browser_context(), NULL));
432 434
433 // Load the two URLs in the second tab. Note that the first navigation creates 435 // Load the two URLs in the second tab. Note that the first navigation creates
434 // a RFH that's not pending (since there is no cross-site transition), so 436 // a RFH that's not pending (since there is no cross-site transition), so
435 // we use the committed one. 437 // we use the committed one.
436 contents2->GetController().LoadURL( 438 contents2->GetController().LoadURL(
437 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 439 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
440 int entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID();
438 contents2->GetMainFrame()->PrepareForCommit(); 441 contents2->GetMainFrame()->PrepareForCommit();
439 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); 442 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame();
440 EXPECT_FALSE(contents2->CrossProcessNavigationPending()); 443 EXPECT_FALSE(contents2->CrossProcessNavigationPending());
441 ntp_rfh2->SendNavigate(100, kChromeUrl); 444 ntp_rfh2->SendNavigate(100, entry_id, true, kChromeUrl);
442 445
443 // The second one is the opposite, creating a cross-site transition and 446 // The second one is the opposite, creating a cross-site transition and
444 // requiring a beforeunload ack. 447 // requiring a beforeunload ack.
445 contents2->GetController().LoadURL( 448 contents2->GetController().LoadURL(
446 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 449 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
450 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID();
447 contents2->GetMainFrame()->PrepareForCommit(); 451 contents2->GetMainFrame()->PrepareForCommit();
448 EXPECT_TRUE(contents2->CrossProcessNavigationPending()); 452 EXPECT_TRUE(contents2->CrossProcessNavigationPending());
449 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); 453 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame();
450 ASSERT_TRUE(dest_rfh2); 454 ASSERT_TRUE(dest_rfh2);
451 455
452 dest_rfh2->SendNavigate(101, kDestUrl); 456 dest_rfh2->SendNavigate(101, entry_id, true, kDestUrl);
453 457
454 // The two RFH's should be different in every way. 458 // The two RFH's should be different in every way.
455 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); 459 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess());
456 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), 460 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(),
457 dest_rfh2->GetSiteInstance()); 461 dest_rfh2->GetSiteInstance());
458 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( 462 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance(
459 contents()->GetMainFrame()->GetSiteInstance())); 463 contents()->GetMainFrame()->GetSiteInstance()));
460 464
461 // Navigate both to the new tab page, and verify that they share a 465 // Navigate both to the new tab page, and verify that they share a
462 // RenderProcessHost (not a SiteInstance). 466 // RenderProcessHost (not a SiteInstance).
463 NavigateActiveAndCommit(kChromeUrl); 467 NavigateActiveAndCommit(kChromeUrl);
464 EXPECT_FALSE(contents()->GetPendingMainFrame()); 468 EXPECT_FALSE(contents()->GetPendingMainFrame());
465 469
466 contents2->GetController().LoadURL( 470 contents2->GetController().LoadURL(
467 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 471 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
472 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID();
468 contents2->GetMainFrame()->PrepareForCommit(); 473 contents2->GetMainFrame()->PrepareForCommit();
469 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); 474 contents2->GetPendingMainFrame()->SendNavigate(102, entry_id, true,
475 kChromeUrl);
470 476
471 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), 477 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(),
472 contents2->GetMainFrame()->GetSiteInstance()); 478 contents2->GetMainFrame()->GetSiteInstance());
473 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), 479 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(),
474 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); 480 contents2->GetMainFrame()->GetSiteInstance()->GetProcess());
475 } 481 }
476 482
477 // Ensure that the browser ignores most IPC messages that arrive from a 483 // Ensure that the browser ignores most IPC messages that arrive from a
478 // RenderViewHost that has been swapped out. We do not want to take 484 // RenderViewHost that has been swapped out. We do not want to take
479 // action on requests from a non-active renderer. The main exception is 485 // action on requests from a non-active renderer. The main exception is
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 EXPECT_TRUE(observer.favicon_received()); 596 EXPECT_TRUE(observer.favicon_received());
591 } 597 }
592 598
593 // Create one more frame in the same SiteInstance where |rfh1| exists so that 599 // Create one more frame in the same SiteInstance where |rfh1| exists so that
594 // it doesn't get deleted on navigation to another site. 600 // it doesn't get deleted on navigation to another site.
595 rfh1->GetSiteInstance()->increment_active_frame_count(); 601 rfh1->GetSiteInstance()->increment_active_frame_count();
596 602
597 // Navigate to a cross-site URL and commit the new page. 603 // Navigate to a cross-site URL and commit the new page.
598 controller().LoadURL( 604 controller().LoadURL(
599 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 605 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
606 int entry_id = controller().GetPendingEntry()->GetUniqueID();
600 contents()->GetMainFrame()->PrepareForCommit(); 607 contents()->GetMainFrame()->PrepareForCommit();
601 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 608 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
602 contents()->TestDidNavigate(rfh2, 1, kDestUrl, ui::PAGE_TRANSITION_TYPED); 609 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kDestUrl,
610 ui::PAGE_TRANSITION_TYPED);
603 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 611 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
604 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 612 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
605 613
606 // The new RVH should be able to update its favicons. 614 // The new RVH should be able to update its favicons.
607 { 615 {
608 PluginFaviconMessageObserver observer(contents()); 616 PluginFaviconMessageObserver observer(contents());
609 EXPECT_TRUE(rfh2->GetRenderViewHost()->OnMessageReceived( 617 EXPECT_TRUE(rfh2->GetRenderViewHost()->OnMessageReceived(
610 ViewHostMsg_UpdateFaviconURL(rfh2->GetRenderViewHost()->GetRoutingID(), 618 ViewHostMsg_UpdateFaviconURL(rfh2->GetRenderViewHost()->GetRoutingID(),
611 icons))); 619 icons)));
612 EXPECT_TRUE(observer.favicon_received()); 620 EXPECT_TRUE(observer.favicon_received());
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 // the second navigation. We have to avoid this in order to exercise the 854 // the second navigation. We have to avoid this in order to exercise the
847 // target code path. 855 // target code path.
848 NavigateActiveAndCommit(kChromeUrl); 856 NavigateActiveAndCommit(kChromeUrl);
849 857
850 // Navigate. Note that "view source" URLs are implemented by putting the RFH 858 // Navigate. Note that "view source" URLs are implemented by putting the RFH
851 // into a view-source mode and then navigating to the inner URL, so that's why 859 // into a view-source mode and then navigating to the inner URL, so that's why
852 // the bare URL is what's committed and returned by the last committed entry's 860 // the bare URL is what's committed and returned by the last committed entry's
853 // GetURL() call. 861 // GetURL() call.
854 controller().LoadURL( 862 controller().LoadURL(
855 kViewSourceUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 863 kViewSourceUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
864 int entry_id = controller().GetPendingEntry()->GetUniqueID();
856 865
857 // Simulate response from RenderFrame for DispatchBeforeUnload. 866 // Simulate response from RenderFrame for DispatchBeforeUnload.
858 contents()->GetMainFrame()->PrepareForCommit(); 867 contents()->GetMainFrame()->PrepareForCommit();
859 ASSERT_TRUE(contents()->GetPendingMainFrame()) 868 ASSERT_TRUE(contents()->GetPendingMainFrame())
860 << "Expected new pending RenderFrameHost to be created."; 869 << "Expected new pending RenderFrameHost to be created.";
861 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); 870 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame();
862 int32 new_id = 871 int32 new_id =
863 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; 872 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1;
864 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); 873 contents()->GetPendingMainFrame()->SendNavigate(new_id, entry_id, true, kUrl);
865 874
866 EXPECT_EQ(1, controller().GetLastCommittedEntryIndex()); 875 EXPECT_EQ(1, controller().GetLastCommittedEntryIndex());
867 NavigationEntry* last_committed = controller().GetLastCommittedEntry(); 876 NavigationEntry* last_committed = controller().GetLastCommittedEntry();
868 ASSERT_NE(nullptr, last_committed); 877 ASSERT_NE(nullptr, last_committed);
869 EXPECT_EQ(kUrl, last_committed->GetURL()); 878 EXPECT_EQ(kUrl, last_committed->GetURL());
870 EXPECT_EQ(kViewSourceUrl, last_committed->GetVirtualURL()); 879 EXPECT_EQ(kViewSourceUrl, last_committed->GetVirtualURL());
871 EXPECT_FALSE(controller().GetPendingEntry()); 880 EXPECT_FALSE(controller().GetPendingEntry());
872 // Because we're using TestWebContents and TestRenderViewHost in this 881 // Because we're using TestWebContents and TestRenderViewHost in this
873 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no 882 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no
874 // EnableViewSourceMode message, here. 883 // EnableViewSourceMode message, here.
875 884
876 // Clear queued messages before load. 885 // Clear queued messages before load.
877 process()->sink().ClearMessages(); 886 process()->sink().ClearMessages();
878 887
879 // Navigate, again. 888 // Navigate, again.
880 controller().LoadURL( 889 controller().LoadURL(
881 kViewSourceUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 890 kViewSourceUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
891 entry_id = controller().GetPendingEntry()->GetUniqueID();
882 contents()->GetMainFrame()->PrepareForCommit(); 892 contents()->GetMainFrame()->PrepareForCommit();
883 893
884 // The same RenderViewHost should be reused. 894 // The same RenderViewHost should be reused.
885 EXPECT_FALSE(contents()->GetPendingMainFrame()); 895 EXPECT_FALSE(contents()->GetPendingMainFrame());
886 EXPECT_EQ(last_rfh, contents()->GetMainFrame()); 896 EXPECT_EQ(last_rfh, contents()->GetMainFrame());
887 897
888 // The renderer sends a commit. 898 // The renderer sends a commit.
889 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); 899 contents()->GetMainFrame()->SendNavigateWithTransition(
900 new_id, entry_id, false, kUrl, ui::PAGE_TRANSITION_TYPED);
890 EXPECT_EQ(1, controller().GetLastCommittedEntryIndex()); 901 EXPECT_EQ(1, controller().GetLastCommittedEntryIndex());
891 EXPECT_FALSE(controller().GetPendingEntry()); 902 EXPECT_FALSE(controller().GetPendingEntry());
892 903
893 // New message should be sent out to make sure to enter view-source mode. 904 // New message should be sent out to make sure to enter view-source mode.
894 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( 905 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching(
895 ViewMsg_EnableViewSourceMode::ID)); 906 ViewMsg_EnableViewSourceMode::ID));
896 } 907 }
897 908
898 // Tests the Init function by checking the initial RenderViewHost. 909 // Tests the Init function by checking the initial RenderViewHost.
899 TEST_F(RenderFrameHostManagerTest, Init) { 910 TEST_F(RenderFrameHostManagerTest, Init) {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 contents()->GetMainFrame()->PrepareForCommit(); 1191 contents()->GetMainFrame()->PrepareForCommit();
1181 // We should have a new pending RFH. 1192 // We should have a new pending RFH.
1182 // Note that in this case, the navigation has not committed, so evil_rfh will 1193 // Note that in this case, the navigation has not committed, so evil_rfh will
1183 // not be deleted yet. 1194 // not be deleted yet.
1184 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); 1195 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame());
1185 EXPECT_NE(evil_rfh->GetRenderViewHost(), 1196 EXPECT_NE(evil_rfh->GetRenderViewHost(),
1186 contents()->GetPendingMainFrame()->GetRenderViewHost()); 1197 contents()->GetPendingMainFrame()->GetRenderViewHost());
1187 1198
1188 // Before that RFH has committed, the evil page reloads itself. 1199 // Before that RFH has committed, the evil page reloads itself.
1189 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1200 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1190 params.page_id = 1; 1201 params.page_id = 0;
1202 params.nav_entry_id = 0;
1203 params.did_create_new_entry = false;
1191 params.url = kUrl2; 1204 params.url = kUrl2;
1192 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 1205 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
1193 params.should_update_history = false; 1206 params.should_update_history = false;
1194 params.gesture = NavigationGestureAuto; 1207 params.gesture = NavigationGestureAuto;
1195 params.was_within_same_page = false; 1208 params.was_within_same_page = false;
1196 params.is_post = false; 1209 params.is_post = false;
1197 params.page_state = PageState::CreateFromURL(kUrl2); 1210 params.page_state = PageState::CreateFromURL(kUrl2);
1198 1211
1199 contents()->GetFrameTree()->root()->navigator()->DidNavigate(evil_rfh, 1212 contents()->GetFrameTree()->root()->navigator()->DidNavigate(evil_rfh,
1200 params); 1213 params);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't 1273 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't
1261 // happen, but we have seen it when going back quickly across many entries 1274 // happen, but we have seen it when going back quickly across many entries
1262 // (http://crbug.com/93427). 1275 // (http://crbug.com/93427).
1263 contents()->GetController().GoBack(); 1276 contents()->GetController().GoBack();
1264 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); 1277 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK());
1265 contents()->GetMainFrame()->PrepareForCommit(); 1278 contents()->GetMainFrame()->PrepareForCommit();
1266 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); 1279 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK());
1267 1280
1268 // The back navigation commits. 1281 // The back navigation commits.
1269 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 1282 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1270 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 1283 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false,
1284 entry1->GetURL());
1271 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); 1285 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK());
1272 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); 1286 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state());
1273 1287
1274 // We should be able to navigate forward. 1288 // We should be able to navigate forward.
1275 contents()->GetController().GoForward(); 1289 contents()->GetController().GoForward();
1276 contents()->GetMainFrame()->PrepareForCommit(); 1290 contents()->GetMainFrame()->PrepareForCommit();
1277 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); 1291 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry();
1278 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); 1292 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetUniqueID(), false,
1293 entry2->GetURL());
1279 EXPECT_EQ(rfh2, main_test_rfh()); 1294 EXPECT_EQ(rfh2, main_test_rfh());
1280 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1295 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1281 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1296 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1282 rfh1->OnSwappedOut(); 1297 rfh1->OnSwappedOut();
1283 EXPECT_TRUE(rfh1->is_swapped_out()); 1298 EXPECT_TRUE(rfh1->is_swapped_out());
1284 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); 1299 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state());
1285 } 1300 }
1286 1301
1287 // Test that we create swapped out RFHs for the opener chain when navigating an 1302 // Test that we create swapped out RFHs for the opener chain when navigating an
1288 // opened tab cross-process. This allows us to support certain cross-process 1303 // opened tab cross-process. This allows us to support certain cross-process
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 contents()->GetMainFrame()->PrepareForCommit(); 1462 contents()->GetMainFrame()->PrepareForCommit();
1448 1463
1449 // Disown the opener from rfh2. 1464 // Disown the opener from rfh2.
1450 rfh2->DidDisownOpener(); 1465 rfh2->DidDisownOpener();
1451 1466
1452 // Ensure the opener is cleared. 1467 // Ensure the opener is cleared.
1453 EXPECT_FALSE(contents()->HasOpener()); 1468 EXPECT_FALSE(contents()->HasOpener());
1454 1469
1455 // The back navigation commits. 1470 // The back navigation commits.
1456 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 1471 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1457 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 1472 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false,
1473 entry1->GetURL());
1458 1474
1459 // Ensure the opener is still cleared. 1475 // Ensure the opener is still cleared.
1460 EXPECT_FALSE(contents()->HasOpener()); 1476 EXPECT_FALSE(contents()->HasOpener());
1461 } 1477 }
1462 1478
1463 // Test that a page can disown the opener just after a cross-process navigation 1479 // Test that a page can disown the opener just after a cross-process navigation
1464 // commits. 1480 // commits.
1465 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { 1481 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) {
1466 const GURL kUrl1("http://www.google.com/"); 1482 const GURL kUrl1("http://www.google.com/");
1467 const GURL kUrl2("http://www.chromium.org/"); 1483 const GURL kUrl2("http://www.chromium.org/");
(...skipping 12 matching lines...) Expand all
1480 // BrowsingInstance). 1496 // BrowsingInstance).
1481 contents()->NavigateAndCommit(kUrl2); 1497 contents()->NavigateAndCommit(kUrl2);
1482 TestRenderFrameHost* rfh2 = main_test_rfh(); 1498 TestRenderFrameHost* rfh2 = main_test_rfh();
1483 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); 1499 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance());
1484 1500
1485 // Commit a back navigation before the DidDisownOpener message arrives. 1501 // Commit a back navigation before the DidDisownOpener message arrives.
1486 // rfh1 will be kept alive because of the opener tab. 1502 // rfh1 will be kept alive because of the opener tab.
1487 contents()->GetController().GoBack(); 1503 contents()->GetController().GoBack();
1488 contents()->GetMainFrame()->PrepareForCommit(); 1504 contents()->GetMainFrame()->PrepareForCommit();
1489 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 1505 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1490 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 1506 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false,
1507 entry1->GetURL());
1491 1508
1492 // Disown the opener from rfh2. 1509 // Disown the opener from rfh2.
1493 rfh2->DidDisownOpener(); 1510 rfh2->DidDisownOpener();
1494 EXPECT_FALSE(contents()->HasOpener()); 1511 EXPECT_FALSE(contents()->HasOpener());
1495 } 1512 }
1496 1513
1497 // Test that we clean up swapped out RenderViewHosts when a process hosting 1514 // Test that we clean up swapped out RenderViewHosts when a process hosting
1498 // those associated RenderViews crashes. http://crbug.com/258993 1515 // those associated RenderViews crashes. http://crbug.com/258993
1499 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { 1516 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) {
1500 const GURL kUrl1("http://www.google.com/"); 1517 const GURL kUrl1("http://www.google.com/");
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 1771
1755 // Navigate to the first page. 1772 // Navigate to the first page.
1756 contents()->NavigateAndCommit(kUrl1); 1773 contents()->NavigateAndCommit(kUrl1);
1757 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); 1774 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
1758 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); 1775 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1);
1759 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1776 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1760 1777
1761 // Navigate to new site, simulating onbeforeunload approval. 1778 // Navigate to new site, simulating onbeforeunload approval.
1762 controller().LoadURL( 1779 controller().LoadURL(
1763 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1780 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1781 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1764 contents()->GetMainFrame()->PrepareForCommit(); 1782 contents()->GetMainFrame()->PrepareForCommit();
1765 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1783 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1766 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1784 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1767 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1785 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1768 1786
1769 // Simulate the swap out ack, unexpectedly early (before commit). It should 1787 // Simulate the swap out ack, unexpectedly early (before commit). It should
1770 // have no effect. 1788 // have no effect.
1771 rfh1->OnSwappedOut(); 1789 rfh1->OnSwappedOut();
1772 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1790 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1773 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1791 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1774 1792
1775 // The new page commits. 1793 // The new page commits.
1776 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1794 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2,
1795 ui::PAGE_TRANSITION_TYPED);
1777 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1796 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1778 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1797 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1779 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1798 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1780 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1799 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1781 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1800 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1782 EXPECT_TRUE( 1801 EXPECT_TRUE(
1783 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); 1802 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1));
1784 1803
1785 // Simulate the swap out ack. 1804 // Simulate the swap out ack.
1786 rfh1->OnSwappedOut(); 1805 rfh1->OnSwappedOut();
(...skipping 15 matching lines...) Expand all
1802 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); 1821 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1);
1803 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1822 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1804 1823
1805 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is 1824 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is
1806 // not deleted on swap out. 1825 // not deleted on swap out.
1807 rfh1->GetSiteInstance()->increment_active_frame_count(); 1826 rfh1->GetSiteInstance()->increment_active_frame_count();
1808 1827
1809 // Navigate to new site, simulating onbeforeunload approval. 1828 // Navigate to new site, simulating onbeforeunload approval.
1810 controller().LoadURL( 1829 controller().LoadURL(
1811 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1830 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1831 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1812 contents()->GetMainFrame()->PrepareForCommit(); 1832 contents()->GetMainFrame()->PrepareForCommit();
1813 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1833 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1814 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1834 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1815 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1835 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1816 1836
1817 // The new page commits. 1837 // The new page commits.
1818 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1838 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2,
1839 ui::PAGE_TRANSITION_TYPED);
1819 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1840 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1820 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1841 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1821 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1842 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1822 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1843 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1823 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1844 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1824 1845
1825 // Simulate the swap out ack. 1846 // Simulate the swap out ack.
1826 rfh1->OnSwappedOut(); 1847 rfh1->OnSwappedOut();
1827 1848
1828 // rfh1 should be swapped out. 1849 // rfh1 should be swapped out.
(...skipping 16 matching lines...) Expand all
1845 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); 1866 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1);
1846 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1867 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1847 1868
1848 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is 1869 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is
1849 // not deleted on swap out. 1870 // not deleted on swap out.
1850 rfh1->GetSiteInstance()->increment_active_frame_count(); 1871 rfh1->GetSiteInstance()->increment_active_frame_count();
1851 1872
1852 // Navigate to new site, simulating onbeforeunload approval. 1873 // Navigate to new site, simulating onbeforeunload approval.
1853 controller().LoadURL( 1874 controller().LoadURL(
1854 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1875 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1876 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1855 rfh1->PrepareForCommit(); 1877 rfh1->PrepareForCommit();
1856 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1878 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1857 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1879 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1858 1880
1859 // The new page commits. 1881 // The new page commits.
1860 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1882 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2,
1883 ui::PAGE_TRANSITION_TYPED);
1861 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1884 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1862 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1885 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1863 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1886 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1864 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1887 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1865 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1888 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1866 1889
1867 // Simulate the swap out ack. 1890 // Simulate the swap out ack.
1868 rfh1->OnSwappedOut(); 1891 rfh1->OnSwappedOut();
1869 1892
1870 // rfh1 should be swapped out. 1893 // rfh1 should be swapped out.
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); 2126 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
2104 contents2->NavigateAndCommit(kUrl3); 2127 contents2->NavigateAndCommit(kUrl3);
2105 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); 2128 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive());
2106 EXPECT_NE(nullptr, 2129 EXPECT_NE(nullptr,
2107 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); 2130 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance()));
2108 EXPECT_EQ(nullptr, 2131 EXPECT_EQ(nullptr,
2109 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); 2132 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance()));
2110 } 2133 }
2111 2134
2112 } // namespace content 2135 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigator_impl_unittest.cc ('k') | content/browser/renderer_host/render_view_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698