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 5272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5283 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); | 5283 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
5284 main_test_rfh()->SimulateNavigationStart(url_1); | 5284 main_test_rfh()->SimulateNavigationStart(url_1); |
5285 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); | 5285 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); |
5286 EXPECT_EQ(ReloadType::NONE, last_reload_type_); | 5286 EXPECT_EQ(ReloadType::NONE, last_reload_type_); |
5287 | 5287 |
5288 main_test_rfh()->SimulateNavigationCommit(url_2); | 5288 main_test_rfh()->SimulateNavigationCommit(url_2); |
5289 main_test_rfh()->SimulateNavigationCommit(url_1); | 5289 main_test_rfh()->SimulateNavigationCommit(url_1); |
5290 main_test_rfh()->SimulateNavigationCommit(url_1); | 5290 main_test_rfh()->SimulateNavigationCommit(url_1); |
5291 } | 5291 } |
5292 | 5292 |
| 5293 // Test to ensure that the pending entry index is updated when a transient entry |
| 5294 // is inserted or removed. |
| 5295 TEST_F(NavigationControllerTest, PendingEntryIndexUpdatedWithTransient) { |
| 5296 NavigationControllerImpl& controller = controller_impl(); |
| 5297 const GURL url_0("http://foo/0"); |
| 5298 const GURL url_1("http://foo/1"); |
| 5299 const GURL url_transient_1("http://foo/transient_1"); |
| 5300 const GURL url_transient_2("http://foo/transient_2"); |
| 5301 |
| 5302 NavigateAndCommit(url_0); |
| 5303 NavigateAndCommit(url_1); |
| 5304 controller.GoBack(); |
| 5305 contents()->CommitPendingNavigation(); |
| 5306 controller.GoForward(); |
| 5307 |
| 5308 // Check the state before the insertion of the transient entry. |
| 5309 // entries[0] = url_0 <- last committed entry. |
| 5310 // entries[1] = url_1 <- pending entry. |
| 5311 ASSERT_EQ(2, controller.GetEntryCount()); |
| 5312 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 5313 EXPECT_EQ(1, controller.GetPendingEntryIndex()); |
| 5314 EXPECT_EQ(controller.GetEntryAtIndex(1), controller.GetPendingEntry()); |
| 5315 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL()); |
| 5316 EXPECT_EQ(url_1, controller.GetEntryAtIndex(1)->GetURL()); |
| 5317 |
| 5318 // Insert a transient entry before the pending one. It should increase the |
| 5319 // pending entry index by one (1 -> 2). |
| 5320 std::unique_ptr<NavigationEntry> transient_entry_1(new NavigationEntryImpl); |
| 5321 transient_entry_1->SetURL(url_transient_1); |
| 5322 controller.SetTransientEntry(std::move(transient_entry_1)); |
| 5323 |
| 5324 // Check the state after the insertion of the transient entry. |
| 5325 // entries[0] = url_0 <- last committed entry |
| 5326 // entries[1] = url_transient_1 <- transient entry |
| 5327 // entries[2] = url_1 <- pending entry |
| 5328 ASSERT_EQ(3, controller.GetEntryCount()); |
| 5329 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 5330 EXPECT_EQ(2, controller.GetPendingEntryIndex()); |
| 5331 EXPECT_EQ(controller.GetEntryAtIndex(1), controller.GetTransientEntry()); |
| 5332 EXPECT_EQ(controller.GetEntryAtIndex(2), controller.GetPendingEntry()); |
| 5333 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL()); |
| 5334 EXPECT_EQ(url_transient_1, controller.GetEntryAtIndex(1)->GetURL()); |
| 5335 EXPECT_EQ(url_1, controller.GetEntryAtIndex(2)->GetURL()); |
| 5336 |
| 5337 // Insert another transient entry. It should replace the previous one and this |
| 5338 // time the pending entry index should retain its value (i.e. 2). |
| 5339 std::unique_ptr<NavigationEntry> transient_entry_2(new NavigationEntryImpl); |
| 5340 transient_entry_2->SetURL(url_transient_2); |
| 5341 controller.SetTransientEntry(std::move(transient_entry_2)); |
| 5342 |
| 5343 // Check the state after the second insertion of a transient entry. |
| 5344 // entries[0] = url_0 <- last committed entry |
| 5345 // entries[1] = url_transient_2 <- transient entry |
| 5346 // entries[2] = url_1 <- pending entry |
| 5347 ASSERT_EQ(3, controller.GetEntryCount()); |
| 5348 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 5349 EXPECT_EQ(2, controller.GetPendingEntryIndex()); |
| 5350 EXPECT_EQ(controller.GetEntryAtIndex(1), controller.GetTransientEntry()); |
| 5351 EXPECT_EQ(controller.GetEntryAtIndex(2), controller.GetPendingEntry()); |
| 5352 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL()); |
| 5353 EXPECT_EQ(url_transient_2, controller.GetEntryAtIndex(1)->GetURL()); |
| 5354 EXPECT_EQ(url_1, controller.GetEntryAtIndex(2)->GetURL()); |
| 5355 |
| 5356 // Commit the pending entry. |
| 5357 contents()->CommitPendingNavigation(); |
| 5358 |
| 5359 // Check the final state. |
| 5360 // entries[0] = url_0 |
| 5361 // entries[1] = url_1 <- last committed entry |
| 5362 ASSERT_EQ(2, controller.GetEntryCount()); |
| 5363 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 5364 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 5365 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
| 5366 EXPECT_EQ(nullptr, controller.GetTransientEntry()); |
| 5367 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL()); |
| 5368 EXPECT_EQ(url_1, controller.GetEntryAtIndex(1)->GetURL()); |
| 5369 } |
| 5370 |
5293 } // namespace content | 5371 } // namespace content |
OLD | NEW |