| 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" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/search/search.h" |
| 14 #include "chrome/browser/sessions/session_service.h" | 15 #include "chrome/browser/sessions/session_service.h" |
| 15 #include "chrome/browser/sessions/session_service_factory.h" | 16 #include "chrome/browser/sessions/session_service_factory.h" |
| 16 #include "chrome/browser/sessions/session_types.h" | 17 #include "chrome/browser/sessions/session_types.h" |
| 17 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 18 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 18 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 19 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 22 #include "chrome/test/base/chrome_render_view_test.h" | 23 #include "chrome/test/base/chrome_render_view_test.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 685 |
| 685 // Don't prune pinned NTPs. | 686 // Don't prune pinned NTPs. |
| 686 tab = new Tab(); | 687 tab = new Tab(); |
| 687 tab->pinned = true; | 688 tab->pinned = true; |
| 688 tab->current_navigation_index = 0; | 689 tab->current_navigation_index = 0; |
| 689 tab->navigations.push_back(navigation); | 690 tab->navigations.push_back(navigation); |
| 690 mutable_entries()->push_front(tab); | 691 mutable_entries()->push_front(tab); |
| 691 EXPECT_EQ(max_entries + 1, service_->entries().size()); | 692 EXPECT_EQ(max_entries + 1, service_->entries().size()); |
| 692 PruneEntries(); | 693 PruneEntries(); |
| 693 EXPECT_EQ(max_entries, service_->entries().size()); | 694 EXPECT_EQ(max_entries, service_->entries().size()); |
| 694 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 695 EXPECT_TRUE(chrome::IsNTPURL( |
| 695 static_cast<Tab*>(service_->entries().front())-> | 696 static_cast<Tab*>(service_->entries().front())-> |
| 696 navigations[0].virtual_url()); | 697 navigations[0].virtual_url(), profile())); |
| 697 | 698 |
| 698 // Don't prune NTPs that have multiple navigations. | 699 // Don't prune NTPs that have multiple navigations. |
| 699 // (Erase the last NTP first.) | 700 // (Erase the last NTP first.) |
| 700 delete service_->entries().front(); | 701 delete service_->entries().front(); |
| 701 mutable_entries()->erase(mutable_entries()->begin()); | 702 mutable_entries()->erase(mutable_entries()->begin()); |
| 702 tab = new Tab(); | 703 tab = new Tab(); |
| 703 tab->current_navigation_index = 1; | 704 tab->current_navigation_index = 1; |
| 704 tab->navigations.push_back(navigation); | 705 tab->navigations.push_back(navigation); |
| 705 tab->navigations.push_back(navigation); | 706 tab->navigations.push_back(navigation); |
| 706 mutable_entries()->push_front(tab); | 707 mutable_entries()->push_front(tab); |
| 707 EXPECT_EQ(max_entries, service_->entries().size()); | 708 EXPECT_EQ(max_entries, service_->entries().size()); |
| 708 PruneEntries(); | 709 PruneEntries(); |
| 709 EXPECT_EQ(max_entries, service_->entries().size()); | 710 EXPECT_EQ(max_entries, service_->entries().size()); |
| 710 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 711 EXPECT_TRUE(chrome::IsNTPURL( |
| 711 static_cast<Tab*>(service_->entries().front())-> | 712 static_cast<Tab*>(service_->entries().front())-> |
| 712 navigations[1].virtual_url()); | 713 navigations[1].virtual_url(), profile())); |
| 713 } | 714 } |
| 714 | 715 |
| 715 // Regression test for crbug.com/106082 | 716 // Regression test for crbug.com/106082 |
| 716 TEST_F(PersistentTabRestoreServiceTest, PruneIsCalled) { | 717 TEST_F(PersistentTabRestoreServiceTest, PruneIsCalled) { |
| 717 CreateSessionServiceWithOneWindow(false); | 718 CreateSessionServiceWithOneWindow(false); |
| 718 | 719 |
| 719 SessionServiceFactory::GetForProfile(profile())-> | 720 SessionServiceFactory::GetForProfile(profile())-> |
| 720 MoveCurrentSessionToLastSession(); | 721 MoveCurrentSessionToLastSession(); |
| 721 | 722 |
| 722 profile()->set_restored_last_session(true); | 723 profile()->set_restored_last_session(true); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 746 | 747 |
| 747 EXPECT_FALSE(service_->IsLoaded()); | 748 EXPECT_FALSE(service_->IsLoaded()); |
| 748 TestTabRestoreServiceObserver observer; | 749 TestTabRestoreServiceObserver observer; |
| 749 service_->AddObserver(&observer); | 750 service_->AddObserver(&observer); |
| 750 EXPECT_EQ(max_entries, service_->entries().size()); | 751 EXPECT_EQ(max_entries, service_->entries().size()); |
| 751 SynchronousLoadTabsFromLastSession(); | 752 SynchronousLoadTabsFromLastSession(); |
| 752 EXPECT_TRUE(observer.got_loaded()); | 753 EXPECT_TRUE(observer.got_loaded()); |
| 753 EXPECT_TRUE(service_->IsLoaded()); | 754 EXPECT_TRUE(service_->IsLoaded()); |
| 754 service_->RemoveObserver(&observer); | 755 service_->RemoveObserver(&observer); |
| 755 } | 756 } |
| OLD | NEW |