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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 3449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3460 EXPECT_EQ(url3, nav_params.a.url); | 3460 EXPECT_EQ(url3, nav_params.a.url); |
3461 process()->sink().ClearMessages(); | 3461 process()->sink().ClearMessages(); |
3462 | 3462 |
3463 // Make sure an extravagant history.go() doesn't break. | 3463 // Make sure an extravagant history.go() doesn't break. |
3464 contents()->OnGoToEntryAtOffset(120); // Out of bounds. | 3464 contents()->OnGoToEntryAtOffset(120); // Out of bounds. |
3465 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3465 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3466 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); | 3466 message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID); |
3467 EXPECT_TRUE(message == NULL); | 3467 EXPECT_TRUE(message == NULL); |
3468 } | 3468 } |
3469 | 3469 |
3470 // Test call to PruneAllButVisible for the only entry. | 3470 // Test call to PruneAllButLastCommitted for the only entry. |
3471 TEST_F(NavigationControllerTest, PruneAllButVisibleForSingle) { | 3471 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) { |
3472 NavigationControllerImpl& controller = controller_impl(); | 3472 NavigationControllerImpl& controller = controller_impl(); |
3473 const GURL url1("http://foo1"); | 3473 const GURL url1("http://foo1"); |
3474 NavigateAndCommit(url1); | 3474 NavigateAndCommit(url1); |
3475 | 3475 |
3476 contents()->ExpectSetHistoryLengthAndPrune( | 3476 contents()->ExpectSetHistoryLengthAndPrune( |
3477 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, | 3477 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, |
3478 controller.GetEntryAtIndex(0)->GetPageID()); | 3478 controller.GetEntryAtIndex(0)->GetPageID()); |
3479 | 3479 |
3480 controller.PruneAllButVisible(); | 3480 controller.PruneAllButLastCommitted(); |
3481 | 3481 |
3482 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3482 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3483 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); | 3483 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); |
3484 } | 3484 } |
3485 | 3485 |
3486 // Test call to PruneAllButVisible for first entry. | 3486 // Test call to PruneAllButLastCommitted for first entry. |
3487 TEST_F(NavigationControllerTest, PruneAllButVisibleForFirst) { | 3487 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForFirst) { |
3488 NavigationControllerImpl& controller = controller_impl(); | 3488 NavigationControllerImpl& controller = controller_impl(); |
3489 const GURL url1("http://foo/1"); | 3489 const GURL url1("http://foo/1"); |
3490 const GURL url2("http://foo/2"); | 3490 const GURL url2("http://foo/2"); |
3491 const GURL url3("http://foo/3"); | 3491 const GURL url3("http://foo/3"); |
3492 | 3492 |
3493 NavigateAndCommit(url1); | 3493 NavigateAndCommit(url1); |
3494 NavigateAndCommit(url2); | 3494 NavigateAndCommit(url2); |
3495 NavigateAndCommit(url3); | 3495 NavigateAndCommit(url3); |
3496 controller.GoBack(); | 3496 controller.GoBack(); |
3497 controller.GoBack(); | 3497 controller.GoBack(); |
3498 contents()->CommitPendingNavigation(); | 3498 contents()->CommitPendingNavigation(); |
3499 | 3499 |
3500 contents()->ExpectSetHistoryLengthAndPrune( | 3500 contents()->ExpectSetHistoryLengthAndPrune( |
3501 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, | 3501 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(0)), 0, |
3502 controller.GetEntryAtIndex(0)->GetPageID()); | 3502 controller.GetEntryAtIndex(0)->GetPageID()); |
3503 | 3503 |
3504 controller.PruneAllButVisible(); | 3504 controller.PruneAllButLastCommitted(); |
3505 | 3505 |
3506 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3506 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3507 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); | 3507 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url1); |
3508 } | 3508 } |
3509 | 3509 |
3510 // Test call to PruneAllButVisible for intermediate entry. | 3510 // Test call to PruneAllButLastCommitted for intermediate entry. |
3511 TEST_F(NavigationControllerTest, PruneAllButVisibleForIntermediate) { | 3511 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForIntermediate) { |
3512 NavigationControllerImpl& controller = controller_impl(); | 3512 NavigationControllerImpl& controller = controller_impl(); |
3513 const GURL url1("http://foo/1"); | 3513 const GURL url1("http://foo/1"); |
3514 const GURL url2("http://foo/2"); | 3514 const GURL url2("http://foo/2"); |
3515 const GURL url3("http://foo/3"); | 3515 const GURL url3("http://foo/3"); |
3516 | 3516 |
3517 NavigateAndCommit(url1); | 3517 NavigateAndCommit(url1); |
3518 NavigateAndCommit(url2); | 3518 NavigateAndCommit(url2); |
3519 NavigateAndCommit(url3); | 3519 NavigateAndCommit(url3); |
3520 controller.GoBack(); | 3520 controller.GoBack(); |
3521 contents()->CommitPendingNavigation(); | 3521 contents()->CommitPendingNavigation(); |
3522 | 3522 |
3523 contents()->ExpectSetHistoryLengthAndPrune( | 3523 contents()->ExpectSetHistoryLengthAndPrune( |
3524 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)), 0, | 3524 GetSiteInstanceFromEntry(controller.GetEntryAtIndex(1)), 0, |
3525 controller.GetEntryAtIndex(1)->GetPageID()); | 3525 controller.GetEntryAtIndex(1)->GetPageID()); |
3526 | 3526 |
3527 controller.PruneAllButVisible(); | 3527 controller.PruneAllButLastCommitted(); |
3528 | 3528 |
3529 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3529 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3530 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url2); | 3530 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url2); |
3531 } | 3531 } |
3532 | 3532 |
3533 // Test call to PruneAllButVisible for a pending entry that is not yet in the | 3533 // Test call to PruneAllButLastCommitted for a pending entry that is not yet in |
3534 // list of entries. | 3534 // the list of entries. |
3535 TEST_F(NavigationControllerTest, PruneAllButVisibleForPendingNotInList) { | 3535 TEST_F(NavigationControllerTest, PruneAllButLastCommittedForPendingNotInList) { |
3536 NavigationControllerImpl& controller = controller_impl(); | 3536 NavigationControllerImpl& controller = controller_impl(); |
3537 const GURL url1("http://foo/1"); | 3537 const GURL url1("http://foo/1"); |
3538 const GURL url2("http://foo/2"); | 3538 const GURL url2("http://foo/2"); |
3539 const GURL url3("http://foo/3"); | 3539 const GURL url3("http://foo/3"); |
3540 | 3540 |
3541 NavigateAndCommit(url1); | 3541 NavigateAndCommit(url1); |
3542 NavigateAndCommit(url2); | 3542 NavigateAndCommit(url2); |
3543 | 3543 |
3544 // Create a pending entry that is not in the entry list. | 3544 // Create a pending entry that is not in the entry list. |
3545 controller.LoadURL( | 3545 controller.LoadURL( |
3546 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 3546 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
3547 EXPECT_TRUE(controller.GetPendingEntry()); | 3547 EXPECT_TRUE(controller.GetPendingEntry()); |
3548 EXPECT_EQ(2, controller.GetEntryCount()); | 3548 EXPECT_EQ(2, controller.GetEntryCount()); |
3549 | 3549 |
3550 contents()->ExpectSetHistoryLengthAndPrune( | 3550 contents()->ExpectSetHistoryLengthAndPrune( |
3551 NULL, 0, controller.GetPendingEntry()->GetPageID()); | 3551 NULL, 0, controller.GetPendingEntry()->GetPageID()); |
3552 controller.PruneAllButVisible(); | 3552 controller.PruneAllButLastCommitted(); |
3553 | 3553 |
3554 // We should only have the last committed and pending entries at this point, | 3554 // We should only have the last committed and pending entries at this point, |
3555 // and the pending entry should still not be in the entry list. | 3555 // and the pending entry should still not be in the entry list. |
3556 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 3556 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
3557 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 3557 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
3558 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3558 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3559 EXPECT_TRUE(controller.GetPendingEntry()); | 3559 EXPECT_TRUE(controller.GetPendingEntry()); |
3560 EXPECT_EQ(1, controller.GetEntryCount()); | 3560 EXPECT_EQ(1, controller.GetEntryCount()); |
3561 | 3561 |
3562 // Try to commit the pending entry. | 3562 // Try to commit the pending entry. |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3835 EXPECT_EQ(1, controller.GetEntryCount()); | 3835 EXPECT_EQ(1, controller.GetEntryCount()); |
3836 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 3836 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
3837 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 3837 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
3838 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3838 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3839 EXPECT_FALSE(controller.CanGoBack()); | 3839 EXPECT_FALSE(controller.CanGoBack()); |
3840 EXPECT_FALSE(controller.CanGoForward()); | 3840 EXPECT_FALSE(controller.CanGoForward()); |
3841 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 3841 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
3842 } | 3842 } |
3843 | 3843 |
3844 } // namespace content | 3844 } // namespace content |
OLD | NEW |