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

Side by Side Diff: content/browser/web_contents/render_view_host_manager_unittest.cc

Issue 15682009: Eliminate SwapOut message parameters, keeping state in RVHM instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflicts Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "content/browser/browser_thread_impl.h" 6 #include "content/browser/browser_thread_impl.h"
7 #include "content/browser/renderer_host/test_render_view_host.h" 7 #include "content/browser/renderer_host/test_render_view_host.h"
8 #include "content/browser/site_instance_impl.h" 8 #include "content/browser/site_instance_impl.h"
9 #include "content/browser/web_contents/navigation_controller_impl.h" 9 #include "content/browser/web_contents/navigation_controller_impl.h"
10 #include "content/browser/web_contents/navigation_entry_impl.h" 10 #include "content/browser/web_contents/navigation_entry_impl.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 old_rvh->SendShouldCloseACK(true); 104 old_rvh->SendShouldCloseACK(true);
105 105
106 // Commit the navigation with a new page ID. 106 // Commit the navigation with a new page ID.
107 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( 107 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
108 active_rvh()->GetSiteInstance()); 108 active_rvh()->GetSiteInstance());
109 active_test_rvh()->SendNavigate(max_page_id + 1, url); 109 active_test_rvh()->SendNavigate(max_page_id + 1, url);
110 110
111 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation 111 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation
112 // without making any network requests. 112 // without making any network requests.
113 if (old_rvh != active_rvh()) 113 if (old_rvh != active_rvh())
114 old_rvh->OnSwapOutACK(false); 114 old_rvh->OnSwappedOut(false);
115 } 115 }
116 116
117 bool ShouldSwapProcesses(RenderViewHostManager* manager, 117 bool ShouldSwapProcesses(RenderViewHostManager* manager,
118 const NavigationEntryImpl* cur_entry, 118 const NavigationEntryImpl* cur_entry,
119 const NavigationEntryImpl* new_entry) const { 119 const NavigationEntryImpl* new_entry) const {
120 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); 120 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry);
121 } 121 }
122 122
123 private: 123 private:
124 RenderViewHostManagerTestWebUIControllerFactory factory_; 124 RenderViewHostManagerTestWebUIControllerFactory factory_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // The second one is the opposite, creating a cross-site transition and 157 // The second one is the opposite, creating a cross-site transition and
158 // requiring a beforeunload ack. 158 // requiring a beforeunload ack.
159 contents2->GetController().LoadURL( 159 contents2->GetController().LoadURL(
160 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); 160 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
161 EXPECT_TRUE(contents2->cross_navigation_pending()); 161 EXPECT_TRUE(contents2->cross_navigation_pending());
162 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( 162 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
163 contents2->GetRenderManagerForTesting()->pending_render_view_host()); 163 contents2->GetRenderManagerForTesting()->pending_render_view_host());
164 ASSERT_TRUE(dest_rvh2); 164 ASSERT_TRUE(dest_rvh2);
165 ntp_rvh2->SendShouldCloseACK(true); 165 ntp_rvh2->SendShouldCloseACK(true);
166 dest_rvh2->SendNavigate(101, kDestUrl); 166 dest_rvh2->SendNavigate(101, kDestUrl);
167 ntp_rvh2->OnSwapOutACK(false); 167 ntp_rvh2->OnSwappedOut(false);
168 168
169 // The two RVH's should be different in every way. 169 // The two RVH's should be different in every way.
170 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); 170 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess());
171 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); 171 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance());
172 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( 172 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance(
173 dest_rvh2->GetSiteInstance())); 173 dest_rvh2->GetSiteInstance()));
174 174
175 // Navigate both to the new tab page, and verify that they share a 175 // Navigate both to the new tab page, and verify that they share a
176 // RenderProcessHost (not a SiteInstance). 176 // RenderProcessHost (not a SiteInstance).
177 NavigateActiveAndCommit(kChromeUrl); 177 NavigateActiveAndCommit(kChromeUrl);
178 178
179 contents2->GetController().LoadURL( 179 contents2->GetController().LoadURL(
180 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); 180 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
181 dest_rvh2->SendShouldCloseACK(true); 181 dest_rvh2->SendShouldCloseACK(true);
182 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()-> 182 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()->
183 pending_render_view_host())->SendNavigate(102, kChromeUrl); 183 pending_render_view_host())->SendNavigate(102, kChromeUrl);
184 dest_rvh2->OnSwapOutACK(false); 184 dest_rvh2->OnSwappedOut(false);
185 185
186 EXPECT_NE(active_rvh()->GetSiteInstance(), 186 EXPECT_NE(active_rvh()->GetSiteInstance(),
187 contents2->GetRenderViewHost()->GetSiteInstance()); 187 contents2->GetRenderViewHost()->GetSiteInstance());
188 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), 188 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(),
189 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); 189 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess());
190 } 190 }
191 191
192 // Ensure that the browser ignores most IPC messages that arrive from a 192 // Ensure that the browser ignores most IPC messages that arrive from a
193 // RenderViewHost that has been swapped out. We do not want to take 193 // RenderViewHost that has been swapped out. We do not want to take
194 // action on requests from a non-active renderer. The main exception is 194 // action on requests from a non-active renderer. The main exception is
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by 510 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by
511 // FirePageBeforeUnload. 511 // FirePageBeforeUnload.
512 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host); 512 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host);
513 MockRenderProcessHost* test_process_host = 513 MockRenderProcessHost* test_process_host =
514 static_cast<MockRenderProcessHost*>(test_host->GetProcess()); 514 static_cast<MockRenderProcessHost*>(test_host->GetProcess());
515 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 515 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
516 ViewMsg_ShouldClose::ID)); 516 ViewMsg_ShouldClose::ID));
517 test_host->SendShouldCloseACK(true); 517 test_host->SendShouldCloseACK(true);
518 518
519 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 519 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
520 // call of RenderViewHostManager::OnCrossSiteResponse before 520 // call of RenderViewHostManager::SwapOutOldPage before
521 // RenderViewHostManager::DidNavigateMainFrame is called. 521 // RenderViewHostManager::DidNavigateMainFrame is called.
522 // The RVH is not swapped out until the commit. 522 // The RVH is not swapped out until the commit.
523 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(), 523 manager.SwapOutOldPage();
524 host2->GetPendingRequestId());
525 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 524 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
526 ViewMsg_SwapOut::ID)); 525 ViewMsg_SwapOut::ID));
527 test_host->OnSwapOutACK(false); 526 test_host->OnSwappedOut(false);
528 527
529 EXPECT_EQ(host, manager.current_host()); 528 EXPECT_EQ(host, manager.current_host());
530 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( 529 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
531 manager.current_host())->is_swapped_out()); 530 manager.current_host())->is_swapped_out());
532 EXPECT_EQ(host2, manager.pending_render_view_host()); 531 EXPECT_EQ(host2, manager.pending_render_view_host());
533 // There should be still no navigation messages being sent. 532 // There should be still no navigation messages being sent.
534 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 533 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
535 ViewMsg_Navigate::ID)); 534 ViewMsg_Navigate::ID));
536 535
537 // 3) Cross-site navigate to next site before 2) has committed. -------------- 536 // 3) Cross-site navigate to next site before 2) has committed. --------------
(...skipping 19 matching lines...) Expand all
557 EXPECT_EQ(host, manager.current_host()); 556 EXPECT_EQ(host, manager.current_host());
558 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( 557 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
559 manager.current_host())->is_swapped_out()); 558 manager.current_host())->is_swapped_out());
560 559
561 // Simulate a response to the second beforeunload request. 560 // Simulate a response to the second beforeunload request.
562 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 561 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
563 ViewMsg_ShouldClose::ID)); 562 ViewMsg_ShouldClose::ID));
564 test_host->SendShouldCloseACK(true); 563 test_host->SendShouldCloseACK(true);
565 564
566 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 565 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
567 // call of RenderViewHostManager::OnCrossSiteResponse before 566 // call of RenderViewHostManager::SwapOutOldPage before
568 // RenderViewHostManager::DidNavigateMainFrame is called. 567 // RenderViewHostManager::DidNavigateMainFrame is called.
569 // The RVH is not swapped out until the commit. 568 // The RVH is not swapped out until the commit.
570 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(), 569 manager.SwapOutOldPage();
571 static_cast<RenderViewHostImpl*>(
572 host3)->GetPendingRequestId());
573 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 570 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
574 ViewMsg_SwapOut::ID)); 571 ViewMsg_SwapOut::ID));
575 test_host->OnSwapOutACK(false); 572 test_host->OnSwappedOut(false);
576 573
577 // Commit. 574 // Commit.
578 manager.DidNavigateMainFrame(host3); 575 manager.DidNavigateMainFrame(host3);
579 EXPECT_TRUE(host3 == manager.current_host()); 576 EXPECT_TRUE(host3 == manager.current_host());
580 ASSERT_TRUE(host3); 577 ASSERT_TRUE(host3);
581 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> 578 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
582 HasSite()); 579 HasSite());
583 // Check the pending RenderViewHost has been committed. 580 // Check the pending RenderViewHost has been committed.
584 EXPECT_FALSE(manager.pending_render_view_host()); 581 EXPECT_FALSE(manager.pending_render_view_host());
585 582
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 contents()->NavigateAndCommit(kUrl2); 751 contents()->NavigateAndCommit(kUrl2);
755 TestRenderViewHost* rvh2 = test_rvh(); 752 TestRenderViewHost* rvh2 = test_rvh();
756 753
757 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't 754 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't
758 // happen, but we have seen it when going back quickly across many entries 755 // happen, but we have seen it when going back quickly across many entries
759 // (http://crbug.com/93427). 756 // (http://crbug.com/93427).
760 contents()->GetController().GoBack(); 757 contents()->GetController().GoBack();
761 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack()); 758 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack());
762 contents()->ProceedWithCrossSiteNavigation(); 759 contents()->ProceedWithCrossSiteNavigation();
763 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack()); 760 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack());
764 rvh2->SwapOut(1, 1); 761 rvh2->SwapOut();
765 EXPECT_TRUE(rvh2->is_waiting_for_unload_ack()); 762 EXPECT_TRUE(rvh2->is_waiting_for_unload_ack());
766 763
767 // The back navigation commits. We should proactively clear the 764 // The back navigation commits. We should proactively clear the
768 // is_waiting_for_unload_ack state to be safe. 765 // is_waiting_for_unload_ack state to be safe.
769 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 766 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
770 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 767 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL());
771 EXPECT_TRUE(rvh2->is_swapped_out()); 768 EXPECT_TRUE(rvh2->is_swapped_out());
772 EXPECT_FALSE(rvh2->is_waiting_for_unload_ack()); 769 EXPECT_FALSE(rvh2->is_waiting_for_unload_ack());
773 770
774 // We should be able to navigate forward. 771 // We should be able to navigate forward.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 941
945 // Commit. 942 // Commit.
946 manager.DidNavigateMainFrame(host); 943 manager.DidNavigateMainFrame(host);
947 EXPECT_EQ(host, manager.current_host()); 944 EXPECT_EQ(host, manager.current_host());
948 ASSERT_TRUE(host); 945 ASSERT_TRUE(host);
949 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 946 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
950 instance); 947 instance);
951 } 948 }
952 949
953 } // namespace content 950 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698