OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/arc/arc_util.h" | 5 #include "chrome/browser/chromeos/arc/arc_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/test/scoped_command_line.h" | 12 #include "base/test/scoped_command_line.h" |
| 13 #include "base/values.h" |
13 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow
.h" | 14 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow
.h" |
14 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
16 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/pref_names.h" |
19 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/prefs/pref_service.h" |
20 #include "components/signin/core/account_id/account_id.h" | 23 #include "components/signin/core/account_id/account_id.h" |
| 24 #include "components/sync_preferences/testing_pref_service_syncable.h" |
21 #include "components/user_manager/user_manager.h" | 25 #include "components/user_manager/user_manager.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
24 | 28 |
25 namespace arc { | 29 namespace arc { |
26 namespace util { | 30 namespace util { |
27 | 31 |
28 namespace { | 32 namespace { |
29 | 33 |
30 constexpr char kTestProfileName[] = "user@gmail.com"; | 34 constexpr char kTestProfileName[] = "user@gmail.com"; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 ScopedLogIn login(GetFakeUserManager(), manager_id); | 222 ScopedLogIn login(GetFakeUserManager(), manager_id); |
219 GetFakeUserManager()->SetUserFlow( | 223 GetFakeUserManager()->SetUserFlow( |
220 manager_id, new chromeos::SupervisedUserCreationFlow(manager_id)); | 224 manager_id, new chromeos::SupervisedUserCreationFlow(manager_id)); |
221 EXPECT_FALSE(IsArcAllowedForProfile(profile())); | 225 EXPECT_FALSE(IsArcAllowedForProfile(profile())); |
222 GetFakeUserManager()->ResetUserFlow(manager_id); | 226 GetFakeUserManager()->ResetUserFlow(manager_id); |
223 } | 227 } |
224 | 228 |
225 // TODO(hidehiko): Add test for Ephemeral users. There seems no way to easily | 229 // TODO(hidehiko): Add test for Ephemeral users. There seems no way to easily |
226 // simulate ephemeral user. | 230 // simulate ephemeral user. |
227 | 231 |
| 232 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) { |
| 233 // Ensure IsAllowedForProfile() true. |
| 234 ScopedLogIn login(GetFakeUserManager(), |
| 235 AccountId::FromUserEmailGaiaId( |
| 236 profile()->GetProfileUserName(), kTestGaiaId)); |
| 237 ASSERT_TRUE(IsArcAllowedForProfile(profile())); |
| 238 |
| 239 // By default, Google Play Store is disabled. |
| 240 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 241 |
| 242 // Enable Google Play Store. |
| 243 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 244 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| 245 |
| 246 // Disable Google Play Store. |
| 247 SetArcPlayStoreEnabledForProfile(profile(), false); |
| 248 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 249 } |
| 250 |
| 251 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile_NotAllowed) { |
| 252 ASSERT_FALSE(IsArcAllowedForProfile(profile())); |
| 253 |
| 254 // If ARC is not allowed for the profile, always return false. |
| 255 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 256 |
| 257 // Directly set the preference value, to avoid DCHECK in |
| 258 // SetArcPlayStoreEnabledForProfile(). |
| 259 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 260 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 261 } |
| 262 |
| 263 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile_Managed) { |
| 264 // Ensure IsAllowedForProfile() true. |
| 265 ScopedLogIn login(GetFakeUserManager(), |
| 266 AccountId::FromUserEmailGaiaId( |
| 267 profile()->GetProfileUserName(), kTestGaiaId)); |
| 268 ASSERT_TRUE(IsArcAllowedForProfile(profile())); |
| 269 |
| 270 // By default it is not managed. |
| 271 EXPECT_FALSE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 272 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 273 |
| 274 // 1) Set managed preference to true, then try to set the value to false |
| 275 // via SetArcPlayStoreEnabledForProfile(). |
| 276 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, |
| 277 new base::Value(true)); |
| 278 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 279 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| 280 SetArcPlayStoreEnabledForProfile(profile(), false); |
| 281 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 282 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| 283 |
| 284 // Remove managed state. |
| 285 profile()->GetTestingPrefService()->RemoveManagedPref(prefs::kArcEnabled); |
| 286 EXPECT_FALSE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 287 |
| 288 // 2) Set managed preference to false, then try to set the value to true |
| 289 // via SetArcPlayStoreEnabledForProfile(). |
| 290 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, |
| 291 new base::Value(false)); |
| 292 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 293 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 294 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 295 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 296 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 297 |
| 298 // Remove managed state. |
| 299 profile()->GetTestingPrefService()->RemoveManagedPref(prefs::kArcEnabled); |
| 300 EXPECT_FALSE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 301 } |
| 302 |
228 } // namespace util | 303 } // namespace util |
229 } // namespace arc | 304 } // namespace arc |
OLD | NEW |