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

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

Issue 2782553004: Move TestingPrefService to use unique_ptr<Value> (Closed)
Patch Set: comments Created 3 years, 8 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 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 InsertAddPinChange(&sync_list, 0, extension1_->id()); 1460 InsertAddPinChange(&sync_list, 0, extension1_->id());
1461 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId); 1461 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId);
1462 InsertAddPinChange(&sync_list, 2, extension3_->id()); 1462 InsertAddPinChange(&sync_list, 2, extension3_->id());
1463 SendPinChanges(sync_list, true); 1463 SendPinChanges(sync_list, true);
1464 1464
1465 base::ListValue policy_value; 1465 base::ListValue policy_value;
1466 // extension 2 4 are pinned by policy 1466 // extension 2 4 are pinned by policy
1467 InsertPrefValue(&policy_value, 0, extension2_->id()); 1467 InsertPrefValue(&policy_value, 0, extension2_->id());
1468 InsertPrefValue(&policy_value, 1, extension4_->id()); 1468 InsertPrefValue(&policy_value, 1, extension4_->id());
1469 profile()->GetTestingPrefService()->SetManagedPref( 1469 profile()->GetTestingPrefService()->SetManagedPref(
1470 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 1470 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
1471 1471
1472 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1472 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1473 // 2 is not pinned as it's not installed 1473 // 2 is not pinned as it's not installed
1474 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1474 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1475 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1475 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1476 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 1476 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
1477 // install extension 2 and check 1477 // install extension 2 and check
1478 extension_service_->AddExtension(extension2_.get()); 1478 extension_service_->AddExtension(extension2_.get());
1479 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1479 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1480 1480
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 InitLauncherController(); 2702 InitLauncherController();
2703 2703
2704 syncer::SyncChangeList sync_list; 2704 syncer::SyncChangeList sync_list;
2705 InsertAddPinChange(&sync_list, 0, extension_misc::kChromeAppId); 2705 InsertAddPinChange(&sync_list, 0, extension_misc::kChromeAppId);
2706 SendPinChanges(sync_list, true); 2706 SendPinChanges(sync_list, true);
2707 2707
2708 base::ListValue policy_value; 2708 base::ListValue policy_value;
2709 InsertPrefValue(&policy_value, 0, extension1_->id()); 2709 InsertPrefValue(&policy_value, 0, extension1_->id());
2710 InsertPrefValue(&policy_value, 1, extension2_->id()); 2710 InsertPrefValue(&policy_value, 1, extension2_->id());
2711 profile()->GetTestingPrefService()->SetManagedPref( 2711 profile()->GetTestingPrefService()->SetManagedPref(
2712 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 2712 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
2713 2713
2714 // Only |extension1_| should get pinned. |extension2_| is specified but not 2714 // Only |extension1_| should get pinned. |extension2_| is specified but not
2715 // installed, and |extension3_| is part of the default set, but that shouldn't 2715 // installed, and |extension3_| is part of the default set, but that shouldn't
2716 // take effect when the policy override is in place. 2716 // take effect when the policy override is in place.
2717 ASSERT_EQ(3, model_->item_count()); 2717 ASSERT_EQ(3, model_->item_count());
2718 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 2718 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type);
2719 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2719 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2720 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 2720 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
2721 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2721 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2722 2722
2723 // Installing |extension2_| should add it to the launcher. 2723 // Installing |extension2_| should add it to the launcher.
2724 extension_service_->AddExtension(extension2_.get()); 2724 extension_service_->AddExtension(extension2_.get());
2725 ASSERT_EQ(4, model_->item_count()); 2725 ASSERT_EQ(4, model_->item_count());
2726 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 2726 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type);
2727 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 2727 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type);
2728 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2728 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2729 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2729 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2730 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2730 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2731 2731
2732 // Removing |extension1_| from the policy should not be reflected in the 2732 // Removing |extension1_| from the policy should not be reflected in the
2733 // launcher and pin will exist. 2733 // launcher and pin will exist.
2734 policy_value.Remove(0, NULL); 2734 policy_value.Remove(0, NULL);
2735 profile()->GetTestingPrefService()->SetManagedPref( 2735 profile()->GetTestingPrefService()->SetManagedPref(
2736 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 2736 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
2737 EXPECT_EQ(4, model_->item_count()); 2737 EXPECT_EQ(4, model_->item_count());
2738 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 2738 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type);
2739 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2739 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2740 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2740 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2741 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2741 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2742 } 2742 }
2743 2743
2744 TEST_F(ChromeLauncherControllerImplTest, UnpinWithUninstall) { 2744 TEST_F(ChromeLauncherControllerImplTest, UnpinWithUninstall) {
2745 extension_service_->AddExtension(extension3_.get()); 2745 extension_service_->AddExtension(extension3_.get());
2746 extension_service_->AddExtension(extension4_.get()); 2746 extension_service_->AddExtension(extension4_.get());
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
3704 arc::mojom::AppInfo appinfo = CreateAppInfo( 3704 arc::mojom::AppInfo appinfo = CreateAppInfo(
3705 "Some App", "SomeActivity", "com.example.app", OrientationLock::NONE); 3705 "Some App", "SomeActivity", "com.example.app", OrientationLock::NONE);
3706 const std::string app_id = AddArcAppAndShortcut(appinfo); 3706 const std::string app_id = AddArcAppAndShortcut(appinfo);
3707 3707
3708 // Set policy, that makes pins ARC app. Unlike native extension, for ARC app 3708 // Set policy, that makes pins ARC app. Unlike native extension, for ARC app
3709 // package_name (not hash) specified as id. In this test we check that 3709 // package_name (not hash) specified as id. In this test we check that
3710 // by hash we can determine that appropriate package was set by policy. 3710 // by hash we can determine that appropriate package was set by policy.
3711 base::ListValue policy_value; 3711 base::ListValue policy_value;
3712 InsertPrefValue(&policy_value, 0, appinfo.package_name); 3712 InsertPrefValue(&policy_value, 0, appinfo.package_name);
3713 profile()->GetTestingPrefService()->SetManagedPref( 3713 profile()->GetTestingPrefService()->SetManagedPref(
3714 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 3714 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
3715 3715
3716 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); 3716 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id));
3717 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 3717 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
3718 GetPinnableForAppID(app_id, profile())); 3718 GetPinnableForAppID(app_id, profile()));
3719 } 3719 }
3720 3720
3721 TEST_P(ChromeLauncherControllerImplWithArcTest, ArcManaged) { 3721 TEST_P(ChromeLauncherControllerImplWithArcTest, ArcManaged) {
3722 // TODO(victorhsieh): Implement opt-in and opt-out. 3722 // TODO(victorhsieh): Implement opt-in and opt-out.
3723 if (arc::ShouldArcAlwaysStart()) 3723 if (arc::ShouldArcAlwaysStart())
3724 return; 3724 return;
(...skipping 12 matching lines...) Expand all
3737 // of removing pinned icon in ArcSessionManager::OnOptInPreferenceChanged(). 3737 // of removing pinned icon in ArcSessionManager::OnOptInPreferenceChanged().
3738 SetShelfDelegate(); 3738 SetShelfDelegate();
3739 3739
3740 // Initial run, ARC is not managed and disabled, Play Store pin should be 3740 // Initial run, ARC is not managed and disabled, Play Store pin should be
3741 // available. 3741 // available.
3742 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED, 3742 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED,
3743 "AppList, Chrome, Play Store"); 3743 "AppList, Chrome, Play Store");
3744 3744
3745 // ARC is managed and enabled, Play Store pin should be available. 3745 // ARC is managed and enabled, Play Store pin should be available.
3746 // Note: NEGOTIATING_TERMS_OF_SERVICE here means that opt-in flow starts. 3746 // Note: NEGOTIATING_TERMS_OF_SERVICE here means that opt-in flow starts.
3747 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, 3747 profile()->GetTestingPrefService()->SetManagedPref(
3748 new base::Value(true)); 3748 prefs::kArcEnabled, base::MakeUnique<base::Value>(true));
3749 base::RunLoop().RunUntilIdle(); 3749 base::RunLoop().RunUntilIdle();
3750 ValidateArcState(true, true, 3750 ValidateArcState(true, true,
3751 arc::ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, 3751 arc::ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE,
3752 "AppList, Chrome, Play Store"); 3752 "AppList, Chrome, Play Store");
3753 3753
3754 // ARC is managed and disabled, Play Store pin should not be available. 3754 // ARC is managed and disabled, Play Store pin should not be available.
3755 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, 3755 profile()->GetTestingPrefService()->SetManagedPref(
3756 new base::Value(false)); 3756 prefs::kArcEnabled, base::MakeUnique<base::Value>(false));
3757 base::RunLoop().RunUntilIdle(); 3757 base::RunLoop().RunUntilIdle();
3758 ValidateArcState(false, true, arc::ArcSessionManager::State::STOPPED, 3758 ValidateArcState(false, true, arc::ArcSessionManager::State::STOPPED,
3759 "AppList, Chrome"); 3759 "AppList, Chrome");
3760 3760
3761 // ARC is not managed and disabled, Play Store pin should be available. 3761 // ARC is not managed and disabled, Play Store pin should be available.
3762 profile()->GetTestingPrefService()->RemoveManagedPref(prefs::kArcEnabled); 3762 profile()->GetTestingPrefService()->RemoveManagedPref(prefs::kArcEnabled);
3763 base::RunLoop().RunUntilIdle(); 3763 base::RunLoop().RunUntilIdle();
3764 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED, 3764 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED,
3765 "AppList, Chrome, Play Store"); 3765 "AppList, Chrome, Play Store");
3766 3766
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
4420 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4420 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4421 shelf_controller->auto_hide()); 4421 shelf_controller->auto_hide());
4422 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4422 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4423 4423
4424 PrefService* prefs = profile()->GetTestingPrefService(); 4424 PrefService* prefs = profile()->GetTestingPrefService();
4425 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); 4425 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal));
4426 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); 4426 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment));
4427 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); 4427 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal));
4428 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); 4428 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior));
4429 } 4429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698