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

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

Issue 10917231: Revamp TabNavigation class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac Created 8 years, 3 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_factory.h" 8 #include "chrome/browser/sessions/session_service_factory.h"
8 #include "chrome/browser/sessions/session_service.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/tab_restore_service.h" 11 #include "chrome/browser/sessions/tab_restore_service.h"
11 #include "chrome/browser/sessions/tab_restore_service_factory.h" 12 #include "chrome/browser/sessions/tab_restore_service_factory.h"
12 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/chrome_render_view_test.h" 17 #include "chrome/test/base/chrome_render_view_test.h"
17 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 SessionServiceFactory::GetForProfile(profile()); 113 SessionServiceFactory::GetForProfile(profile());
113 SessionID tab_id; 114 SessionID tab_id;
114 SessionID window_id; 115 SessionID window_id;
115 session_service->SetWindowType( 116 session_service->SetWindowType(
116 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 117 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
117 session_service->SetTabWindow(window_id, tab_id); 118 session_service->SetTabWindow(window_id, tab_id);
118 session_service->SetTabIndexInWindow(window_id, tab_id, 0); 119 session_service->SetTabIndexInWindow(window_id, tab_id, 0);
119 session_service->SetSelectedTabInWindow(window_id, 0); 120 session_service->SetSelectedTabInWindow(window_id, 0);
120 if (pinned) 121 if (pinned)
121 session_service->SetPinnedState(window_id, tab_id, true); 122 session_service->SetPinnedState(window_id, tab_id, true);
122 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); 123 session_service->UpdateTabNavigation(
123 entry->SetURL(url1_); 124 window_id, tab_id,
124 session_service->UpdateTabNavigation(window_id, tab_id, 0, *entry.get()); 125 SessionTypesTestHelper::CreateNavigation(url1_.spec(), "title"));
125 } 126 }
126 127
127 // Creates a SessionService and assigns it to the Profile. The SessionService 128 // Creates a SessionService and assigns it to the Profile. The SessionService
128 // is configured with a single window with a single tab pointing at url1_ by 129 // is configured with a single window with a single tab pointing at url1_ by
129 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the 130 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the
130 // tab is marked as pinned in the session service. 131 // tab is marked as pinned in the session service.
131 void CreateSessionServiceWithOneWindow(bool pinned) { 132 void CreateSessionServiceWithOneWindow(bool pinned) {
132 // The profile takes ownership of this. 133 // The profile takes ownership of this.
133 SessionService* session_service = new SessionService(profile()); 134 SessionService* session_service = new SessionService(profile());
134 SessionServiceFactory::SetForTestProfile(profile(), session_service); 135 SessionServiceFactory::SetForTestProfile(profile(), session_service);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 EXPECT_EQ(tab_timestamp.ToInternalValue(), 551 EXPECT_EQ(tab_timestamp.ToInternalValue(),
551 restored_tab->timestamp.ToInternalValue()); 552 restored_tab->timestamp.ToInternalValue());
552 } 553 }
553 554
554 TEST_F(TabRestoreServiceTest, PruneEntries) { 555 TEST_F(TabRestoreServiceTest, PruneEntries) {
555 service_->ClearEntries(); 556 service_->ClearEntries();
556 ASSERT_TRUE(service_->entries().empty()); 557 ASSERT_TRUE(service_->entries().empty());
557 558
558 const size_t max_entries = TabRestoreService::kMaxEntries; 559 const size_t max_entries = TabRestoreService::kMaxEntries;
559 for (size_t i = 0; i < max_entries + 5; i++) { 560 for (size_t i = 0; i < max_entries + 5; i++) {
560 TabNavigation navigation; 561 TabNavigation navigation =
561 navigation.set_virtual_url(GURL(StringPrintf("http://%d", 562 SessionTypesTestHelper::CreateNavigation(
562 static_cast<int>(i)))); 563 StringPrintf("http://%d", static_cast<int>(i)),
563 navigation.set_title(ASCIIToUTF16(StringPrintf("%d", static_cast<int>(i)))); 564 StringPrintf("%d", static_cast<int>(i)));
564 565
565 Tab* tab = new Tab(); 566 Tab* tab = new Tab();
566 tab->navigations.push_back(navigation); 567 tab->navigations.push_back(navigation);
567 tab->current_navigation_index = 0; 568 tab->current_navigation_index = 0;
568 569
569 service_->entries_.push_back(tab); 570 service_->entries_.push_back(tab);
570 } 571 }
571 572
572 // Only keep kMaxEntries around. 573 // Only keep kMaxEntries around.
573 EXPECT_EQ(max_entries + 5, service_->entries_.size()); 574 EXPECT_EQ(max_entries + 5, service_->entries_.size());
574 service_->PruneEntries(); 575 service_->PruneEntries();
575 EXPECT_EQ(max_entries, service_->entries_.size()); 576 EXPECT_EQ(max_entries, service_->entries_.size());
576 // Pruning again does nothing. 577 // Pruning again does nothing.
577 service_->PruneEntries(); 578 service_->PruneEntries();
578 EXPECT_EQ(max_entries, service_->entries_.size()); 579 EXPECT_EQ(max_entries, service_->entries_.size());
579 580
580 // Prune older first. 581 // Prune older first.
581 TabNavigation navigation;
582 const char kRecentUrl[] = "http://recent"; 582 const char kRecentUrl[] = "http://recent";
583 navigation.set_virtual_url(GURL(kRecentUrl)); 583 TabNavigation navigation =
584 navigation.set_title(ASCIIToUTF16("Most recent")); 584 SessionTypesTestHelper::CreateNavigation(kRecentUrl, "Most recent");
585 Tab* tab = new Tab(); 585 Tab* tab = new Tab();
586 tab->navigations.push_back(navigation); 586 tab->navigations.push_back(navigation);
587 tab->current_navigation_index = 0; 587 tab->current_navigation_index = 0;
588 service_->entries_.push_front(tab); 588 service_->entries_.push_front(tab);
589 EXPECT_EQ(max_entries + 1, service_->entries_.size()); 589 EXPECT_EQ(max_entries + 1, service_->entries_.size());
590 service_->PruneEntries(); 590 service_->PruneEntries();
591 EXPECT_EQ(max_entries, service_->entries_.size()); 591 EXPECT_EQ(max_entries, service_->entries_.size());
592 EXPECT_EQ(GURL(kRecentUrl), 592 EXPECT_EQ(GURL(kRecentUrl),
593 static_cast<Tab*>(service_->entries_.front())-> 593 static_cast<Tab*>(service_->entries_.front())->
594 navigations[0].virtual_url()); 594 navigations[0].virtual_url());
595 595
596 // Ignore NTPs. 596 // Ignore NTPs.
597 navigation.set_virtual_url(GURL(chrome::kChromeUINewTabURL)); 597 navigation =
598 navigation.set_title(ASCIIToUTF16("New tab")); 598 SessionTypesTestHelper::CreateNavigation(
599 chrome::kChromeUINewTabURL, "New tab");
599 600
600 tab = new Tab(); 601 tab = new Tab();
601 tab->navigations.push_back(navigation); 602 tab->navigations.push_back(navigation);
602 tab->current_navigation_index = 0; 603 tab->current_navigation_index = 0;
603 service_->entries_.push_front(tab); 604 service_->entries_.push_front(tab);
604 605
605 EXPECT_EQ(max_entries + 1, service_->entries_.size()); 606 EXPECT_EQ(max_entries + 1, service_->entries_.size());
606 service_->PruneEntries(); 607 service_->PruneEntries();
607 EXPECT_EQ(max_entries, service_->entries_.size()); 608 EXPECT_EQ(max_entries, service_->entries_.size());
608 EXPECT_EQ(GURL(kRecentUrl), 609 EXPECT_EQ(GURL(kRecentUrl),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 for (size_t i = 0; i < max_entries + 5; i++) { 653 for (size_t i = 0; i < max_entries + 5; i++) {
653 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); 654 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i))));
654 service_->CreateHistoricalTab(contents(), -1); 655 service_->CreateHistoricalTab(contents(), -1);
655 } 656 }
656 657
657 EXPECT_EQ(max_entries, service_->entries_.size()); 658 EXPECT_EQ(max_entries, service_->entries_.size());
658 // This should not crash. 659 // This should not crash.
659 service_->LoadTabsFromLastSession(); 660 service_->LoadTabsFromLastSession();
660 EXPECT_EQ(max_entries, service_->entries_.size()); 661 EXPECT_EQ(max_entries, service_->entries_.size());
661 } 662 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/tab_restore_service.cc ('k') | chrome/browser/sync/glue/session_model_associator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698