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

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

Issue 789643005: PlzNavigate: make content unit tests work with browser side navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cancel-navigations
Patch Set: Created 5 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
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/command_line.h"
5 #include "base/logging.h" 6 #include "base/logging.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/frame_host/cross_site_transferring_request.h" 8 #include "content/browser/frame_host/cross_site_transferring_request.h"
8 #include "content/browser/frame_host/interstitial_page_impl.h" 9 #include "content/browser/frame_host/interstitial_page_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/media/audio_stream_monitor.h" 11 #include "content/browser/media/audio_stream_monitor.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h" 12 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/site_instance_impl.h" 13 #include "content/browser/site_instance_impl.h"
13 #include "content/browser/webui/web_ui_controller_factory_registry.h" 14 #include "content/browser/webui/web_ui_controller_factory_registry.h"
14 #include "content/common/frame_messages.h" 15 #include "content/common/frame_messages.h"
15 #include "content/common/input/synthetic_web_input_event_builders.h" 16 #include "content/common/input/synthetic_web_input_event_builders.h"
16 #include "content/common/view_messages.h" 17 #include "content/common/view_messages.h"
17 #include "content/public/browser/global_request_id.h" 18 #include "content/public/browser/global_request_id.h"
18 #include "content/public/browser/interstitial_page_delegate.h" 19 #include "content/public/browser/interstitial_page_delegate.h"
19 #include "content/public/browser/navigation_details.h" 20 #include "content/public/browser/navigation_details.h"
20 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_source.h" 22 #include "content/public/browser/notification_source.h"
22 #include "content/public/browser/render_widget_host_view.h" 23 #include "content/public/browser/render_widget_host_view.h"
23 #include "content/public/browser/web_contents_delegate.h" 24 #include "content/public/browser/web_contents_delegate.h"
24 #include "content/public/browser/web_contents_observer.h" 25 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/browser/web_ui_controller.h" 26 #include "content/public/browser/web_ui_controller.h"
26 #include "content/public/common/bindings_policy.h" 27 #include "content/public/common/bindings_policy.h"
27 #include "content/public/common/content_constants.h" 28 #include "content/public/common/content_constants.h"
29 #include "content/public/common/content_switches.h"
28 #include "content/public/common/url_constants.h" 30 #include "content/public/common/url_constants.h"
29 #include "content/public/common/url_utils.h" 31 #include "content/public/common/url_utils.h"
30 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
31 #include "content/public/test/test_utils.h" 33 #include "content/public/test/test_utils.h"
32 #include "content/test/test_content_browser_client.h" 34 #include "content/test/test_content_browser_client.h"
33 #include "content/test/test_content_client.h" 35 #include "content/test/test_content_client.h"
34 #include "content/test/test_render_frame_host.h" 36 #include "content/test/test_render_frame_host.h"
35 #include "content/test/test_render_view_host.h" 37 #include "content/test/test_render_view_host.h"
36 #include "content/test/test_web_contents.h" 38 #include "content/test/test_web_contents.h"
37 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { 471 TEST_F(WebContentsImplTest, CrossSiteBoundaries) {
470 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 472 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
471 int orig_rvh_delete_count = 0; 473 int orig_rvh_delete_count = 0;
472 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 474 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
473 SiteInstance* instance1 = contents()->GetSiteInstance(); 475 SiteInstance* instance1 = contents()->GetSiteInstance();
474 476
475 // Navigate to URL. First URL should use first RenderViewHost. 477 // Navigate to URL. First URL should use first RenderViewHost.
476 const GURL url("http://www.google.com"); 478 const GURL url("http://www.google.com");
477 controller().LoadURL( 479 controller().LoadURL(
478 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 480 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
481 orig_rfh->PrepareForCommit(url);
479 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 482 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
480 483
481 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so 484 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so
482 // that orig_rfh doesn't get deleted when it gets swapped out. 485 // that orig_rfh doesn't get deleted when it gets swapped out.
483 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 486 orig_rfh->GetSiteInstance()->increment_active_frame_count();
484 487
485 EXPECT_FALSE(contents()->cross_navigation_pending()); 488 EXPECT_FALSE(contents()->cross_navigation_pending());
486 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 489 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
487 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 490 EXPECT_EQ(url, contents()->GetLastCommittedURL());
488 EXPECT_EQ(url, contents()->GetVisibleURL()); 491 EXPECT_EQ(url, contents()->GetVisibleURL());
489 492
490 // Navigate to new site 493 // Navigate to new site
491 const GURL url2("http://www.yahoo.com"); 494 const GURL url2("http://www.yahoo.com");
492 controller().LoadURL( 495 controller().LoadURL(
493 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 496 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
497 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
498 switches::kEnableBrowserSideNavigation)) {
499 orig_rfh->PrepareForCommit(url2);
500 }
494 EXPECT_TRUE(contents()->cross_navigation_pending()); 501 EXPECT_TRUE(contents()->cross_navigation_pending());
495 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 502 EXPECT_EQ(url, contents()->GetLastCommittedURL());
496 EXPECT_EQ(url2, contents()->GetVisibleURL()); 503 EXPECT_EQ(url2, contents()->GetVisibleURL());
497 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 504 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
498 int pending_rvh_delete_count = 0; 505 int pending_rvh_delete_count = 0;
499 pending_rfh->GetRenderViewHost()->set_delete_counter( 506 pending_rfh->GetRenderViewHost()->set_delete_counter(
500 &pending_rvh_delete_count); 507 &pending_rvh_delete_count);
501 508
502 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. 509 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
503 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 510 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
504 orig_rfh->SendBeforeUnloadACK(true); 511 switches::kEnableBrowserSideNavigation)) {
505 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 512 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
513 orig_rfh->SendBeforeUnloadACK(true);
514 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
515 }
506 516
507 // DidNavigate from the pending page 517 // DidNavigate from the pending page
508 contents()->TestDidNavigate( 518 contents()->TestDidNavigate(
509 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 519 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
510 SiteInstance* instance2 = contents()->GetSiteInstance(); 520 SiteInstance* instance2 = contents()->GetSiteInstance();
511 521
512 // Keep the number of active frames in pending_rfh's SiteInstance 522 // Keep the number of active frames in pending_rfh's SiteInstance
513 // non-zero so that orig_rfh doesn't get deleted when it gets 523 // non-zero so that orig_rfh doesn't get deleted when it gets
514 // swapped out. 524 // swapped out.
515 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 525 pending_rfh->GetSiteInstance()->increment_active_frame_count();
516 526
517 EXPECT_FALSE(contents()->cross_navigation_pending()); 527 EXPECT_FALSE(contents()->cross_navigation_pending());
518 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 528 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
519 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 529 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
520 EXPECT_EQ(url2, contents()->GetVisibleURL()); 530 EXPECT_EQ(url2, contents()->GetVisibleURL());
521 EXPECT_NE(instance1, instance2); 531 EXPECT_NE(instance1, instance2);
522 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 532 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
523 // We keep the original RFH around, swapped out. 533 // We keep the original RFH around, swapped out.
524 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 534 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
525 orig_rfh)); 535 orig_rfh));
526 EXPECT_EQ(orig_rvh_delete_count, 0); 536 EXPECT_EQ(orig_rvh_delete_count, 0);
527 537
528 // Going back should switch SiteInstances again. The first SiteInstance is 538 // Going back should switch SiteInstances again. The first SiteInstance is
529 // stored in the NavigationEntry, so it should be the same as at the start. 539 // stored in the NavigationEntry, so it should be the same as at the start.
530 // We should use the same RFH as before, swapping it back in. 540 // We should use the same RFH as before, swapping it back in.
531 controller().GoBack(); 541 controller().GoBack();
542 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
543 switches::kEnableBrowserSideNavigation)) {
544 contents()->GetMainFrame()->PrepareForCommit(url);
545 }
532 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); 546 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame();
533 EXPECT_EQ(orig_rfh, goback_rfh); 547 EXPECT_EQ(orig_rfh, goback_rfh);
534 EXPECT_TRUE(contents()->cross_navigation_pending()); 548 EXPECT_TRUE(contents()->cross_navigation_pending());
535 549
536 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. 550 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
537 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); 551 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
538 pending_rfh->SendBeforeUnloadACK(true); 552 switches::kEnableBrowserSideNavigation)) {
539 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); 553 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
554 pending_rfh->SendBeforeUnloadACK(true);
555 EXPECT_FALSE(goback_rfh->are_navigations_suspended());
556 }
540 557
541 // DidNavigate from the back action 558 // DidNavigate from the back action
542 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 559 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
543 EXPECT_FALSE(contents()->cross_navigation_pending()); 560 EXPECT_FALSE(contents()->cross_navigation_pending());
544 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); 561 EXPECT_EQ(goback_rfh, contents()->GetMainFrame());
545 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 562 EXPECT_EQ(instance1, contents()->GetSiteInstance());
546 // The pending RFH should now be swapped out, not deleted. 563 // The pending RFH should now be swapped out, not deleted.
547 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 564 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
548 IsOnSwappedOutList(pending_rfh)); 565 IsOnSwappedOutList(pending_rfh));
549 EXPECT_EQ(pending_rvh_delete_count, 0); 566 EXPECT_EQ(pending_rvh_delete_count, 0);
(...skipping 11 matching lines...) Expand all
561 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 578 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
562 579
563 int orig_rvh_delete_count = 0; 580 int orig_rvh_delete_count = 0;
564 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 581 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
565 SiteInstance* instance1 = contents()->GetSiteInstance(); 582 SiteInstance* instance1 = contents()->GetSiteInstance();
566 583
567 // Navigate to URL. First URL should use first RenderViewHost. 584 // Navigate to URL. First URL should use first RenderViewHost.
568 const GURL url("http://www.google.com"); 585 const GURL url("http://www.google.com");
569 controller().LoadURL( 586 controller().LoadURL(
570 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 587 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
588 contents()->GetMainFrame()->PrepareForCommit(url);
571 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 589 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
572 590
573 EXPECT_FALSE(contents()->cross_navigation_pending()); 591 EXPECT_FALSE(contents()->cross_navigation_pending());
574 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 592 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
575 593
576 // Simulate a renderer crash. 594 // Simulate a renderer crash.
577 orig_rfh->GetRenderViewHost()->set_render_view_created(false); 595 orig_rfh->GetRenderViewHost()->set_render_view_created(false);
578 orig_rfh->set_render_frame_created(false); 596 orig_rfh->set_render_frame_created(false);
579 597
580 // Navigate to new site. We should not go into PENDING. 598 // Navigate to new site. We should not go into PENDING.
581 const GURL url2("http://www.yahoo.com"); 599 const GURL url2("http://www.yahoo.com");
582 controller().LoadURL( 600 controller().LoadURL(
583 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 601 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
602 contents()->GetMainFrame()->PrepareForCommit(url2);
584 TestRenderFrameHost* new_rfh = contents()->GetMainFrame(); 603 TestRenderFrameHost* new_rfh = contents()->GetMainFrame();
585 EXPECT_FALSE(contents()->cross_navigation_pending()); 604 EXPECT_FALSE(contents()->cross_navigation_pending());
586 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 605 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
587 EXPECT_NE(orig_rfh, new_rfh); 606 EXPECT_NE(orig_rfh, new_rfh);
588 EXPECT_EQ(orig_rvh_delete_count, 1); 607 EXPECT_EQ(orig_rvh_delete_count, 1);
589 608
590 // DidNavigate from the new page 609 // DidNavigate from the new page
591 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 610 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
592 SiteInstance* instance2 = contents()->GetSiteInstance(); 611 SiteInstance* instance2 = contents()->GetSiteInstance();
593 612
(...skipping 11 matching lines...) Expand all
605 // both contentses to a new site will place both contentses in a single 624 // both contentses to a new site will place both contentses in a single
606 // SiteInstance. 625 // SiteInstance.
607 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { 626 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) {
608 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 627 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
609 SiteInstance* instance1 = contents()->GetSiteInstance(); 628 SiteInstance* instance1 = contents()->GetSiteInstance();
610 629
611 // Navigate to URL. First URL should use first RenderViewHost. 630 // Navigate to URL. First URL should use first RenderViewHost.
612 const GURL url("http://www.google.com"); 631 const GURL url("http://www.google.com");
613 controller().LoadURL( 632 controller().LoadURL(
614 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 633 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
634 contents()->GetMainFrame()->PrepareForCommit(url);
615 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 635 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
616 636
617 // Open a new contents with the same SiteInstance, navigated to the same site. 637 // Open a new contents with the same SiteInstance, navigated to the same site.
618 scoped_ptr<TestWebContents> contents2( 638 scoped_ptr<TestWebContents> contents2(
619 TestWebContents::Create(browser_context(), instance1)); 639 TestWebContents::Create(browser_context(), instance1));
620 contents2->GetController().LoadURL(url, Referrer(), 640 contents2->GetController().LoadURL(url, Referrer(),
621 ui::PAGE_TRANSITION_TYPED, 641 ui::PAGE_TRANSITION_TYPED,
622 std::string()); 642 std::string());
643 contents2->GetMainFrame()->PrepareForCommit(url);
623 // Need this page id to be 2 since the site instance is the same (which is the 644 // Need this page id to be 2 since the site instance is the same (which is the
624 // scope of page IDs) and we want to consider this a new page. 645 // scope of page IDs) and we want to consider this a new page.
625 contents2->TestDidNavigate( 646 contents2->TestDidNavigate(
626 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 647 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED);
627 648
628 // Navigate first contents to a new site. 649 // Navigate first contents to a new site.
629 const GURL url2a("http://www.yahoo.com"); 650 const GURL url2a("http://www.yahoo.com");
630 controller().LoadURL( 651 controller().LoadURL(
631 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 652 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
632 orig_rfh->SendBeforeUnloadACK(true); 653 orig_rfh->PrepareForCommit(url2a);
633 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame(); 654 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame();
634 contents()->TestDidNavigate( 655 contents()->TestDidNavigate(
635 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED); 656 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED);
636 SiteInstance* instance2a = contents()->GetSiteInstance(); 657 SiteInstance* instance2a = contents()->GetSiteInstance();
637 EXPECT_NE(instance1, instance2a); 658 EXPECT_NE(instance1, instance2a);
638 659
639 // Navigate second contents to the same site as the first tab. 660 // Navigate second contents to the same site as the first tab.
640 const GURL url2b("http://mail.yahoo.com"); 661 const GURL url2b("http://mail.yahoo.com");
641 contents2->GetController().LoadURL(url2b, Referrer(), 662 contents2->GetController().LoadURL(url2b, Referrer(),
642 ui::PAGE_TRANSITION_TYPED, 663 ui::PAGE_TRANSITION_TYPED,
643 std::string()); 664 std::string());
644 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 665 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
645 rfh2->SendBeforeUnloadACK(true); 666 rfh2->PrepareForCommit(url2b);
646 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame(); 667 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame();
647 EXPECT_TRUE(pending_rfh_b != NULL); 668 EXPECT_TRUE(pending_rfh_b != NULL);
648 EXPECT_TRUE(contents2->cross_navigation_pending()); 669 EXPECT_TRUE(contents2->cross_navigation_pending());
649 670
650 // NOTE(creis): We used to be in danger of showing a crash page here if the 671 // NOTE(creis): We used to be in danger of showing a crash page here if the
651 // second contents hadn't navigated somewhere first (bug 1145430). That case 672 // second contents hadn't navigated somewhere first (bug 1145430). That case
652 // is now covered by the CrossSiteBoundariesAfterCrash test. 673 // is now covered by the CrossSiteBoundariesAfterCrash test.
653 contents2->TestDidNavigate( 674 contents2->TestDidNavigate(
654 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED); 675 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED);
655 SiteInstance* instance2b = contents2->GetSiteInstance(); 676 SiteInstance* instance2b = contents2->GetSiteInstance();
(...skipping 14 matching lines...) Expand all
670 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 691 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
671 int orig_rvh_delete_count = 0; 692 int orig_rvh_delete_count = 0;
672 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 693 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
673 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); 694 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance();
674 695
675 browser_client.set_assign_site_for_url(false); 696 browser_client.set_assign_site_for_url(false);
676 // Navigate to an URL that will not assign a new SiteInstance. 697 // Navigate to an URL that will not assign a new SiteInstance.
677 const GURL native_url("non-site-url://stuffandthings"); 698 const GURL native_url("non-site-url://stuffandthings");
678 controller().LoadURL( 699 controller().LoadURL(
679 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 700 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
701 contents()->GetMainFrame()->PrepareForCommit(native_url);
680 contents()->TestDidNavigate( 702 contents()->TestDidNavigate(
681 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED); 703 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED);
682 704
683 EXPECT_FALSE(contents()->cross_navigation_pending()); 705 EXPECT_FALSE(contents()->cross_navigation_pending());
684 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 706 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
685 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 707 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
686 EXPECT_EQ(native_url, contents()->GetVisibleURL()); 708 EXPECT_EQ(native_url, contents()->GetVisibleURL());
687 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 709 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
688 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); 710 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL());
689 EXPECT_FALSE(orig_instance->HasSite()); 711 EXPECT_FALSE(orig_instance->HasSite());
690 712
691 browser_client.set_assign_site_for_url(true); 713 browser_client.set_assign_site_for_url(true);
692 // Navigate to new site (should keep same site instance). 714 // Navigate to new site (should keep same site instance).
693 const GURL url("http://www.google.com"); 715 const GURL url("http://www.google.com");
694 controller().LoadURL( 716 controller().LoadURL(
695 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 717 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
718 contents()->GetMainFrame()->PrepareForCommit(url);
696 EXPECT_FALSE(contents()->cross_navigation_pending()); 719 EXPECT_FALSE(contents()->cross_navigation_pending());
697 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 720 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
698 EXPECT_EQ(url, contents()->GetVisibleURL()); 721 EXPECT_EQ(url, contents()->GetVisibleURL());
699 EXPECT_FALSE(contents()->GetPendingMainFrame()); 722 EXPECT_FALSE(contents()->GetPendingMainFrame());
700 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 723 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
701 724
702 // Keep the number of active frames in orig_rfh's SiteInstance 725 // Keep the number of active frames in orig_rfh's SiteInstance
703 // non-zero so that orig_rfh doesn't get deleted when it gets 726 // non-zero so that orig_rfh doesn't get deleted when it gets
704 // swapped out. 727 // swapped out.
705 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 728 orig_rfh->GetSiteInstance()->increment_active_frame_count();
706 729
707 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 730 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
708 EXPECT_TRUE( 731 EXPECT_TRUE(
709 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); 732 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com"));
710 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 733 EXPECT_EQ(url, contents()->GetLastCommittedURL());
711 734
712 // Navigate to another new site (should create a new site instance). 735 // Navigate to another new site (should create a new site instance).
713 const GURL url2("http://www.yahoo.com"); 736 const GURL url2("http://www.yahoo.com");
714 controller().LoadURL( 737 controller().LoadURL(
715 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 738 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
739 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
740 switches::kEnableBrowserSideNavigation)) {
741 orig_rfh->PrepareForCommit(url2);
742 }
716 EXPECT_TRUE(contents()->cross_navigation_pending()); 743 EXPECT_TRUE(contents()->cross_navigation_pending());
717 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 744 EXPECT_EQ(url, contents()->GetLastCommittedURL());
718 EXPECT_EQ(url2, contents()->GetVisibleURL()); 745 EXPECT_EQ(url2, contents()->GetVisibleURL());
719 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 746 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
720 int pending_rvh_delete_count = 0; 747 int pending_rvh_delete_count = 0;
721 pending_rfh->GetRenderViewHost()->set_delete_counter( 748 pending_rfh->GetRenderViewHost()->set_delete_counter(
722 &pending_rvh_delete_count); 749 &pending_rvh_delete_count);
723 750
724 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. 751 // Navigations should be suspended in pending_rvh until BeforeUnloadACK.
725 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 752 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
726 orig_rfh->SendBeforeUnloadACK(true); 753 switches::kEnableBrowserSideNavigation)) {
727 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 754 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
755 orig_rfh->SendBeforeUnloadACK(true);
756 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
757 }
728 758
729 // DidNavigate from the pending page. 759 // DidNavigate from the pending page.
730 contents()->TestDidNavigate( 760 contents()->TestDidNavigate(
731 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 761 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
732 SiteInstance* new_instance = contents()->GetSiteInstance(); 762 SiteInstance* new_instance = contents()->GetSiteInstance();
733 763
734 EXPECT_FALSE(contents()->cross_navigation_pending()); 764 EXPECT_FALSE(contents()->cross_navigation_pending());
735 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 765 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
736 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 766 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
737 EXPECT_EQ(url2, contents()->GetVisibleURL()); 767 EXPECT_EQ(url2, contents()->GetVisibleURL());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 browser_context()); 841 browser_context());
812 entry->SetPageID(0); 842 entry->SetPageID(0);
813 entries.push_back(entry); 843 entries.push_back(entry);
814 controller().Restore( 844 controller().Restore(
815 0, 845 0,
816 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, 846 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
817 &entries); 847 &entries);
818 ASSERT_EQ(0u, entries.size()); 848 ASSERT_EQ(0u, entries.size());
819 ASSERT_EQ(1, controller().GetEntryCount()); 849 ASSERT_EQ(1, controller().GetEntryCount());
820 controller().GoToIndex(0); 850 controller().GoToIndex(0);
851 orig_rfh->PrepareForCommit(regular_url);
821 contents()->TestDidNavigate( 852 contents()->TestDidNavigate(
822 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD); 853 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD);
823 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 854 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
824 EXPECT_TRUE(orig_instance->HasSite()); 855 EXPECT_TRUE(orig_instance->HasSite());
825 856
826 // Navigate to another site and verify that a new SiteInstance was created. 857 // Navigate to another site and verify that a new SiteInstance was created.
827 const GURL url("http://www.google.com"); 858 const GURL url("http://www.google.com");
828 controller().LoadURL( 859 controller().LoadURL(
829 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 860 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
861 orig_rfh->PrepareForCommit(url);
830 contents()->TestDidNavigate( 862 contents()->TestDidNavigate(
831 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 863 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED);
832 EXPECT_NE(orig_instance, contents()->GetSiteInstance()); 864 EXPECT_NE(orig_instance, contents()->GetSiteInstance());
833 865
834 // Cleanup. 866 // Cleanup.
835 DeleteContents(); 867 DeleteContents();
836 } 868 }
837 869
838 // Test that we can find an opener RVH even if it's pending. 870 // Test that we can find an opener RVH even if it's pending.
839 // http://crbug.com/176252. 871 // http://crbug.com/176252.
840 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { 872 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) {
841 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 873 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
842 874
843 // Navigate to a URL. 875 // Navigate to a URL.
844 const GURL url("http://www.google.com"); 876 const GURL url("http://www.google.com");
845 controller().LoadURL( 877 controller().LoadURL(
846 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 878 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
879 orig_rfh->PrepareForCommit(url);
847 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 880 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
848 881
849 // Start to navigate first tab to a new site, so that it has a pending RVH. 882 // Start to navigate first tab to a new site, so that it has a pending RVH.
850 const GURL url2("http://www.yahoo.com"); 883 const GURL url2("http://www.yahoo.com");
851 controller().LoadURL( 884 controller().LoadURL(
852 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 885 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
853 orig_rfh->SendBeforeUnloadACK(true); 886 orig_rfh->PrepareForCommit(url2);
854 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 887 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
855 888
856 // While it is still pending, simulate opening a new tab with the first tab 889 // While it is still pending, simulate opening a new tab with the first tab
857 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews 890 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews
858 // on the opener to ensure that an RVH exists. 891 // on the opener to ensure that an RVH exists.
859 int opener_routing_id = 892 int opener_routing_id =
860 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance()); 893 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance());
861 894
862 // We should find the pending RVH and not create a new one. 895 // We should find the pending RVH and not create a new one.
863 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(), 896 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(),
864 opener_routing_id); 897 opener_routing_id);
865 } 898 }
866 899
867 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, 900 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site,
868 // to determine whether a navigation is cross-site. 901 // to determine whether a navigation is cross-site.
869 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { 902 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) {
870 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 903 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
871 SiteInstance* instance1 = contents()->GetSiteInstance(); 904 SiteInstance* instance1 = contents()->GetSiteInstance();
872 905
873 // Navigate to URL. 906 // Navigate to URL.
874 const GURL url("http://www.google.com"); 907 const GURL url("http://www.google.com");
875 controller().LoadURL( 908 controller().LoadURL(
876 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 909 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
910 contents()->GetMainFrame()->PrepareForCommit(url);
877 contents()->TestDidNavigate( 911 contents()->TestDidNavigate(
878 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 912 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
879 913
880 // Open a related contents to a second site. 914 // Open a related contents to a second site.
881 scoped_ptr<TestWebContents> contents2( 915 scoped_ptr<TestWebContents> contents2(
882 TestWebContents::Create(browser_context(), instance1)); 916 TestWebContents::Create(browser_context(), instance1));
883 const GURL url2("http://www.yahoo.com"); 917 const GURL url2("http://www.yahoo.com");
884 contents2->GetController().LoadURL(url2, Referrer(), 918 contents2->GetController().LoadURL(url2, Referrer(),
885 ui::PAGE_TRANSITION_TYPED, 919 ui::PAGE_TRANSITION_TYPED,
886 std::string()); 920 std::string());
921 contents2->GetMainFrame()->PrepareForCommit(url2);
887 // The first RVH in contents2 isn't live yet, so we shortcut the cross site 922 // The first RVH in contents2 isn't live yet, so we shortcut the cross site
888 // pending. 923 // pending.
889 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 924 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
890 EXPECT_FALSE(contents2->cross_navigation_pending()); 925 EXPECT_FALSE(contents2->cross_navigation_pending());
891 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED); 926 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED);
892 SiteInstance* instance2 = contents2->GetSiteInstance(); 927 SiteInstance* instance2 = contents2->GetSiteInstance();
893 EXPECT_NE(instance1, instance2); 928 EXPECT_NE(instance1, instance2);
894 EXPECT_FALSE(contents2->cross_navigation_pending()); 929 EXPECT_FALSE(contents2->cross_navigation_pending());
895 930
896 // Simulate a link click in first contents to second site. Doesn't switch 931 // Simulate a link click in first contents to second site. Doesn't switch
897 // SiteInstances, because we don't intercept WebKit navigations. 932 // SiteInstances, because we don't intercept WebKit navigations.
898 contents()->TestDidNavigate( 933 contents()->TestDidNavigate(
899 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); 934 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED);
900 SiteInstance* instance3 = contents()->GetSiteInstance(); 935 SiteInstance* instance3 = contents()->GetSiteInstance();
901 EXPECT_EQ(instance1, instance3); 936 EXPECT_EQ(instance1, instance3);
902 EXPECT_FALSE(contents()->cross_navigation_pending()); 937 EXPECT_FALSE(contents()->cross_navigation_pending());
903 938
904 // Navigate to the new site. Doesn't switch SiteInstancees, because we 939 // Navigate to the new site. Doesn't switch SiteInstancees, because we
905 // compare against the current URL, not the SiteInstance's site. 940 // compare against the current URL, not the SiteInstance's site.
906 const GURL url3("http://mail.yahoo.com"); 941 const GURL url3("http://mail.yahoo.com");
907 controller().LoadURL( 942 controller().LoadURL(
908 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 943 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
909 EXPECT_FALSE(contents()->cross_navigation_pending()); 944 EXPECT_FALSE(contents()->cross_navigation_pending());
945 contents()->GetMainFrame()->PrepareForCommit(url3);
910 contents()->TestDidNavigate( 946 contents()->TestDidNavigate(
911 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED); 947 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED);
912 SiteInstance* instance4 = contents()->GetSiteInstance(); 948 SiteInstance* instance4 = contents()->GetSiteInstance();
913 EXPECT_EQ(instance1, instance4); 949 EXPECT_EQ(instance1, instance4);
914 } 950 }
915 951
916 // Test that the onbeforeunload and onunload handlers run when navigating 952 // Test that the onbeforeunload and onunload handlers run when navigating
917 // across site boundaries. 953 // across site boundaries.
918 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { 954 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) {
919 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 955 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
920 SiteInstance* instance1 = contents()->GetSiteInstance(); 956 SiteInstance* instance1 = contents()->GetSiteInstance();
921 957
922 // Navigate to URL. First URL should use first RenderViewHost. 958 // Navigate to URL. First URL should use first RenderViewHost.
923 const GURL url("http://www.google.com"); 959 const GURL url("http://www.google.com");
924 controller().LoadURL( 960 controller().LoadURL(
925 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 961 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
962 contents()->GetMainFrame()->PrepareForCommit(url);
926 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 963 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
927 EXPECT_FALSE(contents()->cross_navigation_pending()); 964 EXPECT_FALSE(contents()->cross_navigation_pending());
928 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 965 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
929 966
930 // Navigate to new site, but simulate an onbeforeunload denial. 967 // Navigate to new site, but simulate an onbeforeunload denial.
931 const GURL url2("http://www.yahoo.com"); 968 const GURL url2("http://www.yahoo.com");
932 controller().LoadURL( 969 controller().LoadURL(
933 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 970 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
934 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 971 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
935 base::TimeTicks now = base::TimeTicks::Now(); 972 base::TimeTicks now = base::TimeTicks::Now();
936 orig_rfh->OnMessageReceived( 973 orig_rfh->OnMessageReceived(
937 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 974 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
938 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 975 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
939 EXPECT_FALSE(contents()->cross_navigation_pending()); 976 EXPECT_FALSE(contents()->cross_navigation_pending());
940 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 977 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
941 978
942 // Navigate again, but simulate an onbeforeunload approval. 979 // Navigate again, but simulate an onbeforeunload approval.
943 controller().LoadURL( 980 controller().LoadURL(
944 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 981 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
945 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 982 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
946 now = base::TimeTicks::Now(); 983 now = base::TimeTicks::Now();
947 orig_rfh->OnMessageReceived( 984 orig_rfh->PrepareForCommit(url2);
948 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 985 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
949 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
950 EXPECT_TRUE(contents()->cross_navigation_pending()); 986 EXPECT_TRUE(contents()->cross_navigation_pending());
951 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 987 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
952 988
953 // We won't hear DidNavigate until the onunload handler has finished running. 989 // We won't hear DidNavigate until the onunload handler has finished running.
954 990
955 // DidNavigate from the pending page. 991 // DidNavigate from the pending page.
956 contents()->TestDidNavigate( 992 contents()->TestDidNavigate(
957 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 993 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
958 SiteInstance* instance2 = contents()->GetSiteInstance(); 994 SiteInstance* instance2 = contents()->GetSiteInstance();
959 EXPECT_FALSE(contents()->cross_navigation_pending()); 995 EXPECT_FALSE(contents()->cross_navigation_pending());
960 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 996 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
961 EXPECT_NE(instance1, instance2); 997 EXPECT_NE(instance1, instance2);
962 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 998 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
963 } 999 }
964 1000
965 // Test that during a slow cross-site navigation, the original renderer can 1001 // Test that during a slow cross-site navigation, the original renderer can
966 // navigate to a different URL and have it displayed, canceling the slow 1002 // navigate to a different URL and have it displayed, canceling the slow
967 // navigation. 1003 // navigation.
968 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { 1004 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) {
969 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1005 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
970 SiteInstance* instance1 = contents()->GetSiteInstance(); 1006 SiteInstance* instance1 = contents()->GetSiteInstance();
971 1007
972 // Navigate to URL. First URL should use first RenderFrameHost. 1008 // Navigate to URL. First URL should use first RenderFrameHost.
973 const GURL url("http://www.google.com"); 1009 const GURL url("http://www.google.com");
974 controller().LoadURL( 1010 controller().LoadURL(
975 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1011 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1012 contents()->GetMainFrame()->PrepareForCommit(url);
976 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1013 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
977 EXPECT_FALSE(contents()->cross_navigation_pending()); 1014 EXPECT_FALSE(contents()->cross_navigation_pending());
978 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1015 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
979 1016
980 // Navigate to new site, simulating an onbeforeunload approval. 1017 // Navigate to new site, simulating an onbeforeunload approval.
981 const GURL url2("http://www.yahoo.com"); 1018 const GURL url2("http://www.yahoo.com");
982 controller().LoadURL( 1019 controller().LoadURL(
983 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1020 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
984 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1021 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
985 base::TimeTicks now = base::TimeTicks::Now(); 1022 orig_rfh->PrepareForCommit(url2);
986 orig_rfh->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
987 EXPECT_TRUE(contents()->cross_navigation_pending()); 1023 EXPECT_TRUE(contents()->cross_navigation_pending());
988 1024
989 // Suppose the original renderer navigates before the new one is ready. 1025 // Suppose the original renderer navigates before the new one is ready.
990 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); 1026 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo"));
991 1027
992 // Verify that the pending navigation is cancelled. 1028 // Verify that the pending navigation is cancelled.
993 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 1029 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
994 SiteInstance* instance2 = contents()->GetSiteInstance(); 1030 SiteInstance* instance2 = contents()->GetSiteInstance();
995 EXPECT_FALSE(contents()->cross_navigation_pending()); 1031 EXPECT_FALSE(contents()->cross_navigation_pending());
996 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1032 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
997 EXPECT_EQ(instance1, instance2); 1033 EXPECT_EQ(instance1, instance2);
998 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1034 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
999 } 1035 }
1000 1036
1001 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1037 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1002 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1038 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1003 const GURL url1("chrome://blah"); 1039 const GURL url1("chrome://blah");
1004 controller().LoadURL( 1040 controller().LoadURL(
1005 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1041 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1006 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); 1042 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame();
1043 ntp_rfh->PrepareForCommit(url1);
1007 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED); 1044 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED);
1008 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1045 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1009 SiteInstance* instance1 = contents()->GetSiteInstance(); 1046 SiteInstance* instance1 = contents()->GetSiteInstance();
1010 1047
1011 EXPECT_FALSE(contents()->cross_navigation_pending()); 1048 EXPECT_FALSE(contents()->cross_navigation_pending());
1012 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); 1049 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame());
1013 EXPECT_EQ(url1, entry1->GetURL()); 1050 EXPECT_EQ(url1, entry1->GetURL());
1014 EXPECT_EQ(instance1, 1051 EXPECT_EQ(instance1,
1015 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1052 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1016 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() & 1053 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() &
1017 BINDINGS_POLICY_WEB_UI); 1054 BINDINGS_POLICY_WEB_UI);
1018 1055
1019 // Navigate to new site. 1056 // Navigate to new site.
1020 const GURL url2("http://www.google.com"); 1057 const GURL url2("http://www.google.com");
1021 controller().LoadURL( 1058 controller().LoadURL(
1022 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1059 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1023 EXPECT_TRUE(contents()->cross_navigation_pending()); 1060 EXPECT_TRUE(contents()->cross_navigation_pending());
1024 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1061 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1025 1062
1026 // Simulate beforeunload approval. 1063 // Simulate beforeunload approval.
1027 EXPECT_TRUE(ntp_rfh->is_waiting_for_beforeunload_ack()); 1064 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK());
1028 base::TimeTicks now = base::TimeTicks::Now(); 1065 base::TimeTicks now = base::TimeTicks::Now();
1029 ntp_rfh->OnMessageReceived( 1066 ntp_rfh->PrepareForCommit(url2);
1030 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1031 1067
1032 // DidNavigate from the pending page. 1068 // DidNavigate from the pending page.
1033 contents()->TestDidNavigate( 1069 contents()->TestDidNavigate(
1034 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1070 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1035 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1071 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1036 SiteInstance* instance2 = contents()->GetSiteInstance(); 1072 SiteInstance* instance2 = contents()->GetSiteInstance();
1037 1073
1038 EXPECT_FALSE(contents()->cross_navigation_pending()); 1074 EXPECT_FALSE(contents()->cross_navigation_pending());
1039 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1075 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1040 EXPECT_NE(instance1, instance2); 1076 EXPECT_NE(instance1, instance2);
1041 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1077 EXPECT_FALSE(contents()->GetPendingMainFrame());
1042 EXPECT_EQ(url2, entry2->GetURL()); 1078 EXPECT_EQ(url2, entry2->GetURL());
1043 EXPECT_EQ(instance2, 1079 EXPECT_EQ(instance2,
1044 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 1080 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
1045 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & 1081 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() &
1046 BINDINGS_POLICY_WEB_UI); 1082 BINDINGS_POLICY_WEB_UI);
1047 1083
1048 // Navigate to third page on same site. 1084 // Navigate to third page on same site.
1049 const GURL url3("http://news.google.com"); 1085 const GURL url3("http://news.google.com");
1050 controller().LoadURL( 1086 controller().LoadURL(
1051 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1087 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1052 EXPECT_FALSE(contents()->cross_navigation_pending()); 1088 EXPECT_FALSE(contents()->cross_navigation_pending());
1089 contents()->GetMainFrame()->PrepareForCommit(url3);
1053 contents()->TestDidNavigate( 1090 contents()->TestDidNavigate(
1054 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED); 1091 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED);
1055 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 1092 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
1056 SiteInstance* instance3 = contents()->GetSiteInstance(); 1093 SiteInstance* instance3 = contents()->GetSiteInstance();
1057 1094
1058 EXPECT_FALSE(contents()->cross_navigation_pending()); 1095 EXPECT_FALSE(contents()->cross_navigation_pending());
1059 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1096 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1060 EXPECT_EQ(instance2, instance3); 1097 EXPECT_EQ(instance2, instance3);
1061 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1098 EXPECT_FALSE(contents()->GetPendingMainFrame());
1062 EXPECT_EQ(url3, entry3->GetURL()); 1099 EXPECT_EQ(url3, entry3->GetURL());
1063 EXPECT_EQ(instance3, 1100 EXPECT_EQ(instance3,
1064 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1101 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
1065 1102
1066 // Go back within the site. 1103 // Go back within the site.
1067 controller().GoBack(); 1104 controller().GoBack();
1068 EXPECT_FALSE(contents()->cross_navigation_pending()); 1105 EXPECT_FALSE(contents()->cross_navigation_pending());
1069 EXPECT_EQ(entry2, controller().GetPendingEntry()); 1106 EXPECT_EQ(entry2, controller().GetPendingEntry());
1070 1107
1071 // Before that commits, go back again. 1108 // Before that commits, go back again.
1072 controller().GoBack(); 1109 controller().GoBack();
1073 EXPECT_TRUE(contents()->cross_navigation_pending()); 1110 EXPECT_TRUE(contents()->cross_navigation_pending());
1074 EXPECT_TRUE(contents()->GetPendingMainFrame()); 1111 EXPECT_TRUE(contents()->GetPendingMainFrame());
1075 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1112 EXPECT_EQ(entry1, controller().GetPendingEntry());
1076 1113
1077 // Simulate beforeunload approval. 1114 // Simulate beforeunload approval.
1078 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack()); 1115 EXPECT_TRUE(google_rfh->IsWaitingForBeforeUnloadACK());
1079 now = base::TimeTicks::Now(); 1116 now = base::TimeTicks::Now();
1117 google_rfh->PrepareForCommit(url2);
1080 google_rfh->OnMessageReceived( 1118 google_rfh->OnMessageReceived(
1081 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1119 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1082 1120
1083 // DidNavigate from the first back. This aborts the second back's pending RFH. 1121 // DidNavigate from the first back. This aborts the second back's pending RFH.
1084 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1122 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1085 1123
1086 // We should commit this page and forget about the second back. 1124 // We should commit this page and forget about the second back.
1087 EXPECT_FALSE(contents()->cross_navigation_pending()); 1125 EXPECT_FALSE(contents()->cross_navigation_pending());
1088 EXPECT_FALSE(controller().GetPendingEntry()); 1126 EXPECT_FALSE(controller().GetPendingEntry());
1089 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1127 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
(...skipping 11 matching lines...) Expand all
1101 1139
1102 // Test that during a slow cross-site navigation, a sub-frame navigation in the 1140 // Test that during a slow cross-site navigation, a sub-frame navigation in the
1103 // original renderer will not cancel the slow navigation (bug 42029). 1141 // original renderer will not cancel the slow navigation (bug 42029).
1104 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { 1142 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) {
1105 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1143 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1106 1144
1107 // Navigate to URL. First URL should use the original RenderFrameHost. 1145 // Navigate to URL. First URL should use the original RenderFrameHost.
1108 const GURL url("http://www.google.com"); 1146 const GURL url("http://www.google.com");
1109 controller().LoadURL( 1147 controller().LoadURL(
1110 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1148 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1149 contents()->GetMainFrame()->PrepareForCommit(url);
1111 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1150 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1112 EXPECT_FALSE(contents()->cross_navigation_pending()); 1151 EXPECT_FALSE(contents()->cross_navigation_pending());
1113 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1152 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1114 1153
1115 // Start navigating to new site. 1154 // Start navigating to new site.
1116 const GURL url2("http://www.yahoo.com"); 1155 const GURL url2("http://www.yahoo.com");
1117 controller().LoadURL( 1156 controller().LoadURL(
1118 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1157 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1119 1158
1120 // Simulate a sub-frame navigation arriving and ensure the RVH is still 1159 // Simulate a sub-frame navigation arriving and ensure the RVH is still
1121 // waiting for a before unload response. 1160 // waiting for a before unload response.
1122 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); 1161 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe");
1123 child_rfh->SendNavigateWithTransition( 1162 child_rfh->SendNavigateWithTransition(
1124 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME); 1163 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME);
1125 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1164 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1126 1165
1127 // Now simulate the onbeforeunload approval and verify the navigation is 1166 // Now simulate the onbeforeunload approval and verify the navigation is
1128 // not canceled. 1167 // not canceled.
1129 base::TimeTicks now = base::TimeTicks::Now(); 1168 orig_rfh->PrepareForCommit(url2);
1130 orig_rfh->OnMessageReceived( 1169 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1131 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1132 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack());
1133 EXPECT_TRUE(contents()->cross_navigation_pending()); 1170 EXPECT_TRUE(contents()->cross_navigation_pending());
1134 } 1171 }
1135 1172
1136 // Test that a cross-site navigation is not preempted if the previous 1173 // Test that a cross-site navigation is not preempted if the previous
1137 // renderer sends a FrameNavigate message just before being told to stop. 1174 // renderer sends a FrameNavigate message just before being told to stop.
1138 // We should only preempt the cross-site navigation if the previous renderer 1175 // We should only preempt the cross-site navigation if the previous renderer
1139 // has started a new navigation. See http://crbug.com/79176. 1176 // has started a new navigation. See http://crbug.com/79176.
1140 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1177 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1141 // Navigate to NTP URL. 1178 // Navigate to NTP URL.
1142 const GURL url("chrome://blah"); 1179 const GURL url("chrome://blah");
1143 controller().LoadURL( 1180 controller().LoadURL(
1144 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1181 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1145 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1182 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1146 EXPECT_FALSE(contents()->cross_navigation_pending()); 1183 EXPECT_FALSE(contents()->cross_navigation_pending());
1147 1184
1148 // Navigate to new site, with the beforeunload request in flight. 1185 // Navigate to new site, with the beforeunload request in flight.
1149 const GURL url2("http://www.yahoo.com"); 1186 const GURL url2("http://www.yahoo.com");
1150 controller().LoadURL( 1187 controller().LoadURL(
1151 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1188 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1152 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1189 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
1153 EXPECT_TRUE(contents()->cross_navigation_pending()); 1190 EXPECT_TRUE(contents()->cross_navigation_pending());
1154 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1191 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1155 1192
1156 // Suppose the first navigation tries to commit now, with a 1193 // Suppose the first navigation tries to commit now, with a
1157 // FrameMsg_Stop in flight. This should not cancel the pending navigation, 1194 // FrameMsg_Stop in flight. This should not cancel the pending navigation,
1158 // but it should act as if the beforeunload ack arrived. 1195 // but it should act as if the beforeunload ack arrived.
1159 orig_rfh->SendNavigate(1, GURL("chrome://blah")); 1196 orig_rfh->SendNavigate(1, GURL("chrome://blah"));
1160 EXPECT_TRUE(contents()->cross_navigation_pending()); 1197 EXPECT_TRUE(contents()->cross_navigation_pending());
1161 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1198 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1162 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 1199 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1163 1200
1164 // The pending navigation should be able to commit successfully. 1201 // The pending navigation should be able to commit successfully.
1165 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1202 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1166 EXPECT_FALSE(contents()->cross_navigation_pending()); 1203 EXPECT_FALSE(contents()->cross_navigation_pending());
1167 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1204 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
1168 } 1205 }
1169 1206
1170 // Test that a cross-site navigation that doesn't commit after the unload 1207 // Test that a cross-site navigation that doesn't commit after the unload
1171 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 1208 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562
1172 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { 1209 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) {
1173 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1210 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1174 SiteInstance* instance1 = contents()->GetSiteInstance(); 1211 SiteInstance* instance1 = contents()->GetSiteInstance();
1175 1212
1176 // Navigate to URL. First URL should use original RenderFrameHost. 1213 // Navigate to URL. First URL should use original RenderFrameHost.
1177 const GURL url("http://www.google.com"); 1214 const GURL url("http://www.google.com");
1178 controller().LoadURL( 1215 controller().LoadURL(
1179 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1216 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1217 contents()->GetMainFrame()->PrepareForCommit(url);
1180 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1218 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1181 EXPECT_FALSE(contents()->cross_navigation_pending()); 1219 EXPECT_FALSE(contents()->cross_navigation_pending());
1182 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1220 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1183 1221
1184 // Navigate to new site, simulating an onbeforeunload approval. 1222 // Navigate to new site, simulating an onbeforeunload approval.
1185 const GURL url2("http://www.yahoo.com"); 1223 const GURL url2("http://www.yahoo.com");
1186 controller().LoadURL( 1224 controller().LoadURL(
1187 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1225 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1188 EXPECT_TRUE(orig_rfh->is_waiting_for_beforeunload_ack()); 1226 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1189 base::TimeTicks now = base::TimeTicks::Now(); 1227 contents()->GetMainFrame()->PrepareForCommit(url2);
1190 orig_rfh->OnMessageReceived(
1191 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1192 EXPECT_TRUE(contents()->cross_navigation_pending()); 1228 EXPECT_TRUE(contents()->cross_navigation_pending());
1193 1229
1194 // Simulate swap out message when the response arrives. 1230 // Simulate swap out message when the response arrives.
1195 orig_rfh->OnSwappedOut(); 1231 orig_rfh->OnSwappedOut();
1196 1232
1197 // Suppose the navigation doesn't get a chance to commit, and the user 1233 // Suppose the navigation doesn't get a chance to commit, and the user
1198 // navigates in the current RFH's SiteInstance. 1234 // navigates in the current RFH's SiteInstance.
1199 controller().LoadURL( 1235 controller().LoadURL(
1200 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1236 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1201 1237
1202 // Verify that the pending navigation is cancelled and the renderer is no 1238 // Verify that the pending navigation is cancelled and the renderer is no
1203 // longer swapped out. 1239 // longer swapped out.
1204 EXPECT_FALSE(orig_rfh->is_waiting_for_beforeunload_ack()); 1240 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1205 SiteInstance* instance2 = contents()->GetSiteInstance(); 1241 SiteInstance* instance2 = contents()->GetSiteInstance();
1206 EXPECT_FALSE(contents()->cross_navigation_pending()); 1242 EXPECT_FALSE(contents()->cross_navigation_pending());
1207 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1243 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1208 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, orig_rfh->rfh_state()); 1244 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, orig_rfh->rfh_state());
1209 EXPECT_EQ(instance1, instance2); 1245 EXPECT_EQ(instance1, instance2);
1210 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1246 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1211 } 1247 }
1212 1248
1213 // Test that NavigationEntries have the correct page state after going 1249 // Test that NavigationEntries have the correct page state after going
1214 // forward and back. Prevents regression for bug 1116137. 1250 // forward and back. Prevents regression for bug 1116137.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) { 1322 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) {
1287 FakeFullscreenDelegate fake_delegate; 1323 FakeFullscreenDelegate fake_delegate;
1288 contents()->SetDelegate(&fake_delegate); 1324 contents()->SetDelegate(&fake_delegate);
1289 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1325 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1290 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost(); 1326 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost();
1291 1327
1292 // Navigate to a site. 1328 // Navigate to a site.
1293 const GURL url("http://www.google.com"); 1329 const GURL url("http://www.google.com");
1294 controller().LoadURL( 1330 controller().LoadURL(
1295 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1331 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1332 contents()->GetMainFrame()->PrepareForCommit(url);
1296 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1333 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED);
1297 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1334 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1298 1335
1299 // Toggle fullscreen mode on (as if initiated via IPC from renderer). 1336 // Toggle fullscreen mode on (as if initiated via IPC from renderer).
1300 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1337 EXPECT_FALSE(orig_rvh->IsFullscreen());
1301 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1338 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1302 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1339 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1303 orig_rvh->OnMessageReceived( 1340 orig_rvh->OnMessageReceived(
1304 ViewHostMsg_ToggleFullscreen(orig_rvh->GetRoutingID(), true)); 1341 ViewHostMsg_ToggleFullscreen(orig_rvh->GetRoutingID(), true));
1305 EXPECT_TRUE(orig_rvh->IsFullscreen()); 1342 EXPECT_TRUE(orig_rvh->IsFullscreen());
1306 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); 1343 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab());
1307 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1344 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1308 1345
1309 // Navigate to a new site. 1346 // Navigate to a new site.
1310 const GURL url2("http://www.yahoo.com"); 1347 const GURL url2("http://www.yahoo.com");
1311 controller().LoadURL( 1348 controller().LoadURL(
1312 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1349 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1350 contents()->GetMainFrame()->PrepareForCommit(url2);
1313 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame(); 1351 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame();
1314 contents()->TestDidNavigate( 1352 contents()->TestDidNavigate(
1315 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1353 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED);
1316 1354
1317 // Confirm fullscreen has exited. 1355 // Confirm fullscreen has exited.
1318 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1356 EXPECT_FALSE(orig_rvh->IsFullscreen());
1319 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1357 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1320 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1358 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1321 1359
1322 contents()->SetDelegate(NULL); 1360 contents()->SetDelegate(NULL);
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 // Navigate to a URL in the same site. 2668 // Navigate to a URL in the same site.
2631 contents->GetController().LoadURL(GURL("http://a.com/2"), 2669 contents->GetController().LoadURL(GURL("http://a.com/2"),
2632 Referrer(), 2670 Referrer(),
2633 ui::PAGE_TRANSITION_TYPED, 2671 ui::PAGE_TRANSITION_TYPED,
2634 std::string()); 2672 std::string());
2635 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2673 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2636 contents->CommitPendingNavigation(); 2674 contents->CommitPendingNavigation();
2637 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2675 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2638 2676
2639 // Navigate to a URL in a different site. 2677 // Navigate to a URL in a different site.
2640 contents->GetController().LoadURL(GURL("http://b.com"), 2678 const GURL kUrl = GURL("http://b.com");
2679 contents->GetController().LoadURL(kUrl,
2641 Referrer(), 2680 Referrer(),
2642 ui::PAGE_TRANSITION_TYPED, 2681 ui::PAGE_TRANSITION_TYPED,
2643 std::string()); 2682 std::string());
2683 contents->GetMainFrame()->PrepareForCommit(kUrl);
2644 EXPECT_TRUE(contents->cross_navigation_pending()); 2684 EXPECT_TRUE(contents->cross_navigation_pending());
2645 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2685 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2646 contents->CommitPendingNavigation(); 2686 contents->CommitPendingNavigation();
2647 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2687 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2648 2688
2649 contents.reset(); 2689 contents.reset();
2650 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); 2690 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount());
2651 } 2691 }
2652 2692
2653 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes 2693 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes
(...skipping 10 matching lines...) Expand all
2664 2704
2665 // Navigate to a URL. 2705 // Navigate to a URL.
2666 contents->NavigateAndCommit(GURL("http://a.com")); 2706 contents->NavigateAndCommit(GURL("http://a.com"));
2667 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2707 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2668 2708
2669 // Navigate to a URL with WebUI. This will change BrowsingInstances. 2709 // Navigate to a URL with WebUI. This will change BrowsingInstances.
2670 contents->GetController().LoadURL(GURL(kTestWebUIUrl), 2710 contents->GetController().LoadURL(GURL(kTestWebUIUrl),
2671 Referrer(), 2711 Referrer(),
2672 ui::PAGE_TRANSITION_TYPED, 2712 ui::PAGE_TRANSITION_TYPED,
2673 std::string()); 2713 std::string());
2714 contents->GetMainFrame()->PrepareForCommit(GURL(kTestWebUIUrl));
2674 EXPECT_TRUE(contents->cross_navigation_pending()); 2715 EXPECT_TRUE(contents->cross_navigation_pending());
2675 scoped_refptr<SiteInstance> instance_webui( 2716 scoped_refptr<SiteInstance> instance_webui(
2676 contents->GetPendingMainFrame()->GetSiteInstance()); 2717 contents->GetPendingMainFrame()->GetSiteInstance());
2677 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); 2718 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get()));
2678 2719
2679 // At this point, contents still counts for the old BrowsingInstance. 2720 // At this point, contents still counts for the old BrowsingInstance.
2680 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); 2721 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount());
2681 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); 2722 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount());
2682 2723
2683 // Commit and contents counts for the new one. 2724 // Commit and contents counts for the new one.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2786 2827
2787 // Destroy the remote player. No power save blockers should remain. 2828 // Destroy the remote player. No power save blockers should remain.
2788 rfh->OnMessageReceived( 2829 rfh->OnMessageReceived(
2789 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); 2830 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId));
2790 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2831 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
2791 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2832 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2792 } 2833 }
2793 #endif 2834 #endif
2794 2835
2795 } // namespace content 2836 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698