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

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

Issue 2708923013: Split ArcSessionManager::OnPrimaryUserProfilePrepared(). (Closed)
Patch Set: Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <tuple> 7 #include <tuple>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 public: 207 public:
208 ArcSessionManagerTest() = default; 208 ArcSessionManagerTest() = default;
209 209
210 void SetUp() override { 210 void SetUp() override {
211 ArcSessionManagerTestBase::SetUp(); 211 ArcSessionManagerTestBase::SetUp();
212 212
213 const AccountId account_id(AccountId::FromUserEmailGaiaId( 213 const AccountId account_id(AccountId::FromUserEmailGaiaId(
214 profile()->GetProfileUserName(), "1234567890")); 214 profile()->GetProfileUserName(), "1234567890"));
215 GetFakeUserManager()->AddUser(account_id); 215 GetFakeUserManager()->AddUser(account_id);
216 GetFakeUserManager()->LoginUser(account_id); 216 GetFakeUserManager()->LoginUser(account_id);
217
218 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
219 arc_session_manager()->state());
220 ASSERT_TRUE(arc_session_manager()->IsSessionStopped());
217 } 221 }
218 222
219 private: 223 private:
220 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 224 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
221 }; 225 };
222 226
223 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 227 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) {
224 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 228 ASSERT_FALSE(IsArcPlayStoreEnabledForProfile(profile()));
229 arc_session_manager()->SetProfile(profile());
230 arc_session_manager()->StartPreferenceHandler();
231
232 // If the initial value of Google Play Store enabled preference is false,
233 // the data dir is being removed.
234 EXPECT_TRUE(
235 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
236 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
225 arc_session_manager()->state()); 237 arc_session_manager()->state());
226
227 PrefService* const pref = profile()->GetPrefs();
228 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
229
230 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
231
232 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 238 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
233 239
234 pref->SetBoolean(prefs::kArcEnabled, true); 240 SetArcPlayStoreEnabledForProfile(profile(), true);
235 base::RunLoop().RunUntilIdle(); 241 base::RunLoop().RunUntilIdle();
236 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 242 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
237 arc_session_manager()->state()); 243 arc_session_manager()->state());
238 244
239 pref->SetBoolean(prefs::kArcEnabled, false); 245 SetArcPlayStoreEnabledForProfile(profile(), false);
240 246
241 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 247 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
242 248
243 // Correctly stop service. 249 // Correctly stop service.
244 arc_session_manager()->Shutdown(); 250 arc_session_manager()->Shutdown();
245 } 251 }
246 252
253 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService_Restart) {
254 // Sets the Google Play Store preference at beginning.
255 SetArcPlayStoreEnabledForProfile(profile(), true);
256
257 arc_session_manager()->SetProfile(profile());
258 arc_session_manager()->StartPreferenceHandler();
259
260 // Setting profile initiates a code fetching process.
261 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
262 arc_session_manager()->state());
263
264 content::BrowserThread::GetBlockingPool()->FlushForTesting();
265 base::RunLoop().RunUntilIdle();
266
267 // UI is disabled in unit tests and this code is unchanged.
268 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
269 arc_session_manager()->state());
270
271 // Correctly stop service.
272 arc_session_manager()->Shutdown();
273 }
274
247 TEST_F(ArcSessionManagerTest, BaseWorkflow) { 275 TEST_F(ArcSessionManagerTest, BaseWorkflow) {
248 ASSERT_TRUE(arc_session_manager()->IsSessionStopped());
249 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
250 arc_session_manager()->state());
251 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); 276 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null());
252 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); 277 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null());
253 278
254 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 279 arc_session_manager()->SetProfile(profile());
255 280
256 // By default ARC is not enabled. 281 // By default, ARC is not enabled.
257 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 282 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
258 283
259 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 284 // Enables ARC. First time, ToS negotiation should start.
285 arc_session_manager()->RequestEnable();
260 base::RunLoop().RunUntilIdle(); 286 base::RunLoop().RunUntilIdle();
261
262 // Setting profile and pref initiates a code fetching process.
263 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 287 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
264 arc_session_manager()->state()); 288 arc_session_manager()->state());
265 289
266 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> 290 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE ->
267 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. 291 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager.
268 arc_session_manager()->StartArc(); 292 arc_session_manager()->StartArc();
269 293
270 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); 294 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null());
271 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); 295 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null());
272 296
273 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 297 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
274 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); 298 ASSERT_TRUE(arc_session_manager()->IsSessionRunning());
275 299
276 arc_session_manager()->Shutdown(); 300 arc_session_manager()->Shutdown();
277 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
hidehiko 2017/02/24 18:29:13 Note: this is unexpected use case, so may be not a
278 arc_session_manager()->state());
279 ASSERT_TRUE(arc_session_manager()->IsSessionStopped());
280
281 // Send profile and don't provide a code.
282 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
283
284 // Setting profile initiates a code fetching process.
285 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
286 arc_session_manager()->state());
287
288 content::BrowserThread::GetBlockingPool()->FlushForTesting();
289 base::RunLoop().RunUntilIdle();
290
291 // UI is disabled in unit tests and this code is unchanged.
292 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
293 arc_session_manager()->state());
294
295 // Correctly stop service.
296 arc_session_manager()->Shutdown();
297 } 301 }
298 302
299 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { 303 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) {
300 PrefService* const pref = profile()->GetPrefs(); 304 SetArcPlayStoreEnabledForProfile(profile(), true);
301 305
302 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 306 // Starts ARC.
303 pref->SetBoolean(prefs::kArcEnabled, true); 307 arc_session_manager()->SetProfile(profile());
308 arc_session_manager()->RequestEnable();
304 base::RunLoop().RunUntilIdle(); 309 base::RunLoop().RunUntilIdle();
305
306 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 310 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
307 arc_session_manager()->state()); 311 arc_session_manager()->state());
308 312
313 // Emulate to cancel the ToS UI (e.g. closing the window).
309 arc_session_manager()->CancelAuthCode(); 314 arc_session_manager()->CancelAuthCode();
310 315
316 // Google Play Store enabled preference should be set to false, too.
317 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile()));
318
319 // Emulate the preference handling.
320 arc_session_manager()->RequestDisable();
321
311 // Wait until data is removed. 322 // Wait until data is removed.
312 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 323 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
313 324
314 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
315
316 // Correctly stop service. 325 // Correctly stop service.
317 arc_session_manager()->Shutdown(); 326 arc_session_manager()->Shutdown();
318 } 327 }
319 328
320 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { 329 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) {
321 PrefService* const pref = profile()->GetPrefs(); 330 // Starts ARC.
322 331 SetArcPlayStoreEnabledForProfile(profile(), true);
323 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 332 arc_session_manager()->SetProfile(profile());
324 pref->SetBoolean(prefs::kArcEnabled, true); 333 arc_session_manager()->RequestEnable();
325 base::RunLoop().RunUntilIdle(); 334 base::RunLoop().RunUntilIdle();
326 335 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
336 arc_session_manager()->state());
327 arc_session_manager()->StartArc(); 337 arc_session_manager()->StartArc();
328
329 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 338 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
330 339
340 // When ARC is properly started, closing UI should be no-op.
331 arc_session_manager()->CancelAuthCode(); 341 arc_session_manager()->CancelAuthCode();
332 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 342 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
333 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); 343 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile()));
334 344
335 // Correctly stop service. 345 // Correctly stop service.
336 arc_session_manager()->Shutdown(); 346 arc_session_manager()->Shutdown();
337 } 347 }
338 348
339 TEST_F(ArcSessionManagerTest, SignInStatus) { 349 TEST_F(ArcSessionManagerTest, Provisioning_Success) {
340 PrefService* const prefs = profile()->GetPrefs(); 350 PrefService* const prefs = profile()->GetPrefs();
341 351
342 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); 352 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null());
343 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); 353 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null());
344 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); 354 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting());
345 355
346 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 356 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
347 prefs->SetBoolean(prefs::kArcEnabled, true);
348 357
349 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 358 arc_session_manager()->SetProfile(profile());
350 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 359 arc_session_manager()->RequestEnable();
360 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
351 arc_session_manager()->state()); 361 arc_session_manager()->state());
352 362
353 // Emulate to accept the terms of service. 363 // Emulate to accept the terms of service.
354 prefs->SetBoolean(prefs::kArcTermsAccepted, true); 364 prefs->SetBoolean(prefs::kArcTermsAccepted, true);
355 arc_session_manager()->StartArc(); 365 arc_session_manager()->StartArc();
356 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 366 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
357 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 367 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
368
369 // Here, provisining is not yet completed, so kArcSignedIn should be false.
358 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 370 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
359 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); 371 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null());
360 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); 372 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting());
373
374 // Emulate successful provisioning.
361 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); 375 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS);
362 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 376 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
363 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 377 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
364 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 378 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
365 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); 379 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null());
366 EXPECT_TRUE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); 380 EXPECT_TRUE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting());
381 }
382
383 TEST_F(ArcSessionManagerTest, Provisioning_Restart) {
384 // Set up the situation that provisioning is successfully done in the
385 // previous session.
386 PrefService* const prefs = profile()->GetPrefs();
387 prefs->SetBoolean(prefs::kArcTermsAccepted, true);
388 prefs->SetBoolean(prefs::kArcSignedIn, true);
389
390 arc_session_manager()->SetProfile(profile());
391 arc_session_manager()->RequestEnable();
367 392
368 // Second start, no fetching code is expected. 393 // Second start, no fetching code is expected.
369 arc_session_manager()->Shutdown();
hidehiko 2017/02/24 18:29:13 Similarly, split into two tests.
370 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
371 arc_session_manager()->state());
372 EXPECT_TRUE(arc_session_manager()->IsSessionStopped());
373 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
374 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
375 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 394 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
376 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 395 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
377 396
378 // Report failure. 397 // Report failure.
379 arc_session_manager()->OnProvisioningFinished( 398 arc_session_manager()->OnProvisioningFinished(
380 ProvisioningResult::GMS_NETWORK_ERROR); 399 ProvisioningResult::GMS_NETWORK_ERROR);
381 // On error, UI to send feedback is showing. In that case, 400 // On error, UI to send feedback is showing. In that case,
382 // the ARC is still necessary to run on background for gathering the logs. 401 // the ARC is still necessary to run on background for gathering the logs.
383 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 402 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
384 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 403 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
385 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 404 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
386 405
387 // Correctly stop service. 406 // Correctly stop service.
388 arc_session_manager()->Shutdown(); 407 arc_session_manager()->Shutdown();
389 } 408 }
390 409
391 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) { 410 TEST_F(ArcSessionManagerTest, RemoveDataDir) {
hidehiko 2017/02/24 18:29:13 Removed. This is testing for public account, which
392 PrefService* const prefs = profile()->GetPrefs(); 411 // Emulate the situation where the initial Google Play Store enabled
393 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 412 // preference is false, i.e., data dir is being removed at beginning.
394 prefs->SetBoolean(prefs::kArcEnabled, true); 413 arc_session_manager()->SetProfile(profile());
395 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 414 arc_session_manager()->RemoveArcData();
396 arc_session_manager()->StartArc();
397 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
398
399 // Create device local account and set it as active.
400 const std::string email = "device-local-account@fake-email.com";
401 TestingProfile::Builder profile_builder;
402 profile_builder.SetProfileName(email);
403 std::unique_ptr<TestingProfile> device_local_profile(profile_builder.Build());
404 const AccountId account_id(AccountId::FromUserEmail(email));
405 GetFakeUserManager()->AddPublicAccountUser(account_id);
406
407 // Remove |profile_| to set the device local account be the primary account.
408 GetFakeUserManager()->RemoveUserFromList(
409 multi_user_util::GetAccountIdFromProfile(profile()));
410 GetFakeUserManager()->LoginUser(account_id);
411
412 // Check that user without GAIA account can't use ARC.
413 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
414 arc_session_manager()->OnPrimaryUserProfilePrepared(
415 device_local_profile.get());
416 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
417 arc_session_manager()->state());
418
419 // Correctly stop service.
420 arc_session_manager()->Shutdown();
421 }
422
423 TEST_F(ArcSessionManagerTest, DisabledForNonPrimaryProfile) {
hidehiko 2017/02/24 18:29:13 Removed. Similary, this is also tested in ChromeAr
424 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
425 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
426 arc_session_manager()->StartArc();
427 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
428
429 // Create a second profile and set it as the active profile.
430 const std::string email = "test@example.com";
431 TestingProfile::Builder profile_builder;
432 profile_builder.SetProfileName(email);
433 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build());
434 const AccountId account_id(AccountId::FromUserEmail(email));
435 GetFakeUserManager()->AddUser(account_id);
436 GetFakeUserManager()->SwitchActiveUser(account_id);
437 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
438
439 // Check that non-primary user can't use ARC.
440 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get()));
441 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get()));
442
443 arc_session_manager()->Shutdown();
444 }
445
446 TEST_F(ArcSessionManagerTest, RemoveDataFolder) {
447 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
448 // Starting session manager with prefs::kArcEnabled off automatically removes
449 // Android's data folder.
450 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
451 EXPECT_TRUE( 415 EXPECT_TRUE(
452 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 416 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
453 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, 417 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
454 arc_session_manager()->state()); 418 arc_session_manager()->state());
455 // Enable ARC. Data is removed asyncronously. At this moment session manager 419 // Enable ARC. Data is removed asyncronously. At this moment session manager
456 // should be in REMOVING_DATA_DIR state. 420 // should be in REMOVING_DATA_DIR state.
457 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 421 arc_session_manager()->RequestEnable();
458 EXPECT_TRUE( 422 EXPECT_TRUE(
459 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 423 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
460 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, 424 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
461 arc_session_manager()->state()); 425 arc_session_manager()->state());
462 // Wait until data is removed. 426 // Wait until data is removed.
463 base::RunLoop().RunUntilIdle(); 427 base::RunLoop().RunUntilIdle();
464 EXPECT_FALSE( 428 EXPECT_FALSE(
465 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 429 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
466 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 430 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
467 arc_session_manager()->state()); 431 arc_session_manager()->state());
468 arc_session_manager()->StartArc(); 432 arc_session_manager()->StartArc();
469 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 433 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
470 434
471 // Now request to remove data and stop session manager. 435 // Now request to remove data and stop session manager.
472 arc_session_manager()->RemoveArcData(); 436 arc_session_manager()->RemoveArcData();
473 ASSERT_TRUE( 437 ASSERT_TRUE(
474 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 438 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
475 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 439 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
476 arc_session_manager()->Shutdown(); 440 arc_session_manager()->Shutdown();
477 base::RunLoop().RunUntilIdle(); 441 base::RunLoop().RunUntilIdle();
478 // Request should persist. 442 // Request should persist.
479 ASSERT_TRUE( 443 ASSERT_TRUE(
480 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 444 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
445 }
481 446
482 // Emulate next sign-in. Data should be removed first and ARC started after. 447 TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) {
483 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 448 // Emulate second sign-in. Data should be removed first and ARC started after.
449 PrefService* const prefs = profile()->GetPrefs();
450 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true);
451 arc_session_manager()->SetProfile(profile());
452 arc_session_manager()->RequestEnable();
484 EXPECT_TRUE( 453 EXPECT_TRUE(
485 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 454 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
486
487 ASSERT_TRUE( 455 ASSERT_TRUE(
488 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); 456 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE));
489
490 EXPECT_FALSE( 457 EXPECT_FALSE(
491 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 458 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
492 459
493 arc_session_manager()->StartArc();
494 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
495
496 arc_session_manager()->Shutdown(); 460 arc_session_manager()->Shutdown();
497 } 461 }
498 462
499 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { 463 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) {
500 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 464 arc_session_manager()->SetProfile(profile());
501 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 465 arc_session_manager()->RequestEnable();
502 arc_session_manager()->StartArc(); 466 arc_session_manager()->StartArc();
503 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 467 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
504 468
505 // Report some failure that does not stop the bridge. 469 // Report some failure that does not stop the bridge.
506 arc_session_manager()->OnProvisioningFinished( 470 arc_session_manager()->OnProvisioningFinished(
507 ProvisioningResult::GMS_SIGN_IN_FAILED); 471 ProvisioningResult::GMS_SIGN_IN_FAILED);
508 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 472 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
509 473
510 // Try to send another error that stops the bridge if sent first. It should 474 // Try to send another error that stops the bridge if sent first. It should
511 // be ignored. 475 // be ignored.
(...skipping 30 matching lines...) Expand all
542 506
543 // Assign test values to the prefs. 507 // Assign test values to the prefs.
544 if (backup_restore_pref_value().is_bool()) { 508 if (backup_restore_pref_value().is_bool()) {
545 prefs->SetManagedPref(prefs::kArcBackupRestoreEnabled, 509 prefs->SetManagedPref(prefs::kArcBackupRestoreEnabled,
546 backup_restore_pref_value().DeepCopy()); 510 backup_restore_pref_value().DeepCopy());
547 } 511 }
548 if (location_service_pref_value().is_bool()) { 512 if (location_service_pref_value().is_bool()) {
549 prefs->SetManagedPref(prefs::kArcLocationServiceEnabled, 513 prefs->SetManagedPref(prefs::kArcLocationServiceEnabled,
550 location_service_pref_value().DeepCopy()); 514 location_service_pref_value().DeepCopy());
551 } 515 }
552
553 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
554 EXPECT_TRUE(arc::IsArcPlayStoreEnabledForProfile(profile())); 516 EXPECT_TRUE(arc::IsArcPlayStoreEnabledForProfile(profile()));
555 EXPECT_TRUE(arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); 517 EXPECT_TRUE(arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile()));
556 518
519 arc_session_manager()->SetProfile(profile());
520 arc_session_manager()->RequestEnable();
521
557 // Terms of Service are skipped if both ArcBackupRestoreEnabled and 522 // Terms of Service are skipped if both ArcBackupRestoreEnabled and
558 // ArcLocationServiceEnabled are managed. 523 // ArcLocationServiceEnabled are managed.
559 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && 524 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() &&
560 location_service_pref_value().is_bool(); 525 location_service_pref_value().is_bool();
561 EXPECT_EQ(expected_terms_skipping 526 EXPECT_EQ(expected_terms_skipping
562 ? ArcSessionManager::State::ACTIVE 527 ? ArcSessionManager::State::ACTIVE
563 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 528 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
564 arc_session_manager()->state()); 529 arc_session_manager()->state());
565 530
566 // Complete provisioning if it's not done yet. 531 // Complete provisioning if it's not done yet.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 AccountId::FromUserEmail(profile()->GetProfileUserName())); 572 AccountId::FromUserEmail(profile()->GetProfileUserName()));
608 GetFakeUserManager()->AddArcKioskAppUser(account_id); 573 GetFakeUserManager()->AddArcKioskAppUser(account_id);
609 GetFakeUserManager()->LoginUser(account_id); 574 GetFakeUserManager()->LoginUser(account_id);
610 } 575 }
611 576
612 private: 577 private:
613 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerKioskTest); 578 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerKioskTest);
614 }; 579 };
615 580
616 TEST_F(ArcSessionManagerKioskTest, AuthFailure) { 581 TEST_F(ArcSessionManagerKioskTest, AuthFailure) {
617 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 582 arc_session_manager()->SetProfile(profile());
618 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 583 arc_session_manager()->RequestEnable();
619 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 584 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
620 585
621 // Replace chrome::AttemptUserExit() for testing. 586 // Replace chrome::AttemptUserExit() for testing.
622 // At the end of test, leave the dangling pointer |terminated|, 587 // At the end of test, leave the dangling pointer |terminated|,
623 // assuming the callback is invoked exactly once in OnProvisioningFinished() 588 // assuming the callback is invoked exactly once in OnProvisioningFinished()
624 // and not invoked then, including TearDown(). 589 // and not invoked then, including TearDown().
625 bool terminated = false; 590 bool terminated = false;
626 arc_session_manager()->SetAttemptUserExitCallbackForTesting( 591 arc_session_manager()->SetAttemptUserExitCallbackForTesting(
627 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); 592 base::Bind([](bool* terminated) { *terminated = true; }, &terminated));
628 593
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 if (IsManagedUser()) { 659 if (IsManagedUser()) {
695 policy::ProfilePolicyConnector* const connector = 660 policy::ProfilePolicyConnector* const connector =
696 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( 661 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(
697 profile()); 662 profile());
698 connector->OverrideIsManagedForTesting(true); 663 connector->OverrideIsManagedForTesting(true);
699 664
700 profile()->GetTestingPrefService()->SetManagedPref( 665 profile()->GetTestingPrefService()->SetManagedPref(
701 prefs::kArcEnabled, new base::FundamentalValue(true)); 666 prefs::kArcEnabled, new base::FundamentalValue(true));
702 } 667 }
703 668
704 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 669 arc_session_manager()->SetProfile(profile());
670 arc_session_manager()->StartPreferenceHandler();
705 } 671 }
706 672
707 void TearDown() override { 673 void TearDown() override {
708 // Correctly stop service. 674 // Correctly stop service.
709 arc_session_manager()->Shutdown(); 675 arc_session_manager()->Shutdown();
710 676
711 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( 677 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting(
712 nullptr); 678 nullptr);
713 679
714 ArcSessionOobeOptInTest::TearDown(); 680 ArcSessionOobeOptInTest::TearDown();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { 719 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override {
754 observer_list_.AddObserver(observer); 720 observer_list_.AddObserver(observer);
755 } 721 }
756 722
757 void RemoveObserver( 723 void RemoveObserver(
758 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { 724 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override {
759 observer_list_.RemoveObserver(observer); 725 observer_list_.RemoveObserver(observer);
760 } 726 }
761 727
762 void Show() override { 728 void Show() override {
763 // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is 729 // To match ArcTermsOfServiceScreenHandler logic where Google Play Store
764 // set to true on showing UI. 730 // enabled preferencee is set to true on showing UI.
765 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 731 SetArcPlayStoreEnabledForProfile(profile(), true);
766 } 732 }
767 733
768 void Hide() override {} 734 void Hide() override {}
769 735
770 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver> 736 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver>
771 observer_list_; 737 observer_list_;
772 738
773 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); 739 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest);
774 }; 740 };
775 741
(...skipping 28 matching lines...) Expand all
804 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 770 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
805 arc_session_manager()->state()); 771 arc_session_manager()->state());
806 CloseLoginDisplayHost(); 772 CloseLoginDisplayHost();
807 ReportActorDestroyed(); 773 ReportActorDestroyed();
808 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 774 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
809 if (!IsManagedUser()) 775 if (!IsManagedUser())
810 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); 776 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile()));
811 } 777 }
812 778
813 } // namespace arc 779 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698