| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/toolbar/recent_tabs_sub_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" | 17 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" |
| 17 #include "chrome/browser/sessions/session_service.h" | 18 #include "chrome/browser/sessions/session_service.h" |
| 18 #include "chrome/browser/sessions/session_service_factory.h" | 19 #include "chrome/browser/sessions/session_service_factory.h" |
| 19 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 20 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_test_util.h" | 21 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 "RecentTabsSubMenuModelTest", | 127 "RecentTabsSubMenuModelTest", |
| 127 "Test Machine", | 128 "Test Machine", |
| 128 "Chromium 10k", | 129 "Chromium 10k", |
| 129 "Chrome 10k", | 130 "Chrome 10k", |
| 130 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 131 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
| 131 "device_id")) { | 132 "device_id")) { |
| 132 sync_prefs_.reset(new sync_driver::SyncPrefs(testing_profile_.GetPrefs())); | 133 sync_prefs_.reset(new sync_driver::SyncPrefs(testing_profile_.GetPrefs())); |
| 133 manager_.reset(new browser_sync::SessionsSyncManager( | 134 manager_.reset(new browser_sync::SessionsSyncManager( |
| 134 sync_service_.GetSyncClient()->GetSyncSessionsClient(), | 135 sync_service_.GetSyncClient()->GetSyncSessionsClient(), |
| 135 sync_prefs_.get(), local_device_.get(), | 136 sync_prefs_.get(), local_device_.get(), |
| 136 scoped_ptr<browser_sync::LocalSessionEventRouter>(new DummyRouter()), | 137 std::unique_ptr<browser_sync::LocalSessionEventRouter>( |
| 138 new DummyRouter()), |
| 137 base::Closure(), base::Closure())); | 139 base::Closure(), base::Closure())); |
| 138 manager_->MergeDataAndStartSyncing( | 140 manager_->MergeDataAndStartSyncing( |
| 139 syncer::SESSIONS, | 141 syncer::SESSIONS, syncer::SyncDataList(), |
| 140 syncer::SyncDataList(), | 142 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 141 scoped_ptr<syncer::SyncChangeProcessor>( | 143 new syncer::FakeSyncChangeProcessor), |
| 142 new syncer::FakeSyncChangeProcessor), | 144 std::unique_ptr<syncer::SyncErrorFactory>( |
| 143 scoped_ptr<syncer::SyncErrorFactory>( | |
| 144 new syncer::SyncErrorFactoryMock)); | 145 new syncer::SyncErrorFactoryMock)); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void WaitForLoadFromLastSession() { | 148 void WaitForLoadFromLastSession() { |
| 148 content::RunAllBlockingPoolTasksUntilIdle(); | 149 content::RunAllBlockingPoolTasksUntilIdle(); |
| 149 } | 150 } |
| 150 | 151 |
| 151 static scoped_ptr<KeyedService> GetTabRestoreService( | 152 static std::unique_ptr<KeyedService> GetTabRestoreService( |
| 152 content::BrowserContext* browser_context) { | 153 content::BrowserContext* browser_context) { |
| 153 return make_scoped_ptr(new sessions::PersistentTabRestoreService( | 154 return base::WrapUnique(new sessions::PersistentTabRestoreService( |
| 154 make_scoped_ptr(new ChromeTabRestoreServiceClient( | 155 base::WrapUnique(new ChromeTabRestoreServiceClient( |
| 155 Profile::FromBrowserContext(browser_context))), | 156 Profile::FromBrowserContext(browser_context))), |
| 156 nullptr)); | 157 nullptr)); |
| 157 } | 158 } |
| 158 | 159 |
| 159 sync_driver::OpenTabsUIDelegate* GetOpenTabsDelegate() { | 160 sync_driver::OpenTabsUIDelegate* GetOpenTabsDelegate() { |
| 160 return manager_.get(); | 161 return manager_.get(); |
| 161 } | 162 } |
| 162 | 163 |
| 163 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) { | 164 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) { |
| 164 helper->ExportToSessionsSyncManager(manager_.get()); | 165 helper->ExportToSessionsSyncManager(manager_.get()); |
| 165 } | 166 } |
| 166 | 167 |
| 167 private: | 168 private: |
| 168 TestingProfile testing_profile_; | 169 TestingProfile testing_profile_; |
| 169 ProfileSyncServiceMock sync_service_; | 170 ProfileSyncServiceMock sync_service_; |
| 170 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_; | 171 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_; |
| 171 scoped_ptr<browser_sync::SessionsSyncManager> manager_; | 172 std::unique_ptr<browser_sync::SessionsSyncManager> manager_; |
| 172 scoped_ptr<sync_driver::LocalDeviceInfoProviderMock> local_device_; | 173 std::unique_ptr<sync_driver::LocalDeviceInfoProviderMock> local_device_; |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 // Test disabled "Recently closed" header with no foreign tabs. | 176 // Test disabled "Recently closed" header with no foreign tabs. |
| 176 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { | 177 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { |
| 177 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 178 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
| 178 | 179 |
| 179 // Expected menu: | 180 // Expected menu: |
| 180 // Menu index Menu items | 181 // Menu index Menu items |
| 181 // --------------------------------------------- | 182 // --------------------------------------------- |
| 182 // 0 History | 183 // 0 History |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 277 |
| 277 // Add 2 tabs and close them. | 278 // Add 2 tabs and close them. |
| 278 AddTab(browser(), GURL("http://wnd/tab0")); | 279 AddTab(browser(), GURL("http://wnd/tab0")); |
| 279 AddTab(browser(), GURL("http://wnd/tab1")); | 280 AddTab(browser(), GURL("http://wnd/tab1")); |
| 280 browser()->tab_strip_model()->CloseAllTabs(); | 281 browser()->tab_strip_model()->CloseAllTabs(); |
| 281 | 282 |
| 282 // Create a SessionService for the profile (profile owns the service) and add | 283 // Create a SessionService for the profile (profile owns the service) and add |
| 283 // a window with a tab to this session. | 284 // a window with a tab to this session. |
| 284 SessionService* session_service = new SessionService(profile()); | 285 SessionService* session_service = new SessionService(profile()); |
| 285 SessionServiceFactory::SetForTestProfile(profile(), | 286 SessionServiceFactory::SetForTestProfile(profile(), |
| 286 make_scoped_ptr(session_service)); | 287 base::WrapUnique(session_service)); |
| 287 SessionID tab_id; | 288 SessionID tab_id; |
| 288 SessionID window_id; | 289 SessionID window_id; |
| 289 session_service->SetWindowType(window_id, | 290 session_service->SetWindowType(window_id, |
| 290 Browser::TYPE_TABBED, | 291 Browser::TYPE_TABBED, |
| 291 SessionService::TYPE_NORMAL); | 292 SessionService::TYPE_NORMAL); |
| 292 session_service->SetTabWindow(window_id, tab_id); | 293 session_service->SetTabWindow(window_id, tab_id); |
| 293 session_service->SetTabIndexInWindow(window_id, tab_id, 0); | 294 session_service->SetTabIndexInWindow(window_id, tab_id, 0); |
| 294 session_service->SetSelectedTabInWindow(window_id, 0); | 295 session_service->SetSelectedTabInWindow(window_id, 0); |
| 295 session_service->UpdateTabNavigation( | 296 session_service->UpdateTabNavigation( |
| 296 window_id, tab_id, | 297 window_id, tab_id, |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 // 2 Recently closed heaer (disabled) | 601 // 2 Recently closed heaer (disabled) |
| 601 // 3 <separator> | 602 // 3 <separator> |
| 602 // 4 No tabs from other Devices | 603 // 4 No tabs from other Devices |
| 603 | 604 |
| 604 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 605 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
| 605 EXPECT_EQ(5, model.GetItemCount()); | 606 EXPECT_EQ(5, model.GetItemCount()); |
| 606 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 607 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
| 607 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); | 608 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
| 608 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(4)); | 609 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(4)); |
| 609 } | 610 } |
| OLD | NEW |