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

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

Issue 10831116: Move SessionStorageNamespace entirely into NavigationController and support StoragePartitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/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/renderer_host/render_view_host_impl.h" 7 #include "content/browser/renderer_host/render_view_host_impl.h"
8 #include "content/browser/renderer_host/test_render_view_host.h" 8 #include "content/browser/renderer_host/test_render_view_host.h"
9 #include "content/browser/site_instance_impl.h" 9 #include "content/browser/site_instance_impl.h"
10 #include "content/browser/web_contents/interstitial_page_impl.h" 10 #include "content/browser/web_contents/interstitial_page_impl.h"
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 TestRenderViewHost* orig_rvh = test_rvh(); 548 TestRenderViewHost* orig_rvh = test_rvh();
549 SiteInstance* instance1 = contents()->GetSiteInstance(); 549 SiteInstance* instance1 = contents()->GetSiteInstance();
550 550
551 // Navigate to URL. First URL should use first RenderViewHost. 551 // Navigate to URL. First URL should use first RenderViewHost.
552 const GURL url("http://www.google.com"); 552 const GURL url("http://www.google.com");
553 controller().LoadURL( 553 controller().LoadURL(
554 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 554 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
555 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 555 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
556 556
557 // Open a new contents with the same SiteInstance, navigated to the same site. 557 // Open a new contents with the same SiteInstance, navigated to the same site.
558 TestWebContents contents2(browser_context_.get(), instance1); 558 scoped_ptr<TestWebContents> contents2(
559 contents2.transition_cross_site = true; 559 TestWebContents::Create(browser_context_.get(), instance1));
560 contents2.GetController().LoadURL(url, content::Referrer(), 560 contents2->transition_cross_site = true;
561 contents2->GetController().LoadURL(url, content::Referrer(),
561 content::PAGE_TRANSITION_TYPED, 562 content::PAGE_TRANSITION_TYPED,
562 std::string()); 563 std::string());
563 // Need this page id to be 2 since the site instance is the same (which is the 564 // Need this page id to be 2 since the site instance is the same (which is the
564 // scope of page IDs) and we want to consider this a new page. 565 // scope of page IDs) and we want to consider this a new page.
565 contents2.TestDidNavigate( 566 contents2->TestDidNavigate(
566 contents2.GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED); 567 contents2->GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED);
567 568
568 // Navigate first contents to a new site. 569 // Navigate first contents to a new site.
569 const GURL url2a("http://www.yahoo.com"); 570 const GURL url2a("http://www.yahoo.com");
570 controller().LoadURL( 571 controller().LoadURL(
571 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, 572 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED,
572 std::string()); 573 std::string());
573 orig_rvh->SendShouldCloseACK(true); 574 orig_rvh->SendShouldCloseACK(true);
574 TestRenderViewHost* pending_rvh_a = 575 TestRenderViewHost* pending_rvh_a =
575 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); 576 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost());
576 contents()->TestDidNavigate( 577 contents()->TestDidNavigate(
577 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); 578 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED);
578 SiteInstance* instance2a = contents()->GetSiteInstance(); 579 SiteInstance* instance2a = contents()->GetSiteInstance();
579 EXPECT_NE(instance1, instance2a); 580 EXPECT_NE(instance1, instance2a);
580 581
581 // Navigate second contents to the same site as the first tab. 582 // Navigate second contents to the same site as the first tab.
582 const GURL url2b("http://mail.yahoo.com"); 583 const GURL url2b("http://mail.yahoo.com");
583 contents2.GetController().LoadURL(url2b, content::Referrer(), 584 contents2->GetController().LoadURL(url2b, content::Referrer(),
584 content::PAGE_TRANSITION_TYPED, 585 content::PAGE_TRANSITION_TYPED,
585 std::string()); 586 std::string());
586 TestRenderViewHost* rvh2 = 587 TestRenderViewHost* rvh2 =
587 static_cast<TestRenderViewHost*>(contents2.GetRenderViewHost()); 588 static_cast<TestRenderViewHost*>(contents2->GetRenderViewHost());
588 rvh2->SendShouldCloseACK(true); 589 rvh2->SendShouldCloseACK(true);
589 TestRenderViewHost* pending_rvh_b = 590 TestRenderViewHost* pending_rvh_b =
590 static_cast<TestRenderViewHost*>(contents2.GetPendingRenderViewHost()); 591 static_cast<TestRenderViewHost*>(contents2->GetPendingRenderViewHost());
591 EXPECT_TRUE(pending_rvh_b != NULL); 592 EXPECT_TRUE(pending_rvh_b != NULL);
592 EXPECT_TRUE(contents2.cross_navigation_pending()); 593 EXPECT_TRUE(contents2->cross_navigation_pending());
593 594
594 // NOTE(creis): We used to be in danger of showing a crash page here if the 595 // NOTE(creis): We used to be in danger of showing a crash page here if the
595 // second contents hadn't navigated somewhere first (bug 1145430). That case 596 // second contents hadn't navigated somewhere first (bug 1145430). That case
596 // is now covered by the CrossSiteBoundariesAfterCrash test. 597 // is now covered by the CrossSiteBoundariesAfterCrash test.
597 contents2.TestDidNavigate( 598 contents2->TestDidNavigate(
598 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); 599 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED);
599 SiteInstance* instance2b = contents2.GetSiteInstance(); 600 SiteInstance* instance2b = contents2->GetSiteInstance();
600 EXPECT_NE(instance1, instance2b); 601 EXPECT_NE(instance1, instance2b);
601 602
602 // Both contentses should now be in the same SiteInstance. 603 // Both contentses should now be in the same SiteInstance.
603 EXPECT_EQ(instance2a, instance2b); 604 EXPECT_EQ(instance2a, instance2b);
604 } 605 }
605 606
606 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, 607 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site,
607 // to determine whether a navigation is cross-site. 608 // to determine whether a navigation is cross-site.
608 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { 609 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) {
609 contents()->transition_cross_site = true; 610 contents()->transition_cross_site = true;
610 RenderViewHost* orig_rvh = rvh(); 611 RenderViewHost* orig_rvh = rvh();
611 SiteInstance* instance1 = contents()->GetSiteInstance(); 612 SiteInstance* instance1 = contents()->GetSiteInstance();
612 613
613 // Navigate to URL. 614 // Navigate to URL.
614 const GURL url("http://www.google.com"); 615 const GURL url("http://www.google.com");
615 controller().LoadURL( 616 controller().LoadURL(
616 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 617 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
617 contents()->TestDidNavigate( 618 contents()->TestDidNavigate(
618 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 619 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
619 620
620 // Open a related contents to a second site. 621 // Open a related contents to a second site.
621 TestWebContents contents2(browser_context_.get(), instance1); 622 scoped_ptr<TestWebContents> contents2(
622 contents2.transition_cross_site = true; 623 TestWebContents::Create(browser_context_.get(), instance1));
624 contents2->transition_cross_site = true;
623 const GURL url2("http://www.yahoo.com"); 625 const GURL url2("http://www.yahoo.com");
624 contents2.GetController().LoadURL(url2, content::Referrer(), 626 contents2->GetController().LoadURL(url2, content::Referrer(),
625 content::PAGE_TRANSITION_TYPED, 627 content::PAGE_TRANSITION_TYPED,
626 std::string()); 628 std::string());
627 // The first RVH in contents2 isn't live yet, so we shortcut the cross site 629 // The first RVH in contents2 isn't live yet, so we shortcut the cross site
628 // pending. 630 // pending.
629 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( 631 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>(
630 contents2.GetRenderViewHost()); 632 contents2->GetRenderViewHost());
631 EXPECT_FALSE(contents2.cross_navigation_pending()); 633 EXPECT_FALSE(contents2->cross_navigation_pending());
632 contents2.TestDidNavigate(rvh2, 2, url2, content::PAGE_TRANSITION_TYPED); 634 contents2->TestDidNavigate(rvh2, 2, url2, content::PAGE_TRANSITION_TYPED);
633 SiteInstance* instance2 = contents2.GetSiteInstance(); 635 SiteInstance* instance2 = contents2->GetSiteInstance();
634 EXPECT_NE(instance1, instance2); 636 EXPECT_NE(instance1, instance2);
635 EXPECT_FALSE(contents2.cross_navigation_pending()); 637 EXPECT_FALSE(contents2->cross_navigation_pending());
636 638
637 // Simulate a link click in first contents to second site. Doesn't switch 639 // Simulate a link click in first contents to second site. Doesn't switch
638 // SiteInstances, because we don't intercept WebKit navigations. 640 // SiteInstances, because we don't intercept WebKit navigations.
639 contents()->TestDidNavigate( 641 contents()->TestDidNavigate(
640 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED); 642 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED);
641 SiteInstance* instance3 = contents()->GetSiteInstance(); 643 SiteInstance* instance3 = contents()->GetSiteInstance();
642 EXPECT_EQ(instance1, instance3); 644 EXPECT_EQ(instance1, instance3);
643 EXPECT_FALSE(contents()->cross_navigation_pending()); 645 EXPECT_FALSE(contents()->cross_navigation_pending());
644 646
645 // Navigate to the new site. Doesn't switch SiteInstancees, because we 647 // Navigate to the new site. Doesn't switch SiteInstancees, because we
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 TestInterstitialPageStateGuard state_guard(interstitial); 1870 TestInterstitialPageStateGuard state_guard(interstitial);
1869 interstitial->Show(); 1871 interstitial->Show();
1870 interstitial->TestDidNavigate(1, url2); 1872 interstitial->TestDidNavigate(1, url2);
1871 EXPECT_TRUE(interstitial->is_showing()); 1873 EXPECT_TRUE(interstitial->is_showing());
1872 EXPECT_EQ(2, controller().GetEntryCount()); 1874 EXPECT_EQ(2, controller().GetEntryCount());
1873 1875
1874 // Create another NavigationController. 1876 // Create another NavigationController.
1875 GURL url3("http://foo2"); 1877 GURL url3("http://foo2");
1876 scoped_ptr<TestWebContents> other_contents( 1878 scoped_ptr<TestWebContents> other_contents(
1877 static_cast<TestWebContents*>(CreateTestWebContents())); 1879 static_cast<TestWebContents*>(CreateTestWebContents()));
1878 NavigationControllerImpl& other_controller = 1880 NavigationControllerImpl& other_controller = other_contents->GetController();
1879 other_contents->GetControllerImpl();
1880 other_contents->NavigateAndCommit(url3); 1881 other_contents->NavigateAndCommit(url3);
1881 other_contents->ExpectSetHistoryLengthAndPrune( 1882 other_contents->ExpectSetHistoryLengthAndPrune(
1882 NavigationEntryImpl::FromNavigationEntry( 1883 NavigationEntryImpl::FromNavigationEntry(
1883 other_controller.GetEntryAtIndex(0))->site_instance(), 1, 1884 other_controller.GetEntryAtIndex(0))->site_instance(), 1,
1884 other_controller.GetEntryAtIndex(0)->GetPageID()); 1885 other_controller.GetEntryAtIndex(0)->GetPageID());
1885 other_controller.CopyStateFromAndPrune(&controller()); 1886 other_controller.CopyStateFromAndPrune(&controller());
1886 1887
1887 // The merged controller should only have two entries: url1 and url2. 1888 // The merged controller should only have two entries: url1 and url2.
1888 ASSERT_EQ(2, other_controller.GetEntryCount()); 1889 ASSERT_EQ(2, other_controller.GetEntryCount());
1889 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); 1890 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
1890 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 1891 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
1891 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 1892 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
1892 1893
1893 // And the merged controller shouldn't be showing an interstitial. 1894 // And the merged controller shouldn't be showing an interstitial.
1894 EXPECT_FALSE(other_contents->ShowingInterstitialPage()); 1895 EXPECT_FALSE(other_contents->ShowingInterstitialPage());
1895 } 1896 }
1896 1897
1897 // Makes sure that CopyStateFromAndPrune does the right thing if the object 1898 // Makes sure that CopyStateFromAndPrune does the right thing if the object
1898 // CopyStateFromAndPrune is invoked on is showing an interstitial. 1899 // CopyStateFromAndPrune is invoked on is showing an interstitial.
1899 TEST_F(WebContentsImplTest, CopyStateFromAndPruneTargetInterstitial) { 1900 TEST_F(WebContentsImplTest, CopyStateFromAndPruneTargetInterstitial) {
1900 // Navigate to a page. 1901 // Navigate to a page.
1901 GURL url1("http://www.google.com"); 1902 GURL url1("http://www.google.com");
1902 contents()->NavigateAndCommit(url1); 1903 contents()->NavigateAndCommit(url1);
1903 1904
1904 // Create another NavigationController. 1905 // Create another NavigationController.
1905 scoped_ptr<TestWebContents> other_contents( 1906 scoped_ptr<TestWebContents> other_contents(
1906 static_cast<TestWebContents*>(CreateTestWebContents())); 1907 static_cast<TestWebContents*>(CreateTestWebContents()));
1907 NavigationControllerImpl& other_controller = 1908 NavigationControllerImpl& other_controller = other_contents->GetController();
1908 other_contents->GetControllerImpl();
1909 1909
1910 // Navigate it to url2. 1910 // Navigate it to url2.
1911 GURL url2("http://foo2"); 1911 GURL url2("http://foo2");
1912 other_contents->NavigateAndCommit(url2); 1912 other_contents->NavigateAndCommit(url2);
1913 1913
1914 // Show an interstitial. 1914 // Show an interstitial.
1915 TestInterstitialPage::InterstitialState state = 1915 TestInterstitialPage::InterstitialState state =
1916 TestInterstitialPage::UNDECIDED; 1916 TestInterstitialPage::UNDECIDED;
1917 bool deleted = false; 1917 bool deleted = false;
1918 GURL url3("http://interstitial"); 1918 GURL url3("http://interstitial");
(...skipping 20 matching lines...) Expand all
1939 // It should have a transient entry. 1939 // It should have a transient entry.
1940 EXPECT_TRUE(other_controller.GetTransientEntry()); 1940 EXPECT_TRUE(other_controller.GetTransientEntry());
1941 1941
1942 // And the interstitial should be showing. 1942 // And the interstitial should be showing.
1943 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); 1943 EXPECT_TRUE(other_contents->ShowingInterstitialPage());
1944 1944
1945 // And the interstitial should do a reload on don't proceed. 1945 // And the interstitial should do a reload on don't proceed.
1946 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( 1946 EXPECT_TRUE(static_cast<InterstitialPageImpl*>(
1947 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); 1947 other_contents->GetInterstitialPage())->reload_on_dont_proceed());
1948 } 1948 }
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/public/browser/browser_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698