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

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

Issue 636673002: Remove navigation from TestRenderViewHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a TODO Created 6 years, 2 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
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/frame_host/cross_site_transferring_request.h" 10 #include "content/browser/frame_host/cross_site_transferring_request.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void set_should_create_webui(bool should_create_webui) { 274 void set_should_create_webui(bool should_create_webui) {
275 factory_.set_should_create_webui(should_create_webui); 275 factory_.set_should_create_webui(should_create_webui);
276 } 276 }
277 277
278 void NavigateActiveAndCommit(const GURL& url) { 278 void NavigateActiveAndCommit(const GURL& url) {
279 // Note: we navigate the active RenderFrameHost because previous navigations 279 // Note: we navigate the active RenderFrameHost because previous navigations
280 // won't have committed yet, so NavigateAndCommit does the wrong thing 280 // won't have committed yet, so NavigateAndCommit does the wrong thing
281 // for us. 281 // for us.
282 controller().LoadURL( 282 controller().LoadURL(
283 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 283 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
284 TestRenderViewHost* old_rvh = test_rvh(); 284 TestRenderFrameHost* old_rfh = contents()->GetMainFrame();
285 TestRenderFrameHost* old_rfh = main_test_rfh(); 285 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame()
286 TestRenderFrameHost* active_rfh = pending_main_rfh() ? 286 ? contents()->GetPendingMainFrame()
287 static_cast<TestRenderFrameHost*>(pending_main_rfh()) : 287 : old_rfh;
288 old_rfh;
289 288
290 // Simulate the BeforeUnload_ACK that is received from the current renderer 289 // Simulate the BeforeUnload_ACK that is received from the current renderer
291 // for a cross-site navigation. 290 // for a cross-site navigation.
292 if (old_rfh != active_rfh) { 291 if (old_rfh != active_rfh) {
293 old_rfh->SendBeforeUnloadACK(true); 292 old_rfh->SendBeforeUnloadACK(true);
294 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); 293 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state());
295 } 294 }
296 295
297 // Commit the navigation with a new page ID. 296 // Commit the navigation with a new page ID.
298 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( 297 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance(
299 active_rfh->GetSiteInstance()); 298 active_rfh->GetSiteInstance());
300 299
301 // Use an observer to avoid accessing a deleted renderer later on when the 300 // Use an observer to avoid accessing a deleted renderer later on when the
302 // state is being checked. 301 // state is being checked.
303 RenderFrameHostDeletedObserver rfh_observer(old_rfh); 302 RenderFrameHostDeletedObserver rfh_observer(old_rfh);
304 RenderViewHostDeletedObserver rvh_observer(old_rvh); 303 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost());
305 active_rfh->SendNavigate(max_page_id + 1, url); 304 active_rfh->SendNavigate(max_page_id + 1, url);
306 305
307 // Make sure that we start to run the unload handler at the time of commit. 306 // Make sure that we start to run the unload handler at the time of commit.
308 bool expecting_rfh_shutdown = false; 307 bool expecting_rfh_shutdown = false;
309 if (old_rfh != active_rfh && !rfh_observer.deleted()) { 308 if (old_rfh != active_rfh && !rfh_observer.deleted()) {
310 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, 309 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT,
311 old_rfh->rfh_state()); 310 old_rfh->rfh_state());
312 if (!old_rfh->GetSiteInstance()->active_frame_count()) { 311 if (!old_rfh->GetSiteInstance()->active_frame_count()) {
313 expecting_rfh_shutdown = true; 312 expecting_rfh_shutdown = true;
314 EXPECT_TRUE( 313 EXPECT_TRUE(
315 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion( 314 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion(
316 old_rfh)); 315 old_rfh));
317 } 316 }
318 } 317 }
319 318
320 // Simulate the swap out ACK coming from the pending renderer. This should 319 // Simulate the swap out ACK coming from the pending renderer. This should
321 // either shut down the old RFH or leave it in a swapped out state. 320 // either shut down the old RFH or leave it in a swapped out state.
322 if (old_rfh != active_rfh) { 321 if (old_rfh != active_rfh) {
323 old_rfh->OnSwappedOut(); 322 old_rfh->OnSwappedOut();
324 if (expecting_rfh_shutdown) { 323 if (expecting_rfh_shutdown) {
325 EXPECT_TRUE(rfh_observer.deleted()); 324 EXPECT_TRUE(rfh_observer.deleted());
326 EXPECT_TRUE(rvh_observer.deleted()); 325 EXPECT_TRUE(rvh_observer.deleted());
327 } else { 326 } else {
328 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, 327 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT,
329 old_rfh->rfh_state()); 328 old_rfh->rfh_state());
330 } 329 }
331 } 330 }
331 EXPECT_EQ(active_rfh, contents()->GetMainFrame());
332 EXPECT_EQ(NULL, contents()->GetPendingMainFrame());
332 } 333 }
333 334
334 bool ShouldSwapProcesses(RenderFrameHostManager* manager, 335 bool ShouldSwapProcesses(RenderFrameHostManager* manager,
335 const NavigationEntryImpl* current_entry, 336 const NavigationEntryImpl* current_entry,
336 const NavigationEntryImpl* new_entry) const { 337 const NavigationEntryImpl* new_entry) const {
337 CHECK(new_entry); 338 CHECK(new_entry);
338 BrowserContext* browser_context = 339 BrowserContext* browser_context =
339 manager->delegate_->GetControllerForRenderManager().GetBrowserContext(); 340 manager->delegate_->GetControllerForRenderManager().GetBrowserContext();
340 const GURL& current_effective_url = current_entry ? 341 const GURL& current_effective_url = current_entry ?
341 SiteInstanceImpl::GetEffectiveURL(browser_context, 342 SiteInstanceImpl::GetEffectiveURL(browser_context,
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 1693 pending_rfh->GetSiteInstance()->increment_active_frame_count();
1693 1694
1694 contents()->GetMainFrame()->OnMessageReceived( 1695 contents()->GetMainFrame()->OnMessageReceived(
1695 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1696 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
1696 EXPECT_FALSE(contents()->cross_navigation_pending()); 1697 EXPECT_FALSE(contents()->cross_navigation_pending());
1697 EXPECT_FALSE(rfh_deleted_observer.deleted()); 1698 EXPECT_FALSE(rfh_deleted_observer.deleted());
1698 } 1699 }
1699 } 1700 }
1700 1701
1701 } // namespace content 1702 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698