OLD | NEW |
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> |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 RenderViewHostImplTestHarness::SetUp(); | 211 RenderViewHostImplTestHarness::SetUp(); |
212 WebContents* web_contents = RenderViewHostImplTestHarness::web_contents(); | 212 WebContents* web_contents = RenderViewHostImplTestHarness::web_contents(); |
213 ASSERT_TRUE(web_contents); // The WebContents should be created by now. | 213 ASSERT_TRUE(web_contents); // The WebContents should be created by now. |
214 WebContentsObserver::Observe(web_contents); | 214 WebContentsObserver::Observe(web_contents); |
215 } | 215 } |
216 | 216 |
217 // WebContentsObserver: | 217 // WebContentsObserver: |
218 void DidStartNavigationToPendingEntry(const GURL& url, | 218 void DidStartNavigationToPendingEntry(const GURL& url, |
219 ReloadType reload_type) override { | 219 ReloadType reload_type) override { |
220 navigated_url_ = url; | 220 navigated_url_ = url; |
| 221 last_reload_type_ = reload_type; |
221 } | 222 } |
222 | 223 |
223 void NavigationEntryCommitted( | 224 void NavigationEntryCommitted( |
224 const LoadCommittedDetails& load_details) override { | 225 const LoadCommittedDetails& load_details) override { |
225 navigation_entry_committed_counter_++; | 226 navigation_entry_committed_counter_++; |
226 } | 227 } |
227 | 228 |
228 const GURL& navigated_url() const { | 229 const GURL& navigated_url() const { |
229 return navigated_url_; | 230 return navigated_url_; |
230 } | 231 } |
(...skipping 24 matching lines...) Expand all Loading... |
255 std::tuple<CommonNavigationParams, StartNavigationParams, | 256 std::tuple<CommonNavigationParams, StartNavigationParams, |
256 RequestNavigationParams> | 257 RequestNavigationParams> |
257 nav_params; | 258 nav_params; |
258 FrameMsg_Navigate::Read(message, &nav_params); | 259 FrameMsg_Navigate::Read(message, &nav_params); |
259 return std::get<0>(nav_params).url; | 260 return std::get<0>(nav_params).url; |
260 } | 261 } |
261 | 262 |
262 protected: | 263 protected: |
263 GURL navigated_url_; | 264 GURL navigated_url_; |
264 size_t navigation_entry_committed_counter_; | 265 size_t navigation_entry_committed_counter_; |
| 266 ReloadType last_reload_type_; |
265 }; | 267 }; |
266 | 268 |
267 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, | 269 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
268 NavigationController* controller) { | 270 NavigationController* controller) { |
269 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, | 271 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, |
270 Source<NavigationController>(controller)); | 272 Source<NavigationController>(controller)); |
271 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, | 273 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, |
272 Source<NavigationController>(controller)); | 274 Source<NavigationController>(controller)); |
273 } | 275 } |
274 | 276 |
(...skipping 4928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5203 // pruned it will end up as a *new* entry at the end of the entry list. This | 5205 // pruned it will end up as a *new* entry at the end of the entry list. This |
5204 // means that occasionally a navigation conflict will end up with one entry | 5206 // means that occasionally a navigation conflict will end up with one entry |
5205 // bubbling to the end of the entry list, but that's the least-bad option. | 5207 // bubbling to the end of the entry list, but that's the least-bad option. |
5206 EXPECT_EQ(3, controller.GetEntryCount()); | 5208 EXPECT_EQ(3, controller.GetEntryCount()); |
5207 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 5209 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
5208 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); | 5210 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); |
5209 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); | 5211 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); |
5210 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); | 5212 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); |
5211 } | 5213 } |
5212 | 5214 |
| 5215 // Tests that successive navigations with intermittent duplicate navigations |
| 5216 // are correctly marked as reload in the navigation controller. |
| 5217 // We test the cases where in a navigation is pending/comitted before the new |
| 5218 // navigation is initiated. |
| 5219 // http://crbug.com/664319 |
| 5220 TEST_F(NavigationControllerTest, MultipleNavigationsAndReload) { |
| 5221 NavigationControllerImpl& controller = controller_impl(); |
| 5222 TestNotificationTracker notifications; |
| 5223 RegisterForAllNavNotifications(¬ifications, &controller); |
| 5224 |
| 5225 GURL initial_url("http://www.google.com"); |
| 5226 GURL url_1("http://foo.com"); |
| 5227 GURL url_2("http://foo2.com"); |
| 5228 |
| 5229 // Test 1. |
| 5230 // A normal navigation to initial_url should not be marked as a reload. |
| 5231 controller.LoadURL(initial_url, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 5232 std::string()); |
| 5233 EXPECT_EQ(initial_url, controller.GetVisibleEntry()->GetURL()); |
| 5234 main_test_rfh()->SimulateNavigationStart(initial_url); |
| 5235 EXPECT_EQ(initial_url, controller.GetVisibleEntry()->GetURL()); |
| 5236 |
| 5237 main_test_rfh()->SimulateNavigationCommit(initial_url); |
| 5238 EXPECT_EQ(ReloadType::NONE, last_reload_type_); |
| 5239 |
| 5240 // Test 2. |
| 5241 // A navigation to initial_url with the navigation commit delayed should be |
| 5242 // marked as a reload. |
| 5243 controller.LoadURL(initial_url, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 5244 std::string()); |
| 5245 |
| 5246 EXPECT_EQ(initial_url, controller.GetVisibleEntry()->GetURL()); |
| 5247 main_test_rfh()->SimulateNavigationStart(initial_url); |
| 5248 EXPECT_EQ(initial_url, controller.GetVisibleEntry()->GetURL()); |
| 5249 EXPECT_EQ(ReloadType::NORMAL, last_reload_type_); |
| 5250 |
| 5251 // Test 3. |
| 5252 // A navigation to url_1 while the navigation to intial_url is still pending |
| 5253 // should not be marked as a reload. |
| 5254 controller.LoadURL(url_1, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 5255 std::string()); |
| 5256 |
| 5257 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
| 5258 main_test_rfh()->SimulateNavigationStart(url_1); |
| 5259 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
| 5260 EXPECT_EQ(ReloadType::NONE, last_reload_type_); |
| 5261 |
| 5262 // Test 4. |
| 5263 // A navigation to url_1 while the previous navigation to url_1 is pending |
| 5264 // should be marked as reload. |
| 5265 controller.LoadURL(url_1, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 5266 std::string()); |
| 5267 |
| 5268 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
| 5269 main_test_rfh()->SimulateNavigationStart(url_1); |
| 5270 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
| 5271 EXPECT_EQ(ReloadType::NORMAL, last_reload_type_); |
| 5272 |
| 5273 main_test_rfh()->SimulateNavigationCommit(initial_url); |
| 5274 |
| 5275 // Test 5 |
| 5276 // A navigation to url_2 followed by a navigation to the previously pending |
| 5277 // url_1 should not be marked as a reload. |
| 5278 controller.LoadURL(url_2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 5279 std::string()); |
| 5280 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL()); |
| 5281 main_test_rfh()->SimulateNavigationStart(url_2); |
| 5282 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL()); |
| 5283 EXPECT_EQ(ReloadType::NONE, last_reload_type_); |
| 5284 |
| 5285 controller.LoadURL(url_1, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 5286 std::string()); |
| 5287 |
| 5288 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
| 5289 main_test_rfh()->SimulateNavigationStart(url_1); |
| 5290 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
| 5291 EXPECT_EQ(ReloadType::NONE, last_reload_type_); |
| 5292 |
| 5293 main_test_rfh()->SimulateNavigationCommit(url_2); |
| 5294 main_test_rfh()->SimulateNavigationCommit(url_1); |
| 5295 main_test_rfh()->SimulateNavigationCommit(url_1); |
| 5296 } |
| 5297 |
5213 } // namespace content | 5298 } // namespace content |
OLD | NEW |