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

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: Readability. Bringing back removed TC. 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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref)); 2747 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref));
2749 2748
2750 // Navigate to URL with refs. 2749 // Navigate to URL with refs.
2751 test_rvh()->SendNavigate(1, url_with_ref); 2750 test_rvh()->SendNavigate(1, url_with_ref);
2752 2751
2753 // Reloading the page is not an in-page navigation. 2752 // Reloading the page is not an in-page navigation.
2754 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref)); 2753 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref));
2755 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); 2754 EXPECT_FALSE(controller.IsURLInPageNavigation(url));
2756 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); 2755 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url));
2757 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); 2756 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
2758 EXPECT_TRUE(controller.IsURLInPageNavigation( 2757 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref));
2759 other_url_with_ref)); 2758
2759 // Going to the same url again will be considered in-page
2760 // if the renderer says it is even if the navigation type isn't IN_PAGE.
2761 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true,
2762 NAVIGATION_TYPE_UNKNOWN));
2763
2764 // Going back to the non ref url will be considered in-page if the navigation
2765 // type is IN_PAGE.
2766 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true,
2767 NAVIGATION_TYPE_IN_PAGE));
2760 } 2768 }
2761 2769
2762 // Some pages can have subframes with the same base URL (minus the reference) as 2770 // 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 2771 // 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 2772 // these subframe navigations to affect the toplevel document. They should
2765 // instead be ignored. http://crbug.com/5585 2773 // instead be ignored. http://crbug.com/5585
2766 TEST_F(NavigationControllerTest, SameSubframe) { 2774 TEST_F(NavigationControllerTest, SameSubframe) {
2767 NavigationControllerImpl& controller = controller_impl(); 2775 NavigationControllerImpl& controller = controller_impl();
2768 // Navigate the main frame. 2776 // Navigate the main frame.
2769 const GURL url("http://www.google.com/"); 2777 const GURL url("http://www.google.com/");
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3896 PAGE_TRANSITION_LINK); 3904 PAGE_TRANSITION_LINK);
3897 session_helper_.AssertNavigationEquals(nav, 3905 session_helper_.AssertNavigationEquals(nav,
3898 windows_[0]->tabs[0]->navigations[0]); 3906 windows_[0]->tabs[0]->navigations[0]);
3899 nav.set_url(url2); 3907 nav.set_url(url2);
3900 session_helper_.AssertNavigationEquals(nav, 3908 session_helper_.AssertNavigationEquals(nav,
3901 windows_[0]->tabs[0]->navigations[1]); 3909 windows_[0]->tabs[0]->navigations[1]);
3902 } 3910 }
3903 */ 3911 */
3904 3912
3905 } // namespace content 3913 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698