| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | 218 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 219 arc_session_manager()->state()); | 219 arc_session_manager()->state()); |
| 220 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); | 220 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 private: | 223 private: |
| 224 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); | 224 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { | |
| 228 ASSERT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | |
| 229 arc_session_manager()->SetProfile(profile()); | |
| 230 arc_session_manager()->StartPreferenceHandler(); | |
| 231 | |
| 232 EXPECT_FALSE( | |
| 233 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
| 234 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
| 235 | |
| 236 SetArcPlayStoreEnabledForProfile(profile(), true); | |
| 237 base::RunLoop().RunUntilIdle(); | |
| 238 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 239 arc_session_manager()->state()); | |
| 240 | |
| 241 SetArcPlayStoreEnabledForProfile(profile(), false); | |
| 242 | |
| 243 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); | |
| 244 | |
| 245 // Correctly stop service. | |
| 246 arc_session_manager()->Shutdown(); | |
| 247 } | |
| 248 | |
| 249 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService_Restart) { | |
| 250 // Sets the Google Play Store preference at beginning. | |
| 251 SetArcPlayStoreEnabledForProfile(profile(), true); | |
| 252 | |
| 253 arc_session_manager()->SetProfile(profile()); | |
| 254 arc_session_manager()->StartPreferenceHandler(); | |
| 255 | |
| 256 // Setting profile initiates a code fetching process. | |
| 257 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 258 arc_session_manager()->state()); | |
| 259 | |
| 260 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 261 base::RunLoop().RunUntilIdle(); | |
| 262 | |
| 263 // UI is disabled in unit tests and this code is unchanged. | |
| 264 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 265 arc_session_manager()->state()); | |
| 266 | |
| 267 // Correctly stop service. | |
| 268 arc_session_manager()->Shutdown(); | |
| 269 } | |
| 270 | |
| 271 TEST_F(ArcSessionManagerTest, BaseWorkflow) { | 227 TEST_F(ArcSessionManagerTest, BaseWorkflow) { |
| 272 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 228 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 273 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 229 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| 274 | 230 |
| 275 arc_session_manager()->SetProfile(profile()); | 231 arc_session_manager()->SetProfile(profile()); |
| 276 | 232 |
| 277 // By default ARC is not enabled. | 233 // By default ARC is not enabled. |
| 278 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 234 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 279 | 235 |
| 280 // Enables ARC. First time, ToS negotiation should start. | 236 // Enables ARC. First time, ToS negotiation should start. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 EXPECT_TRUE( | 407 EXPECT_TRUE( |
| 452 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 408 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 453 ASSERT_TRUE( | 409 ASSERT_TRUE( |
| 454 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); | 410 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); |
| 455 EXPECT_FALSE( | 411 EXPECT_FALSE( |
| 456 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 412 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 457 | 413 |
| 458 arc_session_manager()->Shutdown(); | 414 arc_session_manager()->Shutdown(); |
| 459 } | 415 } |
| 460 | 416 |
| 461 TEST_F(ArcSessionManagerTest, RemoveDataDir_Managed) { | |
| 462 // Set ARC to be managed and disabled. | |
| 463 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, | |
| 464 new base::Value(false)); | |
| 465 | |
| 466 // Starting session manager with prefs::kArcEnabled off in a managed profile | |
| 467 // does automatically remove Android's data folder. | |
| 468 arc_session_manager()->SetProfile(profile()); | |
| 469 arc_session_manager()->StartPreferenceHandler(); | |
| 470 EXPECT_TRUE( | |
| 471 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
| 472 } | |
| 473 | |
| 474 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { | 417 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { |
| 475 arc_session_manager()->SetProfile(profile()); | 418 arc_session_manager()->SetProfile(profile()); |
| 476 arc_session_manager()->RequestEnable(); | 419 arc_session_manager()->RequestEnable(); |
| 477 arc_session_manager()->StartArcForTesting(); | 420 arc_session_manager()->StartArcForTesting(); |
| 478 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 421 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 479 | 422 |
| 480 // Report some failure that does not stop the bridge. | 423 // Report some failure that does not stop the bridge. |
| 481 arc_session_manager()->OnProvisioningFinished( | 424 arc_session_manager()->OnProvisioningFinished( |
| 482 ProvisioningResult::GMS_SIGN_IN_FAILED); | 425 ProvisioningResult::GMS_SIGN_IN_FAILED); |
| 483 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 426 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 policy::ProfilePolicyConnector* const connector = | 614 policy::ProfilePolicyConnector* const connector = |
| 672 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 615 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 673 profile()); | 616 profile()); |
| 674 connector->OverrideIsManagedForTesting(true); | 617 connector->OverrideIsManagedForTesting(true); |
| 675 | 618 |
| 676 profile()->GetTestingPrefService()->SetManagedPref( | 619 profile()->GetTestingPrefService()->SetManagedPref( |
| 677 prefs::kArcEnabled, new base::FundamentalValue(true)); | 620 prefs::kArcEnabled, new base::FundamentalValue(true)); |
| 678 } | 621 } |
| 679 | 622 |
| 680 arc_session_manager()->SetProfile(profile()); | 623 arc_session_manager()->SetProfile(profile()); |
| 681 arc_session_manager()->StartPreferenceHandler(); | 624 if (IsArcPlayStoreEnabledForProfile(profile())) |
| 625 arc_session_manager()->RequestEnable(); |
| 682 } | 626 } |
| 683 | 627 |
| 684 void TearDown() override { | 628 void TearDown() override { |
| 685 // Correctly stop service. | 629 // Correctly stop service. |
| 686 arc_session_manager()->Shutdown(); | 630 arc_session_manager()->Shutdown(); |
| 687 | 631 |
| 688 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( | 632 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( |
| 689 nullptr); | 633 nullptr); |
| 690 | 634 |
| 691 ArcSessionOobeOptInTest::TearDown(); | 635 ArcSessionOobeOptInTest::TearDown(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 719 observer_list_.AddObserver(observer); | 663 observer_list_.AddObserver(observer); |
| 720 } | 664 } |
| 721 | 665 |
| 722 void RemoveObserver( | 666 void RemoveObserver( |
| 723 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { | 667 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { |
| 724 observer_list_.RemoveObserver(observer); | 668 observer_list_.RemoveObserver(observer); |
| 725 } | 669 } |
| 726 | 670 |
| 727 void Show() override { | 671 void Show() override { |
| 728 // To match ArcTermsOfServiceScreenHandler logic where Google Play Store | 672 // To match ArcTermsOfServiceScreenHandler logic where Google Play Store |
| 729 // enabled preferencee is set to true on showing UI. | 673 // enabled preferencee is set to true on showing UI, which eventually |
| 730 SetArcPlayStoreEnabledForProfile(profile(), true); | 674 // triggers to call RequestEnable(). |
| 675 arc_session_manager()->RequestEnable(); |
| 731 } | 676 } |
| 732 | 677 |
| 733 void Hide() override {} | 678 void Hide() override {} |
| 734 | 679 |
| 735 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver> | 680 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver> |
| 736 observer_list_; | 681 observer_list_; |
| 737 | 682 |
| 738 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); | 683 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); |
| 739 }; | 684 }; |
| 740 | 685 |
| 741 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, | 686 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, |
| 742 ArcSessionOobeOptInNegotiatorTest, | 687 ArcSessionOobeOptInNegotiatorTest, |
| 743 ::testing::Values(true, false)); | 688 ::testing::Values(true, false)); |
| 744 | 689 |
| 745 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { | 690 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { |
| 746 view()->Show(); | 691 view()->Show(); |
| 747 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 692 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 748 arc_session_manager()->state()); | 693 arc_session_manager()->state()); |
| 749 ReportResult(true); | 694 ReportResult(true); |
| 750 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 695 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 751 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); | |
| 752 } | 696 } |
| 753 | 697 |
| 754 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { | 698 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { |
| 755 view()->Show(); | 699 view()->Show(); |
| 756 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 700 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 757 arc_session_manager()->state()); | 701 arc_session_manager()->state()); |
| 758 ReportResult(false); | 702 ReportResult(false); |
| 759 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 703 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 760 if (!IsManagedUser()) | |
| 761 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | |
| 762 } | 704 } |
| 763 | 705 |
| 764 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsViewDestroyed) { | 706 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsViewDestroyed) { |
| 765 view()->Show(); | 707 view()->Show(); |
| 766 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 708 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 767 arc_session_manager()->state()); | 709 arc_session_manager()->state()); |
| 768 CloseLoginDisplayHost(); | 710 CloseLoginDisplayHost(); |
| 769 ReportViewDestroyed(); | 711 ReportViewDestroyed(); |
| 770 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 712 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 771 if (!IsManagedUser()) | |
| 772 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | |
| 773 } | 713 } |
| 774 | 714 |
| 775 } // namespace arc | 715 } // namespace arc |
| OLD | NEW |