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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_unittest.cc

Issue 2391253004: Use mojo Shelf interfaces for both mash and classic ash. (Closed)
Patch Set: Address comments. Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ash/launcher/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 bool IsValidIDForCurrentUser(const std::string& id) const override { 234 bool IsValidIDForCurrentUser(const std::string& id) const override {
235 for (TabToStringMap::const_iterator i = tab_id_map_.begin(); 235 for (TabToStringMap::const_iterator i = tab_id_map_.begin();
236 i != tab_id_map_.end(); ++i) { 236 i != tab_id_map_.end(); ++i) {
237 if (i->second == id) 237 if (i->second == id)
238 return true; 238 return true;
239 } 239 }
240 return false; 240 return false;
241 } 241 }
242 242
243 void SetCurrentUser(Profile* profile) override {
244 // We can ignore this for now.
245 }
246
247 ArcAppListPrefs* GetArcAppListPrefs() const override { return nullptr; } 243 ArcAppListPrefs* GetArcAppListPrefs() const override { return nullptr; }
248 244
249 private: 245 private:
250 typedef std::map<content::WebContents*, std::string> TabToStringMap; 246 typedef std::map<content::WebContents*, std::string> TabToStringMap;
251 247
252 TabToStringMap tab_id_map_; 248 TabToStringMap tab_id_map_;
253 249
254 DISALLOW_COPY_AND_ASSIGN(TestLauncherControllerHelper); 250 DISALLOW_COPY_AND_ASSIGN(TestLauncherControllerHelper);
255 }; 251 };
256 252
(...skipping 29 matching lines...) Expand all
286 new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); 282 new ChromeLauncherAppMenuItem(base::string16(), NULL, false));
287 items.push_back( 283 items.push_back(
288 new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); 284 new ChromeLauncherAppMenuItem(base::string16(), NULL, false));
289 return items; 285 return items;
290 } 286 }
291 ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) override { 287 ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) override {
292 return NULL; 288 return NULL;
293 } 289 }
294 bool IsDraggable() override { return false; } 290 bool IsDraggable() override { return false; }
295 bool CanPin() const override { 291 bool CanPin() const override {
296 return GetPinnableForAppID(app_id(), launcher_controller()->GetProfile()) == 292 return GetPinnableForAppID(app_id(), launcher_controller()->profile()) ==
297 AppListControllerDelegate::PIN_EDITABLE; 293 AppListControllerDelegate::PIN_EDITABLE;
298 } 294 }
299 bool ShouldShowTooltip() override { return false; } 295 bool ShouldShowTooltip() override { return false; }
300 296
301 private: 297 private:
302 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); 298 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController);
303 }; 299 };
304 300
305 } // namespace 301 } // namespace
306 302
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 void AddAppListLauncherItem() { 492 void AddAppListLauncherItem() {
497 ash::ShelfItem app_list; 493 ash::ShelfItem app_list;
498 app_list.type = ash::TYPE_APP_LIST; 494 app_list.type = ash::TYPE_APP_LIST;
499 model_->Add(app_list); 495 model_->Add(app_list);
500 } 496 }
501 497
502 void InitLauncherController() { 498 void InitLauncherController() {
503 AddAppListLauncherItem(); 499 AddAppListLauncherItem();
504 launcher_controller_.reset( 500 launcher_controller_.reset(
505 new ChromeLauncherControllerImpl(profile(), model_.get())); 501 new ChromeLauncherControllerImpl(profile(), model_.get()));
502 // TODO(crbug.com/654622): Some tests break with a non-null static instance.
503 ChromeLauncherControllerImpl::set_instance_for_test(nullptr);
506 launcher_controller_->Init(); 504 launcher_controller_->Init();
507 } 505 }
508 506
509 void InitLauncherControllerWithBrowser() { 507 void InitLauncherControllerWithBrowser() {
510 InitLauncherController(); 508 InitLauncherController();
511 chrome::NewTab(browser()); 509 chrome::NewTab(browser());
512 browser()->window()->Show(); 510 browser()->window()->Show();
513 } 511 }
514 512
515 void RecreateChromeLauncher() { 513 void RecreateChromeLauncher() {
516 // Destroy controller first if it exists. 514 // Destroy controller first if it exists.
517 launcher_controller_.reset(); 515 launcher_controller_.reset();
518 model_.reset(new ash::ShelfModel); 516 model_.reset(new ash::ShelfModel);
519 AddAppListLauncherItem(); 517 AddAppListLauncherItem();
520 launcher_controller_.reset( 518 launcher_controller_ =
521 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); 519 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_.get());
522 launcher_controller_->Init(); 520 launcher_controller_->Init();
523 } 521 }
524 522
525 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) { 523 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) {
526 app_service_->MergeDataAndStartSyncing( 524 app_service_->MergeDataAndStartSyncing(
527 syncer::APP_LIST, init_sync_list, 525 syncer::APP_LIST, init_sync_list,
528 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), 526 base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
529 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 527 base::MakeUnique<syncer::SyncErrorFactoryMock>());
530 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size()); 528 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size());
531 } 529 }
532 530
533 void StopAppSyncService() { app_service_->StopSyncing(syncer::APP_LIST); } 531 void StopAppSyncService() { app_service_->StopSyncing(syncer::APP_LIST); }
534 532
535 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) { 533 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) {
536 std::vector<std::unique_ptr<AppIconLoader>> loaders; 534 std::vector<std::unique_ptr<AppIconLoader>> loaders;
537 loaders.push_back(std::move(loader)); 535 loaders.push_back(std::move(loader));
538 launcher_controller_->SetAppIconLoadersForTest(loaders); 536 launcher_controller_->SetAppIconLoadersForTest(loaders);
539 } 537 }
540 538
541 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1, 539 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1,
542 std::unique_ptr<AppIconLoader> loader2) { 540 std::unique_ptr<AppIconLoader> loader2) {
543 std::vector<std::unique_ptr<AppIconLoader>> loaders; 541 std::vector<std::unique_ptr<AppIconLoader>> loaders;
544 loaders.push_back(std::move(loader1)); 542 loaders.push_back(std::move(loader1));
545 loaders.push_back(std::move(loader2)); 543 loaders.push_back(std::move(loader2));
546 launcher_controller_->SetAppIconLoadersForTest(loaders); 544 launcher_controller_->SetAppIconLoadersForTest(loaders);
547 } 545 }
548 546
549 void SetLauncherControllerHelper(LauncherControllerHelper* helper) { 547 void SetLauncherControllerHelper(LauncherControllerHelper* helper) {
550 launcher_controller_->SetLauncherControllerHelperForTest(helper); 548 launcher_controller_->SetLauncherControllerHelperForTest(
549 base::WrapUnique<LauncherControllerHelper>(helper));
551 } 550 }
552 551
553 void InsertPrefValue(base::ListValue* pref_value, 552 void InsertPrefValue(base::ListValue* pref_value,
554 int index, 553 int index,
555 const std::string& extension_id) { 554 const std::string& extension_id) {
556 auto entry = base::MakeUnique<base::DictionaryValue>(); 555 auto entry = base::MakeUnique<base::DictionaryValue>();
557 entry->SetString(ash::launcher::kPinnedAppsPrefAppIDPath, extension_id); 556 entry->SetString(ash::launcher::kPinnedAppsPrefAppIDPath, extension_id);
558 pref_value->Insert(index, std::move(entry)); 557 pref_value->Insert(index, std::move(entry));
559 } 558 }
560 559
(...skipping 2852 matching lines...) Expand 10 before | Expand all | Expand 10 after
3413 model_->Move(1, 3); 3412 model_->Move(1, 3);
3414 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3413 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
3415 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); 3414 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
3416 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 3415 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
3417 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 3416 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type);
3418 3417
3419 launcher_controller_.reset(); 3418 launcher_controller_.reset();
3420 model_.reset(new ash::ShelfModel); 3419 model_.reset(new ash::ShelfModel);
3421 3420
3422 AddAppListLauncherItem(); 3421 AddAppListLauncherItem();
3423 launcher_controller_.reset( 3422 launcher_controller_ =
3424 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); 3423 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_.get());
3425 helper = new TestLauncherControllerHelper(profile()); 3424 helper = new TestLauncherControllerHelper(profile());
3426 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3425 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3427 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3426 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
3428 SetLauncherControllerHelper(helper); 3427 SetLauncherControllerHelper(helper);
3429 launcher_controller_->Init(); 3428 launcher_controller_->Init();
3430 3429
3431 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl. 3430 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl.
3432 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3431 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
3433 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); 3432 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
3434 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 3433 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
(...skipping 24 matching lines...) Expand all
3459 EXPECT_EQ(1, app_icon_loader->fetch_count()); 3458 EXPECT_EQ(1, app_icon_loader->fetch_count());
3460 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 3459 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
3461 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 3460 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
3462 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 3461 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
3463 EXPECT_EQ(initial_size + 1, model_->items().size()); 3462 EXPECT_EQ(initial_size + 1, model_->items().size());
3464 3463
3465 launcher_controller_.reset(); 3464 launcher_controller_.reset();
3466 model_.reset(new ash::ShelfModel); 3465 model_.reset(new ash::ShelfModel);
3467 3466
3468 AddAppListLauncherItem(); 3467 AddAppListLauncherItem();
3469 launcher_controller_.reset( 3468 launcher_controller_ =
3470 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); 3469 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_.get());
3471 helper = new TestLauncherControllerHelper(profile()); 3470 helper = new TestLauncherControllerHelper(profile());
3472 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3471 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3473 SetLauncherControllerHelper(helper); 3472 SetLauncherControllerHelper(helper);
3474 // app_icon_loader is owned by ChromeLauncherControllerImpl. 3473 // app_icon_loader is owned by ChromeLauncherControllerImpl.
3475 app_icon_loader = new TestAppIconLoaderImpl; 3474 app_icon_loader = new TestAppIconLoaderImpl;
3476 app_icon_loader->AddSupportedApp("1"); 3475 app_icon_loader->AddSupportedApp("1");
3477 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3476 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
3478 launcher_controller_->Init(); 3477 launcher_controller_->Init();
3479 3478
3480 EXPECT_EQ(1, app_icon_loader->fetch_count()); 3479 EXPECT_EQ(1, app_icon_loader->fetch_count());
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
3926 NotifyOnTaskOrientationLockRequested(task_id_current_, 3925 NotifyOnTaskOrientationLockRequested(task_id_current_,
3927 OrientationLock::CURRENT); 3926 OrientationLock::CURRENT);
3928 EXPECT_TRUE(controller->rotation_locked()); 3927 EXPECT_TRUE(controller->rotation_locked());
3929 EXPECT_EQ(display::Display::ROTATE_0, 3928 EXPECT_EQ(display::Display::ROTATE_0,
3930 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3929 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3931 } 3930 }
3932 3931
3933 TEST_F(ChromeLauncherControllerArcDefaultAppsTest, DefaultApps) { 3932 TEST_F(ChromeLauncherControllerArcDefaultAppsTest, DefaultApps) {
3934 arc_test_.SetUp(profile()); 3933 arc_test_.SetUp(profile());
3935 InitLauncherController(); 3934 InitLauncherController();
3936 ChromeLauncherController::set_instance(launcher_controller_.get()); 3935 ChromeLauncherController::set_instance_for_test(launcher_controller_.get());
3937 arc::ArcAuthService::SetShelfDelegateForTesting(launcher_controller_.get()); 3936 arc::ArcAuthService::SetShelfDelegateForTesting(launcher_controller_.get());
3938 3937
3939 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs(); 3938 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs();
3940 EnableArc(false); 3939 EnableArc(false);
3941 EXPECT_FALSE(arc_test_.arc_auth_service()->IsArcEnabled()); 3940 EXPECT_FALSE(arc_test_.arc_auth_service()->IsArcEnabled());
3942 ASSERT_TRUE(prefs->GetAppIds().size()); 3941 ASSERT_TRUE(prefs->GetAppIds().size());
3943 3942
3944 const std::string app_id = 3943 const std::string app_id =
3945 ArcAppTest::GetAppId(arc_test_.fake_default_apps()[0]); 3944 ArcAppTest::GetAppId(arc_test_.fake_default_apps()[0]);
3946 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id)); 3945 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
4009 app_service_->GetPinPosition(extension_misc::kChromeAppId))); 4008 app_service_->GetPinPosition(extension_misc::kChromeAppId)));
4010 EXPECT_TRUE( 4009 EXPECT_TRUE(
4011 position_1.Equals(app_service_->GetPinPosition(extension1_->id()))); 4010 position_1.Equals(app_service_->GetPinPosition(extension1_->id())));
4012 EXPECT_TRUE( 4011 EXPECT_TRUE(
4013 position_1.Equals(app_service_->GetPinPosition(extension1_->id()))); 4012 position_1.Equals(app_service_->GetPinPosition(extension1_->id())));
4014 EXPECT_TRUE( 4013 EXPECT_TRUE(
4015 position_2.Equals(app_service_->GetPinPosition(extension2_->id()))); 4014 position_2.Equals(app_service_->GetPinPosition(extension2_->id())));
4016 EXPECT_TRUE( 4015 EXPECT_TRUE(
4017 position_3.Equals(app_service_->GetPinPosition(extension3_->id()))); 4016 position_3.Equals(app_service_->GetPinPosition(extension3_->id())));
4018 } 4017 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698