OLD | NEW |
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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.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/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/renderer_host/test_render_view_host.h" | 9 #include "content/browser/renderer_host/test_render_view_host.h" |
10 #include "content/browser/site_instance_impl.h" | 10 #include "content/browser/site_instance_impl.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 contents()->UpdateMaxPageIDForSiteInstance(instance2, 7); | 362 contents()->UpdateMaxPageIDForSiteInstance(instance2, 7); |
363 EXPECT_EQ(3, contents()->GetMaxPageID()); | 363 EXPECT_EQ(3, contents()->GetMaxPageID()); |
364 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1)); | 364 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1)); |
365 EXPECT_EQ(7, contents()->GetMaxPageIDForSiteInstance(instance2)); | 365 EXPECT_EQ(7, contents()->GetMaxPageIDForSiteInstance(instance2)); |
366 } | 366 } |
367 | 367 |
368 // Test simple same-SiteInstance navigation. | 368 // Test simple same-SiteInstance navigation. |
369 TEST_F(TabContentsTest, SimpleNavigation) { | 369 TEST_F(TabContentsTest, SimpleNavigation) { |
370 TestRenderViewHost* orig_rvh = test_rvh(); | 370 TestRenderViewHost* orig_rvh = test_rvh(); |
371 SiteInstance* instance1 = contents()->GetSiteInstance(); | 371 SiteInstance* instance1 = contents()->GetSiteInstance(); |
372 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 372 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
373 | 373 |
374 // Navigate to URL | 374 // Navigate to URL |
375 const GURL url("http://www.google.com"); | 375 const GURL url("http://www.google.com"); |
376 controller().LoadURL( | 376 controller().LoadURL( |
377 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 377 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
378 EXPECT_FALSE(contents()->cross_navigation_pending()); | 378 EXPECT_FALSE(contents()->cross_navigation_pending()); |
379 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance()); | 379 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance()); |
380 // Controller's pending entry will have a NULL site instance until we assign | 380 // Controller's pending entry will have a NULL site instance until we assign |
381 // it in DidNavigate. | 381 // it in DidNavigate. |
382 EXPECT_TRUE( | 382 EXPECT_TRUE( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 425 |
426 EXPECT_FALSE(contents()->cross_navigation_pending()); | 426 EXPECT_FALSE(contents()->cross_navigation_pending()); |
427 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 427 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
428 | 428 |
429 // Navigate to new site | 429 // Navigate to new site |
430 const GURL url2("http://www.yahoo.com"); | 430 const GURL url2("http://www.yahoo.com"); |
431 controller().LoadURL( | 431 controller().LoadURL( |
432 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 432 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
433 EXPECT_TRUE(contents()->cross_navigation_pending()); | 433 EXPECT_TRUE(contents()->cross_navigation_pending()); |
434 TestRenderViewHost* pending_rvh = | 434 TestRenderViewHost* pending_rvh = |
435 static_cast<TestRenderViewHost*>(contents()->pending_rvh()); | 435 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
436 int pending_rvh_delete_count = 0; | 436 int pending_rvh_delete_count = 0; |
437 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 437 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
438 | 438 |
439 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 439 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
440 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 440 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
441 orig_rvh->SendShouldCloseACK(true); | 441 orig_rvh->SendShouldCloseACK(true); |
442 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 442 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
443 | 443 |
444 // DidNavigate from the pending page | 444 // DidNavigate from the pending page |
445 contents()->TestDidNavigate( | 445 contents()->TestDidNavigate( |
446 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 446 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
447 SiteInstance* instance2 = contents()->GetSiteInstance(); | 447 SiteInstance* instance2 = contents()->GetSiteInstance(); |
448 | 448 |
449 EXPECT_FALSE(contents()->cross_navigation_pending()); | 449 EXPECT_FALSE(contents()->cross_navigation_pending()); |
450 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 450 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
451 EXPECT_NE(instance1, instance2); | 451 EXPECT_NE(instance1, instance2); |
452 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 452 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
453 // We keep the original RVH around, swapped out. | 453 // We keep the original RVH around, swapped out. |
454 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh)); | 454 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh)); |
455 EXPECT_EQ(orig_rvh_delete_count, 0); | 455 EXPECT_EQ(orig_rvh_delete_count, 0); |
456 | 456 |
457 // Going back should switch SiteInstances again. The first SiteInstance is | 457 // Going back should switch SiteInstances again. The first SiteInstance is |
458 // stored in the NavigationEntry, so it should be the same as at the start. | 458 // stored in the NavigationEntry, so it should be the same as at the start. |
459 // We should use the same RVH as before, swapping it back in. | 459 // We should use the same RVH as before, swapping it back in. |
460 controller().GoBack(); | 460 controller().GoBack(); |
461 TestRenderViewHost* goback_rvh = | 461 TestRenderViewHost* goback_rvh = |
462 static_cast<TestRenderViewHost*>(contents()->pending_rvh()); | 462 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
463 EXPECT_EQ(orig_rvh, goback_rvh); | 463 EXPECT_EQ(orig_rvh, goback_rvh); |
464 EXPECT_TRUE(contents()->cross_navigation_pending()); | 464 EXPECT_TRUE(contents()->cross_navigation_pending()); |
465 | 465 |
466 // Navigations should be suspended in goback_rvh until ShouldCloseACK. | 466 // Navigations should be suspended in goback_rvh until ShouldCloseACK. |
467 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); | 467 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); |
468 pending_rvh->SendShouldCloseACK(true); | 468 pending_rvh->SendShouldCloseACK(true); |
469 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); | 469 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); |
470 | 470 |
471 // DidNavigate from the back action | 471 // DidNavigate from the back action |
472 contents()->TestDidNavigate( | 472 contents()->TestDidNavigate( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 505 |
506 // Crash the renderer. | 506 // Crash the renderer. |
507 orig_rvh->set_render_view_created(false); | 507 orig_rvh->set_render_view_created(false); |
508 | 508 |
509 // Navigate to new site. We should not go into PENDING. | 509 // Navigate to new site. We should not go into PENDING. |
510 const GURL url2("http://www.yahoo.com"); | 510 const GURL url2("http://www.yahoo.com"); |
511 controller().LoadURL( | 511 controller().LoadURL( |
512 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 512 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
513 RenderViewHost* new_rvh = rvh(); | 513 RenderViewHost* new_rvh = rvh(); |
514 EXPECT_FALSE(contents()->cross_navigation_pending()); | 514 EXPECT_FALSE(contents()->cross_navigation_pending()); |
515 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 515 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
516 EXPECT_NE(orig_rvh, new_rvh); | 516 EXPECT_NE(orig_rvh, new_rvh); |
517 EXPECT_EQ(orig_rvh_delete_count, 1); | 517 EXPECT_EQ(orig_rvh_delete_count, 1); |
518 | 518 |
519 // DidNavigate from the new page | 519 // DidNavigate from the new page |
520 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 520 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
521 SiteInstance* instance2 = contents()->GetSiteInstance(); | 521 SiteInstance* instance2 = contents()->GetSiteInstance(); |
522 | 522 |
523 EXPECT_FALSE(contents()->cross_navigation_pending()); | 523 EXPECT_FALSE(contents()->cross_navigation_pending()); |
524 EXPECT_EQ(new_rvh, rvh()); | 524 EXPECT_EQ(new_rvh, rvh()); |
525 EXPECT_NE(instance1, instance2); | 525 EXPECT_NE(instance1, instance2); |
526 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 526 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
527 | 527 |
528 // Close tab and ensure RVHs are deleted. | 528 // Close tab and ensure RVHs are deleted. |
529 DeleteContents(); | 529 DeleteContents(); |
530 EXPECT_EQ(orig_rvh_delete_count, 1); | 530 EXPECT_EQ(orig_rvh_delete_count, 1); |
531 } | 531 } |
532 | 532 |
533 // Test that opening a new tab in the same SiteInstance and then navigating | 533 // Test that opening a new tab in the same SiteInstance and then navigating |
534 // both tabs to a new site will place both tabs in a single SiteInstance. | 534 // both tabs to a new site will place both tabs in a single SiteInstance. |
535 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { | 535 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { |
536 contents()->transition_cross_site = true; | 536 contents()->transition_cross_site = true; |
(...skipping 17 matching lines...) Expand all Loading... |
554 contents2.TestDidNavigate( | 554 contents2.TestDidNavigate( |
555 contents2.GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED); | 555 contents2.GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED); |
556 | 556 |
557 // Navigate first tab to a new site | 557 // Navigate first tab to a new site |
558 const GURL url2a("http://www.yahoo.com"); | 558 const GURL url2a("http://www.yahoo.com"); |
559 controller().LoadURL( | 559 controller().LoadURL( |
560 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 560 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, |
561 std::string()); | 561 std::string()); |
562 orig_rvh->SendShouldCloseACK(true); | 562 orig_rvh->SendShouldCloseACK(true); |
563 TestRenderViewHost* pending_rvh_a = | 563 TestRenderViewHost* pending_rvh_a = |
564 static_cast<TestRenderViewHost*>(contents()->pending_rvh()); | 564 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
565 contents()->TestDidNavigate( | 565 contents()->TestDidNavigate( |
566 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); | 566 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); |
567 SiteInstance* instance2a = contents()->GetSiteInstance(); | 567 SiteInstance* instance2a = contents()->GetSiteInstance(); |
568 EXPECT_NE(instance1, instance2a); | 568 EXPECT_NE(instance1, instance2a); |
569 | 569 |
570 // Navigate second tab to the same site as the first tab | 570 // Navigate second tab to the same site as the first tab |
571 const GURL url2b("http://mail.yahoo.com"); | 571 const GURL url2b("http://mail.yahoo.com"); |
572 contents2.GetController().LoadURL(url2b, content::Referrer(), | 572 contents2.GetController().LoadURL(url2b, content::Referrer(), |
573 content::PAGE_TRANSITION_TYPED, | 573 content::PAGE_TRANSITION_TYPED, |
574 std::string()); | 574 std::string()); |
575 TestRenderViewHost* rvh2 = | 575 TestRenderViewHost* rvh2 = |
576 static_cast<TestRenderViewHost*>(contents2.GetRenderViewHost()); | 576 static_cast<TestRenderViewHost*>(contents2.GetRenderViewHost()); |
577 rvh2->SendShouldCloseACK(true); | 577 rvh2->SendShouldCloseACK(true); |
578 TestRenderViewHost* pending_rvh_b = | 578 TestRenderViewHost* pending_rvh_b = |
579 static_cast<TestRenderViewHost*>(contents2.pending_rvh()); | 579 static_cast<TestRenderViewHost*>(contents2.GetPendingRenderViewHost()); |
580 EXPECT_TRUE(pending_rvh_b != NULL); | 580 EXPECT_TRUE(pending_rvh_b != NULL); |
581 EXPECT_TRUE(contents2.cross_navigation_pending()); | 581 EXPECT_TRUE(contents2.cross_navigation_pending()); |
582 | 582 |
583 // NOTE(creis): We used to be in danger of showing a sad tab page here if the | 583 // NOTE(creis): We used to be in danger of showing a sad tab page here if the |
584 // second tab hadn't navigated somewhere first (bug 1145430). That case is | 584 // second tab hadn't navigated somewhere first (bug 1145430). That case is |
585 // now covered by the CrossSiteBoundariesAfterCrash test. | 585 // now covered by the CrossSiteBoundariesAfterCrash test. |
586 contents2.TestDidNavigate( | 586 contents2.TestDidNavigate( |
587 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); | 587 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); |
588 SiteInstance* instance2b = contents2.GetSiteInstance(); | 588 SiteInstance* instance2b = contents2.GetSiteInstance(); |
589 EXPECT_NE(instance1, instance2b); | 589 EXPECT_NE(instance1, instance2b); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 656 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
657 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 657 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
658 EXPECT_FALSE(contents()->cross_navigation_pending()); | 658 EXPECT_FALSE(contents()->cross_navigation_pending()); |
659 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 659 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
660 | 660 |
661 // Navigate to new site, but simulate an onbeforeunload denial. | 661 // Navigate to new site, but simulate an onbeforeunload denial. |
662 const GURL url2("http://www.yahoo.com"); | 662 const GURL url2("http://www.yahoo.com"); |
663 controller().LoadURL( | 663 controller().LoadURL( |
664 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 664 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
665 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 665 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
666 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 666 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
667 0, false, base::TimeTicks(), base::TimeTicks())); | 667 0, false, base::TimeTicks(), base::TimeTicks())); |
668 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 668 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
669 EXPECT_FALSE(contents()->cross_navigation_pending()); | 669 EXPECT_FALSE(contents()->cross_navigation_pending()); |
670 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 670 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
671 | 671 |
672 // Navigate again, but simulate an onbeforeunload approval. | 672 // Navigate again, but simulate an onbeforeunload approval. |
673 controller().LoadURL( | 673 controller().LoadURL( |
674 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 674 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
675 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 675 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
676 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 676 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
677 0, true, base::TimeTicks(), base::TimeTicks())); | 677 0, true, base::TimeTicks(), base::TimeTicks())); |
678 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 678 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
679 EXPECT_TRUE(contents()->cross_navigation_pending()); | 679 EXPECT_TRUE(contents()->cross_navigation_pending()); |
680 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 680 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
681 contents()->pending_rvh()); | 681 contents()->GetPendingRenderViewHost()); |
682 | 682 |
683 // We won't hear DidNavigate until the onunload handler has finished running. | 683 // We won't hear DidNavigate until the onunload handler has finished running. |
684 // (No way to simulate that here, but it involves a call from RDH to | 684 // (No way to simulate that here, but it involves a call from RDH to |
685 // TabContents::OnCrossSiteResponse.) | 685 // TabContents::OnCrossSiteResponse.) |
686 | 686 |
687 // DidNavigate from the pending page | 687 // DidNavigate from the pending page |
688 contents()->TestDidNavigate( | 688 contents()->TestDidNavigate( |
689 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 689 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
690 SiteInstance* instance2 = contents()->GetSiteInstance(); | 690 SiteInstance* instance2 = contents()->GetSiteInstance(); |
691 EXPECT_FALSE(contents()->cross_navigation_pending()); | 691 EXPECT_FALSE(contents()->cross_navigation_pending()); |
692 EXPECT_EQ(pending_rvh, rvh()); | 692 EXPECT_EQ(pending_rvh, rvh()); |
693 EXPECT_NE(instance1, instance2); | 693 EXPECT_NE(instance1, instance2); |
694 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 694 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
695 } | 695 } |
696 | 696 |
697 // Test that during a slow cross-site navigation, the original renderer can | 697 // Test that during a slow cross-site navigation, the original renderer can |
698 // navigate to a different URL and have it displayed, canceling the slow | 698 // navigate to a different URL and have it displayed, canceling the slow |
699 // navigation. | 699 // navigation. |
700 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { | 700 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { |
701 contents()->transition_cross_site = true; | 701 contents()->transition_cross_site = true; |
702 TestRenderViewHost* orig_rvh = test_rvh(); | 702 TestRenderViewHost* orig_rvh = test_rvh(); |
703 SiteInstance* instance1 = contents()->GetSiteInstance(); | 703 SiteInstance* instance1 = contents()->GetSiteInstance(); |
704 | 704 |
705 // Navigate to URL. First URL should use first RenderViewHost. | 705 // Navigate to URL. First URL should use first RenderViewHost. |
706 const GURL url("http://www.google.com"); | 706 const GURL url("http://www.google.com"); |
707 controller().LoadURL( | 707 controller().LoadURL( |
708 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 708 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
709 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 709 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
710 EXPECT_FALSE(contents()->cross_navigation_pending()); | 710 EXPECT_FALSE(contents()->cross_navigation_pending()); |
711 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 711 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
712 | 712 |
713 // Navigate to new site, simulating an onbeforeunload approval. | 713 // Navigate to new site, simulating an onbeforeunload approval. |
714 const GURL url2("http://www.yahoo.com"); | 714 const GURL url2("http://www.yahoo.com"); |
715 controller().LoadURL( | 715 controller().LoadURL( |
716 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 716 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
717 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 717 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
718 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 718 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
719 0, true, base::TimeTicks(), base::TimeTicks())); | 719 0, true, base::TimeTicks(), base::TimeTicks())); |
720 EXPECT_TRUE(contents()->cross_navigation_pending()); | 720 EXPECT_TRUE(contents()->cross_navigation_pending()); |
721 | 721 |
722 // Suppose the original renderer navigates before the new one is ready. | 722 // Suppose the original renderer navigates before the new one is ready. |
723 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 723 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
724 | 724 |
725 // Verify that the pending navigation is cancelled. | 725 // Verify that the pending navigation is cancelled. |
726 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 726 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
727 SiteInstance* instance2 = contents()->GetSiteInstance(); | 727 SiteInstance* instance2 = contents()->GetSiteInstance(); |
728 EXPECT_FALSE(contents()->cross_navigation_pending()); | 728 EXPECT_FALSE(contents()->cross_navigation_pending()); |
729 EXPECT_EQ(orig_rvh, rvh()); | 729 EXPECT_EQ(orig_rvh, rvh()); |
730 EXPECT_EQ(instance1, instance2); | 730 EXPECT_EQ(instance1, instance2); |
731 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 731 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
732 } | 732 } |
733 | 733 |
734 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { | 734 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { |
735 contents()->transition_cross_site = true; | 735 contents()->transition_cross_site = true; |
736 | 736 |
737 // Start with a web ui page, which gets a new RVH with WebUI bindings. | 737 // Start with a web ui page, which gets a new RVH with WebUI bindings. |
738 const GURL url1("tabcontentstest://blah"); | 738 const GURL url1("tabcontentstest://blah"); |
739 controller().LoadURL( | 739 controller().LoadURL( |
740 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 740 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
741 TestRenderViewHost* ntp_rvh = test_rvh(); | 741 TestRenderViewHost* ntp_rvh = test_rvh(); |
742 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); | 742 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); |
743 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 743 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
744 SiteInstance* instance1 = contents()->GetSiteInstance(); | 744 SiteInstance* instance1 = contents()->GetSiteInstance(); |
745 | 745 |
746 EXPECT_FALSE(contents()->cross_navigation_pending()); | 746 EXPECT_FALSE(contents()->cross_navigation_pending()); |
747 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); | 747 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); |
748 EXPECT_EQ(url1, entry1->GetURL()); | 748 EXPECT_EQ(url1, entry1->GetURL()); |
749 EXPECT_EQ(instance1, | 749 EXPECT_EQ(instance1, |
750 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 750 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
751 EXPECT_TRUE(ntp_rvh->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); | 751 EXPECT_TRUE(ntp_rvh->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); |
752 | 752 |
753 // Navigate to new site. | 753 // Navigate to new site. |
754 const GURL url2("http://www.google.com"); | 754 const GURL url2("http://www.google.com"); |
755 controller().LoadURL( | 755 controller().LoadURL( |
756 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 756 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
757 EXPECT_TRUE(contents()->cross_navigation_pending()); | 757 EXPECT_TRUE(contents()->cross_navigation_pending()); |
758 TestRenderViewHost* google_rvh = | 758 TestRenderViewHost* google_rvh = |
759 static_cast<TestRenderViewHost*>(contents()->pending_rvh()); | 759 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
760 | 760 |
761 // Simulate beforeunload approval. | 761 // Simulate beforeunload approval. |
762 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); | 762 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); |
763 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 763 ntp_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
764 0, true, base::TimeTicks(), base::TimeTicks())); | 764 0, true, base::TimeTicks(), base::TimeTicks())); |
765 | 765 |
766 // DidNavigate from the pending page. | 766 // DidNavigate from the pending page. |
767 contents()->TestDidNavigate( | 767 contents()->TestDidNavigate( |
768 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 768 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
769 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); | 769 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
770 SiteInstance* instance2 = contents()->GetSiteInstance(); | 770 SiteInstance* instance2 = contents()->GetSiteInstance(); |
771 | 771 |
772 EXPECT_FALSE(contents()->cross_navigation_pending()); | 772 EXPECT_FALSE(contents()->cross_navigation_pending()); |
773 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 773 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
774 EXPECT_NE(instance1, instance2); | 774 EXPECT_NE(instance1, instance2); |
775 EXPECT_FALSE(contents()->pending_rvh()); | 775 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); |
776 EXPECT_EQ(url2, entry2->GetURL()); | 776 EXPECT_EQ(url2, entry2->GetURL()); |
777 EXPECT_EQ(instance2, | 777 EXPECT_EQ(instance2, |
778 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); | 778 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); |
779 EXPECT_FALSE(google_rvh->GetEnabledBindings() & | 779 EXPECT_FALSE(google_rvh->GetEnabledBindings() & |
780 content::BINDINGS_POLICY_WEB_UI); | 780 content::BINDINGS_POLICY_WEB_UI); |
781 | 781 |
782 // Navigate to third page on same site. | 782 // Navigate to third page on same site. |
783 const GURL url3("http://news.google.com"); | 783 const GURL url3("http://news.google.com"); |
784 controller().LoadURL( | 784 controller().LoadURL( |
785 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 785 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
786 EXPECT_FALSE(contents()->cross_navigation_pending()); | 786 EXPECT_FALSE(contents()->cross_navigation_pending()); |
787 contents()->TestDidNavigate( | 787 contents()->TestDidNavigate( |
788 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED); | 788 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED); |
789 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 789 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
790 SiteInstance* instance3 = contents()->GetSiteInstance(); | 790 SiteInstance* instance3 = contents()->GetSiteInstance(); |
791 | 791 |
792 EXPECT_FALSE(contents()->cross_navigation_pending()); | 792 EXPECT_FALSE(contents()->cross_navigation_pending()); |
793 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 793 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
794 EXPECT_EQ(instance2, instance3); | 794 EXPECT_EQ(instance2, instance3); |
795 EXPECT_FALSE(contents()->pending_rvh()); | 795 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); |
796 EXPECT_EQ(url3, entry3->GetURL()); | 796 EXPECT_EQ(url3, entry3->GetURL()); |
797 EXPECT_EQ(instance3, | 797 EXPECT_EQ(instance3, |
798 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 798 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
799 | 799 |
800 // Go back within the site. | 800 // Go back within the site. |
801 controller().GoBack(); | 801 controller().GoBack(); |
802 EXPECT_FALSE(contents()->cross_navigation_pending()); | 802 EXPECT_FALSE(contents()->cross_navigation_pending()); |
803 EXPECT_EQ(entry2, controller().GetPendingEntry()); | 803 EXPECT_EQ(entry2, controller().GetPendingEntry()); |
804 | 804 |
805 // Before that commits, go back again. | 805 // Before that commits, go back again. |
806 controller().GoBack(); | 806 controller().GoBack(); |
807 EXPECT_TRUE(contents()->cross_navigation_pending()); | 807 EXPECT_TRUE(contents()->cross_navigation_pending()); |
808 EXPECT_TRUE(contents()->pending_rvh()); | 808 EXPECT_TRUE(contents()->GetPendingRenderViewHost()); |
809 EXPECT_EQ(entry1, controller().GetPendingEntry()); | 809 EXPECT_EQ(entry1, controller().GetPendingEntry()); |
810 | 810 |
811 // Simulate beforeunload approval. | 811 // Simulate beforeunload approval. |
812 EXPECT_TRUE(google_rvh->is_waiting_for_beforeunload_ack()); | 812 EXPECT_TRUE(google_rvh->is_waiting_for_beforeunload_ack()); |
813 google_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 813 google_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
814 0, true, base::TimeTicks(), base::TimeTicks())); | 814 0, true, base::TimeTicks(), base::TimeTicks())); |
815 | 815 |
816 // DidNavigate from the first back. This aborts the second back's pending RVH. | 816 // DidNavigate from the first back. This aborts the second back's pending RVH. |
817 contents()->TestDidNavigate( | 817 contents()->TestDidNavigate( |
818 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 818 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
819 | 819 |
820 // We should commit this page and forget about the second back. | 820 // We should commit this page and forget about the second back. |
821 EXPECT_FALSE(contents()->cross_navigation_pending()); | 821 EXPECT_FALSE(contents()->cross_navigation_pending()); |
822 EXPECT_FALSE(controller().GetPendingEntry()); | 822 EXPECT_FALSE(controller().GetPendingEntry()); |
823 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 823 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
(...skipping 29 matching lines...) Expand all Loading... |
853 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 853 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
854 | 854 |
855 // Simulate a sub-frame navigation arriving and ensure the RVH is still | 855 // Simulate a sub-frame navigation arriving and ensure the RVH is still |
856 // waiting for a before unload response. | 856 // waiting for a before unload response. |
857 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), | 857 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), |
858 content::PAGE_TRANSITION_AUTO_SUBFRAME); | 858 content::PAGE_TRANSITION_AUTO_SUBFRAME); |
859 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 859 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
860 | 860 |
861 // Now simulate the onbeforeunload approval and verify the navigation is | 861 // Now simulate the onbeforeunload approval and verify the navigation is |
862 // not canceled. | 862 // not canceled. |
863 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 863 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
864 0, true, base::TimeTicks(), base::TimeTicks())); | 864 0, true, base::TimeTicks(), base::TimeTicks())); |
865 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 865 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
866 EXPECT_TRUE(contents()->cross_navigation_pending()); | 866 EXPECT_TRUE(contents()->cross_navigation_pending()); |
867 } | 867 } |
868 | 868 |
869 // Test that a cross-site navigation is not preempted if the previous | 869 // Test that a cross-site navigation is not preempted if the previous |
870 // renderer sends a FrameNavigate message just before being told to stop. | 870 // renderer sends a FrameNavigate message just before being told to stop. |
871 // We should only preempt the cross-site navigation if the previous renderer | 871 // We should only preempt the cross-site navigation if the previous renderer |
872 // has started a new navigation. See http://crbug.com/79176. | 872 // has started a new navigation. See http://crbug.com/79176. |
873 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) { | 873 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) { |
874 contents()->transition_cross_site = true; | 874 contents()->transition_cross_site = true; |
875 | 875 |
876 // Navigate to NTP URL. | 876 // Navigate to NTP URL. |
877 const GURL url("tabcontentstest://blah"); | 877 const GURL url("tabcontentstest://blah"); |
878 controller().LoadURL( | 878 controller().LoadURL( |
879 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 879 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
880 TestRenderViewHost* orig_rvh = test_rvh(); | 880 TestRenderViewHost* orig_rvh = test_rvh(); |
881 EXPECT_FALSE(contents()->cross_navigation_pending()); | 881 EXPECT_FALSE(contents()->cross_navigation_pending()); |
882 | 882 |
883 // Navigate to new site, with the beforeunload request in flight. | 883 // Navigate to new site, with the beforeunload request in flight. |
884 const GURL url2("http://www.yahoo.com"); | 884 const GURL url2("http://www.yahoo.com"); |
885 controller().LoadURL( | 885 controller().LoadURL( |
886 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 886 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
887 TestRenderViewHost* pending_rvh = | 887 TestRenderViewHost* pending_rvh = |
888 static_cast<TestRenderViewHost*>(contents()->pending_rvh()); | 888 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
889 EXPECT_TRUE(contents()->cross_navigation_pending()); | 889 EXPECT_TRUE(contents()->cross_navigation_pending()); |
890 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 890 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
891 | 891 |
892 // Suppose the first navigation tries to commit now, with a | 892 // Suppose the first navigation tries to commit now, with a |
893 // ViewMsg_Stop in flight. This should not cancel the pending navigation, | 893 // ViewMsg_Stop in flight. This should not cancel the pending navigation, |
894 // but it should act as if the beforeunload ack arrived. | 894 // but it should act as if the beforeunload ack arrived. |
895 orig_rvh->SendNavigate(1, GURL("tabcontentstest://blah")); | 895 orig_rvh->SendNavigate(1, GURL("tabcontentstest://blah")); |
896 EXPECT_TRUE(contents()->cross_navigation_pending()); | 896 EXPECT_TRUE(contents()->cross_navigation_pending()); |
897 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 897 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
898 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 898 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
(...skipping 19 matching lines...) Expand all Loading... |
918 controller().LoadURL( | 918 controller().LoadURL( |
919 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 919 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
920 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 920 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
921 EXPECT_FALSE(contents()->cross_navigation_pending()); | 921 EXPECT_FALSE(contents()->cross_navigation_pending()); |
922 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 922 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
923 | 923 |
924 // Navigate to new site, simulating an onbeforeunload approval. | 924 // Navigate to new site, simulating an onbeforeunload approval. |
925 const GURL url2("http://www.yahoo.com"); | 925 const GURL url2("http://www.yahoo.com"); |
926 controller().LoadURL( | 926 controller().LoadURL( |
927 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 927 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
928 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 928 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
929 0, true, base::TimeTicks(), base::TimeTicks())); | 929 0, true, base::TimeTicks(), base::TimeTicks())); |
930 EXPECT_TRUE(contents()->cross_navigation_pending()); | 930 EXPECT_TRUE(contents()->cross_navigation_pending()); |
931 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 931 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
932 contents()->pending_rvh()); | 932 contents()->GetPendingRenderViewHost()); |
933 | 933 |
934 // Simulate the pending renderer's response, which leads to an unload request | 934 // Simulate the pending renderer's response, which leads to an unload request |
935 // being sent to orig_rvh. | 935 // being sent to orig_rvh. |
936 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse(0, 0); | 936 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse(0, 0); |
937 | 937 |
938 // Suppose the original renderer navigates now, while the unload request is in | 938 // Suppose the original renderer navigates now, while the unload request is in |
939 // flight. We should ignore it, wait for the unload ack, and let the pending | 939 // flight. We should ignore it, wait for the unload ack, and let the pending |
940 // request continue. Otherwise, the tab may close spontaneously or stop | 940 // request continue. Otherwise, the tab may close spontaneously or stop |
941 // responding to navigation requests. (See bug 23942.) | 941 // responding to navigation requests. (See bug 23942.) |
942 ViewHostMsg_FrameNavigate_Params params1a; | 942 ViewHostMsg_FrameNavigate_Params params1a; |
943 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), | 943 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), |
944 content::PAGE_TRANSITION_TYPED); | 944 content::PAGE_TRANSITION_TYPED); |
945 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 945 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
946 | 946 |
947 // Verify that the pending navigation is still in progress. | 947 // Verify that the pending navigation is still in progress. |
948 EXPECT_TRUE(contents()->cross_navigation_pending()); | 948 EXPECT_TRUE(contents()->cross_navigation_pending()); |
949 EXPECT_TRUE(contents()->pending_rvh() != NULL); | 949 EXPECT_TRUE(contents()->GetPendingRenderViewHost() != NULL); |
950 | 950 |
951 // DidNavigate from the pending page should commit it. | 951 // DidNavigate from the pending page should commit it. |
952 contents()->TestDidNavigate( | 952 contents()->TestDidNavigate( |
953 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 953 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); |
954 SiteInstance* instance2 = contents()->GetSiteInstance(); | 954 SiteInstance* instance2 = contents()->GetSiteInstance(); |
955 EXPECT_FALSE(contents()->cross_navigation_pending()); | 955 EXPECT_FALSE(contents()->cross_navigation_pending()); |
956 EXPECT_EQ(pending_rvh, rvh()); | 956 EXPECT_EQ(pending_rvh, rvh()); |
957 EXPECT_NE(instance1, instance2); | 957 EXPECT_NE(instance1, instance2); |
958 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 958 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
959 } | 959 } |
960 | 960 |
961 // Test that a cross-site navigation that doesn't commit after the unload | 961 // Test that a cross-site navigation that doesn't commit after the unload |
962 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. | 962 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. |
963 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { | 963 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { |
964 contents()->transition_cross_site = true; | 964 contents()->transition_cross_site = true; |
965 TestRenderViewHost* orig_rvh = test_rvh(); | 965 TestRenderViewHost* orig_rvh = test_rvh(); |
966 SiteInstance* instance1 = contents()->GetSiteInstance(); | 966 SiteInstance* instance1 = contents()->GetSiteInstance(); |
967 | 967 |
968 // Navigate to URL. First URL should use first RenderViewHost. | 968 // Navigate to URL. First URL should use first RenderViewHost. |
969 const GURL url("http://www.google.com"); | 969 const GURL url("http://www.google.com"); |
970 controller().LoadURL( | 970 controller().LoadURL( |
971 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 971 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
972 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 972 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); |
973 EXPECT_FALSE(contents()->cross_navigation_pending()); | 973 EXPECT_FALSE(contents()->cross_navigation_pending()); |
974 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 974 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
975 | 975 |
976 // Navigate to new site, simulating an onbeforeunload approval. | 976 // Navigate to new site, simulating an onbeforeunload approval. |
977 const GURL url2("http://www.yahoo.com"); | 977 const GURL url2("http://www.yahoo.com"); |
978 controller().LoadURL( | 978 controller().LoadURL( |
979 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 979 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
980 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 980 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
981 orig_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 981 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
982 0, true, base::TimeTicks(), base::TimeTicks())); | 982 0, true, base::TimeTicks(), base::TimeTicks())); |
983 EXPECT_TRUE(contents()->cross_navigation_pending()); | 983 EXPECT_TRUE(contents()->cross_navigation_pending()); |
984 | 984 |
985 // Simulate swap out message when the response arrives. | 985 // Simulate swap out message when the response arrives. |
986 orig_rvh->set_is_swapped_out(true); | 986 orig_rvh->set_is_swapped_out(true); |
987 | 987 |
988 // Suppose the navigation doesn't get a chance to commit, and the user | 988 // Suppose the navigation doesn't get a chance to commit, and the user |
989 // navigates in the current RVH's SiteInstance. | 989 // navigates in the current RVH's SiteInstance. |
990 controller().LoadURL( | 990 controller().LoadURL( |
991 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 991 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
992 | 992 |
993 // Verify that the pending navigation is cancelled and the renderer is no | 993 // Verify that the pending navigation is cancelled and the renderer is no |
994 // longer swapped out. | 994 // longer swapped out. |
995 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 995 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
996 SiteInstance* instance2 = contents()->GetSiteInstance(); | 996 SiteInstance* instance2 = contents()->GetSiteInstance(); |
997 EXPECT_FALSE(contents()->cross_navigation_pending()); | 997 EXPECT_FALSE(contents()->cross_navigation_pending()); |
998 EXPECT_EQ(orig_rvh, rvh()); | 998 EXPECT_EQ(orig_rvh, rvh()); |
999 EXPECT_FALSE(orig_rvh->is_swapped_out()); | 999 EXPECT_FALSE(orig_rvh->is_swapped_out()); |
1000 EXPECT_EQ(instance1, instance2); | 1000 EXPECT_EQ(instance1, instance2); |
1001 EXPECT_TRUE(contents()->pending_rvh() == NULL); | 1001 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
1002 } | 1002 } |
1003 | 1003 |
1004 // Test that NavigationEntries have the correct content state after going | 1004 // Test that NavigationEntries have the correct content state after going |
1005 // forward and back. Prevents regression for bug 1116137. | 1005 // forward and back. Prevents regression for bug 1116137. |
1006 TEST_F(TabContentsTest, NavigationEntryContentState) { | 1006 TEST_F(TabContentsTest, NavigationEntryContentState) { |
1007 TestRenderViewHost* orig_rvh = test_rvh(); | 1007 TestRenderViewHost* orig_rvh = test_rvh(); |
1008 | 1008 |
1009 // Navigate to URL. There should be no committed entry yet. | 1009 // Navigate to URL. There should be no committed entry yet. |
1010 const GURL url("http://www.google.com"); | 1010 const GURL url("http://www.google.com"); |
1011 controller().LoadURL( | 1011 controller().LoadURL( |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 bool deleted = false; | 1443 bool deleted = false; |
1444 GURL interstitial_url("http://interstitial"); | 1444 GURL interstitial_url("http://interstitial"); |
1445 TestInterstitialPage* interstitial = | 1445 TestInterstitialPage* interstitial = |
1446 new TestInterstitialPage(contents(), true, interstitial_url, | 1446 new TestInterstitialPage(contents(), true, interstitial_url, |
1447 &state, &deleted); | 1447 &state, &deleted); |
1448 TestInterstitialPageStateGuard state_guard(interstitial); | 1448 TestInterstitialPageStateGuard state_guard(interstitial); |
1449 interstitial->Show(); | 1449 interstitial->Show(); |
1450 interstitial->TestDidNavigate(2, interstitial_url); | 1450 interstitial->TestDidNavigate(2, interstitial_url); |
1451 | 1451 |
1452 // Crash the renderer | 1452 // Crash the renderer |
1453 test_rvh()->TestOnMessageReceived( | 1453 test_rvh()->OnMessageReceived( |
1454 ViewHostMsg_RenderViewGone( | 1454 ViewHostMsg_RenderViewGone( |
1455 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); | 1455 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); |
1456 | 1456 |
1457 // While the interstitial is showing, go back. | 1457 // While the interstitial is showing, go back. |
1458 controller().GoBack(); | 1458 controller().GoBack(); |
1459 test_rvh()->SendNavigate(1, url1); | 1459 test_rvh()->SendNavigate(1, url1); |
1460 | 1460 |
1461 // Make sure we are back to the original page and that the interstitial is | 1461 // Make sure we are back to the original page and that the interstitial is |
1462 // gone. | 1462 // gone. |
1463 EXPECT_TRUE(deleted); | 1463 EXPECT_TRUE(deleted); |
(...skipping 16 matching lines...) Expand all Loading... |
1480 TestInterstitialPage::UNDECIDED; | 1480 TestInterstitialPage::UNDECIDED; |
1481 bool deleted = false; | 1481 bool deleted = false; |
1482 GURL interstitial_url("http://interstitial"); | 1482 GURL interstitial_url("http://interstitial"); |
1483 TestInterstitialPage* interstitial = | 1483 TestInterstitialPage* interstitial = |
1484 new TestInterstitialPage(contents(), true, interstitial_url, | 1484 new TestInterstitialPage(contents(), true, interstitial_url, |
1485 &state, &deleted); | 1485 &state, &deleted); |
1486 TestInterstitialPageStateGuard state_guard(interstitial); | 1486 TestInterstitialPageStateGuard state_guard(interstitial); |
1487 interstitial->Show(); | 1487 interstitial->Show(); |
1488 | 1488 |
1489 // Crash the renderer | 1489 // Crash the renderer |
1490 test_rvh()->TestOnMessageReceived( | 1490 test_rvh()->OnMessageReceived( |
1491 ViewHostMsg_RenderViewGone( | 1491 ViewHostMsg_RenderViewGone( |
1492 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); | 1492 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); |
1493 | 1493 |
1494 interstitial->TestDidNavigate(2, interstitial_url); | 1494 interstitial->TestDidNavigate(2, interstitial_url); |
1495 } | 1495 } |
1496 | 1496 |
1497 // Test navigating to a page that shows an interstitial, then close the tab. | 1497 // Test navigating to a page that shows an interstitial, then close the tab. |
1498 TEST_F(TabContentsTest, ShowInterstitialThenCloseTab) { | 1498 TEST_F(TabContentsTest, ShowInterstitialThenCloseTab) { |
1499 // Show interstitial. | 1499 // Show interstitial. |
1500 TestInterstitialPage::InterstitialState state = | 1500 TestInterstitialPage::InterstitialState state = |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 // It should have a transient entry. | 1927 // It should have a transient entry. |
1928 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1928 EXPECT_TRUE(other_controller.GetTransientEntry()); |
1929 | 1929 |
1930 // And the interstitial should be showing. | 1930 // And the interstitial should be showing. |
1931 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); | 1931 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); |
1932 | 1932 |
1933 // And the interstitial should do a reload on don't proceed. | 1933 // And the interstitial should do a reload on don't proceed. |
1934 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( | 1934 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( |
1935 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); | 1935 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); |
1936 } | 1936 } |
OLD | NEW |