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

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

Issue 2682193002: Convert NavigationController unit and browser tests to use the new navigation callbacks. (Closed)
Patch Set: Created 3 years, 10 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 9
10 #include <memory> 10 #include <memory>
11 #include <tuple> 11 #include <tuple>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "content/browser/frame_host/frame_navigation_entry.h" 23 #include "content/browser/frame_host/frame_navigation_entry.h"
24 #include "content/browser/frame_host/navigation_entry_impl.h" 24 #include "content/browser/frame_host/navigation_entry_impl.h"
25 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 25 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
26 #include "content/browser/frame_host/navigation_handle_impl.h"
26 #include "content/browser/frame_host/navigation_request.h" 27 #include "content/browser/frame_host/navigation_request.h"
27 #include "content/browser/frame_host/navigator.h" 28 #include "content/browser/frame_host/navigator.h"
28 #include "content/browser/frame_host/navigator_impl.h" 29 #include "content/browser/frame_host/navigator_impl.h"
29 #include "content/browser/site_instance_impl.h" 30 #include "content/browser/site_instance_impl.h"
30 #include "content/browser/web_contents/web_contents_impl.h" 31 #include "content/browser/web_contents/web_contents_impl.h"
31 #include "content/common/frame_messages.h" 32 #include "content/common/frame_messages.h"
32 #include "content/common/frame_owner_properties.h" 33 #include "content/common/frame_owner_properties.h"
33 #include "content/common/site_isolation_policy.h" 34 #include "content/common/site_isolation_policy.h"
34 #include "content/common/view_messages.h" 35 #include "content/common/view_messages.h"
35 #include "content/public/browser/navigation_details.h"
36 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
37 #include "content/public/browser/notification_types.h" 37 #include "content/public/browser/notification_types.h"
38 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/web_contents_delegate.h" 39 #include "content/public/browser/web_contents_delegate.h"
40 #include "content/public/browser/web_contents_observer.h" 40 #include "content/public/browser/web_contents_observer.h"
41 #include "content/public/common/browser_side_navigation_policy.h" 41 #include "content/public/common/browser_side_navigation_policy.h"
42 #include "content/public/common/page_state.h" 42 #include "content/public/common/page_state.h"
43 #include "content/public/common/page_type.h" 43 #include "content/public/common/page_type.h"
44 #include "content/public/common/resource_request_body.h" 44 #include "content/public/common/resource_request_body.h"
45 #include "content/public/common/url_constants.h" 45 #include "content/public/common/url_constants.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 304
305 // The number of times ShowRepostFormWarningDialog() was called. 305 // The number of times ShowRepostFormWarningDialog() was called.
306 int repost_form_warning_count_; 306 int repost_form_warning_count_;
307 }; 307 };
308 308
309 // Observer that records the LoadCommittedDetails from the most recent commit. 309 // Observer that records the LoadCommittedDetails from the most recent commit.
310 class LoadCommittedDetailsObserver : public WebContentsObserver { 310 class LoadCommittedDetailsObserver : public WebContentsObserver {
311 public: 311 public:
312 // Observes navigation for the specified |web_contents|. 312 // Observes navigation for the specified |web_contents|.
313 explicit LoadCommittedDetailsObserver(WebContents* web_contents) 313 explicit LoadCommittedDetailsObserver(WebContents* web_contents)
314 : WebContentsObserver(web_contents) {} 314 : WebContentsObserver(web_contents),
315 type_(NAVIGATION_TYPE_UNKNOWN),
316 is_in_page_(false),
317 is_main_frame_(false),
318 did_replace_entry_(false) {}
315 319
316 const LoadCommittedDetails& details() { return details_; } 320 NavigationType type() { return type_; }
321 const GURL& previous_url() { return previous_url_; }
322 bool is_in_page() { return is_in_page_; }
323 bool is_main_frame() { return is_main_frame_; }
324 bool did_replace_entry() { return did_replace_entry_; }
317 325
318 private: 326 private:
319 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, 327 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
320 const LoadCommittedDetails& details, 328 if (!navigation_handle->HasCommitted())
321 const FrameNavigateParams& params) override { 329 return;
322 details_ = details; 330
331 type_ = static_cast<NavigationHandleImpl*>(navigation_handle)->
332 navigation_type();
333 previous_url_ = navigation_handle->GetPreviousURL();
334 is_in_page_ = navigation_handle->IsSamePage();
335 is_main_frame_ = navigation_handle->IsInMainFrame();
336 did_replace_entry_ = navigation_handle->DidReplaceEntry();
323 } 337 }
324 338
325 LoadCommittedDetails details_; 339 NavigationType type_;
nasko 2017/02/09 00:29:11 nit: navigation_type_
jam 2017/02/09 01:15:03 Done.
340 GURL previous_url_;
341 bool is_in_page_;
342 bool is_main_frame_;
343 bool did_replace_entry_;
326 }; 344 };
327 345
328 // PlzNavigate 346 // PlzNavigate
329 // A NavigationControllerTest run with --enable-browser-side-navigation. 347 // A NavigationControllerTest run with --enable-browser-side-navigation.
330 class NavigationControllerTestWithBrowserSideNavigation 348 class NavigationControllerTestWithBrowserSideNavigation
331 : public NavigationControllerTest { 349 : public NavigationControllerTest {
332 public: 350 public:
333 void SetUp() override { 351 void SetUp() override {
334 EnableBrowserSideNavigation(); 352 EnableBrowserSideNavigation();
335 NavigationControllerTest::SetUp(); 353 NavigationControllerTest::SetUp();
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 params.nav_entry_id = entry_id; 2029 params.nav_entry_id = entry_id;
2012 params.did_create_new_entry = false; 2030 params.did_create_new_entry = false;
2013 2031
2014 EXPECT_EQ(0U, notifications.size()); 2032 EXPECT_EQ(0U, notifications.size());
2015 LoadCommittedDetailsObserver observer(contents()); 2033 LoadCommittedDetailsObserver observer(contents());
2016 main_test_rfh()->PrepareForCommit(); 2034 main_test_rfh()->PrepareForCommit();
2017 main_test_rfh()->SendNavigateWithParams(&params); 2035 main_test_rfh()->SendNavigateWithParams(&params);
2018 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2036 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2019 navigation_entry_committed_counter_ = 0; 2037 navigation_entry_committed_counter_ = 0;
2020 2038
2021 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type); 2039 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.type());
2022 EXPECT_EQ(controller.GetEntryCount(), 1); 2040 EXPECT_EQ(controller.GetEntryCount(), 1);
2023 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 2041 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
2024 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2042 EXPECT_TRUE(controller.GetLastCommittedEntry());
2025 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2043 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2026 EXPECT_FALSE(controller.GetPendingEntry()); 2044 EXPECT_FALSE(controller.GetPendingEntry());
2027 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2045 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2028 2046
2029 EXPECT_FALSE(controller.CanGoBack()); 2047 EXPECT_FALSE(controller.CanGoBack());
2030 EXPECT_FALSE(controller.CanGoForward()); 2048 EXPECT_FALSE(controller.CanGoForward());
2031 } 2049 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 params.did_create_new_entry = false; 2097 params.did_create_new_entry = false;
2080 params.method = "GET"; 2098 params.method = "GET";
2081 2099
2082 EXPECT_EQ(0U, notifications.size()); 2100 EXPECT_EQ(0U, notifications.size());
2083 LoadCommittedDetailsObserver observer(contents()); 2101 LoadCommittedDetailsObserver observer(contents());
2084 main_test_rfh()->PrepareForCommit(); 2102 main_test_rfh()->PrepareForCommit();
2085 main_test_rfh()->SendNavigateWithParams(&params); 2103 main_test_rfh()->SendNavigateWithParams(&params);
2086 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2104 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2087 navigation_entry_committed_counter_ = 0; 2105 navigation_entry_committed_counter_ = 0;
2088 2106
2089 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type); 2107 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.type());
2090 EXPECT_EQ(controller.GetEntryCount(), 1); 2108 EXPECT_EQ(controller.GetEntryCount(), 1);
2091 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 2109 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
2092 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2110 EXPECT_TRUE(controller.GetLastCommittedEntry());
2093 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2111 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2094 EXPECT_FALSE(controller.GetPendingEntry()); 2112 EXPECT_FALSE(controller.GetPendingEntry());
2095 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2113 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2096 EXPECT_FALSE(controller.GetVisibleEntry()->GetHasPostData()); 2114 EXPECT_FALSE(controller.GetVisibleEntry()->GetHasPostData());
2097 2115
2098 EXPECT_FALSE(controller.CanGoBack()); 2116 EXPECT_FALSE(controller.CanGoBack());
2099 EXPECT_FALSE(controller.CanGoForward()); 2117 EXPECT_FALSE(controller.CanGoForward());
(...skipping 30 matching lines...) Expand all
2130 params.page_state = PageState::CreateFromURL(url2); 2148 params.page_state = PageState::CreateFromURL(url2);
2131 2149
2132 LoadCommittedDetailsObserver observer(contents()); 2150 LoadCommittedDetailsObserver observer(contents());
2133 2151
2134 EXPECT_EQ(0U, notifications.size()); 2152 EXPECT_EQ(0U, notifications.size());
2135 main_test_rfh()->PrepareForCommit(); 2153 main_test_rfh()->PrepareForCommit();
2136 main_test_rfh()->SendNavigateWithParams(&params); 2154 main_test_rfh()->SendNavigateWithParams(&params);
2137 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2155 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2138 navigation_entry_committed_counter_ = 0; 2156 navigation_entry_committed_counter_ = 0;
2139 2157
2140 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.details().type); 2158 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.type());
2141 EXPECT_EQ(controller.GetEntryCount(), 1); 2159 EXPECT_EQ(controller.GetEntryCount(), 1);
2142 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 2160 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
2143 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2161 EXPECT_TRUE(controller.GetLastCommittedEntry());
2144 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2162 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2145 EXPECT_FALSE(controller.GetPendingEntry()); 2163 EXPECT_FALSE(controller.GetPendingEntry());
2146 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2164 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2147 2165
2148 EXPECT_FALSE(controller.CanGoBack()); 2166 EXPECT_FALSE(controller.CanGoBack());
2149 EXPECT_FALSE(controller.CanGoForward()); 2167 EXPECT_FALSE(controller.CanGoForward());
2150 } 2168 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2190 params.intended_as_new_entry = true; 2208 params.intended_as_new_entry = true;
2191 params.did_create_new_entry = false; 2209 params.did_create_new_entry = false;
2192 params.url = url1; 2210 params.url = url1;
2193 params.transition = ui::PAGE_TRANSITION_TYPED; 2211 params.transition = ui::PAGE_TRANSITION_TYPED;
2194 params.page_state = PageState::CreateFromURL(url1); 2212 params.page_state = PageState::CreateFromURL(url1);
2195 2213
2196 LoadCommittedDetailsObserver observer(contents()); 2214 LoadCommittedDetailsObserver observer(contents());
2197 2215
2198 main_test_rfh()->PrepareForCommit(); 2216 main_test_rfh()->PrepareForCommit();
2199 main_test_rfh()->SendNavigateWithParams(&params); 2217 main_test_rfh()->SendNavigateWithParams(&params);
2200 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.details().type); 2218 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.type());
2201 } 2219 }
2202 2220
2203 // Tests navigation via link click within a subframe. A new navigation entry 2221 // Tests navigation via link click within a subframe. A new navigation entry
2204 // should be created. 2222 // should be created.
2205 TEST_F(NavigationControllerTest, NewSubframe) { 2223 TEST_F(NavigationControllerTest, NewSubframe) {
2206 NavigationControllerImpl& controller = controller_impl(); 2224 NavigationControllerImpl& controller = controller_impl();
2207 TestNotificationTracker notifications; 2225 TestNotificationTracker notifications;
2208 RegisterForAllNavNotifications(&notifications, &controller); 2226 RegisterForAllNavNotifications(&notifications, &controller);
2209 2227
2210 const GURL url1("http://foo1"); 2228 const GURL url1("http://foo1");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 params.gesture = NavigationGestureUser; 2273 params.gesture = NavigationGestureUser;
2256 params.method = "GET"; 2274 params.method = "GET";
2257 params.page_state = PageState::CreateFromURL(url2); 2275 params.page_state = PageState::CreateFromURL(url2);
2258 2276
2259 LoadCommittedDetailsObserver observer(contents()); 2277 LoadCommittedDetailsObserver observer(contents());
2260 subframe->SendRendererInitiatedNavigationRequest(url2, true); 2278 subframe->SendRendererInitiatedNavigationRequest(url2, true);
2261 subframe->PrepareForCommit(); 2279 subframe->PrepareForCommit();
2262 subframe->SendNavigateWithParams(&params); 2280 subframe->SendNavigateWithParams(&params);
2263 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2281 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2264 navigation_entry_committed_counter_ = 0; 2282 navigation_entry_committed_counter_ = 0;
2265 EXPECT_EQ(url1, observer.details().previous_url); 2283 EXPECT_EQ(url1, observer.previous_url());
2266 EXPECT_FALSE(observer.details().is_in_page); 2284 EXPECT_FALSE(observer.is_in_page());
2267 EXPECT_FALSE(observer.details().is_main_frame); 2285 EXPECT_FALSE(observer.is_main_frame());
2268 2286
2269 // The new entry should be appended. 2287 // The new entry should be appended.
2270 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); 2288 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2271 EXPECT_EQ(2, controller.GetEntryCount()); 2289 EXPECT_EQ(2, controller.GetEntryCount());
2272 EXPECT_EQ(entry, observer.details().entry);
2273 2290
2274 // New entry should refer to the new page, but the old URL (entries only 2291 // New entry should refer to the new page, but the old URL (entries only
2275 // reflect the toplevel URL). 2292 // reflect the toplevel URL).
2276 EXPECT_EQ(url1, entry->GetURL()); 2293 EXPECT_EQ(url1, entry->GetURL());
2277 2294
2278 // The entry should have a subframe FrameNavigationEntry. 2295 // The entry should have a subframe FrameNavigationEntry.
2279 ASSERT_EQ(1U, entry->root_node()->children.size()); 2296 ASSERT_EQ(1U, entry->root_node()->children.size());
2280 EXPECT_EQ(url2, entry->root_node()->children[0]->frame_entry->url()); 2297 EXPECT_EQ(url2, entry->root_node()->children[0]->frame_entry->url());
2281 } 2298 }
2282 2299
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 self_params.page_state = PageState::CreateFromURL(url1); 2651 self_params.page_state = PageState::CreateFromURL(url1);
2635 self_params.was_within_same_page = true; 2652 self_params.was_within_same_page = true;
2636 2653
2637 LoadCommittedDetailsObserver observer(contents()); 2654 LoadCommittedDetailsObserver observer(contents());
2638 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false); 2655 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false);
2639 main_test_rfh()->PrepareForCommit(); 2656 main_test_rfh()->PrepareForCommit();
2640 main_test_rfh()->SendNavigateWithParams(&self_params); 2657 main_test_rfh()->SendNavigateWithParams(&self_params);
2641 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); 2658 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
2642 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2659 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2643 navigation_entry_committed_counter_ = 0; 2660 navigation_entry_committed_counter_ = 0;
2644 EXPECT_TRUE(observer.details().is_in_page); 2661 EXPECT_TRUE(observer.is_in_page());
2645 EXPECT_TRUE(observer.details().did_replace_entry); 2662 EXPECT_TRUE(observer.did_replace_entry());
2646 EXPECT_EQ(1, controller.GetEntryCount()); 2663 EXPECT_EQ(1, controller.GetEntryCount());
2647 2664
2648 // Fragment navigation to a new page. 2665 // Fragment navigation to a new page.
2649 const GURL url2("http://foo#a"); 2666 const GURL url2("http://foo#a");
2650 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2667 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2651 params.nav_entry_id = 0; 2668 params.nav_entry_id = 0;
2652 params.did_create_new_entry = true; 2669 params.did_create_new_entry = true;
2653 params.url = url2; 2670 params.url = url2;
2654 params.transition = ui::PAGE_TRANSITION_LINK; 2671 params.transition = ui::PAGE_TRANSITION_LINK;
2655 params.should_update_history = false; 2672 params.should_update_history = false;
2656 params.gesture = NavigationGestureUser; 2673 params.gesture = NavigationGestureUser;
2657 params.method = "GET"; 2674 params.method = "GET";
2658 params.page_state = PageState::CreateFromURL(url2); 2675 params.page_state = PageState::CreateFromURL(url2);
2659 params.was_within_same_page = true; 2676 params.was_within_same_page = true;
2660 2677
2661 // This should generate a new entry. 2678 // This should generate a new entry.
2662 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); 2679 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false);
2663 main_test_rfh()->PrepareForCommit(); 2680 main_test_rfh()->PrepareForCommit();
2664 main_test_rfh()->SendNavigateWithParams(&params); 2681 main_test_rfh()->SendNavigateWithParams(&params);
2665 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); 2682 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
2666 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2683 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2667 navigation_entry_committed_counter_ = 0; 2684 navigation_entry_committed_counter_ = 0;
2668 EXPECT_TRUE(observer.details().is_in_page); 2685 EXPECT_TRUE(observer.is_in_page());
2669 EXPECT_FALSE(observer.details().did_replace_entry); 2686 EXPECT_FALSE(observer.did_replace_entry());
2670 EXPECT_EQ(2, controller.GetEntryCount()); 2687 EXPECT_EQ(2, controller.GetEntryCount());
2671 2688
2672 // Go back one. 2689 // Go back one.
2673 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); 2690 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params);
2674 controller.GoBack(); 2691 controller.GoBack();
2675 back_params.url = url1; 2692 back_params.url = url1;
2676 back_params.nav_entry_id = entry1->GetUniqueID(); 2693 back_params.nav_entry_id = entry1->GetUniqueID();
2677 back_params.did_create_new_entry = false; 2694 back_params.did_create_new_entry = false;
2678 main_test_rfh()->PrepareForCommit(); 2695 main_test_rfh()->PrepareForCommit();
2679 main_test_rfh()->SendNavigateWithParams(&back_params); 2696 main_test_rfh()->SendNavigateWithParams(&back_params);
2680 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2697 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2681 navigation_entry_committed_counter_ = 0; 2698 navigation_entry_committed_counter_ = 0;
2682 EXPECT_TRUE(observer.details().is_in_page); 2699 EXPECT_TRUE(observer.is_in_page());
2683 EXPECT_EQ(2, controller.GetEntryCount()); 2700 EXPECT_EQ(2, controller.GetEntryCount());
2684 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2701 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2685 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); 2702 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
2686 2703
2687 // Go forward. 2704 // Go forward.
2688 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); 2705 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params);
2689 controller.GoForward(); 2706 controller.GoForward();
2690 forward_params.url = url2; 2707 forward_params.url = url2;
2691 forward_params.nav_entry_id = entry2->GetUniqueID(); 2708 forward_params.nav_entry_id = entry2->GetUniqueID();
2692 forward_params.did_create_new_entry = false; 2709 forward_params.did_create_new_entry = false;
2693 main_test_rfh()->PrepareForCommit(); 2710 main_test_rfh()->PrepareForCommit();
2694 main_test_rfh()->SendNavigateWithParams(&forward_params); 2711 main_test_rfh()->SendNavigateWithParams(&forward_params);
2695 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2712 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2696 navigation_entry_committed_counter_ = 0; 2713 navigation_entry_committed_counter_ = 0;
2697 EXPECT_TRUE(observer.details().is_in_page); 2714 EXPECT_TRUE(observer.is_in_page());
2698 EXPECT_EQ(2, controller.GetEntryCount()); 2715 EXPECT_EQ(2, controller.GetEntryCount());
2699 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2716 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2700 EXPECT_EQ(forward_params.url, 2717 EXPECT_EQ(forward_params.url,
2701 controller.GetVisibleEntry()->GetURL()); 2718 controller.GetVisibleEntry()->GetURL());
2702 2719
2703 // Now go back and forward again. This is to work around a bug where we would 2720 // Now go back and forward again. This is to work around a bug where we would
2704 // compare the incoming URL with the last committed entry rather than the 2721 // compare the incoming URL with the last committed entry rather than the
2705 // one identified by an existing page ID. This would result in the second URL 2722 // one identified by an existing page ID. This would result in the second URL
2706 // losing the reference fragment when you navigate away from it and then back. 2723 // losing the reference fragment when you navigate away from it and then back.
2707 controller.GoBack(); 2724 controller.GoBack();
2708 main_test_rfh()->PrepareForCommit(); 2725 main_test_rfh()->PrepareForCommit();
2709 main_test_rfh()->SendNavigateWithParams(&back_params); 2726 main_test_rfh()->SendNavigateWithParams(&back_params);
2710 controller.GoForward(); 2727 controller.GoForward();
2711 main_test_rfh()->PrepareForCommit(); 2728 main_test_rfh()->PrepareForCommit();
2712 main_test_rfh()->SendNavigateWithParams(&forward_params); 2729 main_test_rfh()->SendNavigateWithParams(&forward_params);
2713 EXPECT_EQ(forward_params.url, 2730 EXPECT_EQ(forward_params.url,
2714 controller.GetVisibleEntry()->GetURL()); 2731 controller.GetVisibleEntry()->GetURL());
2715 2732
2716 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. 2733 // Finally, navigate to an unrelated URL to make sure in_page is not sticky.
2717 const GURL url3("http://bar"); 2734 const GURL url3("http://bar");
2718 params.nav_entry_id = 0; 2735 params.nav_entry_id = 0;
2719 params.did_create_new_entry = true; 2736 params.did_create_new_entry = true;
2720 params.url = url3; 2737 params.url = url3;
2738 params.was_within_same_page = false;
2721 navigation_entry_committed_counter_ = 0; 2739 navigation_entry_committed_counter_ = 0;
2722 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); 2740 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false);
2723 main_test_rfh()->PrepareForCommit(); 2741 main_test_rfh()->PrepareForCommit();
2724 main_test_rfh()->SendNavigateWithParams(&params); 2742 main_test_rfh()->SendNavigateWithParams(&params);
2725 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2743 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2726 navigation_entry_committed_counter_ = 0; 2744 navigation_entry_committed_counter_ = 0;
2727 EXPECT_FALSE(observer.details().is_in_page); 2745 EXPECT_FALSE(observer.is_in_page());
2728 EXPECT_EQ(3, controller.GetEntryCount()); 2746 EXPECT_EQ(3, controller.GetEntryCount());
2729 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2747 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2730 } 2748 }
2731 2749
2732 TEST_F(NavigationControllerTest, InPage_Replace) { 2750 TEST_F(NavigationControllerTest, InPage_Replace) {
2733 NavigationControllerImpl& controller = controller_impl(); 2751 NavigationControllerImpl& controller = controller_impl();
2734 TestNotificationTracker notifications; 2752 TestNotificationTracker notifications;
2735 RegisterForAllNavNotifications(&notifications, &controller); 2753 RegisterForAllNavNotifications(&notifications, &controller);
2736 2754
2737 // Main page. 2755 // Main page.
(...skipping 15 matching lines...) Expand all
2753 params.page_state = PageState::CreateFromURL(url2); 2771 params.page_state = PageState::CreateFromURL(url2);
2754 params.was_within_same_page = true; 2772 params.was_within_same_page = true;
2755 2773
2756 // This should NOT generate a new entry, nor prune the list. 2774 // This should NOT generate a new entry, nor prune the list.
2757 LoadCommittedDetailsObserver observer(contents()); 2775 LoadCommittedDetailsObserver observer(contents());
2758 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); 2776 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false);
2759 main_test_rfh()->PrepareForCommit(); 2777 main_test_rfh()->PrepareForCommit();
2760 main_test_rfh()->SendNavigateWithParams(&params); 2778 main_test_rfh()->SendNavigateWithParams(&params);
2761 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2779 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2762 navigation_entry_committed_counter_ = 0; 2780 navigation_entry_committed_counter_ = 0;
2763 EXPECT_TRUE(observer.details().is_in_page); 2781 EXPECT_TRUE(observer.is_in_page());
2764 EXPECT_TRUE(observer.details().did_replace_entry); 2782 EXPECT_TRUE(observer.did_replace_entry());
2765 EXPECT_EQ(1, controller.GetEntryCount()); 2783 EXPECT_EQ(1, controller.GetEntryCount());
2766 } 2784 }
2767 2785
2768 // Tests for http://crbug.com/40395 2786 // Tests for http://crbug.com/40395
2769 // Simulates this: 2787 // Simulates this:
2770 // <script> 2788 // <script>
2771 // window.location.replace("#a"); 2789 // window.location.replace("#a");
2772 // window.location='http://foo3/'; 2790 // window.location='http://foo3/';
2773 // </script> 2791 // </script>
2774 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { 2792 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2807 params.page_state = PageState::CreateFromURL(url); 2825 params.page_state = PageState::CreateFromURL(url);
2808 params.was_within_same_page = true; 2826 params.was_within_same_page = true;
2809 2827
2810 // This should NOT generate a new entry, nor prune the list. 2828 // This should NOT generate a new entry, nor prune the list.
2811 LoadCommittedDetailsObserver observer(contents()); 2829 LoadCommittedDetailsObserver observer(contents());
2812 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); 2830 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
2813 main_test_rfh()->PrepareForCommit(); 2831 main_test_rfh()->PrepareForCommit();
2814 main_test_rfh()->SendNavigateWithParams(&params); 2832 main_test_rfh()->SendNavigateWithParams(&params);
2815 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2833 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2816 navigation_entry_committed_counter_ = 0; 2834 navigation_entry_committed_counter_ = 0;
2817 EXPECT_TRUE(observer.details().is_in_page); 2835 EXPECT_TRUE(observer.is_in_page());
2818 EXPECT_TRUE(observer.details().did_replace_entry); 2836 EXPECT_TRUE(observer.did_replace_entry());
2819 EXPECT_EQ(2, controller.GetEntryCount()); 2837 EXPECT_EQ(2, controller.GetEntryCount());
2820 } 2838 }
2821 2839
2822 // Perform a client redirect to a new page. 2840 // Perform a client redirect to a new page.
2823 { 2841 {
2824 const GURL url("http://foo3/"); 2842 const GURL url("http://foo3/");
2825 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2843 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2826 params.nav_entry_id = 0; 2844 params.nav_entry_id = 0;
2827 params.did_create_new_entry = true; 2845 params.did_create_new_entry = true;
2828 params.url = url; 2846 params.url = url;
2829 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 2847 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
2830 params.redirects.push_back(GURL("http://foo2/#a")); 2848 params.redirects.push_back(GURL("http://foo2/#a"));
2831 params.redirects.push_back(url); 2849 params.redirects.push_back(url);
2832 params.should_update_history = true; 2850 params.should_update_history = true;
2833 params.gesture = NavigationGestureUnknown; 2851 params.gesture = NavigationGestureUnknown;
2834 params.method = "GET"; 2852 params.method = "GET";
2835 params.page_state = PageState::CreateFromURL(url); 2853 params.page_state = PageState::CreateFromURL(url);
2836 2854
2837 // This SHOULD generate a new entry. 2855 // This SHOULD generate a new entry.
2838 LoadCommittedDetailsObserver observer(contents()); 2856 LoadCommittedDetailsObserver observer(contents());
2839 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); 2857 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
2840 main_test_rfh()->PrepareForCommit(); 2858 main_test_rfh()->PrepareForCommit();
2841 main_test_rfh()->SendNavigateWithParams(&params); 2859 main_test_rfh()->SendNavigateWithParams(&params);
2842 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2860 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2843 navigation_entry_committed_counter_ = 0; 2861 navigation_entry_committed_counter_ = 0;
2844 EXPECT_FALSE(observer.details().is_in_page); 2862 EXPECT_FALSE(observer.is_in_page());
2845 EXPECT_EQ(3, controller.GetEntryCount()); 2863 EXPECT_EQ(3, controller.GetEntryCount());
2846 } 2864 }
2847 2865
2848 // Verify that BACK brings us back to http://foo2/. 2866 // Verify that BACK brings us back to http://foo2/.
2849 { 2867 {
2850 const GURL url("http://foo2/"); 2868 const GURL url("http://foo2/");
2851 controller.GoBack(); 2869 controller.GoBack();
2852 int entry_id = controller.GetPendingEntry()->GetUniqueID(); 2870 int entry_id = controller.GetPendingEntry()->GetUniqueID();
2853 main_test_rfh()->PrepareForCommit(); 2871 main_test_rfh()->PrepareForCommit();
2854 main_test_rfh()->SendNavigate(entry_id, false, url); 2872 main_test_rfh()->SendNavigate(entry_id, false, url);
(...skipping 2234 matching lines...) Expand 10 before | Expand all | Expand 10 after
5089 params.url_is_unreachable = true; 5107 params.url_is_unreachable = true;
5090 5108
5091 // Navigate to new page. 5109 // Navigate to new page.
5092 { 5110 {
5093 LoadCommittedDetailsObserver observer(contents()); 5111 LoadCommittedDetailsObserver observer(contents());
5094 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); 5112 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
5095 main_test_rfh()->PrepareForCommit(); 5113 main_test_rfh()->PrepareForCommit();
5096 main_test_rfh()->SendNavigateWithParams(&params); 5114 main_test_rfh()->SendNavigateWithParams(&params);
5097 EXPECT_EQ(PAGE_TYPE_ERROR, 5115 EXPECT_EQ(PAGE_TYPE_ERROR,
5098 controller_impl().GetLastCommittedEntry()->GetPageType()); 5116 controller_impl().GetLastCommittedEntry()->GetPageType());
5099 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.details().type); 5117 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.type());
5100 } 5118 }
5101 5119
5102 // Navigate to existing page. 5120 // Navigate to existing page.
5103 { 5121 {
5104 params.did_create_new_entry = false; 5122 params.did_create_new_entry = false;
5105 LoadCommittedDetailsObserver observer(contents()); 5123 LoadCommittedDetailsObserver observer(contents());
5106 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); 5124 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
5107 main_test_rfh()->PrepareForCommit(); 5125 main_test_rfh()->PrepareForCommit();
5108 main_test_rfh()->SendNavigateWithParams(&params); 5126 main_test_rfh()->SendNavigateWithParams(&params);
5109 EXPECT_EQ(PAGE_TYPE_ERROR, 5127 EXPECT_EQ(PAGE_TYPE_ERROR,
5110 controller_impl().GetLastCommittedEntry()->GetPageType()); 5128 controller_impl().GetLastCommittedEntry()->GetPageType());
5111 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.details().type); 5129 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.type());
5112 } 5130 }
5113 5131
5114 // Navigate to same page. 5132 // Navigate to same page.
5115 // Note: The call to LoadURL() creates a pending entry in order to trigger the 5133 // Note: The call to LoadURL() creates a pending entry in order to trigger the
5116 // same-page transition. 5134 // same-page transition.
5117 controller_impl().LoadURL( 5135 controller_impl().LoadURL(
5118 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 5136 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
5119 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID(); 5137 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID();
5120 params.transition = ui::PAGE_TRANSITION_TYPED; 5138 params.transition = ui::PAGE_TRANSITION_TYPED;
5121 { 5139 {
5122 LoadCommittedDetailsObserver observer(contents()); 5140 LoadCommittedDetailsObserver observer(contents());
5123 main_test_rfh()->PrepareForCommit(); 5141 main_test_rfh()->PrepareForCommit();
5124 main_test_rfh()->SendNavigateWithParams(&params); 5142 main_test_rfh()->SendNavigateWithParams(&params);
5125 EXPECT_EQ(PAGE_TYPE_ERROR, 5143 EXPECT_EQ(PAGE_TYPE_ERROR,
5126 controller_impl().GetLastCommittedEntry()->GetPageType()); 5144 controller_impl().GetLastCommittedEntry()->GetPageType());
5127 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type); 5145 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.type());
5128 } 5146 }
5129 5147
5130 // Navigate in page. 5148 // Navigate in page.
5131 params.url = GURL("http://foo#foo"); 5149 params.url = GURL("http://foo#foo");
5132 params.transition = ui::PAGE_TRANSITION_LINK; 5150 params.transition = ui::PAGE_TRANSITION_LINK;
5133 params.was_within_same_page = true; 5151 params.was_within_same_page = true;
5134 { 5152 {
5135 LoadCommittedDetailsObserver observer(contents()); 5153 LoadCommittedDetailsObserver observer(contents());
5136 main_test_rfh()->SendRendererInitiatedNavigationRequest(params.url, false); 5154 main_test_rfh()->SendRendererInitiatedNavigationRequest(params.url, false);
5137 main_test_rfh()->PrepareForCommit(); 5155 main_test_rfh()->PrepareForCommit();
5138 main_test_rfh()->SendNavigateWithParams(&params); 5156 main_test_rfh()->SendNavigateWithParams(&params);
5139 EXPECT_EQ(PAGE_TYPE_ERROR, 5157 EXPECT_EQ(PAGE_TYPE_ERROR,
5140 controller_impl().GetLastCommittedEntry()->GetPageType()); 5158 controller_impl().GetLastCommittedEntry()->GetPageType());
5141 EXPECT_TRUE(observer.details().is_in_page); 5159 EXPECT_TRUE(observer.is_in_page());
5142 } 5160 }
5143 } 5161 }
5144 5162
5145 // Tests that if a stale navigation comes back from the renderer, it is properly 5163 // Tests that if a stale navigation comes back from the renderer, it is properly
5146 // resurrected. 5164 // resurrected.
5147 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) { 5165 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) {
5148 NavigationControllerImpl& controller = controller_impl(); 5166 NavigationControllerImpl& controller = controller_impl();
5149 TestNotificationTracker notifications; 5167 TestNotificationTracker notifications;
5150 RegisterForAllNavNotifications(&notifications, &controller); 5168 RegisterForAllNavNotifications(&notifications, &controller);
5151 5169
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
5280 main_test_rfh()->SimulateNavigationStart(url_1); 5298 main_test_rfh()->SimulateNavigationStart(url_1);
5281 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); 5299 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL());
5282 EXPECT_EQ(ReloadType::NONE, last_reload_type_); 5300 EXPECT_EQ(ReloadType::NONE, last_reload_type_);
5283 5301
5284 main_test_rfh()->SimulateNavigationCommit(url_2); 5302 main_test_rfh()->SimulateNavigationCommit(url_2);
5285 main_test_rfh()->SimulateNavigationCommit(url_1); 5303 main_test_rfh()->SimulateNavigationCommit(url_1);
5286 main_test_rfh()->SimulateNavigationCommit(url_1); 5304 main_test_rfh()->SimulateNavigationCommit(url_1);
5287 } 5305 }
5288 5306
5289 } // namespace content 5307 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698