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

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

Issue 1777903003: Ensure the NavigationHandle's nav entry ID is updated during transfers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 4 years, 9 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 "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "content/browser/frame_host/cross_site_transferring_request.h" 20 #include "content/browser/frame_host/cross_site_transferring_request.h"
21 #include "content/browser/frame_host/frame_navigation_entry.h" 21 #include "content/browser/frame_host/frame_navigation_entry.h"
22 #include "content/browser/frame_host/navigation_entry_impl.h" 22 #include "content/browser/frame_host/navigation_entry_impl.h"
23 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 23 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
24 #include "content/browser/frame_host/navigation_handle_impl.h"
24 #include "content/browser/frame_host/navigation_request.h" 25 #include "content/browser/frame_host/navigation_request.h"
25 #include "content/browser/frame_host/navigator.h" 26 #include "content/browser/frame_host/navigator.h"
26 #include "content/browser/frame_host/navigator_impl.h" 27 #include "content/browser/frame_host/navigator_impl.h"
27 #include "content/browser/site_instance_impl.h" 28 #include "content/browser/site_instance_impl.h"
28 #include "content/browser/web_contents/web_contents_impl.h" 29 #include "content/browser/web_contents/web_contents_impl.h"
29 #include "content/common/frame_messages.h" 30 #include "content/common/frame_messages.h"
30 #include "content/common/site_isolation_policy.h" 31 #include "content/common/site_isolation_policy.h"
31 #include "content/common/ssl_status_serialization.h" 32 #include "content/common/ssl_status_serialization.h"
32 #include "content/common/view_messages.h" 33 #include "content/common/view_messages.h"
33 #include "content/public/browser/navigation_details.h" 34 #include "content/public/browser/navigation_details.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 289 }
289 290
290 private: 291 private:
291 // The number of times NavigationStateChanged has been called. 292 // The number of times NavigationStateChanged has been called.
292 int navigation_state_change_count_; 293 int navigation_state_change_count_;
293 294
294 // The number of times ShowRepostFormWarningDialog() was called. 295 // The number of times ShowRepostFormWarningDialog() was called.
295 int repost_form_warning_count_; 296 int repost_form_warning_count_;
296 }; 297 };
297 298
299 // Observer that records the LoadCommittedDetails from the most recent commit.
300 class LoadCommittedDetailsObserver : public WebContentsObserver {
301 public:
302 // Observes navigation for the specified |web_contents|.
303 explicit LoadCommittedDetailsObserver(WebContents* web_contents)
304 : WebContentsObserver(web_contents) {}
305
306 const LoadCommittedDetails& details() { return details_; }
307
308 private:
309 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
310 const LoadCommittedDetails& details,
311 const FrameNavigateParams& params) override {
312 details_ = details;
313 }
314
315 LoadCommittedDetails details_;
316 };
317
298 // ----------------------------------------------------------------------------- 318 // -----------------------------------------------------------------------------
299 319
300 TEST_F(NavigationControllerTest, Defaults) { 320 TEST_F(NavigationControllerTest, Defaults) {
301 NavigationControllerImpl& controller = controller_impl(); 321 NavigationControllerImpl& controller = controller_impl();
302 322
303 EXPECT_FALSE(controller.GetPendingEntry()); 323 EXPECT_FALSE(controller.GetPendingEntry());
304 EXPECT_FALSE(controller.GetVisibleEntry()); 324 EXPECT_FALSE(controller.GetVisibleEntry());
305 EXPECT_FALSE(controller.GetLastCommittedEntry()); 325 EXPECT_FALSE(controller.GetLastCommittedEntry());
306 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 326 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
307 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); 327 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1);
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 params.did_create_new_entry = true; 1877 params.did_create_new_entry = true;
1858 params.url = url2; 1878 params.url = url2;
1859 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1879 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1860 params.redirects.push_back(GURL("http://foo1")); 1880 params.redirects.push_back(GURL("http://foo1"));
1861 params.redirects.push_back(GURL("http://foo2")); 1881 params.redirects.push_back(GURL("http://foo2"));
1862 params.should_update_history = false; 1882 params.should_update_history = false;
1863 params.gesture = NavigationGestureAuto; 1883 params.gesture = NavigationGestureAuto;
1864 params.is_post = false; 1884 params.is_post = false;
1865 params.page_state = PageState::CreateFromURL(url2); 1885 params.page_state = PageState::CreateFromURL(url2);
1866 1886
1867 LoadCommittedDetails details; 1887 main_test_rfh()->PrepareForCommit();
1868 1888 main_test_rfh()->SendNavigateWithParams(&params);
1869 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1870 &details));
1871 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1889 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1872 navigation_entry_committed_counter_ = 0; 1890 navigation_entry_committed_counter_ = 0;
1873 1891
1874 // Second request. 1892 // Second request.
1875 controller.LoadURL( 1893 controller.LoadURL(
1876 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1894 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1877 entry_id = controller.GetPendingEntry()->GetUniqueID(); 1895 entry_id = controller.GetPendingEntry()->GetUniqueID();
1878 1896
1879 EXPECT_TRUE(controller.GetPendingEntry()); 1897 EXPECT_TRUE(controller.GetPendingEntry());
1880 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1898 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1881 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1899 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1882 1900
1883 params.nav_entry_id = entry_id; 1901 params.nav_entry_id = entry_id;
1884 params.did_create_new_entry = false; 1902 params.did_create_new_entry = false;
1885 1903
1886 EXPECT_EQ(0U, notifications.size()); 1904 EXPECT_EQ(0U, notifications.size());
1887 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1905 LoadCommittedDetailsObserver observer(contents());
1888 &details)); 1906 main_test_rfh()->PrepareForCommit();
1907 main_test_rfh()->SendNavigateWithParams(&params);
1889 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1908 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1890 navigation_entry_committed_counter_ = 0; 1909 navigation_entry_committed_counter_ = 0;
1891 1910
1892 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1911 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type);
1893 EXPECT_EQ(controller.GetEntryCount(), 1); 1912 EXPECT_EQ(controller.GetEntryCount(), 1);
1894 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1913 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1895 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1914 EXPECT_TRUE(controller.GetLastCommittedEntry());
1896 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1915 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1897 EXPECT_FALSE(controller.GetPendingEntry()); 1916 EXPECT_FALSE(controller.GetPendingEntry());
1898 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 1917 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
1899 1918
1900 EXPECT_FALSE(controller.CanGoBack()); 1919 EXPECT_FALSE(controller.CanGoBack());
1901 EXPECT_FALSE(controller.CanGoForward()); 1920 EXPECT_FALSE(controller.CanGoForward());
1902 } 1921 }
(...skipping 23 matching lines...) Expand all
1926 params.did_create_new_entry = true; 1945 params.did_create_new_entry = true;
1927 params.url = url2; 1946 params.url = url2;
1928 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1947 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1929 params.redirects.push_back(GURL("http://foo1")); 1948 params.redirects.push_back(GURL("http://foo1"));
1930 params.redirects.push_back(GURL("http://foo2")); 1949 params.redirects.push_back(GURL("http://foo2"));
1931 params.should_update_history = false; 1950 params.should_update_history = false;
1932 params.gesture = NavigationGestureAuto; 1951 params.gesture = NavigationGestureAuto;
1933 params.is_post = true; 1952 params.is_post = true;
1934 params.page_state = PageState::CreateFromURL(url2); 1953 params.page_state = PageState::CreateFromURL(url2);
1935 1954
1936 LoadCommittedDetails details; 1955 main_test_rfh()->PrepareForCommit();
1937 1956 main_test_rfh()->SendNavigateWithParams(&params);
1938 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1939 &details));
1940 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1957 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1941 navigation_entry_committed_counter_ = 0; 1958 navigation_entry_committed_counter_ = 0;
1942 1959
1943 // Second request. 1960 // Second request.
1944 controller.LoadURL( 1961 controller.LoadURL(
1945 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1962 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1946 entry_id = controller.GetPendingEntry()->GetUniqueID(); 1963 entry_id = controller.GetPendingEntry()->GetUniqueID();
1947 1964
1948 EXPECT_TRUE(controller.GetPendingEntry()); 1965 EXPECT_TRUE(controller.GetPendingEntry());
1949 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1966 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1950 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1967 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1951 1968
1952 params.nav_entry_id = entry_id; 1969 params.nav_entry_id = entry_id;
1953 params.did_create_new_entry = false; 1970 params.did_create_new_entry = false;
1954 params.is_post = false; 1971 params.is_post = false;
1955 1972
1956 EXPECT_EQ(0U, notifications.size()); 1973 EXPECT_EQ(0U, notifications.size());
1957 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1974 LoadCommittedDetailsObserver observer(contents());
1958 &details)); 1975 main_test_rfh()->PrepareForCommit();
1976 main_test_rfh()->SendNavigateWithParams(&params);
1959 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1977 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1960 navigation_entry_committed_counter_ = 0; 1978 navigation_entry_committed_counter_ = 0;
1961 1979
1962 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1980 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type);
1963 EXPECT_EQ(controller.GetEntryCount(), 1); 1981 EXPECT_EQ(controller.GetEntryCount(), 1);
1964 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1982 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1965 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1983 EXPECT_TRUE(controller.GetLastCommittedEntry());
1966 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1984 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1967 EXPECT_FALSE(controller.GetPendingEntry()); 1985 EXPECT_FALSE(controller.GetPendingEntry());
1968 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 1986 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
1969 EXPECT_FALSE(controller.GetVisibleEntry()->GetHasPostData()); 1987 EXPECT_FALSE(controller.GetVisibleEntry()->GetHasPostData());
1970 1988
1971 EXPECT_FALSE(controller.CanGoBack()); 1989 EXPECT_FALSE(controller.CanGoBack());
1972 EXPECT_FALSE(controller.CanGoForward()); 1990 EXPECT_FALSE(controller.CanGoForward());
(...skipping 23 matching lines...) Expand all
1996 params.did_create_new_entry = true; 2014 params.did_create_new_entry = true;
1997 params.url = url2; 2015 params.url = url2;
1998 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 2016 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1999 params.redirects.push_back(GURL("http://foo1")); 2017 params.redirects.push_back(GURL("http://foo1"));
2000 params.redirects.push_back(GURL("http://foo2")); 2018 params.redirects.push_back(GURL("http://foo2"));
2001 params.should_update_history = false; 2019 params.should_update_history = false;
2002 params.gesture = NavigationGestureAuto; 2020 params.gesture = NavigationGestureAuto;
2003 params.is_post = false; 2021 params.is_post = false;
2004 params.page_state = PageState::CreateFromURL(url2); 2022 params.page_state = PageState::CreateFromURL(url2);
2005 2023
2006 LoadCommittedDetails details; 2024 LoadCommittedDetailsObserver observer(contents());
2007 2025
2008 EXPECT_EQ(0U, notifications.size()); 2026 EXPECT_EQ(0U, notifications.size());
2009 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2027 main_test_rfh()->PrepareForCommit();
2010 &details)); 2028 main_test_rfh()->SendNavigateWithParams(&params);
2011 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2029 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2012 navigation_entry_committed_counter_ = 0; 2030 navigation_entry_committed_counter_ = 0;
2013 2031
2014 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); 2032 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.details().type);
2015 EXPECT_EQ(controller.GetEntryCount(), 1); 2033 EXPECT_EQ(controller.GetEntryCount(), 1);
2016 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 2034 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
2017 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2035 EXPECT_TRUE(controller.GetLastCommittedEntry());
2018 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2036 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2019 EXPECT_FALSE(controller.GetPendingEntry()); 2037 EXPECT_FALSE(controller.GetPendingEntry());
2020 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2038 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2021 2039
2022 EXPECT_FALSE(controller.CanGoBack()); 2040 EXPECT_FALSE(controller.CanGoBack());
2023 EXPECT_FALSE(controller.CanGoForward()); 2041 EXPECT_FALSE(controller.CanGoForward());
2024 } 2042 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 // ... and now the renderer sends a commit for the first navigation. 2079 // ... and now the renderer sends a commit for the first navigation.
2062 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2080 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2063 params.page_id = 0; 2081 params.page_id = 0;
2064 params.nav_entry_id = entry_id1; 2082 params.nav_entry_id = entry_id1;
2065 params.intended_as_new_entry = true; 2083 params.intended_as_new_entry = true;
2066 params.did_create_new_entry = false; 2084 params.did_create_new_entry = false;
2067 params.url = url1; 2085 params.url = url1;
2068 params.transition = ui::PAGE_TRANSITION_TYPED; 2086 params.transition = ui::PAGE_TRANSITION_TYPED;
2069 params.page_state = PageState::CreateFromURL(url1); 2087 params.page_state = PageState::CreateFromURL(url1);
2070 2088
2071 LoadCommittedDetails details; 2089 LoadCommittedDetailsObserver observer(contents());
2072 2090
2073 main_test_rfh()->PrepareForCommit(); 2091 main_test_rfh()->PrepareForCommit();
2074 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2092 main_test_rfh()->SendNavigateWithParams(&params);
2075 &details)); 2093 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.details().type);
2076 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type);
2077 } 2094 }
2078 2095
2079 // Tests navigation via link click within a subframe. A new navigation entry 2096 // Tests navigation via link click within a subframe. A new navigation entry
2080 // should be created. 2097 // should be created.
2081 TEST_F(NavigationControllerTest, NewSubframe) { 2098 TEST_F(NavigationControllerTest, NewSubframe) {
2082 NavigationControllerImpl& controller = controller_impl(); 2099 NavigationControllerImpl& controller = controller_impl();
2083 TestNotificationTracker notifications; 2100 TestNotificationTracker notifications;
2084 RegisterForAllNavNotifications(&notifications, &controller); 2101 RegisterForAllNavNotifications(&notifications, &controller);
2085 2102
2086 const GURL url1("http://foo1"); 2103 const GURL url1("http://foo1");
2087 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1); 2104 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1);
2088 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2105 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2089 navigation_entry_committed_counter_ = 0; 2106 navigation_entry_committed_counter_ = 0;
2090 2107
2091 // Prereq: add a subframe with an initial auto-subframe navigation. 2108 // Prereq: add a subframe with an initial auto-subframe navigation.
2092 main_test_rfh()->OnCreateChildFrame( 2109 main_test_rfh()->OnCreateChildFrame(
2093 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document, 2110 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document,
2094 std::string(), "uniqueName0", blink::WebSandboxFlags::None, 2111 std::string(), "uniqueName0", blink::WebSandboxFlags::None,
2095 blink::WebFrameOwnerProperties()); 2112 blink::WebFrameOwnerProperties());
2096 RenderFrameHostImpl* subframe = 2113 TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>(
2097 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); 2114 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host());
2098 const GURL subframe_url("http://foo1/subframe"); 2115 const GURL subframe_url("http://foo1/subframe");
2099 { 2116 {
2100 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2117 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2101 params.page_id = 1; 2118 params.page_id = 1;
2102 params.nav_entry_id = 0; 2119 params.nav_entry_id = 0;
2103 params.did_create_new_entry = false; 2120 params.did_create_new_entry = false;
2104 params.url = subframe_url; 2121 params.url = subframe_url;
2105 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2122 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2106 params.should_update_history = false; 2123 params.should_update_history = false;
2107 params.gesture = NavigationGestureUser; 2124 params.gesture = NavigationGestureUser;
2108 params.is_post = false; 2125 params.is_post = false;
2109 params.page_state = PageState::CreateFromURL(subframe_url); 2126 params.page_state = PageState::CreateFromURL(subframe_url);
2110 2127
2111 // Navigating should do nothing. 2128 // Navigating should do nothing.
2112 LoadCommittedDetails details; 2129 subframe->PrepareForCommit();
2113 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); 2130 subframe->SendNavigateWithParams(&params);
2114 EXPECT_EQ(0U, notifications.size()); 2131 EXPECT_EQ(0U, notifications.size());
2115 } 2132 }
2116 2133
2117 // Now do a new navigation in the frame. 2134 // Now do a new navigation in the frame.
2118 const GURL url2("http://foo2"); 2135 const GURL url2("http://foo2");
2119 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2136 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2120 params.page_id = 2; 2137 params.page_id = 2;
2121 params.nav_entry_id = 0; 2138 params.nav_entry_id = 0;
2122 params.did_create_new_entry = true; 2139 params.did_create_new_entry = true;
2123 params.url = url2; 2140 params.url = url2;
2124 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2141 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2125 params.should_update_history = false; 2142 params.should_update_history = false;
2126 params.gesture = NavigationGestureUser; 2143 params.gesture = NavigationGestureUser;
2127 params.is_post = false; 2144 params.is_post = false;
2128 params.page_state = PageState::CreateFromURL(url2); 2145 params.page_state = PageState::CreateFromURL(url2);
2129 2146
2130 LoadCommittedDetails details; 2147 LoadCommittedDetailsObserver observer(contents());
2131 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); 2148 subframe->PrepareForCommit();
2149 subframe->SendNavigateWithParams(&params);
2132 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2150 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2133 navigation_entry_committed_counter_ = 0; 2151 navigation_entry_committed_counter_ = 0;
2134 EXPECT_EQ(url1, details.previous_url); 2152 EXPECT_EQ(url1, observer.details().previous_url);
2135 EXPECT_FALSE(details.is_in_page); 2153 EXPECT_FALSE(observer.details().is_in_page);
2136 EXPECT_FALSE(details.is_main_frame); 2154 EXPECT_FALSE(observer.details().is_main_frame);
2137 2155
2138 // The new entry should be appended. 2156 // The new entry should be appended.
2139 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); 2157 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2140 EXPECT_EQ(2, controller.GetEntryCount()); 2158 EXPECT_EQ(2, controller.GetEntryCount());
2141 EXPECT_EQ(entry, details.entry); 2159 EXPECT_EQ(entry, observer.details().entry);
2142 2160
2143 // New entry should refer to the new page, but the old URL (entries only 2161 // New entry should refer to the new page, but the old URL (entries only
2144 // reflect the toplevel URL). 2162 // reflect the toplevel URL).
2145 EXPECT_EQ(url1, entry->GetURL()); 2163 EXPECT_EQ(url1, entry->GetURL());
2146 EXPECT_EQ(params.page_id, entry->GetPageID()); 2164 EXPECT_EQ(params.page_id, entry->GetPageID());
2147 2165
2148 // Verify subframe entries if they're enabled (e.g. in --site-per-process). 2166 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2149 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 2167 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2150 // The entry should have a subframe FrameNavigationEntry. 2168 // The entry should have a subframe FrameNavigationEntry.
2151 ASSERT_EQ(1U, entry->root_node()->children.size()); 2169 ASSERT_EQ(1U, entry->root_node()->children.size());
(...skipping 15 matching lines...) Expand all
2167 const GURL url1("http://foo/1"); 2185 const GURL url1("http://foo/1");
2168 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1); 2186 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1);
2169 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2187 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2170 navigation_entry_committed_counter_ = 0; 2188 navigation_entry_committed_counter_ = 0;
2171 2189
2172 // Add a subframe and navigate it. 2190 // Add a subframe and navigate it.
2173 main_test_rfh()->OnCreateChildFrame( 2191 main_test_rfh()->OnCreateChildFrame(
2174 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document, 2192 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document,
2175 std::string(), "uniqueName0", blink::WebSandboxFlags::None, 2193 std::string(), "uniqueName0", blink::WebSandboxFlags::None,
2176 blink::WebFrameOwnerProperties()); 2194 blink::WebFrameOwnerProperties());
2177 RenderFrameHostImpl* subframe = 2195 TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>(
2178 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); 2196 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host());
2179 const GURL url2("http://foo/2"); 2197 const GURL url2("http://foo/2");
2180 { 2198 {
2181 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2199 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2182 params.page_id = 1; 2200 params.page_id = 1;
2183 params.nav_entry_id = 0; 2201 params.nav_entry_id = 0;
2184 params.did_create_new_entry = false; 2202 params.did_create_new_entry = false;
2185 params.url = url2; 2203 params.url = url2;
2186 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2204 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2187 params.should_update_history = false; 2205 params.should_update_history = false;
2188 params.gesture = NavigationGestureUser; 2206 params.gesture = NavigationGestureUser;
2189 params.is_post = false; 2207 params.is_post = false;
2190 params.page_state = PageState::CreateFromURL(url2); 2208 params.page_state = PageState::CreateFromURL(url2);
2191 2209
2192 // Navigating should do nothing. 2210 // Navigating should do nothing.
2193 LoadCommittedDetails details; 2211 subframe->PrepareForCommit();
2194 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); 2212 subframe->SendNavigateWithParams(&params);
2195 EXPECT_EQ(0U, notifications.size()); 2213 EXPECT_EQ(0U, notifications.size());
2196 } 2214 }
2197 2215
2198 // There should still be only one entry. 2216 // There should still be only one entry.
2199 EXPECT_EQ(1, controller.GetEntryCount()); 2217 EXPECT_EQ(1, controller.GetEntryCount());
2200 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); 2218 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2201 EXPECT_EQ(url1, entry->GetURL()); 2219 EXPECT_EQ(url1, entry->GetURL());
2202 EXPECT_EQ(1, entry->GetPageID()); 2220 EXPECT_EQ(1, entry->GetPageID());
2203 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); 2221 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get();
2204 EXPECT_EQ(url1, root_entry->url()); 2222 EXPECT_EQ(url1, root_entry->url());
2205 2223
2206 // Verify subframe entries if they're enabled (e.g. in --site-per-process). 2224 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2207 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 2225 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2208 // The entry should now have a subframe FrameNavigationEntry. 2226 // The entry should now have a subframe FrameNavigationEntry.
2209 ASSERT_EQ(1U, entry->root_node()->children.size()); 2227 ASSERT_EQ(1U, entry->root_node()->children.size());
2210 FrameNavigationEntry* frame_entry = 2228 FrameNavigationEntry* frame_entry =
2211 entry->root_node()->children[0]->frame_entry.get(); 2229 entry->root_node()->children[0]->frame_entry.get();
2212 EXPECT_EQ(url2, frame_entry->url()); 2230 EXPECT_EQ(url2, frame_entry->url());
2213 } else { 2231 } else {
2214 // There are no subframe FrameNavigationEntries by default. 2232 // There are no subframe FrameNavigationEntries by default.
2215 EXPECT_EQ(0U, entry->root_node()->children.size()); 2233 EXPECT_EQ(0U, entry->root_node()->children.size());
2216 } 2234 }
2217 2235
2218 // Add a second subframe and navigate. 2236 // Add a second subframe and navigate.
2219 main_test_rfh()->OnCreateChildFrame( 2237 main_test_rfh()->OnCreateChildFrame(
2220 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document, 2238 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document,
2221 std::string(), "uniqueName1", blink::WebSandboxFlags::None, 2239 std::string(), "uniqueName1", blink::WebSandboxFlags::None,
2222 blink::WebFrameOwnerProperties()); 2240 blink::WebFrameOwnerProperties());
2223 RenderFrameHostImpl* subframe2 = 2241 TestRenderFrameHost* subframe2 = static_cast<TestRenderFrameHost*>(
2224 contents()->GetFrameTree()->root()->child_at(1)->current_frame_host(); 2242 contents()->GetFrameTree()->root()->child_at(1)->current_frame_host());
2225 const GURL url3("http://foo/3"); 2243 const GURL url3("http://foo/3");
2226 { 2244 {
2227 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2245 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2228 params.page_id = 1; 2246 params.page_id = 1;
2229 params.nav_entry_id = 0; 2247 params.nav_entry_id = 0;
2230 params.did_create_new_entry = false; 2248 params.did_create_new_entry = false;
2231 params.url = url3; 2249 params.url = url3;
2232 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2250 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2233 params.should_update_history = false; 2251 params.should_update_history = false;
2234 params.gesture = NavigationGestureUser; 2252 params.gesture = NavigationGestureUser;
2235 params.is_post = false; 2253 params.is_post = false;
2236 params.page_state = PageState::CreateFromURL(url3); 2254 params.page_state = PageState::CreateFromURL(url3);
2237 2255
2238 // Navigating should do nothing. 2256 // Navigating should do nothing.
2239 LoadCommittedDetails details; 2257 subframe2->PrepareForCommit();
2240 EXPECT_FALSE(controller.RendererDidNavigate(subframe2, params, &details)); 2258 subframe2->SendNavigateWithParams(&params);
2241 EXPECT_EQ(0U, notifications.size()); 2259 EXPECT_EQ(0U, notifications.size());
2242 } 2260 }
2243 2261
2244 // There should still be only one entry, mostly unchanged. 2262 // There should still be only one entry, mostly unchanged.
2245 EXPECT_EQ(1, controller.GetEntryCount()); 2263 EXPECT_EQ(1, controller.GetEntryCount());
2246 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); 2264 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
2247 EXPECT_EQ(url1, entry->GetURL()); 2265 EXPECT_EQ(url1, entry->GetURL());
2248 EXPECT_EQ(1, entry->GetPageID()); 2266 EXPECT_EQ(1, entry->GetPageID());
2249 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get()); 2267 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get());
2250 EXPECT_EQ(url1, root_entry->url()); 2268 EXPECT_EQ(url1, root_entry->url());
2251 2269
2252 // Verify subframe entries if they're enabled (e.g. in --site-per-process). 2270 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2253 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 2271 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2254 // The entry should now have 2 subframe FrameNavigationEntries. 2272 // The entry should now have 2 subframe FrameNavigationEntries.
2255 ASSERT_EQ(2U, entry->root_node()->children.size()); 2273 ASSERT_EQ(2U, entry->root_node()->children.size());
2256 FrameNavigationEntry* new_frame_entry = 2274 FrameNavigationEntry* new_frame_entry =
2257 entry->root_node()->children[1]->frame_entry.get(); 2275 entry->root_node()->children[1]->frame_entry.get();
2258 EXPECT_EQ(url3, new_frame_entry->url()); 2276 EXPECT_EQ(url3, new_frame_entry->url());
2259 } else { 2277 } else {
2260 // There are no subframe FrameNavigationEntries by default. 2278 // There are no subframe FrameNavigationEntries by default.
2261 EXPECT_EQ(0U, entry->root_node()->children.size()); 2279 EXPECT_EQ(0U, entry->root_node()->children.size());
2262 } 2280 }
2263 2281
2264 // Add a nested subframe and navigate. 2282 // Add a nested subframe and navigate.
2265 subframe->OnCreateChildFrame(process()->GetNextRoutingID(), 2283 subframe->OnCreateChildFrame(process()->GetNextRoutingID(),
2266 blink::WebTreeScopeType::Document, std::string(), 2284 blink::WebTreeScopeType::Document, std::string(),
2267 "uniqueName2", blink::WebSandboxFlags::None, 2285 "uniqueName2", blink::WebSandboxFlags::None,
2268 blink::WebFrameOwnerProperties()); 2286 blink::WebFrameOwnerProperties());
2269 RenderFrameHostImpl* subframe3 = contents() 2287 TestRenderFrameHost* subframe3 =
2270 ->GetFrameTree() 2288 static_cast<TestRenderFrameHost*>(contents()
2271 ->root() 2289 ->GetFrameTree()
2272 ->child_at(0) 2290 ->root()
2273 ->child_at(0) 2291 ->child_at(0)
2274 ->current_frame_host(); 2292 ->child_at(0)
2293 ->current_frame_host());
2275 const GURL url4("http://foo/4"); 2294 const GURL url4("http://foo/4");
2276 { 2295 {
2277 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2296 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2278 params.page_id = 1; 2297 params.page_id = 1;
2279 params.nav_entry_id = 0; 2298 params.nav_entry_id = 0;
2280 params.did_create_new_entry = false; 2299 params.did_create_new_entry = false;
2281 params.url = url4; 2300 params.url = url4;
2282 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2301 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2283 params.should_update_history = false; 2302 params.should_update_history = false;
2284 params.gesture = NavigationGestureUser; 2303 params.gesture = NavigationGestureUser;
2285 params.is_post = false; 2304 params.is_post = false;
2286 params.page_state = PageState::CreateFromURL(url4); 2305 params.page_state = PageState::CreateFromURL(url4);
2287 2306
2288 // Navigating should do nothing. 2307 // Navigating should do nothing.
2289 LoadCommittedDetails details; 2308 subframe3->PrepareForCommit();
2290 EXPECT_FALSE(controller.RendererDidNavigate(subframe3, params, &details)); 2309 subframe3->SendNavigateWithParams(&params);
2291 EXPECT_EQ(0U, notifications.size()); 2310 EXPECT_EQ(0U, notifications.size());
2292 } 2311 }
2293 2312
2294 // There should still be only one entry, mostly unchanged. 2313 // There should still be only one entry, mostly unchanged.
2295 EXPECT_EQ(1, controller.GetEntryCount()); 2314 EXPECT_EQ(1, controller.GetEntryCount());
2296 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); 2315 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
2297 EXPECT_EQ(url1, entry->GetURL()); 2316 EXPECT_EQ(url1, entry->GetURL());
2298 EXPECT_EQ(1, entry->GetPageID()); 2317 EXPECT_EQ(1, entry->GetPageID());
2299 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get()); 2318 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get());
2300 EXPECT_EQ(url1, root_entry->url()); 2319 EXPECT_EQ(url1, root_entry->url());
(...skipping 23 matching lines...) Expand all
2324 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1); 2343 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1);
2325 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2344 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2326 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); 2345 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
2327 navigation_entry_committed_counter_ = 0; 2346 navigation_entry_committed_counter_ = 0;
2328 2347
2329 // Prereq: add a subframe with an initial auto-subframe navigation. 2348 // Prereq: add a subframe with an initial auto-subframe navigation.
2330 main_test_rfh()->OnCreateChildFrame( 2349 main_test_rfh()->OnCreateChildFrame(
2331 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document, 2350 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document,
2332 std::string(), "uniqueName0", blink::WebSandboxFlags::None, 2351 std::string(), "uniqueName0", blink::WebSandboxFlags::None,
2333 blink::WebFrameOwnerProperties()); 2352 blink::WebFrameOwnerProperties());
2334 RenderFrameHostImpl* subframe = 2353 TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>(
2335 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); 2354 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host());
2336 const GURL subframe_url("http://foo1/subframe"); 2355 const GURL subframe_url("http://foo1/subframe");
2337 { 2356 {
2338 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2357 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2339 params.page_id = 1; 2358 params.page_id = 1;
2340 params.nav_entry_id = 0; 2359 params.nav_entry_id = 0;
2341 params.did_create_new_entry = false; 2360 params.did_create_new_entry = false;
2342 params.url = subframe_url; 2361 params.url = subframe_url;
2343 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2362 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2344 params.should_update_history = false; 2363 params.should_update_history = false;
2345 params.gesture = NavigationGestureUser; 2364 params.gesture = NavigationGestureUser;
2346 params.is_post = false; 2365 params.is_post = false;
2347 params.page_state = PageState::CreateFromURL(subframe_url); 2366 params.page_state = PageState::CreateFromURL(subframe_url);
2348 2367
2349 // Navigating should do nothing. 2368 // Navigating should do nothing.
2350 LoadCommittedDetails details; 2369 subframe->PrepareForCommit();
2351 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); 2370 subframe->SendNavigateWithParams(&params);
2352 EXPECT_EQ(0U, notifications.size()); 2371 EXPECT_EQ(0U, notifications.size());
2353 } 2372 }
2354 2373
2355 // First manual subframe navigation. 2374 // First manual subframe navigation.
2356 const GURL url2("http://foo2"); 2375 const GURL url2("http://foo2");
2357 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2376 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2358 params.page_id = 2; 2377 params.page_id = 2;
2359 params.nav_entry_id = 0; 2378 params.nav_entry_id = 0;
2360 params.did_create_new_entry = true; 2379 params.did_create_new_entry = true;
2361 params.url = url2; 2380 params.url = url2;
2362 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2381 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2363 params.should_update_history = false; 2382 params.should_update_history = false;
2364 params.gesture = NavigationGestureUser; 2383 params.gesture = NavigationGestureUser;
2365 params.is_post = false; 2384 params.is_post = false;
2366 params.page_state = PageState::CreateFromURL(url2); 2385 params.page_state = PageState::CreateFromURL(url2);
2367 2386
2368 // This should generate a new entry. 2387 // This should generate a new entry.
2369 LoadCommittedDetails details; 2388 subframe->PrepareForCommit();
2370 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); 2389 subframe->SendNavigateWithParams(&params);
2371 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); 2390 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
2372 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2391 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2373 navigation_entry_committed_counter_ = 0; 2392 navigation_entry_committed_counter_ = 0;
2374 EXPECT_EQ(2, controller.GetEntryCount()); 2393 EXPECT_EQ(2, controller.GetEntryCount());
2375 2394
2376 // Verify subframe entries if they're enabled (e.g. in --site-per-process). 2395 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2377 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 2396 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2378 // The entry should have a subframe FrameNavigationEntry. 2397 // The entry should have a subframe FrameNavigationEntry.
2379 ASSERT_EQ(1U, entry2->root_node()->children.size()); 2398 ASSERT_EQ(1U, entry2->root_node()->children.size());
2380 EXPECT_EQ(url2, entry2->root_node()->children[0]->frame_entry->url()); 2399 EXPECT_EQ(url2, entry2->root_node()->children[0]->frame_entry->url());
2381 } else { 2400 } else {
2382 // There are no subframe FrameNavigationEntries by default. 2401 // There are no subframe FrameNavigationEntries by default.
2383 EXPECT_EQ(0U, entry2->root_node()->children.size()); 2402 EXPECT_EQ(0U, entry2->root_node()->children.size());
2384 } 2403 }
2385 2404
2386 // Second manual subframe navigation should also make a new entry. 2405 // Second manual subframe navigation should also make a new entry.
2387 const GURL url3("http://foo3"); 2406 const GURL url3("http://foo3");
2388 params.page_id = 3; 2407 params.page_id = 3;
2389 params.nav_entry_id = 0; 2408 params.nav_entry_id = 0;
2390 params.did_create_new_entry = true; 2409 params.did_create_new_entry = true;
2391 params.url = url3; 2410 params.url = url3;
2392 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2411 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2393 params.page_state = PageState::CreateFromURL(url3); 2412 params.page_state = PageState::CreateFromURL(url3);
2394 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); 2413 subframe->PrepareForCommit();
2414 subframe->SendNavigateWithParams(&params);
2395 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2415 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2396 navigation_entry_committed_counter_ = 0; 2416 navigation_entry_committed_counter_ = 0;
2397 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry(); 2417 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry();
2398 EXPECT_EQ(3, controller.GetEntryCount()); 2418 EXPECT_EQ(3, controller.GetEntryCount());
2399 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2419 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2400 2420
2401 // Verify subframe entries if they're enabled (e.g. in --site-per-process). 2421 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2402 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 2422 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2403 // The entry should have a subframe FrameNavigationEntry. 2423 // The entry should have a subframe FrameNavigationEntry.
2404 ASSERT_EQ(1U, entry3->root_node()->children.size()); 2424 ASSERT_EQ(1U, entry3->root_node()->children.size());
2405 EXPECT_EQ(url3, entry3->root_node()->children[0]->frame_entry->url()); 2425 EXPECT_EQ(url3, entry3->root_node()->children[0]->frame_entry->url());
2406 } else { 2426 } else {
2407 // There are no subframe FrameNavigationEntries by default. 2427 // There are no subframe FrameNavigationEntries by default.
2408 EXPECT_EQ(0U, entry3->root_node()->children.size()); 2428 EXPECT_EQ(0U, entry3->root_node()->children.size());
2409 } 2429 }
2410 2430
2411 // Go back one. 2431 // Go back one.
2412 controller.GoBack(); 2432 controller.GoBack();
2413 params.page_id = 2; 2433 params.page_id = 2;
2414 params.nav_entry_id = entry2->GetUniqueID(); 2434 params.nav_entry_id = entry2->GetUniqueID();
2415 params.did_create_new_entry = false; 2435 params.did_create_new_entry = false;
2416 params.url = url2; 2436 params.url = url2;
2417 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2437 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2418 params.page_state = PageState::CreateFromURL(url2); 2438 params.page_state = PageState::CreateFromURL(url2);
2419 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); 2439 subframe->PrepareForCommit();
2440 subframe->SendNavigateWithParams(&params);
2420 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2441 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2421 navigation_entry_committed_counter_ = 0; 2442 navigation_entry_committed_counter_ = 0;
2422 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); 2443 EXPECT_EQ(entry2, controller.GetLastCommittedEntry());
2423 EXPECT_EQ(3, controller.GetEntryCount()); 2444 EXPECT_EQ(3, controller.GetEntryCount());
2424 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2445 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2425 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2446 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2426 EXPECT_FALSE(controller.GetPendingEntry()); 2447 EXPECT_FALSE(controller.GetPendingEntry());
2427 2448
2428 // Go back one more. 2449 // Go back one more.
2429 controller.GoBack(); 2450 controller.GoBack();
2430 params.page_id = 1; 2451 params.page_id = 1;
2431 params.nav_entry_id = entry1->GetUniqueID(); 2452 params.nav_entry_id = entry1->GetUniqueID();
2432 params.did_create_new_entry = false; 2453 params.did_create_new_entry = false;
2433 params.url = subframe_url; 2454 params.url = subframe_url;
2434 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2455 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2435 params.page_state = PageState::CreateFromURL(subframe_url); 2456 params.page_state = PageState::CreateFromURL(subframe_url);
2436 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); 2457 subframe->PrepareForCommit();
2458 subframe->SendNavigateWithParams(&params);
2437 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2459 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2438 navigation_entry_committed_counter_ = 0; 2460 navigation_entry_committed_counter_ = 0;
2439 EXPECT_EQ(entry1, controller.GetLastCommittedEntry()); 2461 EXPECT_EQ(entry1, controller.GetLastCommittedEntry());
2440 EXPECT_EQ(3, controller.GetEntryCount()); 2462 EXPECT_EQ(3, controller.GetEntryCount());
2441 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2463 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2442 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2464 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2443 EXPECT_FALSE(controller.GetPendingEntry()); 2465 EXPECT_FALSE(controller.GetPendingEntry());
2444 } 2466 }
2445 2467
2446 TEST_F(NavigationControllerTest, LinkClick) { 2468 TEST_F(NavigationControllerTest, LinkClick) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 self_params.nav_entry_id = 0; 2509 self_params.nav_entry_id = 0;
2488 self_params.did_create_new_entry = false; 2510 self_params.did_create_new_entry = false;
2489 self_params.url = url1; 2511 self_params.url = url1;
2490 self_params.transition = ui::PAGE_TRANSITION_LINK; 2512 self_params.transition = ui::PAGE_TRANSITION_LINK;
2491 self_params.should_update_history = false; 2513 self_params.should_update_history = false;
2492 self_params.gesture = NavigationGestureUser; 2514 self_params.gesture = NavigationGestureUser;
2493 self_params.is_post = false; 2515 self_params.is_post = false;
2494 self_params.page_state = PageState::CreateFromURL(url1); 2516 self_params.page_state = PageState::CreateFromURL(url1);
2495 self_params.was_within_same_page = true; 2517 self_params.was_within_same_page = true;
2496 2518
2497 LoadCommittedDetails details; 2519 LoadCommittedDetailsObserver observer(contents());
2498 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, 2520 main_test_rfh()->PrepareForCommit();
2499 &details)); 2521 main_test_rfh()->SendNavigateWithParams(&self_params);
2500 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); 2522 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
2501 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2523 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2502 navigation_entry_committed_counter_ = 0; 2524 navigation_entry_committed_counter_ = 0;
2503 EXPECT_TRUE(details.is_in_page); 2525 EXPECT_TRUE(observer.details().is_in_page);
2504 EXPECT_TRUE(details.did_replace_entry); 2526 EXPECT_TRUE(observer.details().did_replace_entry);
2505 EXPECT_EQ(1, controller.GetEntryCount()); 2527 EXPECT_EQ(1, controller.GetEntryCount());
2506 2528
2507 // Fragment navigation to a new page_id. 2529 // Fragment navigation to a new page_id.
2508 const GURL url2("http://foo#a"); 2530 const GURL url2("http://foo#a");
2509 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2531 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2510 params.page_id = 1; 2532 params.page_id = 1;
2511 params.nav_entry_id = 0; 2533 params.nav_entry_id = 0;
2512 params.did_create_new_entry = true; 2534 params.did_create_new_entry = true;
2513 params.url = url2; 2535 params.url = url2;
2514 params.transition = ui::PAGE_TRANSITION_LINK; 2536 params.transition = ui::PAGE_TRANSITION_LINK;
2515 params.should_update_history = false; 2537 params.should_update_history = false;
2516 params.gesture = NavigationGestureUser; 2538 params.gesture = NavigationGestureUser;
2517 params.is_post = false; 2539 params.is_post = false;
2518 params.page_state = PageState::CreateFromURL(url2); 2540 params.page_state = PageState::CreateFromURL(url2);
2519 params.was_within_same_page = true; 2541 params.was_within_same_page = true;
2520 2542
2521 // This should generate a new entry. 2543 // This should generate a new entry.
2522 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2544 main_test_rfh()->PrepareForCommit();
2523 &details)); 2545 main_test_rfh()->SendNavigateWithParams(&params);
2524 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); 2546 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
2525 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2547 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2526 navigation_entry_committed_counter_ = 0; 2548 navigation_entry_committed_counter_ = 0;
2527 EXPECT_TRUE(details.is_in_page); 2549 EXPECT_TRUE(observer.details().is_in_page);
2528 EXPECT_FALSE(details.did_replace_entry); 2550 EXPECT_FALSE(observer.details().did_replace_entry);
2529 EXPECT_EQ(2, controller.GetEntryCount()); 2551 EXPECT_EQ(2, controller.GetEntryCount());
2530 2552
2531 // Go back one. 2553 // Go back one.
2532 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); 2554 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params);
2533 controller.GoBack(); 2555 controller.GoBack();
2534 back_params.url = url1; 2556 back_params.url = url1;
2535 back_params.page_id = 0; 2557 back_params.page_id = 0;
2536 back_params.nav_entry_id = entry1->GetUniqueID(); 2558 back_params.nav_entry_id = entry1->GetUniqueID();
2537 back_params.did_create_new_entry = false; 2559 back_params.did_create_new_entry = false;
2538 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, 2560 main_test_rfh()->PrepareForCommit();
2539 &details)); 2561 main_test_rfh()->SendNavigateWithParams(&back_params);
2540 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2562 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2541 navigation_entry_committed_counter_ = 0; 2563 navigation_entry_committed_counter_ = 0;
2542 EXPECT_TRUE(details.is_in_page); 2564 EXPECT_TRUE(observer.details().is_in_page);
2543 EXPECT_EQ(2, controller.GetEntryCount()); 2565 EXPECT_EQ(2, controller.GetEntryCount());
2544 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2566 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2545 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); 2567 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
2546 2568
2547 // Go forward. 2569 // Go forward.
2548 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); 2570 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params);
2549 controller.GoForward(); 2571 controller.GoForward();
2550 forward_params.url = url2; 2572 forward_params.url = url2;
2551 forward_params.page_id = 1; 2573 forward_params.page_id = 1;
2552 forward_params.nav_entry_id = entry2->GetUniqueID(); 2574 forward_params.nav_entry_id = entry2->GetUniqueID();
2553 forward_params.did_create_new_entry = false; 2575 forward_params.did_create_new_entry = false;
2554 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, 2576 main_test_rfh()->PrepareForCommit();
2555 &details)); 2577 main_test_rfh()->SendNavigateWithParams(&forward_params);
2556 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2578 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2557 navigation_entry_committed_counter_ = 0; 2579 navigation_entry_committed_counter_ = 0;
2558 EXPECT_TRUE(details.is_in_page); 2580 EXPECT_TRUE(observer.details().is_in_page);
2559 EXPECT_EQ(2, controller.GetEntryCount()); 2581 EXPECT_EQ(2, controller.GetEntryCount());
2560 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2582 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2561 EXPECT_EQ(forward_params.url, 2583 EXPECT_EQ(forward_params.url,
2562 controller.GetVisibleEntry()->GetURL()); 2584 controller.GetVisibleEntry()->GetURL());
2563 2585
2564 // Now go back and forward again. This is to work around a bug where we would 2586 // Now go back and forward again. This is to work around a bug where we would
2565 // compare the incoming URL with the last committed entry rather than the 2587 // compare the incoming URL with the last committed entry rather than the
2566 // one identified by an existing page ID. This would result in the second URL 2588 // one identified by an existing page ID. This would result in the second URL
2567 // losing the reference fragment when you navigate away from it and then back. 2589 // losing the reference fragment when you navigate away from it and then back.
2568 controller.GoBack(); 2590 controller.GoBack();
2569 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, 2591 main_test_rfh()->PrepareForCommit();
2570 &details)); 2592 main_test_rfh()->SendNavigateWithParams(&back_params);
2571 controller.GoForward(); 2593 controller.GoForward();
2572 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, 2594 main_test_rfh()->PrepareForCommit();
2573 &details)); 2595 main_test_rfh()->SendNavigateWithParams(&forward_params);
2574 EXPECT_EQ(forward_params.url, 2596 EXPECT_EQ(forward_params.url,
2575 controller.GetVisibleEntry()->GetURL()); 2597 controller.GetVisibleEntry()->GetURL());
2576 2598
2577 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. 2599 // Finally, navigate to an unrelated URL to make sure in_page is not sticky.
2578 const GURL url3("http://bar"); 2600 const GURL url3("http://bar");
2579 params.page_id = 2; 2601 params.page_id = 2;
2580 params.nav_entry_id = 0; 2602 params.nav_entry_id = 0;
2581 params.did_create_new_entry = true; 2603 params.did_create_new_entry = true;
2582 params.url = url3; 2604 params.url = url3;
2583 navigation_entry_committed_counter_ = 0; 2605 navigation_entry_committed_counter_ = 0;
2584 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2606 main_test_rfh()->PrepareForCommit();
2585 &details)); 2607 main_test_rfh()->SendNavigateWithParams(&params);
2586 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2608 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2587 navigation_entry_committed_counter_ = 0; 2609 navigation_entry_committed_counter_ = 0;
2588 EXPECT_FALSE(details.is_in_page); 2610 EXPECT_FALSE(observer.details().is_in_page);
2589 EXPECT_EQ(3, controller.GetEntryCount()); 2611 EXPECT_EQ(3, controller.GetEntryCount());
2590 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2612 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2591 } 2613 }
2592 2614
2593 TEST_F(NavigationControllerTest, InPage_Replace) { 2615 TEST_F(NavigationControllerTest, InPage_Replace) {
2594 NavigationControllerImpl& controller = controller_impl(); 2616 NavigationControllerImpl& controller = controller_impl();
2595 TestNotificationTracker notifications; 2617 TestNotificationTracker notifications;
2596 RegisterForAllNavNotifications(&notifications, &controller); 2618 RegisterForAllNavNotifications(&notifications, &controller);
2597 2619
2598 // Main page. 2620 // Main page.
(...skipping 10 matching lines...) Expand all
2609 params.did_create_new_entry = false; 2631 params.did_create_new_entry = false;
2610 params.url = url2; 2632 params.url = url2;
2611 params.transition = ui::PAGE_TRANSITION_LINK; 2633 params.transition = ui::PAGE_TRANSITION_LINK;
2612 params.should_update_history = false; 2634 params.should_update_history = false;
2613 params.gesture = NavigationGestureUser; 2635 params.gesture = NavigationGestureUser;
2614 params.is_post = false; 2636 params.is_post = false;
2615 params.page_state = PageState::CreateFromURL(url2); 2637 params.page_state = PageState::CreateFromURL(url2);
2616 params.was_within_same_page = true; 2638 params.was_within_same_page = true;
2617 2639
2618 // This should NOT generate a new entry, nor prune the list. 2640 // This should NOT generate a new entry, nor prune the list.
2619 LoadCommittedDetails details; 2641 LoadCommittedDetailsObserver observer(contents());
2620 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2642 main_test_rfh()->PrepareForCommit();
2621 &details)); 2643 main_test_rfh()->SendNavigateWithParams(&params);
2622 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2644 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2623 navigation_entry_committed_counter_ = 0; 2645 navigation_entry_committed_counter_ = 0;
2624 EXPECT_TRUE(details.is_in_page); 2646 EXPECT_TRUE(observer.details().is_in_page);
2625 EXPECT_TRUE(details.did_replace_entry); 2647 EXPECT_TRUE(observer.details().did_replace_entry);
2626 EXPECT_EQ(1, controller.GetEntryCount()); 2648 EXPECT_EQ(1, controller.GetEntryCount());
2627 } 2649 }
2628 2650
2629 // Tests for http://crbug.com/40395 2651 // Tests for http://crbug.com/40395
2630 // Simulates this: 2652 // Simulates this:
2631 // <script> 2653 // <script>
2632 // window.location.replace("#a"); 2654 // window.location.replace("#a");
2633 // window.location='http://foo3/'; 2655 // window.location='http://foo3/';
2634 // </script> 2656 // </script>
2635 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { 2657 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) {
(...skipping 27 matching lines...) Expand all
2663 params.url = url; 2685 params.url = url;
2664 params.transition = ui::PAGE_TRANSITION_LINK; 2686 params.transition = ui::PAGE_TRANSITION_LINK;
2665 params.redirects.push_back(url); 2687 params.redirects.push_back(url);
2666 params.should_update_history = true; 2688 params.should_update_history = true;
2667 params.gesture = NavigationGestureUnknown; 2689 params.gesture = NavigationGestureUnknown;
2668 params.is_post = false; 2690 params.is_post = false;
2669 params.page_state = PageState::CreateFromURL(url); 2691 params.page_state = PageState::CreateFromURL(url);
2670 params.was_within_same_page = true; 2692 params.was_within_same_page = true;
2671 2693
2672 // This should NOT generate a new entry, nor prune the list. 2694 // This should NOT generate a new entry, nor prune the list.
2673 LoadCommittedDetails details; 2695 LoadCommittedDetailsObserver observer(contents());
2674 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2696 main_test_rfh()->PrepareForCommit();
2675 &details)); 2697 main_test_rfh()->SendNavigateWithParams(&params);
2676 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2698 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2677 navigation_entry_committed_counter_ = 0; 2699 navigation_entry_committed_counter_ = 0;
2678 EXPECT_TRUE(details.is_in_page); 2700 EXPECT_TRUE(observer.details().is_in_page);
2679 EXPECT_TRUE(details.did_replace_entry); 2701 EXPECT_TRUE(observer.details().did_replace_entry);
2680 EXPECT_EQ(2, controller.GetEntryCount()); 2702 EXPECT_EQ(2, controller.GetEntryCount());
2681 } 2703 }
2682 2704
2683 // Perform a client redirect to a new page. 2705 // Perform a client redirect to a new page.
2684 { 2706 {
2685 const GURL url("http://foo3/"); 2707 const GURL url("http://foo3/");
2686 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2708 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2687 params.page_id = 2; // New page_id 2709 params.page_id = 2; // New page_id
2688 params.nav_entry_id = 0; 2710 params.nav_entry_id = 0;
2689 params.did_create_new_entry = true; 2711 params.did_create_new_entry = true;
2690 params.url = url; 2712 params.url = url;
2691 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 2713 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
2692 params.redirects.push_back(GURL("http://foo2/#a")); 2714 params.redirects.push_back(GURL("http://foo2/#a"));
2693 params.redirects.push_back(url); 2715 params.redirects.push_back(url);
2694 params.should_update_history = true; 2716 params.should_update_history = true;
2695 params.gesture = NavigationGestureUnknown; 2717 params.gesture = NavigationGestureUnknown;
2696 params.is_post = false; 2718 params.is_post = false;
2697 params.page_state = PageState::CreateFromURL(url); 2719 params.page_state = PageState::CreateFromURL(url);
2698 2720
2699 // This SHOULD generate a new entry. 2721 // This SHOULD generate a new entry.
2700 LoadCommittedDetails details; 2722 LoadCommittedDetailsObserver observer(contents());
2701 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2723 main_test_rfh()->PrepareForCommit();
2702 &details)); 2724 main_test_rfh()->SendNavigateWithParams(&params);
2703 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2725 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2704 navigation_entry_committed_counter_ = 0; 2726 navigation_entry_committed_counter_ = 0;
2705 EXPECT_FALSE(details.is_in_page); 2727 EXPECT_FALSE(observer.details().is_in_page);
2706 EXPECT_EQ(3, controller.GetEntryCount()); 2728 EXPECT_EQ(3, controller.GetEntryCount());
2707 } 2729 }
2708 2730
2709 // Verify that BACK brings us back to http://foo2/. 2731 // Verify that BACK brings us back to http://foo2/.
2710 { 2732 {
2711 const GURL url("http://foo2/"); 2733 const GURL url("http://foo2/");
2712 controller.GoBack(); 2734 controller.GoBack();
2713 int entry_id = controller.GetPendingEntry()->GetUniqueID(); 2735 int entry_id = controller.GetPendingEntry()->GetUniqueID();
2714 main_test_rfh()->PrepareForCommit(); 2736 main_test_rfh()->PrepareForCommit();
2715 main_test_rfh()->SendNavigate(1, entry_id, false, url); 2737 main_test_rfh()->SendNavigate(1, entry_id, false, url);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2896 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2875 params.page_id = 0; 2897 params.page_id = 0;
2876 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID(); 2898 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID();
2877 params.did_create_new_entry = false; 2899 params.did_create_new_entry = false;
2878 params.url = url; 2900 params.url = url;
2879 params.transition = ui::PAGE_TRANSITION_LINK; 2901 params.transition = ui::PAGE_TRANSITION_LINK;
2880 params.should_update_history = false; 2902 params.should_update_history = false;
2881 params.gesture = NavigationGestureUser; 2903 params.gesture = NavigationGestureUser;
2882 params.is_post = false; 2904 params.is_post = false;
2883 params.page_state = PageState::CreateFromURL(url); 2905 params.page_state = PageState::CreateFromURL(url);
2884 LoadCommittedDetails details; 2906 TestRenderFrameHost* main_rfh =
2885 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2907 static_cast<TestRenderFrameHost*>(our_contents->GetMainFrame());
2886 &details); 2908 main_rfh->PrepareForCommit();
2909 main_rfh->SendNavigateWithParams(&params);
2887 2910
2888 // There should be no longer any pending entry and one committed one. This 2911 // There should be no longer any pending entry and one committed one. This
2889 // means that we were able to locate the entry, assign its site instance, and 2912 // means that we were able to locate the entry, assign its site instance, and
2890 // commit it properly. 2913 // commit it properly.
2891 EXPECT_EQ(1, our_controller.GetEntryCount()); 2914 EXPECT_EQ(1, our_controller.GetEntryCount());
2892 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2915 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2893 EXPECT_FALSE(our_controller.GetPendingEntry()); 2916 EXPECT_FALSE(our_controller.GetPendingEntry());
2894 EXPECT_EQ( 2917 EXPECT_EQ(
2895 url, 2918 url,
2896 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); 2919 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2979 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2957 params.page_id = 0; 2980 params.page_id = 0;
2958 params.nav_entry_id = entry->GetUniqueID(); 2981 params.nav_entry_id = entry->GetUniqueID();
2959 params.did_create_new_entry = false; 2982 params.did_create_new_entry = false;
2960 params.url = url; 2983 params.url = url;
2961 params.transition = ui::PAGE_TRANSITION_LINK; 2984 params.transition = ui::PAGE_TRANSITION_LINK;
2962 params.should_update_history = false; 2985 params.should_update_history = false;
2963 params.gesture = NavigationGestureUser; 2986 params.gesture = NavigationGestureUser;
2964 params.is_post = false; 2987 params.is_post = false;
2965 params.page_state = PageState::CreateFromURL(url); 2988 params.page_state = PageState::CreateFromURL(url);
2966 LoadCommittedDetails details; 2989 TestRenderFrameHost* main_rfh =
2967 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2990 static_cast<TestRenderFrameHost*>(our_contents->GetMainFrame());
2968 &details); 2991 main_rfh->PrepareForCommit();
2992 main_rfh->SendNavigateWithParams(&params);
2969 2993
2970 // There should be no pending entry and one committed one. 2994 // There should be no pending entry and one committed one.
2971 EXPECT_EQ(1, our_controller.GetEntryCount()); 2995 EXPECT_EQ(1, our_controller.GetEntryCount());
2972 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2996 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2973 EXPECT_FALSE(our_controller.GetPendingEntry()); 2997 EXPECT_FALSE(our_controller.GetPendingEntry());
2974 EXPECT_EQ( 2998 EXPECT_EQ(
2975 url, 2999 url,
2976 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); 3000 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL());
2977 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, 3001 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE,
2978 our_controller.GetEntryAtIndex(0)->restore_type()); 3002 our_controller.GetEntryAtIndex(0)->restore_type());
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
3763 3787
3764 // We should be at the first navigation entry. 3788 // We should be at the first navigation entry.
3765 EXPECT_EQ(controller.GetEntryCount(), 1); 3789 EXPECT_EQ(controller.GetEntryCount(), 1);
3766 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3790 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3767 3791
3768 // Add and navigate a subframe that would normally count as in-page. 3792 // Add and navigate a subframe that would normally count as in-page.
3769 main_test_rfh()->OnCreateChildFrame( 3793 main_test_rfh()->OnCreateChildFrame(
3770 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document, 3794 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document,
3771 std::string(), "uniqueName0", blink::WebSandboxFlags::None, 3795 std::string(), "uniqueName0", blink::WebSandboxFlags::None,
3772 blink::WebFrameOwnerProperties()); 3796 blink::WebFrameOwnerProperties());
3773 RenderFrameHostImpl* subframe = 3797 TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>(
3774 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); 3798 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host());
3775 const GURL subframe_url("http://www.google.com/#"); 3799 const GURL subframe_url("http://www.google.com/#");
3776 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3800 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3777 params.page_id = 0; 3801 params.page_id = 0;
3778 params.nav_entry_id = 0; 3802 params.nav_entry_id = 0;
3779 params.did_create_new_entry = false; 3803 params.did_create_new_entry = false;
3780 params.url = subframe_url; 3804 params.url = subframe_url;
3781 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3805 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3782 params.should_update_history = false; 3806 params.should_update_history = false;
3783 params.gesture = NavigationGestureAuto; 3807 params.gesture = NavigationGestureAuto;
3784 params.is_post = false; 3808 params.is_post = false;
3785 params.page_state = PageState::CreateFromURL(subframe_url); 3809 params.page_state = PageState::CreateFromURL(subframe_url);
3786 LoadCommittedDetails details; 3810 subframe->PrepareForCommit();
3787 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); 3811 subframe->SendNavigateWithParams(&params);
3788 3812
3789 // Nothing should have changed. 3813 // Nothing should have changed.
3790 EXPECT_EQ(controller.GetEntryCount(), 1); 3814 EXPECT_EQ(controller.GetEntryCount(), 1);
3791 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3815 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3792 } 3816 }
3793 3817
3794 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 3818 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
3795 // false. 3819 // false.
3796 TEST_F(NavigationControllerTest, CloneAndGoBack) { 3820 TEST_F(NavigationControllerTest, CloneAndGoBack) {
3797 NavigationControllerImpl& controller = controller_impl(); 3821 NavigationControllerImpl& controller = controller_impl();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3930 const GURL url2("http://bar/"); 3954 const GURL url2("http://bar/");
3931 controller.LoadURL( 3955 controller.LoadURL(
3932 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3956 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3933 3957
3934 // Send a subframe update from the first page, as if one had just 3958 // Send a subframe update from the first page, as if one had just
3935 // automatically loaded. Auto subframes don't increment the page ID. 3959 // automatically loaded. Auto subframes don't increment the page ID.
3936 main_test_rfh()->OnCreateChildFrame( 3960 main_test_rfh()->OnCreateChildFrame(
3937 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document, 3961 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document,
3938 std::string(), "uniqueName0", blink::WebSandboxFlags::None, 3962 std::string(), "uniqueName0", blink::WebSandboxFlags::None,
3939 blink::WebFrameOwnerProperties()); 3963 blink::WebFrameOwnerProperties());
3940 RenderFrameHostImpl* subframe = 3964 TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>(
3941 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); 3965 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host());
3942 const GURL url1_sub("http://foo/subframe"); 3966 const GURL url1_sub("http://foo/subframe");
3943 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3967 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3944 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); 3968 params.page_id = controller.GetLastCommittedEntry()->GetPageID();
3945 params.nav_entry_id = 0; 3969 params.nav_entry_id = 0;
3946 params.did_create_new_entry = false; 3970 params.did_create_new_entry = false;
3947 params.url = url1_sub; 3971 params.url = url1_sub;
3948 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3972 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3949 params.should_update_history = false; 3973 params.should_update_history = false;
3950 params.gesture = NavigationGestureAuto; 3974 params.gesture = NavigationGestureAuto;
3951 params.is_post = false; 3975 params.is_post = false;
3952 params.page_state = PageState::CreateFromURL(url1_sub); 3976 params.page_state = PageState::CreateFromURL(url1_sub);
3953 LoadCommittedDetails details;
3954 3977
3955 // This should return false meaning that nothing was actually updated. 3978 // This should return false meaning that nothing was actually updated.
3956 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); 3979 subframe->PrepareForCommit();
3980 subframe->SendNavigateWithParams(&params);
3957 3981
3958 // The notification should have updated the last committed one, and not 3982 // The notification should have updated the last committed one, and not
3959 // the pending load. 3983 // the pending load.
3960 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); 3984 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL());
3961 3985
3962 // The active entry should be unchanged by the subframe load. 3986 // The active entry should be unchanged by the subframe load.
3963 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3987 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3964 } 3988 }
3965 3989
3966 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. 3990 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target.
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
5005 contents()->GetMainFrame()->SendNavigateWithParams(&params); 5029 contents()->GetMainFrame()->SendNavigateWithParams(&params);
5006 5030
5007 // Now reload. replaceState overrides the POST, so we should not show a 5031 // Now reload. replaceState overrides the POST, so we should not show a
5008 // repost warning dialog. 5032 // repost warning dialog.
5009 controller_impl().Reload(true); 5033 controller_impl().Reload(true);
5010 EXPECT_EQ(0, delegate->repost_form_warning_count()); 5034 EXPECT_EQ(0, delegate->repost_form_warning_count());
5011 } 5035 }
5012 5036
5013 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { 5037 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) {
5014 GURL url("http://foo"); 5038 GURL url("http://foo");
5039 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED,
5040 std::string());
5015 FrameHostMsg_DidCommitProvisionalLoad_Params params; 5041 FrameHostMsg_DidCommitProvisionalLoad_Params params;
5016 params.page_id = 1; 5042 params.page_id = 1;
5017 params.nav_entry_id = 0; 5043 params.nav_entry_id = 0;
5018 params.did_create_new_entry = true; 5044 params.did_create_new_entry = true;
5019 params.url = url; 5045 params.url = url;
5020 params.transition = ui::PAGE_TRANSITION_LINK; 5046 params.transition = ui::PAGE_TRANSITION_LINK;
5021 params.gesture = NavigationGestureUser; 5047 params.gesture = NavigationGestureUser;
5022 params.page_state = PageState::CreateFromURL(url); 5048 params.page_state = PageState::CreateFromURL(url);
5023 params.was_within_same_page = false; 5049 params.was_within_same_page = false;
5024 params.is_post = true; 5050 params.is_post = true;
5025 params.post_id = 2; 5051 params.post_id = 2;
5026 params.url_is_unreachable = true; 5052 params.url_is_unreachable = true;
5027 5053
5028 // Navigate to new page. 5054 // Navigate to new page.
5029 { 5055 {
5030 LoadCommittedDetails details; 5056 LoadCommittedDetailsObserver observer(contents());
5031 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 5057 main_test_rfh()->PrepareForCommit();
5058 main_test_rfh()->SendNavigateWithParams(&params);
5032 EXPECT_EQ(PAGE_TYPE_ERROR, 5059 EXPECT_EQ(PAGE_TYPE_ERROR,
5033 controller_impl().GetLastCommittedEntry()->GetPageType()); 5060 controller_impl().GetLastCommittedEntry()->GetPageType());
5034 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); 5061 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.details().type);
5035 } 5062 }
5036 5063
5037 // Navigate to existing page. 5064 // Navigate to existing page.
5038 { 5065 {
5039 params.did_create_new_entry = false; 5066 params.did_create_new_entry = false;
5040 LoadCommittedDetails details; 5067 LoadCommittedDetailsObserver observer(contents());
5041 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 5068 main_test_rfh()->PrepareForCommit();
5069 main_test_rfh()->SendNavigateWithParams(&params);
5042 EXPECT_EQ(PAGE_TYPE_ERROR, 5070 EXPECT_EQ(PAGE_TYPE_ERROR,
5043 controller_impl().GetLastCommittedEntry()->GetPageType()); 5071 controller_impl().GetLastCommittedEntry()->GetPageType());
5044 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); 5072 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.details().type);
5045 } 5073 }
5046 5074
5047 // Navigate to same page. 5075 // Navigate to same page.
5048 // Note: The call to LoadURL() creates a pending entry in order to trigger the 5076 // Note: The call to LoadURL() creates a pending entry in order to trigger the
5049 // same-page transition. 5077 // same-page transition.
5050 controller_impl().LoadURL( 5078 controller_impl().LoadURL(
5051 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 5079 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
5052 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID(); 5080 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID();
5053 params.transition = ui::PAGE_TRANSITION_TYPED; 5081 params.transition = ui::PAGE_TRANSITION_TYPED;
5054 { 5082 {
5055 LoadCommittedDetails details; 5083 LoadCommittedDetailsObserver observer(contents());
5056 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 5084 main_test_rfh()->PrepareForCommit();
5085 main_test_rfh()->SendNavigateWithParams(&params);
5057 EXPECT_EQ(PAGE_TYPE_ERROR, 5086 EXPECT_EQ(PAGE_TYPE_ERROR,
5058 controller_impl().GetLastCommittedEntry()->GetPageType()); 5087 controller_impl().GetLastCommittedEntry()->GetPageType());
5059 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, details.type); 5088 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type);
5060 } 5089 }
5061 5090
5062 // Navigate in page. 5091 // Navigate in page.
5063 params.url = GURL("http://foo#foo"); 5092 params.url = GURL("http://foo#foo");
5064 params.transition = ui::PAGE_TRANSITION_LINK; 5093 params.transition = ui::PAGE_TRANSITION_LINK;
5065 params.was_within_same_page = true; 5094 params.was_within_same_page = true;
5066 { 5095 {
5067 LoadCommittedDetails details; 5096 LoadCommittedDetailsObserver observer(contents());
5068 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 5097 main_test_rfh()->PrepareForCommit();
5098 main_test_rfh()->SendNavigateWithParams(&params);
5069 EXPECT_EQ(PAGE_TYPE_ERROR, 5099 EXPECT_EQ(PAGE_TYPE_ERROR,
5070 controller_impl().GetLastCommittedEntry()->GetPageType()); 5100 controller_impl().GetLastCommittedEntry()->GetPageType());
5071 EXPECT_TRUE(details.is_in_page); 5101 EXPECT_TRUE(observer.details().is_in_page);
5072 } 5102 }
5073 } 5103 }
5074 5104
5075 // Tests that if a stale navigation comes back from the renderer, it is properly 5105 // Tests that if a stale navigation comes back from the renderer, it is properly
5076 // resurrected. 5106 // resurrected.
5077 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) { 5107 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) {
5078 NavigationControllerImpl& controller = controller_impl(); 5108 NavigationControllerImpl& controller = controller_impl();
5079 TestNotificationTracker notifications; 5109 TestNotificationTracker notifications;
5080 RegisterForAllNavNotifications(&notifications, &controller); 5110 RegisterForAllNavNotifications(&notifications, &controller);
5081 5111
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5132 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); 5162 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL());
5133 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); 5163 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL());
5134 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); 5164 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL());
5135 } 5165 }
5136 5166
5137 // Test that if a renderer provides bogus security info (that fails to 5167 // Test that if a renderer provides bogus security info (that fails to
5138 // deserialize properly) when reporting a navigation, the renderer gets 5168 // deserialize properly) when reporting a navigation, the renderer gets
5139 // killed. 5169 // killed.
5140 TEST_F(NavigationControllerTest, RendererNavigateBogusSecurityInfo) { 5170 TEST_F(NavigationControllerTest, RendererNavigateBogusSecurityInfo) {
5141 GURL url("http://foo.test"); 5171 GURL url("http://foo.test");
5172 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED,
5173 std::string());
5142 FrameHostMsg_DidCommitProvisionalLoad_Params params; 5174 FrameHostMsg_DidCommitProvisionalLoad_Params params;
5143 params.page_id = 0; 5175 params.page_id = 0;
5144 params.nav_entry_id = 0; 5176 params.nav_entry_id = 0;
5145 params.did_create_new_entry = true; 5177 params.did_create_new_entry = true;
5146 params.url = url; 5178 params.url = url;
5147 params.transition = ui::PAGE_TRANSITION_LINK; 5179 params.transition = ui::PAGE_TRANSITION_LINK;
5148 params.should_update_history = true; 5180 params.should_update_history = true;
5149 params.gesture = NavigationGestureUser; 5181 params.gesture = NavigationGestureUser;
5150 params.is_post = false; 5182 params.is_post = false;
5151 params.page_state = PageState::CreateFromURL(url); 5183 params.page_state = PageState::CreateFromURL(url);
5152 params.was_within_same_page = false; 5184 params.was_within_same_page = false;
5153 params.security_info = "bogus security info!"; 5185 params.security_info = "bogus security info!";
5154 5186
5155 LoadCommittedDetails details; 5187 LoadCommittedDetailsObserver observer(contents());
5156 EXPECT_EQ(0, main_test_rfh()->GetProcess()->bad_msg_count()); 5188 EXPECT_EQ(0, main_test_rfh()->GetProcess()->bad_msg_count());
5157 EXPECT_TRUE( 5189 main_test_rfh()->PrepareForCommit();
5158 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details)); 5190 main_test_rfh()->SendNavigateWithParams(&params);
5159 5191
5160 SSLStatus default_ssl_status; 5192 SSLStatus default_ssl_status;
5161 EXPECT_EQ(default_ssl_status.security_style, 5193 EXPECT_EQ(default_ssl_status.security_style,
5162 details.ssl_status.security_style); 5194 observer.details().ssl_status.security_style);
5163 EXPECT_EQ(default_ssl_status.cert_id, details.ssl_status.cert_id); 5195 EXPECT_EQ(default_ssl_status.cert_id, observer.details().ssl_status.cert_id);
5164 EXPECT_EQ(default_ssl_status.cert_status, details.ssl_status.cert_status); 5196 EXPECT_EQ(default_ssl_status.cert_status,
5165 EXPECT_EQ(default_ssl_status.security_bits, details.ssl_status.security_bits); 5197 observer.details().ssl_status.cert_status);
5198 EXPECT_EQ(default_ssl_status.security_bits,
5199 observer.details().ssl_status.security_bits);
5166 EXPECT_EQ(default_ssl_status.connection_status, 5200 EXPECT_EQ(default_ssl_status.connection_status,
5167 details.ssl_status.connection_status); 5201 observer.details().ssl_status.connection_status);
5168 EXPECT_EQ(default_ssl_status.content_status, 5202 EXPECT_EQ(default_ssl_status.content_status,
5169 details.ssl_status.content_status); 5203 observer.details().ssl_status.content_status);
5170 EXPECT_EQ(0u, details.ssl_status.signed_certificate_timestamp_ids.size()); 5204 EXPECT_EQ(
5205 0u,
5206 observer.details().ssl_status.signed_certificate_timestamp_ids.size());
5171 5207
5172 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); 5208 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count());
5173 } 5209 }
5174 5210
5175 } // namespace content 5211 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698