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" |
11 // These are only used for commented out tests. If someone wants to enable | 11 // These are only used for commented out tests. If someone wants to enable |
12 // them, they should be moved to chrome first. | 12 // them, they should be moved to chrome first. |
13 // #include "chrome/browser/history/history.h" | 13 // #include "chrome/browser/history/history.h" |
14 // #include "chrome/browser/profiles/profile_manager.h" | 14 // #include "chrome/browser/profiles/profile_manager.h" |
15 // #include "chrome/browser/sessions/session_service.h" | 15 // #include "chrome/browser/sessions/session_service.h" |
16 // #include "chrome/browser/sessions/session_service_factory.h" | 16 // #include "chrome/browser/sessions/session_service_factory.h" |
17 // #include "chrome/browser/sessions/session_service_test_helper.h" | 17 // #include "chrome/browser/sessions/session_service_test_helper.h" |
18 // #include "chrome/browser/sessions/session_types.h" | 18 // #include "chrome/browser/sessions/session_types.h" |
19 #include "content/browser/renderer_host/test_render_view_host.h" | 19 #include "content/browser/renderer_host/test_render_view_host.h" |
20 #include "content/browser/site_instance.h" | 20 #include "content/browser/site_instance_impl.h" |
21 #include "content/browser/tab_contents/navigation_controller_impl.h" | 21 #include "content/browser/tab_contents/navigation_controller_impl.h" |
22 #include "content/browser/tab_contents/navigation_entry_impl.h" | 22 #include "content/browser/tab_contents/navigation_entry_impl.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/browser/tab_contents/test_tab_contents.h" | 24 #include "content/browser/tab_contents/test_tab_contents.h" |
25 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
26 #include "content/public/browser/navigation_details.h" | 26 #include "content/public/browser/navigation_details.h" |
27 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/web_contents_delegate.h" | 29 #include "content/public/browser/web_contents_delegate.h" |
30 #include "content/test/test_browser_context.h" | 30 #include "content/test/test_browser_context.h" |
(...skipping 25 matching lines...) Expand all Loading... |
56 content::Source<NavigationController>( | 56 content::Source<NavigationController>( |
57 controller)); | 57 controller)); |
58 tracker->ListenFor(content::NOTIFICATION_NAV_LIST_PRUNED, | 58 tracker->ListenFor(content::NOTIFICATION_NAV_LIST_PRUNED, |
59 content::Source<NavigationController>( | 59 content::Source<NavigationController>( |
60 controller)); | 60 controller)); |
61 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_CHANGED, | 61 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_CHANGED, |
62 content::Source<NavigationController>( | 62 content::Source<NavigationController>( |
63 controller)); | 63 controller)); |
64 } | 64 } |
65 | 65 |
66 SiteInstance* GetSiteInstanceFromEntry(NavigationEntry* entry) { | 66 content::SiteInstance* GetSiteInstanceFromEntry(NavigationEntry* entry) { |
67 return NavigationEntryImpl::FromNavigationEntry(entry)->site_instance(); | 67 return NavigationEntryImpl::FromNavigationEntry(entry)->site_instance(); |
68 } | 68 } |
69 | 69 |
70 class TestWebContentsDelegate : public content::WebContentsDelegate { | 70 class TestWebContentsDelegate : public content::WebContentsDelegate { |
71 public: | 71 public: |
72 explicit TestWebContentsDelegate() : | 72 explicit TestWebContentsDelegate() : |
73 navigation_state_change_count_(0) {} | 73 navigation_state_change_count_(0) {} |
74 | 74 |
75 int navigation_state_change_count() { | 75 int navigation_state_change_count() { |
76 return navigation_state_change_count_; | 76 return navigation_state_change_count_; |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 // First navigate three places so we have some back history. | 753 // First navigate three places so we have some back history. |
754 rvh()->SendNavigate(0, kUrl1); | 754 rvh()->SendNavigate(0, kUrl1); |
755 rvh()->SendNavigate(1, kUrl2); | 755 rvh()->SendNavigate(1, kUrl2); |
756 rvh()->SendNavigate(2, kUrl3); | 756 rvh()->SendNavigate(2, kUrl3); |
757 | 757 |
758 // With nothing pending, say we get a navigation to the second entry. | 758 // With nothing pending, say we get a navigation to the second entry. |
759 rvh()->SendNavigate(1, kUrl2); | 759 rvh()->SendNavigate(1, kUrl2); |
760 | 760 |
761 // We know all the entries have the same site instance, so we can just grab | 761 // We know all the entries have the same site instance, so we can just grab |
762 // a random one for looking up other entries. | 762 // a random one for looking up other entries. |
763 SiteInstance* site_instance = NavigationEntryImpl::FromNavigationEntry( | 763 content::SiteInstance* site_instance = |
764 controller.GetLastCommittedEntry())->site_instance(); | 764 NavigationEntryImpl::FromNavigationEntry( |
| 765 controller.GetLastCommittedEntry())->site_instance(); |
765 | 766 |
766 // That second URL should be the last committed and it should have gotten the | 767 // That second URL should be the last committed and it should have gotten the |
767 // new title. | 768 // new title. |
768 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 769 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
769 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 770 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
770 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 771 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
771 | 772 |
772 // Now go forward to the last item again and say it was committed. | 773 // Now go forward to the last item again and say it was committed. |
773 controller.GoForward(); | 774 controller.GoForward(); |
774 rvh()->SendNavigate(2, kUrl3); | 775 rvh()->SendNavigate(2, kUrl3); |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 | 1572 |
1572 // There should be no longer any pending entry and one committed one. This | 1573 // There should be no longer any pending entry and one committed one. This |
1573 // means that we were able to locate the entry, assign its site instance, and | 1574 // means that we were able to locate the entry, assign its site instance, and |
1574 // commit it properly. | 1575 // commit it properly. |
1575 EXPECT_EQ(1, our_controller.GetEntryCount()); | 1576 EXPECT_EQ(1, our_controller.GetEntryCount()); |
1576 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 1577 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
1577 EXPECT_FALSE(our_controller.GetPendingEntry()); | 1578 EXPECT_FALSE(our_controller.GetPendingEntry()); |
1578 EXPECT_EQ(url, | 1579 EXPECT_EQ(url, |
1579 NavigationEntryImpl::FromNavigationEntry( | 1580 NavigationEntryImpl::FromNavigationEntry( |
1580 our_controller.GetLastCommittedEntry())->site_instance()-> | 1581 our_controller.GetLastCommittedEntry())->site_instance()-> |
1581 site()); | 1582 GetSite()); |
1582 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 1583 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1583 NavigationEntryImpl::FromNavigationEntry( | 1584 NavigationEntryImpl::FromNavigationEntry( |
1584 our_controller.GetEntryAtIndex(0))->restore_type()); | 1585 our_controller.GetEntryAtIndex(0))->restore_type()); |
1585 } | 1586 } |
1586 | 1587 |
1587 // Tests that we can still navigate to a restored entry after a different | 1588 // Tests that we can still navigate to a restored entry after a different |
1588 // navigation fails and clears the pending entry. http://crbug.com/90085 | 1589 // navigation fails and clears the pending entry. http://crbug.com/90085 |
1589 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 1590 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
1590 // Create a NavigationController with a restored set of tabs. | 1591 // Create a NavigationController with a restored set of tabs. |
1591 GURL url("http://foo"); | 1592 GURL url("http://foo"); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 content::LoadCommittedDetails details; | 1652 content::LoadCommittedDetails details; |
1652 our_controller.RendererDidNavigate(params, &details); | 1653 our_controller.RendererDidNavigate(params, &details); |
1653 | 1654 |
1654 // There should be no pending entry and one committed one. | 1655 // There should be no pending entry and one committed one. |
1655 EXPECT_EQ(1, our_controller.GetEntryCount()); | 1656 EXPECT_EQ(1, our_controller.GetEntryCount()); |
1656 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 1657 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
1657 EXPECT_FALSE(our_controller.GetPendingEntry()); | 1658 EXPECT_FALSE(our_controller.GetPendingEntry()); |
1658 EXPECT_EQ(url, | 1659 EXPECT_EQ(url, |
1659 NavigationEntryImpl::FromNavigationEntry( | 1660 NavigationEntryImpl::FromNavigationEntry( |
1660 our_controller.GetLastCommittedEntry())->site_instance()-> | 1661 our_controller.GetLastCommittedEntry())->site_instance()-> |
1661 site()); | 1662 GetSite()); |
1662 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 1663 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
1663 NavigationEntryImpl::FromNavigationEntry( | 1664 NavigationEntryImpl::FromNavigationEntry( |
1664 our_controller.GetEntryAtIndex(0))->restore_type()); | 1665 our_controller.GetEntryAtIndex(0))->restore_type()); |
1665 } | 1666 } |
1666 | 1667 |
1667 // Make sure that the page type and stuff is correct after an interstitial. | 1668 // Make sure that the page type and stuff is correct after an interstitial. |
1668 TEST_F(NavigationControllerTest, Interstitial) { | 1669 TEST_F(NavigationControllerTest, Interstitial) { |
1669 NavigationControllerImpl& controller = controller_impl(); | 1670 NavigationControllerImpl& controller = controller_impl(); |
1670 // First navigate somewhere normal. | 1671 // First navigate somewhere normal. |
1671 const GURL url1("http://foo"); | 1672 const GURL url1("http://foo"); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 TEST_F(NavigationControllerTest, CopyStateFromAndPrune) { | 2057 TEST_F(NavigationControllerTest, CopyStateFromAndPrune) { |
2057 NavigationControllerImpl& controller = controller_impl(); | 2058 NavigationControllerImpl& controller = controller_impl(); |
2058 const GURL url1("http://foo/1"); | 2059 const GURL url1("http://foo/1"); |
2059 const GURL url2("http://foo/2"); | 2060 const GURL url2("http://foo/2"); |
2060 const GURL url3("http://foo/3"); | 2061 const GURL url3("http://foo/3"); |
2061 | 2062 |
2062 NavigateAndCommit(url1); | 2063 NavigateAndCommit(url1); |
2063 NavigateAndCommit(url2); | 2064 NavigateAndCommit(url2); |
2064 | 2065 |
2065 // First two entries should have the same SiteInstance. | 2066 // First two entries should have the same SiteInstance. |
2066 SiteInstance* instance1 = | 2067 content::SiteInstance* instance1 = |
2067 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)); | 2068 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)); |
2068 SiteInstance* instance2 = | 2069 content::SiteInstance* instance2 = |
2069 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)); | 2070 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)); |
2070 EXPECT_EQ(instance1, instance2); | 2071 EXPECT_EQ(instance1, instance2); |
2071 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID()); | 2072 EXPECT_EQ(0, controller.GetEntryAtIndex(0)->GetPageID()); |
2072 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); | 2073 EXPECT_EQ(1, controller.GetEntryAtIndex(1)->GetPageID()); |
2073 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); | 2074 EXPECT_EQ(1, contents()->GetMaxPageIDForSiteInstance(instance1)); |
2074 | 2075 |
2075 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); | 2076 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
2076 NavigationControllerImpl& other_controller = | 2077 NavigationControllerImpl& other_controller = |
2077 other_contents->GetControllerImpl(); | 2078 other_contents->GetControllerImpl(); |
2078 other_contents->NavigateAndCommit(url3); | 2079 other_contents->NavigateAndCommit(url3); |
2079 other_contents->ExpectSetHistoryLengthAndPrune( | 2080 other_contents->ExpectSetHistoryLengthAndPrune( |
2080 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, | 2081 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)), 2, |
2081 other_controller.GetEntryAtIndex(0)->GetPageID()); | 2082 other_controller.GetEntryAtIndex(0)->GetPageID()); |
2082 other_controller.CopyStateFromAndPrune(&controller); | 2083 other_controller.CopyStateFromAndPrune(&controller); |
2083 | 2084 |
2084 // other_controller should now contain the 3 urls: url1, url2 and url3. | 2085 // other_controller should now contain the 3 urls: url1, url2 and url3. |
2085 | 2086 |
2086 ASSERT_EQ(3, other_controller.GetEntryCount()); | 2087 ASSERT_EQ(3, other_controller.GetEntryCount()); |
2087 | 2088 |
2088 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); | 2089 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
2089 | 2090 |
2090 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 2091 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
2091 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); | 2092 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); |
2092 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); | 2093 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL()); |
2093 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); | 2094 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); |
2094 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID()); | 2095 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID()); |
2095 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); | 2096 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); |
2096 | 2097 |
2097 // A new SiteInstance should be used for the new tab. | 2098 // A new SiteInstance should be used for the new tab. |
2098 SiteInstance* instance3 = | 2099 content::SiteInstance* instance3 = |
2099 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); | 2100 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(2)); |
2100 EXPECT_NE(instance3, instance1); | 2101 EXPECT_NE(instance3, instance1); |
2101 | 2102 |
2102 // The max page ID map should be copied over and updated with the max page ID | 2103 // The max page ID map should be copied over and updated with the max page ID |
2103 // from the current tab. | 2104 // from the current tab. |
2104 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 2105 EXPECT_EQ(1, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
2105 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); | 2106 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance3)); |
2106 } | 2107 } |
2107 | 2108 |
2108 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in | 2109 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in |
(...skipping 18 matching lines...) Expand all Loading... |
2127 | 2128 |
2128 ASSERT_EQ(1, other_controller.GetEntryCount()); | 2129 ASSERT_EQ(1, other_controller.GetEntryCount()); |
2129 | 2130 |
2130 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); | 2131 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); |
2131 | 2132 |
2132 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 2133 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
2133 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); | 2134 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); |
2134 | 2135 |
2135 // The max page ID map should be copied over and updated with the max page ID | 2136 // The max page ID map should be copied over and updated with the max page ID |
2136 // from the current tab. | 2137 // from the current tab. |
2137 SiteInstance* instance1 = | 2138 content::SiteInstance* instance1 = |
2138 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); | 2139 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); |
2139 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 2140 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
2140 } | 2141 } |
2141 | 2142 |
2142 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in | 2143 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in |
2143 // the target. | 2144 // the target. |
2144 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { | 2145 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { |
2145 NavigationControllerImpl& controller = controller_impl(); | 2146 NavigationControllerImpl& controller = controller_impl(); |
2146 const GURL url1("http://foo1"); | 2147 const GURL url1("http://foo1"); |
2147 const GURL url2("http://foo2"); | 2148 const GURL url2("http://foo2"); |
(...skipping 20 matching lines...) Expand all Loading... |
2168 | 2169 |
2169 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 2170 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
2170 | 2171 |
2171 // And there should be a pending entry for url3. | 2172 // And there should be a pending entry for url3. |
2172 ASSERT_TRUE(other_controller.GetPendingEntry()); | 2173 ASSERT_TRUE(other_controller.GetPendingEntry()); |
2173 | 2174 |
2174 EXPECT_EQ(url3, other_controller.GetPendingEntry()->GetURL()); | 2175 EXPECT_EQ(url3, other_controller.GetPendingEntry()->GetURL()); |
2175 | 2176 |
2176 // The max page ID map should be copied over and updated with the max page ID | 2177 // The max page ID map should be copied over and updated with the max page ID |
2177 // from the current tab. | 2178 // from the current tab. |
2178 SiteInstance* instance1 = | 2179 content::SiteInstance* instance1 = |
2179 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); | 2180 GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); |
2180 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 2181 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
2181 } | 2182 } |
2182 | 2183 |
2183 // Tests that navigations initiated from the page (with the history object) | 2184 // Tests that navigations initiated from the page (with the history object) |
2184 // work as expected without navigation entries. | 2185 // work as expected without navigation entries. |
2185 TEST_F(NavigationControllerTest, HistoryNavigate) { | 2186 TEST_F(NavigationControllerTest, HistoryNavigate) { |
2186 NavigationControllerImpl& controller = controller_impl(); | 2187 NavigationControllerImpl& controller = controller_impl(); |
2187 const GURL url1("http://foo/1"); | 2188 const GURL url1("http://foo/1"); |
2188 const GURL url2("http://foo/2"); | 2189 const GURL url2("http://foo/2"); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 TabNavigation nav(0, url0, GURL(), string16(), | 2517 TabNavigation nav(0, url0, GURL(), string16(), |
2517 webkit_glue::CreateHistoryStateForURL(url0), | 2518 webkit_glue::CreateHistoryStateForURL(url0), |
2518 content::PAGE_TRANSITION_LINK); | 2519 content::PAGE_TRANSITION_LINK); |
2519 session_helper_.AssertNavigationEquals(nav, | 2520 session_helper_.AssertNavigationEquals(nav, |
2520 windows_[0]->tabs[0]->navigations[0]); | 2521 windows_[0]->tabs[0]->navigations[0]); |
2521 nav.set_url(url2); | 2522 nav.set_url(url2); |
2522 session_helper_.AssertNavigationEquals(nav, | 2523 session_helper_.AssertNavigationEquals(nav, |
2523 windows_[0]->tabs[0]->navigations[1]); | 2524 windows_[0]->tabs[0]->navigations[1]); |
2524 } | 2525 } |
2525 */ | 2526 */ |
OLD | NEW |