| 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 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 SessionID id(controller().session_id()); | 1718 SessionID id(controller().session_id()); |
| 1719 const GURL url1("http://foo1"); | 1719 const GURL url1("http://foo1"); |
| 1720 const GURL url2("http://foo2"); | 1720 const GURL url2("http://foo2"); |
| 1721 const GURL url3("http://foo3"); | 1721 const GURL url3("http://foo3"); |
| 1722 | 1722 |
| 1723 NavigateAndCommit(url1); | 1723 NavigateAndCommit(url1); |
| 1724 NavigateAndCommit(url2); | 1724 NavigateAndCommit(url2); |
| 1725 | 1725 |
| 1726 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); | 1726 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
| 1727 NavigationController& other_controller = other_contents->controller(); | 1727 NavigationController& other_controller = other_contents->controller(); |
| 1728 SessionID other_id(other_controller.session_id()); |
| 1728 other_contents->NavigateAndCommit(url3); | 1729 other_contents->NavigateAndCommit(url3); |
| 1729 other_controller.CopyStateFromAndPrune(&controller()); | 1730 other_controller.CopyStateFromAndPrune(&controller()); |
| 1730 | 1731 |
| 1731 // other_controller should now contain the 3 urls: url1, url2 and url3. | 1732 // other_controller should now contain the 3 urls: url1, url2 and url3. |
| 1732 | 1733 |
| 1733 ASSERT_EQ(3, other_controller.entry_count()); | 1734 ASSERT_EQ(3, other_controller.entry_count()); |
| 1734 | 1735 |
| 1735 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); | 1736 ASSERT_EQ(2, other_controller.GetCurrentEntryIndex()); |
| 1736 | 1737 |
| 1737 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); | 1738 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); |
| 1738 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->url()); | 1739 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->url()); |
| 1739 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->url()); | 1740 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->url()); |
| 1740 | 1741 |
| 1741 // The session id of the new tab should be that of the old, and the old should | 1742 // Make sure session ids didn't change. |
| 1742 // get a new id. | 1743 EXPECT_EQ(id.id(), controller().session_id().id()); |
| 1743 EXPECT_EQ(id.id(), other_controller.session_id().id()); | 1744 EXPECT_EQ(other_id.id(), other_controller.session_id().id()); |
| 1744 EXPECT_NE(id.id(), controller().session_id().id()); | |
| 1745 } | 1745 } |
| 1746 | 1746 |
| 1747 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in | 1747 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in |
| 1748 // the target. | 1748 // the target. |
| 1749 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) { | 1749 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) { |
| 1750 SessionID id(controller().session_id()); | 1750 SessionID id(controller().session_id()); |
| 1751 const GURL url1("http://foo1"); | 1751 const GURL url1("http://foo1"); |
| 1752 const GURL url2("http://foo2"); | 1752 const GURL url2("http://foo2"); |
| 1753 const GURL url3("http://foo3"); | 1753 const GURL url3("http://foo3"); |
| 1754 | 1754 |
| 1755 NavigateAndCommit(url1); | 1755 NavigateAndCommit(url1); |
| 1756 NavigateAndCommit(url2); | 1756 NavigateAndCommit(url2); |
| 1757 controller().GoBack(); | 1757 controller().GoBack(); |
| 1758 | 1758 |
| 1759 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); | 1759 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
| 1760 NavigationController& other_controller = other_contents->controller(); | 1760 NavigationController& other_controller = other_contents->controller(); |
| 1761 SessionID other_id(other_controller.session_id()); |
| 1761 other_controller.CopyStateFromAndPrune(&controller()); | 1762 other_controller.CopyStateFromAndPrune(&controller()); |
| 1762 | 1763 |
| 1763 // other_controller should now contain the 1 url: url1. | 1764 // other_controller should now contain the 1 url: url1. |
| 1764 | 1765 |
| 1765 ASSERT_EQ(1, other_controller.entry_count()); | 1766 ASSERT_EQ(1, other_controller.entry_count()); |
| 1766 | 1767 |
| 1767 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); | 1768 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); |
| 1768 | 1769 |
| 1769 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); | 1770 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); |
| 1770 | 1771 |
| 1771 // The session id of the new tab should be that of the old, and the old should | 1772 // Make sure session ids didn't change. |
| 1772 // get a new id. | 1773 EXPECT_EQ(id.id(), controller().session_id().id()); |
| 1773 EXPECT_EQ(id.id(), other_controller.session_id().id()); | 1774 EXPECT_EQ(other_id.id(), other_controller.session_id().id()); |
| 1774 EXPECT_NE(id.id(), controller().session_id().id()); | |
| 1775 } | 1775 } |
| 1776 | 1776 |
| 1777 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in | 1777 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in |
| 1778 // the target. | 1778 // the target. |
| 1779 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { | 1779 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { |
| 1780 SessionID id(controller().session_id()); | 1780 SessionID id(controller().session_id()); |
| 1781 const GURL url1("http://foo1"); | 1781 const GURL url1("http://foo1"); |
| 1782 const GURL url2("http://foo2"); | 1782 const GURL url2("http://foo2"); |
| 1783 const GURL url3("http://foo3"); | 1783 const GURL url3("http://foo3"); |
| 1784 | 1784 |
| 1785 NavigateAndCommit(url1); | 1785 NavigateAndCommit(url1); |
| 1786 NavigateAndCommit(url2); | 1786 NavigateAndCommit(url2); |
| 1787 controller().GoBack(); | 1787 controller().GoBack(); |
| 1788 | 1788 |
| 1789 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); | 1789 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); |
| 1790 NavigationController& other_controller = other_contents->controller(); | 1790 NavigationController& other_controller = other_contents->controller(); |
| 1791 SessionID other_id(other_controller.session_id()); |
| 1791 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED); | 1792 other_controller.LoadURL(url3, GURL(), PageTransition::TYPED); |
| 1792 other_controller.CopyStateFromAndPrune(&controller()); | 1793 other_controller.CopyStateFromAndPrune(&controller()); |
| 1793 | 1794 |
| 1794 // other_controller should now contain 1 entry for url1, and a pending entry | 1795 // other_controller should now contain 1 entry for url1, and a pending entry |
| 1795 // for url3. | 1796 // for url3. |
| 1796 | 1797 |
| 1797 ASSERT_EQ(1, other_controller.entry_count()); | 1798 ASSERT_EQ(1, other_controller.entry_count()); |
| 1798 | 1799 |
| 1799 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); | 1800 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); |
| 1800 | 1801 |
| 1801 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); | 1802 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->url()); |
| 1802 | 1803 |
| 1803 // And there should be a pending entry for url3. | 1804 // And there should be a pending entry for url3. |
| 1804 ASSERT_TRUE(other_controller.pending_entry()); | 1805 ASSERT_TRUE(other_controller.pending_entry()); |
| 1805 | 1806 |
| 1806 EXPECT_EQ(url3, other_controller.pending_entry()->url()); | 1807 EXPECT_EQ(url3, other_controller.pending_entry()->url()); |
| 1807 | 1808 |
| 1808 // The session id of the new tab should be that of the old, and the old should | 1809 // Make sure session ids didn't change. |
| 1809 // be get a new id. | 1810 EXPECT_EQ(id.id(), controller().session_id().id()); |
| 1810 EXPECT_EQ(id.id(), other_controller.session_id().id()); | 1811 EXPECT_EQ(other_id.id(), other_controller.session_id().id()); |
| 1811 EXPECT_NE(id.id(), controller().session_id().id()); | |
| 1812 } | 1812 } |
| 1813 | 1813 |
| 1814 // Tests that navigations initiated from the page (with the history object) | 1814 // Tests that navigations initiated from the page (with the history object) |
| 1815 // work as expected without navigation entries. | 1815 // work as expected without navigation entries. |
| 1816 TEST_F(NavigationControllerTest, HistoryNavigate) { | 1816 TEST_F(NavigationControllerTest, HistoryNavigate) { |
| 1817 const GURL url1("http://foo1"); | 1817 const GURL url1("http://foo1"); |
| 1818 const GURL url2("http://foo2"); | 1818 const GURL url2("http://foo2"); |
| 1819 const GURL url3("http://foo3"); | 1819 const GURL url3("http://foo3"); |
| 1820 | 1820 |
| 1821 NavigateAndCommit(url1); | 1821 NavigateAndCommit(url1); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 PageTransition::LINK); | 2025 PageTransition::LINK); |
| 2026 session_helper_.AssertNavigationEquals(nav, | 2026 session_helper_.AssertNavigationEquals(nav, |
| 2027 windows_[0]->tabs[0]->navigations[0]); | 2027 windows_[0]->tabs[0]->navigations[0]); |
| 2028 nav.set_url(url2); | 2028 nav.set_url(url2); |
| 2029 session_helper_.AssertNavigationEquals(nav, | 2029 session_helper_.AssertNavigationEquals(nav, |
| 2030 windows_[0]->tabs[0]->navigations[1]); | 2030 windows_[0]->tabs[0]->navigations[1]); |
| 2031 } | 2031 } |
| 2032 */ | 2032 */ |
| 2033 | 2033 |
| 2034 } // namespace | 2034 } // namespace |
| OLD | NEW |