Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 virtual void TearDown() OVERRIDE { | 262 virtual void TearDown() OVERRIDE { |
| 263 lifetime_checker_.reset(); | 263 lifetime_checker_.reset(); |
| 264 RenderViewHostImplTestHarness::TearDown(); | 264 RenderViewHostImplTestHarness::TearDown(); |
| 265 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); | 265 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void set_should_create_webui(bool should_create_webui) { | 268 void set_should_create_webui(bool should_create_webui) { |
| 269 factory_.set_should_create_webui(should_create_webui); | 269 factory_.set_should_create_webui(should_create_webui); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void StartCrossSiteTransition(TestWebContents* contents) { | |
| 273 std::vector<GURL> url_chain; | |
| 274 contents->GetRenderManagerForTesting()->OnCrossSiteResponse( | |
| 275 contents->GetRenderManagerForTesting()->pending_frame_host(), | |
| 276 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), | |
| 277 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); | |
| 278 EXPECT_TRUE(contents->cross_navigation_pending()); | |
| 279 RenderViewHostImpl* rvh = contents->GetRenderViewHost(); | |
| 280 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_UNLOAD_ACK, | |
| 281 rvh->rvh_state()); | |
| 282 } | |
| 283 | |
| 284 void NavigateActiveAndCommit(const GURL& url) { | 272 void NavigateActiveAndCommit(const GURL& url) { |
| 285 // Note: we navigate the active RenderViewHost because previous navigations | 273 // Note: we navigate the active RenderFrameHost because previous navigations |
| 286 // won't have committed yet, so NavigateAndCommit does the wrong thing | 274 // won't have committed yet, so NavigateAndCommit does the wrong thing |
| 287 // for us. | 275 // for us. |
| 288 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 276 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
| 289 TestRenderViewHost* old_rvh = test_rvh(); | 277 TestRenderViewHost* old_rvh = test_rvh(); |
| 290 | 278 |
| 291 // Simulate the BeforeUnload_ACK that is received from the current renderer | 279 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 292 // for a cross-site navigation. | 280 // for a cross-site navigation. |
| 293 if (old_rvh != active_rvh()) { | 281 if (old_rvh != active_rvh()) { |
| 294 old_rvh->SendBeforeUnloadACK(true); | 282 old_rvh->SendBeforeUnloadACK(true); |
| 295 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, old_rvh->rvh_state()); | 283 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, old_rvh->rvh_state()); |
| 296 } | 284 } |
| 297 | 285 |
| 298 // Commit the navigation with a new page ID. | 286 // Commit the navigation with a new page ID. |
| 299 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 287 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
| 300 active_rvh()->GetSiteInstance()); | 288 active_rvh()->GetSiteInstance()); |
| 301 | 289 |
| 302 // Simulate the response coming from the pending renderer. | |
| 303 if (old_rvh != active_rvh()) | |
| 304 StartCrossSiteTransition(contents()); | |
| 305 | |
| 306 // Simulate the SwapOut_ACK that fires if you commit a cross-site | |
| 307 // navigation. | |
| 308 if (old_rvh != active_rvh()) { | |
| 309 old_rvh->OnSwappedOut(false); | |
| 310 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_COMMIT, | |
| 311 old_rvh->rvh_state()); | |
| 312 } | |
| 313 | |
| 314 // Use an observer to avoid accessing a deleted renderer later on when the | 290 // Use an observer to avoid accessing a deleted renderer later on when the |
| 315 // state is being checked. | 291 // state is being checked. |
| 316 RenderViewHostDeletedObserver rvh_observer(old_rvh); | 292 RenderViewHostDeletedObserver rvh_observer(old_rvh); |
| 317 active_test_rvh()->SendNavigate(max_page_id + 1, url); | 293 active_test_rvh()->SendNavigate(max_page_id + 1, url); |
| 318 | 294 |
| 319 if (old_rvh != active_rvh() && !rvh_observer.deleted()) | 295 // Make sure that we start to run the unload handler at the time of commit. |
| 320 EXPECT_TRUE(old_rvh->IsSwappedOut()); | 296 bool expecting_rvh_shutdown = false; |
| 297 if (old_rvh != active_rvh() && !rvh_observer.deleted()) { | |
| 298 if (!static_cast<SiteInstanceImpl*>( | |
| 299 old_rvh->GetSiteInstance())->active_view_count()) { | |
| 300 expecting_rvh_shutdown = true; | |
| 301 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, | |
| 302 old_rvh->rvh_state()); | |
| 303 } else { | |
| 304 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, | |
| 305 old_rvh->rvh_state()); | |
| 306 } | |
| 307 } | |
| 308 | |
| 309 // Simulate the swap out ACK coming from the pending renderer. This should | |
| 310 // either shut down the old RVH or leave it in a swapped out state. | |
| 311 if (old_rvh != active_rvh()) { | |
| 312 old_rvh->OnSwappedOut(false); | |
| 313 if (expecting_rvh_shutdown) { | |
| 314 EXPECT_TRUE(rvh_observer.deleted()); | |
| 315 } else { | |
| 316 EXPECT_EQ(RenderViewHostImpl::STATE_SWAPPED_OUT, | |
| 317 old_rvh->rvh_state()); | |
| 318 } | |
| 319 } | |
| 321 } | 320 } |
| 322 | 321 |
| 323 bool ShouldSwapProcesses(RenderFrameHostManager* manager, | 322 bool ShouldSwapProcesses(RenderFrameHostManager* manager, |
| 324 const NavigationEntryImpl* current_entry, | 323 const NavigationEntryImpl* current_entry, |
| 325 const NavigationEntryImpl* new_entry) const { | 324 const NavigationEntryImpl* new_entry) const { |
| 326 CHECK(new_entry); | 325 CHECK(new_entry); |
| 327 BrowserContext* browser_context = | 326 BrowserContext* browser_context = |
| 328 manager->delegate_->GetControllerForRenderManager().GetBrowserContext(); | 327 manager->delegate_->GetControllerForRenderManager().GetBrowserContext(); |
| 329 const GURL& current_effective_url = current_entry ? | 328 const GURL& current_effective_url = current_entry ? |
| 330 SiteInstanceImpl::GetEffectiveURL(browser_context, | 329 SiteInstanceImpl::GetEffectiveURL(browser_context, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 | 415 |
| 417 // The second one is the opposite, creating a cross-site transition and | 416 // The second one is the opposite, creating a cross-site transition and |
| 418 // requiring a beforeunload ack. | 417 // requiring a beforeunload ack. |
| 419 contents2->GetController().LoadURL( | 418 contents2->GetController().LoadURL( |
| 420 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 419 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
| 421 EXPECT_TRUE(contents2->cross_navigation_pending()); | 420 EXPECT_TRUE(contents2->cross_navigation_pending()); |
| 422 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 421 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
| 423 ASSERT_TRUE(dest_rfh2); | 422 ASSERT_TRUE(dest_rfh2); |
| 424 | 423 |
| 425 ntp_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); | 424 ntp_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); |
| 426 StartCrossSiteTransition(contents2.get()); | |
| 427 dest_rfh2->SendNavigate(101, kDestUrl); | 425 dest_rfh2->SendNavigate(101, kDestUrl); |
| 428 | 426 |
| 429 // The two RFH's should be different in every way. | 427 // The two RFH's should be different in every way. |
| 430 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 428 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
| 431 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 429 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
| 432 dest_rfh2->GetSiteInstance()); | 430 dest_rfh2->GetSiteInstance()); |
| 433 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 431 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
| 434 contents()->GetMainFrame()->GetSiteInstance())); | 432 contents()->GetMainFrame()->GetSiteInstance())); |
| 435 | 433 |
| 436 // Navigate both to the new tab page, and verify that they share a | 434 // Navigate both to the new tab page, and verify that they share a |
| 437 // RenderProcessHost (not a SiteInstance). | 435 // RenderProcessHost (not a SiteInstance). |
| 438 NavigateActiveAndCommit(kChromeUrl); | 436 NavigateActiveAndCommit(kChromeUrl); |
| 439 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 437 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
| 440 | 438 |
| 441 contents2->GetController().LoadURL( | 439 contents2->GetController().LoadURL( |
| 442 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 440 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
| 443 dest_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); | 441 dest_rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); |
| 444 StartCrossSiteTransition(contents2.get()); | |
| 445 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); | 442 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); |
| 446 | 443 |
| 447 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 444 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
| 448 contents2->GetMainFrame()->GetSiteInstance()); | 445 contents2->GetMainFrame()->GetSiteInstance()); |
| 449 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), | 446 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), |
| 450 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); | 447 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); |
| 451 } | 448 } |
| 452 | 449 |
| 453 // Ensure that the browser ignores most IPC messages that arrive from a | 450 // Ensure that the browser ignores most IPC messages that arrive from a |
| 454 // RenderViewHost that has been swapped out. We do not want to take | 451 // RenderViewHost that has been swapped out. We do not want to take |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | 867 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> |
| 871 HasSite()); | 868 HasSite()); |
| 872 // Check the pending RenderFrameHost has been committed. | 869 // Check the pending RenderFrameHost has been committed. |
| 873 EXPECT_FALSE(manager->pending_frame_host()); | 870 EXPECT_FALSE(manager->pending_frame_host()); |
| 874 | 871 |
| 875 // We should observe a notification. | 872 // We should observe a notification. |
| 876 EXPECT_TRUE( | 873 EXPECT_TRUE( |
| 877 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 874 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 878 } | 875 } |
| 879 | 876 |
| 880 // Tests the Navigate function. In this unit test we verify that the Navigate | |
| 881 // function can handle a new navigation event before the previous navigation | |
| 882 // has been committed. This is also a regression test for | |
| 883 // http://crbug.com/104600. | |
| 884 TEST_F(RenderFrameHostManagerTest, NavigateWithEarlyReNavigation) { | |
|
nasko
2014/08/19 16:45:22
Just to make sure I understand it right, we don't
Charlie Reis
2014/08/19 21:20:31
Correct. This was exercising a bug that happened
| |
| 885 TestNotificationTracker notifications; | |
| 886 | |
| 887 SiteInstance* instance = SiteInstance::Create(browser_context()); | |
| 888 | |
| 889 scoped_ptr<TestWebContents> web_contents( | |
| 890 TestWebContents::Create(browser_context(), instance)); | |
| 891 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | |
| 892 Source<WebContents>(web_contents.get())); | |
| 893 | |
| 894 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | |
| 895 | |
| 896 // 1) The first navigation. -------------------------- | |
| 897 const GURL kUrl1("http://www.google.com/"); | |
| 898 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | |
| 899 Referrer(), base::string16() /* title */, | |
| 900 PAGE_TRANSITION_TYPED, | |
| 901 false /* is_renderer_init */); | |
| 902 RenderFrameHostImpl* host = manager->Navigate(entry1); | |
| 903 | |
| 904 // The RenderFrameHost created in Init will be reused. | |
| 905 EXPECT_TRUE(host == manager->current_frame_host()); | |
| 906 EXPECT_FALSE(manager->pending_frame_host()); | |
| 907 | |
| 908 // We should observe a notification. | |
| 909 EXPECT_TRUE( | |
| 910 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | |
| 911 notifications.Reset(); | |
| 912 | |
| 913 // Commit. | |
| 914 manager->DidNavigateFrame(host); | |
| 915 | |
| 916 // Commit to SiteInstance should be delayed until RenderView commit. | |
| 917 EXPECT_TRUE(host == manager->current_frame_host()); | |
| 918 ASSERT_TRUE(host); | |
| 919 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> | |
| 920 HasSite()); | |
| 921 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); | |
| 922 | |
| 923 // 2) Cross-site navigate to next site. ------------------------- | |
| 924 const GURL kUrl2("http://www.example.com"); | |
| 925 NavigationEntryImpl entry2( | |
| 926 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), | |
| 927 base::string16() /* title */, PAGE_TRANSITION_TYPED, | |
| 928 false /* is_renderer_init */); | |
| 929 RenderFrameHostImpl* host2 = manager->Navigate(entry2); | |
| 930 int host2_process_id = host2->GetProcess()->GetID(); | |
| 931 | |
| 932 // A new RenderFrameHost should be created. | |
| 933 EXPECT_TRUE(manager->pending_frame_host()); | |
| 934 ASSERT_EQ(host2, manager->pending_frame_host()); | |
| 935 EXPECT_NE(host2, host); | |
| 936 | |
| 937 // Check that the navigation is still suspended because the old RVH | |
| 938 // is not swapped out, yet. | |
| 939 EXPECT_TRUE(host2->are_navigations_suspended()); | |
| 940 MockRenderProcessHost* test_process_host2 = | |
| 941 static_cast<MockRenderProcessHost*>(host2->GetProcess()); | |
| 942 test_process_host2->sink().ClearMessages(); | |
| 943 host2->render_view_host()->NavigateToURL(kUrl2); | |
| 944 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( | |
| 945 FrameMsg_Navigate::ID)); | |
| 946 | |
| 947 // Allow closing the current Render View (precondition for swapping out | |
| 948 // the RVH): Simulate response from RenderFrame for FrameMsg_BeforeUnload sent | |
| 949 // by DispatchBeforeUnload. | |
| 950 TestRenderViewHost* test_host = | |
| 951 static_cast<TestRenderViewHost*>(host->render_view_host()); | |
| 952 MockRenderProcessHost* test_process_host = | |
| 953 static_cast<MockRenderProcessHost*>(test_host->GetProcess()); | |
| 954 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( | |
| 955 FrameMsg_BeforeUnload::ID)); | |
| 956 test_host->SendBeforeUnloadACK(true); | |
| 957 | |
| 958 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a | |
| 959 // call of RenderFrameHostManager::SwapOutOldPage before | |
| 960 // RenderFrameHostManager::DidNavigateFrame is called. | |
| 961 // The RVH is swapped out after receiving the unload ack. | |
| 962 manager->SwapOutOldPage(); | |
| 963 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( | |
| 964 FrameMsg_SwapOut::ID)); | |
| 965 test_host->OnSwappedOut(false); | |
| 966 | |
| 967 EXPECT_EQ(host, manager->current_frame_host()); | |
| 968 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); | |
| 969 EXPECT_EQ(host2, manager->pending_frame_host()); | |
| 970 // There should be still no navigation messages being sent. | |
| 971 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( | |
| 972 FrameMsg_Navigate::ID)); | |
| 973 | |
| 974 // 3) Cross-site navigate to next site before 2) has committed. -------------- | |
| 975 const GURL kUrl3("http://webkit.org/"); | |
| 976 NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3, | |
| 977 Referrer(), base::string16() /* title */, | |
| 978 PAGE_TRANSITION_TYPED, | |
| 979 false /* is_renderer_init */); | |
| 980 test_process_host->sink().ClearMessages(); | |
| 981 RenderFrameHostImpl* host3 = manager->Navigate(entry3); | |
| 982 | |
| 983 // A new RenderFrameHost should be created. host2 is now deleted. | |
| 984 EXPECT_TRUE(manager->pending_frame_host()); | |
| 985 ASSERT_EQ(host3, manager->pending_frame_host()); | |
| 986 EXPECT_NE(host3, host); | |
| 987 EXPECT_NE(host3->GetProcess()->GetID(), host2_process_id); | |
| 988 | |
| 989 // Navigations in the new RFH should be suspended. | |
| 990 EXPECT_TRUE(host3->are_navigations_suspended()); | |
| 991 EXPECT_EQ(host, manager->current_frame_host()); | |
| 992 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); | |
| 993 | |
| 994 // Simulate a response to the second beforeunload request. | |
| 995 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( | |
| 996 FrameMsg_BeforeUnload::ID)); | |
| 997 test_host->SendBeforeUnloadACK(true); | |
| 998 | |
| 999 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a | |
| 1000 // call of RenderFrameHostManager::SwapOutOldPage before | |
| 1001 // RenderFrameHostManager::DidNavigateFrame is called. Since the previous | |
| 1002 // navigation has already caused the renderer to start swapping out, there | |
| 1003 // will be no more SwapOut messages being sent. | |
| 1004 manager->SwapOutOldPage(); | |
| 1005 EXPECT_FALSE(test_process_host->sink().GetUniqueMessageMatching( | |
| 1006 FrameMsg_SwapOut::ID)); | |
| 1007 test_host->OnSwappedOut(false); | |
| 1008 | |
| 1009 // Commit. | |
| 1010 manager->DidNavigateFrame(host3); | |
| 1011 EXPECT_TRUE(host3 == manager->current_frame_host()); | |
| 1012 ASSERT_TRUE(host3); | |
| 1013 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> | |
| 1014 HasSite()); | |
| 1015 // Check the pending RenderFrameHost has been committed. | |
| 1016 EXPECT_FALSE(manager->pending_frame_host()); | |
| 1017 | |
| 1018 // We should observe a notification. | |
| 1019 EXPECT_TRUE( | |
| 1020 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | |
| 1021 } | |
| 1022 | |
| 1023 // Test that navigation is not blocked when we make new navigation before | |
| 1024 // previous one has been committed. This is also a regression test for | |
| 1025 // http://crbug.com/104600. | |
| 1026 TEST_F(RenderFrameHostManagerTest, NewCrossNavigationBetweenSwapOutAndCommit) { | |
| 1027 const GURL kUrl1("http://www.google.com/"); | |
| 1028 const GURL kUrl2("http://www.chromium.org/"); | |
| 1029 const GURL kUrl3("http://www.youtube.com/"); | |
| 1030 | |
| 1031 contents()->NavigateAndCommit(kUrl1); | |
| 1032 TestRenderViewHost* rvh1 = test_rvh(); | |
| 1033 | |
| 1034 // Keep active_view_count nonzero so that no swapped out views in | |
| 1035 // this SiteInstance get forcefully deleted. | |
| 1036 static_cast<SiteInstanceImpl*>(rvh1->GetSiteInstance())-> | |
| 1037 increment_active_view_count(); | |
| 1038 | |
| 1039 // Navigate but don't commit. | |
| 1040 contents()->GetController().LoadURL( | |
| 1041 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
| 1042 EXPECT_TRUE(rvh1->is_waiting_for_beforeunload_ack()); | |
| 1043 contents()->ProceedWithCrossSiteNavigation(); | |
| 1044 EXPECT_FALSE(rvh1->is_waiting_for_beforeunload_ack()); | |
| 1045 StartCrossSiteTransition(contents()); | |
| 1046 EXPECT_TRUE(rvh1->IsWaitingForUnloadACK()); | |
| 1047 | |
| 1048 rvh1->OnSwappedOut(false); | |
| 1049 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_COMMIT, rvh1->rvh_state()); | |
| 1050 | |
| 1051 TestRenderViewHost* rvh2 = pending_test_rvh(); | |
| 1052 EXPECT_TRUE(rvh2); | |
| 1053 static_cast<SiteInstanceImpl*>(rvh2->GetSiteInstance())-> | |
| 1054 increment_active_view_count(); | |
| 1055 | |
| 1056 contents()->GetController().LoadURL( | |
| 1057 kUrl3, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
| 1058 // Pending rvh2 is already deleted. | |
| 1059 contents()->ProceedWithCrossSiteNavigation(); | |
| 1060 | |
| 1061 TestRenderFrameHost* rfh3 = contents()->GetPendingMainFrame(); | |
| 1062 EXPECT_TRUE(rfh3); | |
| 1063 // Navigation should be already unblocked by rvh1. | |
| 1064 EXPECT_FALSE(rfh3->are_navigations_suspended()); | |
| 1065 } | |
| 1066 | |
| 1067 // Tests WebUI creation. | 877 // Tests WebUI creation. |
| 1068 TEST_F(RenderFrameHostManagerTest, WebUI) { | 878 TEST_F(RenderFrameHostManagerTest, WebUI) { |
| 1069 set_should_create_webui(true); | 879 set_should_create_webui(true); |
| 1070 SiteInstance* instance = SiteInstance::Create(browser_context()); | 880 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 1071 | 881 |
| 1072 scoped_ptr<TestWebContents> web_contents( | 882 scoped_ptr<TestWebContents> web_contents( |
| 1073 TestWebContents::Create(browser_context(), instance)); | 883 TestWebContents::Create(browser_context(), instance)); |
| 1074 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 884 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1075 | 885 |
| 1076 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); | 886 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1246 static_cast<SiteInstanceImpl*>(rvh2->GetSiteInstance())-> | 1056 static_cast<SiteInstanceImpl*>(rvh2->GetSiteInstance())-> |
| 1247 increment_active_view_count(); | 1057 increment_active_view_count(); |
| 1248 | 1058 |
| 1249 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 1059 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
| 1250 // happen, but we have seen it when going back quickly across many entries | 1060 // happen, but we have seen it when going back quickly across many entries |
| 1251 // (http://crbug.com/93427). | 1061 // (http://crbug.com/93427). |
| 1252 contents()->GetController().GoBack(); | 1062 contents()->GetController().GoBack(); |
| 1253 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack()); | 1063 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack()); |
| 1254 contents()->ProceedWithCrossSiteNavigation(); | 1064 contents()->ProceedWithCrossSiteNavigation(); |
| 1255 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack()); | 1065 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack()); |
| 1256 StartCrossSiteTransition(contents()); | |
| 1257 EXPECT_TRUE(rvh2->IsWaitingForUnloadACK()); | |
| 1258 | 1066 |
| 1259 // The back navigation commits. | 1067 // The back navigation commits. |
| 1260 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1068 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
| 1261 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1069 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
| 1070 EXPECT_TRUE(rvh2->IsWaitingForUnloadACK()); | |
| 1262 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh2->rvh_state()); | 1071 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh2->rvh_state()); |
| 1263 | 1072 |
| 1264 // We should be able to navigate forward. | 1073 // We should be able to navigate forward. |
| 1265 contents()->GetController().GoForward(); | 1074 contents()->GetController().GoForward(); |
| 1266 contents()->ProceedWithCrossSiteNavigation(); | 1075 contents()->ProceedWithCrossSiteNavigation(); |
| 1267 StartCrossSiteTransition(contents()); | |
| 1268 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1076 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
| 1269 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 1077 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
| 1270 EXPECT_EQ(rvh2, rvh()); | 1078 EXPECT_EQ(rvh2, rvh()); |
| 1271 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh2->rvh_state()); | 1079 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh2->rvh_state()); |
| 1272 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh1->rvh_state()); | 1080 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh1->rvh_state()); |
| 1273 rvh1->OnSwappedOut(false); | 1081 rvh1->OnSwappedOut(false); |
| 1274 EXPECT_TRUE(rvh1->IsSwappedOut()); | 1082 EXPECT_TRUE(rvh1->IsSwappedOut()); |
| 1083 EXPECT_EQ(RenderViewHostImpl::STATE_SWAPPED_OUT, rvh1->rvh_state()); | |
| 1275 } | 1084 } |
| 1276 | 1085 |
| 1277 // Test that we create swapped out RVHs for the opener chain when navigating an | 1086 // Test that we create swapped out RVHs for the opener chain when navigating an |
| 1278 // opened tab cross-process. This allows us to support certain cross-process | 1087 // opened tab cross-process. This allows us to support certain cross-process |
| 1279 // JavaScript calls (http://crbug.com/99202). | 1088 // JavaScript calls (http://crbug.com/99202). |
| 1280 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRVHs) { | 1089 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRVHs) { |
| 1281 const GURL kUrl1("http://www.google.com/"); | 1090 const GURL kUrl1("http://www.google.com/"); |
| 1282 const GURL kUrl2("http://www.chromium.org/"); | 1091 const GURL kUrl2("http://www.chromium.org/"); |
| 1283 const GURL kChromeUrl("chrome://foo"); | 1092 const GURL kChromeUrl("chrome://foo"); |
| 1284 | 1093 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1552 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1361 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1553 Source<RenderWidgetHost>(host2->render_view_host())); | 1362 Source<RenderWidgetHost>(host2->render_view_host())); |
| 1554 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); | 1363 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); |
| 1555 | 1364 |
| 1556 EXPECT_TRUE( | 1365 EXPECT_TRUE( |
| 1557 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); | 1366 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); |
| 1558 EXPECT_FALSE(manager->pending_frame_host()); | 1367 EXPECT_FALSE(manager->pending_frame_host()); |
| 1559 EXPECT_EQ(host, manager->current_frame_host()); | 1368 EXPECT_EQ(host, manager->current_frame_host()); |
| 1560 } | 1369 } |
| 1561 | 1370 |
| 1562 // Tests that the RenderViewHost is properly deleted when the SwapOutACK is | 1371 // Tests that the RenderFrameHost is properly deleted when the swap out ack is |
| 1563 // received before the new page commits. | 1372 // received (after commit). |
|
nasko
2014/08/19 16:45:23
nit: I read "(after commit)" as a test case variat
Charlie Reis
2014/08/19 21:20:31
Done.
| |
| 1564 TEST_F(RenderFrameHostManagerTest, | 1373 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
| 1565 SwapOutACKBeforeNewPageCommitsLeadsToDeletion) { | |
| 1566 const GURL kUrl1("http://www.google.com/"); | 1374 const GURL kUrl1("http://www.google.com/"); |
| 1567 const GURL kUrl2("http://www.chromium.org/"); | 1375 const GURL kUrl2("http://www.chromium.org/"); |
| 1568 | 1376 |
| 1569 // Navigate to the first page. | |
| 1570 contents()->NavigateAndCommit(kUrl1); | |
| 1571 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | |
| 1572 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | |
| 1573 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | |
| 1574 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1575 | |
| 1576 // Navigate to new site, simulating onbeforeunload approval. | |
| 1577 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
| 1578 base::TimeTicks now = base::TimeTicks::Now(); | |
| 1579 rfh1->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
| 1580 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
| 1581 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | |
| 1582 | |
| 1583 // Simulate rfh2's response, which leads to an unload request being sent to | |
| 1584 // rfh1. | |
| 1585 std::vector<GURL> url_chain; | |
| 1586 url_chain.push_back(GURL()); | |
| 1587 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse( | |
| 1588 rfh2, | |
| 1589 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), | |
| 1590 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); | |
| 1591 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
| 1592 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_UNLOAD_ACK, | |
| 1593 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1594 | |
| 1595 // Simulate the swap out ack. | |
| 1596 rfh1->OnSwappedOut(false); | |
| 1597 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_COMMIT, | |
| 1598 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1599 | |
| 1600 // The new page commits. | |
| 1601 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); | |
| 1602 EXPECT_FALSE(contents()->cross_navigation_pending()); | |
| 1603 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | |
| 1604 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | |
| 1605 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | |
| 1606 rfh2->GetRenderViewHost()->rvh_state()); | |
| 1607 | |
| 1608 // rfh1's rvh should have been deleted. | |
| 1609 EXPECT_TRUE(rvh_deleted_observer.deleted()); | |
| 1610 rfh1 = NULL; | |
| 1611 } | |
| 1612 | |
| 1613 // Tests that the RenderViewHost is properly swapped out when the SwapOutACK is | |
| 1614 // received before the new page commits. | |
| 1615 TEST_F(RenderFrameHostManagerTest, | |
| 1616 SwapOutACKBeforeNewPageCommitsLeadsToSwapOut) { | |
| 1617 const GURL kUrl1("http://www.google.com/"); | |
| 1618 const GURL kUrl2("http://www.chromium.org/"); | |
| 1619 | |
| 1620 // Navigate to the first page. | |
| 1621 contents()->NavigateAndCommit(kUrl1); | |
| 1622 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | |
| 1623 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | |
| 1624 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | |
| 1625 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1626 | |
| 1627 // Increment the number of active views in SiteInstanceImpl so that rfh2 is | |
| 1628 // not deleted on swap out. | |
| 1629 static_cast<SiteInstanceImpl*>( | |
| 1630 rfh1->GetSiteInstance())->increment_active_view_count(); | |
| 1631 | |
| 1632 // Navigate to new site, simulating onbeforeunload approval. | |
| 1633 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
| 1634 base::TimeTicks now = base::TimeTicks::Now(); | |
| 1635 contents()->GetMainFrame()->OnMessageReceived( | |
| 1636 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
| 1637 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
| 1638 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | |
| 1639 | |
| 1640 // Simulate rfh2's response, which leads to an unload request being sent to | |
| 1641 // rfh1. | |
| 1642 std::vector<GURL> url_chain; | |
| 1643 url_chain.push_back(GURL()); | |
| 1644 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse( | |
| 1645 rfh2, | |
| 1646 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), | |
| 1647 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); | |
| 1648 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
| 1649 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_UNLOAD_ACK, | |
| 1650 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1651 | |
| 1652 // Simulate the swap out ack. | |
| 1653 rfh1->OnSwappedOut(false); | |
| 1654 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_COMMIT, | |
| 1655 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1656 | |
| 1657 // The new page commits. | |
| 1658 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); | |
| 1659 EXPECT_FALSE(contents()->cross_navigation_pending()); | |
| 1660 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | |
| 1661 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | |
| 1662 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | |
| 1663 rfh2->GetRenderViewHost()->rvh_state()); | |
| 1664 | |
| 1665 // rfh1 should be swapped out. | |
| 1666 EXPECT_FALSE(rvh_deleted_observer.deleted()); | |
| 1667 EXPECT_TRUE(rfh1->GetRenderViewHost()->IsSwappedOut()); | |
| 1668 } | |
| 1669 | |
| 1670 // Tests that the RenderViewHost is properly deleted when the new | |
| 1671 // page commits before the swap out ack is received. | |
| 1672 TEST_F(RenderFrameHostManagerTest, | |
| 1673 NewPageCommitsBeforeSwapOutACKLeadsToDeletion) { | |
| 1674 const GURL kUrl1("http://www.google.com/"); | |
| 1675 const GURL kUrl2("http://www.chromium.org/"); | |
| 1676 | |
| 1677 // Navigate to the first page. | 1377 // Navigate to the first page. |
| 1678 contents()->NavigateAndCommit(kUrl1); | 1378 contents()->NavigateAndCommit(kUrl1); |
| 1679 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1379 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1680 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1380 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); |
| 1681 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1381 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
| 1682 rfh1->GetRenderViewHost()->rvh_state()); | 1382 rfh1->GetRenderViewHost()->rvh_state()); |
| 1683 | 1383 |
| 1684 // Navigate to new site, simulating onbeforeunload approval. | 1384 // Navigate to new site, simulating onbeforeunload approval. |
| 1685 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1385 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
| 1686 base::TimeTicks now = base::TimeTicks::Now(); | 1386 base::TimeTicks now = base::TimeTicks::Now(); |
| 1687 contents()->GetMainFrame()->OnMessageReceived( | 1387 contents()->GetMainFrame()->OnMessageReceived( |
| 1688 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1388 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
| 1689 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1389 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 1690 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1390 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1691 | 1391 |
| 1692 // Simulate rfh2's response, which leads to an unload request being sent to | |
| 1693 // rfh1. | |
| 1694 std::vector<GURL> url_chain; | |
| 1695 url_chain.push_back(GURL()); | |
| 1696 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse( | |
| 1697 rfh2, | |
| 1698 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), | |
| 1699 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); | |
| 1700 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
| 1701 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_UNLOAD_ACK, | |
|
nasko
2014/08/19 16:45:22
I'd keep the state expectation, just change the va
Charlie Reis
2014/08/19 21:20:31
Done.
| |
| 1702 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1703 | |
| 1704 // The new page commits. | 1392 // The new page commits. |
| 1705 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); | 1393 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); |
| 1706 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1394 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 1707 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1395 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1708 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1396 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1709 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1397 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
| 1710 rfh2->GetRenderViewHost()->rvh_state()); | 1398 rfh2->GetRenderViewHost()->rvh_state()); |
| 1711 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, | 1399 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, |
| 1712 rfh1->GetRenderViewHost()->rvh_state()); | 1400 rfh1->GetRenderViewHost()->rvh_state()); |
| 1713 | 1401 |
| 1714 // Simulate the swap out ack. | 1402 // Simulate the swap out ack. |
| 1715 rfh1->OnSwappedOut(false); | 1403 rfh1->OnSwappedOut(false); |
| 1716 | 1404 |
| 1717 // rfh1 should have been deleted. | 1405 // rfh1 should have been deleted. |
| 1718 EXPECT_TRUE(rvh_deleted_observer.deleted()); | 1406 EXPECT_TRUE(rvh_deleted_observer.deleted()); |
| 1719 rfh1 = NULL; | 1407 rfh1 = NULL; |
| 1720 } | 1408 } |
| 1721 | 1409 |
| 1722 // Tests that the RenderViewHost is properly swapped out when the new page | 1410 // Tests that the RenderFrameHost is properly swapped out when the swap out ack |
| 1723 // commits before the swap out ack is received. | 1411 // is received (after commit). |
| 1724 TEST_F(RenderFrameHostManagerTest, | 1412 TEST_F(RenderFrameHostManagerTest, SwapOutFrameAfterSwapOutACK) { |
| 1725 NewPageCommitsBeforeSwapOutACKLeadsToSwapOut) { | |
| 1726 const GURL kUrl1("http://www.google.com/"); | 1413 const GURL kUrl1("http://www.google.com/"); |
| 1727 const GURL kUrl2("http://www.chromium.org/"); | 1414 const GURL kUrl2("http://www.chromium.org/"); |
| 1728 | 1415 |
| 1729 // Navigate to the first page. | 1416 // Navigate to the first page. |
| 1730 contents()->NavigateAndCommit(kUrl1); | 1417 contents()->NavigateAndCommit(kUrl1); |
| 1731 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1418 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1732 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); | 1419 RenderViewHostDeletedObserver rvh_deleted_observer(rfh1->GetRenderViewHost()); |
| 1733 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1420 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
| 1734 rfh1->GetRenderViewHost()->rvh_state()); | 1421 rfh1->GetRenderViewHost()->rvh_state()); |
| 1735 | 1422 |
| 1736 // Increment the number of active views in SiteInstanceImpl so that rfh1 is | 1423 // Increment the number of active views in SiteInstanceImpl so that rfh1 is |
| 1737 // not deleted on swap out. | 1424 // not deleted on swap out. |
| 1738 static_cast<SiteInstanceImpl*>( | 1425 static_cast<SiteInstanceImpl*>( |
| 1739 rfh1->GetSiteInstance())->increment_active_view_count(); | 1426 rfh1->GetSiteInstance())->increment_active_view_count(); |
| 1740 | 1427 |
| 1741 // Navigate to new site, simulating onbeforeunload approval. | 1428 // Navigate to new site, simulating onbeforeunload approval. |
| 1742 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1429 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
| 1743 base::TimeTicks now = base::TimeTicks::Now(); | 1430 base::TimeTicks now = base::TimeTicks::Now(); |
| 1744 contents()->GetMainFrame()->OnMessageReceived( | 1431 contents()->GetMainFrame()->OnMessageReceived( |
| 1745 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1432 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
| 1746 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1433 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 1747 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1434 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1748 | 1435 |
| 1749 // Simulate rfh2's response, which leads to an unload request being sent to | |
| 1750 // rfh1. | |
| 1751 std::vector<GURL> url_chain; | |
| 1752 url_chain.push_back(GURL()); | |
| 1753 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse( | |
| 1754 rfh2, | |
| 1755 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), | |
| 1756 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); | |
| 1757 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
| 1758 EXPECT_EQ(RenderViewHostImpl::STATE_WAITING_FOR_UNLOAD_ACK, | |
| 1759 rfh1->GetRenderViewHost()->rvh_state()); | |
| 1760 | |
| 1761 // The new page commits. | 1436 // The new page commits. |
| 1762 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); | 1437 contents()->TestDidNavigate(rfh2, 1, kUrl2, PAGE_TRANSITION_TYPED); |
| 1763 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1438 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 1764 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1439 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1765 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1440 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1766 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1441 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
| 1767 rfh2->GetRenderViewHost()->rvh_state()); | 1442 rfh2->GetRenderViewHost()->rvh_state()); |
| 1768 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, | 1443 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, |
| 1769 rfh1->GetRenderViewHost()->rvh_state()); | 1444 rfh1->GetRenderViewHost()->rvh_state()); |
| 1770 | 1445 |
| 1771 // Simulate the swap out ack. | 1446 // Simulate the swap out ack. |
| 1772 rfh1->OnSwappedOut(false); | 1447 rfh1->OnSwappedOut(false); |
|
nasko
2014/08/19 16:45:22
nit: So what happens if we get a swap out ack befo
Charlie Reis
2014/08/19 21:20:31
Good idea. I added a test line to verify that we
| |
| 1773 | 1448 |
| 1774 // rfh1 should be swapped out. | 1449 // rfh1 should be swapped out. |
| 1775 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1450 EXPECT_FALSE(rvh_deleted_observer.deleted()); |
| 1776 EXPECT_TRUE(rfh1->GetRenderViewHost()->IsSwappedOut()); | 1451 EXPECT_TRUE(rfh1->GetRenderViewHost()->IsSwappedOut()); |
| 1777 } | 1452 } |
| 1778 | 1453 |
| 1779 // Test that the RenderViewHost is properly swapped out if a navigation in the | 1454 // Test that the RenderViewHost is properly swapped out if a navigation in the |
| 1780 // new renderer commits before sending the SwapOut message to the old renderer. | 1455 // new renderer commits before sending the SwapOut message to the old renderer. |
| 1781 // This simulates a cross-site navigation to a synchronously committing URL | 1456 // This simulates a cross-site navigation to a synchronously committing URL |
| 1782 // (e.g., a data URL) and ensures it works properly. | 1457 // (e.g., a data URL) and ensures it works properly. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1906 NavigationRequest* main_request = NavigationRequestForRenderFrameManager( | 1581 NavigationRequest* main_request = NavigationRequestForRenderFrameManager( |
| 1907 contents()->GetMainFrame()->frame_tree_node()->render_manager()); | 1582 contents()->GetMainFrame()->frame_tree_node()->render_manager()); |
| 1908 ASSERT_TRUE(main_request); | 1583 ASSERT_TRUE(main_request); |
| 1909 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url); | 1584 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url); |
| 1910 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies); | 1585 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies); |
| 1911 EXPECT_TRUE(main_request->info_for_testing().is_main_frame); | 1586 EXPECT_TRUE(main_request->info_for_testing().is_main_frame); |
| 1912 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame); | 1587 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame); |
| 1913 } | 1588 } |
| 1914 | 1589 |
| 1915 } // namespace content | 1590 } // namespace content |
| OLD | NEW |