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/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 Loading... |
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 |
| 105 DISALLOW_COPY_AND_ASSIGN(FakeUserManagerWithLocalState); |
| 106 }; |
| 107 |
88 } // namespace | 108 } // namespace |
89 | 109 |
90 class ChromeArcUtilTest : public testing::Test { | 110 class ChromeArcUtilTest : public testing::Test { |
91 public: | 111 public: |
92 ChromeArcUtilTest() = default; | 112 ChromeArcUtilTest() = default; |
93 ~ChromeArcUtilTest() override = default; | 113 ~ChromeArcUtilTest() override = default; |
94 | 114 |
95 void SetUp() override { | 115 void SetUp() override { |
96 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); | 116 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); |
97 command_line_->GetProcessCommandLine()->InitFromArgv({"", "--enable-arc"}); | 117 command_line_->GetProcessCommandLine()->InitFromArgv({"", "--enable-arc"}); |
98 | 118 |
99 user_manager_enabler_ = | 119 user_manager_enabler_ = |
100 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( | 120 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( |
101 new chromeos::FakeChromeUserManager()); | 121 new FakeUserManagerWithLocalState()); |
102 chromeos::WallpaperManager::Initialize(); | 122 chromeos::WallpaperManager::Initialize(); |
103 profile_ = base::MakeUnique<TestingProfile>(); | 123 profile_ = base::MakeUnique<TestingProfile>(); |
104 profile_->set_profile_name(kTestProfileName); | 124 profile_->set_profile_name(kTestProfileName); |
105 } | 125 } |
106 | 126 |
107 void TearDown() override { | 127 void TearDown() override { |
108 profile_.reset(); | 128 profile_.reset(); |
109 chromeos::WallpaperManager::Shutdown(); | 129 chromeos::WallpaperManager::Shutdown(); |
110 user_manager_enabler_.reset(); | 130 user_manager_enabler_.reset(); |
111 command_line_.reset(); | 131 command_line_.reset(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DemoAccount) { | 291 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DemoAccount) { |
272 ScopedLogIn login(GetFakeUserManager(), user_manager::DemoAccountId()); | 292 ScopedLogIn login(GetFakeUserManager(), user_manager::DemoAccountId()); |
273 EXPECT_FALSE(IsArcAllowedForProfile(profile())); | 293 EXPECT_FALSE(IsArcAllowedForProfile(profile())); |
274 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile())); | 294 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile())); |
275 } | 295 } |
276 | 296 |
277 TEST_F(ChromeArcUtilTest, IsArcCompatibleFileSystemUsedForProfile) { | 297 TEST_F(ChromeArcUtilTest, IsArcCompatibleFileSystemUsedForProfile) { |
278 // TODO(kinaba): Come up with some way to test the conditions below | 298 // TODO(kinaba): Come up with some way to test the conditions below |
279 // causes differences in the return values of IsArcAllowedForProfile() | 299 // causes differences in the return values of IsArcAllowedForProfile() |
280 // and IsArcAllowedInAppListForProfile(). | 300 // and IsArcAllowedInAppListForProfile(). |
281 ScopedLogIn login(GetFakeUserManager(), | 301 const AccountId id(AccountId::FromUserEmailGaiaId( |
282 AccountId::FromUserEmailGaiaId( | 302 profile()->GetProfileUserName(), kTestGaiaId)); |
283 profile()->GetProfileUserName(), kTestGaiaId)); | 303 ScopedLogIn login(GetFakeUserManager(), id); |
284 | 304 |
285 // Unconfirmed + Old ARC | 305 // Unconfirmed + Old ARC |
286 profile()->GetPrefs()->ClearPref(prefs::kArcCompatibleFilesystemChosen); | |
287 base::SysInfo::SetChromeOSVersionInfoForTest( | 306 base::SysInfo::SetChromeOSVersionInfoForTest( |
288 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); | 307 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); |
289 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); | 308 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
290 | 309 |
291 // Unconfirmed + New ARC | 310 // Unconfirmed + New ARC |
292 base::SysInfo::SetChromeOSVersionInfoForTest( | 311 base::SysInfo::SetChromeOSVersionInfoForTest( |
293 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); | 312 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); |
294 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile())); | 313 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
295 | 314 |
296 // Old FS + Old ARC | 315 // Old FS + Old ARC |
297 profile()->GetPrefs()->SetBoolean(prefs::kArcCompatibleFilesystemChosen, | 316 user_manager::known_user::SetIntegerPref( |
298 false); | 317 id, prefs::kArcCompatibleFilesystemChosen, kFileSystemIncompatible); |
299 base::SysInfo::SetChromeOSVersionInfoForTest( | 318 base::SysInfo::SetChromeOSVersionInfoForTest( |
300 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); | 319 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); |
301 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); | 320 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
302 | 321 |
303 // Old FS + New ARC | 322 // Old FS + New ARC |
304 base::SysInfo::SetChromeOSVersionInfoForTest( | 323 base::SysInfo::SetChromeOSVersionInfoForTest( |
305 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); | 324 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); |
306 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile())); | 325 EXPECT_FALSE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
307 | 326 |
308 // New FS + Old ARC | 327 // New FS + Old ARC |
309 profile()->GetPrefs()->SetBoolean(prefs::kArcCompatibleFilesystemChosen, | 328 user_manager::known_user::SetIntegerPref( |
310 true); | 329 id, prefs::kArcCompatibleFilesystemChosen, kFileSystemCompatible); |
311 base::SysInfo::SetChromeOSVersionInfoForTest( | 330 base::SysInfo::SetChromeOSVersionInfoForTest( |
312 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); | 331 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); |
313 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); | 332 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
314 | 333 |
315 // New FS + New ARC | 334 // New FS + New ARC |
316 base::SysInfo::SetChromeOSVersionInfoForTest( | 335 base::SysInfo::SetChromeOSVersionInfoForTest( |
317 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); | 336 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); |
318 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); | 337 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
| 338 |
| 339 // New FS (User notified) + Old ARC |
| 340 user_manager::known_user::SetIntegerPref( |
| 341 id, prefs::kArcCompatibleFilesystemChosen, |
| 342 kFileSystemCompatibleAndNotified); |
| 343 base::SysInfo::SetChromeOSVersionInfoForTest( |
| 344 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now()); |
| 345 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
| 346 |
| 347 // New FS (User notified) + New ARC |
| 348 base::SysInfo::SetChromeOSVersionInfoForTest( |
| 349 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now()); |
| 350 EXPECT_TRUE(IsArcCompatibleFileSystemUsedForProfile(profile())); |
319 } | 351 } |
320 | 352 |
321 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) { | 353 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) { |
322 // Ensure IsAllowedForProfile() true. | 354 // Ensure IsAllowedForProfile() true. |
323 ScopedLogIn login(GetFakeUserManager(), | 355 ScopedLogIn login(GetFakeUserManager(), |
324 AccountId::FromUserEmailGaiaId( | 356 AccountId::FromUserEmailGaiaId( |
325 profile()->GetProfileUserName(), kTestGaiaId)); | 357 profile()->GetProfileUserName(), kTestGaiaId)); |
326 ASSERT_TRUE(IsArcAllowedForProfile(profile())); | 358 ASSERT_TRUE(IsArcAllowedForProfile(profile())); |
327 | 359 |
328 // By default, Google Play Store is disabled. | 360 // By default, Google Play Store is disabled. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile())); | 446 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile())); |
415 | 447 |
416 // Both OptIn prefs are set to managed values, and the function returns true. | 448 // Both OptIn prefs are set to managed values, and the function returns true. |
417 profile()->GetTestingPrefService()->SetManagedPref( | 449 profile()->GetTestingPrefService()->SetManagedPref( |
418 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false)); | 450 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false)); |
419 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile())); | 451 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile())); |
420 } | 452 } |
421 | 453 |
422 } // namespace util | 454 } // namespace util |
423 } // namespace arc | 455 } // namespace arc |
OLD | NEW |