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

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

Issue 2708353007: Remove ArcSessionManager::SetShelfDelegateForTesting. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « chrome/browser/chromeos/arc/arc_session_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 items.push_back( 275 items.push_back(
276 base::MakeUnique<ash::ShelfApplicationMenuItem>(base::string16())); 276 base::MakeUnique<ash::ShelfApplicationMenuItem>(base::string16()));
277 return items; 277 return items;
278 } 278 }
279 void Close() override {} 279 void Close() override {}
280 280
281 private: 281 private:
282 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); 282 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController);
283 }; 283 };
284 284
285 // Proxies to ShelfDelegate invocation to the given
286 // ChromeLauncherControllerImpl instance. Because of ownership management,
287 // ChromeLauncherControllerImpl instance cannot be injected to WmShell.
288 // This wraps the instance, so that it can be injected.
289 class ProxyShelfDelegate : public ash::ShelfDelegate {
290 public:
291 explicit ProxyShelfDelegate(ChromeLauncherControllerImpl* controller)
292 : controller_(controller) {}
293 ~ProxyShelfDelegate() override = default;
294
295 ash::ShelfID GetShelfIDForAppID(const std::string& app_id) override {
296 return controller_->GetShelfIDForAppID(app_id);
297 };
298
299 ash::ShelfID GetShelfIDForAppIDAndLaunchID(
300 const std::string& app_id,
301 const std::string& launch_id) override {
302 return controller_->GetShelfIDForAppIDAndLaunchID(app_id, launch_id);
303 }
304
305 bool HasShelfIDToAppIDMapping(ash::ShelfID id) const override {
306 return controller_->HasShelfIDToAppIDMapping(id);
307 }
308
309 const std::string& GetAppIDForShelfID(ash::ShelfID id) override {
310 return controller_->GetAppIDForShelfID(id);
311 }
312
313 void PinAppWithID(const std::string& app_id) override {
314 return controller_->PinAppWithID(app_id);
315 }
316
317 bool IsAppPinned(const std::string& app_id) override {
318 return controller_->IsAppPinned(app_id);
319 }
320
321 void UnpinAppWithID(const std::string& app_id) override {
322 return controller_->UnpinAppWithID(app_id);
323 }
324
325 private:
326 ChromeLauncherControllerImpl* const controller_;
327
328 DISALLOW_COPY_AND_ASSIGN(ProxyShelfDelegate);
329 };
330
285 } // namespace 331 } // namespace
286 332
287 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { 333 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest {
288 protected: 334 protected:
289 ChromeLauncherControllerImplTest() 335 ChromeLauncherControllerImplTest()
290 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {} 336 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {}
291 337
292 ~ChromeLauncherControllerImplTest() override {} 338 ~ChromeLauncherControllerImplTest() override {}
293 339
294 void SetUp() override { 340 void SetUp() override {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Destroy controller first if it exists. 547 // Destroy controller first if it exists.
502 launcher_controller_.reset(); 548 launcher_controller_.reset();
503 while (model_->item_count() > 0) 549 while (model_->item_count() > 0)
504 model_->RemoveItemAt(0); 550 model_->RemoveItemAt(0);
505 AddAppListLauncherItem(); 551 AddAppListLauncherItem();
506 launcher_controller_ = 552 launcher_controller_ =
507 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_); 553 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_);
508 launcher_controller_->Init(); 554 launcher_controller_->Init();
509 } 555 }
510 556
557 // This needs to be called after InitLaunchController(), or its family.
558 // It is not supported to recreate the instance.
559 void SetShelfDelegate() {
560 ash::WmShell::Get()->SetShelfDelegateForTesting(
561 base::MakeUnique<ProxyShelfDelegate>(launcher_controller_.get()));
562 }
563
511 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) { 564 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) {
512 app_service_->MergeDataAndStartSyncing( 565 app_service_->MergeDataAndStartSyncing(
513 syncer::APP_LIST, init_sync_list, 566 syncer::APP_LIST, init_sync_list,
514 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), 567 base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
515 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 568 base::MakeUnique<syncer::SyncErrorFactoryMock>());
516 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size()); 569 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size());
517 } 570 }
518 571
519 void StopAppSyncService() { app_service_->StopSyncing(syncer::APP_LIST); } 572 void StopAppSyncService() { app_service_->StopSyncing(syncer::APP_LIST); }
520 573
(...skipping 3058 matching lines...) Expand 10 before | Expand all | Expand 10 after
3579 extension_service_->AddExtension(arc_support_host_.get()); 3632 extension_service_->AddExtension(arc_support_host_.get());
3580 // Test enables ARC, so turn it off for initial values. 3633 // Test enables ARC, so turn it off for initial values.
3581 EnableArc(false); 3634 EnableArc(false);
3582 3635
3583 InitLauncherController(); 3636 InitLauncherController();
3584 3637
3585 // To prevent import legacy pins each time. 3638 // To prevent import legacy pins each time.
3586 // Initially pins are imported from legacy pref based model. 3639 // Initially pins are imported from legacy pref based model.
3587 StartPrefSyncService(syncer::SyncDataList()); 3640 StartPrefSyncService(syncer::SyncDataList());
3588 3641
3589 arc::ArcSessionManager::SetShelfDelegateForTesting( 3642 // Inject launcher_controller_ as ShelfDelegate to verify the behavior
Luis Héctor Chávez 2017/02/23 19:23:09 nit: |launch_controller_|, "behavior of removing"
hidehiko 2017/02/24 05:42:11 Done.
3590 launcher_controller_.get()); 3643 // to remove pinned icon in ArcSessionManager::OnOptInPreferenceChanged().
3644 SetShelfDelegate();
3591 3645
3592 // Initial run, ARC is not managed and disabled, Play Store pin should be 3646 // Initial run, ARC is not managed and disabled, Play Store pin should be
3593 // available. 3647 // available.
3594 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED, 3648 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED,
3595 "AppList, Chrome, Play Store"); 3649 "AppList, Chrome, Play Store");
3596 3650
3597 // ARC is managed and enabled, Play Store pin should be available. 3651 // ARC is managed and enabled, Play Store pin should be available.
3598 // Note: SHOWING_TERMS_OF_SERVICE here means that opt-in flow starts. 3652 // Note: SHOWING_TERMS_OF_SERVICE here means that opt-in flow starts.
3599 profile()->GetTestingPrefService()->SetManagedPref( 3653 profile()->GetTestingPrefService()->SetManagedPref(
3600 prefs::kArcEnabled, new base::FundamentalValue(true)); 3654 prefs::kArcEnabled, new base::FundamentalValue(true));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3730 } // namespace 3784 } // namespace
3731 3785
3732 TEST_F(ChromeLauncherControllerOrientationTest, 3786 TEST_F(ChromeLauncherControllerOrientationTest,
3733 ArcOrientationLockBeforeWindowReady) { 3787 ArcOrientationLockBeforeWindowReady) {
3734 ASSERT_TRUE(display::Display::HasInternalDisplay()); 3788 ASSERT_TRUE(display::Display::HasInternalDisplay());
3735 3789
3736 extension_service_->AddExtension(arc_support_host_.get()); 3790 extension_service_->AddExtension(arc_support_host_.get());
3737 EnableArc(true); 3791 EnableArc(true);
3738 3792
3739 InitLauncherController(); 3793 InitLauncherController();
3740 arc::ArcSessionManager::SetShelfDelegateForTesting(
3741 launcher_controller_.get());
3742 3794
3743 ash::ScreenOrientationController* controller = 3795 ash::ScreenOrientationController* controller =
3744 ash::Shell::GetInstance()->screen_orientation_controller(); 3796 ash::Shell::GetInstance()->screen_orientation_controller();
3745 3797
3746 std::string app_id1("org.chromium.arc.1"); 3798 std::string app_id1("org.chromium.arc.1");
3747 int task_id1 = 1; 3799 int task_id1 = 1;
3748 arc::mojom::AppInfo appinfo1 = 3800 arc::mojom::AppInfo appinfo1 =
3749 CreateAppInfo("Test1", "test", "com.example.app", OrientationLock::NONE); 3801 CreateAppInfo("Test1", "test", "com.example.app", OrientationLock::NONE);
3750 3802
3751 AddArcAppAndShortcut(appinfo1); 3803 AddArcAppAndShortcut(appinfo1);
(...skipping 30 matching lines...) Expand all
3782 } 3834 }
3783 3835
3784 TEST_F(ChromeLauncherControllerOrientationTest, ArcOrientationLock) { 3836 TEST_F(ChromeLauncherControllerOrientationTest, ArcOrientationLock) {
3785 ASSERT_TRUE(display::Display::HasInternalDisplay()); 3837 ASSERT_TRUE(display::Display::HasInternalDisplay());
3786 3838
3787 extension_service_->AddExtension(arc_support_host_.get()); 3839 extension_service_->AddExtension(arc_support_host_.get());
3788 EnableArc(true); 3840 EnableArc(true);
3789 EnableTabletMode(true); 3841 EnableTabletMode(true);
3790 3842
3791 InitLauncherController(); 3843 InitLauncherController();
3792 arc::ArcSessionManager::SetShelfDelegateForTesting(
3793 launcher_controller_.get());
3794 3844
3795 InitApps(); 3845 InitApps();
3796 ash::ScreenOrientationController* controller = 3846 ash::ScreenOrientationController* controller =
3797 ash::Shell::GetInstance()->screen_orientation_controller(); 3847 ash::Shell::GetInstance()->screen_orientation_controller();
3798 3848
3799 // Activating a window with NON orientation unlocks the screen. 3849 // Activating a window with NON orientation unlocks the screen.
3800 window_none_->Activate(); 3850 window_none_->Activate();
3801 EXPECT_FALSE(controller->rotation_locked()); 3851 EXPECT_FALSE(controller->rotation_locked());
3802 EXPECT_EQ(display::Display::ROTATE_0, 3852 EXPECT_EQ(display::Display::ROTATE_0,
3803 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3853 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 } 3931 }
3882 3932
3883 TEST_F(ChromeLauncherControllerOrientationTest, CurrentWithLandscapeDisplay) { 3933 TEST_F(ChromeLauncherControllerOrientationTest, CurrentWithLandscapeDisplay) {
3884 ASSERT_TRUE(display::Display::HasInternalDisplay()); 3934 ASSERT_TRUE(display::Display::HasInternalDisplay());
3885 3935
3886 extension_service_->AddExtension(arc_support_host_.get()); 3936 extension_service_->AddExtension(arc_support_host_.get());
3887 EnableArc(true); 3937 EnableArc(true);
3888 EnableTabletMode(true); 3938 EnableTabletMode(true);
3889 3939
3890 InitLauncherController(); 3940 InitLauncherController();
3891 arc::ArcSessionManager::SetShelfDelegateForTesting(
3892 launcher_controller_.get());
3893 3941
3894 InitApps(); 3942 InitApps();
3895 ash::ScreenOrientationController* controller = 3943 ash::ScreenOrientationController* controller =
3896 ash::Shell::GetInstance()->screen_orientation_controller(); 3944 ash::Shell::GetInstance()->screen_orientation_controller();
3897 3945
3898 // Start with portrait. 3946 // Start with portrait.
3899 window_portrait_->Activate(); 3947 window_portrait_->Activate();
3900 3948
3901 // Create a arc window to lock the CURRENT orientation. 3949 // Create a arc window to lock the CURRENT orientation.
3902 views::Widget* window_current = CreateArcWindow(window_app_id_current_); 3950 views::Widget* window_current = CreateArcWindow(window_app_id_current_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3940 OrientationLock::CURRENT); 3988 OrientationLock::CURRENT);
3941 EXPECT_TRUE(controller->rotation_locked()); 3989 EXPECT_TRUE(controller->rotation_locked());
3942 EXPECT_EQ(display::Display::ROTATE_0, 3990 EXPECT_EQ(display::Display::ROTATE_0,
3943 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3991 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3944 } 3992 }
3945 3993
3946 TEST_F(ChromeLauncherControllerArcDefaultAppsTest, DefaultApps) { 3994 TEST_F(ChromeLauncherControllerArcDefaultAppsTest, DefaultApps) {
3947 arc_test_.SetUp(profile()); 3995 arc_test_.SetUp(profile());
3948 InitLauncherController(); 3996 InitLauncherController();
3949 ChromeLauncherController::set_instance_for_test(launcher_controller_.get()); 3997 ChromeLauncherController::set_instance_for_test(launcher_controller_.get());
3950 arc::ArcSessionManager::SetShelfDelegateForTesting(
3951 launcher_controller_.get());
3952 3998
3953 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs(); 3999 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs();
3954 EnableArc(false); 4000 EnableArc(false);
3955 EXPECT_FALSE(arc::IsArcPlayStoreEnabledForProfile(profile())); 4001 EXPECT_FALSE(arc::IsArcPlayStoreEnabledForProfile(profile()));
3956 ASSERT_TRUE(prefs->GetAppIds().size()); 4002 ASSERT_TRUE(prefs->GetAppIds().size());
3957 4003
3958 const std::string app_id = 4004 const std::string app_id =
3959 ArcAppTest::GetAppId(arc_test_.fake_default_apps()[0]); 4005 ArcAppTest::GetAppId(arc_test_.fake_default_apps()[0]);
3960 EXPECT_EQ(ash::kInvalidShelfID, 4006 EXPECT_EQ(ash::kInvalidShelfID,
3961 launcher_controller_->GetShelfIDForAppID(app_id)); 4007 launcher_controller_->GetShelfIDForAppID(app_id));
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
4210 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4256 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4211 shelf_controller->auto_hide()); 4257 shelf_controller->auto_hide());
4212 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4258 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4213 4259
4214 PrefService* prefs = profile()->GetTestingPrefService(); 4260 PrefService* prefs = profile()->GetTestingPrefService();
4215 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); 4261 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal));
4216 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); 4262 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment));
4217 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); 4263 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal));
4218 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); 4264 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior));
4219 } 4265 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_session_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698