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_factory.h" | 7 #include "chrome/browser/sessions/session_service_factory.h" |
8 #include "chrome/browser/sessions/session_service.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/tab_restore_service.h" | 10 #include "chrome/browser/sessions/tab_restore_service.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 SessionServiceFactory::GetForProfile(profile()); | 109 SessionServiceFactory::GetForProfile(profile()); |
110 SessionID tab_id; | 110 SessionID tab_id; |
111 SessionID window_id; | 111 SessionID window_id; |
112 session_service->SetWindowType( | 112 session_service->SetWindowType( |
113 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 113 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
114 session_service->SetTabWindow(window_id, tab_id); | 114 session_service->SetTabWindow(window_id, tab_id); |
115 session_service->SetTabIndexInWindow(window_id, tab_id, 0); | 115 session_service->SetTabIndexInWindow(window_id, tab_id, 0); |
116 session_service->SetSelectedTabInWindow(window_id, 0); | 116 session_service->SetSelectedTabInWindow(window_id, 0); |
117 if (pinned) | 117 if (pinned) |
118 session_service->SetPinnedState(window_id, tab_id, true); | 118 session_service->SetPinnedState(window_id, tab_id, true); |
119 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());; | 119 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
120 entry->SetURL(url1_); | 120 entry->SetURL(url1_); |
121 session_service->UpdateTabNavigation(window_id, tab_id, 0, *entry.get()); | 121 session_service->UpdateTabNavigation(window_id, tab_id, 0, *entry.get()); |
122 } | 122 } |
123 | 123 |
124 // Creates a SessionService and assigns it to the Profile. The SessionService | 124 // Creates a SessionService and assigns it to the Profile. The SessionService |
125 // is configured with a single window with a single tab pointing at url1_ by | 125 // is configured with a single window with a single tab pointing at url1_ by |
126 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the | 126 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the |
127 // tab is marked as pinned in the session service. | 127 // tab is marked as pinned in the session service. |
128 void CreateSessionServiceWithOneWindow(bool pinned) { | 128 void CreateSessionServiceWithOneWindow(bool pinned) { |
129 // The profile takes ownership of this. | 129 // The profile takes ownership of this. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 282 |
283 // One entry should be created. | 283 // One entry should be created. |
284 ASSERT_EQ(1U, trs->entries().size()); | 284 ASSERT_EQ(1U, trs->entries().size()); |
285 const TabRestoreService::Entry* restored_entry = trs->entries().front(); | 285 const TabRestoreService::Entry* restored_entry = trs->entries().front(); |
286 | 286 |
287 // It should be a window with an app. | 287 // It should be a window with an app. |
288 ASSERT_EQ(TabRestoreService::WINDOW, restored_entry->type); | 288 ASSERT_EQ(TabRestoreService::WINDOW, restored_entry->type); |
289 const Window* restored_window = | 289 const Window* restored_window = |
290 static_cast<const Window*>(restored_entry); | 290 static_cast<const Window*>(restored_entry); |
291 EXPECT_EQ(app_name, restored_window->app_name); | 291 EXPECT_EQ(app_name, restored_window->app_name); |
292 | |
293 } | 292 } |
294 #endif | 293 #endif // defined(USE_AURA) |
295 | 294 |
296 // Make sure we persist entries to disk that have post data. | 295 // Make sure we persist entries to disk that have post data. |
297 TEST_F(TabRestoreServiceTest, DontPersistPostData) { | 296 TEST_F(TabRestoreServiceTest, DontPersistPostData) { |
298 AddThreeNavigations(); | 297 AddThreeNavigations(); |
299 controller().GetEntryAtIndex(0)->SetHasPostData(true); | 298 controller().GetEntryAtIndex(0)->SetHasPostData(true); |
300 controller().GetEntryAtIndex(1)->SetHasPostData(true); | 299 controller().GetEntryAtIndex(1)->SetHasPostData(true); |
301 controller().GetEntryAtIndex(2)->SetHasPostData(true); | 300 controller().GetEntryAtIndex(2)->SetHasPostData(true); |
302 | 301 |
303 // Have the service record the tab. | 302 // Have the service record the tab. |
304 service_->CreateHistoricalTab(contents(), -1); | 303 service_->CreateHistoricalTab(contents(), -1); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 // Only keep kMaxEntries around. | 565 // Only keep kMaxEntries around. |
567 EXPECT_EQ(max_entries + 5, service_->entries_.size()); | 566 EXPECT_EQ(max_entries + 5, service_->entries_.size()); |
568 service_->PruneEntries(); | 567 service_->PruneEntries(); |
569 EXPECT_EQ(max_entries, service_->entries_.size()); | 568 EXPECT_EQ(max_entries, service_->entries_.size()); |
570 // Pruning again does nothing. | 569 // Pruning again does nothing. |
571 service_->PruneEntries(); | 570 service_->PruneEntries(); |
572 EXPECT_EQ(max_entries, service_->entries_.size()); | 571 EXPECT_EQ(max_entries, service_->entries_.size()); |
573 | 572 |
574 // Prune older first. | 573 // Prune older first. |
575 TabNavigation navigation; | 574 TabNavigation navigation; |
576 navigation.set_virtual_url(GURL("http://recent")); | 575 const char kRecentUrl[] = "http://recent"; |
| 576 navigation.set_virtual_url(GURL(kRecentUrl)); |
577 navigation.set_title(ASCIIToUTF16("Most recent")); | 577 navigation.set_title(ASCIIToUTF16("Most recent")); |
578 Tab* tab = new Tab(); | 578 Tab* tab = new Tab(); |
579 tab->navigations.push_back(navigation); | 579 tab->navigations.push_back(navigation); |
580 tab->current_navigation_index = 0; | 580 tab->current_navigation_index = 0; |
581 service_->entries_.push_front(tab); | 581 service_->entries_.push_front(tab); |
582 EXPECT_EQ(max_entries + 1, service_->entries_.size()); | 582 EXPECT_EQ(max_entries + 1, service_->entries_.size()); |
583 service_->PruneEntries(); | 583 service_->PruneEntries(); |
584 EXPECT_EQ(max_entries, service_->entries_.size()); | 584 EXPECT_EQ(max_entries, service_->entries_.size()); |
585 EXPECT_EQ(GURL("http://recent"), | 585 EXPECT_EQ(GURL(kRecentUrl), |
586 static_cast<Tab*>(service_->entries_.front())-> | 586 static_cast<Tab*>(service_->entries_.front())-> |
587 navigations[0].virtual_url()); | 587 navigations[0].virtual_url()); |
588 | 588 |
589 // Ignore NTPs. | 589 // Ignore NTPs. |
590 navigation.set_virtual_url(GURL(chrome::kChromeUINewTabURL)); | 590 navigation.set_virtual_url(GURL(chrome::kChromeUINewTabURL)); |
591 navigation.set_title(ASCIIToUTF16("New tab")); | 591 navigation.set_title(ASCIIToUTF16("New tab")); |
592 | 592 |
593 tab = new Tab(); | 593 tab = new Tab(); |
594 tab->navigations.push_back(navigation); | 594 tab->navigations.push_back(navigation); |
595 tab->current_navigation_index = 0; | 595 tab->current_navigation_index = 0; |
596 service_->entries_.push_front(tab); | 596 service_->entries_.push_front(tab); |
597 | 597 |
598 EXPECT_EQ(max_entries + 1, service_->entries_.size()); | 598 EXPECT_EQ(max_entries + 1, service_->entries_.size()); |
599 service_->PruneEntries(); | 599 service_->PruneEntries(); |
600 EXPECT_EQ(max_entries, service_->entries_.size()); | 600 EXPECT_EQ(max_entries, service_->entries_.size()); |
601 EXPECT_EQ(GURL("http://recent"), | 601 EXPECT_EQ(GURL(kRecentUrl), |
602 static_cast<Tab*>(service_->entries_.front())-> | 602 static_cast<Tab*>(service_->entries_.front())-> |
603 navigations[0].virtual_url()); | 603 navigations[0].virtual_url()); |
604 | 604 |
605 // Don't prune pinned NTPs. | 605 // Don't prune pinned NTPs. |
606 tab = new Tab(); | 606 tab = new Tab(); |
607 tab->pinned = true; | 607 tab->pinned = true; |
608 tab->current_navigation_index = 0; | 608 tab->current_navigation_index = 0; |
609 tab->navigations.push_back(navigation); | 609 tab->navigations.push_back(navigation); |
610 service_->entries_.push_front(tab); | 610 service_->entries_.push_front(tab); |
611 EXPECT_EQ(max_entries + 1, service_->entries_.size()); | 611 EXPECT_EQ(max_entries + 1, service_->entries_.size()); |
612 service_->PruneEntries(); | 612 service_->PruneEntries(); |
613 EXPECT_EQ(max_entries, service_->entries_.size()); | 613 EXPECT_EQ(max_entries, service_->entries_.size()); |
614 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 614 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
615 static_cast<Tab*>(service_->entries_.front())-> | 615 static_cast<Tab*>(service_->entries_.front())-> |
616 navigations[0].virtual_url()); | 616 navigations[0].virtual_url()); |
617 | 617 |
618 // Don't prune NTPs that have multiple navigations. | 618 // Don't prune NTPs that have multiple navigations. |
619 // (Erase the last NTP first.) | 619 // (Erase the last NTP first.) |
| 620 delete service_->entries_.front(); |
620 service_->entries_.erase(service_->entries_.begin()); | 621 service_->entries_.erase(service_->entries_.begin()); |
621 tab = new Tab(); | 622 tab = new Tab(); |
622 tab->current_navigation_index = 1; | 623 tab->current_navigation_index = 1; |
623 tab->navigations.push_back(navigation); | 624 tab->navigations.push_back(navigation); |
624 tab->navigations.push_back(navigation); | 625 tab->navigations.push_back(navigation); |
625 service_->entries_.push_front(tab); | 626 service_->entries_.push_front(tab); |
626 EXPECT_EQ(max_entries, service_->entries_.size()); | 627 EXPECT_EQ(max_entries, service_->entries_.size()); |
627 service_->PruneEntries(); | 628 service_->PruneEntries(); |
628 EXPECT_EQ(max_entries, service_->entries_.size()); | 629 EXPECT_EQ(max_entries, service_->entries_.size()); |
629 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 630 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
(...skipping 14 matching lines...) Expand all Loading... |
644 for (size_t i = 0; i < max_entries + 5; i++) { | 645 for (size_t i = 0; i < max_entries + 5; i++) { |
645 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); | 646 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); |
646 service_->CreateHistoricalTab(contents(), -1); | 647 service_->CreateHistoricalTab(contents(), -1); |
647 } | 648 } |
648 | 649 |
649 EXPECT_EQ(max_entries, service_->entries_.size()); | 650 EXPECT_EQ(max_entries, service_->entries_.size()); |
650 // This should not crash. | 651 // This should not crash. |
651 service_->LoadTabsFromLastSession(); | 652 service_->LoadTabsFromLastSession(); |
652 EXPECT_EQ(max_entries, service_->entries_.size()); | 653 EXPECT_EQ(max_entries, service_->entries_.size()); |
653 } | 654 } |
OLD | NEW |