OLD | NEW |
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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 229 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
230 | 230 |
231 arc_session_manager()->SetProfile(profile()); | 231 arc_session_manager()->SetProfile(profile()); |
232 | 232 |
233 // By default ARC is not enabled. | 233 // By default ARC is not enabled. |
234 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 234 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
235 | 235 |
236 // Enables ARC. First time, ToS negotiation should start. | 236 // Enables ARC. First time, ToS negotiation should start. |
237 arc_session_manager()->RequestEnable(); | 237 arc_session_manager()->RequestEnable(); |
238 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
239 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 239 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
240 arc_session_manager()->state()); | 240 arc_session_manager()->state()); |
241 | 241 |
242 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> | 242 // TODO(hidehiko): Verify state transition from NEGOTIATING_TERMS_OF_SERVICE |
243 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. | 243 // -> CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. |
244 arc_session_manager()->StartArcForTesting(); | 244 arc_session_manager()->StartArcForTesting(); |
245 | 245 |
246 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 246 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
247 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); | 247 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); |
248 | 248 |
249 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 249 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
250 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); | 250 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); |
251 | 251 |
252 arc_session_manager()->Shutdown(); | 252 arc_session_manager()->Shutdown(); |
253 } | 253 } |
254 | 254 |
255 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { | 255 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { |
256 SetArcPlayStoreEnabledForProfile(profile(), true); | 256 SetArcPlayStoreEnabledForProfile(profile(), true); |
257 | 257 |
258 // Starts ARC. | 258 // Starts ARC. |
259 arc_session_manager()->SetProfile(profile()); | 259 arc_session_manager()->SetProfile(profile()); |
260 arc_session_manager()->RequestEnable(); | 260 arc_session_manager()->RequestEnable(); |
261 base::RunLoop().RunUntilIdle(); | 261 base::RunLoop().RunUntilIdle(); |
262 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 262 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
263 arc_session_manager()->state()); | 263 arc_session_manager()->state()); |
264 | 264 |
265 // Emulate to cancel the ToS UI (e.g. closing the window). | 265 // Emulate to cancel the ToS UI (e.g. closing the window). |
266 arc_session_manager()->CancelAuthCode(); | 266 arc_session_manager()->CancelAuthCode(); |
267 | 267 |
268 // Google Play Store enabled preference should be set to false, too. | 268 // Google Play Store enabled preference should be set to false, too. |
269 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 269 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
270 | 270 |
271 // Emulate the preference handling. | 271 // Emulate the preference handling. |
272 arc_session_manager()->RequestDisable(); | 272 arc_session_manager()->RequestDisable(); |
273 | 273 |
274 // Wait until data is removed. | 274 // Wait until data is removed. |
275 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); | 275 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
276 | 276 |
277 // Correctly stop service. | 277 // Correctly stop service. |
278 arc_session_manager()->Shutdown(); | 278 arc_session_manager()->Shutdown(); |
279 } | 279 } |
280 | 280 |
281 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { | 281 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { |
282 // Starts ARC. | 282 // Starts ARC. |
283 SetArcPlayStoreEnabledForProfile(profile(), true); | 283 SetArcPlayStoreEnabledForProfile(profile(), true); |
284 arc_session_manager()->SetProfile(profile()); | 284 arc_session_manager()->SetProfile(profile()); |
285 arc_session_manager()->RequestEnable(); | 285 arc_session_manager()->RequestEnable(); |
286 base::RunLoop().RunUntilIdle(); | 286 base::RunLoop().RunUntilIdle(); |
287 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 287 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
288 arc_session_manager()->state()); | 288 arc_session_manager()->state()); |
289 arc_session_manager()->StartArcForTesting(); | 289 arc_session_manager()->StartArcForTesting(); |
290 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 290 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
291 | 291 |
292 // When ARC is properly started, closing UI should be no-op. | 292 // When ARC is properly started, closing UI should be no-op. |
293 arc_session_manager()->CancelAuthCode(); | 293 arc_session_manager()->CancelAuthCode(); |
294 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 294 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
295 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); | 295 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
296 | 296 |
297 // Correctly stop service. | 297 // Correctly stop service. |
298 arc_session_manager()->Shutdown(); | 298 arc_session_manager()->Shutdown(); |
299 } | 299 } |
300 | 300 |
301 TEST_F(ArcSessionManagerTest, Provisioning_Success) { | 301 TEST_F(ArcSessionManagerTest, Provisioning_Success) { |
302 PrefService* const prefs = profile()->GetPrefs(); | 302 PrefService* const prefs = profile()->GetPrefs(); |
303 | 303 |
304 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 304 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
305 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 305 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
306 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 306 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
307 | 307 |
308 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 308 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
309 | 309 |
310 arc_session_manager()->SetProfile(profile()); | 310 arc_session_manager()->SetProfile(profile()); |
311 arc_session_manager()->RequestEnable(); | 311 arc_session_manager()->RequestEnable(); |
312 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 312 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
313 arc_session_manager()->state()); | 313 arc_session_manager()->state()); |
314 | 314 |
315 // Emulate to accept the terms of service. | 315 // Emulate to accept the terms of service. |
316 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 316 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
317 arc_session_manager()->StartArcForTesting(); | 317 arc_session_manager()->StartArcForTesting(); |
318 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 318 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
319 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 319 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
320 | 320 |
321 // Here, provisining is not yet completed, so kArcSignedIn should be false. | 321 // Here, provisining is not yet completed, so kArcSignedIn should be false. |
322 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 322 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 // should be in REMOVING_DATA_DIR state. | 374 // should be in REMOVING_DATA_DIR state. |
375 arc_session_manager()->RequestEnable(); | 375 arc_session_manager()->RequestEnable(); |
376 EXPECT_TRUE( | 376 EXPECT_TRUE( |
377 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 377 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
378 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | 378 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
379 arc_session_manager()->state()); | 379 arc_session_manager()->state()); |
380 // Wait until data is removed. | 380 // Wait until data is removed. |
381 base::RunLoop().RunUntilIdle(); | 381 base::RunLoop().RunUntilIdle(); |
382 EXPECT_FALSE( | 382 EXPECT_FALSE( |
383 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 383 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
384 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 384 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
385 arc_session_manager()->state()); | 385 arc_session_manager()->state()); |
386 arc_session_manager()->StartArcForTesting(); | 386 arc_session_manager()->StartArcForTesting(); |
387 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 387 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
388 | 388 |
389 // Request to remove data and stop session manager. | 389 // Request to remove data and stop session manager. |
390 arc_session_manager()->RemoveArcData(); | 390 arc_session_manager()->RemoveArcData(); |
391 ASSERT_TRUE( | 391 ASSERT_TRUE( |
392 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 392 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
393 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 393 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
394 arc_session_manager()->Shutdown(); | 394 arc_session_manager()->Shutdown(); |
395 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
396 // Request should persist. | 396 // Request should persist. |
397 ASSERT_TRUE( | 397 ASSERT_TRUE( |
398 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 398 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
399 } | 399 } |
400 | 400 |
401 TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) { | 401 TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) { |
402 // Emulate second sign-in. Data should be removed first and ARC started after. | 402 // Emulate second sign-in. Data should be removed first and ARC started after. |
403 PrefService* const prefs = profile()->GetPrefs(); | 403 PrefService* const prefs = profile()->GetPrefs(); |
404 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); | 404 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); |
405 arc_session_manager()->SetProfile(profile()); | 405 arc_session_manager()->SetProfile(profile()); |
406 arc_session_manager()->RequestEnable(); | 406 arc_session_manager()->RequestEnable(); |
407 EXPECT_TRUE( | 407 EXPECT_TRUE( |
408 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 408 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
409 ASSERT_TRUE( | 409 ASSERT_TRUE(WaitForDataRemoved( |
410 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); | 410 ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE)); |
411 EXPECT_FALSE( | 411 EXPECT_FALSE( |
412 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 412 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
413 | 413 |
414 arc_session_manager()->Shutdown(); | 414 arc_session_manager()->Shutdown(); |
415 } | 415 } |
416 | 416 |
417 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { | 417 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { |
418 arc_session_manager()->SetProfile(profile()); | 418 arc_session_manager()->SetProfile(profile()); |
419 arc_session_manager()->RequestEnable(); | 419 arc_session_manager()->RequestEnable(); |
420 arc_session_manager()->StartArcForTesting(); | 420 arc_session_manager()->StartArcForTesting(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 472 |
473 arc_session_manager()->SetProfile(profile()); | 473 arc_session_manager()->SetProfile(profile()); |
474 arc_session_manager()->RequestEnable(); | 474 arc_session_manager()->RequestEnable(); |
475 | 475 |
476 // Terms of Service are skipped if both ArcBackupRestoreEnabled and | 476 // Terms of Service are skipped if both ArcBackupRestoreEnabled and |
477 // ArcLocationServiceEnabled are managed. | 477 // ArcLocationServiceEnabled are managed. |
478 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && | 478 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && |
479 location_service_pref_value().is_bool(); | 479 location_service_pref_value().is_bool(); |
480 EXPECT_EQ(expected_terms_skipping | 480 EXPECT_EQ(expected_terms_skipping |
481 ? ArcSessionManager::State::ACTIVE | 481 ? ArcSessionManager::State::ACTIVE |
482 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 482 : ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
483 arc_session_manager()->state()); | 483 arc_session_manager()->state()); |
484 | 484 |
485 // Complete provisioning if it's not done yet. | 485 // Complete provisioning if it's not done yet. |
486 if (!expected_terms_skipping) { | 486 if (!expected_terms_skipping) { |
487 arc_session_manager()->StartArcForTesting(); | 487 arc_session_manager()->StartArcForTesting(); |
488 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); | 488 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); |
489 } | 489 } |
490 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 490 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
491 | 491 |
492 // Play Store app is launched unless the Terms screen was suppressed by the | 492 // Play Store app is launched unless the Terms screen was suppressed by the |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 | 682 |
683 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); | 683 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); |
684 }; | 684 }; |
685 | 685 |
686 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, | 686 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, |
687 ArcSessionOobeOptInNegotiatorTest, | 687 ArcSessionOobeOptInNegotiatorTest, |
688 ::testing::Values(true, false)); | 688 ::testing::Values(true, false)); |
689 | 689 |
690 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { | 690 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { |
691 view()->Show(); | 691 view()->Show(); |
692 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 692 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
693 arc_session_manager()->state()); | 693 arc_session_manager()->state()); |
694 ReportResult(true); | 694 ReportResult(true); |
695 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 695 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
696 } | 696 } |
697 | 697 |
698 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { | 698 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { |
699 view()->Show(); | 699 view()->Show(); |
700 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 700 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
701 arc_session_manager()->state()); | 701 arc_session_manager()->state()); |
702 ReportResult(false); | 702 ReportResult(false); |
703 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 703 // ArcPlayStoreEnabledPreferenceHandler is not running, so the state should |
| 704 // be kept as is. |
| 705 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 706 arc_session_manager()->state()); |
| 707 // Managed user's preference should not be overwritten. |
| 708 if (!IsManagedUser()) |
| 709 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
704 } | 710 } |
705 | 711 |
706 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsViewDestroyed) { | 712 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsViewDestroyed) { |
707 view()->Show(); | 713 view()->Show(); |
708 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 714 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
709 arc_session_manager()->state()); | 715 arc_session_manager()->state()); |
710 CloseLoginDisplayHost(); | 716 CloseLoginDisplayHost(); |
711 ReportViewDestroyed(); | 717 ReportViewDestroyed(); |
712 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 718 // ArcPlayStoreEnabledPreferenceHandler is not running, so the state should |
| 719 // be kept as is. |
| 720 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 721 arc_session_manager()->state()); |
| 722 // Managed user's preference should not be overwritten. |
| 723 if (!IsManagedUser()) |
| 724 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
713 } | 725 } |
714 | 726 |
715 } // namespace arc | 727 } // namespace arc |
OLD | NEW |