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

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

Issue 2808353008: arc: kArcCompatibleFilesystemChosen pref to local state and integer. (Closed)
Patch Set: Update reflecting review 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 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/sys_info.h" 12 #include "base/sys_info.h"
13 #include "base/test/scoped_command_line.h" 13 #include "base/test/scoped_command_line.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
15 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow .h" 16 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow .h"
16 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 17 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
18 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" 20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
25 #include "components/prefs/testing_pref_service.h"
24 #include "components/signin/core/account_id/account_id.h" 26 #include "components/signin/core/account_id/account_id.h"
25 #include "components/sync_preferences/testing_pref_service_syncable.h" 27 #include "components/sync_preferences/testing_pref_service_syncable.h"
28 #include "components/user_manager/known_user.h"
26 #include "components/user_manager/user_manager.h" 29 #include "components/user_manager/user_manager.h"
27 #include "components/user_manager/user_names.h" 30 #include "components/user_manager/user_names.h"
28 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
30 33
31 namespace arc { 34 namespace arc {
32 namespace util { 35 namespace util {
33 36
34 namespace { 37 namespace {
35 38
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 81 }
79 82
80 void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); } 83 void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); }
81 84
82 chromeos::FakeChromeUserManager* fake_user_manager_; 85 chromeos::FakeChromeUserManager* fake_user_manager_;
83 const AccountId account_id_; 86 const AccountId account_id_;
84 87
85 DISALLOW_COPY_AND_ASSIGN(ScopedLogIn); 88 DISALLOW_COPY_AND_ASSIGN(ScopedLogIn);
86 }; 89 };
87 90
91 class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager {
92 public:
93 FakeUserManagerWithLocalState()
94 : test_local_state_(base::MakeUnique<TestingPrefServiceSimple>()) {
95 RegisterPrefs(test_local_state_->registry());
96 }
97
98 PrefService* GetLocalState() const override {
99 return test_local_state_.get();
100 }
101
102 private:
103 std::unique_ptr<TestingPrefServiceSimple> test_local_state_;
104 };
xiyuan 2017/04/14 06:51:31 nit: DISALLOW_COPY_AND_ASSIGN(...)
kinaba 2017/04/14 06:57:13 Done.
105
88 } // namespace 106 } // namespace
89 107
90 class ChromeArcUtilTest : public testing::Test { 108 class ChromeArcUtilTest : public testing::Test {
91 public: 109 public:
92 ChromeArcUtilTest() = default; 110 ChromeArcUtilTest() = default;
93 ~ChromeArcUtilTest() override = default; 111 ~ChromeArcUtilTest() override = default;
94 112
95 void SetUp() override { 113 void SetUp() override {
96 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); 114 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>();
97 command_line_->GetProcessCommandLine()->InitFromArgv({"", "--enable-arc"}); 115 command_line_->GetProcessCommandLine()->InitFromArgv({"", "--enable-arc"});
98 116
99 user_manager_enabler_ = 117 user_manager_enabler_ =
100 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( 118 base::MakeUnique<chromeos::ScopedUserManagerEnabler>(
101 new chromeos::FakeChromeUserManager()); 119 new FakeUserManagerWithLocalState());
102 chromeos::WallpaperManager::Initialize(); 120 chromeos::WallpaperManager::Initialize();
103 profile_ = base::MakeUnique<TestingProfile>(); 121 profile_ = base::MakeUnique<TestingProfile>();
104 profile_->set_profile_name(kTestProfileName); 122 profile_->set_profile_name(kTestProfileName);
105 } 123 }
106 124
107 void TearDown() override { 125 void TearDown() override {
108 profile_.reset(); 126 profile_.reset();
109 chromeos::WallpaperManager::Shutdown(); 127 chromeos::WallpaperManager::Shutdown();
110 user_manager_enabler_.reset(); 128 user_manager_enabler_.reset();
111 command_line_.reset(); 129 command_line_.reset();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DemoAccount) { 289 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DemoAccount) {
272 ScopedLogIn login(GetFakeUserManager(), user_manager::DemoAccountId()); 290 ScopedLogIn login(GetFakeUserManager(), user_manager::DemoAccountId());
273 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 291 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
274 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile())); 292 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
275 } 293 }
276 294
277 TEST_F(ChromeArcUtilTest, IsArcCompatibleFileSystemUsedForProfile) { 295 TEST_F(ChromeArcUtilTest, IsArcCompatibleFileSystemUsedForProfile) {
278 // TODO(kinaba): Come up with some way to test the conditions below 296 // TODO(kinaba): Come up with some way to test the conditions below
279 // causes differences in the return values of IsArcAllowedForProfile() 297 // causes differences in the return values of IsArcAllowedForProfile()
280 // and IsArcAllowedInAppListForProfile(). 298 // and IsArcAllowedInAppListForProfile().
281 ScopedLogIn login(GetFakeUserManager(), 299 const AccountId id(AccountId::FromUserEmailGaiaId(
282 AccountId::FromUserEmailGaiaId( 300 profile()->GetProfileUserName(), kTestGaiaId));
283 profile()->GetProfileUserName(), kTestGaiaId)); 301 ScopedLogIn login(GetFakeUserManager(), id);
284 302
285 // Unconfirmed + Old ARC 303 // Unconfirmed + Old ARC
286 profile()->GetPrefs()->ClearPref(prefs::kArcCompatibleFilesystemChosen);
287 base::SysInfo::SetChromeOSVersionInfoForTest( 304 base::SysInfo::SetChromeOSVersionInfoForTest(
288 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); 305 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now());
289 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); 306 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile()));
290 307
291 // Unconfirmed + New ARC 308 // Unconfirmed + New ARC
292 base::SysInfo::SetChromeOSVersionInfoForTest( 309 base::SysInfo::SetChromeOSVersionInfoForTest(
293 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); 310 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now());
294 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile())); 311 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile()));
295 312
296 // Old FS + Old ARC 313 // Old FS + Old ARC
297 profile()->GetPrefs()->SetBoolean(prefs::kArcCompatibleFilesystemChosen, 314 user_manager::known_user::SetIntegerPref(
298 false); 315 id, prefs::kArcCompatibleFilesystemChosen, kFileSystemIncompatible);
299 base::SysInfo::SetChromeOSVersionInfoForTest( 316 base::SysInfo::SetChromeOSVersionInfoForTest(
300 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); 317 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now());
301 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); 318 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile()));
302 319
303 // Old FS + New ARC 320 // Old FS + New ARC
304 base::SysInfo::SetChromeOSVersionInfoForTest( 321 base::SysInfo::SetChromeOSVersionInfoForTest(
305 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); 322 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now());
306 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile())); 323 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile()));
307 324
308 // New FS + Old ARC 325 // New FS + Old ARC
309 profile()->GetPrefs()->SetBoolean(prefs::kArcCompatibleFilesystemChosen, 326 user_manager::known_user::SetIntegerPref(
310 true); 327 id, prefs::kArcCompatibleFilesystemChosen, kFileSystemCompatible);
311 base::SysInfo::SetChromeOSVersionInfoForTest( 328 base::SysInfo::SetChromeOSVersionInfoForTest(
312 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); 329 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now());
313 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); 330 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile()));
314 331
315 // New FS + New ARC 332 // New FS + New ARC
316 base::SysInfo::SetChromeOSVersionInfoForTest( 333 base::SysInfo::SetChromeOSVersionInfoForTest(
317 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); 334 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now());
318 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); 335 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile()));
336
337 // New FS (User notified) + Old ARC
338 user_manager::known_user::SetIntegerPref(
339 id, prefs::kArcCompatibleFilesystemChosen,
340 kFileSystemCompatibleAndNotified);
341 base::SysInfo::SetChromeOSVersionInfoForTest(
342 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now());
343 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile()));
344
345 // New FS (User notified) + New ARC
346 base::SysInfo::SetChromeOSVersionInfoForTest(
347 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now());
348 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile()));
319 } 349 }
320 350
321 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) { 351 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) {
322 // Ensure IsAllowedForProfile() true. 352 // Ensure IsAllowedForProfile() true.
323 ScopedLogIn login(GetFakeUserManager(), 353 ScopedLogIn login(GetFakeUserManager(),
324 AccountId::FromUserEmailGaiaId( 354 AccountId::FromUserEmailGaiaId(
325 profile()->GetProfileUserName(), kTestGaiaId)); 355 profile()->GetProfileUserName(), kTestGaiaId));
326 ASSERT_TRUE(IsArcAllowedForProfile(profile())); 356 ASSERT_TRUE(IsArcAllowedForProfile(profile()));
327 357
328 // By default, Google Play Store is disabled. 358 // By default, Google Play Store is disabled.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile())); 444 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile()));
415 445
416 // Both OptIn prefs are set to managed values, and the function returns true. 446 // Both OptIn prefs are set to managed values, and the function returns true.
417 profile()->GetTestingPrefService()->SetManagedPref( 447 profile()->GetTestingPrefService()->SetManagedPref(
418 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false)); 448 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false));
419 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile())); 449 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile()));
420 } 450 }
421 451
422 } // namespace util 452 } // namespace util
423 } // namespace arc 453 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_util.cc ('k') | chrome/browser/chromeos/login/session/user_session_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698