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

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

Issue 21544005: Take the navigation type into account when checking if the navigation is in page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More generic and brave fix Created 7 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 // Fragment navigation to a new page_id. 1914 // Fragment navigation to a new page_id.
1915 const GURL url2("http://foo#a"); 1915 const GURL url2("http://foo#a");
1916 ViewHostMsg_FrameNavigate_Params params; 1916 ViewHostMsg_FrameNavigate_Params params;
1917 params.page_id = 1; 1917 params.page_id = 1;
1918 params.url = url2; 1918 params.url = url2;
1919 params.transition = PAGE_TRANSITION_LINK; 1919 params.transition = PAGE_TRANSITION_LINK;
1920 params.should_update_history = false; 1920 params.should_update_history = false;
1921 params.gesture = NavigationGestureUser; 1921 params.gesture = NavigationGestureUser;
1922 params.is_post = false; 1922 params.is_post = false;
1923 params.page_state = PageState::CreateFromURL(url2); 1923 params.page_state = PageState::CreateFromURL(url2);
1924 params.was_within_same_page = true;
1924 1925
1925 // This should generate a new entry. 1926 // This should generate a new entry.
1926 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1927 EXPECT_TRUE(controller.RendererDidNavigate(params, &details));
1927 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1928 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1928 navigation_entry_committed_counter_ = 0; 1929 navigation_entry_committed_counter_ = 0;
1929 EXPECT_TRUE(details.is_in_page); 1930 EXPECT_TRUE(details.is_in_page);
1930 EXPECT_FALSE(details.did_replace_entry); 1931 EXPECT_FALSE(details.did_replace_entry);
1931 EXPECT_EQ(2, controller.GetEntryCount()); 1932 EXPECT_EQ(2, controller.GetEntryCount());
1932 1933
1933 // Go back one. 1934 // Go back one.
1934 ViewHostMsg_FrameNavigate_Params back_params(params); 1935 ViewHostMsg_FrameNavigate_Params back_params(params);
1935 controller.GoBack(); 1936 controller.GoBack();
1936 back_params.url = url1; 1937 back_params.url = url1;
1937 back_params.page_id = 0; 1938 back_params.page_id = 0;
1938 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); 1939 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details));
1939 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1940 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1940 navigation_entry_committed_counter_ = 0; 1941 navigation_entry_committed_counter_ = 0;
1941 // is_in_page is false in that case but should be true. 1942 EXPECT_TRUE(details.is_in_page);
1942 // See comment in AreURLsInPageNavigation() in navigation_controller.cc
1943 // EXPECT_TRUE(details.is_in_page);
1944 EXPECT_EQ(2, controller.GetEntryCount()); 1943 EXPECT_EQ(2, controller.GetEntryCount());
1945 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 1944 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
1946 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL()); 1945 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL());
1947 1946
1948 // Go forward 1947 // Go forward
1949 ViewHostMsg_FrameNavigate_Params forward_params(params); 1948 ViewHostMsg_FrameNavigate_Params forward_params(params);
1950 controller.GoForward(); 1949 controller.GoForward();
1951 forward_params.url = url2; 1950 forward_params.url = url2;
1952 forward_params.page_id = 1; 1951 forward_params.page_id = 1;
1953 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); 1952 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details));
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 2733
2735 // Tests that IsInPageNavigation returns appropriate results. Prevents 2734 // Tests that IsInPageNavigation returns appropriate results. Prevents
2736 // regression for bug 1126349. 2735 // regression for bug 1126349.
2737 TEST_F(NavigationControllerTest, IsInPageNavigation) { 2736 TEST_F(NavigationControllerTest, IsInPageNavigation) {
2738 NavigationControllerImpl& controller = controller_impl(); 2737 NavigationControllerImpl& controller = controller_impl();
2739 // Navigate to URL with no refs. 2738 // Navigate to URL with no refs.
2740 const GURL url("http://www.google.com/home.html"); 2739 const GURL url("http://www.google.com/home.html");
2741 test_rvh()->SendNavigate(0, url); 2740 test_rvh()->SendNavigate(0, url);
2742 2741
2743 // Reloading the page is not an in-page navigation. 2742 // Reloading the page is not an in-page navigation.
2744 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); 2743 EXPECT_FALSE(controller.IsURLInPageNavigation(url,
2744 content::NAVIGATION_TYPE_SAME_PAGE));
Charlie Reis 2013/08/06 18:48:08 Don't need to pass the type in any of these but th
2745 const GURL other_url("http://www.google.com/add.html"); 2745 const GURL other_url("http://www.google.com/add.html");
2746 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); 2746 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url,
2747 content::NAVIGATION_TYPE_NEW_PAGE));
2747 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); 2748 const GURL url_with_ref("http://www.google.com/home.html#my_ref");
2748 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref)); 2749 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref,
2750 content::NAVIGATION_TYPE_IN_PAGE));
2749 2751
2750 // Navigate to URL with refs. 2752 // Navigate to URL with refs.
2751 test_rvh()->SendNavigate(1, url_with_ref); 2753 test_rvh()->SendNavigate(1, url_with_ref);
2752 2754
2753 // Reloading the page is not an in-page navigation. 2755 // Reloading the page is not an in-page navigation.
2754 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref)); 2756 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref,
2755 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); 2757 content::NAVIGATION_TYPE_SAME_PAGE));
2756 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); 2758 EXPECT_FALSE(controller.IsURLInPageNavigation(url,
2759 content::NAVIGATION_TYPE_NEW_PAGE));
2760 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url,
2761 content::NAVIGATION_TYPE_NEW_PAGE));
2757 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); 2762 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
2758 EXPECT_TRUE(controller.IsURLInPageNavigation( 2763 EXPECT_TRUE(controller.IsURLInPageNavigation(
2759 other_url_with_ref)); 2764 other_url_with_ref, content::NAVIGATION_TYPE_IN_PAGE));
2765
2766 // Going to the same url again will also be considered in-page
2767 // if the renderer says it is even the navigation type isn't IN_PAGE.
Charlie Reis 2013/08/06 18:48:08 nit: even if
2768 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true,
2769 content::NAVIGATION_TYPE_UNKNOWN));
Charlie Reis 2013/08/06 18:48:08 This case is good to test, but can you also add th
pstanek 2013/08/07 11:39:35 Ok. But I'll modify it a bit since it's the naviga
2760 } 2770 }
2761 2771
2762 // Some pages can have subframes with the same base URL (minus the reference) as 2772 // Some pages can have subframes with the same base URL (minus the reference) as
2763 // the main page. Even though this is hard, it can happen, and we don't want 2773 // the main page. Even though this is hard, it can happen, and we don't want
2764 // these subframe navigations to affect the toplevel document. They should 2774 // these subframe navigations to affect the toplevel document. They should
2765 // instead be ignored. http://crbug.com/5585 2775 // instead be ignored. http://crbug.com/5585
2766 TEST_F(NavigationControllerTest, SameSubframe) { 2776 TEST_F(NavigationControllerTest, SameSubframe) {
2767 NavigationControllerImpl& controller = controller_impl(); 2777 NavigationControllerImpl& controller = controller_impl();
2768 // Navigate the main frame. 2778 // Navigate the main frame.
2769 const GURL url("http://www.google.com/"); 2779 const GURL url("http://www.google.com/");
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3896 PAGE_TRANSITION_LINK); 3906 PAGE_TRANSITION_LINK);
3897 session_helper_.AssertNavigationEquals(nav, 3907 session_helper_.AssertNavigationEquals(nav,
3898 windows_[0]->tabs[0]->navigations[0]); 3908 windows_[0]->tabs[0]->navigations[0]);
3899 nav.set_url(url2); 3909 nav.set_url(url2);
3900 session_helper_.AssertNavigationEquals(nav, 3910 session_helper_.AssertNavigationEquals(nav,
3901 windows_[0]->tabs[0]->navigations[1]); 3911 windows_[0]->tabs[0]->navigations[1]);
3902 } 3912 }
3903 */ 3913 */
3904 3914
3905 } // namespace content 3915 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698