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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 556703004: Remove page id from FrameNavigateParams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleaner Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 // We should update the post state on the NavigationEntry. 625 // We should update the post state on the NavigationEntry.
626 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) { 626 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) {
627 NavigationControllerImpl& controller = controller_impl(); 627 NavigationControllerImpl& controller = controller_impl();
628 TestNotificationTracker notifications; 628 TestNotificationTracker notifications;
629 RegisterForAllNavNotifications(&notifications, &controller); 629 RegisterForAllNavNotifications(&notifications, &controller);
630 630
631 const GURL url1("http://foo1"); 631 const GURL url1("http://foo1");
632 632
633 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 633 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
634 FrameHostMsg_DidCommitProvisionalLoad_Params params; 634 FrameHostMsg_DidCommitProvisionalLoad_Params params;
635 params.page_id = 0;
636 params.url = url1; 635 params.url = url1;
637 params.transition = PAGE_TRANSITION_TYPED; 636 params.transition = PAGE_TRANSITION_TYPED;
638 params.is_post = true; 637 params.is_post = true;
639 params.post_id = 123; 638 params.post_id = 123;
640 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); 639 params.page_state = PageState::CreateForTesting(url1, false, 0, 0);
641 main_test_rfh()->SendNavigateWithParams(&params); 640 main_test_rfh()->SendNavigateWithParams(0, &params);
642 641
643 // The post data should be visible. 642 // The post data should be visible.
644 NavigationEntry* entry = controller.GetVisibleEntry(); 643 NavigationEntry* entry = controller.GetVisibleEntry();
645 ASSERT_TRUE(entry); 644 ASSERT_TRUE(entry);
646 EXPECT_TRUE(entry->GetHasPostData()); 645 EXPECT_TRUE(entry->GetHasPostData());
647 EXPECT_EQ(entry->GetPostID(), 123); 646 EXPECT_EQ(entry->GetPostID(), 123);
648 647
649 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 648 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
650 main_test_rfh()->SendNavigate(0, url1); 649 main_test_rfh()->SendNavigate(0, url1);
651 650
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1023 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1025 EXPECT_EQ(0, delegate->navigation_state_change_count()); 1024 EXPECT_EQ(0, delegate->navigation_state_change_count());
1026 1025
1027 // The visible entry should be the last committed URL, not the pending one. 1026 // The visible entry should be the last committed URL, not the pending one.
1028 EXPECT_EQ(kExistingURL, controller.GetVisibleEntry()->GetURL()); 1027 EXPECT_EQ(kExistingURL, controller.GetVisibleEntry()->GetURL());
1029 1028
1030 // Now the navigation redirects. 1029 // Now the navigation redirects.
1031 const GURL kRedirectURL("http://foo/see"); 1030 const GURL kRedirectURL("http://foo/see");
1032 main_test_rfh()->OnMessageReceived( 1031 main_test_rfh()->OnMessageReceived(
1033 FrameHostMsg_DidRedirectProvisionalLoad(0, // routing_id 1032 FrameHostMsg_DidRedirectProvisionalLoad(0, // routing_id
1034 -1, // pending page_id 1033 1, // pending page_id
1035 kNewURL, // old url 1034 kNewURL, // old url
1036 kRedirectURL)); // new url 1035 kRedirectURL)); // new url
1037 1036
1038 // We don't want to change the NavigationEntry's url, in case it cancels. 1037 // We don't want to change the NavigationEntry's url, in case it cancels.
1039 // Prevents regression of http://crbug.com/77786. 1038 // Prevents regression of http://crbug.com/77786.
1040 EXPECT_EQ(kNewURL, controller.GetPendingEntry()->GetURL()); 1039 EXPECT_EQ(kNewURL, controller.GetPendingEntry()->GetURL());
1041 1040
1042 // It may abort before committing, if it's a download or due to a stop or 1041 // It may abort before committing, if it's a download or due to a stop or
1043 // a new navigation from the user. 1042 // a new navigation from the user.
1044 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; 1043 FrameHostMsg_DidFailProvisionalLoadWithError_Params params;
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 navigation_entry_committed_counter_ = 0; 1685 navigation_entry_committed_counter_ = 0;
1687 1686
1688 // Second request 1687 // Second request
1689 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1688 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1690 1689
1691 EXPECT_TRUE(controller.GetPendingEntry()); 1690 EXPECT_TRUE(controller.GetPendingEntry());
1692 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1691 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1693 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1692 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1694 1693
1695 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1694 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1696 params.page_id = 0;
1697 params.url = url2; 1695 params.url = url2;
1698 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; 1696 params.transition = PAGE_TRANSITION_SERVER_REDIRECT;
1699 params.redirects.push_back(GURL("http://foo1")); 1697 params.redirects.push_back(GURL("http://foo1"));
1700 params.redirects.push_back(GURL("http://foo2")); 1698 params.redirects.push_back(GURL("http://foo2"));
1701 params.should_update_history = false; 1699 params.should_update_history = false;
1702 params.gesture = NavigationGestureAuto; 1700 params.gesture = NavigationGestureAuto;
1703 params.is_post = false; 1701 params.is_post = false;
1704 params.page_state = PageState::CreateFromURL(url2); 1702 params.page_state = PageState::CreateFromURL(url2);
1705 1703
1706 LoadCommittedDetails details; 1704 LoadCommittedDetails details;
1707 1705
1708 EXPECT_EQ(0U, notifications.size()); 1706 EXPECT_EQ(0U, notifications.size());
1709 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1707 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1710 &details)); 1708 &details));
1711 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1709 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1712 navigation_entry_committed_counter_ = 0; 1710 navigation_entry_committed_counter_ = 0;
1713 1711
1714 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1712 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1715 EXPECT_EQ(controller.GetEntryCount(), 1); 1713 EXPECT_EQ(controller.GetEntryCount(), 1);
1716 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1714 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1717 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1715 EXPECT_TRUE(controller.GetLastCommittedEntry());
1718 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1716 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1719 EXPECT_FALSE(controller.GetPendingEntry()); 1717 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 24 matching lines...) Expand all
1744 navigation_entry_committed_counter_ = 0; 1742 navigation_entry_committed_counter_ = 0;
1745 1743
1746 // Second request 1744 // Second request
1747 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1745 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1748 1746
1749 EXPECT_TRUE(controller.GetPendingEntry()); 1747 EXPECT_TRUE(controller.GetPendingEntry());
1750 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1748 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1751 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1749 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1752 1750
1753 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1751 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1754 params.page_id = 0;
1755 params.url = url2; 1752 params.url = url2;
1756 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; 1753 params.transition = PAGE_TRANSITION_SERVER_REDIRECT;
1757 params.redirects.push_back(GURL("http://foo1")); 1754 params.redirects.push_back(GURL("http://foo1"));
1758 params.redirects.push_back(GURL("http://foo2")); 1755 params.redirects.push_back(GURL("http://foo2"));
1759 params.should_update_history = false; 1756 params.should_update_history = false;
1760 params.gesture = NavigationGestureAuto; 1757 params.gesture = NavigationGestureAuto;
1761 params.is_post = false; 1758 params.is_post = false;
1762 params.page_state = PageState::CreateFromURL(url2); 1759 params.page_state = PageState::CreateFromURL(url2);
1763 1760
1764 LoadCommittedDetails details; 1761 LoadCommittedDetails details;
1765 1762
1766 EXPECT_EQ(0U, notifications.size()); 1763 EXPECT_EQ(0U, notifications.size());
1767 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1764 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1768 &details)); 1765 &details));
1769 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1766 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1770 navigation_entry_committed_counter_ = 0; 1767 navigation_entry_committed_counter_ = 0;
1771 1768
1772 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1769 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1773 EXPECT_EQ(controller.GetEntryCount(), 1); 1770 EXPECT_EQ(controller.GetEntryCount(), 1);
1774 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1771 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1775 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1772 EXPECT_TRUE(controller.GetLastCommittedEntry());
1776 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1773 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1777 EXPECT_FALSE(controller.GetPendingEntry()); 1774 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 14 matching lines...) Expand all
1792 const GURL url2("http://foo2"); // Redirection target 1789 const GURL url2("http://foo2"); // Redirection target
1793 1790
1794 // First request 1791 // First request
1795 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1792 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1796 1793
1797 EXPECT_TRUE(controller.GetPendingEntry()); 1794 EXPECT_TRUE(controller.GetPendingEntry());
1798 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1795 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1799 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1796 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1800 1797
1801 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1798 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1802 params.page_id = 0;
1803 params.url = url2; 1799 params.url = url2;
1804 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; 1800 params.transition = PAGE_TRANSITION_SERVER_REDIRECT;
1805 params.redirects.push_back(GURL("http://foo1")); 1801 params.redirects.push_back(GURL("http://foo1"));
1806 params.redirects.push_back(GURL("http://foo2")); 1802 params.redirects.push_back(GURL("http://foo2"));
1807 params.should_update_history = false; 1803 params.should_update_history = false;
1808 params.gesture = NavigationGestureAuto; 1804 params.gesture = NavigationGestureAuto;
1809 params.is_post = false; 1805 params.is_post = false;
1810 params.page_state = PageState::CreateFromURL(url2); 1806 params.page_state = PageState::CreateFromURL(url2);
1811 1807
1812 LoadCommittedDetails details; 1808 LoadCommittedDetails details;
1813 1809
1814 EXPECT_EQ(0U, notifications.size()); 1810 EXPECT_EQ(0U, notifications.size());
1815 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1811 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1816 &details)); 1812 &details));
1817 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1813 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1818 navigation_entry_committed_counter_ = 0; 1814 navigation_entry_committed_counter_ = 0;
1819 1815
1820 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); 1816 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE);
1821 EXPECT_EQ(controller.GetEntryCount(), 1); 1817 EXPECT_EQ(controller.GetEntryCount(), 1);
1822 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1818 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1823 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1819 EXPECT_TRUE(controller.GetLastCommittedEntry());
1824 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1820 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1825 EXPECT_FALSE(controller.GetPendingEntry()); 1821 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 10 matching lines...) Expand all
1836 TestNotificationTracker notifications; 1832 TestNotificationTracker notifications;
1837 RegisterForAllNavNotifications(&notifications, &controller); 1833 RegisterForAllNavNotifications(&notifications, &controller);
1838 1834
1839 const GURL url1("http://foo1"); 1835 const GURL url1("http://foo1");
1840 main_test_rfh()->SendNavigate(0, url1); 1836 main_test_rfh()->SendNavigate(0, url1);
1841 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1837 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1842 navigation_entry_committed_counter_ = 0; 1838 navigation_entry_committed_counter_ = 0;
1843 1839
1844 const GURL url2("http://foo2"); 1840 const GURL url2("http://foo2");
1845 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1841 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1846 params.page_id = 1;
1847 params.url = url2; 1842 params.url = url2;
1848 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; 1843 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
1849 params.should_update_history = false; 1844 params.should_update_history = false;
1850 params.gesture = NavigationGestureUser; 1845 params.gesture = NavigationGestureUser;
1851 params.is_post = false; 1846 params.is_post = false;
1852 params.page_state = PageState::CreateFromURL(url2); 1847 params.page_state = PageState::CreateFromURL(url2);
1853 1848
1854 LoadCommittedDetails details; 1849 LoadCommittedDetails details;
1855 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1850 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1856 &details)); 1851 &details));
1857 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1852 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1858 navigation_entry_committed_counter_ = 0; 1853 navigation_entry_committed_counter_ = 0;
1859 EXPECT_EQ(url1, details.previous_url); 1854 EXPECT_EQ(url1, details.previous_url);
1860 EXPECT_FALSE(details.is_in_page); 1855 EXPECT_FALSE(details.is_in_page);
1861 EXPECT_FALSE(details.is_main_frame); 1856 EXPECT_FALSE(details.is_main_frame);
1862 1857
1863 // The new entry should be appended. 1858 // The new entry should be appended.
1864 EXPECT_EQ(2, controller.GetEntryCount()); 1859 EXPECT_EQ(2, controller.GetEntryCount());
1865 1860
1866 // New entry should refer to the new page, but the old URL (entries only 1861 // New entry should refer to the new page, but the old URL (entries only
1867 // reflect the toplevel URL). 1862 // reflect the toplevel URL).
1868 EXPECT_EQ(url1, details.entry->GetURL()); 1863 EXPECT_EQ(url1, details.entry->GetURL());
1869 EXPECT_EQ(params.page_id, details.entry->GetPageID()); 1864 EXPECT_EQ(1, details.entry->GetPageID());
1870 } 1865 }
1871 1866
1872 // Some pages create a popup, then write an iframe into it. This causes a 1867 // Some pages create a popup, then write an iframe into it. This causes a
1873 // subframe navigation without having any committed entry. Such navigations 1868 // subframe navigation without having any committed entry. Such navigations
1874 // just get thrown on the ground, but we shouldn't crash. 1869 // just get thrown on the ground, but we shouldn't crash.
1875 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { 1870 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) {
1876 NavigationControllerImpl& controller = controller_impl(); 1871 NavigationControllerImpl& controller = controller_impl();
1877 TestNotificationTracker notifications; 1872 TestNotificationTracker notifications;
1878 RegisterForAllNavNotifications(&notifications, &controller); 1873 RegisterForAllNavNotifications(&notifications, &controller);
1879 1874
1880 // Navigation controller currently has no entries. 1875 // Navigation controller currently has no entries.
1881 const GURL url("http://foo2"); 1876 const GURL url("http://foo2");
1882 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1877 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1883 params.page_id = 1;
1884 params.url = url; 1878 params.url = url;
1885 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 1879 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
1886 params.should_update_history = false; 1880 params.should_update_history = false;
1887 params.gesture = NavigationGestureAuto; 1881 params.gesture = NavigationGestureAuto;
1888 params.is_post = false; 1882 params.is_post = false;
1889 params.page_state = PageState::CreateFromURL(url); 1883 params.page_state = PageState::CreateFromURL(url);
1890 1884
1891 LoadCommittedDetails details; 1885 LoadCommittedDetails details;
1892 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 1886 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1893 &details)); 1887 &details));
1894 EXPECT_EQ(0U, notifications.size()); 1888 EXPECT_EQ(0U, notifications.size());
1895 } 1889 }
1896 1890
1897 // Auto subframes are ones the page loads automatically like ads. They should 1891 // Auto subframes are ones the page loads automatically like ads. They should
1898 // not create new navigation entries. 1892 // not create new navigation entries.
1899 TEST_F(NavigationControllerTest, AutoSubframe) { 1893 TEST_F(NavigationControllerTest, AutoSubframe) {
1900 NavigationControllerImpl& controller = controller_impl(); 1894 NavigationControllerImpl& controller = controller_impl();
1901 TestNotificationTracker notifications; 1895 TestNotificationTracker notifications;
1902 RegisterForAllNavNotifications(&notifications, &controller); 1896 RegisterForAllNavNotifications(&notifications, &controller);
1903 1897
1904 const GURL url1("http://foo1"); 1898 const GURL url1("http://foo1");
1905 main_test_rfh()->SendNavigate(0, url1); 1899 main_test_rfh()->SendNavigate(0, url1);
1906 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1900 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1907 navigation_entry_committed_counter_ = 0; 1901 navigation_entry_committed_counter_ = 0;
1908 1902
1909 const GURL url2("http://foo2"); 1903 const GURL url2("http://foo2");
1910 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1904 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1911 params.page_id = 0;
1912 params.url = url2; 1905 params.url = url2;
1913 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 1906 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
1914 params.should_update_history = false; 1907 params.should_update_history = false;
1915 params.gesture = NavigationGestureUser; 1908 params.gesture = NavigationGestureUser;
1916 params.is_post = false; 1909 params.is_post = false;
1917 params.page_state = PageState::CreateFromURL(url2); 1910 params.page_state = PageState::CreateFromURL(url2);
1918 1911
1919 // Navigating should do nothing. 1912 // Navigating should do nothing.
1920 LoadCommittedDetails details; 1913 LoadCommittedDetails details;
1921 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 1914 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1922 &details)); 1915 &details));
1923 EXPECT_EQ(0U, notifications.size()); 1916 EXPECT_EQ(0U, notifications.size());
1924 1917
1925 // There should still be only one entry. 1918 // There should still be only one entry.
1926 EXPECT_EQ(1, controller.GetEntryCount()); 1919 EXPECT_EQ(1, controller.GetEntryCount());
1927 } 1920 }
1928 1921
1929 // Tests navigation and then going back to a subframe navigation. 1922 // Tests navigation and then going back to a subframe navigation.
1930 TEST_F(NavigationControllerTest, BackSubframe) { 1923 TEST_F(NavigationControllerTest, BackSubframe) {
1931 NavigationControllerImpl& controller = controller_impl(); 1924 NavigationControllerImpl& controller = controller_impl();
1932 TestNotificationTracker notifications; 1925 TestNotificationTracker notifications;
1933 RegisterForAllNavNotifications(&notifications, &controller); 1926 RegisterForAllNavNotifications(&notifications, &controller);
1934 1927
1935 // Main page. 1928 // Main page.
1936 const GURL url1("http://foo1"); 1929 const GURL url1("http://foo1");
1937 main_test_rfh()->SendNavigate(0, url1); 1930 main_test_rfh()->SendNavigate(0, url1);
1938 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1931 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1939 navigation_entry_committed_counter_ = 0; 1932 navigation_entry_committed_counter_ = 0;
1940 1933
1941 // First manual subframe navigation. 1934 // First manual subframe navigation.
1942 const GURL url2("http://foo2"); 1935 const GURL url2("http://foo2");
1943 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1936 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1944 params.page_id = 1;
1945 params.url = url2; 1937 params.url = url2;
1946 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; 1938 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
1947 params.should_update_history = false; 1939 params.should_update_history = false;
1948 params.gesture = NavigationGestureUser; 1940 params.gesture = NavigationGestureUser;
1949 params.is_post = false; 1941 params.is_post = false;
1950 params.page_state = PageState::CreateFromURL(url2); 1942 params.page_state = PageState::CreateFromURL(url2);
1951 1943
1952 // This should generate a new entry. 1944 // This should generate a new entry.
1953 LoadCommittedDetails details; 1945 LoadCommittedDetails details;
1954 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1946 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1955 &details)); 1947 &details));
1956 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1948 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1957 navigation_entry_committed_counter_ = 0; 1949 navigation_entry_committed_counter_ = 0;
1958 EXPECT_EQ(2, controller.GetEntryCount()); 1950 EXPECT_EQ(2, controller.GetEntryCount());
1959 1951
1960 // Second manual subframe navigation should also make a new entry. 1952 // Second manual subframe navigation should also make a new entry.
1961 const GURL url3("http://foo3"); 1953 const GURL url3("http://foo3");
1962 params.page_id = 2;
1963 params.url = url3; 1954 params.url = url3;
1964 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1955 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 2, params,
1965 &details)); 1956 &details));
1966 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1957 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1967 navigation_entry_committed_counter_ = 0; 1958 navigation_entry_committed_counter_ = 0;
1968 EXPECT_EQ(3, controller.GetEntryCount()); 1959 EXPECT_EQ(3, controller.GetEntryCount());
1969 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 1960 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
1970 1961
1971 // Go back one. 1962 // Go back one.
1972 controller.GoBack(); 1963 controller.GoBack();
1973 params.url = url2; 1964 params.url = url2;
1974 params.page_id = 1; 1965 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1975 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1976 &details)); 1966 &details));
1977 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1967 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1978 navigation_entry_committed_counter_ = 0; 1968 navigation_entry_committed_counter_ = 0;
1979 EXPECT_EQ(3, controller.GetEntryCount()); 1969 EXPECT_EQ(3, controller.GetEntryCount());
1980 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 1970 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
1981 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1971 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1982 EXPECT_FALSE(controller.GetPendingEntry()); 1972 EXPECT_FALSE(controller.GetPendingEntry());
1983 1973
1984 // Go back one more. 1974 // Go back one more.
1985 controller.GoBack(); 1975 controller.GoBack();
1986 params.url = url1; 1976 params.url = url1;
1987 params.page_id = 0; 1977 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1988 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1989 &details)); 1978 &details));
1990 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1979 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1991 navigation_entry_committed_counter_ = 0; 1980 navigation_entry_committed_counter_ = 0;
1992 EXPECT_EQ(3, controller.GetEntryCount()); 1981 EXPECT_EQ(3, controller.GetEntryCount());
1993 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 1982 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
1994 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1983 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1995 EXPECT_FALSE(controller.GetPendingEntry()); 1984 EXPECT_FALSE(controller.GetPendingEntry());
1996 } 1985 }
1997 1986
1998 TEST_F(NavigationControllerTest, LinkClick) { 1987 TEST_F(NavigationControllerTest, LinkClick) {
(...skipping 29 matching lines...) Expand all
2028 2017
2029 // Main page. 2018 // Main page.
2030 const GURL url1("http://foo"); 2019 const GURL url1("http://foo");
2031 main_test_rfh()->SendNavigate(0, url1); 2020 main_test_rfh()->SendNavigate(0, url1);
2032 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2021 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2033 navigation_entry_committed_counter_ = 0; 2022 navigation_entry_committed_counter_ = 0;
2034 2023
2035 // Ensure main page navigation to same url respects the was_within_same_page 2024 // Ensure main page navigation to same url respects the was_within_same_page
2036 // hint provided in the params. 2025 // hint provided in the params.
2037 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; 2026 FrameHostMsg_DidCommitProvisionalLoad_Params self_params;
2038 self_params.page_id = 0;
2039 self_params.url = url1; 2027 self_params.url = url1;
2040 self_params.transition = PAGE_TRANSITION_LINK; 2028 self_params.transition = PAGE_TRANSITION_LINK;
2041 self_params.should_update_history = false; 2029 self_params.should_update_history = false;
2042 self_params.gesture = NavigationGestureUser; 2030 self_params.gesture = NavigationGestureUser;
2043 self_params.is_post = false; 2031 self_params.is_post = false;
2044 self_params.page_state = PageState::CreateFromURL(url1); 2032 self_params.page_state = PageState::CreateFromURL(url1);
2045 self_params.was_within_same_page = true; 2033 self_params.was_within_same_page = true;
2046 2034
2047 LoadCommittedDetails details; 2035 LoadCommittedDetails details;
2048 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, 2036 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, self_params,
2049 &details)); 2037 &details));
2050 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2038 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2051 navigation_entry_committed_counter_ = 0; 2039 navigation_entry_committed_counter_ = 0;
2052 EXPECT_TRUE(details.is_in_page); 2040 EXPECT_TRUE(details.is_in_page);
2053 EXPECT_TRUE(details.did_replace_entry); 2041 EXPECT_TRUE(details.did_replace_entry);
2054 EXPECT_EQ(1, controller.GetEntryCount()); 2042 EXPECT_EQ(1, controller.GetEntryCount());
2055 2043
2056 // Fragment navigation to a new page_id. 2044 // Fragment navigation to a new page_id.
2057 const GURL url2("http://foo#a"); 2045 const GURL url2("http://foo#a");
2058 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2046 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2059 params.page_id = 1;
2060 params.url = url2; 2047 params.url = url2;
2061 params.transition = PAGE_TRANSITION_LINK; 2048 params.transition = PAGE_TRANSITION_LINK;
2062 params.should_update_history = false; 2049 params.should_update_history = false;
2063 params.gesture = NavigationGestureUser; 2050 params.gesture = NavigationGestureUser;
2064 params.is_post = false; 2051 params.is_post = false;
2065 params.page_state = PageState::CreateFromURL(url2); 2052 params.page_state = PageState::CreateFromURL(url2);
2066 params.was_within_same_page = true; 2053 params.was_within_same_page = true;
2067 2054
2068 // This should generate a new entry. 2055 // This should generate a new entry.
2069 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2056 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
2070 &details)); 2057 &details));
2071 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2058 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2072 navigation_entry_committed_counter_ = 0; 2059 navigation_entry_committed_counter_ = 0;
2073 EXPECT_TRUE(details.is_in_page); 2060 EXPECT_TRUE(details.is_in_page);
2074 EXPECT_FALSE(details.did_replace_entry); 2061 EXPECT_FALSE(details.did_replace_entry);
2075 EXPECT_EQ(2, controller.GetEntryCount()); 2062 EXPECT_EQ(2, controller.GetEntryCount());
2076 2063
2077 // Go back one. 2064 // Go back one.
2078 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); 2065 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params);
2079 controller.GoBack(); 2066 controller.GoBack();
2080 back_params.url = url1; 2067 back_params.url = url1;
2081 back_params.page_id = 0; 2068 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, back_params,
2082 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params,
2083 &details)); 2069 &details));
2084 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2070 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2085 navigation_entry_committed_counter_ = 0; 2071 navigation_entry_committed_counter_ = 0;
2086 EXPECT_TRUE(details.is_in_page); 2072 EXPECT_TRUE(details.is_in_page);
2087 EXPECT_EQ(2, controller.GetEntryCount()); 2073 EXPECT_EQ(2, controller.GetEntryCount());
2088 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2074 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2089 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); 2075 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
2090 2076
2091 // Go forward 2077 // Go forward
2092 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); 2078 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params);
2093 controller.GoForward(); 2079 controller.GoForward();
2094 forward_params.url = url2; 2080 forward_params.url = url2;
2095 forward_params.page_id = 1; 2081 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, forward_params,
2096 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params,
2097 &details)); 2082 &details));
2098 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2083 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2099 navigation_entry_committed_counter_ = 0; 2084 navigation_entry_committed_counter_ = 0;
2100 EXPECT_TRUE(details.is_in_page); 2085 EXPECT_TRUE(details.is_in_page);
2101 EXPECT_EQ(2, controller.GetEntryCount()); 2086 EXPECT_EQ(2, controller.GetEntryCount());
2102 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2087 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2103 EXPECT_EQ(forward_params.url, 2088 EXPECT_EQ(forward_params.url,
2104 controller.GetVisibleEntry()->GetURL()); 2089 controller.GetVisibleEntry()->GetURL());
2105 2090
2106 // Now go back and forward again. This is to work around a bug where we would 2091 // Now go back and forward again. This is to work around a bug where we would
2107 // compare the incoming URL with the last committed entry rather than the 2092 // compare the incoming URL with the last committed entry rather than the
2108 // one identified by an existing page ID. This would result in the second URL 2093 // one identified by an existing page ID. This would result in the second URL
2109 // losing the reference fragment when you navigate away from it and then back. 2094 // losing the reference fragment when you navigate away from it and then back.
2110 controller.GoBack(); 2095 controller.GoBack();
2111 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, 2096 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, back_params,
2112 &details)); 2097 &details));
2113 controller.GoForward(); 2098 controller.GoForward();
2114 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, 2099 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, forward_params,
2115 &details)); 2100 &details));
2116 EXPECT_EQ(forward_params.url, 2101 EXPECT_EQ(forward_params.url,
2117 controller.GetVisibleEntry()->GetURL()); 2102 controller.GetVisibleEntry()->GetURL());
2118 2103
2119 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. 2104 // Finally, navigate to an unrelated URL to make sure in_page is not sticky.
2120 const GURL url3("http://bar"); 2105 const GURL url3("http://bar");
2121 params.page_id = 2;
2122 params.url = url3; 2106 params.url = url3;
2123 navigation_entry_committed_counter_ = 0; 2107 navigation_entry_committed_counter_ = 0;
2124 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2108 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 2, params,
2125 &details)); 2109 &details));
2126 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2110 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2127 navigation_entry_committed_counter_ = 0; 2111 navigation_entry_committed_counter_ = 0;
2128 EXPECT_FALSE(details.is_in_page); 2112 EXPECT_FALSE(details.is_in_page);
2129 EXPECT_EQ(3, controller.GetEntryCount()); 2113 EXPECT_EQ(3, controller.GetEntryCount());
2130 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2114 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2131 } 2115 }
2132 2116
2133 TEST_F(NavigationControllerTest, InPage_Replace) { 2117 TEST_F(NavigationControllerTest, InPage_Replace) {
2134 NavigationControllerImpl& controller = controller_impl(); 2118 NavigationControllerImpl& controller = controller_impl();
2135 TestNotificationTracker notifications; 2119 TestNotificationTracker notifications;
2136 RegisterForAllNavNotifications(&notifications, &controller); 2120 RegisterForAllNavNotifications(&notifications, &controller);
2137 2121
2138 // Main page. 2122 // Main page.
2139 const GURL url1("http://foo"); 2123 const GURL url1("http://foo");
2140 main_test_rfh()->SendNavigate(0, url1); 2124 main_test_rfh()->SendNavigate(0, url1);
2141 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2125 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2142 navigation_entry_committed_counter_ = 0; 2126 navigation_entry_committed_counter_ = 0;
2143 2127
2144 // First navigation. 2128 // First navigation.
2145 const GURL url2("http://foo#a"); 2129 const GURL url2("http://foo#a");
2146 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2130 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2147 params.page_id = 0; // Same page_id
2148 params.url = url2; 2131 params.url = url2;
2149 params.transition = PAGE_TRANSITION_LINK; 2132 params.transition = PAGE_TRANSITION_LINK;
2150 params.should_update_history = false; 2133 params.should_update_history = false;
2151 params.gesture = NavigationGestureUser; 2134 params.gesture = NavigationGestureUser;
2152 params.is_post = false; 2135 params.is_post = false;
2153 params.page_state = PageState::CreateFromURL(url2); 2136 params.page_state = PageState::CreateFromURL(url2);
2154 params.was_within_same_page = true; 2137 params.was_within_same_page = true;
2155 2138
2156 // This should NOT generate a new entry, nor prune the list. 2139 // This should NOT generate a new entry, nor prune the list.
2157 LoadCommittedDetails details; 2140 LoadCommittedDetails details;
2158 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2141 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(),
2159 &details)); 2142 0, /* same page_id */
2143 params, &details));
2160 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2144 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2161 navigation_entry_committed_counter_ = 0; 2145 navigation_entry_committed_counter_ = 0;
2162 EXPECT_TRUE(details.is_in_page); 2146 EXPECT_TRUE(details.is_in_page);
2163 EXPECT_TRUE(details.did_replace_entry); 2147 EXPECT_TRUE(details.did_replace_entry);
2164 EXPECT_EQ(1, controller.GetEntryCount()); 2148 EXPECT_EQ(1, controller.GetEntryCount());
2165 } 2149 }
2166 2150
2167 // Tests for http://crbug.com/40395 2151 // Tests for http://crbug.com/40395
2168 // Simulates this: 2152 // Simulates this:
2169 // <script> 2153 // <script>
(...skipping 18 matching lines...) Expand all
2188 const GURL url("http://foo2/"); 2172 const GURL url("http://foo2/");
2189 main_test_rfh()->SendNavigate(1, url); 2173 main_test_rfh()->SendNavigate(1, url);
2190 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2174 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2191 navigation_entry_committed_counter_ = 0; 2175 navigation_entry_committed_counter_ = 0;
2192 } 2176 }
2193 2177
2194 // Navigate within the page. 2178 // Navigate within the page.
2195 { 2179 {
2196 const GURL url("http://foo2/#a"); 2180 const GURL url("http://foo2/#a");
2197 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2181 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2198 params.page_id = 1; // Same page_id
2199 params.url = url; 2182 params.url = url;
2200 params.transition = PAGE_TRANSITION_LINK; 2183 params.transition = PAGE_TRANSITION_LINK;
2201 params.redirects.push_back(url); 2184 params.redirects.push_back(url);
2202 params.should_update_history = true; 2185 params.should_update_history = true;
2203 params.gesture = NavigationGestureUnknown; 2186 params.gesture = NavigationGestureUnknown;
2204 params.is_post = false; 2187 params.is_post = false;
2205 params.page_state = PageState::CreateFromURL(url); 2188 params.page_state = PageState::CreateFromURL(url);
2206 params.was_within_same_page = true; 2189 params.was_within_same_page = true;
2207 2190
2208 // This should NOT generate a new entry, nor prune the list. 2191 // This should NOT generate a new entry, nor prune the list.
2209 LoadCommittedDetails details; 2192 LoadCommittedDetails details;
2210 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2193 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(),
2211 &details)); 2194 1, /* same page_id */
2195 params, &details));
2212 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2196 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2213 navigation_entry_committed_counter_ = 0; 2197 navigation_entry_committed_counter_ = 0;
2214 EXPECT_TRUE(details.is_in_page); 2198 EXPECT_TRUE(details.is_in_page);
2215 EXPECT_TRUE(details.did_replace_entry); 2199 EXPECT_TRUE(details.did_replace_entry);
2216 EXPECT_EQ(2, controller.GetEntryCount()); 2200 EXPECT_EQ(2, controller.GetEntryCount());
2217 } 2201 }
2218 2202
2219 // Perform a client redirect to a new page. 2203 // Perform a client redirect to a new page.
2220 { 2204 {
2221 const GURL url("http://foo3/"); 2205 const GURL url("http://foo3/");
2222 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2206 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2223 params.page_id = 2; // New page_id
2224 params.url = url; 2207 params.url = url;
2225 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT; 2208 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT;
2226 params.redirects.push_back(GURL("http://foo2/#a")); 2209 params.redirects.push_back(GURL("http://foo2/#a"));
2227 params.redirects.push_back(url); 2210 params.redirects.push_back(url);
2228 params.should_update_history = true; 2211 params.should_update_history = true;
2229 params.gesture = NavigationGestureUnknown; 2212 params.gesture = NavigationGestureUnknown;
2230 params.is_post = false; 2213 params.is_post = false;
2231 params.page_state = PageState::CreateFromURL(url); 2214 params.page_state = PageState::CreateFromURL(url);
2232 2215
2233 // This SHOULD generate a new entry. 2216 // This SHOULD generate a new entry.
2234 LoadCommittedDetails details; 2217 LoadCommittedDetails details;
2235 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2218 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(),
2236 &details)); 2219 2, /* new page_id */
2220 params, &details));
2237 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2221 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2238 navigation_entry_committed_counter_ = 0; 2222 navigation_entry_committed_counter_ = 0;
2239 EXPECT_FALSE(details.is_in_page); 2223 EXPECT_FALSE(details.is_in_page);
2240 EXPECT_EQ(3, controller.GetEntryCount()); 2224 EXPECT_EQ(3, controller.GetEntryCount());
2241 } 2225 }
2242 2226
2243 // Verify that BACK brings us back to http://foo2/. 2227 // Verify that BACK brings us back to http://foo2/.
2244 { 2228 {
2245 const GURL url("http://foo2/"); 2229 const GURL url("http://foo2/");
2246 controller.GoBack(); 2230 controller.GoBack();
2247 main_test_rfh()->SendNavigate(1, url); 2231 main_test_rfh()->SendNavigate(1, url);
2248 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2232 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2249 navigation_entry_committed_counter_ = 0; 2233 navigation_entry_committed_counter_ = 0;
2250 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 2234 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2251 } 2235 }
2252 } 2236 }
2253 2237
2254 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) 2238 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry)
2255 { 2239 {
2256 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); 2240 ASSERT_FALSE(controller_impl().GetLastCommittedEntry());
2257 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2241 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2258 GURL url("http://foo"); 2242 GURL url("http://foo");
2259 params.page_id = 1;
2260 params.url = url; 2243 params.url = url;
2261 params.page_state = PageState::CreateFromURL(url); 2244 params.page_state = PageState::CreateFromURL(url);
2262 params.was_within_same_page = true; 2245 params.was_within_same_page = true;
2263 test_rvh()->SendNavigateWithParams(&params); 2246 test_rvh()->SendNavigateWithParams(1, &params);
2264 // We pass if we don't crash. 2247 // We pass if we don't crash.
2265 } 2248 }
2266 2249
2267 // NotificationObserver implementation used in verifying we've received the 2250 // NotificationObserver implementation used in verifying we've received the
2268 // NOTIFICATION_NAV_LIST_PRUNED method. 2251 // NOTIFICATION_NAV_LIST_PRUNED method.
2269 class PrunedListener : public NotificationObserver { 2252 class PrunedListener : public NotificationObserver {
2270 public: 2253 public:
2271 explicit PrunedListener(NavigationControllerImpl* controller) 2254 explicit PrunedListener(NavigationControllerImpl* controller)
2272 : notification_count_(0) { 2255 : notification_count_(0) {
2273 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, 2256 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 NavigationEntryImpl::FromNavigationEntry 2377 NavigationEntryImpl::FromNavigationEntry
2395 (our_controller.GetEntryAtIndex(0))->restore_type()); 2378 (our_controller.GetEntryAtIndex(0))->restore_type());
2396 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( 2379 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry(
2397 our_controller.GetEntryAtIndex(0))->site_instance()); 2380 our_controller.GetEntryAtIndex(0))->site_instance());
2398 2381
2399 // Timestamp should remain the same before the navigation finishes. 2382 // Timestamp should remain the same before the navigation finishes.
2400 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); 2383 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp());
2401 2384
2402 // Say we navigated to that entry. 2385 // Say we navigated to that entry.
2403 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2386 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2404 params.page_id = 0;
2405 params.url = url; 2387 params.url = url;
2406 params.transition = PAGE_TRANSITION_LINK; 2388 params.transition = PAGE_TRANSITION_LINK;
2407 params.should_update_history = false; 2389 params.should_update_history = false;
2408 params.gesture = NavigationGestureUser; 2390 params.gesture = NavigationGestureUser;
2409 params.is_post = false; 2391 params.is_post = false;
2410 params.page_state = PageState::CreateFromURL(url); 2392 params.page_state = PageState::CreateFromURL(url);
2411 LoadCommittedDetails details; 2393 LoadCommittedDetails details;
2412 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2394 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), 0, params,
2413 &details); 2395 &details);
2414 2396
2415 // There should be no longer any pending entry and one committed one. This 2397 // There should be no longer any pending entry and one committed one. This
2416 // means that we were able to locate the entry, assign its site instance, and 2398 // means that we were able to locate the entry, assign its site instance, and
2417 // commit it properly. 2399 // commit it properly.
2418 EXPECT_EQ(1, our_controller.GetEntryCount()); 2400 EXPECT_EQ(1, our_controller.GetEntryCount());
2419 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2401 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2420 EXPECT_FALSE(our_controller.GetPendingEntry()); 2402 EXPECT_FALSE(our_controller.GetPendingEntry());
2421 EXPECT_EQ(url, 2403 EXPECT_EQ(url,
2422 NavigationEntryImpl::FromNavigationEntry( 2404 NavigationEntryImpl::FromNavigationEntry(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 fail_load_params.error_code = net::ERR_ABORTED; 2459 fail_load_params.error_code = net::ERR_ABORTED;
2478 fail_load_params.error_description = base::string16(); 2460 fail_load_params.error_description = base::string16();
2479 fail_load_params.url = url; 2461 fail_load_params.url = url;
2480 fail_load_params.showing_repost_interstitial = false; 2462 fail_load_params.showing_repost_interstitial = false;
2481 main_test_rfh()->OnMessageReceived( 2463 main_test_rfh()->OnMessageReceived(
2482 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id 2464 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
2483 fail_load_params)); 2465 fail_load_params));
2484 2466
2485 // Now the pending restored entry commits. 2467 // Now the pending restored entry commits.
2486 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2468 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2487 params.page_id = 0;
2488 params.url = url; 2469 params.url = url;
2489 params.transition = PAGE_TRANSITION_LINK; 2470 params.transition = PAGE_TRANSITION_LINK;
2490 params.should_update_history = false; 2471 params.should_update_history = false;
2491 params.gesture = NavigationGestureUser; 2472 params.gesture = NavigationGestureUser;
2492 params.is_post = false; 2473 params.is_post = false;
2493 params.page_state = PageState::CreateFromURL(url); 2474 params.page_state = PageState::CreateFromURL(url);
2494 LoadCommittedDetails details; 2475 LoadCommittedDetails details;
2495 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2476 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), 0, params,
2496 &details); 2477 &details);
2497 2478
2498 // There should be no pending entry and one committed one. 2479 // There should be no pending entry and one committed one.
2499 EXPECT_EQ(1, our_controller.GetEntryCount()); 2480 EXPECT_EQ(1, our_controller.GetEntryCount());
2500 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2481 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2501 EXPECT_FALSE(our_controller.GetPendingEntry()); 2482 EXPECT_FALSE(our_controller.GetPendingEntry());
2502 EXPECT_EQ(url, 2483 EXPECT_EQ(url,
2503 NavigationEntryImpl::FromNavigationEntry( 2484 NavigationEntryImpl::FromNavigationEntry(
2504 our_controller.GetLastCommittedEntry())->site_instance()-> 2485 our_controller.GetLastCommittedEntry())->site_instance()->
2505 GetSiteURL()); 2486 GetSiteURL());
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
3139 const GURL url("http://www.google.com/"); 3120 const GURL url("http://www.google.com/");
3140 main_test_rfh()->SendNavigate(0, url); 3121 main_test_rfh()->SendNavigate(0, url);
3141 3122
3142 // We should be at the first navigation entry. 3123 // We should be at the first navigation entry.
3143 EXPECT_EQ(controller.GetEntryCount(), 1); 3124 EXPECT_EQ(controller.GetEntryCount(), 1);
3144 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3125 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3145 3126
3146 // Navigate a subframe that would normally count as in-page. 3127 // Navigate a subframe that would normally count as in-page.
3147 const GURL subframe("http://www.google.com/#"); 3128 const GURL subframe("http://www.google.com/#");
3148 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3129 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3149 params.page_id = 0;
3150 params.url = subframe; 3130 params.url = subframe;
3151 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 3131 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
3152 params.should_update_history = false; 3132 params.should_update_history = false;
3153 params.gesture = NavigationGestureAuto; 3133 params.gesture = NavigationGestureAuto;
3154 params.is_post = false; 3134 params.is_post = false;
3155 params.page_state = PageState::CreateFromURL(subframe); 3135 params.page_state = PageState::CreateFromURL(subframe);
3156 LoadCommittedDetails details; 3136 LoadCommittedDetails details;
3157 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3137 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
3158 &details)); 3138 &details));
3159 3139
3160 // Nothing should have changed. 3140 // Nothing should have changed.
3161 EXPECT_EQ(controller.GetEntryCount(), 1); 3141 EXPECT_EQ(controller.GetEntryCount(), 1);
3162 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3142 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3163 } 3143 }
3164 3144
3165 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 3145 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
3166 // false. 3146 // false.
3167 TEST_F(NavigationControllerTest, CloneAndGoBack) { 3147 TEST_F(NavigationControllerTest, CloneAndGoBack) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 3235
3256 // Now start a pending load to a totally different page, but don't commit it. 3236 // Now start a pending load to a totally different page, but don't commit it.
3257 const GURL url2("http://bar/"); 3237 const GURL url2("http://bar/");
3258 controller.LoadURL( 3238 controller.LoadURL(
3259 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 3239 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
3260 3240
3261 // Send a subframe update from the first page, as if one had just 3241 // Send a subframe update from the first page, as if one had just
3262 // automatically loaded. Auto subframes don't increment the page ID. 3242 // automatically loaded. Auto subframes don't increment the page ID.
3263 const GURL url1_sub("http://foo/subframe"); 3243 const GURL url1_sub("http://foo/subframe");
3264 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3244 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3265 params.page_id = controller.GetLastCommittedEntry()->GetPageID();
3266 params.url = url1_sub; 3245 params.url = url1_sub;
3267 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 3246 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
3268 params.should_update_history = false; 3247 params.should_update_history = false;
3269 params.gesture = NavigationGestureAuto; 3248 params.gesture = NavigationGestureAuto;
3270 params.is_post = false; 3249 params.is_post = false;
3271 params.page_state = PageState::CreateFromURL(url1_sub); 3250 params.page_state = PageState::CreateFromURL(url1_sub);
3272 LoadCommittedDetails details; 3251 LoadCommittedDetails details;
3273 3252
3274 // This should return false meaning that nothing was actually updated. 3253 // This should return false meaning that nothing was actually updated.
3275 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3254 EXPECT_FALSE(controller.RendererDidNavigate(
3276 &details)); 3255 main_test_rfh(), controller.GetLastCommittedEntry()->GetPageID(), params,
3256 &details));
3277 3257
3278 // The notification should have updated the last committed one, and not 3258 // The notification should have updated the last committed one, and not
3279 // the pending load. 3259 // the pending load.
3280 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); 3260 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL());
3281 3261
3282 // The active entry should be unchanged by the subframe load. 3262 // The active entry should be unchanged by the subframe load.
3283 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3263 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3284 } 3264 }
3285 3265
3286 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. 3266 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target.
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
4233 base::string16 title(base::ASCIIToUTF16("Title")); 4213 base::string16 title(base::ASCIIToUTF16("Title"));
4234 FaviconStatus favicon; 4214 FaviconStatus favicon;
4235 favicon.valid = true; 4215 favicon.valid = true;
4236 favicon.url = GURL("http://foo/favicon.ico"); 4216 favicon.url = GURL("http://foo/favicon.ico");
4237 controller().GetLastCommittedEntry()->SetTitle(title); 4217 controller().GetLastCommittedEntry()->SetTitle(title);
4238 controller().GetLastCommittedEntry()->GetFavicon() = favicon; 4218 controller().GetLastCommittedEntry()->GetFavicon() = favicon;
4239 4219
4240 // history.pushState() is called. 4220 // history.pushState() is called.
4241 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4221 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4242 GURL url("http://foo#foo"); 4222 GURL url("http://foo#foo");
4243 params.page_id = 2;
4244 params.url = url; 4223 params.url = url;
4245 params.page_state = PageState::CreateFromURL(url); 4224 params.page_state = PageState::CreateFromURL(url);
4246 params.was_within_same_page = true; 4225 params.was_within_same_page = true;
4247 test_rvh()->SendNavigateWithParams(&params); 4226 test_rvh()->SendNavigateWithParams(2, &params);
4248 4227
4249 // The title should immediately be visible on the new NavigationEntry. 4228 // The title should immediately be visible on the new NavigationEntry.
4250 base::string16 new_title = 4229 base::string16 new_title =
4251 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); 4230 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string());
4252 EXPECT_EQ(title, new_title); 4231 EXPECT_EQ(title, new_title);
4253 FaviconStatus new_favicon = 4232 FaviconStatus new_favicon =
4254 controller().GetLastCommittedEntry()->GetFavicon(); 4233 controller().GetLastCommittedEntry()->GetFavicon();
4255 EXPECT_EQ(favicon.valid, new_favicon.valid); 4234 EXPECT_EQ(favicon.valid, new_favicon.valid);
4256 EXPECT_EQ(favicon.url, new_favicon.url); 4235 EXPECT_EQ(favicon.url, new_favicon.url);
4257 } 4236 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4306 } 4285 }
4307 4286
4308 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { 4287 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) {
4309 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 4288 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
4310 EXPECT_FALSE(contents()->GetDelegate()); 4289 EXPECT_FALSE(contents()->GetDelegate());
4311 contents()->SetDelegate(delegate.get()); 4290 contents()->SetDelegate(delegate.get());
4312 4291
4313 // Submit a form. 4292 // Submit a form.
4314 GURL url("http://foo"); 4293 GURL url("http://foo");
4315 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4294 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4316 params.page_id = 1;
4317 params.url = url; 4295 params.url = url;
4318 params.transition = PAGE_TRANSITION_FORM_SUBMIT; 4296 params.transition = PAGE_TRANSITION_FORM_SUBMIT;
4319 params.gesture = NavigationGestureUser; 4297 params.gesture = NavigationGestureUser;
4320 params.page_state = PageState::CreateFromURL(url); 4298 params.page_state = PageState::CreateFromURL(url);
4321 params.was_within_same_page = false; 4299 params.was_within_same_page = false;
4322 params.is_post = true; 4300 params.is_post = true;
4323 params.post_id = 2; 4301 params.post_id = 2;
4324 test_rvh()->SendNavigateWithParams(&params); 4302 test_rvh()->SendNavigateWithParams(1, &params);
4325 4303
4326 // history.replaceState() is called. 4304 // history.replaceState() is called.
4327 GURL replace_url("http://foo#foo"); 4305 GURL replace_url("http://foo#foo");
4328 params.page_id = 1;
4329 params.url = replace_url; 4306 params.url = replace_url;
4330 params.transition = PAGE_TRANSITION_LINK; 4307 params.transition = PAGE_TRANSITION_LINK;
4331 params.gesture = NavigationGestureUser; 4308 params.gesture = NavigationGestureUser;
4332 params.page_state = PageState::CreateFromURL(replace_url); 4309 params.page_state = PageState::CreateFromURL(replace_url);
4333 params.was_within_same_page = true; 4310 params.was_within_same_page = true;
4334 params.is_post = false; 4311 params.is_post = false;
4335 params.post_id = -1; 4312 params.post_id = -1;
4336 test_rvh()->SendNavigateWithParams(&params); 4313 test_rvh()->SendNavigateWithParams(1, &params);
4337 4314
4338 // Now reload. replaceState overrides the POST, so we should not show a 4315 // Now reload. replaceState overrides the POST, so we should not show a
4339 // repost warning dialog. 4316 // repost warning dialog.
4340 controller_impl().Reload(true); 4317 controller_impl().Reload(true);
4341 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4318 EXPECT_EQ(0, delegate->repost_form_warning_count());
4342 } 4319 }
4343 4320
4344 } // namespace content 4321 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698