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

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: fixes Created 6 years, 1 month 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) { 629 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) {
630 NavigationControllerImpl& controller = controller_impl(); 630 NavigationControllerImpl& controller = controller_impl();
631 TestNotificationTracker notifications; 631 TestNotificationTracker notifications;
632 RegisterForAllNavNotifications(&notifications, &controller); 632 RegisterForAllNavNotifications(&notifications, &controller);
633 633
634 const GURL url1("http://foo1"); 634 const GURL url1("http://foo1");
635 635
636 controller.LoadURL( 636 controller.LoadURL(
637 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 637 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
638 FrameHostMsg_DidCommitProvisionalLoad_Params params; 638 FrameHostMsg_DidCommitProvisionalLoad_Params params;
639 params.page_id = 0;
640 params.url = url1; 639 params.url = url1;
641 params.transition = ui::PAGE_TRANSITION_TYPED; 640 params.transition = ui::PAGE_TRANSITION_TYPED;
642 params.is_post = true; 641 params.is_post = true;
643 params.post_id = 123; 642 params.post_id = 123;
644 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); 643 params.page_state = PageState::CreateForTesting(url1, false, 0, 0);
645 main_test_rfh()->SendNavigateWithParams(&params); 644 main_test_rfh()->SendNavigateWithParams(0, &params);
646 645
647 // The post data should be visible. 646 // The post data should be visible.
648 NavigationEntry* entry = controller.GetVisibleEntry(); 647 NavigationEntry* entry = controller.GetVisibleEntry();
649 ASSERT_TRUE(entry); 648 ASSERT_TRUE(entry);
650 EXPECT_TRUE(entry->GetHasPostData()); 649 EXPECT_TRUE(entry->GetHasPostData());
651 EXPECT_EQ(entry->GetPostID(), 123); 650 EXPECT_EQ(entry->GetPostID(), 123);
652 651
653 controller.LoadURL( 652 controller.LoadURL(
654 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 653 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
655 main_test_rfh()->SendNavigate(0, url1); 654 main_test_rfh()->SendNavigate(0, url1);
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 1697
1699 // Second request 1698 // Second request
1700 controller.LoadURL( 1699 controller.LoadURL(
1701 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1700 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1702 1701
1703 EXPECT_TRUE(controller.GetPendingEntry()); 1702 EXPECT_TRUE(controller.GetPendingEntry());
1704 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1703 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1705 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1704 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1706 1705
1707 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1706 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1708 params.page_id = 0;
1709 params.url = url2; 1707 params.url = url2;
1710 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1708 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1711 params.redirects.push_back(GURL("http://foo1")); 1709 params.redirects.push_back(GURL("http://foo1"));
1712 params.redirects.push_back(GURL("http://foo2")); 1710 params.redirects.push_back(GURL("http://foo2"));
1713 params.should_update_history = false; 1711 params.should_update_history = false;
1714 params.gesture = NavigationGestureAuto; 1712 params.gesture = NavigationGestureAuto;
1715 params.is_post = false; 1713 params.is_post = false;
1716 params.page_state = PageState::CreateFromURL(url2); 1714 params.page_state = PageState::CreateFromURL(url2);
1717 1715
1718 LoadCommittedDetails details; 1716 LoadCommittedDetails details;
1719 1717
1720 EXPECT_EQ(0U, notifications.size()); 1718 EXPECT_EQ(0U, notifications.size());
1721 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1719 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1722 &details)); 1720 &details));
1723 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1721 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1724 navigation_entry_committed_counter_ = 0; 1722 navigation_entry_committed_counter_ = 0;
1725 1723
1726 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1724 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1727 EXPECT_EQ(controller.GetEntryCount(), 1); 1725 EXPECT_EQ(controller.GetEntryCount(), 1);
1728 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1726 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1729 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1727 EXPECT_TRUE(controller.GetLastCommittedEntry());
1730 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1728 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1731 EXPECT_FALSE(controller.GetPendingEntry()); 1729 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 26 matching lines...) Expand all
1758 1756
1759 // Second request 1757 // Second request
1760 controller.LoadURL( 1758 controller.LoadURL(
1761 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1759 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1762 1760
1763 EXPECT_TRUE(controller.GetPendingEntry()); 1761 EXPECT_TRUE(controller.GetPendingEntry());
1764 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1762 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1765 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1763 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1766 1764
1767 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1765 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1768 params.page_id = 0;
1769 params.url = url2; 1766 params.url = url2;
1770 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1767 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1771 params.redirects.push_back(GURL("http://foo1")); 1768 params.redirects.push_back(GURL("http://foo1"));
1772 params.redirects.push_back(GURL("http://foo2")); 1769 params.redirects.push_back(GURL("http://foo2"));
1773 params.should_update_history = false; 1770 params.should_update_history = false;
1774 params.gesture = NavigationGestureAuto; 1771 params.gesture = NavigationGestureAuto;
1775 params.is_post = false; 1772 params.is_post = false;
1776 params.page_state = PageState::CreateFromURL(url2); 1773 params.page_state = PageState::CreateFromURL(url2);
1777 1774
1778 LoadCommittedDetails details; 1775 LoadCommittedDetails details;
1779 1776
1780 EXPECT_EQ(0U, notifications.size()); 1777 EXPECT_EQ(0U, notifications.size());
1781 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1778 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1782 &details)); 1779 &details));
1783 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1780 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1784 navigation_entry_committed_counter_ = 0; 1781 navigation_entry_committed_counter_ = 0;
1785 1782
1786 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1783 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1787 EXPECT_EQ(controller.GetEntryCount(), 1); 1784 EXPECT_EQ(controller.GetEntryCount(), 1);
1788 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1785 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1789 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1786 EXPECT_TRUE(controller.GetLastCommittedEntry());
1790 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1787 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1791 EXPECT_FALSE(controller.GetPendingEntry()); 1788 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 15 matching lines...) Expand all
1807 1804
1808 // First request 1805 // First request
1809 controller.LoadURL( 1806 controller.LoadURL(
1810 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1807 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1811 1808
1812 EXPECT_TRUE(controller.GetPendingEntry()); 1809 EXPECT_TRUE(controller.GetPendingEntry());
1813 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1810 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1814 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1811 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1815 1812
1816 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1813 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1817 params.page_id = 0;
1818 params.url = url2; 1814 params.url = url2;
1819 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1815 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1820 params.redirects.push_back(GURL("http://foo1")); 1816 params.redirects.push_back(GURL("http://foo1"));
1821 params.redirects.push_back(GURL("http://foo2")); 1817 params.redirects.push_back(GURL("http://foo2"));
1822 params.should_update_history = false; 1818 params.should_update_history = false;
1823 params.gesture = NavigationGestureAuto; 1819 params.gesture = NavigationGestureAuto;
1824 params.is_post = false; 1820 params.is_post = false;
1825 params.page_state = PageState::CreateFromURL(url2); 1821 params.page_state = PageState::CreateFromURL(url2);
1826 1822
1827 LoadCommittedDetails details; 1823 LoadCommittedDetails details;
1828 1824
1829 EXPECT_EQ(0U, notifications.size()); 1825 EXPECT_EQ(0U, notifications.size());
1830 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1826 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1831 &details)); 1827 &details));
1832 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1828 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1833 navigation_entry_committed_counter_ = 0; 1829 navigation_entry_committed_counter_ = 0;
1834 1830
1835 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); 1831 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE);
1836 EXPECT_EQ(controller.GetEntryCount(), 1); 1832 EXPECT_EQ(controller.GetEntryCount(), 1);
1837 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1833 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1838 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1834 EXPECT_TRUE(controller.GetLastCommittedEntry());
1839 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1835 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1840 EXPECT_FALSE(controller.GetPendingEntry()); 1836 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 10 matching lines...) Expand all
1851 TestNotificationTracker notifications; 1847 TestNotificationTracker notifications;
1852 RegisterForAllNavNotifications(&notifications, &controller); 1848 RegisterForAllNavNotifications(&notifications, &controller);
1853 1849
1854 const GURL url1("http://foo1"); 1850 const GURL url1("http://foo1");
1855 main_test_rfh()->SendNavigate(0, url1); 1851 main_test_rfh()->SendNavigate(0, url1);
1856 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1852 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1857 navigation_entry_committed_counter_ = 0; 1853 navigation_entry_committed_counter_ = 0;
1858 1854
1859 const GURL url2("http://foo2"); 1855 const GURL url2("http://foo2");
1860 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1856 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1861 params.page_id = 1;
1862 params.url = url2; 1857 params.url = url2;
1863 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 1858 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
1864 params.should_update_history = false; 1859 params.should_update_history = false;
1865 params.gesture = NavigationGestureUser; 1860 params.gesture = NavigationGestureUser;
1866 params.is_post = false; 1861 params.is_post = false;
1867 params.page_state = PageState::CreateFromURL(url2); 1862 params.page_state = PageState::CreateFromURL(url2);
1868 1863
1869 LoadCommittedDetails details; 1864 LoadCommittedDetails details;
1870 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1865 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1871 &details)); 1866 &details));
1872 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1867 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1873 navigation_entry_committed_counter_ = 0; 1868 navigation_entry_committed_counter_ = 0;
1874 EXPECT_EQ(url1, details.previous_url); 1869 EXPECT_EQ(url1, details.previous_url);
1875 EXPECT_FALSE(details.is_in_page); 1870 EXPECT_FALSE(details.is_in_page);
1876 EXPECT_FALSE(details.is_main_frame); 1871 EXPECT_FALSE(details.is_main_frame);
1877 1872
1878 // The new entry should be appended. 1873 // The new entry should be appended.
1879 EXPECT_EQ(2, controller.GetEntryCount()); 1874 EXPECT_EQ(2, controller.GetEntryCount());
1880 1875
1881 // New entry should refer to the new page, but the old URL (entries only 1876 // New entry should refer to the new page, but the old URL (entries only
1882 // reflect the toplevel URL). 1877 // reflect the toplevel URL).
1883 EXPECT_EQ(url1, details.entry->GetURL()); 1878 EXPECT_EQ(url1, details.entry->GetURL());
1884 EXPECT_EQ(params.page_id, details.entry->GetPageID()); 1879 EXPECT_EQ(1, details.entry->GetPageID());
1885 } 1880 }
1886 1881
1887 // Some pages create a popup, then write an iframe into it. This causes a 1882 // Some pages create a popup, then write an iframe into it. This causes a
1888 // subframe navigation without having any committed entry. Such navigations 1883 // subframe navigation without having any committed entry. Such navigations
1889 // just get thrown on the ground, but we shouldn't crash. 1884 // just get thrown on the ground, but we shouldn't crash.
1890 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { 1885 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) {
1891 NavigationControllerImpl& controller = controller_impl(); 1886 NavigationControllerImpl& controller = controller_impl();
1892 TestNotificationTracker notifications; 1887 TestNotificationTracker notifications;
1893 RegisterForAllNavNotifications(&notifications, &controller); 1888 RegisterForAllNavNotifications(&notifications, &controller);
1894 1889
1895 // Navigation controller currently has no entries. 1890 // Navigation controller currently has no entries.
1896 const GURL url("http://foo2"); 1891 const GURL url("http://foo2");
1897 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1892 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1898 params.page_id = 1;
1899 params.url = url; 1893 params.url = url;
1900 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 1894 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
1901 params.should_update_history = false; 1895 params.should_update_history = false;
1902 params.gesture = NavigationGestureAuto; 1896 params.gesture = NavigationGestureAuto;
1903 params.is_post = false; 1897 params.is_post = false;
1904 params.page_state = PageState::CreateFromURL(url); 1898 params.page_state = PageState::CreateFromURL(url);
1905 1899
1906 LoadCommittedDetails details; 1900 LoadCommittedDetails details;
1907 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 1901 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1908 &details)); 1902 &details));
1909 EXPECT_EQ(0U, notifications.size()); 1903 EXPECT_EQ(0U, notifications.size());
1910 } 1904 }
1911 1905
1912 // Auto subframes are ones the page loads automatically like ads. They should 1906 // Auto subframes are ones the page loads automatically like ads. They should
1913 // not create new navigation entries. 1907 // not create new navigation entries.
1914 TEST_F(NavigationControllerTest, AutoSubframe) { 1908 TEST_F(NavigationControllerTest, AutoSubframe) {
1915 NavigationControllerImpl& controller = controller_impl(); 1909 NavigationControllerImpl& controller = controller_impl();
1916 TestNotificationTracker notifications; 1910 TestNotificationTracker notifications;
1917 RegisterForAllNavNotifications(&notifications, &controller); 1911 RegisterForAllNavNotifications(&notifications, &controller);
1918 1912
1919 const GURL url1("http://foo1"); 1913 const GURL url1("http://foo1");
1920 main_test_rfh()->SendNavigate(0, url1); 1914 main_test_rfh()->SendNavigate(0, url1);
1921 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1915 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1922 navigation_entry_committed_counter_ = 0; 1916 navigation_entry_committed_counter_ = 0;
1923 1917
1924 const GURL url2("http://foo2"); 1918 const GURL url2("http://foo2");
1925 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1919 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1926 params.page_id = 0;
1927 params.url = url2; 1920 params.url = url2;
1928 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 1921 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
1929 params.should_update_history = false; 1922 params.should_update_history = false;
1930 params.gesture = NavigationGestureUser; 1923 params.gesture = NavigationGestureUser;
1931 params.is_post = false; 1924 params.is_post = false;
1932 params.page_state = PageState::CreateFromURL(url2); 1925 params.page_state = PageState::CreateFromURL(url2);
1933 1926
1934 // Navigating should do nothing. 1927 // Navigating should do nothing.
1935 LoadCommittedDetails details; 1928 LoadCommittedDetails details;
1936 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 1929 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
1937 &details)); 1930 &details));
1938 EXPECT_EQ(0U, notifications.size()); 1931 EXPECT_EQ(0U, notifications.size());
1939 1932
1940 // There should still be only one entry. 1933 // There should still be only one entry.
1941 EXPECT_EQ(1, controller.GetEntryCount()); 1934 EXPECT_EQ(1, controller.GetEntryCount());
1942 } 1935 }
1943 1936
1944 // Tests navigation and then going back to a subframe navigation. 1937 // Tests navigation and then going back to a subframe navigation.
1945 TEST_F(NavigationControllerTest, BackSubframe) { 1938 TEST_F(NavigationControllerTest, BackSubframe) {
1946 NavigationControllerImpl& controller = controller_impl(); 1939 NavigationControllerImpl& controller = controller_impl();
1947 TestNotificationTracker notifications; 1940 TestNotificationTracker notifications;
1948 RegisterForAllNavNotifications(&notifications, &controller); 1941 RegisterForAllNavNotifications(&notifications, &controller);
1949 1942
1950 // Main page. 1943 // Main page.
1951 const GURL url1("http://foo1"); 1944 const GURL url1("http://foo1");
1952 main_test_rfh()->SendNavigate(0, url1); 1945 main_test_rfh()->SendNavigate(0, url1);
1953 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1946 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1954 navigation_entry_committed_counter_ = 0; 1947 navigation_entry_committed_counter_ = 0;
1955 1948
1956 // First manual subframe navigation. 1949 // First manual subframe navigation.
1957 const GURL url2("http://foo2"); 1950 const GURL url2("http://foo2");
1958 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1951 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1959 params.page_id = 1;
1960 params.url = url2; 1952 params.url = url2;
1961 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 1953 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
1962 params.should_update_history = false; 1954 params.should_update_history = false;
1963 params.gesture = NavigationGestureUser; 1955 params.gesture = NavigationGestureUser;
1964 params.is_post = false; 1956 params.is_post = false;
1965 params.page_state = PageState::CreateFromURL(url2); 1957 params.page_state = PageState::CreateFromURL(url2);
1966 1958
1967 // This should generate a new entry. 1959 // This should generate a new entry.
1968 LoadCommittedDetails details; 1960 LoadCommittedDetails details;
1969 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1961 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1970 &details)); 1962 &details));
1971 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1963 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1972 navigation_entry_committed_counter_ = 0; 1964 navigation_entry_committed_counter_ = 0;
1973 EXPECT_EQ(2, controller.GetEntryCount()); 1965 EXPECT_EQ(2, controller.GetEntryCount());
1974 1966
1975 // Second manual subframe navigation should also make a new entry. 1967 // Second manual subframe navigation should also make a new entry.
1976 const GURL url3("http://foo3"); 1968 const GURL url3("http://foo3");
1977 params.page_id = 2;
1978 params.url = url3; 1969 params.url = url3;
1979 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1970 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 2, params,
1980 &details)); 1971 &details));
1981 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1972 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1982 navigation_entry_committed_counter_ = 0; 1973 navigation_entry_committed_counter_ = 0;
1983 EXPECT_EQ(3, controller.GetEntryCount()); 1974 EXPECT_EQ(3, controller.GetEntryCount());
1984 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 1975 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
1985 1976
1986 // Go back one. 1977 // Go back one.
1987 controller.GoBack(); 1978 controller.GoBack();
1988 params.url = url2; 1979 params.url = url2;
1989 params.page_id = 1; 1980 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
1990 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1991 &details)); 1981 &details));
1992 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1982 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1993 navigation_entry_committed_counter_ = 0; 1983 navigation_entry_committed_counter_ = 0;
1994 EXPECT_EQ(3, controller.GetEntryCount()); 1984 EXPECT_EQ(3, controller.GetEntryCount());
1995 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 1985 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
1996 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1986 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1997 EXPECT_FALSE(controller.GetPendingEntry()); 1987 EXPECT_FALSE(controller.GetPendingEntry());
1998 1988
1999 // Go back one more. 1989 // Go back one more.
2000 controller.GoBack(); 1990 controller.GoBack();
2001 params.url = url1; 1991 params.url = url1;
2002 params.page_id = 0; 1992 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
2003 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2004 &details)); 1993 &details));
2005 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1994 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2006 navigation_entry_committed_counter_ = 0; 1995 navigation_entry_committed_counter_ = 0;
2007 EXPECT_EQ(3, controller.GetEntryCount()); 1996 EXPECT_EQ(3, controller.GetEntryCount());
2008 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 1997 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2009 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1998 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2010 EXPECT_FALSE(controller.GetPendingEntry()); 1999 EXPECT_FALSE(controller.GetPendingEntry());
2011 } 2000 }
2012 2001
2013 TEST_F(NavigationControllerTest, LinkClick) { 2002 TEST_F(NavigationControllerTest, LinkClick) {
(...skipping 29 matching lines...) Expand all
2043 2032
2044 // Main page. 2033 // Main page.
2045 const GURL url1("http://foo"); 2034 const GURL url1("http://foo");
2046 main_test_rfh()->SendNavigate(0, url1); 2035 main_test_rfh()->SendNavigate(0, url1);
2047 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2036 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2048 navigation_entry_committed_counter_ = 0; 2037 navigation_entry_committed_counter_ = 0;
2049 2038
2050 // Ensure main page navigation to same url respects the was_within_same_page 2039 // Ensure main page navigation to same url respects the was_within_same_page
2051 // hint provided in the params. 2040 // hint provided in the params.
2052 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; 2041 FrameHostMsg_DidCommitProvisionalLoad_Params self_params;
2053 self_params.page_id = 0;
2054 self_params.url = url1; 2042 self_params.url = url1;
2055 self_params.transition = ui::PAGE_TRANSITION_LINK; 2043 self_params.transition = ui::PAGE_TRANSITION_LINK;
2056 self_params.should_update_history = false; 2044 self_params.should_update_history = false;
2057 self_params.gesture = NavigationGestureUser; 2045 self_params.gesture = NavigationGestureUser;
2058 self_params.is_post = false; 2046 self_params.is_post = false;
2059 self_params.page_state = PageState::CreateFromURL(url1); 2047 self_params.page_state = PageState::CreateFromURL(url1);
2060 self_params.was_within_same_page = true; 2048 self_params.was_within_same_page = true;
2061 2049
2062 LoadCommittedDetails details; 2050 LoadCommittedDetails details;
2063 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, 2051 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, self_params,
2064 &details)); 2052 &details));
2065 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2053 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2066 navigation_entry_committed_counter_ = 0; 2054 navigation_entry_committed_counter_ = 0;
2067 EXPECT_TRUE(details.is_in_page); 2055 EXPECT_TRUE(details.is_in_page);
2068 EXPECT_TRUE(details.did_replace_entry); 2056 EXPECT_TRUE(details.did_replace_entry);
2069 EXPECT_EQ(1, controller.GetEntryCount()); 2057 EXPECT_EQ(1, controller.GetEntryCount());
2070 2058
2071 // Fragment navigation to a new page_id. 2059 // Fragment navigation to a new page_id.
2072 const GURL url2("http://foo#a"); 2060 const GURL url2("http://foo#a");
2073 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2061 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2074 params.page_id = 1;
2075 params.url = url2; 2062 params.url = url2;
2076 params.transition = ui::PAGE_TRANSITION_LINK; 2063 params.transition = ui::PAGE_TRANSITION_LINK;
2077 params.should_update_history = false; 2064 params.should_update_history = false;
2078 params.gesture = NavigationGestureUser; 2065 params.gesture = NavigationGestureUser;
2079 params.is_post = false; 2066 params.is_post = false;
2080 params.page_state = PageState::CreateFromURL(url2); 2067 params.page_state = PageState::CreateFromURL(url2);
2081 params.was_within_same_page = true; 2068 params.was_within_same_page = true;
2082 2069
2083 // This should generate a new entry. 2070 // This should generate a new entry.
2084 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2071 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, params,
2085 &details)); 2072 &details));
2086 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2073 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2087 navigation_entry_committed_counter_ = 0; 2074 navigation_entry_committed_counter_ = 0;
2088 EXPECT_TRUE(details.is_in_page); 2075 EXPECT_TRUE(details.is_in_page);
2089 EXPECT_FALSE(details.did_replace_entry); 2076 EXPECT_FALSE(details.did_replace_entry);
2090 EXPECT_EQ(2, controller.GetEntryCount()); 2077 EXPECT_EQ(2, controller.GetEntryCount());
2091 2078
2092 // Go back one. 2079 // Go back one.
2093 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); 2080 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params);
2094 controller.GoBack(); 2081 controller.GoBack();
2095 back_params.url = url1; 2082 back_params.url = url1;
2096 back_params.page_id = 0; 2083 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, back_params,
2097 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params,
2098 &details)); 2084 &details));
2099 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2085 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2100 navigation_entry_committed_counter_ = 0; 2086 navigation_entry_committed_counter_ = 0;
2101 EXPECT_TRUE(details.is_in_page); 2087 EXPECT_TRUE(details.is_in_page);
2102 EXPECT_EQ(2, controller.GetEntryCount()); 2088 EXPECT_EQ(2, controller.GetEntryCount());
2103 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2089 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2104 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); 2090 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
2105 2091
2106 // Go forward 2092 // Go forward
2107 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); 2093 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params);
2108 controller.GoForward(); 2094 controller.GoForward();
2109 forward_params.url = url2; 2095 forward_params.url = url2;
2110 forward_params.page_id = 1; 2096 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, forward_params,
2111 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params,
2112 &details)); 2097 &details));
2113 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2098 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2114 navigation_entry_committed_counter_ = 0; 2099 navigation_entry_committed_counter_ = 0;
2115 EXPECT_TRUE(details.is_in_page); 2100 EXPECT_TRUE(details.is_in_page);
2116 EXPECT_EQ(2, controller.GetEntryCount()); 2101 EXPECT_EQ(2, controller.GetEntryCount());
2117 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2102 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2118 EXPECT_EQ(forward_params.url, 2103 EXPECT_EQ(forward_params.url,
2119 controller.GetVisibleEntry()->GetURL()); 2104 controller.GetVisibleEntry()->GetURL());
2120 2105
2121 // Now go back and forward again. This is to work around a bug where we would 2106 // Now go back and forward again. This is to work around a bug where we would
2122 // compare the incoming URL with the last committed entry rather than the 2107 // compare the incoming URL with the last committed entry rather than the
2123 // one identified by an existing page ID. This would result in the second URL 2108 // one identified by an existing page ID. This would result in the second URL
2124 // losing the reference fragment when you navigate away from it and then back. 2109 // losing the reference fragment when you navigate away from it and then back.
2125 controller.GoBack(); 2110 controller.GoBack();
2126 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, 2111 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 0, back_params,
2127 &details)); 2112 &details));
2128 controller.GoForward(); 2113 controller.GoForward();
2129 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, 2114 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 1, forward_params,
2130 &details)); 2115 &details));
2131 EXPECT_EQ(forward_params.url, 2116 EXPECT_EQ(forward_params.url,
2132 controller.GetVisibleEntry()->GetURL()); 2117 controller.GetVisibleEntry()->GetURL());
2133 2118
2134 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. 2119 // Finally, navigate to an unrelated URL to make sure in_page is not sticky.
2135 const GURL url3("http://bar"); 2120 const GURL url3("http://bar");
2136 params.page_id = 2;
2137 params.url = url3; 2121 params.url = url3;
2138 navigation_entry_committed_counter_ = 0; 2122 navigation_entry_committed_counter_ = 0;
2139 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2123 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), 2, params,
2140 &details)); 2124 &details));
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 EXPECT_FALSE(details.is_in_page); 2127 EXPECT_FALSE(details.is_in_page);
2144 EXPECT_EQ(3, controller.GetEntryCount()); 2128 EXPECT_EQ(3, controller.GetEntryCount());
2145 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2129 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2146 } 2130 }
2147 2131
2148 TEST_F(NavigationControllerTest, InPage_Replace) { 2132 TEST_F(NavigationControllerTest, InPage_Replace) {
2149 NavigationControllerImpl& controller = controller_impl(); 2133 NavigationControllerImpl& controller = controller_impl();
2150 TestNotificationTracker notifications; 2134 TestNotificationTracker notifications;
2151 RegisterForAllNavNotifications(&notifications, &controller); 2135 RegisterForAllNavNotifications(&notifications, &controller);
2152 2136
2153 // Main page. 2137 // Main page.
2154 const GURL url1("http://foo"); 2138 const GURL url1("http://foo");
2155 main_test_rfh()->SendNavigate(0, url1); 2139 main_test_rfh()->SendNavigate(0, url1);
2156 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2140 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2157 navigation_entry_committed_counter_ = 0; 2141 navigation_entry_committed_counter_ = 0;
2158 2142
2159 // First navigation. 2143 // First navigation.
2160 const GURL url2("http://foo#a"); 2144 const GURL url2("http://foo#a");
2161 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2145 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2162 params.page_id = 0; // Same page_id
2163 params.url = url2; 2146 params.url = url2;
2164 params.transition = ui::PAGE_TRANSITION_LINK; 2147 params.transition = ui::PAGE_TRANSITION_LINK;
2165 params.should_update_history = false; 2148 params.should_update_history = false;
2166 params.gesture = NavigationGestureUser; 2149 params.gesture = NavigationGestureUser;
2167 params.is_post = false; 2150 params.is_post = false;
2168 params.page_state = PageState::CreateFromURL(url2); 2151 params.page_state = PageState::CreateFromURL(url2);
2169 params.was_within_same_page = true; 2152 params.was_within_same_page = true;
2170 2153
2171 // This should NOT generate a new entry, nor prune the list. 2154 // This should NOT generate a new entry, nor prune the list.
2172 LoadCommittedDetails details; 2155 LoadCommittedDetails details;
2173 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2156 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(),
2174 &details)); 2157 0, /* same page_id */
2158 params, &details));
2175 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2159 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2176 navigation_entry_committed_counter_ = 0; 2160 navigation_entry_committed_counter_ = 0;
2177 EXPECT_TRUE(details.is_in_page); 2161 EXPECT_TRUE(details.is_in_page);
2178 EXPECT_TRUE(details.did_replace_entry); 2162 EXPECT_TRUE(details.did_replace_entry);
2179 EXPECT_EQ(1, controller.GetEntryCount()); 2163 EXPECT_EQ(1, controller.GetEntryCount());
2180 } 2164 }
2181 2165
2182 // Tests for http://crbug.com/40395 2166 // Tests for http://crbug.com/40395
2183 // Simulates this: 2167 // Simulates this:
2184 // <script> 2168 // <script>
(...skipping 18 matching lines...) Expand all
2203 const GURL url("http://foo2/"); 2187 const GURL url("http://foo2/");
2204 main_test_rfh()->SendNavigate(1, url); 2188 main_test_rfh()->SendNavigate(1, url);
2205 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2189 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2206 navigation_entry_committed_counter_ = 0; 2190 navigation_entry_committed_counter_ = 0;
2207 } 2191 }
2208 2192
2209 // Navigate within the page. 2193 // Navigate within the page.
2210 { 2194 {
2211 const GURL url("http://foo2/#a"); 2195 const GURL url("http://foo2/#a");
2212 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2196 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2213 params.page_id = 1; // Same page_id
2214 params.url = url; 2197 params.url = url;
2215 params.transition = ui::PAGE_TRANSITION_LINK; 2198 params.transition = ui::PAGE_TRANSITION_LINK;
2216 params.redirects.push_back(url); 2199 params.redirects.push_back(url);
2217 params.should_update_history = true; 2200 params.should_update_history = true;
2218 params.gesture = NavigationGestureUnknown; 2201 params.gesture = NavigationGestureUnknown;
2219 params.is_post = false; 2202 params.is_post = false;
2220 params.page_state = PageState::CreateFromURL(url); 2203 params.page_state = PageState::CreateFromURL(url);
2221 params.was_within_same_page = true; 2204 params.was_within_same_page = true;
2222 2205
2223 // This should NOT generate a new entry, nor prune the list. 2206 // This should NOT generate a new entry, nor prune the list.
2224 LoadCommittedDetails details; 2207 LoadCommittedDetails details;
2225 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2208 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(),
2226 &details)); 2209 1, /* same page_id */
2210 params, &details));
2227 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2211 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2228 navigation_entry_committed_counter_ = 0; 2212 navigation_entry_committed_counter_ = 0;
2229 EXPECT_TRUE(details.is_in_page); 2213 EXPECT_TRUE(details.is_in_page);
2230 EXPECT_TRUE(details.did_replace_entry); 2214 EXPECT_TRUE(details.did_replace_entry);
2231 EXPECT_EQ(2, controller.GetEntryCount()); 2215 EXPECT_EQ(2, controller.GetEntryCount());
2232 } 2216 }
2233 2217
2234 // Perform a client redirect to a new page. 2218 // Perform a client redirect to a new page.
2235 { 2219 {
2236 const GURL url("http://foo3/"); 2220 const GURL url("http://foo3/");
2237 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2221 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2238 params.page_id = 2; // New page_id
2239 params.url = url; 2222 params.url = url;
2240 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 2223 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
2241 params.redirects.push_back(GURL("http://foo2/#a")); 2224 params.redirects.push_back(GURL("http://foo2/#a"));
2242 params.redirects.push_back(url); 2225 params.redirects.push_back(url);
2243 params.should_update_history = true; 2226 params.should_update_history = true;
2244 params.gesture = NavigationGestureUnknown; 2227 params.gesture = NavigationGestureUnknown;
2245 params.is_post = false; 2228 params.is_post = false;
2246 params.page_state = PageState::CreateFromURL(url); 2229 params.page_state = PageState::CreateFromURL(url);
2247 2230
2248 // This SHOULD generate a new entry. 2231 // This SHOULD generate a new entry.
2249 LoadCommittedDetails details; 2232 LoadCommittedDetails details;
2250 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2233 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(),
2251 &details)); 2234 2, /* new page_id */
2235 params, &details));
2252 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2236 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2253 navigation_entry_committed_counter_ = 0; 2237 navigation_entry_committed_counter_ = 0;
2254 EXPECT_FALSE(details.is_in_page); 2238 EXPECT_FALSE(details.is_in_page);
2255 EXPECT_EQ(3, controller.GetEntryCount()); 2239 EXPECT_EQ(3, controller.GetEntryCount());
2256 } 2240 }
2257 2241
2258 // Verify that BACK brings us back to http://foo2/. 2242 // Verify that BACK brings us back to http://foo2/.
2259 { 2243 {
2260 const GURL url("http://foo2/"); 2244 const GURL url("http://foo2/");
2261 controller.GoBack(); 2245 controller.GoBack();
2262 main_test_rfh()->SendNavigate(1, url); 2246 main_test_rfh()->SendNavigate(1, url);
2263 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2247 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2264 navigation_entry_committed_counter_ = 0; 2248 navigation_entry_committed_counter_ = 0;
2265 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 2249 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2266 } 2250 }
2267 } 2251 }
2268 2252
2269 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) 2253 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry)
2270 { 2254 {
2271 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); 2255 ASSERT_FALSE(controller_impl().GetLastCommittedEntry());
2272 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2256 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2273 GURL url("http://foo"); 2257 GURL url("http://foo");
2274 params.page_id = 1;
2275 params.url = url; 2258 params.url = url;
2276 params.page_state = PageState::CreateFromURL(url); 2259 params.page_state = PageState::CreateFromURL(url);
2277 params.was_within_same_page = true; 2260 params.was_within_same_page = true;
2278 contents()->GetMainFrame()->SendNavigateWithParams(&params); 2261 contents()->GetMainFrame()->SendNavigateWithParams(1, &params);
2279 // We pass if we don't crash. 2262 // We pass if we don't crash.
2280 } 2263 }
2281 2264
2282 // NotificationObserver implementation used in verifying we've received the 2265 // NotificationObserver implementation used in verifying we've received the
2283 // NOTIFICATION_NAV_LIST_PRUNED method. 2266 // NOTIFICATION_NAV_LIST_PRUNED method.
2284 class PrunedListener : public NotificationObserver { 2267 class PrunedListener : public NotificationObserver {
2285 public: 2268 public:
2286 explicit PrunedListener(NavigationControllerImpl* controller) 2269 explicit PrunedListener(NavigationControllerImpl* controller)
2287 : notification_count_(0) { 2270 : notification_count_(0) {
2288 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, 2271 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 NavigationEntryImpl::FromNavigationEntry 2392 NavigationEntryImpl::FromNavigationEntry
2410 (our_controller.GetEntryAtIndex(0))->restore_type()); 2393 (our_controller.GetEntryAtIndex(0))->restore_type());
2411 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( 2394 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry(
2412 our_controller.GetEntryAtIndex(0))->site_instance()); 2395 our_controller.GetEntryAtIndex(0))->site_instance());
2413 2396
2414 // Timestamp should remain the same before the navigation finishes. 2397 // Timestamp should remain the same before the navigation finishes.
2415 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); 2398 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp());
2416 2399
2417 // Say we navigated to that entry. 2400 // Say we navigated to that entry.
2418 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2401 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2419 params.page_id = 0;
2420 params.url = url; 2402 params.url = url;
2421 params.transition = ui::PAGE_TRANSITION_LINK; 2403 params.transition = ui::PAGE_TRANSITION_LINK;
2422 params.should_update_history = false; 2404 params.should_update_history = false;
2423 params.gesture = NavigationGestureUser; 2405 params.gesture = NavigationGestureUser;
2424 params.is_post = false; 2406 params.is_post = false;
2425 params.page_state = PageState::CreateFromURL(url); 2407 params.page_state = PageState::CreateFromURL(url);
2426 LoadCommittedDetails details; 2408 LoadCommittedDetails details;
2427 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2409 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), 0, params,
2428 &details); 2410 &details);
2429 2411
2430 // There should be no longer any pending entry and one committed one. This 2412 // There should be no longer any pending entry and one committed one. This
2431 // means that we were able to locate the entry, assign its site instance, and 2413 // means that we were able to locate the entry, assign its site instance, and
2432 // commit it properly. 2414 // commit it properly.
2433 EXPECT_EQ(1, our_controller.GetEntryCount()); 2415 EXPECT_EQ(1, our_controller.GetEntryCount());
2434 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2416 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2435 EXPECT_FALSE(our_controller.GetPendingEntry()); 2417 EXPECT_FALSE(our_controller.GetPendingEntry());
2436 EXPECT_EQ(url, 2418 EXPECT_EQ(url,
2437 NavigationEntryImpl::FromNavigationEntry( 2419 NavigationEntryImpl::FromNavigationEntry(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 fail_load_params.error_code = net::ERR_ABORTED; 2474 fail_load_params.error_code = net::ERR_ABORTED;
2493 fail_load_params.error_description = base::string16(); 2475 fail_load_params.error_description = base::string16();
2494 fail_load_params.url = url; 2476 fail_load_params.url = url;
2495 fail_load_params.showing_repost_interstitial = false; 2477 fail_load_params.showing_repost_interstitial = false;
2496 main_test_rfh()->OnMessageReceived( 2478 main_test_rfh()->OnMessageReceived(
2497 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id 2479 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
2498 fail_load_params)); 2480 fail_load_params));
2499 2481
2500 // Now the pending restored entry commits. 2482 // Now the pending restored entry commits.
2501 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2483 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2502 params.page_id = 0;
2503 params.url = url; 2484 params.url = url;
2504 params.transition = ui::PAGE_TRANSITION_LINK; 2485 params.transition = ui::PAGE_TRANSITION_LINK;
2505 params.should_update_history = false; 2486 params.should_update_history = false;
2506 params.gesture = NavigationGestureUser; 2487 params.gesture = NavigationGestureUser;
2507 params.is_post = false; 2488 params.is_post = false;
2508 params.page_state = PageState::CreateFromURL(url); 2489 params.page_state = PageState::CreateFromURL(url);
2509 LoadCommittedDetails details; 2490 LoadCommittedDetails details;
2510 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2491 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), 0, params,
2511 &details); 2492 &details);
2512 2493
2513 // There should be no pending entry and one committed one. 2494 // There should be no pending entry and one committed one.
2514 EXPECT_EQ(1, our_controller.GetEntryCount()); 2495 EXPECT_EQ(1, our_controller.GetEntryCount());
2515 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2496 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2516 EXPECT_FALSE(our_controller.GetPendingEntry()); 2497 EXPECT_FALSE(our_controller.GetPendingEntry());
2517 EXPECT_EQ(url, 2498 EXPECT_EQ(url,
2518 NavigationEntryImpl::FromNavigationEntry( 2499 NavigationEntryImpl::FromNavigationEntry(
2519 our_controller.GetLastCommittedEntry())->site_instance()-> 2500 our_controller.GetLastCommittedEntry())->site_instance()->
2520 GetSiteURL()); 2501 GetSiteURL());
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
3155 const GURL url("http://www.google.com/"); 3136 const GURL url("http://www.google.com/");
3156 main_test_rfh()->SendNavigate(0, url); 3137 main_test_rfh()->SendNavigate(0, url);
3157 3138
3158 // We should be at the first navigation entry. 3139 // We should be at the first navigation entry.
3159 EXPECT_EQ(controller.GetEntryCount(), 1); 3140 EXPECT_EQ(controller.GetEntryCount(), 1);
3160 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3141 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3161 3142
3162 // Navigate a subframe that would normally count as in-page. 3143 // Navigate a subframe that would normally count as in-page.
3163 const GURL subframe("http://www.google.com/#"); 3144 const GURL subframe("http://www.google.com/#");
3164 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3145 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3165 params.page_id = 0;
3166 params.url = subframe; 3146 params.url = subframe;
3167 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3147 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3168 params.should_update_history = false; 3148 params.should_update_history = false;
3169 params.gesture = NavigationGestureAuto; 3149 params.gesture = NavigationGestureAuto;
3170 params.is_post = false; 3150 params.is_post = false;
3171 params.page_state = PageState::CreateFromURL(subframe); 3151 params.page_state = PageState::CreateFromURL(subframe);
3172 LoadCommittedDetails details; 3152 LoadCommittedDetails details;
3173 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3153 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), 0, params,
3174 &details)); 3154 &details));
3175 3155
3176 // Nothing should have changed. 3156 // Nothing should have changed.
3177 EXPECT_EQ(controller.GetEntryCount(), 1); 3157 EXPECT_EQ(controller.GetEntryCount(), 1);
3178 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3158 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3179 } 3159 }
3180 3160
3181 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 3161 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
3182 // false. 3162 // false.
3183 TEST_F(NavigationControllerTest, CloneAndGoBack) { 3163 TEST_F(NavigationControllerTest, CloneAndGoBack) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 3251
3272 // Now start a pending load to a totally different page, but don't commit it. 3252 // Now start a pending load to a totally different page, but don't commit it.
3273 const GURL url2("http://bar/"); 3253 const GURL url2("http://bar/");
3274 controller.LoadURL( 3254 controller.LoadURL(
3275 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3255 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3276 3256
3277 // Send a subframe update from the first page, as if one had just 3257 // Send a subframe update from the first page, as if one had just
3278 // automatically loaded. Auto subframes don't increment the page ID. 3258 // automatically loaded. Auto subframes don't increment the page ID.
3279 const GURL url1_sub("http://foo/subframe"); 3259 const GURL url1_sub("http://foo/subframe");
3280 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3260 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3281 params.page_id = controller.GetLastCommittedEntry()->GetPageID();
3282 params.url = url1_sub; 3261 params.url = url1_sub;
3283 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3262 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3284 params.should_update_history = false; 3263 params.should_update_history = false;
3285 params.gesture = NavigationGestureAuto; 3264 params.gesture = NavigationGestureAuto;
3286 params.is_post = false; 3265 params.is_post = false;
3287 params.page_state = PageState::CreateFromURL(url1_sub); 3266 params.page_state = PageState::CreateFromURL(url1_sub);
3288 LoadCommittedDetails details; 3267 LoadCommittedDetails details;
3289 3268
3290 // This should return false meaning that nothing was actually updated. 3269 // This should return false meaning that nothing was actually updated.
3291 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3270 EXPECT_FALSE(controller.RendererDidNavigate(
3292 &details)); 3271 main_test_rfh(), controller.GetLastCommittedEntry()->GetPageID(), params,
3272 &details));
3293 3273
3294 // The notification should have updated the last committed one, and not 3274 // The notification should have updated the last committed one, and not
3295 // the pending load. 3275 // the pending load.
3296 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); 3276 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL());
3297 3277
3298 // The active entry should be unchanged by the subframe load. 3278 // The active entry should be unchanged by the subframe load.
3299 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3279 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3300 } 3280 }
3301 3281
3302 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. 3282 // 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
4249 base::string16 title(base::ASCIIToUTF16("Title")); 4229 base::string16 title(base::ASCIIToUTF16("Title"));
4250 FaviconStatus favicon; 4230 FaviconStatus favicon;
4251 favicon.valid = true; 4231 favicon.valid = true;
4252 favicon.url = GURL("http://foo/favicon.ico"); 4232 favicon.url = GURL("http://foo/favicon.ico");
4253 controller().GetLastCommittedEntry()->SetTitle(title); 4233 controller().GetLastCommittedEntry()->SetTitle(title);
4254 controller().GetLastCommittedEntry()->GetFavicon() = favicon; 4234 controller().GetLastCommittedEntry()->GetFavicon() = favicon;
4255 4235
4256 // history.pushState() is called. 4236 // history.pushState() is called.
4257 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4237 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4258 GURL url("http://foo#foo"); 4238 GURL url("http://foo#foo");
4259 params.page_id = 2;
4260 params.url = url; 4239 params.url = url;
4261 params.page_state = PageState::CreateFromURL(url); 4240 params.page_state = PageState::CreateFromURL(url);
4262 params.was_within_same_page = true; 4241 params.was_within_same_page = true;
4263 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4242 contents()->GetMainFrame()->SendNavigateWithParams(2, &params);
4264 4243
4265 // The title should immediately be visible on the new NavigationEntry. 4244 // The title should immediately be visible on the new NavigationEntry.
4266 base::string16 new_title = 4245 base::string16 new_title =
4267 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); 4246 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string());
4268 EXPECT_EQ(title, new_title); 4247 EXPECT_EQ(title, new_title);
4269 FaviconStatus new_favicon = 4248 FaviconStatus new_favicon =
4270 controller().GetLastCommittedEntry()->GetFavicon(); 4249 controller().GetLastCommittedEntry()->GetFavicon();
4271 EXPECT_EQ(favicon.valid, new_favicon.valid); 4250 EXPECT_EQ(favicon.valid, new_favicon.valid);
4272 EXPECT_EQ(favicon.url, new_favicon.url); 4251 EXPECT_EQ(favicon.url, new_favicon.url);
4273 } 4252 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4322 } 4301 }
4323 4302
4324 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { 4303 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) {
4325 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 4304 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
4326 EXPECT_FALSE(contents()->GetDelegate()); 4305 EXPECT_FALSE(contents()->GetDelegate());
4327 contents()->SetDelegate(delegate.get()); 4306 contents()->SetDelegate(delegate.get());
4328 4307
4329 // Submit a form. 4308 // Submit a form.
4330 GURL url("http://foo"); 4309 GURL url("http://foo");
4331 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4310 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4332 params.page_id = 1;
4333 params.url = url; 4311 params.url = url;
4334 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; 4312 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT;
4335 params.gesture = NavigationGestureUser; 4313 params.gesture = NavigationGestureUser;
4336 params.page_state = PageState::CreateFromURL(url); 4314 params.page_state = PageState::CreateFromURL(url);
4337 params.was_within_same_page = false; 4315 params.was_within_same_page = false;
4338 params.is_post = true; 4316 params.is_post = true;
4339 params.post_id = 2; 4317 params.post_id = 2;
4340 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4318 contents()->GetMainFrame()->SendNavigateWithParams(1, &params);
4341 4319
4342 // history.replaceState() is called. 4320 // history.replaceState() is called.
4343 GURL replace_url("http://foo#foo"); 4321 GURL replace_url("http://foo#foo");
4344 params.page_id = 1;
4345 params.url = replace_url; 4322 params.url = replace_url;
4346 params.transition = ui::PAGE_TRANSITION_LINK; 4323 params.transition = ui::PAGE_TRANSITION_LINK;
4347 params.gesture = NavigationGestureUser; 4324 params.gesture = NavigationGestureUser;
4348 params.page_state = PageState::CreateFromURL(replace_url); 4325 params.page_state = PageState::CreateFromURL(replace_url);
4349 params.was_within_same_page = true; 4326 params.was_within_same_page = true;
4350 params.is_post = false; 4327 params.is_post = false;
4351 params.post_id = -1; 4328 params.post_id = -1;
4352 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4329 contents()->GetMainFrame()->SendNavigateWithParams(1, &params);
4353 4330
4354 // Now reload. replaceState overrides the POST, so we should not show a 4331 // Now reload. replaceState overrides the POST, so we should not show a
4355 // repost warning dialog. 4332 // repost warning dialog.
4356 controller_impl().Reload(true); 4333 controller_impl().Reload(true);
4357 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4334 EXPECT_EQ(0, delegate->repost_form_warning_count());
4358 } 4335 }
4359 4336
4360 } // namespace content 4337 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/browser/frame_host/navigator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698