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

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

Issue 15041004: Replace PruneAllButActive with PruneAllButVisible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update tests, mark TODOs Created 7 years, 7 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 2741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2752 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); 2752 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID());
2753 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); 2753 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1));
2754 2754
2755 scoped_ptr<TestWebContents> other_contents( 2755 scoped_ptr<TestWebContents> other_contents(
2756 static_cast<TestWebContents*>(CreateTestWebContents())); 2756 static_cast<TestWebContents*>(CreateTestWebContents()));
2757 NavigationControllerImpl& other_controller = other_contents->GetController(); 2757 NavigationControllerImpl& other_controller = other_contents->GetController();
2758 other_contents->NavigateAndCommit(url3); 2758 other_contents->NavigateAndCommit(url3);
2759 other_contents->ExpectSetHistoryLengthAndPrune( 2759 other_contents->ExpectSetHistoryLengthAndPrune(
2760 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 2760 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
2761 other_controller.GetEntryAtIndex(0)->GetPageID()); 2761 other_controller.GetEntryAtIndex(0)->GetPageID());
2762 other_controller.CopyStateFromAndPrune(&controller); 2762 EXPECT_TRUE(other_controller.CopyStateFromAndPrune(&controller));
2763 2763
2764 // other_controller should now contain the 3 urls: url1, url2 and url3. 2764 // other_controller should now contain the 3 urls: url1, url2 and url3.
2765 2765
2766 ASSERT_EQ(3, other_controller.GetEntryCount()); 2766 ASSERT_EQ(3, other_controller.GetEntryCount());
2767 2767
2768 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 2768 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
2769 2769
2770 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 2770 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
2771 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 2771 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
2772 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); 2772 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
2773 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); 2773 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID());
2774 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID()); 2774 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID());
2775 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); 2775 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
2776 2776
2777 // A new SiteInstance should be used for the new tab. 2777 // A new SiteInstance should be used for the new tab.
2778 SiteInstance* instance3 = 2778 SiteInstance* instance3 =
2779 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); 2779 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2));
2780 EXPECT_NE(instance3, instance1); 2780 EXPECT_NE(instance3, instance1);
2781 2781
2782 // The max page ID map should be copied over and updated with the max page ID 2782 // The max page ID map should be copied over and updated with the max page ID
2783 // from the current tab. 2783 // from the current tab.
2784 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); 2784 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1));
2785 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); 2785 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3));
2786 } 2786 }
2787 2787
2788 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in 2788 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry in
2789 // the target. 2789 // the target.
2790 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) { 2790 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) {
2791 NavigationControllerImpl& controller = controller_impl(); 2791 NavigationControllerImpl& controller = controller_impl();
2792 const GURL url1("http://foo1"); 2792 const GURL url1("http://foo1");
2793 const GURL url2("http://foo2"); 2793 const GURL url2("http://foo2");
2794 const GURL url3("http://foo3"); 2794 const GURL url3("http://foo3");
2795 2795
2796 NavigateAndCommit(url1); 2796 NavigateAndCommit(url1);
2797 NavigateAndCommit(url2); 2797 NavigateAndCommit(url2);
2798 controller.GoBack(); 2798 controller.GoBack();
2799 contents()->CommitPendingNavigation();
2799 2800
2800 scoped_ptr<TestWebContents> other_contents( 2801 scoped_ptr<TestWebContents> other_contents(
2801 static_cast<TestWebContents*>(CreateTestWebContents())); 2802 static_cast<TestWebContents*>(CreateTestWebContents()));
2802 NavigationControllerImpl& other_controller = other_contents->GetController(); 2803 NavigationControllerImpl& other_controller = other_contents->GetController();
2803 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); 2804 other_contents->NavigateAndCommit(url3);
2804 other_controller.CopyStateFromAndPrune(&controller); 2805 other_contents->ExpectSetHistoryLengthAndPrune(
2806 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
2807 other_controller.GetEntryAtIndex(0)->GetPageID());
2808 EXPECT_TRUE(other_controller.CopyStateFromAndPrune(&controller));
2805 2809
2806 // other_controller should now contain the 1 url: url1. 2810 // other_controller should now contain: url1, url3
2807 2811
2808 ASSERT_EQ(1, other_controller.GetEntryCount()); 2812 ASSERT_EQ(2, other_controller.GetEntryCount());
2809 2813 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex());
2810 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex());
2811 2814
2812 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 2815 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
2813 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); 2816 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
2817 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID());
2814 2818
2815 // The max page ID map should be copied over and updated with the max page ID 2819 // The max page ID map should be copied over and updated with the max page ID
2816 // from the current tab. 2820 // from the current tab.
2817 SiteInstance* instance1 = 2821 SiteInstance* instance1 =
2818 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); 2822 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1));
2819 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); 2823 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1));
2820 } 2824 }
2821 2825
2822 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in 2826 // Test CopyStateFromAndPrune with 2 urls, the last selected and 2 entries in
2823 // the target. 2827 // the target.
2824 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { 2828 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) {
2825 NavigationControllerImpl& controller = controller_impl(); 2829 NavigationControllerImpl& controller = controller_impl();
2826 const GURL url1("http://foo1"); 2830 const GURL url1("http://foo1");
2827 const GURL url2("http://foo2"); 2831 const GURL url2("http://foo2");
2828 const GURL url3("http://foo3"); 2832 const GURL url3("http://foo3");
2833 const GURL url4("http://foo4");
2834
2835 NavigateAndCommit(url1);
2836 NavigateAndCommit(url2);
2837
2838 scoped_ptr<TestWebContents> other_contents(
2839 static_cast<TestWebContents*>(CreateTestWebContents()));
2840 NavigationControllerImpl& other_controller = other_contents->GetController();
2841 other_contents->NavigateAndCommit(url3);
2842 other_contents->NavigateAndCommit(url4);
2843 other_contents->ExpectSetHistoryLengthAndPrune(
2844 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)), 2,
2845 other_controller.GetEntryAtIndex(0)->GetPageID());
2846 EXPECT_TRUE(other_controller.CopyStateFromAndPrune(&controller));
2847
2848 // other_controller should now contain: url1, url2, url4
2849
2850 ASSERT_EQ(3, other_controller.GetEntryCount());
2851 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
2852
2853 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
2854 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
2855 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
2856
2857 // The max page ID map should be copied over and updated with the max page ID
2858 // from the current tab.
2859 SiteInstance* instance1 =
2860 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2));
2861 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1));
2862 }
2863
2864 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry plus
2865 // a pending entry in the target.
2866 TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending) {
2867 NavigationControllerImpl& controller = controller_impl();
2868 const GURL url1("http://foo1");
2869 const GURL url2("http://foo2");
2870 const GURL url3("http://foo3");
2871 const GURL url4("http://foo4");
2829 2872
2830 NavigateAndCommit(url1); 2873 NavigateAndCommit(url1);
2831 NavigateAndCommit(url2); 2874 NavigateAndCommit(url2);
2832 controller.GoBack(); 2875 controller.GoBack();
2876 contents()->CommitPendingNavigation();
2833 2877
2834 scoped_ptr<TestWebContents> other_contents( 2878 scoped_ptr<TestWebContents> other_contents(
2835 static_cast<TestWebContents*>(CreateTestWebContents())); 2879 static_cast<TestWebContents*>(CreateTestWebContents()));
2836 NavigationControllerImpl& other_controller = other_contents->GetController(); 2880 NavigationControllerImpl& other_controller = other_contents->GetController();
2881 other_contents->NavigateAndCommit(url3);
2837 other_controller.LoadURL( 2882 other_controller.LoadURL(
2838 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 2883 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string());
2839 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); 2884 other_contents->ExpectSetHistoryLengthAndPrune(
2840 other_controller.CopyStateFromAndPrune(&controller); 2885 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1,
2886 other_controller.GetEntryAtIndex(0)->GetPageID());
2887 EXPECT_TRUE(other_controller.CopyStateFromAndPrune(&controller));
2841 2888
2842 // other_controller should now contain 1 entry for url1, and a pending entry 2889 // other_controller should now contain url1, url3, and a pending entry
2843 // for url3. 2890 // for url4.
2844 2891
2845 ASSERT_EQ(1, other_controller.GetEntryCount()); 2892 ASSERT_EQ(2, other_controller.GetEntryCount());
2846 2893 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
2847 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
2848 2894
2849 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 2895 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
2896 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
2850 2897
2851 // And there should be a pending entry for url3. 2898 // And there should be a pending entry for url4.
2852 ASSERT_TRUE(other_controller.GetPendingEntry()); 2899 ASSERT_TRUE(other_controller.GetPendingEntry());
2853 2900 EXPECT_EQ(url4, other_controller.GetPendingEntry()->GetURL());
2854 EXPECT_EQ(url3, other_controller.GetPendingEntry()->GetURL());
2855 2901
2856 // The max page ID map should be copied over and updated with the max page ID 2902 // The max page ID map should be copied over and updated with the max page ID
2857 // from the current tab. 2903 // from the current tab.
2858 SiteInstance* instance1 = 2904 SiteInstance* instance1 =
2859 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); 2905 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0));
2860 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); 2906 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1));
2861 } 2907 }
2862 2908
2909 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the
2910 // source, and 1 entry in the target. The back pending entry should be ignored.
2911 TEST_F(NavigationControllerTest, CopyStateFromAndPruneSourcePending) {
2912 NavigationControllerImpl& controller = controller_impl();
2913 const GURL url1("http://foo1");
2914 const GURL url2("http://foo2");
2915 const GURL url3("http://foo3");
2916
2917 NavigateAndCommit(url1);
2918 NavigateAndCommit(url2);
2919 controller.GoBack();
2920
2921 scoped_ptr<TestWebContents> other_contents(
2922 static_cast<TestWebContents*>(CreateTestWebContents()));
2923 NavigationControllerImpl& other_controller = other_contents->GetController();
2924 other_contents->NavigateAndCommit(url3);
2925 other_contents->ExpectSetHistoryLengthAndPrune(
2926 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
2927 other_controller.GetEntryAtIndex(0)->GetPageID());
2928 EXPECT_TRUE(other_controller.CopyStateFromAndPrune(&controller));
2929
2930 // other_controller should now contain: url1, url2, url3
2931
2932 ASSERT_EQ(3, other_controller.GetEntryCount());
2933 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
2934
2935 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
2936 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
2937 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
2938 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
2939
2940 // The max page ID map should be copied over and updated with the max page ID
2941 // from the current tab.
2942 SiteInstance* instance1 =
2943 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2));
2944 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1));
2945 }
2946
2863 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, 2947 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest,
2864 // when the max entry count is 3. We should prune one entry. 2948 // when the max entry count is 3. We should prune one entry.
2865 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) { 2949 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) {
2866 NavigationControllerImpl& controller = controller_impl(); 2950 NavigationControllerImpl& controller = controller_impl();
2867 size_t original_count = NavigationControllerImpl::max_entry_count(); 2951 size_t original_count = NavigationControllerImpl::max_entry_count();
2868 const int kMaxEntryCount = 3; 2952 const int kMaxEntryCount = 3;
2869 2953
2870 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); 2954 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount);
2871 2955
2872 const GURL url1("http://foo/1"); 2956 const GURL url1("http://foo/1");
2873 const GURL url2("http://foo/2"); 2957 const GURL url2("http://foo/2");
2874 const GURL url3("http://foo/3"); 2958 const GURL url3("http://foo/3");
2875 const GURL url4("http://foo/4"); 2959 const GURL url4("http://foo/4");
2876 2960
2877 // Create a PrunedListener to observe prune notifications. 2961 // Create a PrunedListener to observe prune notifications.
2878 PrunedListener listener(&controller); 2962 PrunedListener listener(&controller);
2879 2963
2880 NavigateAndCommit(url1); 2964 NavigateAndCommit(url1);
2881 NavigateAndCommit(url2); 2965 NavigateAndCommit(url2);
2882 NavigateAndCommit(url3); 2966 NavigateAndCommit(url3);
2883 2967
2884 scoped_ptr<TestWebContents> other_contents( 2968 scoped_ptr<TestWebContents> other_contents(
2885 static_cast<TestWebContents*>(CreateTestWebContents())); 2969 static_cast<TestWebContents*>(CreateTestWebContents()));
2886 NavigationControllerImpl& other_controller = other_contents->GetController(); 2970 NavigationControllerImpl& other_controller = other_contents->GetController();
2887 other_contents->NavigateAndCommit(url4); 2971 other_contents->NavigateAndCommit(url4);
2888 other_contents->ExpectSetHistoryLengthAndPrune( 2972 other_contents->ExpectSetHistoryLengthAndPrune(
2889 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, 2973 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2,
2890 other_controller.GetEntryAtIndex(0)->GetPageID()); 2974 other_controller.GetEntryAtIndex(0)->GetPageID());
2891 other_controller.CopyStateFromAndPrune(&controller); 2975 EXPECT_TRUE(other_controller.CopyStateFromAndPrune(&controller));
2892 2976
2893 // We should have received a pruned notification. 2977 // We should have received a pruned notification.
2894 EXPECT_EQ(1, listener.notification_count_); 2978 EXPECT_EQ(1, listener.notification_count_);
2895 EXPECT_TRUE(listener.details_.from_front); 2979 EXPECT_TRUE(listener.details_.from_front);
2896 EXPECT_EQ(1, listener.details_.count); 2980 EXPECT_EQ(1, listener.details_.count);
2897 2981
2898 // other_controller should now contain only 3 urls: url2, url3 and url4. 2982 // other_controller should now contain only 3 urls: url2, url3 and url4.
2899 2983
2900 ASSERT_EQ(3, other_controller.GetEntryCount()); 2984 ASSERT_EQ(3, other_controller.GetEntryCount());
2901 2985
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 EXPECT_EQ(url3, nav_params.a.url); 3037 EXPECT_EQ(url3, nav_params.a.url);
2954 process()->sink().ClearMessages(); 3038 process()->sink().ClearMessages();
2955 3039
2956 // Make sure an extravagant history.go() doesn't break. 3040 // Make sure an extravagant history.go() doesn't break.
2957 contents()->OnGoToEntryAtOffset(120); // Out of bounds. 3041 contents()->OnGoToEntryAtOffset(120); // Out of bounds.
2958 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3042 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2959 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); 3043 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID);
2960 EXPECT_TRUE(message == NULL); 3044 EXPECT_TRUE(message == NULL);
2961 } 3045 }
2962 3046
2963 // Test call to PruneAllButActive for the only entry. 3047 // Test call to PruneAllButVisible for the only entry.
2964 TEST_F(NavigationControllerTest, PruneAllButActiveForSingle) { 3048 TEST_F(NavigationControllerTest, PruneAllButVisibleForSingle) {
2965 NavigationControllerImpl& controller = controller_impl(); 3049 NavigationControllerImpl& controller = controller_impl();
2966 const GURL url1("http://foo1"); 3050 const GURL url1("http://foo1");
2967 NavigateAndCommit(url1); 3051 NavigateAndCommit(url1);
2968 3052
2969 contents()->ExpectSetHistoryLengthAndPrune( 3053 contents()->ExpectSetHistoryLengthAndPrune(
2970 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, 3054 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0,
2971 controller.GetEntryAtIndex(0)->GetPageID()); 3055 controller.GetEntryAtIndex(0)->GetPageID());
2972 3056
2973 controller.PruneAllButActive(); 3057 EXPECT_TRUE(controller.PruneAllButVisible());
2974 3058
2975 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3059 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2976 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); 3060 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1);
2977 } 3061 }
2978 3062
2979 // Test call to PruneAllButActive for last entry. 3063 // Test call to PruneAllButVisible for first entry.
2980 TEST_F(NavigationControllerTest, PruneAllButActiveForLast) { 3064 TEST_F(NavigationControllerTest, PruneAllButVisibleForFirst) {
2981 NavigationControllerImpl& controller = controller_impl(); 3065 NavigationControllerImpl& controller = controller_impl();
2982 const GURL url1("http://foo/1"); 3066 const GURL url1("http://foo/1");
2983 const GURL url2("http://foo/2"); 3067 const GURL url2("http://foo/2");
2984 const GURL url3("http://foo/3"); 3068 const GURL url3("http://foo/3");
2985 3069
2986 NavigateAndCommit(url1); 3070 NavigateAndCommit(url1);
2987 NavigateAndCommit(url2); 3071 NavigateAndCommit(url2);
2988 NavigateAndCommit(url3); 3072 NavigateAndCommit(url3);
2989 controller.GoBack(); 3073 controller.GoBack();
2990 controller.GoBack(); 3074 controller.GoBack();
2991 contents()->CommitPendingNavigation(); 3075 contents()->CommitPendingNavigation();
2992 3076
2993 contents()->ExpectSetHistoryLengthAndPrune( 3077 contents()->ExpectSetHistoryLengthAndPrune(
2994 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, 3078 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0,
2995 controller.GetEntryAtIndex(0)->GetPageID()); 3079 controller.GetEntryAtIndex(0)->GetPageID());
2996 3080
2997 controller.PruneAllButActive(); 3081 EXPECT_TRUE(controller.PruneAllButVisible());
2998 3082
2999 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3083 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3000 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); 3084 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1);
3001 } 3085 }
3002 3086
3003 // Test call to PruneAllButActive for intermediate entry. 3087 // Test call to PruneAllButVisible for intermediate entry.
3004 TEST_F(NavigationControllerTest, PruneAllButActiveForIntermediate) { 3088 TEST_F(NavigationControllerTest, PruneAllButVisibleForIntermediate) {
3005 NavigationControllerImpl& controller = controller_impl(); 3089 NavigationControllerImpl& controller = controller_impl();
3006 const GURL url1("http://foo/1"); 3090 const GURL url1("http://foo/1");
3007 const GURL url2("http://foo/2"); 3091 const GURL url2("http://foo/2");
3008 const GURL url3("http://foo/3"); 3092 const GURL url3("http://foo/3");
3009 3093
3010 NavigateAndCommit(url1); 3094 NavigateAndCommit(url1);
3011 NavigateAndCommit(url2); 3095 NavigateAndCommit(url2);
3012 NavigateAndCommit(url3); 3096 NavigateAndCommit(url3);
3013 controller.GoBack(); 3097 controller.GoBack();
3014 contents()->CommitPendingNavigation(); 3098 contents()->CommitPendingNavigation();
3015 3099
3016 contents()->ExpectSetHistoryLengthAndPrune( 3100 contents()->ExpectSetHistoryLengthAndPrune(
3017 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)), 0, 3101 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)), 0,
3018 controller.GetEntryAtIndex(1)->GetPageID()); 3102 controller.GetEntryAtIndex(1)->GetPageID());
3019 3103
3020 controller.PruneAllButActive(); 3104 EXPECT_TRUE(controller.PruneAllButVisible());
3021 3105
3022 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3106 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3023 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url2); 3107 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url2);
3024 } 3108 }
3025 3109
3026 // Test call to PruneAllButActive for a pending entry. 3110 // Test call to PruneAllButVisible for a pending entry that is not yet in the
3027 TEST_F(NavigationControllerTest, PruneAllButActiveForPending) { 3111 // list of entries.
3112 TEST_F(NavigationControllerTest, PruneAllButVisibleForPendingNotInList) {
3028 NavigationControllerImpl& controller = controller_impl(); 3113 NavigationControllerImpl& controller = controller_impl();
3029 const GURL url1("http://foo/1"); 3114 const GURL url1("http://foo/1");
3030 const GURL url2("http://foo/2"); 3115 const GURL url2("http://foo/2");
3031 const GURL url3("http://foo/3");
3032
3033 NavigateAndCommit(url1);
3034 NavigateAndCommit(url2);
3035 NavigateAndCommit(url3);
3036 controller.GoBack();
3037
3038 contents()->ExpectSetHistoryLengthAndPrune(
3039 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)), 0,
3040 controller.GetEntryAtIndex(1)->GetPageID());
3041
3042 controller.PruneAllButActive();
3043
3044 EXPECT_EQ(0, controller.GetPendingEntryIndex());
3045 }
3046
3047 // Test call to PruneAllButActive for a pending entry that is not yet in the
3048 // list of entries.
3049 TEST_F(NavigationControllerTest, PruneAllButActiveForPendingNotInList) {
3050 NavigationControllerImpl& controller = controller_impl();
3051 const GURL url1("http://foo/1");
3052 const GURL url2("http://foo/2");
3053 const GURL url3("http://foo/3"); 3116 const GURL url3("http://foo/3");
3054 3117
3055 NavigateAndCommit(url1); 3118 NavigateAndCommit(url1);
3056 NavigateAndCommit(url2); 3119 NavigateAndCommit(url2);
3057 3120
3058 // Create a pending entry that is not in the entry list. 3121 // Create a pending entry that is not in the entry list.
3059 controller.LoadURL( 3122 controller.LoadURL(
3060 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 3123 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string());
3061 EXPECT_TRUE(controller.GetPendingEntry()); 3124 EXPECT_TRUE(controller.GetPendingEntry());
3062 EXPECT_EQ(2, controller.GetEntryCount()); 3125 EXPECT_EQ(2, controller.GetEntryCount());
3063 3126
3064 contents()->ExpectSetHistoryLengthAndPrune( 3127 contents()->ExpectSetHistoryLengthAndPrune(
3065 NULL, 0, controller.GetPendingEntry()->GetPageID()); 3128 NULL, 0, controller.GetPendingEntry()->GetPageID());
3066 controller.PruneAllButActive(); 3129 EXPECT_TRUE(controller.PruneAllButVisible());
3067 3130
3068 // We should only have the pending entry at this point, and it should still 3131 // We should only have the last committed and pending entries at this point,
3069 // not be in the entry list. 3132 // and the pending entry should still not be in the entry list.
3133 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3134 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL());
3070 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3135 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3071 EXPECT_TRUE(controller.GetPendingEntry()); 3136 EXPECT_TRUE(controller.GetPendingEntry());
3072 EXPECT_EQ(0, controller.GetEntryCount()); 3137 EXPECT_EQ(1, controller.GetEntryCount());
3073 3138
3074 // Try to commit the pending entry. 3139 // Try to commit the pending entry.
3075 test_rvh()->SendNavigate(2, url3); 3140 test_rvh()->SendNavigate(2, url3);
3076 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3141 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3077 EXPECT_FALSE(controller.GetPendingEntry()); 3142 EXPECT_FALSE(controller.GetPendingEntry());
3078 EXPECT_EQ(1, controller.GetEntryCount()); 3143 EXPECT_EQ(2, controller.GetEntryCount());
3079 EXPECT_EQ(url3, controller.GetEntryAtIndex(0)->GetURL()); 3144 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL());
3080 }
3081
3082 // Test call to PruneAllButActive for transient entry.
3083 TEST_F(NavigationControllerTest, PruneAllButActiveForTransient) {
3084 NavigationControllerImpl& controller = controller_impl();
3085 const GURL url0("http://foo/0");
3086 const GURL url1("http://foo/1");
3087 const GURL transient_url("http://foo/transient");
3088
3089 controller.LoadURL(
3090 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string());
3091 test_rvh()->SendNavigate(0, url0);
3092 controller.LoadURL(
3093 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
3094 test_rvh()->SendNavigate(1, url1);
3095
3096 // Adding a transient with no pending entry.
3097 NavigationEntryImpl* transient_entry = new NavigationEntryImpl;
3098 transient_entry->SetURL(transient_url);
3099 controller.SetTransientEntry(transient_entry);
3100
3101 contents()->ExpectSetHistoryLengthAndPrune(
3102 GetSiteInstanceFromEntry(controller.GetTransientEntry()), 0,
3103 controller.GetTransientEntry()->GetPageID());
3104
3105 controller.PruneAllButActive();
3106
3107 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3108 EXPECT_EQ(controller.GetTransientEntry()->GetURL(), transient_url);
3109 } 3145 }
3110 3146
3111 // Test to ensure that when we do a history navigation back to the current 3147 // Test to ensure that when we do a history navigation back to the current
3112 // committed page (e.g., going forward to a slow-loading page, then pressing 3148 // committed page (e.g., going forward to a slow-loading page, then pressing
3113 // the back button), we just stop the navigation to prevent the throbber from 3149 // the back button), we just stop the navigation to prevent the throbber from
3114 // running continuously. Otherwise, the RenderViewHost forces the throbber to 3150 // running continuously. Otherwise, the RenderViewHost forces the throbber to
3115 // start, but WebKit essentially ignores the navigation and never sends a 3151 // start, but WebKit essentially ignores the navigation and never sends a
3116 // message to stop the throbber. 3152 // message to stop the throbber.
3117 TEST_F(NavigationControllerTest, StopOnHistoryNavigationToCurrentPage) { 3153 TEST_F(NavigationControllerTest, StopOnHistoryNavigationToCurrentPage) {
3118 NavigationControllerImpl& controller = controller_impl(); 3154 NavigationControllerImpl& controller = controller_impl();
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 PAGE_TRANSITION_LINK); 3582 PAGE_TRANSITION_LINK);
3547 session_helper_.AssertNavigationEquals(nav, 3583 session_helper_.AssertNavigationEquals(nav,
3548 windows_[0]->tabs[0]->navigations[0]); 3584 windows_[0]->tabs[0]->navigations[0]);
3549 nav.set_url(url2); 3585 nav.set_url(url2);
3550 session_helper_.AssertNavigationEquals(nav, 3586 session_helper_.AssertNavigationEquals(nav,
3551 windows_[0]->tabs[0]->navigations[1]); 3587 windows_[0]->tabs[0]->navigations[1]);
3552 } 3588 }
3553 */ 3589 */
3554 3590
3555 } // namespace content 3591 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698