OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/sessions/persistent_tab_restore_service.h" | 5 #include "chrome/browser/sessions/persistent_tab_restore_service.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 static_cast<Tab*>(restored_entry); | 617 static_cast<Tab*>(restored_entry); |
618 EXPECT_EQ(tab_timestamp.ToInternalValue(), | 618 EXPECT_EQ(tab_timestamp.ToInternalValue(), |
619 restored_tab->timestamp.ToInternalValue()); | 619 restored_tab->timestamp.ToInternalValue()); |
620 ASSERT_EQ(old_navigations.size(), restored_tab->navigations.size()); | 620 ASSERT_EQ(old_navigations.size(), restored_tab->navigations.size()); |
621 for (size_t i = 0; i < restored_tab->navigations.size(); ++i) { | 621 for (size_t i = 0; i < restored_tab->navigations.size(); ++i) { |
622 EXPECT_EQ(old_navigations[i].timestamp(), | 622 EXPECT_EQ(old_navigations[i].timestamp(), |
623 restored_tab->navigations[i].timestamp()); | 623 restored_tab->navigations[i].timestamp()); |
624 } | 624 } |
625 } | 625 } |
626 | 626 |
| 627 // Makes sure we restore status codes correctly. |
| 628 TEST_F(PersistentTabRestoreServiceTest, StatusCodesSurviveRestore) { |
| 629 AddThreeNavigations(); |
| 630 |
| 631 // Have the service record the tab. |
| 632 service_->CreateHistoricalTab(web_contents(), -1); |
| 633 |
| 634 // Make sure an entry was created. |
| 635 ASSERT_EQ(1U, service_->entries().size()); |
| 636 |
| 637 // Make sure the entry matches. |
| 638 std::vector<sessions::SerializedNavigationEntry> old_navigations; |
| 639 { |
| 640 // |entry|/|tab| doesn't survive after RecreateService(). |
| 641 TabRestoreService::Entry* entry = service_->entries().front(); |
| 642 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
| 643 Tab* tab = static_cast<Tab*>(entry); |
| 644 old_navigations = tab->navigations; |
| 645 } |
| 646 |
| 647 EXPECT_EQ(3U, old_navigations.size()); |
| 648 for (size_t i = 0; i < old_navigations.size(); ++i) { |
| 649 EXPECT_EQ(200, old_navigations[i].http_status_code()); |
| 650 } |
| 651 |
| 652 // Set this, otherwise previous session won't be loaded. |
| 653 profile()->set_last_session_exited_cleanly(false); |
| 654 |
| 655 RecreateService(); |
| 656 |
| 657 // One entry should be created. |
| 658 ASSERT_EQ(1U, service_->entries().size()); |
| 659 |
| 660 // And verify the entry. |
| 661 TabRestoreService::Entry* restored_entry = service_->entries().front(); |
| 662 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); |
| 663 Tab* restored_tab = |
| 664 static_cast<Tab*>(restored_entry); |
| 665 ASSERT_EQ(old_navigations.size(), restored_tab->navigations.size()); |
| 666 for (size_t i = 0; i < restored_tab->navigations.size(); ++i) { |
| 667 EXPECT_EQ(200, restored_tab->navigations[i].http_status_code()); |
| 668 } |
| 669 } |
| 670 |
627 TEST_F(PersistentTabRestoreServiceTest, PruneEntries) { | 671 TEST_F(PersistentTabRestoreServiceTest, PruneEntries) { |
628 service_->ClearEntries(); | 672 service_->ClearEntries(); |
629 ASSERT_TRUE(service_->entries().empty()); | 673 ASSERT_TRUE(service_->entries().empty()); |
630 | 674 |
631 const size_t max_entries = kMaxEntries; | 675 const size_t max_entries = kMaxEntries; |
632 for (size_t i = 0; i < max_entries + 5; i++) { | 676 for (size_t i = 0; i < max_entries + 5; i++) { |
633 SerializedNavigationEntry navigation = | 677 SerializedNavigationEntry navigation = |
634 SerializedNavigationEntryTestHelper::CreateNavigation( | 678 SerializedNavigationEntryTestHelper::CreateNavigation( |
635 base::StringPrintf("http://%d", static_cast<int>(i)), | 679 base::StringPrintf("http://%d", static_cast<int>(i)), |
636 base::StringPrintf("%d", static_cast<int>(i))); | 680 base::StringPrintf("%d", static_cast<int>(i))); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 | 790 |
747 EXPECT_FALSE(service_->IsLoaded()); | 791 EXPECT_FALSE(service_->IsLoaded()); |
748 TestTabRestoreServiceObserver observer; | 792 TestTabRestoreServiceObserver observer; |
749 service_->AddObserver(&observer); | 793 service_->AddObserver(&observer); |
750 EXPECT_EQ(max_entries, service_->entries().size()); | 794 EXPECT_EQ(max_entries, service_->entries().size()); |
751 SynchronousLoadTabsFromLastSession(); | 795 SynchronousLoadTabsFromLastSession(); |
752 EXPECT_TRUE(observer.got_loaded()); | 796 EXPECT_TRUE(observer.got_loaded()); |
753 EXPECT_TRUE(service_->IsLoaded()); | 797 EXPECT_TRUE(service_->IsLoaded()); |
754 service_->RemoveObserver(&observer); | 798 service_->RemoveObserver(&observer); |
755 } | 799 } |
OLD | NEW |