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

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

Issue 1082083002: Fix ClassifyNavigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better version of the test Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 1751
1752 EXPECT_EQ(controller.GetEntryCount(), 2); 1752 EXPECT_EQ(controller.GetEntryCount(), 2);
1753 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1753 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1754 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1754 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1755 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1755 EXPECT_TRUE(controller.GetLastCommittedEntry());
1756 EXPECT_FALSE(controller.GetPendingEntry()); 1756 EXPECT_FALSE(controller.GetPendingEntry());
1757 EXPECT_TRUE(controller.CanGoBack()); 1757 EXPECT_TRUE(controller.CanGoBack());
1758 EXPECT_FALSE(controller.CanGoForward()); 1758 EXPECT_FALSE(controller.CanGoForward());
1759 } 1759 }
1760 1760
1761 // Two consequent navigation for the same URL entered in should be considered 1761 // Two consecutive navigations for the same URL entered in should be considered
1762 // as SAME_PAGE navigation even when we are redirected to some other page. 1762 // as SAME_PAGE navigation even when we are redirected to some other page.
1763 TEST_F(NavigationControllerTest, Redirect) { 1763 TEST_F(NavigationControllerTest, Redirect) {
1764 NavigationControllerImpl& controller = controller_impl(); 1764 NavigationControllerImpl& controller = controller_impl();
1765 TestNotificationTracker notifications; 1765 TestNotificationTracker notifications;
1766 RegisterForAllNavNotifications(&notifications, &controller); 1766 RegisterForAllNavNotifications(&notifications, &controller);
1767 1767
1768 const GURL url1("http://foo1"); 1768 const GURL url1("http://foo1");
1769 const GURL url2("http://foo2"); // Redirection target 1769 const GURL url2("http://foo2"); // Redirection target
1770 1770
1771 // First request 1771 // First request
1772 controller.LoadURL( 1772 controller.LoadURL(
1773 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1773 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1774 1774
1775 EXPECT_EQ(0U, notifications.size()); 1775 EXPECT_EQ(0U, notifications.size());
1776 main_test_rfh()->SendNavigate(0, url2); 1776
1777 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1778 params.page_id = 0;
1779 params.url = url2;
1780 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1781 params.redirects.push_back(GURL("http://foo1"));
1782 params.redirects.push_back(GURL("http://foo2"));
1783 params.should_update_history = false;
1784 params.gesture = NavigationGestureAuto;
1785 params.is_post = false;
1786 params.page_state = PageState::CreateFromURL(url2);
1787
1788 LoadCommittedDetails details;
1789
1790 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1791 &details));
1777 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1792 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1778 navigation_entry_committed_counter_ = 0; 1793 navigation_entry_committed_counter_ = 0;
1779 1794
1780 // Second request 1795 // Second request
1781 controller.LoadURL( 1796 controller.LoadURL(
1782 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1797 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1783 1798
1784 EXPECT_TRUE(controller.GetPendingEntry()); 1799 EXPECT_TRUE(controller.GetPendingEntry());
1785 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1800 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1786 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1801 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1787 1802
1788 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1789 params.page_id = 0; 1803 params.page_id = 0;
1790 params.url = url2; 1804 params.url = url2;
1791 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1805 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1792 params.redirects.push_back(GURL("http://foo1")); 1806 params.redirects.push_back(GURL("http://foo1"));
Charlie Reis 2015/04/15 17:43:08 This whole block should get deleted, right? It's
Avi (use Gerrit) 2015/04/15 19:14:16 I'm not sure what you mean by the push_back lines
Charlie Reis 2015/04/15 19:57:36 You've already done all of these assignments on li
Avi (use Gerrit) 2015/04/15 20:19:26 D'oh. Yeah.
1793 params.redirects.push_back(GURL("http://foo2")); 1807 params.redirects.push_back(GURL("http://foo2"));
1794 params.should_update_history = false; 1808 params.should_update_history = false;
1795 params.gesture = NavigationGestureAuto; 1809 params.gesture = NavigationGestureAuto;
1796 params.is_post = false; 1810 params.is_post = false;
1797 params.page_state = PageState::CreateFromURL(url2); 1811 params.page_state = PageState::CreateFromURL(url2);
1798 1812
1799 LoadCommittedDetails details;
1800
1801 EXPECT_EQ(0U, notifications.size()); 1813 EXPECT_EQ(0U, notifications.size());
1802 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1814 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1803 &details)); 1815 &details));
1804 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1816 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1805 navigation_entry_committed_counter_ = 0; 1817 navigation_entry_committed_counter_ = 0;
1806 1818
1807 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1819 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1808 EXPECT_EQ(controller.GetEntryCount(), 1); 1820 EXPECT_EQ(controller.GetEntryCount(), 1);
1809 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1821 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1810 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1822 EXPECT_TRUE(controller.GetLastCommittedEntry());
(...skipping 15 matching lines...) Expand all
1826 1838
1827 const GURL url1("http://foo1"); 1839 const GURL url1("http://foo1");
1828 const GURL url2("http://foo2"); // Redirection target 1840 const GURL url2("http://foo2"); // Redirection target
1829 1841
1830 // First request as POST 1842 // First request as POST
1831 controller.LoadURL( 1843 controller.LoadURL(
1832 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1844 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1833 controller.GetVisibleEntry()->SetHasPostData(true); 1845 controller.GetVisibleEntry()->SetHasPostData(true);
1834 1846
1835 EXPECT_EQ(0U, notifications.size()); 1847 EXPECT_EQ(0U, notifications.size());
1836 main_test_rfh()->SendNavigate(0, url2); 1848
1849 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1850 params.page_id = 0;
1851 params.url = url2;
1852 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1853 params.redirects.push_back(GURL("http://foo1"));
1854 params.redirects.push_back(GURL("http://foo2"));
1855 params.should_update_history = false;
1856 params.gesture = NavigationGestureAuto;
1857 params.is_post = true;
1858 params.page_state = PageState::CreateFromURL(url2);
1859
1860 LoadCommittedDetails details;
1861
1862 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1863 &details));
1837 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1864 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1838 navigation_entry_committed_counter_ = 0; 1865 navigation_entry_committed_counter_ = 0;
1839 1866
1840 // Second request 1867 // Second request
1841 controller.LoadURL( 1868 controller.LoadURL(
1842 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1869 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1843 1870
1844 EXPECT_TRUE(controller.GetPendingEntry()); 1871 EXPECT_TRUE(controller.GetPendingEntry());
1845 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1872 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1846 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1873 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1847 1874
1848 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1849 params.page_id = 0; 1875 params.page_id = 0;
Charlie Reis 2015/04/15 17:43:09 Same.
1850 params.url = url2; 1876 params.url = url2;
1851 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1877 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1852 params.redirects.push_back(GURL("http://foo1")); 1878 params.redirects.push_back(GURL("http://foo1"));
1853 params.redirects.push_back(GURL("http://foo2")); 1879 params.redirects.push_back(GURL("http://foo2"));
1854 params.should_update_history = false; 1880 params.should_update_history = false;
1855 params.gesture = NavigationGestureAuto; 1881 params.gesture = NavigationGestureAuto;
1856 params.is_post = false; 1882 params.is_post = false;
1857 params.page_state = PageState::CreateFromURL(url2); 1883 params.page_state = PageState::CreateFromURL(url2);
1858 1884
1859 LoadCommittedDetails details;
1860
1861 EXPECT_EQ(0U, notifications.size()); 1885 EXPECT_EQ(0U, notifications.size());
1862 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1886 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1863 &details)); 1887 &details));
1864 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1888 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1865 navigation_entry_committed_counter_ = 0; 1889 navigation_entry_committed_counter_ = 0;
1866 1890
1867 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1891 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1868 EXPECT_EQ(controller.GetEntryCount(), 1); 1892 EXPECT_EQ(controller.GetEntryCount(), 1);
1869 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1893 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1870 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1894 EXPECT_TRUE(controller.GetLastCommittedEntry());
(...skipping 2722 matching lines...) Expand 10 before | Expand all | Expand 10 after
4593 { 4617 {
4594 LoadCommittedDetails details; 4618 LoadCommittedDetails details;
4595 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4619 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4596 EXPECT_EQ(PAGE_TYPE_ERROR, 4620 EXPECT_EQ(PAGE_TYPE_ERROR,
4597 controller_impl().GetLastCommittedEntry()->GetPageType()); 4621 controller_impl().GetLastCommittedEntry()->GetPageType());
4598 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4622 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4599 } 4623 }
4600 } 4624 }
4601 4625
4602 } // namespace content 4626 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698