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

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

Issue 7649009: Merge of 97624 to 835 branch. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/835/src/
Patch Set: 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 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 const GURL url1("http://foo1"); 1840 const GURL url1("http://foo1");
1841 const GURL url2("http://foo2"); 1841 const GURL url2("http://foo2");
1842 const GURL url3("http://foo3"); 1842 const GURL url3("http://foo3");
1843 1843
1844 NavigateAndCommit(url1); 1844 NavigateAndCommit(url1);
1845 NavigateAndCommit(url2); 1845 NavigateAndCommit(url2);
1846 1846
1847 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1847 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1848 NavigationController& other_controller = other_contents->controller(); 1848 NavigationController& other_controller = other_contents->controller();
1849 other_contents->NavigateAndCommit(url3); 1849 other_contents->NavigateAndCommit(url3);
1850 other_contents->ExpectSetHistoryLengthAndPrune(
1851 other_controller.GetEntryAtIndex(0)->site_instance(), 2,
1852 other_controller.GetEntryAtIndex(0)->page_id());
1850 other_controller.CopyStateFromAndPrune(&controller(), false); 1853 other_controller.CopyStateFromAndPrune(&controller(), false);
1851 1854
1852 // other_controller should now contain the 3 urls: url1, url2 and url3. 1855 // other_controller should now contain the 3 urls: url1, url2 and url3.
1853 1856
1854 ASSERT_EQ(3, other_controller.entry_count()); 1857 ASSERT_EQ(3, other_controller.entry_count());
1855 1858
1856 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); 1859 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
1857 1860
1858 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1861 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1859 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->url()); 1862 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->url());
1860 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->url()); 1863 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->url());
1861 } 1864 }
1862 1865
1863 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in 1866 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in
1864 // the target. 1867 // the target.
1865 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) { 1868 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) {
1866 const GURL url1("http://foo1"); 1869 const GURL url1("http://foo1");
1867 const GURL url2("http://foo2"); 1870 const GURL url2("http://foo2");
1868 const GURL url3("http://foo3"); 1871 const GURL url3("http://foo3");
1869 1872
1870 NavigateAndCommit(url1); 1873 NavigateAndCommit(url1);
1871 NavigateAndCommit(url2); 1874 NavigateAndCommit(url2);
1872 controller().GoBack(); 1875 controller().GoBack();
1873 1876
1874 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1877 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1875 NavigationController& other_controller = other_contents->controller(); 1878 NavigationController& other_controller = other_contents->controller();
1879 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
1876 other_controller.CopyStateFromAndPrune(&controller(), false); 1880 other_controller.CopyStateFromAndPrune(&controller(), false);
1877 1881
1878 // other_controller should now contain the 1 url: url1. 1882 // other_controller should now contain the 1 url: url1.
1879 1883
1880 ASSERT_EQ(1, other_controller.entry_count()); 1884 ASSERT_EQ(1, other_controller.entry_count());
1881 1885
1882 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); 1886 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex());
1883 1887
1884 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1888 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1885 } 1889 }
1886 1890
1887 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in 1891 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in
1888 // the target. 1892 // the target.
1889 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { 1893 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) {
1890 const GURL url1("http://foo1"); 1894 const GURL url1("http://foo1");
1891 const GURL url2("http://foo2"); 1895 const GURL url2("http://foo2");
1892 const GURL url3("http://foo3"); 1896 const GURL url3("http://foo3");
1893 1897
1894 NavigateAndCommit(url1); 1898 NavigateAndCommit(url1);
1895 NavigateAndCommit(url2); 1899 NavigateAndCommit(url2);
1896 controller().GoBack(); 1900 controller().GoBack();
1897 1901
1898 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1902 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1899 NavigationController& other_controller = other_contents->controller(); 1903 NavigationController& other_controller = other_contents->controller();
1900 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED); 1904 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED);
1905 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
1901 other_controller.CopyStateFromAndPrune(&controller(), false); 1906 other_controller.CopyStateFromAndPrune(&controller(), false);
1902 1907
1903 // other_controller should now contain 1 entry for url1, and a pending entry 1908 // other_controller should now contain 1 entry for url1, and a pending entry
1904 // for url3. 1909 // for url3.
1905 1910
1906 ASSERT_EQ(1, other_controller.entry_count()); 1911 ASSERT_EQ(1, other_controller.entry_count());
1907 1912
1908 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 1913 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
1909 1914
1910 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1915 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1911 1916
1912 // And there should be a pending entry for url3. 1917 // And there should be a pending entry for url3.
1913 ASSERT_TRUE(other_controller.pending_entry()); 1918 ASSERT_TRUE(other_controller.pending_entry());
1914 1919
1915 EXPECT_EQ(url3, other_controller.pending_entry()->url()); 1920 EXPECT_EQ(url3, other_controller.pending_entry()->url());
1916 } 1921 }
1917 1922
1918 // Test CopyStateFromAndPrune with 1 url in source, nothing in target and 1923 // Test CopyStateFromAndPrune with 1 url in source, nothing in target and
1919 // remove_first = true. 1924 // remove_first = true.
1920 TEST_F(NavigationControllerTest, CopyStateFromAndPrune4) { 1925 TEST_F(NavigationControllerTest, CopyStateFromAndPrune4) {
1921 const GURL url1("http://foo1"); 1926 const GURL url1("http://foo1");
1922 1927
1923 NavigateAndCommit(url1); 1928 NavigateAndCommit(url1);
1924 1929
1925 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1930 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1926 NavigationController& other_controller = other_contents->controller(); 1931 NavigationController& other_controller = other_contents->controller();
1932 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
1927 other_controller.CopyStateFromAndPrune(&controller(), true); 1933 other_controller.CopyStateFromAndPrune(&controller(), true);
1928 1934
1929 // other_controller should now contain 1 entry for url1. 1935 // other_controller should now contain 1 entry for url1.
1930 1936
1931 ASSERT_EQ(1, other_controller.entry_count()); 1937 ASSERT_EQ(1, other_controller.entry_count());
1932 1938
1933 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 1939 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
1934 1940
1935 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1941 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1936 1942
1937 // And there should be a pending entry for url3. 1943 // And there should be a pending entry for url3.
1938 ASSERT_FALSE(other_controller.pending_entry()); 1944 ASSERT_FALSE(other_controller.pending_entry());
1939 } 1945 }
1940 1946
1941 // Test CopyStateFromAndPrune with 1 url in source, 1 in target and 1947 // Test CopyStateFromAndPrune with 1 url in source, 1 in target and
1942 // remove_first = true. 1948 // remove_first = true.
1943 TEST_F(NavigationControllerTest, CopyStateFromAndPrune5) { 1949 TEST_F(NavigationControllerTest, CopyStateFromAndPrune5) {
1944 const GURL url1("http://foo1"); 1950 const GURL url1("http://foo1");
1945 const GURL url2("http://foo2"); 1951 const GURL url2("http://foo2");
1946 1952
1947 NavigateAndCommit(url1); 1953 NavigateAndCommit(url1);
1948 1954
1949 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1955 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1950 NavigationController& other_controller = other_contents->controller(); 1956 NavigationController& other_controller = other_contents->controller();
1951 other_contents->NavigateAndCommit(url2); 1957 other_contents->NavigateAndCommit(url2);
1958 other_contents->ExpectSetHistoryLengthAndPrune(
1959 other_controller.GetEntryAtIndex(0)->site_instance(),
1960 1,
1961 other_controller.GetEntryAtIndex(0)->page_id() + 1);
1952 other_controller.CopyStateFromAndPrune(&controller(), true); 1962 other_controller.CopyStateFromAndPrune(&controller(), true);
1953 1963
1954 // other_controller should now contain 1 entry, url1. 1964 // other_controller should now contain 1 entry, url1.
1955 1965
1956 ASSERT_EQ(1, other_controller.entry_count()); 1966 ASSERT_EQ(1, other_controller.entry_count());
1957 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 1967 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
1958 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1968 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1959 1969
1960 // And there should be a pending entry for url3. 1970 // And there should be a pending entry for url3.
1961 ASSERT_FALSE(other_controller.pending_entry()); 1971 ASSERT_FALSE(other_controller.pending_entry());
1962 } 1972 }
1963 1973
1964 // Test CopyStateFromAndPrune with 1 url in source, 2 in target and 1974 // Test CopyStateFromAndPrune with 1 url in source, 2 in target and
1965 // remove_first = true. 1975 // remove_first = true.
1966 TEST_F(NavigationControllerTest, CopyStateFromAndPrune6) { 1976 TEST_F(NavigationControllerTest, CopyStateFromAndPrune6) {
1967 const GURL url1("http://foo1"); 1977 const GURL url1("http://foo1");
1968 const GURL url2("http://foo2"); 1978 const GURL url2("http://foo2");
1969 const GURL url3("http://foo2"); 1979 const GURL url3("http://foo2");
1970 1980
1971 NavigateAndCommit(url1); 1981 NavigateAndCommit(url1);
1972 1982
1973 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1983 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
1974 NavigationController& other_controller = other_contents->controller(); 1984 NavigationController& other_controller = other_contents->controller();
1975 other_contents->NavigateAndCommit(url2); 1985 other_contents->NavigateAndCommit(url2);
1976 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED); 1986 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED);
1987 other_contents->ExpectSetHistoryLengthAndPrune(
1988 other_controller.GetEntryAtIndex(0)->site_instance(),
1989 1,
1990 other_controller.GetEntryAtIndex(0)->page_id() + 1);
1977 other_controller.CopyStateFromAndPrune(&controller(), true); 1991 other_controller.CopyStateFromAndPrune(&controller(), true);
1978 1992
1979 // other_controller should now contain 2 entries: url1, and url3. 1993 // other_controller should now contain 2 entries: url1, and url3.
1980 ASSERT_EQ(1, other_controller.entry_count()); 1994 ASSERT_EQ(1, other_controller.entry_count());
1981 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); 1995 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex());
1982 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); 1996 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url());
1983 1997
1984 // And there should be a pending entry for url3. 1998 // And there should be a pending entry for url3.
1985 ASSERT_TRUE(other_controller.pending_entry()); 1999 ASSERT_TRUE(other_controller.pending_entry());
1986 EXPECT_EQ(url3, other_controller.pending_entry()->url()); 2000 EXPECT_EQ(url3, other_controller.pending_entry()->url());
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 TabNavigation nav(0, url0, GURL(), string16(), 2301 TabNavigation nav(0, url0, GURL(), string16(),
2288 webkit_glue::CreateHistoryStateForURL(url0), 2302 webkit_glue::CreateHistoryStateForURL(url0),
2289 PageTransition::LINK); 2303 PageTransition::LINK);
2290 session_helper_.AssertNavigationEquals(nav, 2304 session_helper_.AssertNavigationEquals(nav,
2291 windows_[0]->tabs[0]->navigations[0]); 2305 windows_[0]->tabs[0]->navigations[0]);
2292 nav.set_url(url2); 2306 nav.set_url(url2);
2293 session_helper_.AssertNavigationEquals(nav, 2307 session_helper_.AssertNavigationEquals(nav,
2294 windows_[0]->tabs[0]->navigations[1]); 2308 windows_[0]->tabs[0]->navigations[1]);
2295 } 2309 }
2296 */ 2310 */
OLDNEW
« no previous file with comments | « content/browser/tab_contents/navigation_controller.cc ('k') | content/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698