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

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: merge 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 navigation_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 navigation_type() { return navigation_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 navigation_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 navigation_type_;
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.navigation_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.navigation_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.navigation_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.navigation_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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 self_params.document_sequence_number); 2655 self_params.document_sequence_number);
2639 self_params.was_within_same_page = true; 2656 self_params.was_within_same_page = true;
2640 2657
2641 LoadCommittedDetailsObserver observer(contents()); 2658 LoadCommittedDetailsObserver observer(contents());
2642 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false); 2659 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false);
2643 main_test_rfh()->PrepareForCommit(); 2660 main_test_rfh()->PrepareForCommit();
2644 main_test_rfh()->SendNavigateWithParams(&self_params); 2661 main_test_rfh()->SendNavigateWithParams(&self_params);
2645 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); 2662 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
2646 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2663 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2647 navigation_entry_committed_counter_ = 0; 2664 navigation_entry_committed_counter_ = 0;
2648 EXPECT_TRUE(observer.details().is_in_page); 2665 EXPECT_TRUE(observer.is_in_page());
2649 EXPECT_TRUE(observer.details().did_replace_entry); 2666 EXPECT_TRUE(observer.did_replace_entry());
2650 EXPECT_EQ(1, controller.GetEntryCount()); 2667 EXPECT_EQ(1, controller.GetEntryCount());
2651 2668
2652 // Fragment navigation to a new page. 2669 // Fragment navigation to a new page.
2653 const GURL url2("http://foo#a"); 2670 const GURL url2("http://foo#a");
2654 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2671 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2655 params.nav_entry_id = 0; 2672 params.nav_entry_id = 0;
2656 params.did_create_new_entry = true; 2673 params.did_create_new_entry = true;
2657 params.url = url2; 2674 params.url = url2;
2658 params.transition = ui::PAGE_TRANSITION_LINK; 2675 params.transition = ui::PAGE_TRANSITION_LINK;
2659 params.should_update_history = false; 2676 params.should_update_history = false;
2660 params.gesture = NavigationGestureUser; 2677 params.gesture = NavigationGestureUser;
2661 params.method = "GET"; 2678 params.method = "GET";
2662 params.item_sequence_number = GenerateSequenceNumber(); 2679 params.item_sequence_number = GenerateSequenceNumber();
2663 params.document_sequence_number = self_params.document_sequence_number; 2680 params.document_sequence_number = self_params.document_sequence_number;
2664 params.page_state = PageState::CreateForTestingWithSequenceNumbers( 2681 params.page_state = PageState::CreateForTestingWithSequenceNumbers(
2665 url2, params.item_sequence_number, params.document_sequence_number); 2682 url2, params.item_sequence_number, params.document_sequence_number);
2666 params.was_within_same_page = true; 2683 params.was_within_same_page = true;
2667 2684
2668 // This should generate a new entry. 2685 // This should generate a new entry.
2669 main_test_rfh()->SendNavigateWithParams(&params); 2686 main_test_rfh()->SendNavigateWithParams(&params);
2670 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); 2687 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
2671 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2688 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2672 navigation_entry_committed_counter_ = 0; 2689 navigation_entry_committed_counter_ = 0;
2673 EXPECT_TRUE(observer.details().is_in_page); 2690 EXPECT_TRUE(observer.is_in_page());
2674 EXPECT_FALSE(observer.details().did_replace_entry); 2691 EXPECT_FALSE(observer.did_replace_entry());
2675 EXPECT_EQ(2, controller.GetEntryCount()); 2692 EXPECT_EQ(2, controller.GetEntryCount());
2676 2693
2677 // Go back one. 2694 // Go back one.
2678 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(self_params); 2695 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(self_params);
2679 controller.GoBack(); 2696 controller.GoBack();
2680 back_params.nav_entry_id = entry1->GetUniqueID(); 2697 back_params.nav_entry_id = entry1->GetUniqueID();
2681 back_params.did_create_new_entry = false; 2698 back_params.did_create_new_entry = false;
2682 main_test_rfh()->SendNavigateWithParams(&back_params); 2699 main_test_rfh()->SendNavigateWithParams(&back_params);
2683 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2700 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2684 navigation_entry_committed_counter_ = 0; 2701 navigation_entry_committed_counter_ = 0;
2685 EXPECT_TRUE(observer.details().is_in_page); 2702 EXPECT_TRUE(observer.is_in_page());
2686 EXPECT_EQ(2, controller.GetEntryCount()); 2703 EXPECT_EQ(2, controller.GetEntryCount());
2687 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2704 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2688 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); 2705 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
2689 2706
2690 // Go forward. 2707 // Go forward.
2691 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); 2708 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params);
2692 controller.GoForward(); 2709 controller.GoForward();
2693 forward_params.nav_entry_id = entry2->GetUniqueID(); 2710 forward_params.nav_entry_id = entry2->GetUniqueID();
2694 forward_params.did_create_new_entry = false; 2711 forward_params.did_create_new_entry = false;
2695 main_test_rfh()->SendNavigateWithParams(&forward_params); 2712 main_test_rfh()->SendNavigateWithParams(&forward_params);
2696 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2713 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2697 navigation_entry_committed_counter_ = 0; 2714 navigation_entry_committed_counter_ = 0;
2698 EXPECT_TRUE(observer.details().is_in_page); 2715 EXPECT_TRUE(observer.is_in_page());
2699 EXPECT_EQ(2, controller.GetEntryCount()); 2716 EXPECT_EQ(2, controller.GetEntryCount());
2700 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2717 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2701 EXPECT_EQ(forward_params.url, 2718 EXPECT_EQ(forward_params.url,
2702 controller.GetVisibleEntry()->GetURL()); 2719 controller.GetVisibleEntry()->GetURL());
2703 2720
2704 // Now go back and forward again. This is to work around a bug where we would 2721 // Now go back and forward again. This is to work around a bug where we would
2705 // compare the incoming URL with the last committed entry rather than the 2722 // compare the incoming URL with the last committed entry rather than the
2706 // one identified by an existing page ID. This would result in the second URL 2723 // one identified by an existing page ID. This would result in the second URL
2707 // losing the reference fragment when you navigate away from it and then back. 2724 // losing the reference fragment when you navigate away from it and then back.
2708 controller.GoBack(); 2725 controller.GoBack();
(...skipping 11 matching lines...) Expand all
2720 params.item_sequence_number = 0; 2737 params.item_sequence_number = 0;
2721 params.document_sequence_number = 0; 2738 params.document_sequence_number = 0;
2722 params.page_state = PageState::CreateFromURL(url3); 2739 params.page_state = PageState::CreateFromURL(url3);
2723 params.was_within_same_page = false; 2740 params.was_within_same_page = false;
2724 navigation_entry_committed_counter_ = 0; 2741 navigation_entry_committed_counter_ = 0;
2725 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); 2742 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false);
2726 main_test_rfh()->PrepareForCommit(); 2743 main_test_rfh()->PrepareForCommit();
2727 main_test_rfh()->SendNavigateWithParams(&params); 2744 main_test_rfh()->SendNavigateWithParams(&params);
2728 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2745 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2729 navigation_entry_committed_counter_ = 0; 2746 navigation_entry_committed_counter_ = 0;
2730 EXPECT_FALSE(observer.details().is_in_page); 2747 EXPECT_FALSE(observer.is_in_page());
2731 EXPECT_EQ(3, controller.GetEntryCount()); 2748 EXPECT_EQ(3, controller.GetEntryCount());
2732 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2749 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2733 } 2750 }
2734 2751
2735 TEST_F(NavigationControllerTest, InPage_Replace) { 2752 TEST_F(NavigationControllerTest, InPage_Replace) {
2736 NavigationControllerImpl& controller = controller_impl(); 2753 NavigationControllerImpl& controller = controller_impl();
2737 TestNotificationTracker notifications; 2754 TestNotificationTracker notifications;
2738 RegisterForAllNavNotifications(&notifications, &controller); 2755 RegisterForAllNavNotifications(&notifications, &controller);
2739 2756
2740 // Main page. 2757 // Main page.
(...skipping 13 matching lines...) Expand all
2754 params.gesture = NavigationGestureUser; 2771 params.gesture = NavigationGestureUser;
2755 params.method = "GET"; 2772 params.method = "GET";
2756 params.page_state = PageState::CreateFromURL(url2); 2773 params.page_state = PageState::CreateFromURL(url2);
2757 params.was_within_same_page = true; 2774 params.was_within_same_page = true;
2758 2775
2759 // This should NOT generate a new entry, nor prune the list. 2776 // This should NOT generate a new entry, nor prune the list.
2760 LoadCommittedDetailsObserver observer(contents()); 2777 LoadCommittedDetailsObserver observer(contents());
2761 main_test_rfh()->SendNavigateWithParams(&params); 2778 main_test_rfh()->SendNavigateWithParams(&params);
2762 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2779 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2763 navigation_entry_committed_counter_ = 0; 2780 navigation_entry_committed_counter_ = 0;
2764 EXPECT_TRUE(observer.details().is_in_page); 2781 EXPECT_TRUE(observer.is_in_page());
2765 EXPECT_TRUE(observer.details().did_replace_entry); 2782 EXPECT_TRUE(observer.did_replace_entry());
2766 EXPECT_EQ(1, controller.GetEntryCount()); 2783 EXPECT_EQ(1, controller.GetEntryCount());
2767 } 2784 }
2768 2785
2769 // Tests for http://crbug.com/40395 2786 // Tests for http://crbug.com/40395
2770 // Simulates this: 2787 // Simulates this:
2771 // <script> 2788 // <script>
2772 // window.location.replace("#a"); 2789 // window.location.replace("#a");
2773 // window.location='http://foo3/'; 2790 // window.location='http://foo3/';
2774 // </script> 2791 // </script>
2775 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { 2792 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) {
(...skipping 30 matching lines...) Expand all
2806 params.gesture = NavigationGestureUnknown; 2823 params.gesture = NavigationGestureUnknown;
2807 params.method = "GET"; 2824 params.method = "GET";
2808 params.page_state = PageState::CreateFromURL(url); 2825 params.page_state = PageState::CreateFromURL(url);
2809 params.was_within_same_page = true; 2826 params.was_within_same_page = true;
2810 2827
2811 // This should NOT generate a new entry, nor prune the list. 2828 // This should NOT generate a new entry, nor prune the list.
2812 LoadCommittedDetailsObserver observer(contents()); 2829 LoadCommittedDetailsObserver observer(contents());
2813 main_test_rfh()->SendNavigateWithParams(&params); 2830 main_test_rfh()->SendNavigateWithParams(&params);
2814 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2831 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2815 navigation_entry_committed_counter_ = 0; 2832 navigation_entry_committed_counter_ = 0;
2816 EXPECT_TRUE(observer.details().is_in_page); 2833 EXPECT_TRUE(observer.is_in_page());
2817 EXPECT_TRUE(observer.details().did_replace_entry); 2834 EXPECT_TRUE(observer.did_replace_entry());
2818 EXPECT_EQ(2, controller.GetEntryCount()); 2835 EXPECT_EQ(2, controller.GetEntryCount());
2819 } 2836 }
2820 2837
2821 // Perform a client redirect to a new page. 2838 // Perform a client redirect to a new page.
2822 { 2839 {
2823 const GURL url("http://foo3/"); 2840 const GURL url("http://foo3/");
2824 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2841 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2825 params.nav_entry_id = 0; 2842 params.nav_entry_id = 0;
2826 params.did_create_new_entry = true; 2843 params.did_create_new_entry = true;
2827 params.url = url; 2844 params.url = url;
2828 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 2845 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
2829 params.redirects.push_back(GURL("http://foo2/#a")); 2846 params.redirects.push_back(GURL("http://foo2/#a"));
2830 params.redirects.push_back(url); 2847 params.redirects.push_back(url);
2831 params.should_update_history = true; 2848 params.should_update_history = true;
2832 params.gesture = NavigationGestureUnknown; 2849 params.gesture = NavigationGestureUnknown;
2833 params.method = "GET"; 2850 params.method = "GET";
2834 params.page_state = PageState::CreateFromURL(url); 2851 params.page_state = PageState::CreateFromURL(url);
2835 2852
2836 // This SHOULD generate a new entry. 2853 // This SHOULD generate a new entry.
2837 LoadCommittedDetailsObserver observer(contents()); 2854 LoadCommittedDetailsObserver observer(contents());
2838 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); 2855 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
2839 main_test_rfh()->PrepareForCommit(); 2856 main_test_rfh()->PrepareForCommit();
2840 main_test_rfh()->SendNavigateWithParams(&params); 2857 main_test_rfh()->SendNavigateWithParams(&params);
2841 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2858 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2842 navigation_entry_committed_counter_ = 0; 2859 navigation_entry_committed_counter_ = 0;
2843 EXPECT_FALSE(observer.details().is_in_page); 2860 EXPECT_FALSE(observer.is_in_page());
2844 EXPECT_EQ(3, controller.GetEntryCount()); 2861 EXPECT_EQ(3, controller.GetEntryCount());
2845 } 2862 }
2846 2863
2847 // Verify that BACK brings us back to http://foo2/. 2864 // Verify that BACK brings us back to http://foo2/.
2848 { 2865 {
2849 const GURL url("http://foo2/"); 2866 const GURL url("http://foo2/");
2850 controller.GoBack(); 2867 controller.GoBack();
2851 int entry_id = controller.GetPendingEntry()->GetUniqueID(); 2868 int entry_id = controller.GetPendingEntry()->GetUniqueID();
2852 main_test_rfh()->PrepareForCommit(); 2869 main_test_rfh()->PrepareForCommit();
2853 main_test_rfh()->SendNavigate(entry_id, false, url); 2870 main_test_rfh()->SendNavigate(entry_id, false, url);
(...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after
5082 params.url_is_unreachable = true; 5099 params.url_is_unreachable = true;
5083 5100
5084 // Navigate to new page. 5101 // Navigate to new page.
5085 { 5102 {
5086 LoadCommittedDetailsObserver observer(contents()); 5103 LoadCommittedDetailsObserver observer(contents());
5087 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); 5104 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
5088 main_test_rfh()->PrepareForCommit(); 5105 main_test_rfh()->PrepareForCommit();
5089 main_test_rfh()->SendNavigateWithParams(&params); 5106 main_test_rfh()->SendNavigateWithParams(&params);
5090 EXPECT_EQ(PAGE_TYPE_ERROR, 5107 EXPECT_EQ(PAGE_TYPE_ERROR,
5091 controller_impl().GetLastCommittedEntry()->GetPageType()); 5108 controller_impl().GetLastCommittedEntry()->GetPageType());
5092 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.details().type); 5109 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.navigation_type());
5093 } 5110 }
5094 5111
5095 // Navigate to existing page. 5112 // Navigate to existing page.
5096 { 5113 {
5097 params.did_create_new_entry = false; 5114 params.did_create_new_entry = false;
5098 LoadCommittedDetailsObserver observer(contents()); 5115 LoadCommittedDetailsObserver observer(contents());
5099 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); 5116 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
5100 main_test_rfh()->PrepareForCommit(); 5117 main_test_rfh()->PrepareForCommit();
5101 main_test_rfh()->SendNavigateWithParams(&params); 5118 main_test_rfh()->SendNavigateWithParams(&params);
5102 EXPECT_EQ(PAGE_TYPE_ERROR, 5119 EXPECT_EQ(PAGE_TYPE_ERROR,
5103 controller_impl().GetLastCommittedEntry()->GetPageType()); 5120 controller_impl().GetLastCommittedEntry()->GetPageType());
5104 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.details().type); 5121 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.navigation_type());
5105 } 5122 }
5106 5123
5107 // Navigate to same page. 5124 // Navigate to same page.
5108 // Note: The call to LoadURL() creates a pending entry in order to trigger the 5125 // Note: The call to LoadURL() creates a pending entry in order to trigger the
5109 // same-page transition. 5126 // same-page transition.
5110 controller_impl().LoadURL( 5127 controller_impl().LoadURL(
5111 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 5128 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
5112 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID(); 5129 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID();
5113 params.transition = ui::PAGE_TRANSITION_TYPED; 5130 params.transition = ui::PAGE_TRANSITION_TYPED;
5114 { 5131 {
5115 LoadCommittedDetailsObserver observer(contents()); 5132 LoadCommittedDetailsObserver observer(contents());
5116 main_test_rfh()->PrepareForCommit(); 5133 main_test_rfh()->PrepareForCommit();
5117 main_test_rfh()->SendNavigateWithParams(&params); 5134 main_test_rfh()->SendNavigateWithParams(&params);
5118 EXPECT_EQ(PAGE_TYPE_ERROR, 5135 EXPECT_EQ(PAGE_TYPE_ERROR,
5119 controller_impl().GetLastCommittedEntry()->GetPageType()); 5136 controller_impl().GetLastCommittedEntry()->GetPageType());
5120 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type); 5137 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.navigation_type());
5121 } 5138 }
5122 5139
5123 // Navigate in page. 5140 // Navigate in page.
5124 params.url = GURL("http://foo#foo"); 5141 params.url = GURL("http://foo#foo");
5125 params.transition = ui::PAGE_TRANSITION_LINK; 5142 params.transition = ui::PAGE_TRANSITION_LINK;
5126 params.was_within_same_page = true; 5143 params.was_within_same_page = true;
5127 { 5144 {
5128 LoadCommittedDetailsObserver observer(contents()); 5145 LoadCommittedDetailsObserver observer(contents());
5129 main_test_rfh()->SendNavigateWithParams(&params); 5146 main_test_rfh()->SendNavigateWithParams(&params);
5130 EXPECT_EQ(PAGE_TYPE_ERROR, 5147 EXPECT_EQ(PAGE_TYPE_ERROR,
5131 controller_impl().GetLastCommittedEntry()->GetPageType()); 5148 controller_impl().GetLastCommittedEntry()->GetPageType());
5132 EXPECT_TRUE(observer.details().is_in_page); 5149 EXPECT_TRUE(observer.is_in_page());
5133 } 5150 }
5134 } 5151 }
5135 5152
5136 // Tests that if a stale navigation comes back from the renderer, it is properly 5153 // Tests that if a stale navigation comes back from the renderer, it is properly
5137 // resurrected. 5154 // resurrected.
5138 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) { 5155 TEST_F(NavigationControllerTest, StaleNavigationsResurrected) {
5139 NavigationControllerImpl& controller = controller_impl(); 5156 NavigationControllerImpl& controller = controller_impl();
5140 TestNotificationTracker notifications; 5157 TestNotificationTracker notifications;
5141 RegisterForAllNavNotifications(&notifications, &controller); 5158 RegisterForAllNavNotifications(&notifications, &controller);
5142 5159
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
5271 main_test_rfh()->SimulateNavigationStart(url_1); 5288 main_test_rfh()->SimulateNavigationStart(url_1);
5272 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); 5289 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL());
5273 EXPECT_EQ(ReloadType::NONE, last_reload_type_); 5290 EXPECT_EQ(ReloadType::NONE, last_reload_type_);
5274 5291
5275 main_test_rfh()->SimulateNavigationCommit(url_2); 5292 main_test_rfh()->SimulateNavigationCommit(url_2);
5276 main_test_rfh()->SimulateNavigationCommit(url_1); 5293 main_test_rfh()->SimulateNavigationCommit(url_1);
5277 main_test_rfh()->SimulateNavigationCommit(url_1); 5294 main_test_rfh()->SimulateNavigationCommit(url_1);
5278 } 5295 }
5279 5296
5280 } // namespace content 5297 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698