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 <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/utf_string_conversions.h" | |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" | 18 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" |
18 #include "chrome/browser/sessions/session_service.h" | 19 #include "chrome/browser/sessions/session_service.h" |
19 #include "chrome/browser/sessions/session_service_factory.h" | 20 #include "chrome/browser/sessions/session_service_factory.h" |
20 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 21 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
22 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
21 #include "chrome/browser/sync/profile_sync_test_util.h" | 23 #include "chrome/browser/sync/profile_sync_test_util.h" |
22 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_tabstrip.h" | 25 #include "chrome/browser/ui/browser_tabstrip.h" |
24 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" | 26 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" |
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
26 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" | 28 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" |
27 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/test/base/browser_with_test_window_test.h" | 30 #include "chrome/test/base/browser_with_test_window_test.h" |
29 #include "chrome/test/base/menu_model_test.h" | 31 #include "chrome/test/base/menu_model_test.h" |
30 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
31 #include "components/browser_sync/profile_sync_service_mock.h" | 33 #include "components/browser_sync/profile_sync_service_mock.h" |
32 #include "components/sessions/core/persistent_tab_restore_service.h" | 34 #include "components/sessions/core/persistent_tab_restore_service.h" |
33 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" | 35 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" |
34 #include "components/sessions/core/session_types.h" | 36 #include "components/sessions/core/session_types.h" |
35 #include "components/sync/base/sync_prefs.h" | 37 #include "components/sync/base/sync_prefs.h" |
36 #include "components/sync/device_info/local_device_info_provider_mock.h" | 38 #include "components/sync/device_info/local_device_info_provider_mock.h" |
37 #include "components/sync/driver/sync_client.h" | 39 #include "components/sync/driver/sync_client.h" |
38 #include "components/sync/model/fake_sync_change_processor.h" | 40 #include "components/sync/model/fake_sync_change_processor.h" |
39 #include "components/sync/model/sync_error_factory_mock.h" | 41 #include "components/sync/model/sync_error_factory_mock.h" |
40 #include "components/sync_sessions/sessions_sync_manager.h" | 42 #include "components/sync_sessions/sessions_sync_manager.h" |
41 #include "components/sync_sessions/synced_session.h" | 43 #include "components/sync_sessions/synced_session.h" |
42 #include "content/public/browser/browser_thread.h" | 44 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/test/test_utils.h" | 45 #include "content/public/test/test_utils.h" |
44 #include "testing/gmock/include/gmock/gmock.h" | 46 #include "testing/gmock/include/gmock/gmock.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
46 | 48 |
49 using testing::_; | |
50 using testing::Invoke; | |
51 using testing::Return; | |
52 | |
47 namespace { | 53 namespace { |
48 | 54 |
49 // This copies parts of MenuModelTest::Delegate and combines them with the | 55 // This copies parts of MenuModelTest::Delegate and combines them with the |
50 // RecentTabsSubMenuModel since RecentTabsSubMenuModel is a | 56 // RecentTabsSubMenuModel since RecentTabsSubMenuModel is a |
51 // SimpleMenuModel::Delegate and not just derived from SimpleMenuModel. | 57 // SimpleMenuModel::Delegate and not just derived from SimpleMenuModel. |
52 class TestRecentTabsSubMenuModel : public RecentTabsSubMenuModel { | 58 class TestRecentTabsSubMenuModel : public RecentTabsSubMenuModel { |
53 public: | 59 public: |
54 TestRecentTabsSubMenuModel(ui::AcceleratorProvider* provider, | 60 TestRecentTabsSubMenuModel(ui::AcceleratorProvider* provider, |
55 Browser* browser, | 61 Browser* browser) |
56 sync_sessions::OpenTabsUIDelegate* delegate) | 62 : RecentTabsSubMenuModel(provider, browser), |
57 : RecentTabsSubMenuModel(provider, browser, delegate), | |
58 execute_count_(0), | 63 execute_count_(0), |
59 enable_count_(0) {} | 64 enable_count_(0) {} |
60 | 65 |
61 // Testing overrides to ui::SimpleMenuModel::Delegate: | 66 // Testing overrides to ui::SimpleMenuModel::Delegate: |
62 bool IsCommandIdEnabled(int command_id) const override { | 67 bool IsCommandIdEnabled(int command_id) const override { |
63 bool val = RecentTabsSubMenuModel::IsCommandIdEnabled(command_id); | 68 bool val = RecentTabsSubMenuModel::IsCommandIdEnabled(command_id); |
64 if (val) | 69 if (val) |
65 ++enable_count_; | 70 ++enable_count_; |
66 return val; | 71 return val; |
67 } | 72 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 }; | 113 }; |
109 | 114 |
110 class DummyRouter : public sync_sessions::LocalSessionEventRouter { | 115 class DummyRouter : public sync_sessions::LocalSessionEventRouter { |
111 public: | 116 public: |
112 ~DummyRouter() override {} | 117 ~DummyRouter() override {} |
113 void StartRoutingTo( | 118 void StartRoutingTo( |
114 sync_sessions::LocalSessionEventHandler* handler) override {} | 119 sync_sessions::LocalSessionEventHandler* handler) override {} |
115 void Stop() override {} | 120 void Stop() override {} |
116 }; | 121 }; |
117 | 122 |
123 class FakeSyncServiceObserverList { | |
124 public: | |
125 FakeSyncServiceObserverList() {} | |
126 ~FakeSyncServiceObserverList() {} | |
127 | |
128 void AddObserver(syncer::SyncServiceObserver* observer) { | |
129 observers_.AddObserver(observer); | |
130 } | |
131 | |
132 void RemoveObserver(syncer::SyncServiceObserver* observer) { | |
133 observers_.RemoveObserver(observer); | |
134 } | |
135 | |
136 void NotifyForeignSessionUpdated() { | |
137 for (auto& observer : observers_) | |
138 observer.OnForeignSessionUpdated(nullptr); | |
139 } | |
140 | |
141 private: | |
142 base::ObserverList<syncer::SyncServiceObserver> observers_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(FakeSyncServiceObserverList); | |
145 }; | |
146 | |
118 } // namespace | 147 } // namespace |
119 | 148 |
120 class RecentTabsSubMenuModelTest | 149 class RecentTabsSubMenuModelTest |
121 : public BrowserWithTestWindowTest { | 150 : public BrowserWithTestWindowTest { |
122 public: | 151 public: |
123 RecentTabsSubMenuModelTest() | 152 RecentTabsSubMenuModelTest() {} |
124 : sync_service_(CreateProfileSyncServiceParamsForTest(&testing_profile_)), | 153 |
125 local_device_(new syncer::LocalDeviceInfoProviderMock( | 154 void SetUp() override { |
126 "RecentTabsSubMenuModelTest", | 155 BrowserWithTestWindowTest::SetUp(); |
127 "Test Machine", | 156 |
128 "Chromium 10k", | 157 local_device_ = base::MakeUnique<syncer::LocalDeviceInfoProviderMock>( |
129 "Chrome 10k", | 158 "RecentTabsSubMenuModelTest", "Test Machine", "Chromium 10k", |
130 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 159 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"); |
131 "device_id")) { | 160 sync_prefs_ = base::MakeUnique<syncer::SyncPrefs>(profile()->GetPrefs()); |
132 sync_prefs_.reset(new syncer::SyncPrefs(testing_profile_.GetPrefs())); | 161 fake_sync_service_observer_list_ = |
162 base::MakeUnique<FakeSyncServiceObserverList>(); | |
163 | |
164 mock_sync_service_ = static_cast<browser_sync::ProfileSyncServiceMock*>( | |
165 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
166 profile(), BuildMockProfileSyncService)); | |
167 | |
168 EXPECT_CALL(*mock_sync_service_, AddObserver(_)) | |
169 .WillRepeatedly(Invoke(fake_sync_service_observer_list_.get(), | |
170 &FakeSyncServiceObserverList::AddObserver)); | |
171 EXPECT_CALL(*mock_sync_service_, RemoveObserver(_)) | |
172 .WillRepeatedly(Invoke(fake_sync_service_observer_list_.get(), | |
173 &FakeSyncServiceObserverList::RemoveObserver)); | |
174 EXPECT_CALL(*mock_sync_service_, IsSyncActive()) | |
175 .WillRepeatedly(Return(true)); | |
176 EXPECT_CALL(*mock_sync_service_, | |
177 IsDataTypeControllerRunning(syncer::SESSIONS)) | |
178 .WillRepeatedly(Return(true)); | |
179 EXPECT_CALL(*mock_sync_service_, | |
180 IsDataTypeControllerRunning(syncer::PROXY_TABS)) | |
181 .WillRepeatedly(Return(true)); | |
182 | |
133 manager_.reset(new sync_sessions::SessionsSyncManager( | 183 manager_.reset(new sync_sessions::SessionsSyncManager( |
134 sync_service_.GetSyncClient()->GetSyncSessionsClient(), | 184 mock_sync_service_->GetSyncClient()->GetSyncSessionsClient(), |
135 sync_prefs_.get(), local_device_.get(), | 185 sync_prefs_.get(), local_device_.get(), |
136 std::unique_ptr<sync_sessions::LocalSessionEventRouter>( | 186 std::unique_ptr<sync_sessions::LocalSessionEventRouter>( |
137 new DummyRouter()), | 187 new DummyRouter()), |
138 base::Closure(), base::Closure())); | 188 base::Bind(&FakeSyncServiceObserverList::NotifyForeignSessionUpdated, |
189 base::Unretained(fake_sync_service_observer_list_.get())), | |
190 base::Closure())); | |
191 | |
192 EXPECT_CALL(*mock_sync_service_, GetOpenTabsUIDelegateMock()) | |
193 .WillRepeatedly(Return(manager_.get())); | |
194 | |
139 manager_->MergeDataAndStartSyncing( | 195 manager_->MergeDataAndStartSyncing( |
140 syncer::SESSIONS, syncer::SyncDataList(), | 196 syncer::SESSIONS, syncer::SyncDataList(), |
141 std::unique_ptr<syncer::SyncChangeProcessor>( | 197 std::unique_ptr<syncer::SyncChangeProcessor>( |
142 new syncer::FakeSyncChangeProcessor), | 198 new syncer::FakeSyncChangeProcessor), |
143 std::unique_ptr<syncer::SyncErrorFactory>( | 199 std::unique_ptr<syncer::SyncErrorFactory>( |
144 new syncer::SyncErrorFactoryMock)); | 200 new syncer::SyncErrorFactoryMock)); |
145 } | 201 } |
146 | 202 |
203 void TearDown() override { | |
204 manager_.reset(); | |
205 fake_sync_service_observer_list_.reset(); | |
206 sync_prefs_.reset(); | |
207 local_device_.reset(); | |
208 BrowserWithTestWindowTest::TearDown(); | |
209 } | |
210 | |
147 void WaitForLoadFromLastSession() { | 211 void WaitForLoadFromLastSession() { |
148 content::RunAllBlockingPoolTasksUntilIdle(); | 212 content::RunAllBlockingPoolTasksUntilIdle(); |
149 } | 213 } |
150 | 214 |
151 static std::unique_ptr<KeyedService> GetTabRestoreService( | 215 static std::unique_ptr<KeyedService> GetTabRestoreService( |
152 content::BrowserContext* browser_context) { | 216 content::BrowserContext* browser_context) { |
153 return base::MakeUnique<sessions::PersistentTabRestoreService>( | 217 return base::MakeUnique<sessions::PersistentTabRestoreService>( |
154 base::WrapUnique(new ChromeTabRestoreServiceClient( | 218 base::WrapUnique(new ChromeTabRestoreServiceClient( |
155 Profile::FromBrowserContext(browser_context))), | 219 Profile::FromBrowserContext(browser_context))), |
156 nullptr); | 220 nullptr); |
157 } | 221 } |
158 | 222 |
159 sync_sessions::OpenTabsUIDelegate* GetOpenTabsDelegate() { | 223 sync_sessions::OpenTabsUIDelegate* GetOpenTabsDelegate() { |
160 return manager_.get(); | 224 return manager_.get(); |
161 } | 225 } |
162 | 226 |
163 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) { | 227 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) { |
164 helper->ExportToSessionsSyncManager(manager_.get()); | 228 helper->ExportToSessionsSyncManager(manager_.get()); |
165 } | 229 } |
166 | 230 |
167 private: | 231 private: |
168 TestingProfile testing_profile_; | 232 std::unique_ptr<syncer::LocalDeviceInfoProviderMock> local_device_; |
169 browser_sync::ProfileSyncServiceMock sync_service_; | |
170 std::unique_ptr<syncer::SyncPrefs> sync_prefs_; | 233 std::unique_ptr<syncer::SyncPrefs> sync_prefs_; |
234 std::unique_ptr<FakeSyncServiceObserverList> fake_sync_service_observer_list_; | |
Peter Kasting
2017/03/24 00:06:27
Nit: How come this needs to be stored in a unique_
| |
235 browser_sync::ProfileSyncServiceMock* mock_sync_service_ = nullptr; | |
171 std::unique_ptr<sync_sessions::SessionsSyncManager> manager_; | 236 std::unique_ptr<sync_sessions::SessionsSyncManager> manager_; |
172 std::unique_ptr<syncer::LocalDeviceInfoProviderMock> local_device_; | |
173 }; | 237 }; |
174 | 238 |
175 // Test disabled "Recently closed" header with no foreign tabs. | 239 // Test disabled "Recently closed" header with no foreign tabs. |
176 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { | 240 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { |
177 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 241 TestRecentTabsSubMenuModel model(nullptr, browser()); |
178 | 242 |
179 // Expected menu: | 243 // Expected menu: |
180 // Menu index Menu items | 244 // Menu index Menu items |
181 // --------------------------------------------- | 245 // --------------------------------------------- |
182 // 0 History | 246 // 0 History |
183 // 1 <separator> | 247 // 1 <separator> |
184 // 2 Recently closed header (disabled) | 248 // 2 Recently closed header (disabled) |
185 // 3 <separator> | 249 // 3 <separator> |
186 // 4 No tabs from other Devices | 250 // 4 No tabs from other Devices |
187 | 251 |
(...skipping 21 matching lines...) Expand all Loading... | |
209 // Test enabled "Recently closed" header with no foreign tabs. | 273 // Test enabled "Recently closed" header with no foreign tabs. |
210 TEST_F(RecentTabsSubMenuModelTest, RecentlyClosedTabsFromCurrentSession) { | 274 TEST_F(RecentTabsSubMenuModelTest, RecentlyClosedTabsFromCurrentSession) { |
211 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( | 275 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( |
212 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); | 276 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); |
213 | 277 |
214 // Add 2 tabs and close them. | 278 // Add 2 tabs and close them. |
215 AddTab(browser(), GURL("http://foo/1")); | 279 AddTab(browser(), GURL("http://foo/1")); |
216 AddTab(browser(), GURL("http://foo/2")); | 280 AddTab(browser(), GURL("http://foo/2")); |
217 browser()->tab_strip_model()->CloseAllTabs(); | 281 browser()->tab_strip_model()->CloseAllTabs(); |
218 | 282 |
219 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 283 TestRecentTabsSubMenuModel model(nullptr, browser()); |
220 // Expected menu: | 284 // Expected menu: |
221 // Menu index Menu items | 285 // Menu index Menu items |
222 // -------------------------------------- | 286 // -------------------------------------- |
223 // 0 History | 287 // 0 History |
224 // 1 <separator> | 288 // 1 <separator> |
225 // 2 Recently closed header | 289 // 2 Recently closed header |
226 // 3 <tab for http://foo/2> | 290 // 3 <tab for http://foo/2> |
227 // 4 <tab for http://foo/1> | 291 // 4 <tab for http://foo/1> |
228 // 5 <separator> | 292 // 5 <separator> |
229 // 6 No tabs from other Devices | 293 // 6 No tabs from other Devices |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 SessionServiceFactory::GetForProfile(profile())-> | 367 SessionServiceFactory::GetForProfile(profile())-> |
304 MoveCurrentSessionToLastSession(); | 368 MoveCurrentSessionToLastSession(); |
305 | 369 |
306 // Create a new TabRestoreService so that it'll load the recently closed tabs | 370 // Create a new TabRestoreService so that it'll load the recently closed tabs |
307 // and windows afresh. | 371 // and windows afresh. |
308 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( | 372 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( |
309 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); | 373 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); |
310 // Let the shutdown of previous TabRestoreService run. | 374 // Let the shutdown of previous TabRestoreService run. |
311 content::RunAllBlockingPoolTasksUntilIdle(); | 375 content::RunAllBlockingPoolTasksUntilIdle(); |
312 | 376 |
313 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 377 TestRecentTabsSubMenuModel model(nullptr, browser()); |
314 TestRecentTabsMenuModelDelegate delegate(&model); | 378 TestRecentTabsMenuModelDelegate delegate(&model); |
315 EXPECT_FALSE(delegate.got_changes()); | 379 EXPECT_FALSE(delegate.got_changes()); |
316 | 380 |
317 // Expected menu before tabs/windows from last session are loaded: | 381 // Expected menu before tabs/windows from last session are loaded: |
318 // Menu index Menu items | 382 // Menu index Menu items |
319 // ---------------------------------------------------------------- | 383 // ---------------------------------------------------------------- |
320 // 0 History | 384 // 0 History |
321 // 1 <separator> | 385 // 1 <separator> |
322 // 2 Recently closed header | 386 // 2 Recently closed header |
323 // 3 <separator> | 387 // 3 <separator> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 // 1 <separator> | 492 // 1 <separator> |
429 // 2 Recently closed header (disabled) | 493 // 2 Recently closed header (disabled) |
430 // 3 <separator> | 494 // 3 <separator> |
431 // 4 <section header for 1st session> | 495 // 4 <section header for 1st session> |
432 // 5-7 <3 tabs of the only window of session 0> | 496 // 5-7 <3 tabs of the only window of session 0> |
433 // 8 <separator> | 497 // 8 <separator> |
434 // 9 <section header for 2nd session> | 498 // 9 <section header for 2nd session> |
435 // 10 <the only tab of window 0 of session 1> | 499 // 10 <the only tab of window 0 of session 1> |
436 // 11-12 <2 tabs of window 1 of session 2> | 500 // 11-12 <2 tabs of window 1 of session 2> |
437 | 501 |
438 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 502 TestRecentTabsSubMenuModel model(nullptr, browser()); |
439 int num_items = model.GetItemCount(); | 503 int num_items = model.GetItemCount(); |
440 EXPECT_EQ(13, num_items); | 504 EXPECT_EQ(13, num_items); |
441 model.ActivatedAt(0); | 505 model.ActivatedAt(0); |
442 EXPECT_TRUE(model.IsEnabledAt(0)); | 506 EXPECT_TRUE(model.IsEnabledAt(0)); |
443 model.ActivatedAt(1); | 507 model.ActivatedAt(1); |
444 EXPECT_TRUE(model.IsEnabledAt(1)); | 508 EXPECT_TRUE(model.IsEnabledAt(1)); |
445 model.ActivatedAt(2); | 509 model.ActivatedAt(2); |
446 EXPECT_FALSE(model.IsEnabledAt(2)); | 510 EXPECT_FALSE(model.IsEnabledAt(2)); |
447 model.ActivatedAt(3); | 511 model.ActivatedAt(3); |
448 EXPECT_TRUE(model.IsEnabledAt(3)); | 512 EXPECT_TRUE(model.IsEnabledAt(3)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); | 550 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); |
487 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); | 551 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); |
488 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(7, &url, &title)); | 552 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(7, &url, &title)); |
489 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(8, &url, &title)); | 553 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(8, &url, &title)); |
490 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(9, &url, &title)); | 554 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(9, &url, &title)); |
491 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(10, &url, &title)); | 555 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(10, &url, &title)); |
492 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(11, &url, &title)); | 556 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(11, &url, &title)); |
493 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(12, &url, &title)); | 557 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(12, &url, &title)); |
494 } | 558 } |
495 | 559 |
560 // Mac doesn't support the dynamic menu. | |
561 #if defined(OS_MACOSX) | |
562 #define MAYBE_OtherDevicesDynamicUpdate DISABLED_OtherDevicesDynamicUpdate | |
563 #else | |
564 #define MAYBE_OtherDevicesDynamicUpdate OtherDevicesDynamicUpdate | |
565 #endif | |
566 TEST_F(RecentTabsSubMenuModelTest, OtherDevicesDynamicUpdate) { | |
567 base::Time update_timestamp = | |
568 base::Time::Now() - base::TimeDelta::FromMinutes(10); | |
569 | |
570 RecentTabsBuilderTestHelper recent_tabs_builder; | |
571 | |
572 // Create one session with one window and one tab. | |
573 recent_tabs_builder.AddSession(); | |
574 recent_tabs_builder.AddWindow(0); | |
575 recent_tabs_builder.AddTabWithInfo(0, 0, update_timestamp, base::string16()); | |
576 | |
577 RegisterRecentTabs(&recent_tabs_builder); | |
578 | |
579 // Verify that data is populated correctly in RecentTabsSubMenuModel. | |
580 // Expected menu: | |
581 // - first inserted tab is most recent and hence is top | |
582 // Menu index Menu items | |
583 // ----------------------------------------------------- | |
584 // 0 History | |
585 // 1 <separator> | |
586 // 2 Recently closed header (disabled) | |
587 // 3 <separator> | |
588 // 4 <section header for 1st session> | |
589 // 5 <tab of the only window of session 0> | |
590 | |
591 TestRecentTabsSubMenuModel model(nullptr, browser()); | |
592 int num_items = model.GetItemCount(); | |
Peter Kasting
2017/03/24 00:06:27
Nit: Just inline into the next statement (2 places
| |
593 EXPECT_EQ(6, num_items); | |
594 model.ActivatedAt(0); | |
Peter Kasting
2017/03/24 00:06:27
Again, is there a way to slim down this test to on
| |
595 EXPECT_TRUE(model.IsEnabledAt(0)); | |
596 model.ActivatedAt(1); | |
597 EXPECT_TRUE(model.IsEnabledAt(1)); | |
598 model.ActivatedAt(2); | |
599 EXPECT_FALSE(model.IsEnabledAt(2)); | |
600 model.ActivatedAt(3); | |
601 EXPECT_TRUE(model.IsEnabledAt(3)); | |
602 | |
603 model.ActivatedAt(5); | |
604 EXPECT_TRUE(model.IsEnabledAt(5)); | |
605 | |
606 EXPECT_EQ(2, model.enable_count()); | |
607 EXPECT_EQ(5, model.execute_count()); | |
608 | |
609 EXPECT_EQ(nullptr, model.GetLabelFontListAt(0)); | |
610 EXPECT_EQ(nullptr, model.GetLabelFontListAt(1)); | |
611 EXPECT_EQ(nullptr, model.GetLabelFontListAt(2)); | |
612 EXPECT_EQ(nullptr, model.GetLabelFontListAt(3)); | |
613 EXPECT_NE(nullptr, model.GetLabelFontListAt(4)); | |
614 EXPECT_EQ(nullptr, model.GetLabelFontListAt(5)); | |
615 | |
616 std::string url; | |
617 base::string16 title; | |
618 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); | |
619 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); | |
620 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); | |
621 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); | |
622 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); | |
623 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); | |
624 | |
625 // Make changes dynamically. | |
626 int previous_enable_count = model.enable_count(); | |
627 int previous_execute_count = model.execute_count(); | |
628 | |
629 update_timestamp = base::Time::Now() - base::TimeDelta::FromMinutes(5); | |
630 | |
631 // Add tab to the only window. | |
632 recent_tabs_builder.AddTabWithInfo(0, 0, update_timestamp, base::string16()); | |
633 | |
634 RegisterRecentTabs(&recent_tabs_builder); | |
635 | |
636 // Verify that data is populated correctly in RecentTabsSubMenuModel. | |
637 // Expected menu: | |
638 // - first inserted tab is most recent and hence is top | |
639 // Menu index Menu items | |
640 // ----------------------------------------------------- | |
641 // 0 History | |
642 // 1 <separator> | |
643 // 2 Recently closed header (disabled) | |
644 // 3 <separator> | |
645 // 4 <section header for 1st session> | |
646 // 5 <new added tab of the only window of session 0> | |
647 // 6 <tab of the only window of session 0> | |
648 | |
649 num_items = model.GetItemCount(); | |
650 EXPECT_EQ(7, num_items); | |
651 model.ActivatedAt(0); | |
652 EXPECT_TRUE(model.IsEnabledAt(0)); | |
653 model.ActivatedAt(1); | |
654 EXPECT_TRUE(model.IsEnabledAt(1)); | |
655 model.ActivatedAt(2); | |
656 EXPECT_FALSE(model.IsEnabledAt(2)); | |
657 model.ActivatedAt(3); | |
658 EXPECT_TRUE(model.IsEnabledAt(3)); | |
659 | |
660 model.ActivatedAt(5); | |
661 EXPECT_TRUE(model.IsEnabledAt(5)); | |
662 model.ActivatedAt(6); | |
663 EXPECT_TRUE(model.IsEnabledAt(6)); | |
664 | |
665 EXPECT_EQ(previous_enable_count + 3, model.enable_count()); | |
666 EXPECT_EQ(previous_execute_count + 6, model.execute_count()); | |
667 | |
668 EXPECT_EQ(nullptr, model.GetLabelFontListAt(0)); | |
669 EXPECT_EQ(nullptr, model.GetLabelFontListAt(1)); | |
670 EXPECT_EQ(nullptr, model.GetLabelFontListAt(2)); | |
671 EXPECT_EQ(nullptr, model.GetLabelFontListAt(3)); | |
672 EXPECT_NE(nullptr, model.GetLabelFontListAt(4)); | |
673 EXPECT_EQ(nullptr, model.GetLabelFontListAt(5)); | |
674 EXPECT_EQ(nullptr, model.GetLabelFontListAt(6)); | |
675 | |
676 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title)); | |
677 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title)); | |
678 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title)); | |
679 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); | |
680 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); | |
681 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); | |
682 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); | |
683 } | |
684 | |
496 // Per http://crbug.com/603744, MaxSessionsAndRecenty fails intermittently on | 685 // Per http://crbug.com/603744, MaxSessionsAndRecenty fails intermittently on |
497 // windows, linux and mac. | 686 // windows, linux and mac. |
498 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | 687 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
499 #define MAYBE_MaxSessionsAndRecency DISABLED_MaxSessionsAndRecency | 688 #define MAYBE_MaxSessionsAndRecency DISABLED_MaxSessionsAndRecency |
500 #else | 689 #else |
501 #define MAYBE_MaxSessionsAndRecency MaxSessionsAndRecency | 690 #define MAYBE_MaxSessionsAndRecency MaxSessionsAndRecency |
502 #endif | 691 #endif |
503 TEST_F(RecentTabsSubMenuModelTest, MAYBE_MaxSessionsAndRecency) { | 692 TEST_F(RecentTabsSubMenuModelTest, MAYBE_MaxSessionsAndRecency) { |
504 // Create 4 sessions : each session has 1 window with 1 tab each. | 693 // Create 4 sessions : each session has 1 window with 1 tab each. |
505 RecentTabsBuilderTestHelper recent_tabs_builder; | 694 RecentTabsBuilderTestHelper recent_tabs_builder; |
(...skipping 15 matching lines...) Expand all Loading... | |
521 // 3 <separator> | 710 // 3 <separator> |
522 // 4 <section header for 1st session> | 711 // 4 <section header for 1st session> |
523 // 5 <the only tab of the only window of session 3> | 712 // 5 <the only tab of the only window of session 3> |
524 // 6 <separator> | 713 // 6 <separator> |
525 // 7 <section header for 2nd session> | 714 // 7 <section header for 2nd session> |
526 // 8 <the only tab of the only window of session 2> | 715 // 8 <the only tab of the only window of session 2> |
527 // 9 <separator> | 716 // 9 <separator> |
528 // 10 <section header for 3rd session> | 717 // 10 <section header for 3rd session> |
529 // 11 <the only tab of the only window of session 1> | 718 // 11 <the only tab of the only window of session 1> |
530 | 719 |
531 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 720 TestRecentTabsSubMenuModel model(nullptr, browser()); |
532 int num_items = model.GetItemCount(); | 721 int num_items = model.GetItemCount(); |
533 EXPECT_EQ(12, num_items); | 722 EXPECT_EQ(12, num_items); |
534 | 723 |
535 std::vector<base::string16> tab_titles = | 724 std::vector<base::string16> tab_titles = |
536 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 725 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
537 EXPECT_EQ(tab_titles[0], model.GetLabelAt(5)); | 726 EXPECT_EQ(tab_titles[0], model.GetLabelAt(5)); |
538 EXPECT_EQ(tab_titles[1], model.GetLabelAt(8)); | 727 EXPECT_EQ(tab_titles[1], model.GetLabelAt(8)); |
539 EXPECT_EQ(tab_titles[2], model.GetLabelAt(11)); | 728 EXPECT_EQ(tab_titles[2], model.GetLabelAt(11)); |
540 } | 729 } |
541 | 730 |
(...skipping 14 matching lines...) Expand all Loading... | |
556 // independent of which window they came from. | 745 // independent of which window they came from. |
557 // Menu index Menu items | 746 // Menu index Menu items |
558 // --------------------------------------------- | 747 // --------------------------------------------- |
559 // 0 History | 748 // 0 History |
560 // 1 <separator> | 749 // 1 <separator> |
561 // 2 Recently closed header (disabled) | 750 // 2 Recently closed header (disabled) |
562 // 3 <separator> | 751 // 3 <separator> |
563 // 4 <section header for session> | 752 // 4 <section header for session> |
564 // 5-8 <4 most-recent tabs of session> | 753 // 5-8 <4 most-recent tabs of session> |
565 | 754 |
566 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 755 TestRecentTabsSubMenuModel model(nullptr, browser()); |
567 int num_items = model.GetItemCount(); | 756 int num_items = model.GetItemCount(); |
568 EXPECT_EQ(9, num_items); | 757 EXPECT_EQ(9, num_items); |
569 | 758 |
570 std::vector<base::string16> tab_titles = | 759 std::vector<base::string16> tab_titles = |
571 recent_tabs_builder.GetTabTitlesSortedByRecency(); | 760 recent_tabs_builder.GetTabTitlesSortedByRecency(); |
572 for (int i = 0; i < 4; ++i) | 761 for (int i = 0; i < 4; ++i) |
573 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 5)); | 762 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 5)); |
574 } | 763 } |
575 | 764 |
576 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { | 765 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { |
577 // Create 1 session with 1 window and 1 tab. | 766 // Create 1 session with 1 window and 1 tab. |
578 RecentTabsBuilderTestHelper recent_tabs_builder; | 767 RecentTabsBuilderTestHelper recent_tabs_builder; |
579 recent_tabs_builder.AddSession(); | 768 recent_tabs_builder.AddSession(); |
580 recent_tabs_builder.AddWindow(0); | 769 recent_tabs_builder.AddWindow(0); |
581 recent_tabs_builder.AddTab(0, 0); | 770 recent_tabs_builder.AddTab(0, 0); |
582 RegisterRecentTabs(&recent_tabs_builder); | 771 RegisterRecentTabs(&recent_tabs_builder); |
583 | 772 |
584 // Menu index Menu items | 773 // Menu index Menu items |
585 // ---------------------------------------------------------- | 774 // ---------------------------------------------------------- |
586 // 0 History | 775 // 0 History |
587 // 1 <separator> | 776 // 1 <separator> |
588 // 2 Recently closed header (disabled) | 777 // 2 Recently closed header (disabled) |
589 // 3 <separator> | 778 // 3 <separator> |
590 // 4 <section header for 1st session> | 779 // 4 <section header for 1st session> |
591 // 5 <the only tab of the only window of session 1> | 780 // 5 <the only tab of the only window of session 1> |
592 | 781 |
593 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); | 782 TestRecentTabsSubMenuModel model(nullptr, browser()); |
594 EXPECT_EQ(6, model.GetItemCount()); | 783 EXPECT_EQ(6, model.GetItemCount()); |
595 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 784 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
596 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); | 785 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
597 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(4)); | 786 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(4)); |
598 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(5)); | 787 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(5)); |
599 } | 788 } |
600 | 789 |
601 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { | 790 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { |
602 // Expected menu: | 791 // Expected menu: |
603 // Menu index Menu items | 792 // Menu index Menu items |
604 // -------------------------------------------- | 793 // -------------------------------------------- |
605 // 0 History | 794 // 0 History |
606 // 1 <separator> | 795 // 1 <separator> |
607 // 2 Recently closed heaer (disabled) | 796 // 2 Recently closed heaer (disabled) |
608 // 3 <separator> | 797 // 3 <separator> |
609 // 4 No tabs from other Devices | 798 // 4 No tabs from other Devices |
610 | 799 |
611 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); | 800 TestRecentTabsSubMenuModel model(nullptr, browser()); |
612 EXPECT_EQ(5, model.GetItemCount()); | 801 EXPECT_EQ(5, model.GetItemCount()); |
613 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); | 802 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); |
614 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); | 803 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); |
615 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(4)); | 804 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(4)); |
616 } | 805 } |
OLD | NEW |