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

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

Issue 118443008: Support cross-process navigations in a single subframe RenderFrameHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup Created 7 years 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 | Annotate | Revision Log
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/file_util.h" 7 #include "base/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 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 params.redirects.push_back(GURL("http://foo1")); 1666 params.redirects.push_back(GURL("http://foo1"));
1667 params.redirects.push_back(GURL("http://foo2")); 1667 params.redirects.push_back(GURL("http://foo2"));
1668 params.should_update_history = false; 1668 params.should_update_history = false;
1669 params.gesture = NavigationGestureAuto; 1669 params.gesture = NavigationGestureAuto;
1670 params.is_post = false; 1670 params.is_post = false;
1671 params.page_state = PageState::CreateFromURL(url2); 1671 params.page_state = PageState::CreateFromURL(url2);
1672 1672
1673 LoadCommittedDetails details; 1673 LoadCommittedDetails details;
1674 1674
1675 EXPECT_EQ(0U, notifications.size()); 1675 EXPECT_EQ(0U, notifications.size());
1676 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1676 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1677 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1677 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1678 navigation_entry_committed_counter_ = 0; 1678 navigation_entry_committed_counter_ = 0;
1679 1679
1680 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1680 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1681 EXPECT_EQ(controller.GetEntryCount(), 1); 1681 EXPECT_EQ(controller.GetEntryCount(), 1);
1682 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1682 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1683 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1683 EXPECT_TRUE(controller.GetLastCommittedEntry());
1684 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1684 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1685 EXPECT_FALSE(controller.GetPendingEntry()); 1685 EXPECT_FALSE(controller.GetPendingEntry());
1686 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 1686 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 params.redirects.push_back(GURL("http://foo1")); 1723 params.redirects.push_back(GURL("http://foo1"));
1724 params.redirects.push_back(GURL("http://foo2")); 1724 params.redirects.push_back(GURL("http://foo2"));
1725 params.should_update_history = false; 1725 params.should_update_history = false;
1726 params.gesture = NavigationGestureAuto; 1726 params.gesture = NavigationGestureAuto;
1727 params.is_post = false; 1727 params.is_post = false;
1728 params.page_state = PageState::CreateFromURL(url2); 1728 params.page_state = PageState::CreateFromURL(url2);
1729 1729
1730 LoadCommittedDetails details; 1730 LoadCommittedDetails details;
1731 1731
1732 EXPECT_EQ(0U, notifications.size()); 1732 EXPECT_EQ(0U, notifications.size());
1733 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1733 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1734 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1734 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1735 navigation_entry_committed_counter_ = 0; 1735 navigation_entry_committed_counter_ = 0;
1736 1736
1737 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1737 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1738 EXPECT_EQ(controller.GetEntryCount(), 1); 1738 EXPECT_EQ(controller.GetEntryCount(), 1);
1739 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1739 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1740 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1740 EXPECT_TRUE(controller.GetLastCommittedEntry());
1741 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1741 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1742 EXPECT_FALSE(controller.GetPendingEntry()); 1742 EXPECT_FALSE(controller.GetPendingEntry());
1743 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 1743 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
(...skipping 26 matching lines...) Expand all
1770 params.redirects.push_back(GURL("http://foo1")); 1770 params.redirects.push_back(GURL("http://foo1"));
1771 params.redirects.push_back(GURL("http://foo2")); 1771 params.redirects.push_back(GURL("http://foo2"));
1772 params.should_update_history = false; 1772 params.should_update_history = false;
1773 params.gesture = NavigationGestureAuto; 1773 params.gesture = NavigationGestureAuto;
1774 params.is_post = false; 1774 params.is_post = false;
1775 params.page_state = PageState::CreateFromURL(url2); 1775 params.page_state = PageState::CreateFromURL(url2);
1776 1776
1777 LoadCommittedDetails details; 1777 LoadCommittedDetails details;
1778 1778
1779 EXPECT_EQ(0U, notifications.size()); 1779 EXPECT_EQ(0U, notifications.size());
1780 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1780 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1781 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1781 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1782 navigation_entry_committed_counter_ = 0; 1782 navigation_entry_committed_counter_ = 0;
1783 1783
1784 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); 1784 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE);
1785 EXPECT_EQ(controller.GetEntryCount(), 1); 1785 EXPECT_EQ(controller.GetEntryCount(), 1);
1786 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1786 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1787 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1787 EXPECT_TRUE(controller.GetLastCommittedEntry());
1788 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1788 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1789 EXPECT_FALSE(controller.GetPendingEntry()); 1789 EXPECT_FALSE(controller.GetPendingEntry());
1790 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 1790 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
(...skipping 18 matching lines...) Expand all
1809 ViewHostMsg_FrameNavigate_Params params; 1809 ViewHostMsg_FrameNavigate_Params params;
1810 params.page_id = 1; 1810 params.page_id = 1;
1811 params.url = url2; 1811 params.url = url2;
1812 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; 1812 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
1813 params.should_update_history = false; 1813 params.should_update_history = false;
1814 params.gesture = NavigationGestureUser; 1814 params.gesture = NavigationGestureUser;
1815 params.is_post = false; 1815 params.is_post = false;
1816 params.page_state = PageState::CreateFromURL(url2); 1816 params.page_state = PageState::CreateFromURL(url2);
1817 1817
1818 LoadCommittedDetails details; 1818 LoadCommittedDetails details;
1819 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1819 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1820 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1820 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1821 navigation_entry_committed_counter_ = 0; 1821 navigation_entry_committed_counter_ = 0;
1822 EXPECT_EQ(url1, details.previous_url); 1822 EXPECT_EQ(url1, details.previous_url);
1823 EXPECT_FALSE(details.is_in_page); 1823 EXPECT_FALSE(details.is_in_page);
1824 EXPECT_FALSE(details.is_main_frame); 1824 EXPECT_FALSE(details.is_main_frame);
1825 1825
1826 // The new entry should be appended. 1826 // The new entry should be appended.
1827 EXPECT_EQ(2, controller.GetEntryCount()); 1827 EXPECT_EQ(2, controller.GetEntryCount());
1828 1828
1829 // New entry should refer to the new page, but the old URL (entries only 1829 // New entry should refer to the new page, but the old URL (entries only
(...skipping 15 matching lines...) Expand all
1845 ViewHostMsg_FrameNavigate_Params params; 1845 ViewHostMsg_FrameNavigate_Params params;
1846 params.page_id = 1; 1846 params.page_id = 1;
1847 params.url = url; 1847 params.url = url;
1848 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 1848 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
1849 params.should_update_history = false; 1849 params.should_update_history = false;
1850 params.gesture = NavigationGestureAuto; 1850 params.gesture = NavigationGestureAuto;
1851 params.is_post = false; 1851 params.is_post = false;
1852 params.page_state = PageState::CreateFromURL(url); 1852 params.page_state = PageState::CreateFromURL(url);
1853 1853
1854 LoadCommittedDetails details; 1854 LoadCommittedDetails details;
1855 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); 1855 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details));
1856 EXPECT_EQ(0U, notifications.size()); 1856 EXPECT_EQ(0U, notifications.size());
1857 } 1857 }
1858 1858
1859 // Auto subframes are ones the page loads automatically like ads. They should 1859 // Auto subframes are ones the page loads automatically like ads. They should
1860 // not create new navigation entries. 1860 // not create new navigation entries.
1861 TEST_F(NavigationControllerTest, AutoSubframe) { 1861 TEST_F(NavigationControllerTest, AutoSubframe) {
1862 NavigationControllerImpl& controller = controller_impl(); 1862 NavigationControllerImpl& controller = controller_impl();
1863 TestNotificationTracker notifications; 1863 TestNotificationTracker notifications;
1864 RegisterForAllNavNotifications(&notifications, &controller); 1864 RegisterForAllNavNotifications(&notifications, &controller);
1865 1865
1866 const GURL url1("http://foo1"); 1866 const GURL url1("http://foo1");
1867 test_rvh()->SendNavigate(0, url1); 1867 test_rvh()->SendNavigate(0, url1);
1868 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1868 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1869 navigation_entry_committed_counter_ = 0; 1869 navigation_entry_committed_counter_ = 0;
1870 1870
1871 const GURL url2("http://foo2"); 1871 const GURL url2("http://foo2");
1872 ViewHostMsg_FrameNavigate_Params params; 1872 ViewHostMsg_FrameNavigate_Params params;
1873 params.page_id = 0; 1873 params.page_id = 0;
1874 params.url = url2; 1874 params.url = url2;
1875 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 1875 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
1876 params.should_update_history = false; 1876 params.should_update_history = false;
1877 params.gesture = NavigationGestureUser; 1877 params.gesture = NavigationGestureUser;
1878 params.is_post = false; 1878 params.is_post = false;
1879 params.page_state = PageState::CreateFromURL(url2); 1879 params.page_state = PageState::CreateFromURL(url2);
1880 1880
1881 // Navigating should do nothing. 1881 // Navigating should do nothing.
1882 LoadCommittedDetails details; 1882 LoadCommittedDetails details;
1883 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); 1883 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details));
1884 EXPECT_EQ(0U, notifications.size()); 1884 EXPECT_EQ(0U, notifications.size());
1885 1885
1886 // There should still be only one entry. 1886 // There should still be only one entry.
1887 EXPECT_EQ(1, controller.GetEntryCount()); 1887 EXPECT_EQ(1, controller.GetEntryCount());
1888 } 1888 }
1889 1889
1890 // Tests navigation and then going back to a subframe navigation. 1890 // Tests navigation and then going back to a subframe navigation.
1891 TEST_F(NavigationControllerTest, BackSubframe) { 1891 TEST_F(NavigationControllerTest, BackSubframe) {
1892 NavigationControllerImpl& controller = controller_impl(); 1892 NavigationControllerImpl& controller = controller_impl();
1893 TestNotificationTracker notifications; 1893 TestNotificationTracker notifications;
(...skipping 11 matching lines...) Expand all
1905 params.page_id = 1; 1905 params.page_id = 1;
1906 params.url = url2; 1906 params.url = url2;
1907 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; 1907 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
1908 params.should_update_history = false; 1908 params.should_update_history = false;
1909 params.gesture = NavigationGestureUser; 1909 params.gesture = NavigationGestureUser;
1910 params.is_post = false; 1910 params.is_post = false;
1911 params.page_state = PageState::CreateFromURL(url2); 1911 params.page_state = PageState::CreateFromURL(url2);
1912 1912
1913 // This should generate a new entry. 1913 // This should generate a new entry.
1914 LoadCommittedDetails details; 1914 LoadCommittedDetails details;
1915 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1915 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1916 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1916 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1917 navigation_entry_committed_counter_ = 0; 1917 navigation_entry_committed_counter_ = 0;
1918 EXPECT_EQ(2, controller.GetEntryCount()); 1918 EXPECT_EQ(2, controller.GetEntryCount());
1919 1919
1920 // Second manual subframe navigation should also make a new entry. 1920 // Second manual subframe navigation should also make a new entry.
1921 const GURL url3("http://foo3"); 1921 const GURL url3("http://foo3");
1922 params.page_id = 2; 1922 params.page_id = 2;
1923 params.url = url3; 1923 params.url = url3;
1924 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1924 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1925 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1925 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1926 navigation_entry_committed_counter_ = 0; 1926 navigation_entry_committed_counter_ = 0;
1927 EXPECT_EQ(3, controller.GetEntryCount()); 1927 EXPECT_EQ(3, controller.GetEntryCount());
1928 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 1928 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
1929 1929
1930 // Go back one. 1930 // Go back one.
1931 controller.GoBack(); 1931 controller.GoBack();
1932 params.url = url2; 1932 params.url = url2;
1933 params.page_id = 1; 1933 params.page_id = 1;
1934 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1934 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1935 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1935 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1936 navigation_entry_committed_counter_ = 0; 1936 navigation_entry_committed_counter_ = 0;
1937 EXPECT_EQ(3, controller.GetEntryCount()); 1937 EXPECT_EQ(3, controller.GetEntryCount());
1938 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 1938 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
1939 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1939 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1940 EXPECT_FALSE(controller.GetPendingEntry()); 1940 EXPECT_FALSE(controller.GetPendingEntry());
1941 1941
1942 // Go back one more. 1942 // Go back one more.
1943 controller.GoBack(); 1943 controller.GoBack();
1944 params.url = url1; 1944 params.url = url1;
1945 params.page_id = 0; 1945 params.page_id = 0;
1946 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1946 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
1947 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1947 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1948 navigation_entry_committed_counter_ = 0; 1948 navigation_entry_committed_counter_ = 0;
1949 EXPECT_EQ(3, controller.GetEntryCount()); 1949 EXPECT_EQ(3, controller.GetEntryCount());
1950 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 1950 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
1951 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1951 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1952 EXPECT_FALSE(controller.GetPendingEntry()); 1952 EXPECT_FALSE(controller.GetPendingEntry());
1953 } 1953 }
1954 1954
1955 TEST_F(NavigationControllerTest, LinkClick) { 1955 TEST_F(NavigationControllerTest, LinkClick) {
1956 NavigationControllerImpl& controller = controller_impl(); 1956 NavigationControllerImpl& controller = controller_impl();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 self_params.page_id = 0; 1995 self_params.page_id = 0;
1996 self_params.url = url1; 1996 self_params.url = url1;
1997 self_params.transition = PAGE_TRANSITION_LINK; 1997 self_params.transition = PAGE_TRANSITION_LINK;
1998 self_params.should_update_history = false; 1998 self_params.should_update_history = false;
1999 self_params.gesture = NavigationGestureUser; 1999 self_params.gesture = NavigationGestureUser;
2000 self_params.is_post = false; 2000 self_params.is_post = false;
2001 self_params.page_state = PageState::CreateFromURL(url1); 2001 self_params.page_state = PageState::CreateFromURL(url1);
2002 self_params.was_within_same_page = true; 2002 self_params.was_within_same_page = true;
2003 2003
2004 LoadCommittedDetails details; 2004 LoadCommittedDetails details;
2005 EXPECT_TRUE(controller.RendererDidNavigate(self_params, &details)); 2005 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), self_params,
2006 &details));
2006 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2007 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2007 navigation_entry_committed_counter_ = 0; 2008 navigation_entry_committed_counter_ = 0;
2008 EXPECT_TRUE(details.is_in_page); 2009 EXPECT_TRUE(details.is_in_page);
2009 EXPECT_TRUE(details.did_replace_entry); 2010 EXPECT_TRUE(details.did_replace_entry);
2010 EXPECT_EQ(1, controller.GetEntryCount()); 2011 EXPECT_EQ(1, controller.GetEntryCount());
2011 2012
2012 // Fragment navigation to a new page_id. 2013 // Fragment navigation to a new page_id.
2013 const GURL url2("http://foo#a"); 2014 const GURL url2("http://foo#a");
2014 ViewHostMsg_FrameNavigate_Params params; 2015 ViewHostMsg_FrameNavigate_Params params;
2015 params.page_id = 1; 2016 params.page_id = 1;
2016 params.url = url2; 2017 params.url = url2;
2017 params.transition = PAGE_TRANSITION_LINK; 2018 params.transition = PAGE_TRANSITION_LINK;
2018 params.should_update_history = false; 2019 params.should_update_history = false;
2019 params.gesture = NavigationGestureUser; 2020 params.gesture = NavigationGestureUser;
2020 params.is_post = false; 2021 params.is_post = false;
2021 params.page_state = PageState::CreateFromURL(url2); 2022 params.page_state = PageState::CreateFromURL(url2);
2022 params.was_within_same_page = true; 2023 params.was_within_same_page = true;
2023 2024
2024 // This should generate a new entry. 2025 // This should generate a new entry.
2025 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 2026 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
2026 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2027 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2027 navigation_entry_committed_counter_ = 0; 2028 navigation_entry_committed_counter_ = 0;
2028 EXPECT_TRUE(details.is_in_page); 2029 EXPECT_TRUE(details.is_in_page);
2029 EXPECT_FALSE(details.did_replace_entry); 2030 EXPECT_FALSE(details.did_replace_entry);
2030 EXPECT_EQ(2, controller.GetEntryCount()); 2031 EXPECT_EQ(2, controller.GetEntryCount());
2031 2032
2032 // Go back one. 2033 // Go back one.
2033 ViewHostMsg_FrameNavigate_Params back_params(params); 2034 ViewHostMsg_FrameNavigate_Params back_params(params);
2034 controller.GoBack(); 2035 controller.GoBack();
2035 back_params.url = url1; 2036 back_params.url = url1;
2036 back_params.page_id = 0; 2037 back_params.page_id = 0;
2037 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); 2038 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), back_params,
2039 &details));
2038 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2040 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2039 navigation_entry_committed_counter_ = 0; 2041 navigation_entry_committed_counter_ = 0;
2040 EXPECT_TRUE(details.is_in_page); 2042 EXPECT_TRUE(details.is_in_page);
2041 EXPECT_EQ(2, controller.GetEntryCount()); 2043 EXPECT_EQ(2, controller.GetEntryCount());
2042 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2044 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2043 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); 2045 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
2044 2046
2045 // Go forward 2047 // Go forward
2046 ViewHostMsg_FrameNavigate_Params forward_params(params); 2048 ViewHostMsg_FrameNavigate_Params forward_params(params);
2047 controller.GoForward(); 2049 controller.GoForward();
2048 forward_params.url = url2; 2050 forward_params.url = url2;
2049 forward_params.page_id = 1; 2051 forward_params.page_id = 1;
2050 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); 2052 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), forward_params,
2053 &details));
2051 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2054 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2052 navigation_entry_committed_counter_ = 0; 2055 navigation_entry_committed_counter_ = 0;
2053 EXPECT_TRUE(details.is_in_page); 2056 EXPECT_TRUE(details.is_in_page);
2054 EXPECT_EQ(2, controller.GetEntryCount()); 2057 EXPECT_EQ(2, controller.GetEntryCount());
2055 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2058 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2056 EXPECT_EQ(forward_params.url, 2059 EXPECT_EQ(forward_params.url,
2057 controller.GetVisibleEntry()->GetURL()); 2060 controller.GetVisibleEntry()->GetURL());
2058 2061
2059 // Now go back and forward again. This is to work around a bug where we would 2062 // Now go back and forward again. This is to work around a bug where we would
2060 // compare the incoming URL with the last committed entry rather than the 2063 // compare the incoming URL with the last committed entry rather than the
2061 // one identified by an existing page ID. This would result in the second URL 2064 // one identified by an existing page ID. This would result in the second URL
2062 // losing the reference fragment when you navigate away from it and then back. 2065 // losing the reference fragment when you navigate away from it and then back.
2063 controller.GoBack(); 2066 controller.GoBack();
2064 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); 2067 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), back_params,
2068 &details));
2065 controller.GoForward(); 2069 controller.GoForward();
2066 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); 2070 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), forward_params,
2071 &details));
2067 EXPECT_EQ(forward_params.url, 2072 EXPECT_EQ(forward_params.url,
2068 controller.GetVisibleEntry()->GetURL()); 2073 controller.GetVisibleEntry()->GetURL());
2069 2074
2070 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. 2075 // Finally, navigate to an unrelated URL to make sure in_page is not sticky.
2071 const GURL url3("http://bar"); 2076 const GURL url3("http://bar");
2072 params.page_id = 2; 2077 params.page_id = 2;
2073 params.url = url3; 2078 params.url = url3;
2074 navigation_entry_committed_counter_ = 0; 2079 navigation_entry_committed_counter_ = 0;
2075 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 2080 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
2076 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2081 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2077 navigation_entry_committed_counter_ = 0; 2082 navigation_entry_committed_counter_ = 0;
2078 EXPECT_FALSE(details.is_in_page); 2083 EXPECT_FALSE(details.is_in_page);
2079 EXPECT_EQ(3, controller.GetEntryCount()); 2084 EXPECT_EQ(3, controller.GetEntryCount());
2080 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2085 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2081 } 2086 }
2082 2087
2083 TEST_F(NavigationControllerTest, InPage_Replace) { 2088 TEST_F(NavigationControllerTest, InPage_Replace) {
2084 NavigationControllerImpl& controller = controller_impl(); 2089 NavigationControllerImpl& controller = controller_impl();
2085 TestNotificationTracker notifications; 2090 TestNotificationTracker notifications;
(...skipping 11 matching lines...) Expand all
2097 params.page_id = 0; // Same page_id 2102 params.page_id = 0; // Same page_id
2098 params.url = url2; 2103 params.url = url2;
2099 params.transition = PAGE_TRANSITION_LINK; 2104 params.transition = PAGE_TRANSITION_LINK;
2100 params.should_update_history = false; 2105 params.should_update_history = false;
2101 params.gesture = NavigationGestureUser; 2106 params.gesture = NavigationGestureUser;
2102 params.is_post = false; 2107 params.is_post = false;
2103 params.page_state = PageState::CreateFromURL(url2); 2108 params.page_state = PageState::CreateFromURL(url2);
2104 2109
2105 // This should NOT generate a new entry, nor prune the list. 2110 // This should NOT generate a new entry, nor prune the list.
2106 LoadCommittedDetails details; 2111 LoadCommittedDetails details;
2107 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 2112 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
2108 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2113 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2109 navigation_entry_committed_counter_ = 0; 2114 navigation_entry_committed_counter_ = 0;
2110 EXPECT_TRUE(details.is_in_page); 2115 EXPECT_TRUE(details.is_in_page);
2111 EXPECT_TRUE(details.did_replace_entry); 2116 EXPECT_TRUE(details.did_replace_entry);
2112 EXPECT_EQ(1, controller.GetEntryCount()); 2117 EXPECT_EQ(1, controller.GetEntryCount());
2113 } 2118 }
2114 2119
2115 // Tests for http://crbug.com/40395 2120 // Tests for http://crbug.com/40395
2116 // Simulates this: 2121 // Simulates this:
2117 // <script> 2122 // <script>
(...skipping 29 matching lines...) Expand all
2147 params.url = url; 2152 params.url = url;
2148 params.transition = PAGE_TRANSITION_LINK; 2153 params.transition = PAGE_TRANSITION_LINK;
2149 params.redirects.push_back(url); 2154 params.redirects.push_back(url);
2150 params.should_update_history = true; 2155 params.should_update_history = true;
2151 params.gesture = NavigationGestureUnknown; 2156 params.gesture = NavigationGestureUnknown;
2152 params.is_post = false; 2157 params.is_post = false;
2153 params.page_state = PageState::CreateFromURL(url); 2158 params.page_state = PageState::CreateFromURL(url);
2154 2159
2155 // This should NOT generate a new entry, nor prune the list. 2160 // This should NOT generate a new entry, nor prune the list.
2156 LoadCommittedDetails details; 2161 LoadCommittedDetails details;
2157 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 2162 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
2158 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2163 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2159 navigation_entry_committed_counter_ = 0; 2164 navigation_entry_committed_counter_ = 0;
2160 EXPECT_TRUE(details.is_in_page); 2165 EXPECT_TRUE(details.is_in_page);
2161 EXPECT_TRUE(details.did_replace_entry); 2166 EXPECT_TRUE(details.did_replace_entry);
2162 EXPECT_EQ(2, controller.GetEntryCount()); 2167 EXPECT_EQ(2, controller.GetEntryCount());
2163 } 2168 }
2164 2169
2165 // Perform a client redirect to a new page. 2170 // Perform a client redirect to a new page.
2166 { 2171 {
2167 const GURL url("http://foo3/"); 2172 const GURL url("http://foo3/");
2168 ViewHostMsg_FrameNavigate_Params params; 2173 ViewHostMsg_FrameNavigate_Params params;
2169 params.page_id = 2; // New page_id 2174 params.page_id = 2; // New page_id
2170 params.url = url; 2175 params.url = url;
2171 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT; 2176 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT;
2172 params.redirects.push_back(GURL("http://foo2/#a")); 2177 params.redirects.push_back(GURL("http://foo2/#a"));
2173 params.redirects.push_back(url); 2178 params.redirects.push_back(url);
2174 params.should_update_history = true; 2179 params.should_update_history = true;
2175 params.gesture = NavigationGestureUnknown; 2180 params.gesture = NavigationGestureUnknown;
2176 params.is_post = false; 2181 params.is_post = false;
2177 params.page_state = PageState::CreateFromURL(url); 2182 params.page_state = PageState::CreateFromURL(url);
2178 2183
2179 // This SHOULD generate a new entry. 2184 // This SHOULD generate a new entry.
2180 LoadCommittedDetails details; 2185 LoadCommittedDetails details;
2181 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 2186 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details));
2182 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2187 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2183 navigation_entry_committed_counter_ = 0; 2188 navigation_entry_committed_counter_ = 0;
2184 EXPECT_FALSE(details.is_in_page); 2189 EXPECT_FALSE(details.is_in_page);
2185 EXPECT_EQ(3, controller.GetEntryCount()); 2190 EXPECT_EQ(3, controller.GetEntryCount());
2186 } 2191 }
2187 2192
2188 // Verify that BACK brings us back to http://foo2/. 2193 // Verify that BACK brings us back to http://foo2/.
2189 { 2194 {
2190 const GURL url("http://foo2/"); 2195 const GURL url("http://foo2/");
2191 controller.GoBack(); 2196 controller.GoBack();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2334 // Say we navigated to that entry. 2339 // Say we navigated to that entry.
2335 ViewHostMsg_FrameNavigate_Params params; 2340 ViewHostMsg_FrameNavigate_Params params;
2336 params.page_id = 0; 2341 params.page_id = 0;
2337 params.url = url; 2342 params.url = url;
2338 params.transition = PAGE_TRANSITION_LINK; 2343 params.transition = PAGE_TRANSITION_LINK;
2339 params.should_update_history = false; 2344 params.should_update_history = false;
2340 params.gesture = NavigationGestureUser; 2345 params.gesture = NavigationGestureUser;
2341 params.is_post = false; 2346 params.is_post = false;
2342 params.page_state = PageState::CreateFromURL(url); 2347 params.page_state = PageState::CreateFromURL(url);
2343 LoadCommittedDetails details; 2348 LoadCommittedDetails details;
2344 our_controller.RendererDidNavigate(params, &details); 2349 our_controller.RendererDidNavigate(our_contents->GetRenderViewHost(), params,
2350 &details);
2345 2351
2346 // There should be no longer any pending entry and one committed one. This 2352 // There should be no longer any pending entry and one committed one. This
2347 // means that we were able to locate the entry, assign its site instance, and 2353 // means that we were able to locate the entry, assign its site instance, and
2348 // commit it properly. 2354 // commit it properly.
2349 EXPECT_EQ(1, our_controller.GetEntryCount()); 2355 EXPECT_EQ(1, our_controller.GetEntryCount());
2350 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2356 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2351 EXPECT_FALSE(our_controller.GetPendingEntry()); 2357 EXPECT_FALSE(our_controller.GetPendingEntry());
2352 EXPECT_EQ(url, 2358 EXPECT_EQ(url,
2353 NavigationEntryImpl::FromNavigationEntry( 2359 NavigationEntryImpl::FromNavigationEntry(
2354 our_controller.GetLastCommittedEntry())->site_instance()-> 2360 our_controller.GetLastCommittedEntry())->site_instance()->
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2420 // Now the pending restored entry commits. 2426 // Now the pending restored entry commits.
2421 ViewHostMsg_FrameNavigate_Params params; 2427 ViewHostMsg_FrameNavigate_Params params;
2422 params.page_id = 0; 2428 params.page_id = 0;
2423 params.url = url; 2429 params.url = url;
2424 params.transition = PAGE_TRANSITION_LINK; 2430 params.transition = PAGE_TRANSITION_LINK;
2425 params.should_update_history = false; 2431 params.should_update_history = false;
2426 params.gesture = NavigationGestureUser; 2432 params.gesture = NavigationGestureUser;
2427 params.is_post = false; 2433 params.is_post = false;
2428 params.page_state = PageState::CreateFromURL(url); 2434 params.page_state = PageState::CreateFromURL(url);
2429 LoadCommittedDetails details; 2435 LoadCommittedDetails details;
2430 our_controller.RendererDidNavigate(params, &details); 2436 our_controller.RendererDidNavigate(rvh, params, &details);
2431 2437
2432 // There should be no pending entry and one committed one. 2438 // There should be no pending entry and one committed one.
2433 EXPECT_EQ(1, our_controller.GetEntryCount()); 2439 EXPECT_EQ(1, our_controller.GetEntryCount());
2434 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2440 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2435 EXPECT_FALSE(our_controller.GetPendingEntry()); 2441 EXPECT_FALSE(our_controller.GetPendingEntry());
2436 EXPECT_EQ(url, 2442 EXPECT_EQ(url,
2437 NavigationEntryImpl::FromNavigationEntry( 2443 NavigationEntryImpl::FromNavigationEntry(
2438 our_controller.GetLastCommittedEntry())->site_instance()-> 2444 our_controller.GetLastCommittedEntry())->site_instance()->
2439 GetSiteURL()); 2445 GetSiteURL());
2440 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, 2446 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE,
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
2945 const GURL subframe("http://www.google.com/#"); 2951 const GURL subframe("http://www.google.com/#");
2946 ViewHostMsg_FrameNavigate_Params params; 2952 ViewHostMsg_FrameNavigate_Params params;
2947 params.page_id = 0; 2953 params.page_id = 0;
2948 params.url = subframe; 2954 params.url = subframe;
2949 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 2955 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2950 params.should_update_history = false; 2956 params.should_update_history = false;
2951 params.gesture = NavigationGestureAuto; 2957 params.gesture = NavigationGestureAuto;
2952 params.is_post = false; 2958 params.is_post = false;
2953 params.page_state = PageState::CreateFromURL(subframe); 2959 params.page_state = PageState::CreateFromURL(subframe);
2954 LoadCommittedDetails details; 2960 LoadCommittedDetails details;
2955 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); 2961 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details));
2956 2962
2957 // Nothing should have changed. 2963 // Nothing should have changed.
2958 EXPECT_EQ(controller.GetEntryCount(), 1); 2964 EXPECT_EQ(controller.GetEntryCount(), 1);
2959 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 2965 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
2960 } 2966 }
2961 2967
2962 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 2968 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
2963 // false. 2969 // false.
2964 TEST_F(NavigationControllerTest, CloneAndGoBack) { 2970 TEST_F(NavigationControllerTest, CloneAndGoBack) {
2965 NavigationControllerImpl& controller = controller_impl(); 2971 NavigationControllerImpl& controller = controller_impl();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); 3068 params.page_id = controller.GetLastCommittedEntry()->GetPageID();
3063 params.url = url1_sub; 3069 params.url = url1_sub;
3064 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 3070 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
3065 params.should_update_history = false; 3071 params.should_update_history = false;
3066 params.gesture = NavigationGestureAuto; 3072 params.gesture = NavigationGestureAuto;
3067 params.is_post = false; 3073 params.is_post = false;
3068 params.page_state = PageState::CreateFromURL(url1_sub); 3074 params.page_state = PageState::CreateFromURL(url1_sub);
3069 LoadCommittedDetails details; 3075 LoadCommittedDetails details;
3070 3076
3071 // This should return false meaning that nothing was actually updated. 3077 // This should return false meaning that nothing was actually updated.
3072 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); 3078 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details));
3073 3079
3074 // The notification should have updated the last committed one, and not 3080 // The notification should have updated the last committed one, and not
3075 // the pending load. 3081 // the pending load.
3076 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); 3082 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL());
3077 3083
3078 // The active entry should be unchanged by the subframe load. 3084 // The active entry should be unchanged by the subframe load.
3079 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3085 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3080 } 3086 }
3081 3087
3082 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. 3088 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target.
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
4008 EXPECT_EQ(1, controller.GetEntryCount()); 4014 EXPECT_EQ(1, controller.GetEntryCount());
4009 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4015 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4010 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4016 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4011 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4017 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4012 EXPECT_FALSE(controller.CanGoBack()); 4018 EXPECT_FALSE(controller.CanGoBack());
4013 EXPECT_FALSE(controller.CanGoForward()); 4019 EXPECT_FALSE(controller.CanGoForward());
4014 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 4020 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
4015 } 4021 }
4016 4022
4017 } // namespace content 4023 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698