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/ui/toolbar/recent_tabs_sub_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
6 | 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
7 #include "base/command_line.h" | 10 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
9 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/sessions/persistent_tab_restore_service.h" |
10 #include "chrome/browser/sessions/session_service.h" | 14 #include "chrome/browser/sessions/session_service.h" |
11 #include "chrome/browser/sessions/session_service_factory.h" | 15 #include "chrome/browser/sessions/session_service_factory.h" |
12 #include "chrome/browser/sessions/session_types.h" | 16 #include "chrome/browser/sessions/session_types.h" |
13 #include "chrome/browser/sessions/persistent_tab_restore_service.h" | |
14 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 17 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
15 #include "chrome/browser/sync/glue/local_device_info_provider_mock.h" | 18 #include "chrome/browser/sync/glue/local_device_info_provider_mock.h" |
16 #include "chrome/browser/sync/glue/synced_session.h" | 19 #include "chrome/browser/sync/glue/synced_session.h" |
17 #include "chrome/browser/sync/profile_sync_service_mock.h" | 20 #include "chrome/browser/sync/profile_sync_service_mock.h" |
18 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" | 21 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
19 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" | 25 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" |
23 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/test/base/browser_with_test_window_test.h" | 27 #include "chrome/test/base/browser_with_test_window_test.h" |
25 #include "chrome/test/base/menu_model_test.h" | 28 #include "chrome/test/base/menu_model_test.h" |
26 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
27 #include "components/sessions/serialized_navigation_entry_test_helper.h" | 30 #include "components/sessions/serialized_navigation_entry_test_helper.h" |
28 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/test/test_utils.h" |
| 33 #include "grit/generated_resources.h" |
29 #include "sync/api/fake_sync_change_processor.h" | 34 #include "sync/api/fake_sync_change_processor.h" |
30 #include "sync/api/sync_error_factory_mock.h" | 35 #include "sync/api/sync_error_factory_mock.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
33 | 38 |
34 namespace { | 39 namespace { |
35 | 40 |
36 // This copies parts of MenuModelTest::Delegate and combines them with the | 41 // This copies parts of MenuModelTest::Delegate and combines them with the |
37 // RecentTabsSubMenuModel since RecentTabsSubMenuModel is a | 42 // RecentTabsSubMenuModel since RecentTabsSubMenuModel is a |
38 // SimpleMenuModel::Delegate and not just derived from SimpleMenuModel. | 43 // SimpleMenuModel::Delegate and not just derived from SimpleMenuModel. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 manager_->MergeDataAndStartSyncing( | 133 manager_->MergeDataAndStartSyncing( |
129 syncer::SESSIONS, | 134 syncer::SESSIONS, |
130 syncer::SyncDataList(), | 135 syncer::SyncDataList(), |
131 scoped_ptr<syncer::SyncChangeProcessor>( | 136 scoped_ptr<syncer::SyncChangeProcessor>( |
132 new syncer::FakeSyncChangeProcessor), | 137 new syncer::FakeSyncChangeProcessor), |
133 scoped_ptr<syncer::SyncErrorFactory>( | 138 scoped_ptr<syncer::SyncErrorFactory>( |
134 new syncer::SyncErrorFactoryMock)); | 139 new syncer::SyncErrorFactoryMock)); |
135 } | 140 } |
136 | 141 |
137 void WaitForLoadFromLastSession() { | 142 void WaitForLoadFromLastSession() { |
138 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 143 content::RunAllBlockingPoolTasksUntilIdle(); |
139 base::RunLoop().RunUntilIdle(); | |
140 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
141 } | 144 } |
142 | 145 |
143 static KeyedService* GetTabRestoreService( | 146 static KeyedService* GetTabRestoreService( |
144 content::BrowserContext* browser_context) { | 147 content::BrowserContext* browser_context) { |
145 // Ownership is tranfered to the profile. | 148 // Ownership is tranfered to the profile. |
146 return new PersistentTabRestoreService( | 149 return new PersistentTabRestoreService( |
147 Profile::FromBrowserContext(browser_context), NULL); | 150 Profile::FromBrowserContext(browser_context), NULL); |
148 } | 151 } |
149 | 152 |
150 browser_sync::OpenTabsUIDelegate* GetOpenTabsDelegate() { | 153 browser_sync::OpenTabsUIDelegate* GetOpenTabsDelegate() { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // Move this session to the last so that TabRestoreService will load it as the | 278 // Move this session to the last so that TabRestoreService will load it as the |
276 // last session. | 279 // last session. |
277 SessionServiceFactory::GetForProfile(profile())-> | 280 SessionServiceFactory::GetForProfile(profile())-> |
278 MoveCurrentSessionToLastSession(); | 281 MoveCurrentSessionToLastSession(); |
279 | 282 |
280 // Create a new TabRestoreService so that it'll load the recently closed tabs | 283 // Create a new TabRestoreService so that it'll load the recently closed tabs |
281 // and windows afresh. | 284 // and windows afresh. |
282 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( | 285 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( |
283 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); | 286 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); |
284 // Let the shutdown of previous TabRestoreService run. | 287 // Let the shutdown of previous TabRestoreService run. |
285 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 288 content::RunAllBlockingPoolTasksUntilIdle(); |
286 | 289 |
287 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 290 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
288 TestRecentTabsMenuModelDelegate delegate(&model); | 291 TestRecentTabsMenuModelDelegate delegate(&model); |
289 EXPECT_FALSE(delegate.got_changes()); | 292 EXPECT_FALSE(delegate.got_changes()); |
290 | 293 |
291 // Expected menu before tabs/windows from last session are loaded: | 294 // Expected menu before tabs/windows from last session are loaded: |
292 // Menu index Menu items | 295 // Menu index Menu items |
293 // ---------------------------------------------------------------- | 296 // ---------------------------------------------------------------- |
294 // 0 Recently closed header | 297 // 0 Recently closed header |
295 // 1 <separator> | 298 // 1 <separator> |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // 0 Recently closed heaer (disabled) | 554 // 0 Recently closed heaer (disabled) |
552 // 1 <separator> | 555 // 1 <separator> |
553 // 2 No tabs from other Devices | 556 // 2 No tabs from other Devices |
554 | 557 |
555 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 558 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
556 EXPECT_EQ(3, model.GetItemCount()); | 559 EXPECT_EQ(3, model.GetItemCount()); |
557 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 560 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
558 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | 561 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
559 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 562 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
560 } | 563 } |
OLD | NEW |