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

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

Issue 88503002: Have the unload event execute in background on cross-site navigations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Keeping the old rvh alive for up to 1s Created 7 years 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 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/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "content/browser/frame_host/navigation_controller_impl.h" 6 #include "content/browser/frame_host/navigation_controller_impl.h"
7 #include "content/browser/frame_host/navigation_entry_impl.h" 7 #include "content/browser/frame_host/navigation_entry_impl.h"
8 #include "content/browser/frame_host/render_frame_host_manager.h" 8 #include "content/browser/frame_host/render_frame_host_manager.h"
9 #include "content/browser/site_instance_impl.h" 9 #include "content/browser/site_instance_impl.h"
10 #include "content/browser/webui/web_ui_controller_factory_registry.h" 10 #include "content/browser/webui/web_ui_controller_factory_registry.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (old_rvh != active_rvh()) 121 if (old_rvh != active_rvh())
122 old_rvh->SendShouldCloseACK(true); 122 old_rvh->SendShouldCloseACK(true);
123 123
124 // Commit the navigation with a new page ID. 124 // Commit the navigation with a new page ID.
125 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( 125 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
126 active_rvh()->GetSiteInstance()); 126 active_rvh()->GetSiteInstance());
127 127
128 // Simulate the SwapOut_ACK that fires if you commit a cross-site 128 // Simulate the SwapOut_ACK that fires if you commit a cross-site
129 // navigation. 129 // navigation.
130 if (old_rvh != active_rvh()) 130 if (old_rvh != active_rvh())
131 old_rvh->OnSwappedOut(false); 131 old_rvh->OnSwappedOut(false, false);
132 132
133 active_test_rvh()->SendNavigate(max_page_id + 1, url); 133 active_test_rvh()->SendNavigate(max_page_id + 1, url);
134 } 134 }
135 135
136 bool ShouldSwapProcesses(RenderFrameHostManager* manager, 136 bool ShouldSwapProcesses(RenderFrameHostManager* manager,
137 const NavigationEntryImpl* current_entry, 137 const NavigationEntryImpl* current_entry,
138 const NavigationEntryImpl* new_entry) const { 138 const NavigationEntryImpl* new_entry) const {
139 return manager->ShouldSwapBrowsingInstancesForNavigation(current_entry, 139 return manager->ShouldSwapBrowsingInstancesForNavigation(current_entry,
140 new_entry); 140 new_entry);
141 } 141 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // The second one is the opposite, creating a cross-site transition and 212 // The second one is the opposite, creating a cross-site transition and
213 // requiring a beforeunload ack. 213 // requiring a beforeunload ack.
214 contents2->GetController().LoadURL( 214 contents2->GetController().LoadURL(
215 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); 215 kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
216 EXPECT_TRUE(contents2->cross_navigation_pending()); 216 EXPECT_TRUE(contents2->cross_navigation_pending());
217 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( 217 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
218 contents2->GetRenderManagerForTesting()->pending_render_view_host()); 218 contents2->GetRenderManagerForTesting()->pending_render_view_host());
219 ASSERT_TRUE(dest_rvh2); 219 ASSERT_TRUE(dest_rvh2);
220 220
221 ntp_rvh2->SendShouldCloseACK(true); 221 ntp_rvh2->SendShouldCloseACK(true);
222 ntp_rvh2->OnSwappedOut(false); 222 ntp_rvh2->OnSwappedOut(false, false);
223 dest_rvh2->SendNavigate(101, kDestUrl); 223 dest_rvh2->SendNavigate(101, kDestUrl);
224 224
225 // The two RVH's should be different in every way. 225 // The two RVH's should be different in every way.
226 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); 226 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess());
227 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); 227 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance());
228 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( 228 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance(
229 dest_rvh2->GetSiteInstance())); 229 dest_rvh2->GetSiteInstance()));
230 230
231 // Navigate both to the new tab page, and verify that they share a 231 // Navigate both to the new tab page, and verify that they share a
232 // RenderProcessHost (not a SiteInstance). 232 // RenderProcessHost (not a SiteInstance).
233 NavigateActiveAndCommit(kChromeUrl); 233 NavigateActiveAndCommit(kChromeUrl);
234 234
235 contents2->GetController().LoadURL( 235 contents2->GetController().LoadURL(
236 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); 236 kChromeUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
237 dest_rvh2->SendShouldCloseACK(true); 237 dest_rvh2->SendShouldCloseACK(true);
238 dest_rvh2->OnSwappedOut(false); 238 dest_rvh2->OnSwappedOut(false, false);
239 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()-> 239 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()->
240 pending_render_view_host())->SendNavigate(102, kChromeUrl); 240 pending_render_view_host())->SendNavigate(102, kChromeUrl);
241 241
242 EXPECT_NE(active_rvh()->GetSiteInstance(), 242 EXPECT_NE(active_rvh()->GetSiteInstance(),
243 contents2->GetRenderViewHost()->GetSiteInstance()); 243 contents2->GetRenderViewHost()->GetSiteInstance());
244 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), 244 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(),
245 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); 245 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess());
246 } 246 }
247 247
248 // Ensure that the browser ignores most IPC messages that arrive from a 248 // Ensure that the browser ignores most IPC messages that arrive from a
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 ViewMsg_ShouldClose::ID)); 752 ViewMsg_ShouldClose::ID));
753 test_host->SendShouldCloseACK(true); 753 test_host->SendShouldCloseACK(true);
754 754
755 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 755 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
756 // call of RenderFrameHostManager::SwapOutOldPage before 756 // call of RenderFrameHostManager::SwapOutOldPage before
757 // RenderFrameHostManager::DidNavigateMainFrame is called. 757 // RenderFrameHostManager::DidNavigateMainFrame is called.
758 // The RVH is not swapped out until the commit. 758 // The RVH is not swapped out until the commit.
759 manager.SwapOutOldPage(); 759 manager.SwapOutOldPage();
760 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 760 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
761 ViewMsg_SwapOut::ID)); 761 ViewMsg_SwapOut::ID));
762 test_host->OnSwappedOut(false); 762 test_host->OnSwappedOut(false, false);
763 763
764 EXPECT_EQ(host, manager.current_host()); 764 EXPECT_EQ(host, manager.current_host());
765 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( 765 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
766 manager.current_host())->is_swapped_out()); 766 manager.current_host())->is_swapped_out());
767 EXPECT_EQ(host2, manager.pending_render_view_host()); 767 EXPECT_EQ(host2, manager.pending_render_view_host());
768 // There should be still no navigation messages being sent. 768 // There should be still no navigation messages being sent.
769 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 769 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
770 ViewMsg_Navigate::ID)); 770 ViewMsg_Navigate::ID));
771 771
772 // 3) Cross-site navigate to next site before 2) has committed. -------------- 772 // 3) Cross-site navigate to next site before 2) has committed. --------------
(...skipping 25 matching lines...) Expand all
798 ViewMsg_ShouldClose::ID)); 798 ViewMsg_ShouldClose::ID));
799 test_host->SendShouldCloseACK(true); 799 test_host->SendShouldCloseACK(true);
800 800
801 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 801 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
802 // call of RenderFrameHostManager::SwapOutOldPage before 802 // call of RenderFrameHostManager::SwapOutOldPage before
803 // RenderFrameHostManager::DidNavigateMainFrame is called. 803 // RenderFrameHostManager::DidNavigateMainFrame is called.
804 // The RVH is not swapped out until the commit. 804 // The RVH is not swapped out until the commit.
805 manager.SwapOutOldPage(); 805 manager.SwapOutOldPage();
806 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 806 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
807 ViewMsg_SwapOut::ID)); 807 ViewMsg_SwapOut::ID));
808 test_host->OnSwappedOut(false); 808 test_host->OnSwappedOut(false, false);
809 809
810 // Commit. 810 // Commit.
811 manager.DidNavigateMainFrame(host3); 811 manager.DidNavigateMainFrame(host3);
812 EXPECT_TRUE(host3 == manager.current_host()); 812 EXPECT_TRUE(host3 == manager.current_host());
813 ASSERT_TRUE(host3); 813 ASSERT_TRUE(host3);
814 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> 814 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
815 HasSite()); 815 HasSite());
816 // Check the pending RenderViewHost has been committed. 816 // Check the pending RenderViewHost has been committed.
817 EXPECT_FALSE(manager.pending_render_view_host()); 817 EXPECT_FALSE(manager.pending_render_view_host());
818 818
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 Source<RenderWidgetHost>(host2)); 1310 Source<RenderWidgetHost>(host2));
1311 manager.ShouldClosePage(false, true, base::TimeTicks()); 1311 manager.ShouldClosePage(false, true, base::TimeTicks());
1312 1312
1313 EXPECT_TRUE( 1313 EXPECT_TRUE(
1314 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); 1314 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED));
1315 EXPECT_FALSE(manager.pending_render_view_host()); 1315 EXPECT_FALSE(manager.pending_render_view_host());
1316 EXPECT_EQ(host, manager.current_host()); 1316 EXPECT_EQ(host, manager.current_host());
1317 } 1317 }
1318 1318
1319 } // namespace content 1319 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698