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 "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/sessions/session_service.h" | 7 #include "chrome/browser/sessions/session_service.h" |
8 #include "chrome/browser/sessions/session_service_factory.h" | 8 #include "chrome/browser/sessions/session_service_factory.h" |
9 #include "chrome/browser/sessions/session_types.h" | 9 #include "chrome/browser/sessions/session_types.h" |
10 #include "chrome/browser/sessions/session_types_test_helper.h" | 10 #include "chrome/browser/sessions/session_types_test_helper.h" |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 std::vector<TabNavigation> old_navigations; | 533 std::vector<TabNavigation> old_navigations; |
534 { | 534 { |
535 // |entry|/|tab| doesn't survive after RecreateService(). | 535 // |entry|/|tab| doesn't survive after RecreateService(). |
536 TabRestoreService::Entry* entry = service_->entries().front(); | 536 TabRestoreService::Entry* entry = service_->entries().front(); |
537 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 537 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
538 Tab* tab = static_cast<Tab*>(entry); | 538 Tab* tab = static_cast<Tab*>(entry); |
539 tab->timestamp = tab_timestamp; | 539 tab->timestamp = tab_timestamp; |
540 old_navigations = tab->navigations; | 540 old_navigations = tab->navigations; |
541 } | 541 } |
542 | 542 |
543 ASSERT_EQ(3U, old_navigations.size()); | 543 EXPECT_EQ(3U, old_navigations.size()); |
544 EXPECT_FALSE(old_navigations[0].timestamp().is_null()); | 544 for (size_t i = 0; i < old_navigations.size(); ++i) { |
545 EXPECT_FALSE(old_navigations[1].timestamp().is_null()); | 545 EXPECT_FALSE( |
546 EXPECT_FALSE(old_navigations[2].timestamp().is_null()); | 546 SessionTypesTestHelper::GetTimestamp(old_navigations[i]).is_null()); |
| 547 } |
547 | 548 |
548 // Set this, otherwise previous session won't be loaded. | 549 // Set this, otherwise previous session won't be loaded. |
549 profile()->set_last_session_exited_cleanly(false); | 550 profile()->set_last_session_exited_cleanly(false); |
550 | 551 |
551 RecreateService(); | 552 RecreateService(); |
552 | 553 |
553 // One entry should be created. | 554 // One entry should be created. |
554 ASSERT_EQ(1U, service_->entries().size()); | 555 ASSERT_EQ(1U, service_->entries().size()); |
555 | 556 |
556 // And verify the entry. | 557 // And verify the entry. |
557 TabRestoreService::Entry* restored_entry = service_->entries().front(); | 558 TabRestoreService::Entry* restored_entry = service_->entries().front(); |
558 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); | 559 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); |
559 Tab* restored_tab = | 560 Tab* restored_tab = |
560 static_cast<Tab*>(restored_entry); | 561 static_cast<Tab*>(restored_entry); |
561 EXPECT_EQ(tab_timestamp.ToInternalValue(), | 562 EXPECT_EQ(tab_timestamp.ToInternalValue(), |
562 restored_tab->timestamp.ToInternalValue()); | 563 restored_tab->timestamp.ToInternalValue()); |
563 ASSERT_EQ(3U, restored_tab->navigations.size()); | 564 ASSERT_EQ(old_navigations.size(), restored_tab->navigations.size()); |
564 EXPECT_EQ(old_navigations[0].timestamp(), | 565 for (size_t i = 0; i < restored_tab->navigations.size(); ++i) { |
565 restored_tab->navigations[0].timestamp()); | 566 EXPECT_EQ( |
566 EXPECT_EQ(old_navigations[1].timestamp(), | 567 SessionTypesTestHelper::GetTimestamp(old_navigations[i]), |
567 restored_tab->navigations[1].timestamp()); | 568 SessionTypesTestHelper::GetTimestamp(restored_tab->navigations[i])); |
568 EXPECT_EQ(old_navigations[2].timestamp(), | 569 } |
569 restored_tab->navigations[2].timestamp()); | 570 } |
| 571 |
| 572 // Makes sure we restore status codes correctly. |
| 573 TEST_F(TabRestoreServiceTest, StatusCodesSurviveRestore) { |
| 574 AddThreeNavigations(); |
| 575 |
| 576 // Have the service record the tab. |
| 577 service_->CreateHistoricalTab(contents(), -1); |
| 578 |
| 579 // Make sure an entry was created. |
| 580 ASSERT_EQ(1U, service_->entries().size()); |
| 581 |
| 582 // Make sure the entry matches. |
| 583 std::vector<TabNavigation> old_navigations; |
| 584 { |
| 585 // |entry|/|tab| doesn't survive after RecreateService(). |
| 586 TabRestoreService::Entry* entry = service_->entries().front(); |
| 587 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
| 588 Tab* tab = static_cast<Tab*>(entry); |
| 589 old_navigations = tab->navigations; |
| 590 } |
| 591 |
| 592 EXPECT_EQ(3U, old_navigations.size()); |
| 593 for (size_t i = 0; i < old_navigations.size(); ++i) { |
| 594 EXPECT_EQ(200, |
| 595 SessionTypesTestHelper::GetHttpStatusCode(old_navigations[i])); |
| 596 } |
| 597 |
| 598 // Set this, otherwise previous session won't be loaded. |
| 599 profile()->set_last_session_exited_cleanly(false); |
| 600 |
| 601 RecreateService(); |
| 602 |
| 603 // One entry should be created. |
| 604 ASSERT_EQ(1U, service_->entries().size()); |
| 605 |
| 606 // And verify the entry. |
| 607 TabRestoreService::Entry* restored_entry = service_->entries().front(); |
| 608 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); |
| 609 Tab* restored_tab = |
| 610 static_cast<Tab*>(restored_entry); |
| 611 ASSERT_EQ(old_navigations.size(), restored_tab->navigations.size()); |
| 612 for (size_t i = 0; i < restored_tab->navigations.size(); ++i) { |
| 613 EXPECT_EQ(200, |
| 614 SessionTypesTestHelper::GetHttpStatusCode( |
| 615 restored_tab->navigations[i])); |
| 616 } |
570 } | 617 } |
571 | 618 |
572 TEST_F(TabRestoreServiceTest, PruneEntries) { | 619 TEST_F(TabRestoreServiceTest, PruneEntries) { |
573 service_->ClearEntries(); | 620 service_->ClearEntries(); |
574 ASSERT_TRUE(service_->entries().empty()); | 621 ASSERT_TRUE(service_->entries().empty()); |
575 | 622 |
576 const size_t max_entries = TabRestoreService::kMaxEntries; | 623 const size_t max_entries = TabRestoreService::kMaxEntries; |
577 for (size_t i = 0; i < max_entries + 5; i++) { | 624 for (size_t i = 0; i < max_entries + 5; i++) { |
578 TabNavigation navigation = | 625 TabNavigation navigation = |
579 SessionTypesTestHelper::CreateNavigation( | 626 SessionTypesTestHelper::CreateNavigation( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 for (size_t i = 0; i < max_entries + 5; i++) { | 717 for (size_t i = 0; i < max_entries + 5; i++) { |
671 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); | 718 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); |
672 service_->CreateHistoricalTab(contents(), -1); | 719 service_->CreateHistoricalTab(contents(), -1); |
673 } | 720 } |
674 | 721 |
675 EXPECT_EQ(max_entries, service_->entries_.size()); | 722 EXPECT_EQ(max_entries, service_->entries_.size()); |
676 // This should not crash. | 723 // This should not crash. |
677 service_->LoadTabsFromLastSession(); | 724 service_->LoadTabsFromLastSession(); |
678 EXPECT_EQ(max_entries, service_->entries_.size()); | 725 EXPECT_EQ(max_entries, service_->entries_.size()); |
679 } | 726 } |
OLD | NEW |