Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/sessions/tab_restore_service_browsertest.cc

Issue 11054025: [Sync] Add HTTP status codes to NavigationEntry and TabNavigation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase onto 11096037 Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 EXPECT_EQ(tab_timestamp.ToInternalValue(), 562 EXPECT_EQ(tab_timestamp.ToInternalValue(),
563 restored_tab->timestamp.ToInternalValue()); 563 restored_tab->timestamp.ToInternalValue());
564 ASSERT_EQ(old_navigations.size(), restored_tab->navigations.size()); 564 ASSERT_EQ(old_navigations.size(), restored_tab->navigations.size());
565 for (size_t i = 0; i < restored_tab->navigations.size(); ++i) { 565 for (size_t i = 0; i < restored_tab->navigations.size(); ++i) {
566 EXPECT_EQ( 566 EXPECT_EQ(
567 SessionTypesTestHelper::GetTimestamp(old_navigations[i]), 567 SessionTypesTestHelper::GetTimestamp(old_navigations[i]),
568 SessionTypesTestHelper::GetTimestamp(restored_tab->navigations[i])); 568 SessionTypesTestHelper::GetTimestamp(restored_tab->navigations[i]));
569 } 569 }
570 } 570 }
571 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 }
617 }
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(
580 StringPrintf("http://%d", static_cast<int>(i)), 627 StringPrintf("http://%d", static_cast<int>(i)),
581 StringPrintf("%d", static_cast<int>(i))); 628 StringPrintf("%d", static_cast<int>(i)));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_types_unittest.cc ('k') | chrome/browser/sync/glue/session_model_associator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698