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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 | 2179 |
2180 EXPECT_EQ(url3, other_controller.GetPendingEntry()->GetURL()); | 2180 EXPECT_EQ(url3, other_controller.GetPendingEntry()->GetURL()); |
2181 | 2181 |
2182 // The max page ID map should be copied over and updated with the max page ID | 2182 // The max page ID map should be copied over and updated with the max page ID |
2183 // from the current tab. | 2183 // from the current tab. |
2184 SiteInstance* instance1 = | 2184 SiteInstance* instance1 = |
2185 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); | 2185 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); |
2186 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 2186 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
2187 } | 2187 } |
2188 | 2188 |
| 2189 // Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, |
| 2190 // when the max entry count is 3. We should prune one entry. |
| 2191 TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) { |
| 2192 NavigationControllerImpl& controller = controller_impl(); |
| 2193 size_t original_count = NavigationControllerImpl::max_entry_count(); |
| 2194 const int kMaxEntryCount = 3; |
| 2195 |
| 2196 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
| 2197 |
| 2198 const GURL url1("http://foo/1"); |
| 2199 const GURL url2("http://foo/2"); |
| 2200 const GURL url3("http://foo/3"); |
| 2201 const GURL url4("http://foo/4"); |
| 2202 |
| 2203 // Create a PrunedListener to observe prune notifications. |
| 2204 PrunedListener listener(&controller); |
| 2205 |
| 2206 NavigateAndCommit(url1); |
| 2207 NavigateAndCommit(url2); |
| 2208 NavigateAndCommit(url3); |
| 2209 |
| 2210 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
| 2211 NavigationControllerImpl& other_controller = |
| 2212 other_contents->GetControllerImpl(); |
| 2213 other_contents->NavigateAndCommit(url4); |
| 2214 other_contents->ExpectSetHistoryLengthAndPrune( |
| 2215 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, |
| 2216 other_controller.GetEntryAtIndex(0)->GetPageID()); |
| 2217 other_controller.CopyStateFromAndPrune(&controller); |
| 2218 |
| 2219 // We should have received a pruned notification. |
| 2220 EXPECT_EQ(1, listener.notification_count_); |
| 2221 EXPECT_TRUE(listener.details_.from_front); |
| 2222 EXPECT_EQ(1, listener.details_.count); |
| 2223 |
| 2224 // other_controller should now contain only 3 urls: url2, url3 and url4. |
| 2225 |
| 2226 ASSERT_EQ(3, other_controller.GetEntryCount()); |
| 2227 |
| 2228 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
| 2229 |
| 2230 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(0)->GetURL()); |
| 2231 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
| 2232 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); |
| 2233 EXPECT_EQ(1, other_controller.GetEntryAtIndex(0)->GetPageID()); |
| 2234 EXPECT_EQ(2, other_controller.GetEntryAtIndex(1)->GetPageID()); |
| 2235 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); |
| 2236 |
| 2237 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
| 2238 } |
| 2239 |
2189 // Tests that navigations initiated from the page (with the history object) | 2240 // Tests that navigations initiated from the page (with the history object) |
2190 // work as expected without navigation entries. | 2241 // work as expected without navigation entries. |
2191 TEST_F(NavigationControllerTest, HistoryNavigate) { | 2242 TEST_F(NavigationControllerTest, HistoryNavigate) { |
2192 NavigationControllerImpl& controller = controller_impl(); | 2243 NavigationControllerImpl& controller = controller_impl(); |
2193 const GURL url1("http://foo/1"); | 2244 const GURL url1("http://foo/1"); |
2194 const GURL url2("http://foo/2"); | 2245 const GURL url2("http://foo/2"); |
2195 const GURL url3("http://foo/3"); | 2246 const GURL url3("http://foo/3"); |
2196 | 2247 |
2197 NavigateAndCommit(url1); | 2248 NavigateAndCommit(url1); |
2198 NavigateAndCommit(url2); | 2249 NavigateAndCommit(url2); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2522 TabNavigation nav(0, url0, GURL(), string16(), | 2573 TabNavigation nav(0, url0, GURL(), string16(), |
2523 webkit_glue::CreateHistoryStateForURL(url0), | 2574 webkit_glue::CreateHistoryStateForURL(url0), |
2524 content::PAGE_TRANSITION_LINK); | 2575 content::PAGE_TRANSITION_LINK); |
2525 session_helper_.AssertNavigationEquals(nav, | 2576 session_helper_.AssertNavigationEquals(nav, |
2526 windows_[0]->tabs[0]->navigations[0]); | 2577 windows_[0]->tabs[0]->navigations[0]); |
2527 nav.set_url(url2); | 2578 nav.set_url(url2); |
2528 session_helper_.AssertNavigationEquals(nav, | 2579 session_helper_.AssertNavigationEquals(nav, |
2529 windows_[0]->tabs[0]->navigations[1]); | 2580 windows_[0]->tabs[0]->navigations[1]); |
2530 } | 2581 } |
2531 */ | 2582 */ |
OLD | NEW |