OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.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 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 | 1798 |
1799 // And there should be a pending entry for url3. | 1799 // And there should be a pending entry for url3. |
1800 ASSERT_TRUE(other_controller.pending_entry()); | 1800 ASSERT_TRUE(other_controller.pending_entry()); |
1801 | 1801 |
1802 EXPECT_EQ(url3, other_controller.pending_entry()->url()); | 1802 EXPECT_EQ(url3, other_controller.pending_entry()->url()); |
1803 | 1803 |
1804 // And the session id should have been copied. | 1804 // And the session id should have been copied. |
1805 EXPECT_EQ(controller().session_id().id(), other_controller.session_id().id()); | 1805 EXPECT_EQ(controller().session_id().id(), other_controller.session_id().id()); |
1806 } | 1806 } |
1807 | 1807 |
| 1808 // Tests that navigations initiated from the page (with the history object) |
| 1809 // work as expected without navigation entries. |
| 1810 TEST_F(NavigationControllerTest, HistoryNavigate) { |
| 1811 const GURL url1("http://foo1"); |
| 1812 const GURL url2("http://foo2"); |
| 1813 const GURL url3("http://foo3"); |
| 1814 |
| 1815 NavigateAndCommit(url1); |
| 1816 NavigateAndCommit(url2); |
| 1817 NavigateAndCommit(url3); |
| 1818 controller().GoBack(); |
| 1819 contents()->CommitPendingNavigation(); |
| 1820 |
| 1821 // Casts the TabContents to a RenderViewHostDelegate::BrowserIntegration so we |
| 1822 // can call GoToEntryAtOffset which is private. |
| 1823 RenderViewHostDelegate::BrowserIntegration* rvh_delegate = |
| 1824 static_cast<RenderViewHostDelegate::BrowserIntegration*>(contents()); |
| 1825 |
| 1826 // Simulate the page calling history.back(), it should not create a pending |
| 1827 // entry. |
| 1828 rvh_delegate->GoToEntryAtOffset(-1); |
| 1829 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 1830 // The actual cross-navigation is suspended until the current RVH tells us |
| 1831 // it unloaded, simulate that. |
| 1832 contents()->ProceedWithCrossSiteNavigation(); |
| 1833 // Also make sure we told the page to navigate. |
| 1834 const IPC::Message* message = |
| 1835 process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); |
| 1836 ASSERT_TRUE(message != NULL); |
| 1837 Tuple1<ViewMsg_Navigate_Params> nav_params; |
| 1838 ViewMsg_Navigate::Read(message, &nav_params); |
| 1839 EXPECT_EQ(url1, nav_params.a.url); |
| 1840 process()->sink().ClearMessages(); |
| 1841 |
| 1842 // Now test history.forward() |
| 1843 rvh_delegate->GoToEntryAtOffset(1); |
| 1844 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 1845 // The actual cross-navigation is suspended until the current RVH tells us |
| 1846 // it unloaded, simulate that. |
| 1847 contents()->ProceedWithCrossSiteNavigation(); |
| 1848 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); |
| 1849 ASSERT_TRUE(message != NULL); |
| 1850 ViewMsg_Navigate::Read(message, &nav_params); |
| 1851 EXPECT_EQ(url3, nav_params.a.url); |
| 1852 process()->sink().ClearMessages(); |
| 1853 |
| 1854 // Make sure an extravagant history.go() doesn't break. |
| 1855 rvh_delegate->GoToEntryAtOffset(120); // Out of bounds. |
| 1856 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 1857 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); |
| 1858 EXPECT_TRUE(message == NULL); |
| 1859 } |
| 1860 |
1808 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot | 1861 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot |
1809 (but not Vista) cleaning up the directory after they run. | 1862 (but not Vista) cleaning up the directory after they run. |
1810 This should be fixed. | 1863 This should be fixed. |
1811 | 1864 |
1812 // A basic test case. Navigates to a single url, and make sure the history | 1865 // A basic test case. Navigates to a single url, and make sure the history |
1813 // db matches. | 1866 // db matches. |
1814 TEST_F(NavigationControllerHistoryTest, Basic) { | 1867 TEST_F(NavigationControllerHistoryTest, Basic) { |
1815 controller().LoadURL(url0, GURL(), PageTransition::LINK); | 1868 controller().LoadURL(url0, GURL(), PageTransition::LINK); |
1816 rvh()->SendNavigate(0, url0); | 1869 rvh()->SendNavigate(0, url0); |
1817 | 1870 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 PageTransition::LINK); | 1933 PageTransition::LINK); |
1881 session_helper_.AssertNavigationEquals(nav, | 1934 session_helper_.AssertNavigationEquals(nav, |
1882 windows_[0]->tabs[0]->navigations[0]); | 1935 windows_[0]->tabs[0]->navigations[0]); |
1883 nav.set_url(url2); | 1936 nav.set_url(url2); |
1884 session_helper_.AssertNavigationEquals(nav, | 1937 session_helper_.AssertNavigationEquals(nav, |
1885 windows_[0]->tabs[0]->navigations[1]); | 1938 windows_[0]->tabs[0]->navigations[1]); |
1886 } | 1939 } |
1887 */ | 1940 */ |
1888 | 1941 |
1889 } // namespace | 1942 } // namespace |
OLD | NEW |