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

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: Rebase to get Android build fix 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/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "content/browser/renderer_host/test_render_view_host.h" 6 #include "content/browser/renderer_host/test_render_view_host.h"
7 #include "content/browser/site_instance_impl.h" 7 #include "content/browser/site_instance_impl.h"
8 #include "content/browser/web_contents/navigation_controller_impl.h" 8 #include "content/browser/web_contents/navigation_controller_impl.h"
9 #include "content/browser/web_contents/navigation_entry_impl.h" 9 #include "content/browser/web_contents/navigation_entry_impl.h"
10 #include "content/browser/web_contents/render_view_host_manager.h" 10 #include "content/browser/web_contents/render_view_host_manager.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 old_rvh->SendShouldCloseACK(true); 102 old_rvh->SendShouldCloseACK(true);
103 103
104 // Commit the navigation with a new page ID. 104 // Commit the navigation with a new page ID.
105 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( 105 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
106 active_rvh()->GetSiteInstance()); 106 active_rvh()->GetSiteInstance());
107 active_test_rvh()->SendNavigate(max_page_id + 1, url); 107 active_test_rvh()->SendNavigate(max_page_id + 1, url);
108 108
109 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation 109 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation
110 // without making any network requests. 110 // without making any network requests.
111 if (old_rvh != active_rvh()) 111 if (old_rvh != active_rvh())
112 old_rvh->OnSwapOutACK(false); 112 old_rvh->OnSwappedOut(false);
113 } 113 }
114 114
115 bool ShouldSwapProcesses(RenderViewHostManager* manager, 115 bool ShouldSwapProcesses(RenderViewHostManager* manager,
116 const NavigationEntryImpl* cur_entry, 116 const NavigationEntryImpl* cur_entry,
117 const NavigationEntryImpl* new_entry) const { 117 const NavigationEntryImpl* new_entry) const {
118 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); 118 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry);
119 } 119 }
120 120
121 private: 121 private:
122 RenderViewHostManagerTestWebUIControllerFactory factory_; 122 RenderViewHostManagerTestWebUIControllerFactory factory_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // The second one is the opposite, creating a cross-site transition and 154 // The second one is the opposite, creating a cross-site transition and
155 // requiring a beforeunload ack. 155 // requiring a beforeunload ack.
156 contents2->GetController().LoadURL( 156 contents2->GetController().LoadURL(
157 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); 157 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
158 EXPECT_TRUE(contents2->cross_navigation_pending()); 158 EXPECT_TRUE(contents2->cross_navigation_pending());
159 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( 159 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
160 contents2->GetRenderManagerForTesting()->pending_render_view_host()); 160 contents2->GetRenderManagerForTesting()->pending_render_view_host());
161 ASSERT_TRUE(dest_rvh2); 161 ASSERT_TRUE(dest_rvh2);
162 ntp_rvh2->SendShouldCloseACK(true); 162 ntp_rvh2->SendShouldCloseACK(true);
163 dest_rvh2->SendNavigate(101, kDestUrl); 163 dest_rvh2->SendNavigate(101, kDestUrl);
164 ntp_rvh2->OnSwapOutACK(false); 164 ntp_rvh2->OnSwappedOut(false);
165 165
166 // The two RVH's should be different in every way. 166 // The two RVH's should be different in every way.
167 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); 167 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess());
168 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); 168 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance());
169 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( 169 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance(
170 dest_rvh2->GetSiteInstance())); 170 dest_rvh2->GetSiteInstance()));
171 171
172 // Navigate both to the new tab page, and verify that they share a 172 // Navigate both to the new tab page, and verify that they share a
173 // RenderProcessHost (not a SiteInstance). 173 // RenderProcessHost (not a SiteInstance).
174 NavigateActiveAndCommit(kChromeUrl); 174 NavigateActiveAndCommit(kChromeUrl);
175 175
176 contents2->GetController().LoadURL( 176 contents2->GetController().LoadURL(
177 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); 177 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
178 dest_rvh2->SendShouldCloseACK(true); 178 dest_rvh2->SendShouldCloseACK(true);
179 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()-> 179 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()->
180 pending_render_view_host())->SendNavigate(102, kChromeUrl); 180 pending_render_view_host())->SendNavigate(102, kChromeUrl);
181 dest_rvh2->OnSwapOutACK(false); 181 dest_rvh2->OnSwappedOut(false);
182 182
183 EXPECT_NE(active_rvh()->GetSiteInstance(), 183 EXPECT_NE(active_rvh()->GetSiteInstance(),
184 contents2->GetRenderViewHost()->GetSiteInstance()); 184 contents2->GetRenderViewHost()->GetSiteInstance());
185 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), 185 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(),
186 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); 186 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess());
187 } 187 }
188 188
189 // Ensure that the browser ignores most IPC messages that arrive from a 189 // Ensure that the browser ignores most IPC messages that arrive from a
190 // RenderViewHost that has been swapped out. We do not want to take 190 // RenderViewHost that has been swapped out. We do not want to take
191 // action on requests from a non-active renderer. The main exception is 191 // action on requests from a non-active renderer. The main exception is
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by 505 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by
506 // FirePageBeforeUnload. 506 // FirePageBeforeUnload.
507 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host); 507 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host);
508 MockRenderProcessHost* test_process_host = 508 MockRenderProcessHost* test_process_host =
509 static_cast<MockRenderProcessHost*>(test_host->GetProcess()); 509 static_cast<MockRenderProcessHost*>(test_host->GetProcess());
510 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 510 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
511 ViewMsg_ShouldClose::ID)); 511 ViewMsg_ShouldClose::ID));
512 test_host->SendShouldCloseACK(true); 512 test_host->SendShouldCloseACK(true);
513 513
514 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 514 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
515 // call of RenderViewHostManager::OnCrossSiteResponse before 515 // call of RenderViewHostManager::SwapOutOldPage before
516 // RenderViewHostManager::DidNavigateMainFrame is called. 516 // RenderViewHostManager::DidNavigateMainFrame is called.
517 // The RVH is not swapped out until the commit. 517 // The RVH is not swapped out until the commit.
518 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(), 518 manager.SwapOutOldPage();
519 host2->GetPendingRequestId());
520 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 519 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
521 ViewMsg_SwapOut::ID)); 520 ViewMsg_SwapOut::ID));
522 test_host->OnSwapOutACK(false); 521 test_host->OnSwappedOut(false);
523 522
524 EXPECT_EQ(host, manager.current_host()); 523 EXPECT_EQ(host, manager.current_host());
525 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( 524 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
526 manager.current_host())->is_swapped_out()); 525 manager.current_host())->is_swapped_out());
527 EXPECT_EQ(host2, manager.pending_render_view_host()); 526 EXPECT_EQ(host2, manager.pending_render_view_host());
528 // There should be still no navigation messages being sent. 527 // There should be still no navigation messages being sent.
529 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 528 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
530 ViewMsg_Navigate::ID)); 529 ViewMsg_Navigate::ID));
531 530
532 // 3) Cross-site navigate to next site before 2) has committed. -------------- 531 // 3) Cross-site navigate to next site before 2) has committed. --------------
(...skipping 19 matching lines...) Expand all
552 EXPECT_EQ(host, manager.current_host()); 551 EXPECT_EQ(host, manager.current_host());
553 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( 552 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
554 manager.current_host())->is_swapped_out()); 553 manager.current_host())->is_swapped_out());
555 554
556 // Simulate a response to the second beforeunload request. 555 // Simulate a response to the second beforeunload request.
557 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 556 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
558 ViewMsg_ShouldClose::ID)); 557 ViewMsg_ShouldClose::ID));
559 test_host->SendShouldCloseACK(true); 558 test_host->SendShouldCloseACK(true);
560 559
561 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 560 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
562 // call of RenderViewHostManager::OnCrossSiteResponse before 561 // call of RenderViewHostManager::SwapOutOldPage before
563 // RenderViewHostManager::DidNavigateMainFrame is called. 562 // RenderViewHostManager::DidNavigateMainFrame is called.
564 // The RVH is not swapped out until the commit. 563 // The RVH is not swapped out until the commit.
565 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(), 564 manager.SwapOutOldPage();
566 static_cast<RenderViewHostImpl*>(
567 host3)->GetPendingRequestId());
568 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 565 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
569 ViewMsg_SwapOut::ID)); 566 ViewMsg_SwapOut::ID));
570 test_host->OnSwapOutACK(false); 567 test_host->OnSwappedOut(false);
571 568
572 // Commit. 569 // Commit.
573 manager.DidNavigateMainFrame(host3); 570 manager.DidNavigateMainFrame(host3);
574 EXPECT_TRUE(host3 == manager.current_host()); 571 EXPECT_TRUE(host3 == manager.current_host());
575 ASSERT_TRUE(host3); 572 ASSERT_TRUE(host3);
576 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> 573 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
577 HasSite()); 574 HasSite());
578 // Check the pending RenderViewHost has been committed. 575 // Check the pending RenderViewHost has been committed.
579 EXPECT_FALSE(manager.pending_render_view_host()); 576 EXPECT_FALSE(manager.pending_render_view_host());
580 577
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 contents()->NavigateAndCommit(kUrl2); 745 contents()->NavigateAndCommit(kUrl2);
749 TestRenderViewHost* rvh2 = test_rvh(); 746 TestRenderViewHost* rvh2 = test_rvh();
750 747
751 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't 748 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't
752 // happen, but we have seen it when going back quickly across many entries 749 // happen, but we have seen it when going back quickly across many entries
753 // (http://crbug.com/93427). 750 // (http://crbug.com/93427).
754 contents()->GetController().GoBack(); 751 contents()->GetController().GoBack();
755 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack()); 752 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack());
756 contents()->ProceedWithCrossSiteNavigation(); 753 contents()->ProceedWithCrossSiteNavigation();
757 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack()); 754 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack());
758 rvh2->SwapOut(1, 1); 755 rvh2->SwapOut();
759 EXPECT_TRUE(rvh2->is_waiting_for_unload_ack()); 756 EXPECT_TRUE(rvh2->is_waiting_for_unload_ack());
760 757
761 // The back navigation commits. We should proactively clear the 758 // The back navigation commits. We should proactively clear the
762 // is_waiting_for_unload_ack state to be safe. 759 // is_waiting_for_unload_ack state to be safe.
763 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 760 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
764 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 761 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL());
765 EXPECT_TRUE(rvh2->is_swapped_out()); 762 EXPECT_TRUE(rvh2->is_swapped_out());
766 EXPECT_FALSE(rvh2->is_waiting_for_unload_ack()); 763 EXPECT_FALSE(rvh2->is_waiting_for_unload_ack());
767 764
768 // We should be able to navigate forward. 765 // We should be able to navigate forward.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 935
939 // Commit. 936 // Commit.
940 manager.DidNavigateMainFrame(host); 937 manager.DidNavigateMainFrame(host);
941 EXPECT_EQ(host, manager.current_host()); 938 EXPECT_EQ(host, manager.current_host());
942 ASSERT_TRUE(host); 939 ASSERT_TRUE(host);
943 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 940 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
944 instance); 941 instance);
945 } 942 }
946 943
947 } // namespace content 944 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/render_view_host_manager.cc ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698