Chromium Code Reviews| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/observer_list.h" | |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 18 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 18 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 19 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 20 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .h" | |
| 21 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" | |
| 22 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r.h" | |
| 23 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r_observer.h" | |
| 24 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 19 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 25 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 26 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 21 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 27 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 29 #include "chrome/browser/policy/profile_policy_connector.h" | |
| 30 #include "chrome/browser/policy/profile_policy_connector_factory.h" | |
| 23 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 31 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 33 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 26 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 34 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 27 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/base/testing_profile.h" | 36 #include "chrome/test/base/testing_profile.h" |
| 29 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
| 30 #include "chromeos/dbus/dbus_thread_manager.h" | 38 #include "chromeos/dbus/dbus_thread_manager.h" |
| 31 #include "chromeos/dbus/fake_session_manager_client.h" | 39 #include "chromeos/dbus/fake_session_manager_client.h" |
| 32 #include "components/arc/arc_service_manager.h" | 40 #include "components/arc/arc_service_manager.h" |
| 33 #include "components/arc/arc_session_runner.h" | 41 #include "components/arc/arc_session_runner.h" |
| 34 #include "components/arc/arc_util.h" | 42 #include "components/arc/arc_util.h" |
| 35 #include "components/arc/test/fake_arc_session.h" | 43 #include "components/arc/test/fake_arc_session.h" |
| 36 #include "components/prefs/pref_service.h" | 44 #include "components/prefs/pref_service.h" |
| 37 #include "components/signin/core/account_id/account_id.h" | 45 #include "components/signin/core/account_id/account_id.h" |
| 38 #include "components/sync/model/fake_sync_change_processor.h" | 46 #include "components/sync/model/fake_sync_change_processor.h" |
| 39 #include "components/sync/model/sync_error_factory_mock.h" | 47 #include "components/sync/model/sync_error_factory_mock.h" |
| 40 #include "components/sync_preferences/testing_pref_service_syncable.h" | 48 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 41 #include "components/user_manager/user_manager.h" | 49 #include "components/user_manager/user_manager.h" |
| 42 #include "components/user_manager/user_names.h" | 50 #include "components/user_manager/user_names.h" |
| 43 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
| 44 #include "content/public/test/test_browser_thread_bundle.h" | 52 #include "content/public/test/test_browser_thread_bundle.h" |
| 45 #include "google_apis/gaia/gaia_constants.h" | 53 #include "google_apis/gaia/gaia_constants.h" |
| 46 #include "google_apis/gaia/gaia_urls.h" | 54 #include "google_apis/gaia/gaia_urls.h" |
| 47 #include "net/http/http_status_code.h" | 55 #include "net/http/http_status_code.h" |
| 48 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 49 | 57 |
| 50 namespace arc { | 58 namespace arc { |
| 51 | 59 |
| 52 class ArcSessionManagerTestBase : public testing::Test { | 60 namespace { |
| 61 | |
| 62 class FakeLoginDisplayHost : public chromeos::LoginDisplayHost { | |
| 63 public: | |
| 64 FakeLoginDisplayHost() { | |
| 65 DCHECK(!chromeos::LoginDisplayHost::default_host_); | |
| 66 chromeos::LoginDisplayHost::default_host_ = this; | |
| 67 } | |
| 68 | |
| 69 ~FakeLoginDisplayHost() override { | |
| 70 DCHECK_EQ(chromeos::LoginDisplayHost::default_host_, this); | |
| 71 chromeos::LoginDisplayHost::default_host_ = nullptr; | |
| 72 } | |
| 73 | |
| 74 /// chromeos::LoginDisplayHost: | |
| 75 chromeos::LoginDisplay* CreateLoginDisplay( | |
| 76 chromeos::LoginDisplay::Delegate* delegate) override { | |
| 77 return nullptr; | |
| 78 } | |
| 79 gfx::NativeWindow GetNativeWindow() const override { return nullptr; } | |
| 80 chromeos::OobeUI* GetOobeUI() const override { return nullptr; } | |
| 81 chromeos::WebUILoginView* GetWebUILoginView() const override { | |
| 82 return nullptr; | |
| 83 } | |
| 84 void BeforeSessionStart() override {} | |
| 85 void Finalize() override {} | |
| 86 void OnCompleteLogin() override {} | |
| 87 void OpenProxySettings() override {} | |
| 88 void SetStatusAreaVisible(bool visible) override {} | |
| 89 chromeos::AutoEnrollmentController* GetAutoEnrollmentController() override { | |
| 90 return nullptr; | |
| 91 } | |
| 92 void StartWizard(chromeos::OobeScreen first_screen) override {} | |
| 93 chromeos::WizardController* GetWizardController() override { return nullptr; } | |
| 94 chromeos::AppLaunchController* GetAppLaunchController() override { | |
| 95 return nullptr; | |
| 96 } | |
| 97 void StartUserAdding(const base::Closure& completion_callback) override {} | |
| 98 void CancelUserAdding() override {} | |
| 99 void StartSignInScreen(const chromeos::LoginScreenContext& context) override { | |
| 100 } | |
| 101 void OnPreferencesChanged() override {} | |
| 102 void PrewarmAuthentication() override {} | |
| 103 void StartAppLaunch(const std::string& app_id, | |
| 104 bool diagnostic_mode, | |
| 105 bool is_auto_launch) override {} | |
| 106 void StartDemoAppLaunch() override {} | |
| 107 | |
| 108 private: | |
| 109 DISALLOW_COPY_AND_ASSIGN(FakeLoginDisplayHost); | |
| 110 }; | |
| 111 | |
| 112 } // namespace | |
| 113 | |
| 114 // Bool parameter is used to implement ArcSessionOobeOptInTest tests for | |
| 115 // managed/unmanaged users. To prevent ambiguous testing::Test inheritance | |
| 116 // implement derivation here, in base class. | |
| 117 class ArcSessionManagerTestBase : public testing::TestWithParam<bool> { | |
| 53 public: | 118 public: |
| 54 ArcSessionManagerTestBase() | 119 ArcSessionManagerTestBase() |
| 55 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 120 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 56 user_manager_enabler_(new chromeos::FakeChromeUserManager()) {} | 121 user_manager_enabler_(new chromeos::FakeChromeUserManager()) {} |
| 57 ~ArcSessionManagerTestBase() override = default; | 122 ~ArcSessionManagerTestBase() override = default; |
| 58 | 123 |
| 59 void SetUp() override { | 124 void SetUp() override { |
| 60 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 125 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 61 base::MakeUnique<chromeos::FakeSessionManagerClient>()); | 126 base::MakeUnique<chromeos::FakeSessionManagerClient>()); |
| 62 | 127 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 90 arc_service_manager_.reset(); | 155 arc_service_manager_.reset(); |
| 91 chromeos::DBusThreadManager::Shutdown(); | 156 chromeos::DBusThreadManager::Shutdown(); |
| 92 } | 157 } |
| 93 | 158 |
| 94 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 159 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 95 return static_cast<chromeos::FakeChromeUserManager*>( | 160 return static_cast<chromeos::FakeChromeUserManager*>( |
| 96 user_manager::UserManager::Get()); | 161 user_manager::UserManager::Get()); |
| 97 } | 162 } |
| 98 | 163 |
| 99 protected: | 164 protected: |
| 100 Profile* profile() { return profile_.get(); } | 165 TestingProfile* profile() { return profile_.get(); } |
| 101 | 166 |
| 102 ArcSessionManager* arc_session_manager() { | 167 ArcSessionManager* arc_session_manager() { |
| 103 return arc_session_manager_.get(); | 168 return arc_session_manager_.get(); |
| 104 } | 169 } |
| 105 | 170 |
| 106 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { | 171 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { |
| 107 if (arc_session_manager()->state() != | 172 if (arc_session_manager()->state() != |
| 108 ArcSessionManager::State::REMOVING_DATA_DIR) | 173 ArcSessionManager::State::REMOVING_DATA_DIR) |
| 109 return false; | 174 return false; |
| 110 | 175 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 // and not invoked then, including TearDown(). | 585 // and not invoked then, including TearDown(). |
| 521 bool terminated = false; | 586 bool terminated = false; |
| 522 arc_session_manager()->SetAttemptUserExitCallbackForTesting( | 587 arc_session_manager()->SetAttemptUserExitCallbackForTesting( |
| 523 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); | 588 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); |
| 524 | 589 |
| 525 arc_session_manager()->OnProvisioningFinished( | 590 arc_session_manager()->OnProvisioningFinished( |
| 526 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 591 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 527 EXPECT_TRUE(terminated); | 592 EXPECT_TRUE(terminated); |
| 528 } | 593 } |
| 529 | 594 |
| 595 class ArcSessionOobeOptInTest : public ArcSessionManagerTest { | |
| 596 public: | |
| 597 ArcSessionOobeOptInTest() = default; | |
| 598 | |
| 599 void SetUp() override { ArcSessionManagerTest::SetUp(); } | |
|
hidehiko
2017/01/31 13:55:30
nit: SetUp()/TearDown() do just calling parent met
khmel
2017/01/31 15:25:22
Done.
| |
| 600 | |
| 601 void TearDown() override { ArcSessionManagerTest::TearDown(); } | |
| 602 | |
| 603 protected: | |
| 604 void CreateLoginDisplayHost() { | |
| 605 fake_login_display_host_ = base::MakeUnique<FakeLoginDisplayHost>(); | |
| 606 } | |
| 607 | |
| 608 void CloseLoginDisplayHost() { fake_login_display_host_.reset(); } | |
| 609 | |
| 610 void AppendEnableArcOOBEOptInSwitch() { | |
| 611 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 612 chromeos::switches::kEnableArcOOBEOptIn); | |
| 613 } | |
| 614 | |
| 615 private: | |
| 616 std::unique_ptr<FakeLoginDisplayHost> fake_login_display_host_; | |
| 617 | |
| 618 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInTest); | |
| 619 }; | |
| 620 | |
| 621 TEST_F(ArcSessionOobeOptInTest, OobeOptInActive) { | |
| 622 // OOBE OptIn is Active in case of OOBE is started for new user and ARC OOBE | |
|
hidehiko
2017/01/31 13:55:30
nit: s/Active/active/
khmel
2017/01/31 15:25:22
Done.
| |
| 623 // is enabled by switch. | |
| 624 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | |
| 625 GetFakeUserManager()->set_current_user_new(true); | |
| 626 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | |
| 627 CreateLoginDisplayHost(); | |
| 628 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | |
| 629 | |
| 630 AppendEnableArcOOBEOptInSwitch(); | |
| 631 GetFakeUserManager()->set_current_user_new(false); | |
| 632 CloseLoginDisplayHost(); | |
| 633 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | |
| 634 GetFakeUserManager()->set_current_user_new(true); | |
| 635 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | |
| 636 CreateLoginDisplayHost(); | |
| 637 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive()); | |
| 638 } | |
| 639 | |
| 640 class ArcSessionOobeOptInNegotiatorTest | |
| 641 : public ArcSessionOobeOptInTest, | |
| 642 public chromeos::ArcTermsOfServiceScreenActor { | |
| 643 public: | |
| 644 ArcSessionOobeOptInNegotiatorTest() = default; | |
| 645 | |
| 646 void SetUp() override { | |
| 647 AppendEnableArcOOBEOptInSwitch(); | |
|
hidehiko
2017/01/31 13:55:30
In common practice, parent's SetUp() should be cal
khmel
2017/01/31 15:25:22
Moved down, this is not principal here. It is comm
| |
| 648 | |
| 649 ArcSessionOobeOptInTest::SetUp(); | |
| 650 | |
| 651 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( | |
| 652 this); | |
| 653 | |
| 654 GetFakeUserManager()->set_current_user_new(true); | |
| 655 | |
| 656 CreateLoginDisplayHost(); | |
| 657 | |
| 658 if (IsManagedUser()) { | |
| 659 policy::ProfilePolicyConnector* const connector = | |
| 660 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | |
| 661 profile()); | |
| 662 connector->OverrideIsManagedForTesting(true); | |
| 663 | |
| 664 profile()->GetTestingPrefService()->SetManagedPref( | |
| 665 prefs::kArcEnabled, new base::FundamentalValue(true)); | |
| 666 } | |
| 667 | |
| 668 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 669 } | |
| 670 | |
| 671 void TearDown() override { | |
| 672 // Correctly stop service. | |
| 673 arc_session_manager()->Shutdown(); | |
| 674 | |
| 675 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( | |
| 676 nullptr); | |
| 677 | |
| 678 ArcSessionOobeOptInTest::TearDown(); | |
| 679 } | |
| 680 | |
| 681 protected: | |
| 682 bool IsManagedUser() { return GetParam(); } | |
| 683 | |
| 684 void ReportResult(bool accepted) { | |
| 685 for (auto& observer : observer_list_) { | |
| 686 if (accepted) | |
| 687 observer.OnAccept(); | |
| 688 else | |
| 689 observer.OnSkip(); | |
| 690 } | |
| 691 base::RunLoop().RunUntilIdle(); | |
| 692 } | |
| 693 | |
| 694 void ReportActorDestroyed() { | |
| 695 for (auto& observer : observer_list_) | |
| 696 observer.OnActorDestroyed(this); | |
| 697 base::RunLoop().RunUntilIdle(); | |
| 698 } | |
| 699 | |
| 700 void MaybeWaitForDataRemoved() { | |
| 701 // In case of managed user we no need to wait data removal because | |
| 702 // ArcSessionManager is initialized with arc.enabled = true already and | |
| 703 // request to remove ARC data is not issued. | |
| 704 if (IsManagedUser()) | |
| 705 return; | |
| 706 | |
| 707 DCHECK_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | |
| 708 ArcSessionManager::Get()->state()); | |
| 709 ArcDataRemovedWaiter().Wait(); | |
| 710 } | |
| 711 | |
| 712 chromeos::ArcTermsOfServiceScreenActor* actor() { return this; } | |
| 713 | |
| 714 private: | |
| 715 // ArcTermsOfServiceScreenActor: | |
| 716 void AddObserver( | |
| 717 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | |
| 718 observer_list_.AddObserver(observer); | |
| 719 } | |
| 720 | |
| 721 void RemoveObserver( | |
| 722 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | |
| 723 observer_list_.RemoveObserver(observer); | |
| 724 } | |
| 725 | |
| 726 void Show() override { | |
| 727 // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is | |
| 728 // set to true on showing UI. | |
| 729 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | |
| 730 } | |
| 731 | |
| 732 void Hide() override {} | |
| 733 | |
| 734 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver> | |
| 735 observer_list_; | |
| 736 | |
| 737 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); | |
| 738 }; | |
| 739 | |
| 740 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, | |
| 741 ArcSessionOobeOptInNegotiatorTest, | |
| 742 ::testing::Values(true, false)); | |
| 743 | |
| 744 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { | |
| 745 actor()->Show(); | |
| 746 MaybeWaitForDataRemoved(); | |
| 747 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 748 arc_session_manager()->state()); | |
| 749 ReportResult(true); | |
| 750 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
| 751 EXPECT_TRUE(arc_session_manager()->IsArcEnabled()); | |
| 752 } | |
| 753 | |
| 754 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { | |
| 755 actor()->Show(); | |
| 756 MaybeWaitForDataRemoved(); | |
| 757 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 758 arc_session_manager()->state()); | |
| 759 ReportResult(false); | |
| 760 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
| 761 EXPECT_FALSE(!IsManagedUser() && arc_session_manager()->IsArcEnabled()); | |
| 762 } | |
| 763 | |
| 764 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsActorDestroyed) { | |
| 765 actor()->Show(); | |
| 766 MaybeWaitForDataRemoved(); | |
| 767 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 768 arc_session_manager()->state()); | |
| 769 CloseLoginDisplayHost(); | |
| 770 ReportActorDestroyed(); | |
| 771 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
| 772 EXPECT_FALSE(!IsManagedUser() && arc_session_manager()->IsArcEnabled()); | |
| 773 } | |
| 774 | |
| 530 } // namespace arc | 775 } // namespace arc |
| OLD | NEW |