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

Side by Side Diff: content/browser/tab_contents/navigation_controller_unittest.cc

Issue 7618016: Additional fixes for prerender/instant + browsing history. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wrong signature Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 const GURL url1("http://foo1"); 1916 const GURL url1("http://foo1");
1917 const GURL url2("http://foo2"); 1917 const GURL url2("http://foo2");
1918 const GURL url3("http://foo3"); 1918 const GURL url3("http://foo3");
1919 1919
1920 NavigateAndCommit(url1); 1920 NavigateAndCommit(url1);
1921 NavigateAndCommit(url2); 1921 NavigateAndCommit(url2);
1922 1922
1923 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1923 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1924 NavigationController& other_controller = other_contents->controller(); 1924 NavigationController& other_controller = other_contents->controller();
1925 other_contents->NavigateAndCommit(url3); 1925 other_contents->NavigateAndCommit(url3);
1926 other_contents->ExpectSetHistoryLengthAndPrune(
1927 other_controller.GetEntryAtIndex(0)->site_instance(), 2,
1928 other_controller.GetEntryAtIndex(0)->page_id());
1926 other_controller.CopyStateFromAndPrune(&controller(), false); 1929 other_controller.CopyStateFromAndPrune(&controller(), false);
1927 1930
1928 // other_controller should now contain the 3 urls: url1, url2 and url3. 1931 // other_controller should now contain the 3 urls: url1, url2 and url3.
1929 1932
1930 ASSERT_EQ(3, other_controller.entry_count()); 1933 ASSERT_EQ(3, other_controller.entry_count());
1931 1934
1932 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 1935 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
1933 1936
1934 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1937 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1935 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->url()); 1938 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->url());
1936 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->url()); 1939 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->url());
1937 } 1940 }
1938 1941
1939 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in 1942 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in
1940 // the target. 1943 // the target.
1941 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) { 1944 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) {
1942 const GURL url1("http://foo1"); 1945 const GURL url1("http://foo1");
1943 const GURL url2("http://foo2"); 1946 const GURL url2("http://foo2");
1944 const GURL url3("http://foo3"); 1947 const GURL url3("http://foo3");
1945 1948
1946 NavigateAndCommit(url1); 1949 NavigateAndCommit(url1);
1947 NavigateAndCommit(url2); 1950 NavigateAndCommit(url2);
1948 controller().GoBack(); 1951 controller().GoBack();
1949 1952
1950 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1953 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1951 NavigationController& other_controller = other_contents->controller(); 1954 NavigationController& other_controller = other_contents->controller();
1955 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
1952 other_controller.CopyStateFromAndPrune(&controller(), false); 1956 other_controller.CopyStateFromAndPrune(&controller(), false);
1953 1957
1954 // other_controller should now contain the 1 url: url1. 1958 // other_controller should now contain the 1 url: url1.
1955 1959
1956 ASSERT_EQ(1, other_controller.entry_count()); 1960 ASSERT_EQ(1, other_controller.entry_count());
1957 1961
1958 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); 1962 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex());
1959 1963
1960 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1964 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1961 } 1965 }
1962 1966
1963 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in 1967 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in
1964 // the target. 1968 // the target.
1965 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { 1969 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) {
1966 const GURL url1("http://foo1"); 1970 const GURL url1("http://foo1");
1967 const GURL url2("http://foo2"); 1971 const GURL url2("http://foo2");
1968 const GURL url3("http://foo3"); 1972 const GURL url3("http://foo3");
1969 1973
1970 NavigateAndCommit(url1); 1974 NavigateAndCommit(url1);
1971 NavigateAndCommit(url2); 1975 NavigateAndCommit(url2);
1972 controller().GoBack(); 1976 controller().GoBack();
1973 1977
1974 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1978 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1975 NavigationController& other_controller = other_contents->controller(); 1979 NavigationController& other_controller = other_contents->controller();
1976 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED); 1980 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED);
1981 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
1977 other_controller.CopyStateFromAndPrune(&controller(), false); 1982 other_controller.CopyStateFromAndPrune(&controller(), false);
1978 1983
1979 // other_controller should now contain 1 entry for url1, and a pending entry 1984 // other_controller should now contain 1 entry for url1, and a pending entry
1980 // for url3. 1985 // for url3.
1981 1986
1982 ASSERT_EQ(1, other_controller.entry_count()); 1987 ASSERT_EQ(1, other_controller.entry_count());
1983 1988
1984 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 1989 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
1985 1990
1986 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1991 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1987 1992
1988 // And there should be a pending entry for url3. 1993 // And there should be a pending entry for url3.
1989 ASSERT_TRUE(other_controller.pending_entry()); 1994 ASSERT_TRUE(other_controller.pending_entry());
1990 1995
1991 EXPECT_EQ(url3, other_controller.pending_entry()->url()); 1996 EXPECT_EQ(url3, other_controller.pending_entry()->url());
1992 } 1997 }
1993 1998
1994 // Test CopyStateFromAndPrune with 1 url in source, nothing in target and 1999 // Test CopyStateFromAndPrune with 1 url in source, nothing in target and
1995 // remove_first = true. 2000 // remove_first = true.
1996 TEST_F(NavigationControllerTest, CopyStateFromAndPrune4) { 2001 TEST_F(NavigationControllerTest, CopyStateFromAndPrune4) {
1997 const GURL url1("http://foo1"); 2002 const GURL url1("http://foo1");
1998 2003
1999 NavigateAndCommit(url1); 2004 NavigateAndCommit(url1);
2000 2005
2001 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 2006 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
2002 NavigationController& other_controller = other_contents->controller(); 2007 NavigationController& other_controller = other_contents->controller();
2008 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
2003 other_controller.CopyStateFromAndPrune(&controller(), true); 2009 other_controller.CopyStateFromAndPrune(&controller(), true);
2004 2010
2005 // other_controller should now contain 1 entry for url1. 2011 // other_controller should now contain 1 entry for url1.
2006 2012
2007 ASSERT_EQ(1, other_controller.entry_count()); 2013 ASSERT_EQ(1, other_controller.entry_count());
2008 2014
2009 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 2015 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
2010 2016
2011 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 2017 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
2012 2018
2013 // And there should be a pending entry for url3. 2019 // And there should be a pending entry for url3.
2014 ASSERT_FALSE(other_controller.pending_entry()); 2020 ASSERT_FALSE(other_controller.pending_entry());
2015 } 2021 }
2016 2022
2017 // Test CopyStateFromAndPrune with 1 url in source, 1 in target and 2023 // Test CopyStateFromAndPrune with 1 url in source, 1 in target and
2018 // remove_first = true. 2024 // remove_first = true.
2019 TEST_F(NavigationControllerTest, CopyStateFromAndPrune5) { 2025 TEST_F(NavigationControllerTest, CopyStateFromAndPrune5) {
2020 const GURL url1("http://foo1"); 2026 const GURL url1("http://foo1");
2021 const GURL url2("http://foo2"); 2027 const GURL url2("http://foo2");
2022 2028
2023 NavigateAndCommit(url1); 2029 NavigateAndCommit(url1);
2024 2030
2025 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 2031 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
2026 NavigationController& other_controller = other_contents->controller(); 2032 NavigationController& other_controller = other_contents->controller();
2027 other_contents->NavigateAndCommit(url2); 2033 other_contents->NavigateAndCommit(url2);
2034 other_contents->ExpectSetHistoryLengthAndPrune(
2035 other_controller.GetEntryAtIndex(0)->site_instance(),
2036 1,
2037 other_controller.GetEntryAtIndex(0)->page_id() + 1);
2028 other_controller.CopyStateFromAndPrune(&controller(), true); 2038 other_controller.CopyStateFromAndPrune(&controller(), true);
2029 2039
2030 // other_controller should now contain 1 entry, url1. 2040 // other_controller should now contain 1 entry, url1.
2031 2041
2032 ASSERT_EQ(1, other_controller.entry_count()); 2042 ASSERT_EQ(1, other_controller.entry_count());
2033 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 2043 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
2034 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 2044 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
2035 2045
2036 // And there should be a pending entry for url3. 2046 // And there should be a pending entry for url3.
2037 ASSERT_FALSE(other_controller.pending_entry()); 2047 ASSERT_FALSE(other_controller.pending_entry());
2038 } 2048 }
2039 2049
2040 // Test CopyStateFromAndPrune with 1 url in source, 2 in target and 2050 // Test CopyStateFromAndPrune with 1 url in source, 2 in target and
2041 // remove_first = true. 2051 // remove_first = true.
2042 TEST_F(NavigationControllerTest, CopyStateFromAndPrune6) { 2052 TEST_F(NavigationControllerTest, CopyStateFromAndPrune6) {
2043 const GURL url1("http://foo1"); 2053 const GURL url1("http://foo1");
2044 const GURL url2("http://foo2"); 2054 const GURL url2("http://foo2");
2045 const GURL url3("http://foo2"); 2055 const GURL url3("http://foo2");
2046 2056
2047 NavigateAndCommit(url1); 2057 NavigateAndCommit(url1);
2048 2058
2049 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 2059 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
2050 NavigationController& other_controller = other_contents->controller(); 2060 NavigationController& other_controller = other_contents->controller();
2051 other_contents->NavigateAndCommit(url2); 2061 other_contents->NavigateAndCommit(url2);
2052 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED); 2062 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED);
2063 other_contents->ExpectSetHistoryLengthAndPrune(
2064 other_controller.GetEntryAtIndex(0)->site_instance(),
2065 1,
2066 other_controller.GetEntryAtIndex(0)->page_id() + 1);
2053 other_controller.CopyStateFromAndPrune(&controller(), true); 2067 other_controller.CopyStateFromAndPrune(&controller(), true);
2054 2068
2055 // other_controller should now contain 2 entries: url1, and url3. 2069 // other_controller should now contain 2 entries: url1, and url3.
2056 ASSERT_EQ(1, other_controller.entry_count()); 2070 ASSERT_EQ(1, other_controller.entry_count());
2057 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 2071 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
2058 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 2072 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
2059 2073
2060 // And there should be a pending entry for url3. 2074 // And there should be a pending entry for url3.
2061 ASSERT_TRUE(other_controller.pending_entry()); 2075 ASSERT_TRUE(other_controller.pending_entry());
2062 EXPECT_EQ(url3, other_controller.pending_entry()->url()); 2076 EXPECT_EQ(url3, other_controller.pending_entry()->url());
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 TabNavigation nav(0, url0, GURL(), string16(), 2377 TabNavigation nav(0, url0, GURL(), string16(),
2364 webkit_glue::CreateHistoryStateForURL(url0), 2378 webkit_glue::CreateHistoryStateForURL(url0),
2365 PageTransition::LINK); 2379 PageTransition::LINK);
2366 session_helper_.AssertNavigationEquals(nav, 2380 session_helper_.AssertNavigationEquals(nav,
2367 windows_[0]->tabs[0]->navigations[0]); 2381 windows_[0]->tabs[0]->navigations[0]);
2368 nav.set_url(url2); 2382 nav.set_url(url2);
2369 session_helper_.AssertNavigationEquals(nav, 2383 session_helper_.AssertNavigationEquals(nav,
2370 windows_[0]->tabs[0]->navigations[1]); 2384 windows_[0]->tabs[0]->navigations[1]);
2371 } 2385 }
2372 */ 2386 */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698