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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/sessions/session_service.h" | 10 #include "chrome/browser/sessions/session_service.h" |
11 #include "chrome/browser/sessions/session_service_factory.h" | 11 #include "chrome/browser/sessions/session_service_factory.h" |
12 #include "chrome/browser/sessions/session_types.h" | 12 #include "chrome/browser/sessions/session_types.h" |
13 #include "chrome/browser/sessions/persistent_tab_restore_service.h" | 13 #include "chrome/browser/sessions/persistent_tab_restore_service.h" |
14 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 14 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 15 #include "chrome/browser/sync/glue/local_device_info_provider_mock.h" |
15 #include "chrome/browser/sync/glue/synced_session.h" | 16 #include "chrome/browser/sync/glue/synced_session.h" |
16 #include "chrome/browser/sync/profile_sync_service_mock.h" | 17 #include "chrome/browser/sync/profile_sync_service_mock.h" |
17 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" | 18 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" | 22 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/test/base/browser_with_test_window_test.h" | 24 #include "chrome/test/base/browser_with_test_window_test.h" |
24 #include "chrome/test/base/menu_model_test.h" | 25 #include "chrome/test/base/menu_model_test.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 public: | 103 public: |
103 virtual ~DummyRouter() {} | 104 virtual ~DummyRouter() {} |
104 virtual void StartRoutingTo( | 105 virtual void StartRoutingTo( |
105 browser_sync::LocalSessionEventHandler* handler) OVERRIDE {} | 106 browser_sync::LocalSessionEventHandler* handler) OVERRIDE {} |
106 virtual void Stop() OVERRIDE {} | 107 virtual void Stop() OVERRIDE {} |
107 }; | 108 }; |
108 | 109 |
109 } // namespace | 110 } // namespace |
110 | 111 |
111 class RecentTabsSubMenuModelTest | 112 class RecentTabsSubMenuModelTest |
112 : public BrowserWithTestWindowTest, | 113 : public BrowserWithTestWindowTest { |
113 public browser_sync::SessionsSyncManager::SyncInternalApiDelegate { | |
114 public: | 114 public: |
115 RecentTabsSubMenuModelTest() | 115 RecentTabsSubMenuModelTest() |
116 : sync_service_(&testing_profile_) { | 116 : sync_service_(&testing_profile_), |
| 117 local_device_(new browser_sync::LocalDeviceInfoProviderMock( |
| 118 "RecentTabsSubMenuModelTest", |
| 119 "Test Machine", |
| 120 "Chromium 10k", |
| 121 "Chrome 10k", |
| 122 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)) { |
117 manager_.reset(new browser_sync::SessionsSyncManager( | 123 manager_.reset(new browser_sync::SessionsSyncManager( |
118 &testing_profile_, | 124 &testing_profile_, |
119 this, | 125 local_device_.get(), |
120 scoped_ptr<browser_sync::LocalSessionEventRouter>( | 126 scoped_ptr<browser_sync::LocalSessionEventRouter>( |
121 new DummyRouter()))); | 127 new DummyRouter()))); |
122 manager_->MergeDataAndStartSyncing( | 128 manager_->MergeDataAndStartSyncing( |
123 syncer::SESSIONS, | 129 syncer::SESSIONS, |
124 syncer::SyncDataList(), | 130 syncer::SyncDataList(), |
125 scoped_ptr<syncer::SyncChangeProcessor>( | 131 scoped_ptr<syncer::SyncChangeProcessor>( |
126 new syncer::FakeSyncChangeProcessor), | 132 new syncer::FakeSyncChangeProcessor), |
127 scoped_ptr<syncer::SyncErrorFactory>( | 133 scoped_ptr<syncer::SyncErrorFactory>( |
128 new syncer::SyncErrorFactoryMock)); | 134 new syncer::SyncErrorFactoryMock)); |
129 } | 135 } |
130 | 136 |
131 void WaitForLoadFromLastSession() { | 137 void WaitForLoadFromLastSession() { |
132 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 138 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
133 base::RunLoop().RunUntilIdle(); | 139 base::RunLoop().RunUntilIdle(); |
134 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 140 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
135 } | 141 } |
136 | 142 |
137 static KeyedService* GetTabRestoreService( | 143 static KeyedService* GetTabRestoreService( |
138 content::BrowserContext* browser_context) { | 144 content::BrowserContext* browser_context) { |
139 // Ownership is tranfered to the profile. | 145 // Ownership is tranfered to the profile. |
140 return new PersistentTabRestoreService( | 146 return new PersistentTabRestoreService( |
141 Profile::FromBrowserContext(browser_context), NULL); | 147 Profile::FromBrowserContext(browser_context), NULL); |
142 } | 148 } |
143 | 149 |
144 | |
145 browser_sync::OpenTabsUIDelegate* GetOpenTabsDelegate() { | 150 browser_sync::OpenTabsUIDelegate* GetOpenTabsDelegate() { |
146 return manager_.get(); | 151 return manager_.get(); |
147 } | 152 } |
148 | 153 |
149 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) { | 154 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) { |
150 helper->ExportToSessionsSyncManager(manager_.get()); | 155 helper->ExportToSessionsSyncManager(manager_.get()); |
151 } | 156 } |
152 | 157 |
153 virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo() | |
154 const OVERRIDE { | |
155 return scoped_ptr<browser_sync::DeviceInfo>( | |
156 new browser_sync::DeviceInfo(GetLocalSyncCacheGUID(), | |
157 "Test Machine", | |
158 "Chromium 10k", | |
159 "Chrome 10k", | |
160 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)); | |
161 } | |
162 | |
163 virtual std::string GetLocalSyncCacheGUID() const OVERRIDE { | |
164 return "RecentTabsSubMenuModelTest"; | |
165 } | |
166 | |
167 private: | 158 private: |
168 TestingProfile testing_profile_; | 159 TestingProfile testing_profile_; |
169 testing::NiceMock<ProfileSyncServiceMock> sync_service_; | 160 testing::NiceMock<ProfileSyncServiceMock> sync_service_; |
170 | 161 |
171 scoped_ptr<browser_sync::SessionsSyncManager> manager_; | 162 scoped_ptr<browser_sync::SessionsSyncManager> manager_; |
| 163 scoped_ptr<browser_sync::LocalDeviceInfoProviderMock> local_device_; |
172 }; | 164 }; |
173 | 165 |
174 // Test disabled "Recently closed" header with no foreign tabs. | 166 // Test disabled "Recently closed" header with no foreign tabs. |
175 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { | 167 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { |
176 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 168 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
177 | 169 |
178 // Expected menu: | 170 // Expected menu: |
179 // Menu index Menu items | 171 // Menu index Menu items |
180 // --------------------------------------------- | 172 // --------------------------------------------- |
181 // 0 Recently closed header (disabled) | 173 // 0 Recently closed header (disabled) |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 // 0 Recently closed heaer (disabled) | 551 // 0 Recently closed heaer (disabled) |
560 // 1 <separator> | 552 // 1 <separator> |
561 // 2 No tabs from other Devices | 553 // 2 No tabs from other Devices |
562 | 554 |
563 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 555 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); |
564 EXPECT_EQ(3, model.GetItemCount()); | 556 EXPECT_EQ(3, model.GetItemCount()); |
565 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); | 557 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); |
566 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); | 558 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); |
567 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 559 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
568 } | 560 } |
OLD | NEW |