| 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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 | 729 |
| 729 // Don't prune pinned NTPs. | 730 // Don't prune pinned NTPs. |
| 730 tab = new Tab(); | 731 tab = new Tab(); |
| 731 tab->pinned = true; | 732 tab->pinned = true; |
| 732 tab->current_navigation_index = 0; | 733 tab->current_navigation_index = 0; |
| 733 tab->navigations.push_back(navigation); | 734 tab->navigations.push_back(navigation); |
| 734 mutable_entries()->push_front(tab); | 735 mutable_entries()->push_front(tab); |
| 735 EXPECT_EQ(max_entries + 1, service_->entries().size()); | 736 EXPECT_EQ(max_entries + 1, service_->entries().size()); |
| 736 PruneEntries(); | 737 PruneEntries(); |
| 737 EXPECT_EQ(max_entries, service_->entries().size()); | 738 EXPECT_EQ(max_entries, service_->entries().size()); |
| 738 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 739 EXPECT_TRUE(chrome::IsNTPURL( |
| 739 static_cast<Tab*>(service_->entries().front())-> | 740 static_cast<Tab*>(service_->entries().front())-> |
| 740 navigations[0].virtual_url()); | 741 navigations[0].virtual_url(), profile())); |
| 741 | 742 |
| 742 // Don't prune NTPs that have multiple navigations. | 743 // Don't prune NTPs that have multiple navigations. |
| 743 // (Erase the last NTP first.) | 744 // (Erase the last NTP first.) |
| 744 delete service_->entries().front(); | 745 delete service_->entries().front(); |
| 745 mutable_entries()->erase(mutable_entries()->begin()); | 746 mutable_entries()->erase(mutable_entries()->begin()); |
| 746 tab = new Tab(); | 747 tab = new Tab(); |
| 747 tab->current_navigation_index = 1; | 748 tab->current_navigation_index = 1; |
| 748 tab->navigations.push_back(navigation); | 749 tab->navigations.push_back(navigation); |
| 749 tab->navigations.push_back(navigation); | 750 tab->navigations.push_back(navigation); |
| 750 mutable_entries()->push_front(tab); | 751 mutable_entries()->push_front(tab); |
| 751 EXPECT_EQ(max_entries, service_->entries().size()); | 752 EXPECT_EQ(max_entries, service_->entries().size()); |
| 752 PruneEntries(); | 753 PruneEntries(); |
| 753 EXPECT_EQ(max_entries, service_->entries().size()); | 754 EXPECT_EQ(max_entries, service_->entries().size()); |
| 754 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 755 EXPECT_TRUE(chrome::IsNTPURL( |
| 755 static_cast<Tab*>(service_->entries().front())-> | 756 static_cast<Tab*>(service_->entries().front())-> |
| 756 navigations[1].virtual_url()); | 757 navigations[1].virtual_url(), profile())); |
| 757 } | 758 } |
| 758 | 759 |
| 759 // Regression test for crbug.com/106082 | 760 // Regression test for crbug.com/106082 |
| 760 TEST_F(PersistentTabRestoreServiceTest, PruneIsCalled) { | 761 TEST_F(PersistentTabRestoreServiceTest, PruneIsCalled) { |
| 761 CreateSessionServiceWithOneWindow(false); | 762 CreateSessionServiceWithOneWindow(false); |
| 762 | 763 |
| 763 SessionServiceFactory::GetForProfile(profile())-> | 764 SessionServiceFactory::GetForProfile(profile())-> |
| 764 MoveCurrentSessionToLastSession(); | 765 MoveCurrentSessionToLastSession(); |
| 765 | 766 |
| 766 profile()->set_restored_last_session(true); | 767 profile()->set_restored_last_session(true); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 790 | 791 |
| 791 EXPECT_FALSE(service_->IsLoaded()); | 792 EXPECT_FALSE(service_->IsLoaded()); |
| 792 TestTabRestoreServiceObserver observer; | 793 TestTabRestoreServiceObserver observer; |
| 793 service_->AddObserver(&observer); | 794 service_->AddObserver(&observer); |
| 794 EXPECT_EQ(max_entries, service_->entries().size()); | 795 EXPECT_EQ(max_entries, service_->entries().size()); |
| 795 SynchronousLoadTabsFromLastSession(); | 796 SynchronousLoadTabsFromLastSession(); |
| 796 EXPECT_TRUE(observer.got_loaded()); | 797 EXPECT_TRUE(observer.got_loaded()); |
| 797 EXPECT_TRUE(service_->IsLoaded()); | 798 EXPECT_TRUE(service_->IsLoaded()); |
| 798 service_->RemoveObserver(&observer); | 799 service_->RemoveObserver(&observer); |
| 799 } | 800 } |
| OLD | NEW |