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

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

Issue 9288037: Do not filter IPC messages until the new RVH commits, to avoid a race. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment as well. Created 8 years, 11 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 "content/browser/browser_thread_impl.h" 5 #include "content/browser/browser_thread_impl.h"
6 #include "content/browser/browser_url_handler.h" 6 #include "content/browser/browser_url_handler.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.h" 9 #include "content/browser/site_instance.h"
10 #include "content/browser/tab_contents/navigation_controller_impl.h" 10 #include "content/browser/tab_contents/navigation_controller_impl.h"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 EXPECT_FALSE(host->site_instance()->has_site()); 421 EXPECT_FALSE(host->site_instance()->has_site());
422 host->site_instance()->SetSite(kUrl1); 422 host->site_instance()->SetSite(kUrl1);
423 423
424 // 2) Cross-site navigate to next site. ------------------------- 424 // 2) Cross-site navigate to next site. -------------------------
425 const GURL kUrl2("http://www.example.com"); 425 const GURL kUrl2("http://www.example.com");
426 NavigationEntryImpl entry2( 426 NavigationEntryImpl entry2(
427 NULL /* instance */, -1 /* page_id */, kUrl2, content::Referrer(), 427 NULL /* instance */, -1 /* page_id */, kUrl2, content::Referrer(),
428 string16() /* title */, content::PAGE_TRANSITION_TYPED, 428 string16() /* title */, content::PAGE_TRANSITION_TYPED,
429 false /* is_renderer_init */); 429 false /* is_renderer_init */);
430 RenderViewHost* host2 = manager.Navigate(entry2); 430 RenderViewHost* host2 = manager.Navigate(entry2);
431 int host2_process_id = host2->process()->GetID();
431 432
432 // A new RenderViewHost should be created. 433 // A new RenderViewHost should be created.
433 EXPECT_TRUE(manager.pending_render_view_host()); 434 EXPECT_TRUE(manager.pending_render_view_host());
434 ASSERT_EQ(host2, manager.pending_render_view_host()); 435 ASSERT_EQ(host2, manager.pending_render_view_host());
436 EXPECT_NE(host2, host);
435 437
436 // Check that the navigation is still suspended because the old RVH 438 // Check that the navigation is still suspended because the old RVH
437 // is not swapped out, yet. 439 // is not swapped out, yet.
440 EXPECT_TRUE(host2->are_navigations_suspended());
438 MockRenderProcessHost* test_process_host2 = 441 MockRenderProcessHost* test_process_host2 =
439 static_cast<MockRenderProcessHost*>(host2->process()); 442 static_cast<MockRenderProcessHost*>(host2->process());
440 test_process_host2->sink().ClearMessages(); 443 test_process_host2->sink().ClearMessages();
441 host2->NavigateToURL(kUrl2); 444 host2->NavigateToURL(kUrl2);
442 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 445 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
443 ViewMsg_Navigate::ID)); 446 ViewMsg_Navigate::ID));
444 447
445 // Allow closing the current Render View (precondition for swapping out 448 // Allow closing the current Render View (precondition for swapping out
446 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by 449 // the RVH): Simulate response from RenderView for ViewMsg_ShouldClose sent by
447 // FirePageBeforeUnload 450 // FirePageBeforeUnload.
448 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host); 451 TestRenderViewHost* test_host = static_cast<TestRenderViewHost*>(host);
449 MockRenderProcessHost* test_process_host = 452 MockRenderProcessHost* test_process_host =
450 static_cast<MockRenderProcessHost*>(test_host->process()); 453 static_cast<MockRenderProcessHost*>(test_host->process());
451 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 454 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
452 ViewMsg_ShouldClose::ID)); 455 ViewMsg_ShouldClose::ID));
453 test_host->SendShouldCloseACK(true); 456 test_host->SendShouldCloseACK(true);
454 457
455 // CrossSiteResourceHandler::StartCrossSiteTransition can trigger a 458 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
456 // call of RenderViewHostManager::OnCrossSiteResponse before 459 // call of RenderViewHostManager::OnCrossSiteResponse before
457 // RenderViewHostManager::DidNavigateMainFrame is called. In this case the 460 // RenderViewHostManager::DidNavigateMainFrame is called.
458 // RVH is swapped out. 461 // The RVH is not swapped out until the commit.
459 manager.OnCrossSiteResponse(host2->process()->GetID(), 462 manager.OnCrossSiteResponse(host2->process()->GetID(),
460 host2->GetPendingRequestId()); 463 host2->GetPendingRequestId());
461 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( 464 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
462 ViewMsg_SwapOut::ID)); 465 ViewMsg_SwapOut::ID));
463 test_host->OnSwapOutACK(); 466 test_host->OnSwapOutACK();
464 467
465 EXPECT_EQ(host, manager.current_host()); 468 EXPECT_EQ(host, manager.current_host());
466 EXPECT_TRUE(manager.current_host()->is_swapped_out()); 469 EXPECT_FALSE(manager.current_host()->is_swapped_out());
467 EXPECT_EQ(host2, manager.pending_render_view_host()); 470 EXPECT_EQ(host2, manager.pending_render_view_host());
468 // There should be still no navigation messages being sent. 471 // There should be still no navigation messages being sent.
469 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 472 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
470 ViewMsg_Navigate::ID)); 473 ViewMsg_Navigate::ID));
471 474
472 // 3) Cross-site navigate to next site before 2) has committed. -------------- 475 // 3) Cross-site navigate to next site before 2) has committed. --------------
473 const GURL kUrl3("http://webkit.org/"); 476 const GURL kUrl3("http://webkit.org/");
474 NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3, 477 NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3,
475 content::Referrer(), string16() /* title */, 478 content::Referrer(), string16() /* title */,
476 content::PAGE_TRANSITION_TYPED, 479 content::PAGE_TRANSITION_TYPED,
477 false /* is_renderer_init */); 480 false /* is_renderer_init */);
481 test_process_host->sink().ClearMessages();
478 RenderViewHost* host3 = manager.Navigate(entry3); 482 RenderViewHost* host3 = manager.Navigate(entry3);
479 483
480 // A new RenderViewHost should be created. 484 // A new RenderViewHost should be created. host2 is now deleted.
481 EXPECT_TRUE(manager.pending_render_view_host()); 485 EXPECT_TRUE(manager.pending_render_view_host());
482 ASSERT_EQ(host3, manager.pending_render_view_host()); 486 ASSERT_EQ(host3, manager.pending_render_view_host());
487 EXPECT_NE(host3, host);
488 EXPECT_NE(host3->process()->GetID(), host2_process_id);
483 489
490 // Navigations in the new RVH should be suspended, which is ok because the
491 // old RVH is not yet swapped out and can respond to a second beforeunload
492 // request.
493 EXPECT_TRUE(host3->are_navigations_suspended());
484 EXPECT_EQ(host, manager.current_host()); 494 EXPECT_EQ(host, manager.current_host());
485 EXPECT_TRUE(manager.current_host()->is_swapped_out()); 495 EXPECT_FALSE(manager.current_host()->is_swapped_out());
486 496
487 // The navigation should not be suspended because the RVH |host| has been 497 // Simulate a response to the second beforeunload request.
488 // swapped out already. Therefore, the RVH should send a navigation event 498 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
489 // immediately. 499 ViewMsg_ShouldClose::ID));
490 MockRenderProcessHost* test_process_host3 = 500 test_host->SendShouldCloseACK(true);
491 static_cast<MockRenderProcessHost*>(host3->process());
492 test_process_host3->sink().ClearMessages();
493 501
494 // Usually TabContents::NavigateToEntry would call 502 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a
495 // RenderViewHostManager::Navigate followed by RenderViewHost::Navigate. 503 // call of RenderViewHostManager::OnCrossSiteResponse before
496 // Here we need to call the latter ourselves. 504 // RenderViewHostManager::DidNavigateMainFrame is called.
497 host3->NavigateToURL(kUrl3); 505 // The RVH is not swapped out until the commit.
498 EXPECT_TRUE(test_process_host3->sink().GetUniqueMessageMatching( 506 manager.OnCrossSiteResponse(host3->process()->GetID(),
499 ViewMsg_Navigate::ID)); 507 host3->GetPendingRequestId());
508 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching(
509 ViewMsg_SwapOut::ID));
510 test_host->OnSwapOutACK();
500 511
501 // Commit. 512 // Commit.
502 manager.DidNavigateMainFrame(host3); 513 manager.DidNavigateMainFrame(host3);
503 EXPECT_TRUE(host3 == manager.current_host()); 514 EXPECT_TRUE(host3 == manager.current_host());
504 ASSERT_TRUE(host3); 515 ASSERT_TRUE(host3);
505 EXPECT_TRUE(host3->site_instance()->has_site()); 516 EXPECT_TRUE(host3->site_instance()->has_site());
506 // Check the pending RenderViewHost has been committed. 517 // Check the pending RenderViewHost has been committed.
507 EXPECT_FALSE(manager.pending_render_view_host()); 518 EXPECT_FALSE(manager.pending_render_view_host());
508 519
509 // We should observe a notification. 520 // We should observe a notification.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 // current one. 626 // current one.
616 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 627 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
617 pending_render_view_host() == NULL); 628 pending_render_view_host() == NULL);
618 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host()); 629 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host());
619 630
620 // Also we should not have a pending navigation entry. 631 // Also we should not have a pending navigation entry.
621 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); 632 NavigationEntry* entry = contents()->GetController().GetActiveEntry();
622 ASSERT_TRUE(entry != NULL); 633 ASSERT_TRUE(entry != NULL);
623 EXPECT_EQ(kUrl2, entry->GetURL()); 634 EXPECT_EQ(kUrl2, entry->GetURL());
624 } 635 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698