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

Side by Side Diff: chrome/browser/chromeos/arc/arc_util_unittest.cc

Issue 2702723002: Extract kArcEnabled preference from ArcSessionManager part 1. (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
OLDNEW
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
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 // Set managed preference to true.
275 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled,
276 new base::Value(true));
277 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile()));
278 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile()));
279
280 // In managed case, SetArcPlayStoreEnabledForProfile() does nothing.
281 SetArcPlayStoreEnabledForProfile(profile(), false);
Yusuke Sato 2017/02/17 22:27:09 nit: can you also test that SetArcPlayStoreEnabled
hidehiko 2017/02/20 18:18:44 Done.
282 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile()));
283 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile()));
284
285 // Remove managed state.
286 profile()->GetTestingPrefService()->RemoveManagedPref(prefs::kArcEnabled);
287 EXPECT_FALSE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile()));
288 }
289
228 } // namespace util 290 } // namespace util
229 } // namespace arc 291 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698