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

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: Changing an approach a bit. 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 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 // Go back one. 1933 // Go back one.
1934 ViewHostMsg_FrameNavigate_Params back_params(params); 1934 ViewHostMsg_FrameNavigate_Params back_params(params);
1935 controller.GoBack(); 1935 controller.GoBack();
1936 back_params.url = url1; 1936 back_params.url = url1;
1937 back_params.page_id = 0; 1937 back_params.page_id = 0;
1938 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); 1938 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details));
1939 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1939 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1940 navigation_entry_committed_counter_ = 0; 1940 navigation_entry_committed_counter_ = 0;
1941 // is_in_page is false in that case but should be true. 1941 // is_in_page is false in that case but should be true.
1942 // See comment in AreURLsInPageNavigation() in navigation_controller.cc 1942 // See comment in AreURLsInPageNavigation() in navigation_controller.cc
1943 // EXPECT_TRUE(details.is_in_page); 1943 // EXPECT_TRUE(details.is_in_page);
Charlie Reis 2013/08/05 22:18:10 Can we fix this now?
1944 EXPECT_EQ(2, controller.GetEntryCount()); 1944 EXPECT_EQ(2, controller.GetEntryCount());
1945 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 1945 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
1946 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL()); 1946 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL());
1947 1947
1948 // Go forward 1948 // Go forward
1949 ViewHostMsg_FrameNavigate_Params forward_params(params); 1949 ViewHostMsg_FrameNavigate_Params forward_params(params);
1950 controller.GoForward(); 1950 controller.GoForward();
1951 forward_params.url = url2; 1951 forward_params.url = url2;
1952 forward_params.page_id = 1; 1952 forward_params.page_id = 1;
1953 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); 1953 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details));
1954 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1954 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1955 navigation_entry_committed_counter_ = 0; 1955 navigation_entry_committed_counter_ = 0;
1956 EXPECT_TRUE(details.is_in_page); 1956 EXPECT_TRUE(details.is_in_page);
1957 EXPECT_EQ(2, controller.GetEntryCount()); 1957 EXPECT_EQ(2, controller.GetEntryCount());
1958 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 1958 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
1959 EXPECT_EQ(forward_params.url, 1959 EXPECT_EQ(forward_params.url,
1960 controller.GetActiveEntry()->GetURL()); 1960 controller.GetActiveEntry()->GetURL());
1961 1961
1962 // Go back and forward again. This time renderer claims it's in page
1963 // navigation.
1964 ViewHostMsg_FrameNavigate_Params second_back_params(back_params);
1965 second_back_params.was_within_same_page = true;
1966 controller.GoBack();
1967 EXPECT_TRUE(controller.RendererDidNavigate(second_back_params, &details));
1968 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1969 navigation_entry_committed_counter_ = 0;
1970 EXPECT_TRUE(details.is_in_page);
1971 EXPECT_EQ(2, controller.GetEntryCount());
1972 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
1973 EXPECT_EQ(second_back_params.url, controller.GetActiveEntry()->GetURL());
1974
1975 ViewHostMsg_FrameNavigate_Params second_forward_params(forward_params);
1976 second_forward_params.was_within_same_page = true;
1977 controller.GoForward();
1978 EXPECT_TRUE(controller.RendererDidNavigate(second_forward_params, &details));
1979 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1980 navigation_entry_committed_counter_ = 0;
1981 EXPECT_TRUE(details.is_in_page);
1982 EXPECT_EQ(2, controller.GetEntryCount());
1983 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
1984 EXPECT_EQ(second_forward_params.url,
1985 controller.GetActiveEntry()->GetURL());
1986
1962 // Now go back and forward again. This is to work around a bug where we would 1987 // Now go back and forward again. This is to work around a bug where we would
1963 // compare the incoming URL with the last committed entry rather than the 1988 // compare the incoming URL with the last committed entry rather than the
1964 // one identified by an existing page ID. This would result in the second URL 1989 // one identified by an existing page ID. This would result in the second URL
1965 // losing the reference fragment when you navigate away from it and then back. 1990 // losing the reference fragment when you navigate away from it and then back.
1966 controller.GoBack(); 1991 controller.GoBack();
1967 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); 1992 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details));
1968 controller.GoForward(); 1993 controller.GoForward();
1969 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); 1994 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details));
1970 EXPECT_EQ(forward_params.url, 1995 EXPECT_EQ(forward_params.url,
1971 controller.GetActiveEntry()->GetURL()); 1996 controller.GetActiveEntry()->GetURL());
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 2774
2750 // Navigate to URL with refs. 2775 // Navigate to URL with refs.
2751 test_rvh()->SendNavigate(1, url_with_ref); 2776 test_rvh()->SendNavigate(1, url_with_ref);
2752 2777
2753 // Reloading the page is not an in-page navigation. 2778 // Reloading the page is not an in-page navigation.
2754 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref)); 2779 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref));
2755 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); 2780 EXPECT_FALSE(controller.IsURLInPageNavigation(url));
2756 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); 2781 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url));
2757 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); 2782 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
2758 EXPECT_TRUE(controller.IsURLInPageNavigation( 2783 EXPECT_TRUE(controller.IsURLInPageNavigation(
2759 other_url_with_ref)); 2784 other_url_with_ref));
Charlie Reis 2013/08/05 22:18:10 Maybe we can add a check and comment below saying
2760 } 2785 }
2761 2786
2762 // Some pages can have subframes with the same base URL (minus the reference) as 2787 // 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 2788 // 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 2789 // these subframe navigations to affect the toplevel document. They should
2765 // instead be ignored. http://crbug.com/5585 2790 // instead be ignored. http://crbug.com/5585
2766 TEST_F(NavigationControllerTest, SameSubframe) { 2791 TEST_F(NavigationControllerTest, SameSubframe) {
2767 NavigationControllerImpl& controller = controller_impl(); 2792 NavigationControllerImpl& controller = controller_impl();
2768 // Navigate the main frame. 2793 // Navigate the main frame.
2769 const GURL url("http://www.google.com/"); 2794 const GURL url("http://www.google.com/");
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3896 PAGE_TRANSITION_LINK); 3921 PAGE_TRANSITION_LINK);
3897 session_helper_.AssertNavigationEquals(nav, 3922 session_helper_.AssertNavigationEquals(nav,
3898 windows_[0]->tabs[0]->navigations[0]); 3923 windows_[0]->tabs[0]->navigations[0]);
3899 nav.set_url(url2); 3924 nav.set_url(url2);
3900 session_helper_.AssertNavigationEquals(nav, 3925 session_helper_.AssertNavigationEquals(nav,
3901 windows_[0]->tabs[0]->navigations[1]); 3926 windows_[0]->tabs[0]->navigations[1]);
3902 } 3927 }
3903 */ 3928 */
3904 3929
3905 } // namespace content 3930 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698