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

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

Issue 10008015: Fixing a problem, where a hung renderer process is not killed when navigating away (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing an uninitialized variable and improving the test. Created 8 years, 8 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/mock_content_browser_client.h" 7 #include "content/browser/mock_content_browser_client.h"
8 #include "content/browser/renderer_host/test_render_view_host.h" 8 #include "content/browser/renderer_host/test_render_view_host.h"
9 #include "content/browser/site_instance_impl.h" 9 #include "content/browser/site_instance_impl.h"
10 #include "content/browser/web_contents/navigation_entry_impl.h" 10 #include "content/browser/web_contents/navigation_entry_impl.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 old_rvh->SendShouldCloseACK(true); 165 old_rvh->SendShouldCloseACK(true);
166 166
167 // Commit the navigation with a new page ID. 167 // Commit the navigation with a new page ID.
168 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( 168 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
169 active_rvh()->GetSiteInstance()); 169 active_rvh()->GetSiteInstance());
170 active_test_rvh()->SendNavigate(max_page_id + 1, url); 170 active_test_rvh()->SendNavigate(max_page_id + 1, url);
171 171
172 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation 172 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation
173 // without making any network requests. 173 // without making any network requests.
174 if (old_rvh != active_rvh()) 174 if (old_rvh != active_rvh())
175 old_rvh->OnSwapOutACK(); 175 old_rvh->OnSwapOutACK(false);
176 } 176 }
177 177
178 bool ShouldSwapProcesses(RenderViewHostManager* manager, 178 bool ShouldSwapProcesses(RenderViewHostManager* manager,
179 const NavigationEntryImpl* cur_entry, 179 const NavigationEntryImpl* cur_entry,
180 const NavigationEntryImpl* new_entry) const { 180 const NavigationEntryImpl* new_entry) const {
181 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); 181 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry);
182 } 182 }
183 183
184 private: 184 private:
185 RenderViewHostManagerTestClient client_; 185 RenderViewHostManagerTestClient client_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // requiring a beforeunload ack. 219 // requiring a beforeunload ack.
220 contents2.GetController().LoadURL( 220 contents2.GetController().LoadURL(
221 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, 221 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
222 std::string()); 222 std::string());
223 EXPECT_TRUE(contents2.cross_navigation_pending()); 223 EXPECT_TRUE(contents2.cross_navigation_pending());
224 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( 224 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
225 contents2.GetRenderManagerForTesting()->pending_render_view_host()); 225 contents2.GetRenderManagerForTesting()->pending_render_view_host());
226 ASSERT_TRUE(dest_rvh2); 226 ASSERT_TRUE(dest_rvh2);
227 ntp_rvh2->SendShouldCloseACK(true); 227 ntp_rvh2->SendShouldCloseACK(true);
228 dest_rvh2->SendNavigate(101, kDestUrl); 228 dest_rvh2->SendNavigate(101, kDestUrl);
229 ntp_rvh2->OnSwapOutACK(); 229 ntp_rvh2->OnSwapOutACK(false);
230 230
231 // The two RVH's should be different in every way. 231 // The two RVH's should be different in every way.
232 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); 232 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess());
233 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); 233 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance());
234 EXPECT_NE(static_cast<SiteInstanceImpl*>(active_rvh()->GetSiteInstance())-> 234 EXPECT_NE(static_cast<SiteInstanceImpl*>(active_rvh()->GetSiteInstance())->
235 browsing_instance_, 235 browsing_instance_,
236 static_cast<SiteInstanceImpl*>(dest_rvh2->GetSiteInstance())-> 236 static_cast<SiteInstanceImpl*>(dest_rvh2->GetSiteInstance())->
237 browsing_instance_); 237 browsing_instance_);
238 238
239 // Navigate both to the new tab page, and verify that they share a 239 // Navigate both to the new tab page, and verify that they share a
240 // SiteInstance. 240 // SiteInstance.
241 NavigateActiveAndCommit(kNtpUrl); 241 NavigateActiveAndCommit(kNtpUrl);
242 242
243 contents2.GetController().LoadURL( 243 contents2.GetController().LoadURL(
244 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, 244 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
245 std::string()); 245 std::string());
246 dest_rvh2->SendShouldCloseACK(true); 246 dest_rvh2->SendShouldCloseACK(true);
247 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> 247 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()->
248 pending_render_view_host())->SendNavigate(102, kNtpUrl); 248 pending_render_view_host())->SendNavigate(102, kNtpUrl);
249 dest_rvh2->OnSwapOutACK(); 249 dest_rvh2->OnSwapOutACK(false);
250 250
251 EXPECT_EQ(active_rvh()->GetSiteInstance(), 251 EXPECT_EQ(active_rvh()->GetSiteInstance(),
252 contents2.GetRenderViewHost()->GetSiteInstance()); 252 contents2.GetRenderViewHost()->GetSiteInstance());
253 } 253 }
254 254
255 // Ensure that the browser ignores most IPC messages that arrive from a 255 // Ensure that the browser ignores most IPC messages that arrive from a
256 // RenderViewHost that has been swapped out. We do not want to take 256 // RenderViewHost that has been swapped out. We do not want to take
257 // action on requests from a non-active renderer. The main exception is 257 // action on requests from a non-active renderer. The main exception is
258 // for synchronous messages, which cannot be ignored without leaving the 258 // for synchronous messages, which cannot be ignored without leaving the
259 // renderer in a stuck state. See http://crbug.com/93427. 259 // renderer in a stuck state. See http://crbug.com/93427.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 test_host->SendShouldCloseACK(true); 576 test_host->SendShouldCloseACK(true);
577 577
578 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 578 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
579 // call of RenderViewHostManager::OnCrossSiteResponse before 579 // call of RenderViewHostManager::OnCrossSiteResponse before
580 // RenderViewHostManager::DidNavigateMainFrame is called. 580 // RenderViewHostManager::DidNavigateMainFrame is called.
581 // The RVH is not swapped out until the commit. 581 // The RVH is not swapped out until the commit.
582 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(), 582 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(),
583 host2->GetPendingRequestId()); 583 host2->GetPendingRequestId());
584 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 584 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
585 ViewMsg_SwapOut::ID)); 585 ViewMsg_SwapOut::ID));
586 test_host->OnSwapOutACK(); 586 test_host->OnSwapOutACK(false);
587 587
588 EXPECT_EQ(host, manager.current_host()); 588 EXPECT_EQ(host, manager.current_host());
589 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( 589 EXPECT_FALSE(static_cast<RenderViewHostImpl*>(
590 manager.current_host())->is_swapped_out()); 590 manager.current_host())->is_swapped_out());
591 EXPECT_EQ(host2, manager.pending_render_view_host()); 591 EXPECT_EQ(host2, manager.pending_render_view_host());
592 // There should be still no navigation messages being sent. 592 // There should be still no navigation messages being sent.
593 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 593 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
594 ViewMsg_Navigate::ID)); 594 ViewMsg_Navigate::ID));
595 595
596 // 3) Cross-site navigate to next site before 2) has committed. -------------- 596 // 3) Cross-site navigate to next site before 2) has committed. --------------
(...skipping 27 matching lines...) Expand all
624 624
625 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a 625 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
626 // call of RenderViewHostManager::OnCrossSiteResponse before 626 // call of RenderViewHostManager::OnCrossSiteResponse before
627 // RenderViewHostManager::DidNavigateMainFrame is called. 627 // RenderViewHostManager::DidNavigateMainFrame is called.
628 // The RVH is not swapped out until the commit. 628 // The RVH is not swapped out until the commit.
629 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(), 629 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(),
630 static_cast<RenderViewHostImpl*>( 630 static_cast<RenderViewHostImpl*>(
631 host3)->GetPendingRequestId()); 631 host3)->GetPendingRequestId());
632 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 632 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
633 ViewMsg_SwapOut::ID)); 633 ViewMsg_SwapOut::ID));
634 test_host->OnSwapOutACK(); 634 test_host->OnSwapOutACK(false);
635 635
636 // Commit. 636 // Commit.
637 manager.DidNavigateMainFrame(host3); 637 manager.DidNavigateMainFrame(host3);
638 EXPECT_TRUE(host3 == manager.current_host()); 638 EXPECT_TRUE(host3 == manager.current_host());
639 ASSERT_TRUE(host3); 639 ASSERT_TRUE(host3);
640 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> 640 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
641 HasSite()); 641 HasSite());
642 // Check the pending RenderViewHost has been committed. 642 // Check the pending RenderViewHost has been committed.
643 EXPECT_FALSE(manager.pending_render_view_host()); 643 EXPECT_FALSE(manager.pending_render_view_host());
644 644
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 763
764 // We should be able to navigate forward. 764 // We should be able to navigate forward.
765 contents()->GetController().GoForward(); 765 contents()->GetController().GoForward();
766 contents()->ProceedWithCrossSiteNavigation(); 766 contents()->ProceedWithCrossSiteNavigation();
767 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); 767 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry();
768 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); 768 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL());
769 EXPECT_EQ(rvh2, rvh()); 769 EXPECT_EQ(rvh2, rvh());
770 EXPECT_FALSE(rvh2->is_swapped_out()); 770 EXPECT_FALSE(rvh2->is_swapped_out());
771 EXPECT_TRUE(rvh1->is_swapped_out()); 771 EXPECT_TRUE(rvh1->is_swapped_out());
772 } 772 }
OLDNEW
« no previous file with comments | « content/browser/web_contents/render_view_host_manager.cc ('k') | content/browser/web_contents/test_web_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698