OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/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 2767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 2799 contents()->CommitPendingNavigation(); |
2800 scoped_ptr<TestWebContents> other_contents( | 2800 |
2801 static_cast<TestWebContents*>(CreateTestWebContents())); | 2801 scoped_ptr<TestWebContents> other_contents( |
2802 NavigationControllerImpl& other_controller = other_contents->GetController(); | 2802 static_cast<TestWebContents*>(CreateTestWebContents())); |
2803 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); | 2803 NavigationControllerImpl& other_controller = other_contents->GetController(); |
2804 other_controller.CopyStateFromAndPrune(&controller); | 2804 other_contents->NavigateAndCommit(url3); |
2805 | 2805 other_contents->ExpectSetHistoryLengthAndPrune( |
2806 // other_controller should now contain the 1 url: url1. | 2806 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, |
2807 | 2807 other_controller.GetEntryAtIndex(0)->GetPageID()); |
2808 ASSERT_EQ(1, other_controller.GetEntryCount()); | 2808 other_controller.CopyStateFromAndPrune(&controller); |
2809 | 2809 |
2810 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); | 2810 // other_controller should now contain: url1, url3 |
2811 | 2811 |
2812 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 2812 ASSERT_EQ(2, other_controller.GetEntryCount()); |
2813 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); | 2813 ASSERT_EQ(1, other_controller.GetCurrentEntryIndex()); |
2814 | 2814 |
2815 // The max page ID map should be copied over and updated with the max page ID | 2815 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
2816 // from the current tab. | 2816 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
2817 SiteInstance* instance1 = | 2817 EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); |
2818 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); | 2818 |
2819 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 2819 // The max page ID map should be copied over and updated with the max page ID |
2820 } | 2820 // from the current tab. |
2821 | 2821 SiteInstance* instance1 = |
2822 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in | 2822 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)); |
| 2823 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
| 2824 } |
| 2825 |
| 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 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, 2 entries in the target, with |
| 2865 // not the last entry selected in the target. |
| 2866 TEST_F(NavigationControllerTest, CopyStateFromAndPruneNotLast) { |
| 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"); |
| 2872 |
| 2873 NavigateAndCommit(url1); |
| 2874 NavigateAndCommit(url2); |
| 2875 |
| 2876 scoped_ptr<TestWebContents> other_contents( |
| 2877 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 2878 NavigationControllerImpl& other_controller = other_contents->GetController(); |
| 2879 other_contents->NavigateAndCommit(url3); |
| 2880 other_contents->NavigateAndCommit(url4); |
| 2881 other_controller.GoBack(); |
| 2882 other_contents->CommitPendingNavigation(); |
| 2883 other_contents->ExpectSetHistoryLengthAndPrune( |
| 2884 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, |
| 2885 other_controller.GetEntryAtIndex(0)->GetPageID()); |
| 2886 other_controller.CopyStateFromAndPrune(&controller); |
| 2887 |
| 2888 // other_controller should now contain: url1, url2, url3 |
| 2889 |
| 2890 ASSERT_EQ(3, other_controller.GetEntryCount()); |
| 2891 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
| 2892 |
| 2893 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
| 2894 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
| 2895 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); |
| 2896 |
| 2897 // The max page ID map should be copied over and updated with the max page ID |
| 2898 // from the current tab. |
| 2899 SiteInstance* instance1 = |
| 2900 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); |
| 2901 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
| 2902 } |
| 2903 |
| 2904 // Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry plus |
| 2905 // a pending entry in the target. |
| 2906 TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending) { |
| 2907 NavigationControllerImpl& controller = controller_impl(); |
| 2908 const GURL url1("http://foo1"); |
| 2909 const GURL url2("http://foo2"); |
| 2910 const GURL url3("http://foo3"); |
| 2911 const GURL url4("http://foo4"); |
2829 | 2912 |
2830 NavigateAndCommit(url1); | 2913 NavigateAndCommit(url1); |
2831 NavigateAndCommit(url2); | 2914 NavigateAndCommit(url2); |
2832 controller.GoBack(); | 2915 controller.GoBack(); |
2833 | 2916 contents()->CommitPendingNavigation(); |
2834 scoped_ptr<TestWebContents> other_contents( | 2917 |
2835 static_cast<TestWebContents*>(CreateTestWebContents())); | 2918 scoped_ptr<TestWebContents> other_contents( |
2836 NavigationControllerImpl& other_controller = other_contents->GetController(); | 2919 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 2920 NavigationControllerImpl& other_controller = other_contents->GetController(); |
| 2921 other_contents->NavigateAndCommit(url3); |
2837 other_controller.LoadURL( | 2922 other_controller.LoadURL( |
2838 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2923 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2839 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); | 2924 other_contents->ExpectSetHistoryLengthAndPrune( |
2840 other_controller.CopyStateFromAndPrune(&controller); | 2925 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, |
2841 | 2926 other_controller.GetEntryAtIndex(0)->GetPageID()); |
2842 // other_controller should now contain 1 entry for url1, and a pending entry | 2927 other_controller.CopyStateFromAndPrune(&controller); |
2843 // for url3. | 2928 |
2844 | 2929 // other_controller should now contain url1, url3, and a pending entry |
2845 ASSERT_EQ(1, other_controller.GetEntryCount()); | 2930 // for url4. |
2846 | 2931 |
2847 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); | 2932 ASSERT_EQ(2, other_controller.GetEntryCount()); |
2848 | 2933 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); |
2849 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 2934 |
2850 | 2935 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
2851 // And there should be a pending entry for url3. | 2936 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
| 2937 |
| 2938 // And there should be a pending entry for url4. |
2852 ASSERT_TRUE(other_controller.GetPendingEntry()); | 2939 ASSERT_TRUE(other_controller.GetPendingEntry()); |
2853 | 2940 EXPECT_EQ(url4, other_controller.GetPendingEntry()->GetURL()); |
2854 EXPECT_EQ(url3, other_controller.GetPendingEntry()->GetURL()); | |
2855 | 2941 |
2856 // The max page ID map should be copied over and updated with the max page ID | 2942 // The max page ID map should be copied over and updated with the max page ID |
2857 // from the current tab. | 2943 // from the current tab. |
2858 SiteInstance* instance1 = | 2944 SiteInstance* instance1 = |
2859 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); | 2945 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); |
2860 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 2946 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
2861 } | 2947 } |
2862 | 2948 |
| 2949 // Test CopyStateFromAndPrune with 1 url in the source, 1 entry and a pending |
| 2950 // client redirect entry (with the same page ID) in the target. This used to |
| 2951 // crash because the last committed entry would be pruned but max_page_id |
| 2952 // remembered the page ID (http://crbug.com/234809). |
| 2953 TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending2) { |
| 2954 NavigationControllerImpl& controller = controller_impl(); |
| 2955 const GURL url1("http://foo1"); |
| 2956 const GURL url2a("http://foo2/a"); |
| 2957 const GURL url2b("http://foo2/b"); |
| 2958 |
| 2959 NavigateAndCommit(url1); |
| 2960 |
| 2961 scoped_ptr<TestWebContents> other_contents( |
| 2962 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 2963 NavigationControllerImpl& other_controller = other_contents->GetController(); |
| 2964 other_contents->NavigateAndCommit(url2a); |
| 2965 // Simulate a client redirect, which has the same page ID as entry 2a. |
| 2966 other_controller.LoadURL( |
| 2967 url2b, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
| 2968 other_controller.GetPendingEntry()->SetPageID( |
| 2969 other_controller.GetLastCommittedEntry()->GetPageID()); |
| 2970 |
| 2971 other_contents->ExpectSetHistoryLengthAndPrune( |
| 2972 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 1, |
| 2973 other_controller.GetEntryAtIndex(0)->GetPageID()); |
| 2974 other_controller.CopyStateFromAndPrune(&controller); |
| 2975 |
| 2976 // other_controller should now contain url1, url2a, and a pending entry |
| 2977 // for url2b. |
| 2978 |
| 2979 ASSERT_EQ(2, other_controller.GetEntryCount()); |
| 2980 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); |
| 2981 |
| 2982 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
| 2983 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); |
| 2984 |
| 2985 // And there should be a pending entry for url4. |
| 2986 ASSERT_TRUE(other_controller.GetPendingEntry()); |
| 2987 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); |
| 2988 |
| 2989 // Let the pending entry commit. |
| 2990 other_contents->CommitPendingNavigation(); |
| 2991 |
| 2992 // The max page ID map should be copied over and updated with the max page ID |
| 2993 // from the current tab. |
| 2994 SiteInstance* instance1 = |
| 2995 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(1)); |
| 2996 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
| 2997 } |
| 2998 |
| 2999 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the |
| 3000 // source, and 1 entry in the target. The back pending entry should be ignored. |
| 3001 TEST_F(NavigationControllerTest, CopyStateFromAndPruneSourcePending) { |
| 3002 NavigationControllerImpl& controller = controller_impl(); |
| 3003 const GURL url1("http://foo1"); |
| 3004 const GURL url2("http://foo2"); |
| 3005 const GURL url3("http://foo3"); |
| 3006 |
| 3007 NavigateAndCommit(url1); |
| 3008 NavigateAndCommit(url2); |
| 3009 controller.GoBack(); |
| 3010 |
| 3011 scoped_ptr<TestWebContents> other_contents( |
| 3012 static_cast<TestWebContents*>(CreateTestWebContents())); |
| 3013 NavigationControllerImpl& other_controller = other_contents->GetController(); |
| 3014 other_contents->NavigateAndCommit(url3); |
| 3015 other_contents->ExpectSetHistoryLengthAndPrune( |
| 3016 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, |
| 3017 other_controller.GetEntryAtIndex(0)->GetPageID()); |
| 3018 other_controller.CopyStateFromAndPrune(&controller); |
| 3019 |
| 3020 // other_controller should now contain: url1, url2, url3 |
| 3021 |
| 3022 ASSERT_EQ(3, other_controller.GetEntryCount()); |
| 3023 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
| 3024 |
| 3025 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
| 3026 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
| 3027 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); |
| 3028 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); |
| 3029 |
| 3030 // The max page ID map should be copied over and updated with the max page ID |
| 3031 // from the current tab. |
| 3032 SiteInstance* instance1 = |
| 3033 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); |
| 3034 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
| 3035 } |
| 3036 |
2863 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, | 3037 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, |
2864 // when the max entry count is 3. We should prune one entry. | 3038 // when the max entry count is 3. We should prune one entry. |
2865 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) { | 3039 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) { |
2866 NavigationControllerImpl& controller = controller_impl(); | 3040 NavigationControllerImpl& controller = controller_impl(); |
2867 size_t original_count = NavigationControllerImpl::max_entry_count(); | 3041 size_t original_count = NavigationControllerImpl::max_entry_count(); |
2868 const int kMaxEntryCount = 3; | 3042 const int kMaxEntryCount = 3; |
2869 | 3043 |
2870 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 3044 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
2871 | 3045 |
2872 const GURL url1("http://foo/1"); | 3046 const GURL url1("http://foo/1"); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2953 EXPECT_EQ(url3, nav_params.a.url); | 3127 EXPECT_EQ(url3, nav_params.a.url); |
2954 process()->sink().ClearMessages(); | 3128 process()->sink().ClearMessages(); |
2955 | 3129 |
2956 // Make sure an extravagant history.go() doesn't break. | 3130 // Make sure an extravagant history.go() doesn't break. |
2957 contents()->OnGoToEntryAtOffset(120); // Out of bounds. | 3131 contents()->OnGoToEntryAtOffset(120); // Out of bounds. |
2958 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3132 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2959 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); | 3133 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); |
2960 EXPECT_TRUE(message == NULL); | 3134 EXPECT_TRUE(message == NULL); |
2961 } | 3135 } |
2962 | 3136 |
2963 // Test call to PruneAllButActive for the only entry. | 3137 // Test call to PruneAllButVisible for the only entry. |
2964 TEST_F(NavigationControllerTest, PruneAllButActiveForSingle) { | 3138 TEST_F(NavigationControllerTest, PruneAllButVisibleForSingle) { |
2965 NavigationControllerImpl& controller = controller_impl(); | 3139 NavigationControllerImpl& controller = controller_impl(); |
2966 const GURL url1("http://foo1"); | 3140 const GURL url1("http://foo1"); |
2967 NavigateAndCommit(url1); | 3141 NavigateAndCommit(url1); |
2968 | 3142 |
2969 contents()->ExpectSetHistoryLengthAndPrune( | 3143 contents()->ExpectSetHistoryLengthAndPrune( |
2970 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, | 3144 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, |
2971 controller.GetEntryAtIndex(0)->GetPageID()); | 3145 controller.GetEntryAtIndex(0)->GetPageID()); |
2972 | 3146 |
2973 controller.PruneAllButActive(); | 3147 controller.PruneAllButVisible(); |
2974 | 3148 |
2975 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3149 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2976 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); | 3150 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); |
2977 } | 3151 } |
2978 | 3152 |
2979 // Test call to PruneAllButActive for last entry. | 3153 // Test call to PruneAllButVisible for first entry. |
2980 TEST_F(NavigationControllerTest, PruneAllButActiveForLast) { | 3154 TEST_F(NavigationControllerTest, PruneAllButVisibleForFirst) { |
2981 NavigationControllerImpl& controller = controller_impl(); | 3155 NavigationControllerImpl& controller = controller_impl(); |
2982 const GURL url1("http://foo/1"); | 3156 const GURL url1("http://foo/1"); |
2983 const GURL url2("http://foo/2"); | 3157 const GURL url2("http://foo/2"); |
2984 const GURL url3("http://foo/3"); | 3158 const GURL url3("http://foo/3"); |
2985 | 3159 |
2986 NavigateAndCommit(url1); | 3160 NavigateAndCommit(url1); |
2987 NavigateAndCommit(url2); | 3161 NavigateAndCommit(url2); |
2988 NavigateAndCommit(url3); | 3162 NavigateAndCommit(url3); |
2989 controller.GoBack(); | 3163 controller.GoBack(); |
2990 controller.GoBack(); | 3164 controller.GoBack(); |
2991 contents()->CommitPendingNavigation(); | 3165 contents()->CommitPendingNavigation(); |
2992 | 3166 |
2993 contents()->ExpectSetHistoryLengthAndPrune( | 3167 contents()->ExpectSetHistoryLengthAndPrune( |
2994 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, | 3168 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, |
2995 controller.GetEntryAtIndex(0)->GetPageID()); | 3169 controller.GetEntryAtIndex(0)->GetPageID()); |
2996 | 3170 |
2997 controller.PruneAllButActive(); | 3171 controller.PruneAllButVisible(); |
2998 | 3172 |
2999 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3173 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3000 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); | 3174 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); |
3001 } | 3175 } |
3002 | 3176 |
3003 // Test call to PruneAllButActive for intermediate entry. | 3177 // Test call to PruneAllButVisible for intermediate entry. |
3004 TEST_F(NavigationControllerTest, PruneAllButActiveForIntermediate) { | 3178 TEST_F(NavigationControllerTest, PruneAllButVisibleForIntermediate) { |
3005 NavigationControllerImpl& controller = controller_impl(); | 3179 NavigationControllerImpl& controller = controller_impl(); |
3006 const GURL url1("http://foo/1"); | 3180 const GURL url1("http://foo/1"); |
3007 const GURL url2("http://foo/2"); | 3181 const GURL url2("http://foo/2"); |
3008 const GURL url3("http://foo/3"); | 3182 const GURL url3("http://foo/3"); |
3009 | 3183 |
3010 NavigateAndCommit(url1); | 3184 NavigateAndCommit(url1); |
3011 NavigateAndCommit(url2); | 3185 NavigateAndCommit(url2); |
3012 NavigateAndCommit(url3); | 3186 NavigateAndCommit(url3); |
3013 controller.GoBack(); | 3187 controller.GoBack(); |
3014 contents()->CommitPendingNavigation(); | 3188 contents()->CommitPendingNavigation(); |
3015 | 3189 |
3016 contents()->ExpectSetHistoryLengthAndPrune( | 3190 contents()->ExpectSetHistoryLengthAndPrune( |
3017 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)), 0, | 3191 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)), 0, |
3018 controller.GetEntryAtIndex(1)->GetPageID()); | 3192 controller.GetEntryAtIndex(1)->GetPageID()); |
3019 | 3193 |
3020 controller.PruneAllButActive(); | 3194 controller.PruneAllButVisible(); |
3021 | 3195 |
3022 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3196 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3023 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url2); | 3197 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url2); |
3024 } | 3198 } |
3025 | 3199 |
3026 // Test call to PruneAllButActive for a pending entry. | 3200 // Test call to PruneAllButVisible for a pending entry that is not yet in the |
3027 TEST_F(NavigationControllerTest, PruneAllButActiveForPending) { | 3201 // list of entries. |
| 3202 TEST_F(NavigationControllerTest, PruneAllButVisibleForPendingNotInList) { |
3028 NavigationControllerImpl& controller = controller_impl(); | 3203 NavigationControllerImpl& controller = controller_impl(); |
3029 const GURL url1("http://foo/1"); | 3204 const GURL url1("http://foo/1"); |
3030 const GURL url2("http://foo/2"); | 3205 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"); | 3206 const GURL url3("http://foo/3"); |
3054 | 3207 |
3055 NavigateAndCommit(url1); | 3208 NavigateAndCommit(url1); |
3056 NavigateAndCommit(url2); | 3209 NavigateAndCommit(url2); |
3057 | 3210 |
3058 // Create a pending entry that is not in the entry list. | 3211 // Create a pending entry that is not in the entry list. |
3059 controller.LoadURL( | 3212 controller.LoadURL( |
3060 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 3213 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
3061 EXPECT_TRUE(controller.GetPendingEntry()); | 3214 EXPECT_TRUE(controller.GetPendingEntry()); |
3062 EXPECT_EQ(2, controller.GetEntryCount()); | 3215 EXPECT_EQ(2, controller.GetEntryCount()); |
3063 | 3216 |
3064 contents()->ExpectSetHistoryLengthAndPrune( | 3217 contents()->ExpectSetHistoryLengthAndPrune( |
3065 NULL, 0, controller.GetPendingEntry()->GetPageID()); | 3218 NULL, 0, controller.GetPendingEntry()->GetPageID()); |
3066 controller.PruneAllButActive(); | 3219 controller.PruneAllButVisible(); |
3067 | 3220 |
3068 // We should only have the pending entry at this point, and it should still | 3221 // We should only have the last committed and pending entries at this point, |
3069 // not be in the entry list. | 3222 // and the pending entry should still not be in the entry list. |
| 3223 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 3224 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
3070 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3225 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3071 EXPECT_TRUE(controller.GetPendingEntry()); | 3226 EXPECT_TRUE(controller.GetPendingEntry()); |
3072 EXPECT_EQ(0, controller.GetEntryCount()); | 3227 EXPECT_EQ(1, controller.GetEntryCount()); |
3073 | 3228 |
3074 // Try to commit the pending entry. | 3229 // Try to commit the pending entry. |
3075 test_rvh()->SendNavigate(2, url3); | 3230 test_rvh()->SendNavigate(2, url3); |
3076 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3231 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3077 EXPECT_FALSE(controller.GetPendingEntry()); | 3232 EXPECT_FALSE(controller.GetPendingEntry()); |
3078 EXPECT_EQ(1, controller.GetEntryCount()); | 3233 EXPECT_EQ(2, controller.GetEntryCount()); |
3079 EXPECT_EQ(url3, controller.GetEntryAtIndex(0)->GetURL()); | 3234 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 } | 3235 } |
3110 | 3236 |
3111 // Test to ensure that when we do a history navigation back to the current | 3237 // 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 | 3238 // 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 | 3239 // the back button), we just stop the navigation to prevent the throbber from |
3114 // running continuously. Otherwise, the RenderViewHost forces the throbber to | 3240 // running continuously. Otherwise, the RenderViewHost forces the throbber to |
3115 // start, but WebKit essentially ignores the navigation and never sends a | 3241 // start, but WebKit essentially ignores the navigation and never sends a |
3116 // message to stop the throbber. | 3242 // message to stop the throbber. |
3117 TEST_F(NavigationControllerTest, StopOnHistoryNavigationToCurrentPage) { | 3243 TEST_F(NavigationControllerTest, StopOnHistoryNavigationToCurrentPage) { |
3118 NavigationControllerImpl& controller = controller_impl(); | 3244 NavigationControllerImpl& controller = controller_impl(); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3546 PAGE_TRANSITION_LINK); | 3672 PAGE_TRANSITION_LINK); |
3547 session_helper_.AssertNavigationEquals(nav, | 3673 session_helper_.AssertNavigationEquals(nav, |
3548 windows_[0]->tabs[0]->navigations[0]); | 3674 windows_[0]->tabs[0]->navigations[0]); |
3549 nav.set_url(url2); | 3675 nav.set_url(url2); |
3550 session_helper_.AssertNavigationEquals(nav, | 3676 session_helper_.AssertNavigationEquals(nav, |
3551 windows_[0]->tabs[0]->navigations[1]); | 3677 windows_[0]->tabs[0]->navigations[1]); |
3552 } | 3678 } |
3553 */ | 3679 */ |
3554 | 3680 |
3555 } // namespace content | 3681 } // namespace content |
OLD | NEW |