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

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

Issue 10907182: Add UMA counter for hung renderers on cross-site navigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 old_rvh->SendShouldCloseACK(true); 168 old_rvh->SendShouldCloseACK(true);
169 169
170 // Commit the navigation with a new page ID. 170 // Commit the navigation with a new page ID.
171 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( 171 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
172 active_rvh()->GetSiteInstance()); 172 active_rvh()->GetSiteInstance());
173 active_test_rvh()->SendNavigate(max_page_id + 1, url); 173 active_test_rvh()->SendNavigate(max_page_id + 1, url);
174 174
175 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation 175 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation
176 // without making any network requests. 176 // without making any network requests.
177 if (old_rvh != active_rvh()) 177 if (old_rvh != active_rvh())
178 old_rvh->OnSwapOutACK(); 178 old_rvh->OnSwapOutACK(false);
179 } 179 }
180 180
181 bool ShouldSwapProcesses(RenderViewHostManager* manager, 181 bool ShouldSwapProcesses(RenderViewHostManager* manager,
182 const NavigationEntryImpl* cur_entry, 182 const NavigationEntryImpl* cur_entry,
183 const NavigationEntryImpl* new_entry) const { 183 const NavigationEntryImpl* new_entry) const {
184 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); 184 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry);
185 } 185 }
186 186
187 private: 187 private:
188 RenderViewHostManagerTestClient client_; 188 RenderViewHostManagerTestClient client_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // requiring a beforeunload ack. 223 // requiring a beforeunload ack.
224 contents2->GetController().LoadURL( 224 contents2->GetController().LoadURL(
225 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, 225 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
226 std::string()); 226 std::string());
227 EXPECT_TRUE(contents2->cross_navigation_pending()); 227 EXPECT_TRUE(contents2->cross_navigation_pending());
228 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( 228 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
229 contents2->GetRenderManagerForTesting()->pending_render_view_host()); 229 contents2->GetRenderManagerForTesting()->pending_render_view_host());
230 ASSERT_TRUE(dest_rvh2); 230 ASSERT_TRUE(dest_rvh2);
231 ntp_rvh2->SendShouldCloseACK(true); 231 ntp_rvh2->SendShouldCloseACK(true);
232 dest_rvh2->SendNavigate(101, kDestUrl); 232 dest_rvh2->SendNavigate(101, kDestUrl);
233 ntp_rvh2->OnSwapOutACK(); 233 ntp_rvh2->OnSwapOutACK(false);
234 234
235 // The two RVH's should be different in every way. 235 // The two RVH's should be different in every way.
236 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); 236 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess());
237 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); 237 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance());
238 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( 238 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance(
239 dest_rvh2->GetSiteInstance())); 239 dest_rvh2->GetSiteInstance()));
240 240
241 // Navigate both to the new tab page, and verify that they share a 241 // Navigate both to the new tab page, and verify that they share a
242 // RenderProcessHost (not a SiteInstance). 242 // RenderProcessHost (not a SiteInstance).
243 NavigateActiveAndCommit(kNtpUrl); 243 NavigateActiveAndCommit(kNtpUrl);
244 244
245 contents2->GetController().LoadURL( 245 contents2->GetController().LoadURL(
246 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, 246 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
247 std::string()); 247 std::string());
248 dest_rvh2->SendShouldCloseACK(true); 248 dest_rvh2->SendShouldCloseACK(true);
249 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()-> 249 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()->
250 pending_render_view_host())->SendNavigate(102, kNtpUrl); 250 pending_render_view_host())->SendNavigate(102, kNtpUrl);
251 dest_rvh2->OnSwapOutACK(); 251 dest_rvh2->OnSwapOutACK(false);
252 252
253 EXPECT_NE(active_rvh()->GetSiteInstance(), 253 EXPECT_NE(active_rvh()->GetSiteInstance(),
254 contents2->GetRenderViewHost()->GetSiteInstance()); 254 contents2->GetRenderViewHost()->GetSiteInstance());
255 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), 255 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(),
256 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); 256 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess());
257 } 257 }
258 258
259 // Ensure that the browser ignores most IPC messages that arrive from a 259 // Ensure that the browser ignores most IPC messages that arrive from a
260 // RenderViewHost that has been swapped out. We do not want to take 260 // RenderViewHost that has been swapped out. We do not want to take
261 // action on requests from a non-active renderer. The main exception is 261 // action on requests from a non-active renderer. The main exception is
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 test_host->SendShouldCloseACK(true); 586 test_host->SendShouldCloseACK(true);
587 587
588 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 588 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
589 // call of RenderViewHostManager::OnCrossSiteResponse before 589 // call of RenderViewHostManager::OnCrossSiteResponse before
590 // RenderViewHostManager::DidNavigateMainFrame is called. 590 // RenderViewHostManager::DidNavigateMainFrame is called.
591 // The RVH is not swapped out until the commit. 591 // The RVH is not swapped out until the commit.
592 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(), 592 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(),
593 host2->GetPendingRequestId()); 593 host2->GetPendingRequestId());
594 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 594 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
595 ViewMsg_SwapOut::ID)); 595 ViewMsg_SwapOut::ID));
596 test_host->OnSwapOutACK(); 596 test_host->OnSwapOutACK(false);
597 597
598 EXPECT_EQ(host, manager.current_host()); 598 EXPECT_EQ(host, manager.current_host());
599 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( 599 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
600 manager.current_host())->is_swapped_out()); 600 manager.current_host())->is_swapped_out());
601 EXPECT_EQ(host2, manager.pending_render_view_host()); 601 EXPECT_EQ(host2, manager.pending_render_view_host());
602 // There should be still no navigation messages being sent. 602 // There should be still no navigation messages being sent.
603 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 603 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
604 ViewMsg_Navigate::ID)); 604 ViewMsg_Navigate::ID));
605 605
606 // 3) Cross-site navigate to next site before 2) has committed. -------------- 606 // 3) Cross-site navigate to next site before 2) has committed. --------------
(...skipping 27 matching lines...) Expand all
634 634
635 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 635 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
636 // call of RenderViewHostManager::OnCrossSiteResponse before 636 // call of RenderViewHostManager::OnCrossSiteResponse before
637 // RenderViewHostManager::DidNavigateMainFrame is called. 637 // RenderViewHostManager::DidNavigateMainFrame is called.
638 // The RVH is not swapped out until the commit. 638 // The RVH is not swapped out until the commit.
639 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(), 639 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(),
640 static_cast<RenderViewHostImpl*>( 640 static_cast<RenderViewHostImpl*>(
641 host3)->GetPendingRequestId()); 641 host3)->GetPendingRequestId());
642 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 642 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
643 ViewMsg_SwapOut::ID)); 643 ViewMsg_SwapOut::ID));
644 test_host->OnSwapOutACK(); 644 test_host->OnSwapOutACK(false);
645 645
646 // Commit. 646 // Commit.
647 manager.DidNavigateMainFrame(host3); 647 manager.DidNavigateMainFrame(host3);
648 EXPECT_TRUE(host3 == manager.current_host()); 648 EXPECT_TRUE(host3 == manager.current_host());
649 ASSERT_TRUE(host3); 649 ASSERT_TRUE(host3);
650 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> 650 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
651 HasSite()); 651 HasSite());
652 // Check the pending RenderViewHost has been committed. 652 // Check the pending RenderViewHost has been committed.
653 EXPECT_FALSE(manager.pending_render_view_host()); 653 EXPECT_FALSE(manager.pending_render_view_host());
654 654
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 EXPECT_FALSE(manager.pending_render_view_host()); 946 EXPECT_FALSE(manager.pending_render_view_host());
947 947
948 // Commit. 948 // Commit.
949 manager.DidNavigateMainFrame(host); 949 manager.DidNavigateMainFrame(host);
950 EXPECT_EQ(host, manager.current_host()); 950 EXPECT_EQ(host, manager.current_host());
951 ASSERT_TRUE(host); 951 ASSERT_TRUE(host);
952 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 952 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
953 instance); 953 instance);
954 954
955 } 955 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698