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

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

Issue 2806443002: arc: Add IsArcAllowedInAppListForProfile. (Closed)
Patch Set: Test 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/test/scoped_command_line.h" 13 #include "base/test/scoped_command_line.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow .h" 15 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow .h"
15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 16 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 18 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 std::unique_ptr<TestingProfile> profile_; 132 std::unique_ptr<TestingProfile> profile_;
132 133
133 DISALLOW_COPY_AND_ASSIGN(ChromeArcUtilTest); 134 DISALLOW_COPY_AND_ASSIGN(ChromeArcUtilTest);
134 }; 135 };
135 136
136 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile) { 137 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile) {
137 ScopedLogIn login(GetFakeUserManager(), 138 ScopedLogIn login(GetFakeUserManager(),
138 AccountId::FromUserEmailGaiaId( 139 AccountId::FromUserEmailGaiaId(
139 profile()->GetProfileUserName(), kTestGaiaId)); 140 profile()->GetProfileUserName(), kTestGaiaId));
140 EXPECT_TRUE(IsArcAllowedForProfile(profile())); 141 EXPECT_TRUE(IsArcAllowedForProfile(profile()));
142 EXPECT_TRUE(IsArcAllowedInAppListForProfile(profile()));
141 143
142 // false for nullptr. 144 // false for nullptr.
143 EXPECT_FALSE(IsArcAllowedForProfile(nullptr)); 145 EXPECT_FALSE(IsArcAllowedForProfile(nullptr));
146 EXPECT_FALSE(IsArcAllowedInAppListForProfile(nullptr));
144 147
145 // false for incognito mode profile. 148 // false for incognito mode profile.
146 EXPECT_FALSE(IsArcAllowedForProfile(profile()->GetOffTheRecordProfile())); 149 EXPECT_FALSE(IsArcAllowedForProfile(profile()->GetOffTheRecordProfile()));
150 EXPECT_FALSE(
151 IsArcAllowedInAppListForProfile(profile()->GetOffTheRecordProfile()));
147 152
148 // false for Legacy supervised user. 153 // false for Legacy supervised user.
149 profile()->SetSupervisedUserId("foo"); 154 profile()->SetSupervisedUserId("foo");
150 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 155 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
156 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
151 } 157 }
152 158
153 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DisableArc) { 159 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DisableArc) {
154 base::CommandLine::ForCurrentProcess()->InitFromArgv({""}); 160 base::CommandLine::ForCurrentProcess()->InitFromArgv({""});
155 ScopedLogIn login(GetFakeUserManager(), 161 ScopedLogIn login(GetFakeUserManager(),
156 AccountId::FromUserEmailGaiaId( 162 AccountId::FromUserEmailGaiaId(
157 profile()->GetProfileUserName(), kTestGaiaId)); 163 profile()->GetProfileUserName(), kTestGaiaId));
158 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 164 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
165 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
159 } 166 }
160 167
161 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_NonPrimaryProfile) { 168 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_NonPrimaryProfile) {
162 ScopedLogIn login2( 169 ScopedLogIn login2(
163 GetFakeUserManager(), 170 GetFakeUserManager(),
164 AccountId::FromUserEmailGaiaId("user2@gmail.com", "0123456789")); 171 AccountId::FromUserEmailGaiaId("user2@gmail.com", "0123456789"));
165 ScopedLogIn login(GetFakeUserManager(), 172 ScopedLogIn login(GetFakeUserManager(),
166 AccountId::FromUserEmailGaiaId( 173 AccountId::FromUserEmailGaiaId(
167 profile()->GetProfileUserName(), kTestGaiaId)); 174 profile()->GetProfileUserName(), kTestGaiaId));
168 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 175 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
176 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
169 } 177 }
170 178
171 // User without GAIA account. 179 // User without GAIA account.
172 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_PublicAccount) { 180 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_PublicAccount) {
173 ScopedLogIn login(GetFakeUserManager(), 181 ScopedLogIn login(GetFakeUserManager(),
174 AccountId::FromUserEmail("public_user@gmail.com"), 182 AccountId::FromUserEmail("public_user@gmail.com"),
175 user_manager::USER_TYPE_PUBLIC_ACCOUNT); 183 user_manager::USER_TYPE_PUBLIC_ACCOUNT);
176 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 184 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
185 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
177 } 186 }
178 187
179 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_ActiveDirectoryEnabled) { 188 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_ActiveDirectoryEnabled) {
180 base::CommandLine::ForCurrentProcess()->InitFromArgv( 189 base::CommandLine::ForCurrentProcess()->InitFromArgv(
181 {"", "--arc-availability=officially-supported-with-active-directory"}); 190 {"", "--arc-availability=officially-supported-with-active-directory"});
182 ScopedLogIn login( 191 ScopedLogIn login(
183 GetFakeUserManager(), 192 GetFakeUserManager(),
184 AccountId::AdFromObjGuid("f04557de-5da2-40ce-ae9d-b8874d8da96e"), 193 AccountId::AdFromObjGuid("f04557de-5da2-40ce-ae9d-b8874d8da96e"),
185 user_manager::USER_TYPE_ACTIVE_DIRECTORY); 194 user_manager::USER_TYPE_ACTIVE_DIRECTORY);
186 EXPECT_FALSE(chromeos::ProfileHelper::Get() 195 EXPECT_FALSE(chromeos::ProfileHelper::Get()
187 ->GetUserByProfile(profile()) 196 ->GetUserByProfile(profile())
188 ->HasGaiaAccount()); 197 ->HasGaiaAccount());
189 EXPECT_TRUE(IsArcAllowedForProfile(profile())); 198 EXPECT_TRUE(IsArcAllowedForProfile(profile()));
199 EXPECT_TRUE(IsArcAllowedInAppListForProfile(profile()));
190 } 200 }
191 201
192 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_ActiveDirectoryDisabled) { 202 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_ActiveDirectoryDisabled) {
193 ScopedLogIn login( 203 ScopedLogIn login(
194 GetFakeUserManager(), 204 GetFakeUserManager(),
195 AccountId::AdFromObjGuid("f04557de-5da2-40ce-ae9d-b8874d8da96e"), 205 AccountId::AdFromObjGuid("f04557de-5da2-40ce-ae9d-b8874d8da96e"),
196 user_manager::USER_TYPE_ACTIVE_DIRECTORY); 206 user_manager::USER_TYPE_ACTIVE_DIRECTORY);
197 EXPECT_FALSE(chromeos::ProfileHelper::Get() 207 EXPECT_FALSE(chromeos::ProfileHelper::Get()
198 ->GetUserByProfile(profile()) 208 ->GetUserByProfile(profile())
199 ->HasGaiaAccount()); 209 ->HasGaiaAccount());
200 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 210 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
211 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
201 } 212 }
202 213
203 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_KioskArcNotAvailable) { 214 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_KioskArcNotAvailable) {
204 base::CommandLine::ForCurrentProcess()->InitFromArgv({""}); 215 base::CommandLine::ForCurrentProcess()->InitFromArgv({""});
205 ScopedLogIn login(GetFakeUserManager(), 216 ScopedLogIn login(GetFakeUserManager(),
206 AccountId::FromUserEmail(profile()->GetProfileUserName()), 217 AccountId::FromUserEmail(profile()->GetProfileUserName()),
207 user_manager::USER_TYPE_ARC_KIOSK_APP); 218 user_manager::USER_TYPE_ARC_KIOSK_APP);
208 EXPECT_FALSE(chromeos::ProfileHelper::Get() 219 EXPECT_FALSE(chromeos::ProfileHelper::Get()
209 ->GetUserByProfile(profile()) 220 ->GetUserByProfile(profile())
210 ->HasGaiaAccount()); 221 ->HasGaiaAccount());
211 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 222 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
223 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
212 } 224 }
213 225
214 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_KioskArcInstalled) { 226 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_KioskArcInstalled) {
215 base::CommandLine::ForCurrentProcess()->InitFromArgv( 227 base::CommandLine::ForCurrentProcess()->InitFromArgv(
216 {"", "--arc-availability=installed"}); 228 {"", "--arc-availability=installed"});
217 ScopedLogIn login(GetFakeUserManager(), 229 ScopedLogIn login(GetFakeUserManager(),
218 AccountId::FromUserEmail(profile()->GetProfileUserName()), 230 AccountId::FromUserEmail(profile()->GetProfileUserName()),
219 user_manager::USER_TYPE_ARC_KIOSK_APP); 231 user_manager::USER_TYPE_ARC_KIOSK_APP);
220 EXPECT_FALSE(chromeos::ProfileHelper::Get() 232 EXPECT_FALSE(chromeos::ProfileHelper::Get()
221 ->GetUserByProfile(profile()) 233 ->GetUserByProfile(profile())
222 ->HasGaiaAccount()); 234 ->HasGaiaAccount());
223 EXPECT_TRUE(IsArcAllowedForProfile(profile())); 235 EXPECT_TRUE(IsArcAllowedForProfile(profile()));
236 EXPECT_TRUE(IsArcAllowedInAppListForProfile(profile()));
224 } 237 }
225 238
226 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_KioskArcSupported) { 239 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_KioskArcSupported) {
227 base::CommandLine::ForCurrentProcess()->InitFromArgv( 240 base::CommandLine::ForCurrentProcess()->InitFromArgv(
228 {"", "--arc-availability=officially-supported"}); 241 {"", "--arc-availability=officially-supported"});
229 ScopedLogIn login(GetFakeUserManager(), 242 ScopedLogIn login(GetFakeUserManager(),
230 AccountId::FromUserEmail(profile()->GetProfileUserName()), 243 AccountId::FromUserEmail(profile()->GetProfileUserName()),
231 user_manager::USER_TYPE_ARC_KIOSK_APP); 244 user_manager::USER_TYPE_ARC_KIOSK_APP);
232 EXPECT_FALSE(chromeos::ProfileHelper::Get() 245 EXPECT_FALSE(chromeos::ProfileHelper::Get()
233 ->GetUserByProfile(profile()) 246 ->GetUserByProfile(profile())
234 ->HasGaiaAccount()); 247 ->HasGaiaAccount());
235 EXPECT_TRUE(IsArcAllowedForProfile(profile())); 248 EXPECT_TRUE(IsArcAllowedForProfile(profile()));
249 EXPECT_TRUE(IsArcAllowedInAppListForProfile(profile()));
236 } 250 }
237 251
238 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_SupervisedUserFlow) { 252 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_SupervisedUserFlow) {
239 auto manager_id = AccountId::FromUserEmailGaiaId( 253 auto manager_id = AccountId::FromUserEmailGaiaId(
240 profile()->GetProfileUserName(), kTestGaiaId); 254 profile()->GetProfileUserName(), kTestGaiaId);
241 ScopedLogIn login(GetFakeUserManager(), manager_id); 255 ScopedLogIn login(GetFakeUserManager(), manager_id);
242 GetFakeUserManager()->SetUserFlow( 256 GetFakeUserManager()->SetUserFlow(
243 manager_id, new chromeos::SupervisedUserCreationFlow(manager_id)); 257 manager_id, new chromeos::SupervisedUserCreationFlow(manager_id));
244 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 258 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
245 GetFakeUserManager()->ResetUserFlow(manager_id); 259 GetFakeUserManager()->ResetUserFlow(manager_id);
246 } 260 }
247 261
248 // Guest account is interpreted as EphemeralDataUser. 262 // Guest account is interpreted as EphemeralDataUser.
249 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_GuestAccount) { 263 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_GuestAccount) {
250 ScopedLogIn login(GetFakeUserManager(), 264 ScopedLogIn login(GetFakeUserManager(),
251 GetFakeUserManager()->GetGuestAccountId()); 265 GetFakeUserManager()->GetGuestAccountId());
252 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 266 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
267 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
253 } 268 }
254 269
255 // Demo account is interpreted as EphemeralDataUser. 270 // Demo account is interpreted as EphemeralDataUser.
256 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DemoAccount) { 271 TEST_F(ChromeArcUtilTest, IsArcAllowedForProfile_DemoAccount) {
257 ScopedLogIn login(GetFakeUserManager(), user_manager::DemoAccountId()); 272 ScopedLogIn login(GetFakeUserManager(), user_manager::DemoAccountId());
258 EXPECT_FALSE(IsArcAllowedForProfile(profile())); 273 EXPECT_FALSE(IsArcAllowedForProfile(profile()));
274 EXPECT_FALSE(IsArcAllowedInAppListForProfile(profile()));
275 }
276
277 TEST_F(ChromeArcUtilTest, IsProfileVerifiedToBeOnArcCompatibleFilesystem) {
278 // TODO(kinaba): Come up with some way to test the conditions below
279 // causes differences in the return values of IsArcAllowedForProfile()
280 // and IsArcAllowedInAppListForProfile().
281 ScopedLogIn login(GetFakeUserManager(),
282 AccountId::FromUserEmailGaiaId(
283 profile()->GetProfileUserName(), kTestGaiaId));
284
285 // Unconfirmed + Old ARC
286 profile()->GetPrefs()->ClearPref(prefs::kArcCompatibleFilesystemChosen);
287 base::SysInfo::SetChromeOSVersionInfoForTest(
288 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now());
289 EXPECT_TRUE(IsProfileVerifiedToBeOnArcCompatibleFilesystem(profile()));
290
291 // Unconfirmed + New ARC
292 base::SysInfo::SetChromeOSVersionInfoForTest(
293 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now());
294 EXPECT_FALSE(IsProfileVerifiedToBeOnArcCompatibleFilesystem(profile()));
295
296 // Old FS + Old ARC
297 profile()->GetPrefs()->SetBoolean(prefs::kArcCompatibleFilesystemChosen,
298 false);
299 base::SysInfo::SetChromeOSVersionInfoForTest(
300 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now());
301 EXPECT_TRUE(IsProfileVerifiedToBeOnArcCompatibleFilesystem(profile()));
302
303 // Old FS + New ARC
304 base::SysInfo::SetChromeOSVersionInfoForTest(
305 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now());
306 EXPECT_FALSE(IsProfileVerifiedToBeOnArcCompatibleFilesystem(profile()));
307
308 // New FS + Old ARC
309 profile()->GetPrefs()->SetBoolean(prefs::kArcCompatibleFilesystemChosen,
310 true);
311 base::SysInfo::SetChromeOSVersionInfoForTest(
312 "CHROMEOS_ARC_ANDROID_SDK_VERSION=23", base::Time::Now());
313 EXPECT_TRUE(IsProfileVerifiedToBeOnArcCompatibleFilesystem(profile()));
314
315 // New FS + New ARC
316 base::SysInfo::SetChromeOSVersionInfoForTest(
317 "CHROMEOS_ARC_ANDROID_SDK_VERSION=25", base::Time::Now());
318 EXPECT_TRUE(IsProfileVerifiedToBeOnArcCompatibleFilesystem(profile()));
259 } 319 }
260 320
261 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) { 321 TEST_F(ChromeArcUtilTest, ArcPlayStoreEnabledForProfile) {
262 // Ensure IsAllowedForProfile() true. 322 // Ensure IsAllowedForProfile() true.
263 ScopedLogIn login(GetFakeUserManager(), 323 ScopedLogIn login(GetFakeUserManager(),
264 AccountId::FromUserEmailGaiaId( 324 AccountId::FromUserEmailGaiaId(
265 profile()->GetProfileUserName(), kTestGaiaId)); 325 profile()->GetProfileUserName(), kTestGaiaId));
266 ASSERT_TRUE(IsArcAllowedForProfile(profile())); 326 ASSERT_TRUE(IsArcAllowedForProfile(profile()));
267 327
268 // By default, Google Play Store is disabled. 328 // By default, Google Play Store is disabled.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile())); 414 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile()));
355 415
356 // Both OptIn prefs are set to managed values, and the function returns true. 416 // Both OptIn prefs are set to managed values, and the function returns true.
357 profile()->GetTestingPrefService()->SetManagedPref( 417 profile()->GetTestingPrefService()->SetManagedPref(
358 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false)); 418 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false));
359 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile())); 419 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile()));
360 } 420 }
361 421
362 } // namespace util 422 } // namespace util
363 } // namespace arc 423 } // namespace arc
OLDNEW
« chrome/browser/chromeos/arc/arc_util.h ('K') | « chrome/browser/chromeos/arc/arc_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698