| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" |
| 15 #include "chrome/browser/sessions/session_service.h" | 16 #include "chrome/browser/sessions/session_service.h" |
| 16 #include "chrome/browser/sessions/session_service_factory.h" | 17 #include "chrome/browser/sessions/session_service_factory.h" |
| 17 #include "chrome/browser/sessions/session_service_utils.h" | 18 #include "chrome/browser/sessions/session_service_utils.h" |
| 18 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 19 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 19 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 20 #include "chrome/browser/sessions/tab_restore_service_observer.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/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/sessions/serialized_navigation_entry_test_helper.h" | 25 #include "components/sessions/serialized_navigation_entry_test_helper.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 protected: | 74 protected: |
| 74 enum { | 75 enum { |
| 75 kMaxEntries = TabRestoreServiceHelper::kMaxEntries, | 76 kMaxEntries = TabRestoreServiceHelper::kMaxEntries, |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 // testing::Test: | 79 // testing::Test: |
| 79 void SetUp() override { | 80 void SetUp() override { |
| 80 ChromeRenderViewHostTestHarness::SetUp(); | 81 ChromeRenderViewHostTestHarness::SetUp(); |
| 81 time_factory_ = new PersistentTabRestoreTimeFactory(); | 82 time_factory_ = new PersistentTabRestoreTimeFactory(); |
| 82 service_.reset(new PersistentTabRestoreService(profile(), time_factory_)); | 83 service_.reset(new PersistentTabRestoreService( |
| 84 profile(), |
| 85 make_scoped_ptr(new ChromeTabRestoreServiceClient(profile())), |
| 86 time_factory_)); |
| 83 } | 87 } |
| 84 | 88 |
| 85 void TearDown() override { | 89 void TearDown() override { |
| 86 service_->Shutdown(); | 90 service_->Shutdown(); |
| 87 service_.reset(); | 91 service_.reset(); |
| 88 delete time_factory_; | 92 delete time_factory_; |
| 89 ChromeRenderViewHostTestHarness::TearDown(); | 93 ChromeRenderViewHostTestHarness::TearDown(); |
| 90 } | 94 } |
| 91 | 95 |
| 92 TabRestoreService::Entries* mutable_entries() { | 96 TabRestoreService::Entries* mutable_entries() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 110 controller().GoToIndex(index); | 114 controller().GoToIndex(index); |
| 111 WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 115 WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void RecreateService() { | 118 void RecreateService() { |
| 115 // Must set service to null first so that it is destroyed before the new | 119 // Must set service to null first so that it is destroyed before the new |
| 116 // one is created. | 120 // one is created. |
| 117 service_->Shutdown(); | 121 service_->Shutdown(); |
| 118 content::RunAllBlockingPoolTasksUntilIdle(); | 122 content::RunAllBlockingPoolTasksUntilIdle(); |
| 119 service_.reset(); | 123 service_.reset(); |
| 120 service_.reset(new PersistentTabRestoreService(profile(), time_factory_)); | 124 service_.reset(new PersistentTabRestoreService( |
| 125 profile(), |
| 126 make_scoped_ptr(new ChromeTabRestoreServiceClient(profile())), |
| 127 time_factory_)); |
| 121 SynchronousLoadTabsFromLastSession(); | 128 SynchronousLoadTabsFromLastSession(); |
| 122 } | 129 } |
| 123 | 130 |
| 124 // Adds a window with one tab and url to the profile's session service. | 131 // Adds a window with one tab and url to the profile's session service. |
| 125 // If |pinned| is true, the tab is marked as pinned in the session service. | 132 // If |pinned| is true, the tab is marked as pinned in the session service. |
| 126 void AddWindowWithOneTabToSessionService(bool pinned) { | 133 void AddWindowWithOneTabToSessionService(bool pinned) { |
| 127 SessionService* session_service = | 134 SessionService* session_service = |
| 128 SessionServiceFactory::GetForProfile(profile()); | 135 SessionServiceFactory::GetForProfile(profile()); |
| 129 SessionID tab_id; | 136 SessionID tab_id; |
| 130 SessionID window_id; | 137 SessionID window_id; |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 762 |
| 756 EXPECT_FALSE(service_->IsLoaded()); | 763 EXPECT_FALSE(service_->IsLoaded()); |
| 757 TestTabRestoreServiceObserver observer; | 764 TestTabRestoreServiceObserver observer; |
| 758 service_->AddObserver(&observer); | 765 service_->AddObserver(&observer); |
| 759 EXPECT_EQ(max_entries, service_->entries().size()); | 766 EXPECT_EQ(max_entries, service_->entries().size()); |
| 760 SynchronousLoadTabsFromLastSession(); | 767 SynchronousLoadTabsFromLastSession(); |
| 761 EXPECT_TRUE(observer.got_loaded()); | 768 EXPECT_TRUE(observer.got_loaded()); |
| 762 EXPECT_TRUE(service_->IsLoaded()); | 769 EXPECT_TRUE(service_->IsLoaded()); |
| 763 service_->RemoveObserver(&observer); | 770 service_->RemoveObserver(&observer); |
| 764 } | 771 } |
| OLD | NEW |