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 <stdint.h> | 5 #include <stdint.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 // Navigate to URL. First URL should use first RenderViewHost. | 680 // Navigate to URL. First URL should use first RenderViewHost. |
681 const GURL url("http://www.google.com"); | 681 const GURL url("http://www.google.com"); |
682 controller().LoadURL( | 682 controller().LoadURL( |
683 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 683 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
684 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 684 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
685 contents()->GetMainFrame()->PrepareForCommit(); | 685 contents()->GetMainFrame()->PrepareForCommit(); |
686 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url, | 686 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url, |
687 ui::PAGE_TRANSITION_TYPED); | 687 ui::PAGE_TRANSITION_TYPED); |
688 | 688 |
689 // Open a new contents with the same SiteInstance, navigated to the same site. | 689 // Open a new contents with the same SiteInstance, navigated to the same site. |
690 scoped_ptr<TestWebContents> contents2( | 690 std::unique_ptr<TestWebContents> contents2( |
691 TestWebContents::Create(browser_context(), instance1)); | 691 TestWebContents::Create(browser_context(), instance1)); |
692 contents2->GetController().LoadURL(url, Referrer(), | 692 contents2->GetController().LoadURL(url, Referrer(), |
693 ui::PAGE_TRANSITION_TYPED, | 693 ui::PAGE_TRANSITION_TYPED, |
694 std::string()); | 694 std::string()); |
695 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID(); | 695 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID(); |
696 contents2->GetMainFrame()->PrepareForCommit(); | 696 contents2->GetMainFrame()->PrepareForCommit(); |
697 // Need this page id to be 2 since the site instance is the same (which is the | 697 // Need this page id to be 2 since the site instance is the same (which is the |
698 // scope of page IDs) and we want to consider this a new page. | 698 // scope of page IDs) and we want to consider this a new page. |
699 contents2->TestDidNavigate(contents2->GetMainFrame(), 2, entry_id, true, url, | 699 contents2->TestDidNavigate(contents2->GetMainFrame(), 2, entry_id, true, url, |
700 ui::PAGE_TRANSITION_TYPED); | 700 ui::PAGE_TRANSITION_TYPED); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 TEST_F(WebContentsImplTest, NavigateFromRestoredSitelessUrl) { | 841 TEST_F(WebContentsImplTest, NavigateFromRestoredSitelessUrl) { |
842 WebContentsImplTestBrowserClient browser_client; | 842 WebContentsImplTestBrowserClient browser_client; |
843 SetBrowserClientForTesting(&browser_client); | 843 SetBrowserClientForTesting(&browser_client); |
844 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); | 844 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); |
845 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 845 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
846 | 846 |
847 // Restore a navigation entry for URL that should not assign site to the | 847 // Restore a navigation entry for URL that should not assign site to the |
848 // SiteInstance. | 848 // SiteInstance. |
849 browser_client.set_assign_site_for_url(false); | 849 browser_client.set_assign_site_for_url(false); |
850 const GURL native_url("non-site-url://stuffandthings"); | 850 const GURL native_url("non-site-url://stuffandthings"); |
851 std::vector<scoped_ptr<NavigationEntry>> entries; | 851 std::vector<std::unique_ptr<NavigationEntry>> entries; |
852 scoped_ptr<NavigationEntry> new_entry = | 852 std::unique_ptr<NavigationEntry> new_entry = |
853 NavigationControllerImpl::CreateNavigationEntry( | 853 NavigationControllerImpl::CreateNavigationEntry( |
854 native_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, | 854 native_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, |
855 std::string(), browser_context()); | 855 std::string(), browser_context()); |
856 new_entry->SetPageID(0); | 856 new_entry->SetPageID(0); |
857 entries.push_back(std::move(new_entry)); | 857 entries.push_back(std::move(new_entry)); |
858 controller().Restore( | 858 controller().Restore( |
859 0, | 859 0, |
860 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 860 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
861 &entries); | 861 &entries); |
862 ASSERT_EQ(0u, entries.size()); | 862 ASSERT_EQ(0u, entries.size()); |
(...skipping 28 matching lines...) Expand all Loading... |
891 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) { | 891 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) { |
892 WebContentsImplTestBrowserClient browser_client; | 892 WebContentsImplTestBrowserClient browser_client; |
893 SetBrowserClientForTesting(&browser_client); | 893 SetBrowserClientForTesting(&browser_client); |
894 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); | 894 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); |
895 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 895 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
896 | 896 |
897 // Restore a navigation entry for a regular URL ensuring that the embedder | 897 // Restore a navigation entry for a regular URL ensuring that the embedder |
898 // ShouldAssignSiteForUrl override is disabled (i.e. returns true). | 898 // ShouldAssignSiteForUrl override is disabled (i.e. returns true). |
899 browser_client.set_assign_site_for_url(true); | 899 browser_client.set_assign_site_for_url(true); |
900 const GURL regular_url("http://www.yahoo.com"); | 900 const GURL regular_url("http://www.yahoo.com"); |
901 std::vector<scoped_ptr<NavigationEntry>> entries; | 901 std::vector<std::unique_ptr<NavigationEntry>> entries; |
902 scoped_ptr<NavigationEntry> new_entry = | 902 std::unique_ptr<NavigationEntry> new_entry = |
903 NavigationControllerImpl::CreateNavigationEntry( | 903 NavigationControllerImpl::CreateNavigationEntry( |
904 regular_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, | 904 regular_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, |
905 std::string(), browser_context()); | 905 std::string(), browser_context()); |
906 new_entry->SetPageID(0); | 906 new_entry->SetPageID(0); |
907 entries.push_back(std::move(new_entry)); | 907 entries.push_back(std::move(new_entry)); |
908 controller().Restore( | 908 controller().Restore( |
909 0, | 909 0, |
910 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 910 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
911 &entries); | 911 &entries); |
912 ASSERT_EQ(0u, entries.size()); | 912 ASSERT_EQ(0u, entries.size()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 const GURL url2("http://www.yahoo.com"); | 953 const GURL url2("http://www.yahoo.com"); |
954 controller().LoadURL( | 954 controller().LoadURL( |
955 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 955 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
956 orig_rfh->PrepareForCommit(); | 956 orig_rfh->PrepareForCommit(); |
957 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); | 957 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); |
958 SiteInstance* instance = pending_rfh->GetSiteInstance(); | 958 SiteInstance* instance = pending_rfh->GetSiteInstance(); |
959 | 959 |
960 // While it is still pending, simulate opening a new tab with the first tab | 960 // While it is still pending, simulate opening a new tab with the first tab |
961 // as its opener. This will call CreateOpenerProxies on the opener to ensure | 961 // as its opener. This will call CreateOpenerProxies on the opener to ensure |
962 // that an RVH exists. | 962 // that an RVH exists. |
963 scoped_ptr<TestWebContents> popup( | 963 std::unique_ptr<TestWebContents> popup( |
964 TestWebContents::Create(browser_context(), instance)); | 964 TestWebContents::Create(browser_context(), instance)); |
965 popup->SetOpener(contents()); | 965 popup->SetOpener(contents()); |
966 contents()->GetRenderManager()->CreateOpenerProxies(instance, nullptr); | 966 contents()->GetRenderManager()->CreateOpenerProxies(instance, nullptr); |
967 | 967 |
968 // If swapped out is forbidden, a new proxy should be created for the opener | 968 // If swapped out is forbidden, a new proxy should be created for the opener |
969 // in |instance|, and we should ensure that its routing ID is returned here. | 969 // in |instance|, and we should ensure that its routing ID is returned here. |
970 // Otherwise, we should find the pending RFH and not create a new proxy. | 970 // Otherwise, we should find the pending RFH and not create a new proxy. |
971 int opener_frame_routing_id = | 971 int opener_frame_routing_id = |
972 popup->GetRenderManager()->GetOpenerRoutingID(instance); | 972 popup->GetRenderManager()->GetOpenerRoutingID(instance); |
973 RenderFrameProxyHost* proxy = | 973 RenderFrameProxyHost* proxy = |
(...skipping 18 matching lines...) Expand all Loading... |
992 // Navigate to URL. | 992 // Navigate to URL. |
993 const GURL url("http://www.google.com"); | 993 const GURL url("http://www.google.com"); |
994 controller().LoadURL( | 994 controller().LoadURL( |
995 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 995 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
996 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 996 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
997 contents()->GetMainFrame()->PrepareForCommit(); | 997 contents()->GetMainFrame()->PrepareForCommit(); |
998 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url, | 998 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url, |
999 ui::PAGE_TRANSITION_TYPED); | 999 ui::PAGE_TRANSITION_TYPED); |
1000 | 1000 |
1001 // Open a related contents to a second site. | 1001 // Open a related contents to a second site. |
1002 scoped_ptr<TestWebContents> contents2( | 1002 std::unique_ptr<TestWebContents> contents2( |
1003 TestWebContents::Create(browser_context(), instance1)); | 1003 TestWebContents::Create(browser_context(), instance1)); |
1004 const GURL url2("http://www.yahoo.com"); | 1004 const GURL url2("http://www.yahoo.com"); |
1005 contents2->GetController().LoadURL(url2, Referrer(), | 1005 contents2->GetController().LoadURL(url2, Referrer(), |
1006 ui::PAGE_TRANSITION_TYPED, | 1006 ui::PAGE_TRANSITION_TYPED, |
1007 std::string()); | 1007 std::string()); |
1008 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID(); | 1008 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID(); |
1009 contents2->GetMainFrame()->PrepareForCommit(); | 1009 contents2->GetMainFrame()->PrepareForCommit(); |
1010 | 1010 |
1011 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 1011 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
1012 // pending. | 1012 // pending. |
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2537 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 2537 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
2538 TestInterstitialPageStateGuard state_guard(interstitial); | 2538 TestInterstitialPageStateGuard state_guard(interstitial); |
2539 interstitial->Show(); | 2539 interstitial->Show(); |
2540 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID(); | 2540 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID(); |
2541 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2); | 2541 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2); |
2542 EXPECT_TRUE(interstitial->is_showing()); | 2542 EXPECT_TRUE(interstitial->is_showing()); |
2543 EXPECT_EQ(2, controller().GetEntryCount()); | 2543 EXPECT_EQ(2, controller().GetEntryCount()); |
2544 | 2544 |
2545 // Create another NavigationController. | 2545 // Create another NavigationController. |
2546 GURL url3("http://foo2"); | 2546 GURL url3("http://foo2"); |
2547 scoped_ptr<TestWebContents> other_contents( | 2547 std::unique_ptr<TestWebContents> other_contents( |
2548 static_cast<TestWebContents*>(CreateTestWebContents())); | 2548 static_cast<TestWebContents*>(CreateTestWebContents())); |
2549 NavigationControllerImpl& other_controller = other_contents->GetController(); | 2549 NavigationControllerImpl& other_controller = other_contents->GetController(); |
2550 other_contents->NavigateAndCommit(url3); | 2550 other_contents->NavigateAndCommit(url3); |
2551 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); | 2551 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); |
2552 other_controller.CopyStateFromAndPrune(&controller(), false); | 2552 other_controller.CopyStateFromAndPrune(&controller(), false); |
2553 | 2553 |
2554 // The merged controller should only have two entries: url1 and url2. | 2554 // The merged controller should only have two entries: url1 and url2. |
2555 ASSERT_EQ(2, other_controller.GetEntryCount()); | 2555 ASSERT_EQ(2, other_controller.GetEntryCount()); |
2556 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); | 2556 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); |
2557 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 2557 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
2558 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); | 2558 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
2559 | 2559 |
2560 // And the merged controller shouldn't be showing an interstitial. | 2560 // And the merged controller shouldn't be showing an interstitial. |
2561 EXPECT_FALSE(other_contents->ShowingInterstitialPage()); | 2561 EXPECT_FALSE(other_contents->ShowingInterstitialPage()); |
2562 } | 2562 } |
2563 | 2563 |
2564 // Makes sure that CopyStateFromAndPrune cannot be called if the target is | 2564 // Makes sure that CopyStateFromAndPrune cannot be called if the target is |
2565 // showing an interstitial. | 2565 // showing an interstitial. |
2566 TEST_F(WebContentsImplTest, CopyStateFromAndPruneTargetInterstitial) { | 2566 TEST_F(WebContentsImplTest, CopyStateFromAndPruneTargetInterstitial) { |
2567 // Navigate to a page. | 2567 // Navigate to a page. |
2568 GURL url1("http://www.google.com"); | 2568 GURL url1("http://www.google.com"); |
2569 contents()->NavigateAndCommit(url1); | 2569 contents()->NavigateAndCommit(url1); |
2570 | 2570 |
2571 // Create another NavigationController. | 2571 // Create another NavigationController. |
2572 scoped_ptr<TestWebContents> other_contents( | 2572 std::unique_ptr<TestWebContents> other_contents( |
2573 static_cast<TestWebContents*>(CreateTestWebContents())); | 2573 static_cast<TestWebContents*>(CreateTestWebContents())); |
2574 NavigationControllerImpl& other_controller = other_contents->GetController(); | 2574 NavigationControllerImpl& other_controller = other_contents->GetController(); |
2575 | 2575 |
2576 // Navigate it to url2. | 2576 // Navigate it to url2. |
2577 GURL url2("http://foo2"); | 2577 GURL url2("http://foo2"); |
2578 other_contents->NavigateAndCommit(url2); | 2578 other_contents->NavigateAndCommit(url2); |
2579 | 2579 |
2580 // Show an interstitial. | 2580 // Show an interstitial. |
2581 TestInterstitialPage::InterstitialState state = | 2581 TestInterstitialPage::InterstitialState state = |
2582 TestInterstitialPage::INVALID; | 2582 TestInterstitialPage::INVALID; |
(...skipping 29 matching lines...) Expand all Loading... |
2612 // will use the given URL to create the NavigationEntry as well, and that | 2612 // will use the given URL to create the NavigationEntry as well, and that |
2613 // entry should contain the filtered URL. | 2613 // entry should contain the filtered URL. |
2614 contents()->NavigateAndCommit(url_normalized); | 2614 contents()->NavigateAndCommit(url_normalized); |
2615 | 2615 |
2616 // Check that an IPC with about:whatever is correctly normalized. | 2616 // Check that an IPC with about:whatever is correctly normalized. |
2617 contents()->TestDidFinishLoad(url_from_ipc); | 2617 contents()->TestDidFinishLoad(url_from_ipc); |
2618 | 2618 |
2619 EXPECT_EQ(url_normalized, observer.last_url()); | 2619 EXPECT_EQ(url_normalized, observer.last_url()); |
2620 | 2620 |
2621 // Create and navigate another WebContents. | 2621 // Create and navigate another WebContents. |
2622 scoped_ptr<TestWebContents> other_contents( | 2622 std::unique_ptr<TestWebContents> other_contents( |
2623 static_cast<TestWebContents*>(CreateTestWebContents())); | 2623 static_cast<TestWebContents*>(CreateTestWebContents())); |
2624 TestWebContentsObserver other_observer(other_contents.get()); | 2624 TestWebContentsObserver other_observer(other_contents.get()); |
2625 other_contents->NavigateAndCommit(url_normalized); | 2625 other_contents->NavigateAndCommit(url_normalized); |
2626 | 2626 |
2627 // Check that an IPC with about:whatever is correctly normalized. | 2627 // Check that an IPC with about:whatever is correctly normalized. |
2628 other_contents->TestDidFailLoadWithError( | 2628 other_contents->TestDidFailLoadWithError( |
2629 url_from_ipc, 1, base::string16(), false); | 2629 url_from_ipc, 1, base::string16(), false); |
2630 EXPECT_EQ(url_normalized, other_observer.last_url()); | 2630 EXPECT_EQ(url_normalized, other_observer.last_url()); |
2631 } | 2631 } |
2632 | 2632 |
2633 // Test that if a pending contents is deleted before it is shown, we don't | 2633 // Test that if a pending contents is deleted before it is shown, we don't |
2634 // crash. | 2634 // crash. |
2635 TEST_F(WebContentsImplTest, PendingContents) { | 2635 TEST_F(WebContentsImplTest, PendingContents) { |
2636 scoped_ptr<TestWebContents> other_contents( | 2636 std::unique_ptr<TestWebContents> other_contents( |
2637 static_cast<TestWebContents*>(CreateTestWebContents())); | 2637 static_cast<TestWebContents*>(CreateTestWebContents())); |
2638 contents()->AddPendingContents(other_contents.get()); | 2638 contents()->AddPendingContents(other_contents.get()); |
2639 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); | 2639 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); |
2640 other_contents.reset(); | 2640 other_contents.reset(); |
2641 EXPECT_EQ(nullptr, contents()->GetCreatedWindow(route_id)); | 2641 EXPECT_EQ(nullptr, contents()->GetCreatedWindow(route_id)); |
2642 } | 2642 } |
2643 | 2643 |
2644 TEST_F(WebContentsImplTest, CapturerOverridesPreferredSize) { | 2644 TEST_F(WebContentsImplTest, CapturerOverridesPreferredSize) { |
2645 const gfx::Size original_preferred_size(1024, 768); | 2645 const gfx::Size original_preferred_size(1024, 768); |
2646 contents()->UpdatePreferredSize(original_preferred_size); | 2646 contents()->UpdatePreferredSize(original_preferred_size); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2786 int contents_zoom_changed_call_count_; | 2786 int contents_zoom_changed_call_count_; |
2787 bool last_zoom_in_; | 2787 bool last_zoom_in_; |
2788 | 2788 |
2789 DISALLOW_COPY_AND_ASSIGN(ContentsZoomChangedDelegate); | 2789 DISALLOW_COPY_AND_ASSIGN(ContentsZoomChangedDelegate); |
2790 }; | 2790 }; |
2791 | 2791 |
2792 // Tests that some mouseehweel events get turned into browser zoom requests. | 2792 // Tests that some mouseehweel events get turned into browser zoom requests. |
2793 TEST_F(WebContentsImplTest, HandleWheelEvent) { | 2793 TEST_F(WebContentsImplTest, HandleWheelEvent) { |
2794 using blink::WebInputEvent; | 2794 using blink::WebInputEvent; |
2795 | 2795 |
2796 scoped_ptr<ContentsZoomChangedDelegate> delegate( | 2796 std::unique_ptr<ContentsZoomChangedDelegate> delegate( |
2797 new ContentsZoomChangedDelegate()); | 2797 new ContentsZoomChangedDelegate()); |
2798 contents()->SetDelegate(delegate.get()); | 2798 contents()->SetDelegate(delegate.get()); |
2799 | 2799 |
2800 int modifiers = 0; | 2800 int modifiers = 0; |
2801 // Verify that normal mouse wheel events do nothing to change the zoom level. | 2801 // Verify that normal mouse wheel events do nothing to change the zoom level. |
2802 blink::WebMouseWheelEvent event = | 2802 blink::WebMouseWheelEvent event = |
2803 SyntheticWebMouseWheelEventBuilder::Build(0, 0, 0, 1, modifiers, false); | 2803 SyntheticWebMouseWheelEventBuilder::Build(0, 0, 0, 1, modifiers, false); |
2804 EXPECT_FALSE(contents()->HandleWheelEvent(event)); | 2804 EXPECT_FALSE(contents()->HandleWheelEvent(event)); |
2805 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | 2805 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
2806 | 2806 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2866 // SiteInstances and includes WebContents that have not navigated yet. | 2866 // SiteInstances and includes WebContents that have not navigated yet. |
2867 TEST_F(WebContentsImplTest, ActiveContentsCountBasic) { | 2867 TEST_F(WebContentsImplTest, ActiveContentsCountBasic) { |
2868 scoped_refptr<SiteInstance> instance1( | 2868 scoped_refptr<SiteInstance> instance1( |
2869 SiteInstance::CreateForURL(browser_context(), GURL("http://a.com"))); | 2869 SiteInstance::CreateForURL(browser_context(), GURL("http://a.com"))); |
2870 scoped_refptr<SiteInstance> instance2( | 2870 scoped_refptr<SiteInstance> instance2( |
2871 instance1->GetRelatedSiteInstance(GURL("http://b.com"))); | 2871 instance1->GetRelatedSiteInstance(GURL("http://b.com"))); |
2872 | 2872 |
2873 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); | 2873 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); |
2874 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); | 2874 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); |
2875 | 2875 |
2876 scoped_ptr<TestWebContents> contents1( | 2876 std::unique_ptr<TestWebContents> contents1( |
2877 TestWebContents::Create(browser_context(), instance1.get())); | 2877 TestWebContents::Create(browser_context(), instance1.get())); |
2878 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); | 2878 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); |
2879 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); | 2879 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); |
2880 | 2880 |
2881 scoped_ptr<TestWebContents> contents2( | 2881 std::unique_ptr<TestWebContents> contents2( |
2882 TestWebContents::Create(browser_context(), instance1.get())); | 2882 TestWebContents::Create(browser_context(), instance1.get())); |
2883 EXPECT_EQ(2u, instance1->GetRelatedActiveContentsCount()); | 2883 EXPECT_EQ(2u, instance1->GetRelatedActiveContentsCount()); |
2884 EXPECT_EQ(2u, instance2->GetRelatedActiveContentsCount()); | 2884 EXPECT_EQ(2u, instance2->GetRelatedActiveContentsCount()); |
2885 | 2885 |
2886 contents1.reset(); | 2886 contents1.reset(); |
2887 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); | 2887 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); |
2888 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); | 2888 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); |
2889 | 2889 |
2890 contents2.reset(); | 2890 contents2.reset(); |
2891 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); | 2891 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); |
2892 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); | 2892 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); |
2893 } | 2893 } |
2894 | 2894 |
2895 // Tests that GetRelatedActiveContentsCount is preserved correctly across | 2895 // Tests that GetRelatedActiveContentsCount is preserved correctly across |
2896 // same-site and cross-site navigations. | 2896 // same-site and cross-site navigations. |
2897 TEST_F(WebContentsImplTest, ActiveContentsCountNavigate) { | 2897 TEST_F(WebContentsImplTest, ActiveContentsCountNavigate) { |
2898 scoped_refptr<SiteInstance> instance( | 2898 scoped_refptr<SiteInstance> instance( |
2899 SiteInstance::Create(browser_context())); | 2899 SiteInstance::Create(browser_context())); |
2900 | 2900 |
2901 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2901 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2902 | 2902 |
2903 scoped_ptr<TestWebContents> contents( | 2903 std::unique_ptr<TestWebContents> contents( |
2904 TestWebContents::Create(browser_context(), instance.get())); | 2904 TestWebContents::Create(browser_context(), instance.get())); |
2905 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2905 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2906 | 2906 |
2907 // Navigate to a URL. | 2907 // Navigate to a URL. |
2908 contents->GetController().LoadURL(GURL("http://a.com/1"), | 2908 contents->GetController().LoadURL(GURL("http://a.com/1"), |
2909 Referrer(), | 2909 Referrer(), |
2910 ui::PAGE_TRANSITION_TYPED, | 2910 ui::PAGE_TRANSITION_TYPED, |
2911 std::string()); | 2911 std::string()); |
2912 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2912 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2913 contents->CommitPendingNavigation(); | 2913 contents->CommitPendingNavigation(); |
(...skipping 27 matching lines...) Expand all Loading... |
2941 } | 2941 } |
2942 | 2942 |
2943 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes | 2943 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes |
2944 // from WebUI. | 2944 // from WebUI. |
2945 TEST_F(WebContentsImplTest, ActiveContentsCountChangeBrowsingInstance) { | 2945 TEST_F(WebContentsImplTest, ActiveContentsCountChangeBrowsingInstance) { |
2946 scoped_refptr<SiteInstance> instance( | 2946 scoped_refptr<SiteInstance> instance( |
2947 SiteInstance::Create(browser_context())); | 2947 SiteInstance::Create(browser_context())); |
2948 | 2948 |
2949 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2949 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2950 | 2950 |
2951 scoped_ptr<TestWebContents> contents( | 2951 std::unique_ptr<TestWebContents> contents( |
2952 TestWebContents::Create(browser_context(), instance.get())); | 2952 TestWebContents::Create(browser_context(), instance.get())); |
2953 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2953 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2954 | 2954 |
2955 // Navigate to a URL. | 2955 // Navigate to a URL. |
2956 contents->NavigateAndCommit(GURL("http://a.com")); | 2956 contents->NavigateAndCommit(GURL("http://a.com")); |
2957 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2957 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2958 | 2958 |
2959 // Navigate to a URL which sort of looks like a chrome:// url. | 2959 // Navigate to a URL which sort of looks like a chrome:// url. |
2960 contents->NavigateAndCommit(GURL("http://gpu")); | 2960 contents->NavigateAndCommit(GURL("http://gpu")); |
2961 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2961 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3440 // An automatic navigation. | 3440 // An automatic navigation. |
3441 contents()->GetMainFrame()->SendNavigateWithModificationCallback( | 3441 contents()->GetMainFrame()->SendNavigateWithModificationCallback( |
3442 2, 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); | 3442 2, 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); |
3443 | 3443 |
3444 EXPECT_EQ(1u, dialog_manager.reset_count()); | 3444 EXPECT_EQ(1u, dialog_manager.reset_count()); |
3445 | 3445 |
3446 contents()->SetJavaScriptDialogManagerForTesting(nullptr); | 3446 contents()->SetJavaScriptDialogManagerForTesting(nullptr); |
3447 } | 3447 } |
3448 | 3448 |
3449 } // namespace content | 3449 } // namespace content |
OLD | NEW |