Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc

Issue 2768633003: Dynamic updating recent menu for tabs from other devices. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
118 } // namespace 123 } // namespace
119 124
120 class RecentTabsSubMenuModelTest 125 class RecentTabsSubMenuModelTest
121 : public BrowserWithTestWindowTest { 126 : public BrowserWithTestWindowTest {
122 public: 127 public:
123 RecentTabsSubMenuModelTest() 128 RecentTabsSubMenuModelTest() {}
124 : sync_service_(CreateProfileSyncServiceParamsForTest(&testing_profile_)), 129
125 local_device_(new syncer::LocalDeviceInfoProviderMock( 130 void SetUp() override {
126 "RecentTabsSubMenuModelTest", 131 BrowserWithTestWindowTest::SetUp();
127 "Test Machine", 132
128 "Chromium 10k", 133 local_device_ = base::MakeUnique<syncer::LocalDeviceInfoProviderMock>(
Peter Kasting 2017/03/23 04:48:34 This seems very heavyweight. It would be nice to
129 "Chrome 10k", 134 "RecentTabsSubMenuModelTest", "Test Machine", "Chromium 10k",
130 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, 135 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id");
131 "device_id")) { 136
132 sync_prefs_.reset(new syncer::SyncPrefs(testing_profile_.GetPrefs())); 137 sync_prefs_.reset(new syncer::SyncPrefs(profile()->GetPrefs()));
138
139 mock_sync_service_ = static_cast<browser_sync::ProfileSyncServiceMock*>(
140 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
141 profile(), BuildMockProfileSyncService));
142
143 EXPECT_CALL(*mock_sync_service_, AddObserver(_))
144 .WillRepeatedly(Invoke(this, &RecentTabsSubMenuModelTest::AddObserver));
145 EXPECT_CALL(*mock_sync_service_, RemoveObserver(_))
146 .WillRepeatedly(
147 Invoke(this, &RecentTabsSubMenuModelTest::RemoveObserver));
148 EXPECT_CALL(*mock_sync_service_, IsSyncActive())
149 .WillRepeatedly(Return(true));
150 EXPECT_CALL(*mock_sync_service_,
151 IsDataTypeControllerRunning(syncer::SESSIONS))
152 .WillRepeatedly(Return(true));
153 EXPECT_CALL(*mock_sync_service_,
154 IsDataTypeControllerRunning(syncer::PROXY_TABS))
155 .WillRepeatedly(Return(true));
156
133 manager_.reset(new sync_sessions::SessionsSyncManager( 157 manager_.reset(new sync_sessions::SessionsSyncManager(
134 sync_service_.GetSyncClient()->GetSyncSessionsClient(), 158 mock_sync_service_->GetSyncClient()->GetSyncSessionsClient(),
135 sync_prefs_.get(), local_device_.get(), 159 sync_prefs_.get(), local_device_.get(),
136 std::unique_ptr<sync_sessions::LocalSessionEventRouter>( 160 std::unique_ptr<sync_sessions::LocalSessionEventRouter>(
137 new DummyRouter()), 161 new DummyRouter()),
138 base::Closure(), base::Closure())); 162 base::Bind(
163 &browser_sync::ProfileSyncService::NotifyForeignSessionUpdated,
164 base::Unretained(mock_sync_service_)),
165 base::Closure()));
166
167 EXPECT_CALL(*mock_sync_service_, GetOpenTabsUIDelegateMock())
168 .WillRepeatedly(Return(manager_.get()));
169
139 manager_->MergeDataAndStartSyncing( 170 manager_->MergeDataAndStartSyncing(
140 syncer::SESSIONS, syncer::SyncDataList(), 171 syncer::SESSIONS, syncer::SyncDataList(),
141 std::unique_ptr<syncer::SyncChangeProcessor>( 172 std::unique_ptr<syncer::SyncChangeProcessor>(
142 new syncer::FakeSyncChangeProcessor), 173 new syncer::FakeSyncChangeProcessor),
143 std::unique_ptr<syncer::SyncErrorFactory>( 174 std::unique_ptr<syncer::SyncErrorFactory>(
144 new syncer::SyncErrorFactoryMock)); 175 new syncer::SyncErrorFactoryMock));
145 } 176 }
146 177
178 void TearDown() override {
179 manager_.reset();
180 sync_prefs_.reset();
181 local_device_.reset();
182 BrowserWithTestWindowTest::TearDown();
183 }
184
185 void AddObserver(syncer::SyncServiceObserver* observer) {
186 mock_sync_service_->SyncServiceBase::AddObserver(observer);
187 }
188
189 void RemoveObserver(syncer::SyncServiceObserver* observer) {
190 mock_sync_service_->SyncServiceBase::RemoveObserver(observer);
191 }
192
147 void WaitForLoadFromLastSession() { 193 void WaitForLoadFromLastSession() {
148 content::RunAllBlockingPoolTasksUntilIdle(); 194 content::RunAllBlockingPoolTasksUntilIdle();
149 } 195 }
150 196
151 static std::unique_ptr<KeyedService> GetTabRestoreService( 197 static std::unique_ptr<KeyedService> GetTabRestoreService(
152 content::BrowserContext* browser_context) { 198 content::BrowserContext* browser_context) {
153 return base::MakeUnique<sessions::PersistentTabRestoreService>( 199 return base::MakeUnique<sessions::PersistentTabRestoreService>(
154 base::WrapUnique(new ChromeTabRestoreServiceClient( 200 base::WrapUnique(new ChromeTabRestoreServiceClient(
155 Profile::FromBrowserContext(browser_context))), 201 Profile::FromBrowserContext(browser_context))),
156 nullptr); 202 nullptr);
157 } 203 }
158 204
159 sync_sessions::OpenTabsUIDelegate* GetOpenTabsDelegate() { 205 sync_sessions::OpenTabsUIDelegate* GetOpenTabsDelegate() {
160 return manager_.get(); 206 return manager_.get();
161 } 207 }
162 208
163 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) { 209 void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) {
164 helper->ExportToSessionsSyncManager(manager_.get()); 210 helper->ExportToSessionsSyncManager(manager_.get());
165 } 211 }
166 212
167 private: 213 private:
168 TestingProfile testing_profile_; 214 std::unique_ptr<syncer::LocalDeviceInfoProviderMock> local_device_;
169 browser_sync::ProfileSyncServiceMock sync_service_;
170 std::unique_ptr<syncer::SyncPrefs> sync_prefs_; 215 std::unique_ptr<syncer::SyncPrefs> sync_prefs_;
216 browser_sync::ProfileSyncServiceMock* mock_sync_service_ = nullptr;
171 std::unique_ptr<sync_sessions::SessionsSyncManager> manager_; 217 std::unique_ptr<sync_sessions::SessionsSyncManager> manager_;
172 std::unique_ptr<syncer::LocalDeviceInfoProviderMock> local_device_;
173 }; 218 };
174 219
175 // Test disabled "Recently closed" header with no foreign tabs. 220 // Test disabled "Recently closed" header with no foreign tabs.
176 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { 221 TEST_F(RecentTabsSubMenuModelTest, NoTabs) {
177 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); 222 TestRecentTabsSubMenuModel model(nullptr, browser());
178 223
179 // Expected menu: 224 // Expected menu:
180 // Menu index Menu items 225 // Menu index Menu items
181 // --------------------------------------------- 226 // ---------------------------------------------
182 // 0 History 227 // 0 History
183 // 1 <separator> 228 // 1 <separator>
184 // 2 Recently closed header (disabled) 229 // 2 Recently closed header (disabled)
185 // 3 <separator> 230 // 3 <separator>
186 // 4 No tabs from other Devices 231 // 4 No tabs from other Devices
187 232
(...skipping 21 matching lines...) Expand all
209 // Test enabled "Recently closed" header with no foreign tabs. 254 // Test enabled "Recently closed" header with no foreign tabs.
210 TEST_F(RecentTabsSubMenuModelTest, RecentlyClosedTabsFromCurrentSession) { 255 TEST_F(RecentTabsSubMenuModelTest, RecentlyClosedTabsFromCurrentSession) {
211 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( 256 TabRestoreServiceFactory::GetInstance()->SetTestingFactory(
212 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); 257 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService);
213 258
214 // Add 2 tabs and close them. 259 // Add 2 tabs and close them.
215 AddTab(browser(), GURL("http://foo/1")); 260 AddTab(browser(), GURL("http://foo/1"));
216 AddTab(browser(), GURL("http://foo/2")); 261 AddTab(browser(), GURL("http://foo/2"));
217 browser()->tab_strip_model()->CloseAllTabs(); 262 browser()->tab_strip_model()->CloseAllTabs();
218 263
219 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); 264 TestRecentTabsSubMenuModel model(nullptr, browser());
220 // Expected menu: 265 // Expected menu:
221 // Menu index Menu items 266 // Menu index Menu items
222 // -------------------------------------- 267 // --------------------------------------
223 // 0 History 268 // 0 History
224 // 1 <separator> 269 // 1 <separator>
225 // 2 Recently closed header 270 // 2 Recently closed header
226 // 3 <tab for http://foo/2> 271 // 3 <tab for http://foo/2>
227 // 4 <tab for http://foo/1> 272 // 4 <tab for http://foo/1>
228 // 5 <separator> 273 // 5 <separator>
229 // 6 No tabs from other Devices 274 // 6 No tabs from other Devices
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 SessionServiceFactory::GetForProfile(profile())-> 348 SessionServiceFactory::GetForProfile(profile())->
304 MoveCurrentSessionToLastSession(); 349 MoveCurrentSessionToLastSession();
305 350
306 // Create a new TabRestoreService so that it'll load the recently closed tabs 351 // Create a new TabRestoreService so that it'll load the recently closed tabs
307 // and windows afresh. 352 // and windows afresh.
308 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( 353 TabRestoreServiceFactory::GetInstance()->SetTestingFactory(
309 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); 354 profile(), RecentTabsSubMenuModelTest::GetTabRestoreService);
310 // Let the shutdown of previous TabRestoreService run. 355 // Let the shutdown of previous TabRestoreService run.
311 content::RunAllBlockingPoolTasksUntilIdle(); 356 content::RunAllBlockingPoolTasksUntilIdle();
312 357
313 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); 358 TestRecentTabsSubMenuModel model(nullptr, browser());
314 TestRecentTabsMenuModelDelegate delegate(&model); 359 TestRecentTabsMenuModelDelegate delegate(&model);
315 EXPECT_FALSE(delegate.got_changes()); 360 EXPECT_FALSE(delegate.got_changes());
316 361
317 // Expected menu before tabs/windows from last session are loaded: 362 // Expected menu before tabs/windows from last session are loaded:
318 // Menu index Menu items 363 // Menu index Menu items
319 // ---------------------------------------------------------------- 364 // ----------------------------------------------------------------
320 // 0 History 365 // 0 History
321 // 1 <separator> 366 // 1 <separator>
322 // 2 Recently closed header 367 // 2 Recently closed header
323 // 3 <separator> 368 // 3 <separator>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // 1 <separator> 473 // 1 <separator>
429 // 2 Recently closed header (disabled) 474 // 2 Recently closed header (disabled)
430 // 3 <separator> 475 // 3 <separator>
431 // 4 <section header for 1st session> 476 // 4 <section header for 1st session>
432 // 5-7 <3 tabs of the only window of session 0> 477 // 5-7 <3 tabs of the only window of session 0>
433 // 8 <separator> 478 // 8 <separator>
434 // 9 <section header for 2nd session> 479 // 9 <section header for 2nd session>
435 // 10 <the only tab of window 0 of session 1> 480 // 10 <the only tab of window 0 of session 1>
436 // 11-12 <2 tabs of window 1 of session 2> 481 // 11-12 <2 tabs of window 1 of session 2>
437 482
438 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); 483 TestRecentTabsSubMenuModel model(nullptr, browser());
439 int num_items = model.GetItemCount(); 484 int num_items = model.GetItemCount();
440 EXPECT_EQ(13, num_items); 485 EXPECT_EQ(13, num_items);
441 model.ActivatedAt(0); 486 model.ActivatedAt(0);
442 EXPECT_TRUE(model.IsEnabledAt(0)); 487 EXPECT_TRUE(model.IsEnabledAt(0));
443 model.ActivatedAt(1); 488 model.ActivatedAt(1);
444 EXPECT_TRUE(model.IsEnabledAt(1)); 489 EXPECT_TRUE(model.IsEnabledAt(1));
445 model.ActivatedAt(2); 490 model.ActivatedAt(2);
446 EXPECT_FALSE(model.IsEnabledAt(2)); 491 EXPECT_FALSE(model.IsEnabledAt(2));
447 model.ActivatedAt(3); 492 model.ActivatedAt(3);
448 EXPECT_TRUE(model.IsEnabledAt(3)); 493 EXPECT_TRUE(model.IsEnabledAt(3));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title)); 529 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title));
485 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title)); 530 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title));
486 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title)); 531 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title));
487 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(6, &url, &title)); 532 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(6, &url, &title));
488 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(7, &url, &title)); 533 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(7, &url, &title));
489 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(8, &url, &title)); 534 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(8, &url, &title));
490 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(9, &url, &title)); 535 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(9, &url, &title));
491 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(10, &url, &title)); 536 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(10, &url, &title));
492 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(11, &url, &title)); 537 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(11, &url, &title));
493 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(12, &url, &title)); 538 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(12, &url, &title));
539
Peter Kasting 2017/03/23 04:48:35 Nit: Prefer to pull this out into its own test, ev
540 // Remove this when dynamic model is enabled in RecentTabsSubMenuModel.
Peter Kasting 2017/03/23 04:48:34 Nit: This comment sounds like "remove this block",
541 #if !defined(OS_MACOSX)
542 // Make changes dynamically
543 int previous_enable_count = model.enable_count();
544 int previous_execute_count = model.execute_count();
545
546 base::Time update_timestamp =
547 base::Time::Now() - base::TimeDelta::FromMinutes(5);
548
549 // Add tab to the only window in the first session and add tab to the seсond
550 // window in the second session.
551 recent_tabs_builder.AddTabWithInfo(0, 0, update_timestamp, base::string16());
552 recent_tabs_builder.AddTabWithInfo(1, 1, update_timestamp, base::string16());
553
554 RegisterRecentTabs(&recent_tabs_builder);
555
556 // Verify that data is populated correctly in RecentTabsSubMenuModel.
557 // Expected menu:
558 // - first inserted tab is most recent and hence is top
559 // Menu index Menu items
560 // -----------------------------------------------------
561 // 0 History
562 // 1 <separator>
563 // 2 Recently closed header (disabled)
564 // 3 <separator>
565 // 4 <section header for 1st session>
566 // 5 <new added tab of the only window of session 0>
567 // 6-8 <3 tabs of the only window of session 0>
568 // 9 <separator>
569 // 10 <section header for 2nd session>
570 // 11 <new added tab of window 1 of session 2>
571 // 12 <the only tab of window 0 of session 1>
572 // 13-14 <2 tabs of window 1 of session 2>
573
574 num_items = model.GetItemCount();
Peter Kasting 2017/03/23 04:48:34 Do we really need to check everything below in ord
575 EXPECT_EQ(15, num_items);
576 model.ActivatedAt(0);
577 EXPECT_TRUE(model.IsEnabledAt(0));
578 model.ActivatedAt(1);
579 EXPECT_TRUE(model.IsEnabledAt(1));
580 model.ActivatedAt(2);
581 EXPECT_FALSE(model.IsEnabledAt(2));
582 model.ActivatedAt(3);
583 EXPECT_TRUE(model.IsEnabledAt(3));
584
585 model.ActivatedAt(5);
586 EXPECT_TRUE(model.IsEnabledAt(5));
587 model.ActivatedAt(6);
588 EXPECT_TRUE(model.IsEnabledAt(6));
589 model.ActivatedAt(7);
590 EXPECT_TRUE(model.IsEnabledAt(7));
591 model.ActivatedAt(8);
592 EXPECT_TRUE(model.IsEnabledAt(8));
593
594 model.ActivatedAt(11);
595 EXPECT_TRUE(model.IsEnabledAt(11));
596 model.ActivatedAt(12);
597 EXPECT_TRUE(model.IsEnabledAt(12));
598 model.ActivatedAt(13);
599 EXPECT_TRUE(model.IsEnabledAt(13));
600 model.ActivatedAt(14);
601 EXPECT_TRUE(model.IsEnabledAt(14));
602
603 EXPECT_EQ(previous_enable_count + 9, model.enable_count());
604 EXPECT_EQ(previous_execute_count + 12, model.execute_count());
605
606 EXPECT_EQ(nullptr, model.GetLabelFontListAt(0));
607 EXPECT_EQ(nullptr, model.GetLabelFontListAt(1));
608 EXPECT_EQ(nullptr, model.GetLabelFontListAt(2));
609 EXPECT_EQ(nullptr, model.GetLabelFontListAt(3));
610 EXPECT_TRUE(model.GetLabelFontListAt(4) != nullptr);
Peter Kasting 2017/03/23 04:48:35 Nit: Can probably be EXPECT_NE(nullptr, ...); (2 p
611 EXPECT_EQ(nullptr, model.GetLabelFontListAt(5));
612 EXPECT_EQ(nullptr, model.GetLabelFontListAt(6));
613 EXPECT_EQ(nullptr, model.GetLabelFontListAt(7));
614 EXPECT_EQ(nullptr, model.GetLabelFontListAt(8));
615 EXPECT_EQ(nullptr, model.GetLabelFontListAt(9));
616 EXPECT_TRUE(model.GetLabelFontListAt(10) != nullptr);
617 EXPECT_EQ(nullptr, model.GetLabelFontListAt(11));
618 EXPECT_EQ(nullptr, model.GetLabelFontListAt(12));
619 EXPECT_EQ(nullptr, model.GetLabelFontListAt(13));
620 EXPECT_EQ(nullptr, model.GetLabelFontListAt(14));
621
622 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(0, &url, &title));
623 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(1, &url, &title));
624 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(2, &url, &title));
625 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(3, &url, &title));
626 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(4, &url, &title));
627 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(5, &url, &title));
628 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(6, &url, &title));
629 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(7, &url, &title));
630 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(8, &url, &title));
631 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(9, &url, &title));
632 EXPECT_FALSE(model.GetURLAndTitleForItemAtIndex(10, &url, &title));
633 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(11, &url, &title));
634 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(12, &url, &title));
635 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(13, &url, &title));
636 EXPECT_TRUE(model.GetURLAndTitleForItemAtIndex(14, &url, &title));
637 #endif // !defined(OS_MACOSX)
494 } 638 }
495 639
496 // Per http://crbug.com/603744, MaxSessionsAndRecenty fails intermittently on 640 // Per http://crbug.com/603744, MaxSessionsAndRecenty fails intermittently on
497 // windows, linux and mac. 641 // windows, linux and mac.
498 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) 642 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
499 #define MAYBE_MaxSessionsAndRecency DISABLED_MaxSessionsAndRecency 643 #define MAYBE_MaxSessionsAndRecency DISABLED_MaxSessionsAndRecency
500 #else 644 #else
501 #define MAYBE_MaxSessionsAndRecency MaxSessionsAndRecency 645 #define MAYBE_MaxSessionsAndRecency MaxSessionsAndRecency
502 #endif 646 #endif
503 TEST_F(RecentTabsSubMenuModelTest, MAYBE_MaxSessionsAndRecency) { 647 TEST_F(RecentTabsSubMenuModelTest, MAYBE_MaxSessionsAndRecency) {
(...skipping 17 matching lines...) Expand all
521 // 3 <separator> 665 // 3 <separator>
522 // 4 <section header for 1st session> 666 // 4 <section header for 1st session>
523 // 5 <the only tab of the only window of session 3> 667 // 5 <the only tab of the only window of session 3>
524 // 6 <separator> 668 // 6 <separator>
525 // 7 <section header for 2nd session> 669 // 7 <section header for 2nd session>
526 // 8 <the only tab of the only window of session 2> 670 // 8 <the only tab of the only window of session 2>
527 // 9 <separator> 671 // 9 <separator>
528 // 10 <section header for 3rd session> 672 // 10 <section header for 3rd session>
529 // 11 <the only tab of the only window of session 1> 673 // 11 <the only tab of the only window of session 1>
530 674
531 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); 675 TestRecentTabsSubMenuModel model(nullptr, browser());
532 int num_items = model.GetItemCount(); 676 int num_items = model.GetItemCount();
533 EXPECT_EQ(12, num_items); 677 EXPECT_EQ(12, num_items);
534 678
535 std::vector<base::string16> tab_titles = 679 std::vector<base::string16> tab_titles =
536 recent_tabs_builder.GetTabTitlesSortedByRecency(); 680 recent_tabs_builder.GetTabTitlesSortedByRecency();
537 EXPECT_EQ(tab_titles[0], model.GetLabelAt(5)); 681 EXPECT_EQ(tab_titles[0], model.GetLabelAt(5));
538 EXPECT_EQ(tab_titles[1], model.GetLabelAt(8)); 682 EXPECT_EQ(tab_titles[1], model.GetLabelAt(8));
539 EXPECT_EQ(tab_titles[2], model.GetLabelAt(11)); 683 EXPECT_EQ(tab_titles[2], model.GetLabelAt(11));
540 } 684 }
541 685
(...skipping 14 matching lines...) Expand all
556 // independent of which window they came from. 700 // independent of which window they came from.
557 // Menu index Menu items 701 // Menu index Menu items
558 // --------------------------------------------- 702 // ---------------------------------------------
559 // 0 History 703 // 0 History
560 // 1 <separator> 704 // 1 <separator>
561 // 2 Recently closed header (disabled) 705 // 2 Recently closed header (disabled)
562 // 3 <separator> 706 // 3 <separator>
563 // 4 <section header for session> 707 // 4 <section header for session>
564 // 5-8 <4 most-recent tabs of session> 708 // 5-8 <4 most-recent tabs of session>
565 709
566 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); 710 TestRecentTabsSubMenuModel model(nullptr, browser());
567 int num_items = model.GetItemCount(); 711 int num_items = model.GetItemCount();
568 EXPECT_EQ(9, num_items); 712 EXPECT_EQ(9, num_items);
569 713
570 std::vector<base::string16> tab_titles = 714 std::vector<base::string16> tab_titles =
571 recent_tabs_builder.GetTabTitlesSortedByRecency(); 715 recent_tabs_builder.GetTabTitlesSortedByRecency();
572 for (int i = 0; i < 4; ++i) 716 for (int i = 0; i < 4; ++i)
573 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 5)); 717 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 5));
574 } 718 }
575 719
576 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { 720 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) {
577 // Create 1 session with 1 window and 1 tab. 721 // Create 1 session with 1 window and 1 tab.
578 RecentTabsBuilderTestHelper recent_tabs_builder; 722 RecentTabsBuilderTestHelper recent_tabs_builder;
579 recent_tabs_builder.AddSession(); 723 recent_tabs_builder.AddSession();
580 recent_tabs_builder.AddWindow(0); 724 recent_tabs_builder.AddWindow(0);
581 recent_tabs_builder.AddTab(0, 0); 725 recent_tabs_builder.AddTab(0, 0);
582 RegisterRecentTabs(&recent_tabs_builder); 726 RegisterRecentTabs(&recent_tabs_builder);
583 727
584 // Menu index Menu items 728 // Menu index Menu items
585 // ---------------------------------------------------------- 729 // ----------------------------------------------------------
586 // 0 History 730 // 0 History
587 // 1 <separator> 731 // 1 <separator>
588 // 2 Recently closed header (disabled) 732 // 2 Recently closed header (disabled)
589 // 3 <separator> 733 // 3 <separator>
590 // 4 <section header for 1st session> 734 // 4 <section header for 1st session>
591 // 5 <the only tab of the only window of session 1> 735 // 5 <the only tab of the only window of session 1>
592 736
593 TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate()); 737 TestRecentTabsSubMenuModel model(nullptr, browser());
594 EXPECT_EQ(6, model.GetItemCount()); 738 EXPECT_EQ(6, model.GetItemCount());
595 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); 739 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2));
596 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); 740 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3));
597 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(4)); 741 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(4));
598 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(5)); 742 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(5));
599 } 743 }
600 744
601 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { 745 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) {
602 // Expected menu: 746 // Expected menu:
603 // Menu index Menu items 747 // Menu index Menu items
604 // -------------------------------------------- 748 // --------------------------------------------
605 // 0 History 749 // 0 History
606 // 1 <separator> 750 // 1 <separator>
607 // 2 Recently closed heaer (disabled) 751 // 2 Recently closed heaer (disabled)
608 // 3 <separator> 752 // 3 <separator>
609 // 4 No tabs from other Devices 753 // 4 No tabs from other Devices
610 754
611 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); 755 TestRecentTabsSubMenuModel model(nullptr, browser());
612 EXPECT_EQ(5, model.GetItemCount()); 756 EXPECT_EQ(5, model.GetItemCount());
613 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); 757 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2));
614 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); 758 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3));
615 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(4)); 759 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(4));
616 } 760 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698