| 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 "base/values.h" |
| 14 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow
.h" | 14 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow
.h" |
| 15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| 23 #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" | 24 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 25 #include "components/user_manager/user_manager.h" | 25 #include "components/user_manager/user_manager.h" |
| 26 #include "components/user_manager/user_names.h" |
| 26 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 namespace arc { | 30 namespace arc { |
| 30 namespace util { | 31 namespace util { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 constexpr char kTestProfileName[] = "user@gmail.com"; | 35 constexpr char kTestProfileName[] = "user@gmail.com"; |
| 35 constexpr char kTestGaiaId[] = "1234567890"; | 36 constexpr char kTestGaiaId[] = "1234567890"; |
| 36 | 37 |
| 37 class ScopedLogIn { | 38 class ScopedLogIn { |
| 38 public: | 39 public: |
| 39 ScopedLogIn( | 40 ScopedLogIn( |
| 40 chromeos::FakeChromeUserManager* fake_user_manager, | 41 chromeos::FakeChromeUserManager* fake_user_manager, |
| 41 const AccountId& account_id, | 42 const AccountId& account_id, |
| 42 user_manager::UserType user_type = user_manager::USER_TYPE_REGULAR) | 43 user_manager::UserType user_type = user_manager::USER_TYPE_REGULAR) |
| 43 : fake_user_manager_(fake_user_manager), account_id_(account_id) { | 44 : fake_user_manager_(fake_user_manager), account_id_(account_id) { |
| 44 switch (user_type) { | 45 switch (user_type) { |
| 45 case user_manager::USER_TYPE_REGULAR: // fallthrough | 46 case user_manager::USER_TYPE_REGULAR: // fallthrough |
| 46 case user_manager::USER_TYPE_ACTIVE_DIRECTORY: | 47 case user_manager::USER_TYPE_ACTIVE_DIRECTORY: |
| 47 LogIn(); | 48 LogIn(); |
| 48 break; | 49 break; |
| 50 case user_manager::USER_TYPE_PUBLIC_ACCOUNT: |
| 51 LogInAsPublicAccount(); |
| 52 break; |
| 49 case user_manager::USER_TYPE_ARC_KIOSK_APP: | 53 case user_manager::USER_TYPE_ARC_KIOSK_APP: |
| 50 LogInArcKioskApp(); | 54 LogInArcKioskApp(); |
| 51 break; | 55 break; |
| 52 default: | 56 default: |
| 53 NOTREACHED(); | 57 NOTREACHED(); |
| 54 } | 58 } |
| 55 } | 59 } |
| 56 | 60 |
| 57 ~ScopedLogIn() { LogOut(); } | 61 ~ScopedLogIn() { LogOut(); } |
| 58 | 62 |
| 59 private: | 63 private: |
| 60 void LogIn() { | 64 void LogIn() { |
| 61 fake_user_manager_->AddUser(account_id_); | 65 fake_user_manager_->AddUser(account_id_); |
| 62 fake_user_manager_->LoginUser(account_id_); | 66 fake_user_manager_->LoginUser(account_id_); |
| 63 } | 67 } |
| 64 | 68 |
| 69 void LogInAsPublicAccount() { |
| 70 fake_user_manager_->AddPublicAccountUser(account_id_); |
| 71 fake_user_manager_->LoginUser(account_id_); |
| 72 } |
| 73 |
| 65 void LogInArcKioskApp() { | 74 void LogInArcKioskApp() { |
| 66 fake_user_manager_->AddArcKioskAppUser(account_id_); | 75 fake_user_manager_->AddArcKioskAppUser(account_id_); |
| 67 fake_user_manager_->LoginUser(account_id_); | 76 fake_user_manager_->LoginUser(account_id_); |
| 68 } | 77 } |
| 69 | 78 |
| 70 void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); } | 79 void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); } |
| 71 | 80 |
| 72 chromeos::FakeChromeUserManager* fake_user_manager_; | 81 chromeos::FakeChromeUserManager* fake_user_manager_; |
| 73 const AccountId account_id_; | 82 const AccountId account_id_; |
| 74 | 83 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_NonPrimaryProfile) { | 161 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_NonPrimaryProfile) { |
| 153 ScopedLogIn login2( | 162 ScopedLogIn login2( |
| 154 GetFakeUserManager(), | 163 GetFakeUserManager(), |
| 155 AccountId::FromUserEmailGaiaId("user2@gmail.com", "0123456789")); | 164 AccountId::FromUserEmailGaiaId("user2@gmail.com", "0123456789")); |
| 156 ScopedLogIn login(GetFakeUserManager(), | 165 ScopedLogIn login(GetFakeUserManager(), |
| 157 AccountId::FromUserEmailGaiaId( | 166 AccountId::FromUserEmailGaiaId( |
| 158 profile()->GetProfileUserName(), kTestGaiaId)); | 167 profile()->GetProfileUserName(), kTestGaiaId)); |
| 159 EXPECT_FALSE(IsArcAllowedForProfile(profile())); | 168 EXPECT_FALSE(IsArcAllowedForProfile(profile())); |
| 160 } | 169 } |
| 161 | 170 |
| 171 // User without GAIA account. |
| 172 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_PublicAccount) { |
| 173 ScopedLogIn login(GetFakeUserManager(), |
| 174 AccountId::FromUserEmail("public_user@gmail.com"), |
| 175 user_manager::USER_TYPE_PUBLIC_ACCOUNT); |
| 176 EXPECT_FALSE(IsArcAllowedForProfile(profile())); |
| 177 } |
| 178 |
| 162 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_ActiveDirectoryEnabled) { | 179 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_ActiveDirectoryEnabled) { |
| 163 base::CommandLine::ForCurrentProcess()->InitFromArgv( | 180 base::CommandLine::ForCurrentProcess()->InitFromArgv( |
| 164 {"", "--arc-availability=officially-supported-with-active-directory"}); | 181 {"", "--arc-availability=officially-supported-with-active-directory"}); |
| 165 ScopedLogIn login( | 182 ScopedLogIn login( |
| 166 GetFakeUserManager(), | 183 GetFakeUserManager(), |
| 167 AccountId::AdFromObjGuid("f04557de-5da2-40ce-ae9d-b8874d8da96e"), | 184 AccountId::AdFromObjGuid("f04557de-5da2-40ce-ae9d-b8874d8da96e"), |
| 168 user_manager::USER_TYPE_ACTIVE_DIRECTORY); | 185 user_manager::USER_TYPE_ACTIVE_DIRECTORY); |
| 169 EXPECT_FALSE(chromeos::ProfileHelper::Get() | 186 EXPECT_FALSE(chromeos::ProfileHelper::Get() |
| 170 ->GetUserByProfile(profile()) | 187 ->GetUserByProfile(profile()) |
| 171 ->HasGaiaAccount()); | 188 ->HasGaiaAccount()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_SupervisedUserFlow) { | 236 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_SupervisedUserFlow) { |
| 220 auto manager_id = AccountId::FromUserEmailGaiaId( | 237 auto manager_id = AccountId::FromUserEmailGaiaId( |
| 221 profile()->GetProfileUserName(), kTestGaiaId); | 238 profile()->GetProfileUserName(), kTestGaiaId); |
| 222 ScopedLogIn login(GetFakeUserManager(), manager_id); | 239 ScopedLogIn login(GetFakeUserManager(), manager_id); |
| 223 GetFakeUserManager()->SetUserFlow( | 240 GetFakeUserManager()->SetUserFlow( |
| 224 manager_id, new chromeos::SupervisedUserCreationFlow(manager_id)); | 241 manager_id, new chromeos::SupervisedUserCreationFlow(manager_id)); |
| 225 EXPECT_FALSE(IsArcAllowedForProfile(profile())); | 242 EXPECT_FALSE(IsArcAllowedForProfile(profile())); |
| 226 GetFakeUserManager()->ResetUserFlow(manager_id); | 243 GetFakeUserManager()->ResetUserFlow(manager_id); |
| 227 } | 244 } |
| 228 | 245 |
| 229 // TODO(hidehiko): Add test for Ephemeral users. There seems no way to easily | 246 // Guest account is interpreted as EphemeralDataUser. |
| 230 // simulate ephemeral user. | 247 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_GuestAccount) { |
| 248 ScopedLogIn login(GetFakeUserManager(), |
| 249 GetFakeUserManager()->GetGuestAccountId()); |
| 250 EXPECT_FALSE(IsArcAllowedForProfile(profile())); |
| 251 } |
| 252 |
| 253 // Demo account is interpreted as EphemeralDataUser. |
| 254 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DemoAccount) { |
| 255 ScopedLogIn login(GetFakeUserManager(), user_manager::DemoAccountId()); |
| 256 EXPECT_FALSE(IsArcAllowedForProfile(profile())); |
| 257 } |
| 231 | 258 |
| 232 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) { | 259 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) { |
| 233 // Ensure IsAllowedForProfile() true. | 260 // Ensure IsAllowedForProfile() true. |
| 234 ScopedLogIn login(GetFakeUserManager(), | 261 ScopedLogIn login(GetFakeUserManager(), |
| 235 AccountId::FromUserEmailGaiaId( | 262 AccountId::FromUserEmailGaiaId( |
| 236 profile()->GetProfileUserName(), kTestGaiaId)); | 263 profile()->GetProfileUserName(), kTestGaiaId)); |
| 237 ASSERT_TRUE(IsArcAllowedForProfile(profile())); | 264 ASSERT_TRUE(IsArcAllowedForProfile(profile())); |
| 238 | 265 |
| 239 // By default, Google Play Store is disabled. | 266 // By default, Google Play Store is disabled. |
| 240 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 267 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); | 322 EXPECT_TRUE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 296 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 323 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 297 | 324 |
| 298 // Remove managed state. | 325 // Remove managed state. |
| 299 profile()->GetTestingPrefService()->RemoveManagedPref(prefs::kArcEnabled); | 326 profile()->GetTestingPrefService()->RemoveManagedPref(prefs::kArcEnabled); |
| 300 EXPECT_FALSE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); | 327 EXPECT_FALSE(IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 301 } | 328 } |
| 302 | 329 |
| 303 } // namespace util | 330 } // namespace util |
| 304 } // namespace arc | 331 } // namespace arc |
| OLD | NEW |