| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 230 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| 231 | 231 |
| 232 arc_session_manager()->SetProfile(profile()); | 232 arc_session_manager()->SetProfile(profile()); |
| 233 | 233 |
| 234 // By default ARC is not enabled. | 234 // By default ARC is not enabled. |
| 235 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 235 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 236 | 236 |
| 237 // Enables ARC. First time, ToS negotiation should start. | 237 // Enables ARC. First time, ToS negotiation should start. |
| 238 arc_session_manager()->RequestEnable(); | 238 arc_session_manager()->RequestEnable(); |
| 239 base::RunLoop().RunUntilIdle(); | 239 base::RunLoop().RunUntilIdle(); |
| 240 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 240 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 241 arc_session_manager()->state()); | 241 arc_session_manager()->state()); |
| 242 | 242 |
| 243 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> | 243 // TODO(hidehiko): Verify state transition from NEGOTIATING_TERMS_OF_SERVICE |
| 244 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. | 244 // -> CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. |
| 245 arc_session_manager()->StartArcForTesting(); | 245 arc_session_manager()->StartArcForTesting(); |
| 246 | 246 |
| 247 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 247 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 248 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); | 248 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); |
| 249 | 249 |
| 250 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 250 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 251 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); | 251 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 252 | 252 |
| 253 arc_session_manager()->Shutdown(); | 253 arc_session_manager()->Shutdown(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { | 256 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { |
| 257 SetArcPlayStoreEnabledForProfile(profile(), true); | 257 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 258 | 258 |
| 259 // Starts ARC. | 259 // Starts ARC. |
| 260 arc_session_manager()->SetProfile(profile()); | 260 arc_session_manager()->SetProfile(profile()); |
| 261 arc_session_manager()->RequestEnable(); | 261 arc_session_manager()->RequestEnable(); |
| 262 base::RunLoop().RunUntilIdle(); | 262 base::RunLoop().RunUntilIdle(); |
| 263 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 263 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 264 arc_session_manager()->state()); | 264 arc_session_manager()->state()); |
| 265 | 265 |
| 266 // Emulate to cancel the ToS UI (e.g. closing the window). | 266 // Emulate to cancel the ToS UI (e.g. closing the window). |
| 267 arc_session_manager()->CancelAuthCode(); | 267 arc_session_manager()->CancelAuthCode(); |
| 268 | 268 |
| 269 // Google Play Store enabled preference should be set to false, too. | 269 // Google Play Store enabled preference should be set to false, too. |
| 270 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 270 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 271 | 271 |
| 272 // Emulate the preference handling. | 272 // Emulate the preference handling. |
| 273 arc_session_manager()->RequestDisable(); | 273 arc_session_manager()->RequestDisable(); |
| 274 | 274 |
| 275 // Wait until data is removed. | 275 // Wait until data is removed. |
| 276 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); | 276 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| 277 | 277 |
| 278 // Correctly stop service. | 278 // Correctly stop service. |
| 279 arc_session_manager()->Shutdown(); | 279 arc_session_manager()->Shutdown(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { | 282 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { |
| 283 // Starts ARC. | 283 // Starts ARC. |
| 284 SetArcPlayStoreEnabledForProfile(profile(), true); | 284 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 285 arc_session_manager()->SetProfile(profile()); | 285 arc_session_manager()->SetProfile(profile()); |
| 286 arc_session_manager()->RequestEnable(); | 286 arc_session_manager()->RequestEnable(); |
| 287 base::RunLoop().RunUntilIdle(); | 287 base::RunLoop().RunUntilIdle(); |
| 288 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 288 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 289 arc_session_manager()->state()); | 289 arc_session_manager()->state()); |
| 290 arc_session_manager()->StartArcForTesting(); | 290 arc_session_manager()->StartArcForTesting(); |
| 291 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 291 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 292 | 292 |
| 293 // When ARC is properly started, closing UI should be no-op. | 293 // When ARC is properly started, closing UI should be no-op. |
| 294 arc_session_manager()->CancelAuthCode(); | 294 arc_session_manager()->CancelAuthCode(); |
| 295 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 295 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 296 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); | 296 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| 297 | 297 |
| 298 // Correctly stop service. | 298 // Correctly stop service. |
| 299 arc_session_manager()->Shutdown(); | 299 arc_session_manager()->Shutdown(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 TEST_F(ArcSessionManagerTest, Provisioning_Success) { | 302 TEST_F(ArcSessionManagerTest, Provisioning_Success) { |
| 303 PrefService* const prefs = profile()->GetPrefs(); | 303 PrefService* const prefs = profile()->GetPrefs(); |
| 304 | 304 |
| 305 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 305 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 306 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 306 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| 307 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 307 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| 308 | 308 |
| 309 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 309 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 310 | 310 |
| 311 arc_session_manager()->SetProfile(profile()); | 311 arc_session_manager()->SetProfile(profile()); |
| 312 arc_session_manager()->RequestEnable(); | 312 arc_session_manager()->RequestEnable(); |
| 313 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 313 ASSERT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 314 arc_session_manager()->state()); | 314 arc_session_manager()->state()); |
| 315 | 315 |
| 316 // Emulate to accept the terms of service. | 316 // Emulate to accept the terms of service. |
| 317 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 317 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 318 arc_session_manager()->StartArcForTesting(); | 318 arc_session_manager()->StartArcForTesting(); |
| 319 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 319 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 320 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 320 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 321 | 321 |
| 322 // Here, provisining is not yet completed, so kArcSignedIn should be false. | 322 // Here, provisining is not yet completed, so kArcSignedIn should be false. |
| 323 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 323 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // should be in REMOVING_DATA_DIR state. | 375 // should be in REMOVING_DATA_DIR state. |
| 376 arc_session_manager()->RequestEnable(); | 376 arc_session_manager()->RequestEnable(); |
| 377 EXPECT_TRUE( | 377 EXPECT_TRUE( |
| 378 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 378 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 379 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | 379 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 380 arc_session_manager()->state()); | 380 arc_session_manager()->state()); |
| 381 // Wait until data is removed. | 381 // Wait until data is removed. |
| 382 base::RunLoop().RunUntilIdle(); | 382 base::RunLoop().RunUntilIdle(); |
| 383 EXPECT_FALSE( | 383 EXPECT_FALSE( |
| 384 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 384 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 385 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 385 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 386 arc_session_manager()->state()); | 386 arc_session_manager()->state()); |
| 387 arc_session_manager()->StartArcForTesting(); | 387 arc_session_manager()->StartArcForTesting(); |
| 388 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 388 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 389 | 389 |
| 390 // Request to remove data and stop session manager. | 390 // Request to remove data and stop session manager. |
| 391 arc_session_manager()->RemoveArcData(); | 391 arc_session_manager()->RemoveArcData(); |
| 392 ASSERT_TRUE( | 392 ASSERT_TRUE( |
| 393 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 393 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 394 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 394 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 395 arc_session_manager()->Shutdown(); | 395 arc_session_manager()->Shutdown(); |
| 396 base::RunLoop().RunUntilIdle(); | 396 base::RunLoop().RunUntilIdle(); |
| 397 // Request should persist. | 397 // Request should persist. |
| 398 ASSERT_TRUE( | 398 ASSERT_TRUE( |
| 399 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 399 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 400 } | 400 } |
| 401 | 401 |
| 402 TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) { | 402 TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) { |
| 403 // Emulate second sign-in. Data should be removed first and ARC started after. | 403 // Emulate second sign-in. Data should be removed first and ARC started after. |
| 404 PrefService* const prefs = profile()->GetPrefs(); | 404 PrefService* const prefs = profile()->GetPrefs(); |
| 405 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); | 405 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| 406 arc_session_manager()->SetProfile(profile()); | 406 arc_session_manager()->SetProfile(profile()); |
| 407 arc_session_manager()->RequestEnable(); | 407 arc_session_manager()->RequestEnable(); |
| 408 EXPECT_TRUE( | 408 EXPECT_TRUE( |
| 409 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 409 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 410 ASSERT_TRUE( | 410 ASSERT_TRUE(WaitForDataRemoved( |
| 411 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); | 411 ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE)); |
| 412 EXPECT_FALSE( | 412 EXPECT_FALSE( |
| 413 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 413 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 414 | 414 |
| 415 arc_session_manager()->Shutdown(); | 415 arc_session_manager()->Shutdown(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { | 418 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { |
| 419 arc_session_manager()->SetProfile(profile()); | 419 arc_session_manager()->SetProfile(profile()); |
| 420 arc_session_manager()->RequestEnable(); | 420 arc_session_manager()->RequestEnable(); |
| 421 arc_session_manager()->StartArcForTesting(); | 421 arc_session_manager()->StartArcForTesting(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 512 |
| 513 arc_session_manager()->SetProfile(profile()); | 513 arc_session_manager()->SetProfile(profile()); |
| 514 arc_session_manager()->RequestEnable(); | 514 arc_session_manager()->RequestEnable(); |
| 515 | 515 |
| 516 // Terms of Service are skipped if both ArcBackupRestoreEnabled and | 516 // Terms of Service are skipped if both ArcBackupRestoreEnabled and |
| 517 // ArcLocationServiceEnabled are managed. | 517 // ArcLocationServiceEnabled are managed. |
| 518 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && | 518 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && |
| 519 location_service_pref_value().is_bool(); | 519 location_service_pref_value().is_bool(); |
| 520 EXPECT_EQ(expected_terms_skipping | 520 EXPECT_EQ(expected_terms_skipping |
| 521 ? ArcSessionManager::State::ACTIVE | 521 ? ArcSessionManager::State::ACTIVE |
| 522 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 522 : ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 523 arc_session_manager()->state()); | 523 arc_session_manager()->state()); |
| 524 | 524 |
| 525 // Complete provisioning if it's not done yet. | 525 // Complete provisioning if it's not done yet. |
| 526 if (!expected_terms_skipping) { | 526 if (!expected_terms_skipping) { |
| 527 arc_session_manager()->StartArcForTesting(); | 527 arc_session_manager()->StartArcForTesting(); |
| 528 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); | 528 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); |
| 529 } | 529 } |
| 530 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 530 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 531 | 531 |
| 532 // Play Store app is launched unless the Terms screen was suppressed by the | 532 // 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... |
| 722 | 722 |
| 723 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); | 723 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); |
| 724 }; | 724 }; |
| 725 | 725 |
| 726 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, | 726 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, |
| 727 ArcSessionOobeOptInNegotiatorTest, | 727 ArcSessionOobeOptInNegotiatorTest, |
| 728 ::testing::Values(true, false)); | 728 ::testing::Values(true, false)); |
| 729 | 729 |
| 730 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { | 730 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { |
| 731 view()->Show(); | 731 view()->Show(); |
| 732 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 732 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 733 arc_session_manager()->state()); | 733 arc_session_manager()->state()); |
| 734 ReportResult(true); | 734 ReportResult(true); |
| 735 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 735 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 736 } | 736 } |
| 737 | 737 |
| 738 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { | 738 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { |
| 739 view()->Show(); | 739 view()->Show(); |
| 740 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 740 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 741 arc_session_manager()->state()); | 741 arc_session_manager()->state()); |
| 742 ReportResult(false); | 742 ReportResult(false); |
| 743 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 743 // ArcPlayStoreEnabledPreferenceHandler is not running, so the state should |
| 744 // be kept as is. |
| 745 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 746 arc_session_manager()->state()); |
| 747 // Managed user's preference should not be overwritten. |
| 748 if (!IsManagedUser()) |
| 749 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 744 } | 750 } |
| 745 | 751 |
| 746 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsViewDestroyed) { | 752 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsViewDestroyed) { |
| 747 view()->Show(); | 753 view()->Show(); |
| 748 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 754 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 749 arc_session_manager()->state()); | 755 arc_session_manager()->state()); |
| 750 CloseLoginDisplayHost(); | 756 CloseLoginDisplayHost(); |
| 751 ReportViewDestroyed(); | 757 ReportViewDestroyed(); |
| 752 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 758 // ArcPlayStoreEnabledPreferenceHandler is not running, so the state should |
| 759 // be kept as is. |
| 760 EXPECT_EQ(ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, |
| 761 arc_session_manager()->state()); |
| 762 // Managed user's preference should not be overwritten. |
| 763 if (!IsManagedUser()) |
| 764 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 753 } | 765 } |
| 754 | 766 |
| 755 } // namespace arc | 767 } // namespace arc |
| OLD | NEW |