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

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: fix 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
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
1777 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1778 navigation_entry_committed_counter_ = 0;
1779
1780 // Second request
1781 controller.LoadURL(
1782 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1783
1784 EXPECT_TRUE(controller.GetPendingEntry());
1785 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1786 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1787 1776
1788 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1777 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1789 params.page_id = 0; 1778 params.page_id = 0;
1790 params.url = url2; 1779 params.url = url2;
1791 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1780 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1792 params.redirects.push_back(GURL("http://foo1")); 1781 params.redirects.push_back(GURL("http://foo1"));
1793 params.redirects.push_back(GURL("http://foo2")); 1782 params.redirects.push_back(GURL("http://foo2"));
1794 params.should_update_history = false; 1783 params.should_update_history = false;
1795 params.gesture = NavigationGestureAuto; 1784 params.gesture = NavigationGestureAuto;
1796 params.is_post = false; 1785 params.is_post = false;
1797 params.page_state = PageState::CreateFromURL(url2); 1786 params.page_state = PageState::CreateFromURL(url2);
1798 1787
1799 LoadCommittedDetails details; 1788 LoadCommittedDetails details;
1800 1789
1790 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1791 &details));
1792 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1793 navigation_entry_committed_counter_ = 0;
1794
1795 // Second request.
1796 controller.LoadURL(
1797 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1798
1799 EXPECT_TRUE(controller.GetPendingEntry());
1800 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1801 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1801 EXPECT_EQ(0U, notifications.size()); 1802 EXPECT_EQ(0U, notifications.size());
1802 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1803 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1803 &details)); 1804 &details));
1804 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1805 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1805 navigation_entry_committed_counter_ = 0; 1806 navigation_entry_committed_counter_ = 0;
1806 1807
1807 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1808 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1808 EXPECT_EQ(controller.GetEntryCount(), 1); 1809 EXPECT_EQ(controller.GetEntryCount(), 1);
1809 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1810 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1810 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1811 EXPECT_TRUE(controller.GetLastCommittedEntry());
1811 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1812 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1812 EXPECT_FALSE(controller.GetPendingEntry()); 1813 EXPECT_FALSE(controller.GetPendingEntry());
1813 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 1814 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
1814 1815
1815 EXPECT_FALSE(controller.CanGoBack()); 1816 EXPECT_FALSE(controller.CanGoBack());
1816 EXPECT_FALSE(controller.CanGoForward()); 1817 EXPECT_FALSE(controller.CanGoForward());
1817 } 1818 }
1818 1819
1819 // Similar to Redirect above, but the first URL is requested by POST, 1820 // Similar to Redirect above, but the first URL is requested by POST,
1820 // the second URL is requested by GET. NavigationEntry::has_post_data_ 1821 // the second URL is requested by GET. NavigationEntry::has_post_data_
1821 // must be cleared. http://crbug.com/21245 1822 // must be cleared. http://crbug.com/21245
1822 TEST_F(NavigationControllerTest, PostThenRedirect) { 1823 TEST_F(NavigationControllerTest, PostThenRedirect) {
1823 NavigationControllerImpl& controller = controller_impl(); 1824 NavigationControllerImpl& controller = controller_impl();
1824 TestNotificationTracker notifications; 1825 TestNotificationTracker notifications;
1825 RegisterForAllNavNotifications(&notifications, &controller); 1826 RegisterForAllNavNotifications(&notifications, &controller);
1826 1827
1827 const GURL url1("http://foo1"); 1828 const GURL url1("http://foo1");
1828 const GURL url2("http://foo2"); // Redirection target 1829 const GURL url2("http://foo2"); // Redirection target
1829 1830
1830 // First request as POST 1831 // First request as POST.
1831 controller.LoadURL( 1832 controller.LoadURL(
1832 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1833 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1833 controller.GetVisibleEntry()->SetHasPostData(true); 1834 controller.GetVisibleEntry()->SetHasPostData(true);
1834 1835
1835 EXPECT_EQ(0U, notifications.size()); 1836 EXPECT_EQ(0U, notifications.size());
1836 main_test_rfh()->SendNavigate(0, url2);
1837 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1838 navigation_entry_committed_counter_ = 0;
1839
1840 // Second request
1841 controller.LoadURL(
1842 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1843
1844 EXPECT_TRUE(controller.GetPendingEntry());
1845 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1846 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1847 1837
1848 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1838 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1849 params.page_id = 0; 1839 params.page_id = 0;
1850 params.url = url2; 1840 params.url = url2;
1851 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1841 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1852 params.redirects.push_back(GURL("http://foo1")); 1842 params.redirects.push_back(GURL("http://foo1"));
1853 params.redirects.push_back(GURL("http://foo2")); 1843 params.redirects.push_back(GURL("http://foo2"));
1854 params.should_update_history = false; 1844 params.should_update_history = false;
1855 params.gesture = NavigationGestureAuto; 1845 params.gesture = NavigationGestureAuto;
1856 params.is_post = false; 1846 params.is_post = true;
1857 params.page_state = PageState::CreateFromURL(url2); 1847 params.page_state = PageState::CreateFromURL(url2);
1858 1848
1859 LoadCommittedDetails details; 1849 LoadCommittedDetails details;
1860 1850
1851 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1852 &details));
1853 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1854 navigation_entry_committed_counter_ = 0;
1855
1856 // Second request.
1857 controller.LoadURL(
1858 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1859
1860 EXPECT_TRUE(controller.GetPendingEntry());
1861 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1862 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1863
1864 params.is_post = false;
1865
1861 EXPECT_EQ(0U, notifications.size()); 1866 EXPECT_EQ(0U, notifications.size());
1862 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1867 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1863 &details)); 1868 &details));
1864 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1869 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1865 navigation_entry_committed_counter_ = 0; 1870 navigation_entry_committed_counter_ = 0;
1866 1871
1867 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1872 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1868 EXPECT_EQ(controller.GetEntryCount(), 1); 1873 EXPECT_EQ(controller.GetEntryCount(), 1);
1869 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1874 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1870 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1875 EXPECT_TRUE(controller.GetLastCommittedEntry());
(...skipping 2722 matching lines...) Expand 10 before | Expand all | Expand 10 after
4593 { 4598 {
4594 LoadCommittedDetails details; 4599 LoadCommittedDetails details;
4595 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4600 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4596 EXPECT_EQ(PAGE_TYPE_ERROR, 4601 EXPECT_EQ(PAGE_TYPE_ERROR,
4597 controller_impl().GetLastCommittedEntry()->GetPageType()); 4602 controller_impl().GetLastCommittedEntry()->GetPageType());
4598 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4603 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4599 } 4604 }
4600 } 4605 }
4601 4606
4602 } // namespace content 4607 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698