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 <tuple> | 7 #include <tuple> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 22 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 22 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 23 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .h" | 23 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .h" |
| 24 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" | 24 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" |
| 25 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r.h" | 25 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_view .h" |
| 26 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r_observer.h" | 26 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_view _observer.h" |
| 27 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 27 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 28 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 28 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 29 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 29 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 30 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 30 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 32 #include "chrome/browser/policy/profile_policy_connector.h" | 32 #include "chrome/browser/policy/profile_policy_connector.h" |
| 33 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 33 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 34 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 34 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 36 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 CloseLoginDisplayHost(); | 710 CloseLoginDisplayHost(); |
| 711 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | 711 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); |
| 712 GetFakeUserManager()->set_current_user_new(true); | 712 GetFakeUserManager()->set_current_user_new(true); |
| 713 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | 713 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); |
| 714 CreateLoginDisplayHost(); | 714 CreateLoginDisplayHost(); |
| 715 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive()); | 715 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive()); |
| 716 } | 716 } |
| 717 | 717 |
| 718 class ArcSessionOobeOptInNegotiatorTest | 718 class ArcSessionOobeOptInNegotiatorTest |
| 719 : public ArcSessionOobeOptInTest, | 719 : public ArcSessionOobeOptInTest, |
| 720 public chromeos::ArcTermsOfServiceScreenActor, | 720 public chromeos::ArcTermsOfServiceScreenView, |
| 721 public testing::WithParamInterface<bool> { | 721 public testing::WithParamInterface<bool> { |
| 722 public: | 722 public: |
| 723 ArcSessionOobeOptInNegotiatorTest() = default; | 723 ArcSessionOobeOptInNegotiatorTest() = default; |
| 724 | 724 |
| 725 void SetUp() override { | 725 void SetUp() override { |
| 726 ArcSessionOobeOptInTest::SetUp(); | 726 ArcSessionOobeOptInTest::SetUp(); |
| 727 | 727 |
| 728 AppendEnableArcOOBEOptInSwitch(); | 728 AppendEnableArcOOBEOptInSwitch(); |
| 729 | 729 |
| 730 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( | 730 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( |
|
hidehiko
2017/02/23 05:34:07
s/Actor/View, too?
jdufault
2017/02/24 00:40:15
Done.
| |
| 731 this); | 731 this); |
| 732 | 732 |
| 733 GetFakeUserManager()->set_current_user_new(true); | 733 GetFakeUserManager()->set_current_user_new(true); |
| 734 | 734 |
| 735 CreateLoginDisplayHost(); | 735 CreateLoginDisplayHost(); |
| 736 | 736 |
| 737 if (IsManagedUser()) { | 737 if (IsManagedUser()) { |
| 738 policy::ProfilePolicyConnector* const connector = | 738 policy::ProfilePolicyConnector* const connector = |
| 739 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 739 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 740 profile()); | 740 profile()); |
| 741 connector->OverrideIsManagedForTesting(true); | 741 connector->OverrideIsManagedForTesting(true); |
| 742 | 742 |
| 743 profile()->GetTestingPrefService()->SetManagedPref( | 743 profile()->GetTestingPrefService()->SetManagedPref( |
| 744 prefs::kArcEnabled, new base::FundamentalValue(true)); | 744 prefs::kArcEnabled, new base::FundamentalValue(true)); |
| 745 } | 745 } |
| 746 | 746 |
| 747 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 747 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 748 } | 748 } |
| 749 | 749 |
| 750 void TearDown() override { | 750 void TearDown() override { |
| 751 // Correctly stop service. | 751 // Correctly stop service. |
| 752 arc_session_manager()->Shutdown(); | 752 arc_session_manager()->Shutdown(); |
| 753 | 753 |
| 754 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( | 754 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( |
|
hidehiko
2017/02/23 05:34:07
ditto.
jdufault
2017/02/24 00:40:15
Done.
| |
| 755 nullptr); | 755 nullptr); |
| 756 | 756 |
| 757 ArcSessionOobeOptInTest::TearDown(); | 757 ArcSessionOobeOptInTest::TearDown(); |
| 758 } | 758 } |
| 759 | 759 |
| 760 protected: | 760 protected: |
| 761 bool IsManagedUser() { return GetParam(); } | 761 bool IsManagedUser() { return GetParam(); } |
| 762 | 762 |
| 763 void ReportResult(bool accepted) { | 763 void ReportResult(bool accepted) { |
| 764 for (auto& observer : observer_list_) { | 764 for (auto& observer : observer_list_) { |
| 765 if (accepted) | 765 if (accepted) |
| 766 observer.OnAccept(); | 766 observer.OnAccept(); |
| 767 else | 767 else |
| 768 observer.OnSkip(); | 768 observer.OnSkip(); |
| 769 } | 769 } |
| 770 base::RunLoop().RunUntilIdle(); | 770 base::RunLoop().RunUntilIdle(); |
| 771 } | 771 } |
| 772 | 772 |
| 773 void ReportActorDestroyed() { | 773 void ReportActorDestroyed() { |
|
hidehiko
2017/02/23 05:34:07
s/Actor/View/ here, too?
jdufault
2017/02/24 00:40:15
Done.
| |
| 774 for (auto& observer : observer_list_) | 774 for (auto& observer : observer_list_) |
| 775 observer.OnActorDestroyed(this); | 775 observer.OnViewDestroyed(this); |
| 776 base::RunLoop().RunUntilIdle(); | 776 base::RunLoop().RunUntilIdle(); |
| 777 } | 777 } |
| 778 | 778 |
| 779 void MaybeWaitForDataRemoved() { | 779 void MaybeWaitForDataRemoved() { |
| 780 // In case of managed user we no need to wait data removal because | 780 // In case of managed user we no need to wait data removal because |
| 781 // ArcSessionManager is initialized with arc.enabled = true already and | 781 // ArcSessionManager is initialized with arc.enabled = true already and |
| 782 // request to remove ARC data is not issued. | 782 // request to remove ARC data is not issued. |
| 783 if (IsManagedUser()) | 783 if (IsManagedUser()) |
| 784 return; | 784 return; |
| 785 | 785 |
| 786 DCHECK_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | 786 DCHECK_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 787 ArcSessionManager::Get()->state()); | 787 ArcSessionManager::Get()->state()); |
| 788 ArcDataRemovedWaiter().Wait(); | 788 ArcDataRemovedWaiter().Wait(); |
| 789 } | 789 } |
| 790 | 790 |
| 791 chromeos::ArcTermsOfServiceScreenActor* actor() { return this; } | 791 chromeos::ArcTermsOfServiceScreenView* view() { return this; } |
| 792 | 792 |
| 793 private: | 793 private: |
| 794 // ArcTermsOfServiceScreenActor: | 794 // ArcTermsOfServiceScreenView: |
| 795 void AddObserver( | 795 void AddObserver( |
| 796 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | 796 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { |
| 797 observer_list_.AddObserver(observer); | 797 observer_list_.AddObserver(observer); |
| 798 } | 798 } |
| 799 | 799 |
| 800 void RemoveObserver( | 800 void RemoveObserver( |
| 801 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | 801 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { |
| 802 observer_list_.RemoveObserver(observer); | 802 observer_list_.RemoveObserver(observer); |
| 803 } | 803 } |
| 804 | 804 |
| 805 void Show() override { | 805 void Show() override { |
| 806 // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is | 806 // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is |
| 807 // set to true on showing UI. | 807 // set to true on showing UI. |
| 808 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 808 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 809 } | 809 } |
| 810 | 810 |
| 811 void Hide() override {} | 811 void Hide() override {} |
| 812 | 812 |
| 813 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver> | 813 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver> |
| 814 observer_list_; | 814 observer_list_; |
| 815 | 815 |
| 816 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); | 816 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); |
| 817 }; | 817 }; |
| 818 | 818 |
| 819 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, | 819 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, |
| 820 ArcSessionOobeOptInNegotiatorTest, | 820 ArcSessionOobeOptInNegotiatorTest, |
| 821 ::testing::Values(true, false)); | 821 ::testing::Values(true, false)); |
| 822 | 822 |
| 823 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { | 823 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { |
| 824 actor()->Show(); | 824 view()->Show(); |
| 825 MaybeWaitForDataRemoved(); | 825 MaybeWaitForDataRemoved(); |
| 826 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 826 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 827 arc_session_manager()->state()); | 827 arc_session_manager()->state()); |
| 828 ReportResult(true); | 828 ReportResult(true); |
| 829 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 829 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 830 EXPECT_TRUE(arc_session_manager()->IsArcPlayStoreEnabled()); | 830 EXPECT_TRUE(arc_session_manager()->IsArcPlayStoreEnabled()); |
| 831 } | 831 } |
| 832 | 832 |
| 833 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { | 833 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { |
| 834 actor()->Show(); | 834 view()->Show(); |
| 835 MaybeWaitForDataRemoved(); | 835 MaybeWaitForDataRemoved(); |
| 836 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 836 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 837 arc_session_manager()->state()); | 837 arc_session_manager()->state()); |
| 838 ReportResult(false); | 838 ReportResult(false); |
| 839 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 839 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 840 EXPECT_FALSE(!IsManagedUser() && | 840 EXPECT_FALSE(!IsManagedUser() && |
| 841 arc_session_manager()->IsArcPlayStoreEnabled()); | 841 arc_session_manager()->IsArcPlayStoreEnabled()); |
| 842 } | 842 } |
| 843 | 843 |
| 844 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsActorDestroyed) { | 844 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsActorDestroyed) { |
|
hidehiko
2017/02/23 05:34:07
s/Actor/View/ too_
jdufault
2017/02/24 00:40:15
Done.
| |
| 845 actor()->Show(); | 845 view()->Show(); |
| 846 MaybeWaitForDataRemoved(); | 846 MaybeWaitForDataRemoved(); |
| 847 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 847 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 848 arc_session_manager()->state()); | 848 arc_session_manager()->state()); |
| 849 CloseLoginDisplayHost(); | 849 CloseLoginDisplayHost(); |
| 850 ReportActorDestroyed(); | 850 ReportActorDestroyed(); |
| 851 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 851 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 852 EXPECT_FALSE(!IsManagedUser() && | 852 EXPECT_FALSE(!IsManagedUser() && |
| 853 arc_session_manager()->IsArcPlayStoreEnabled()); | 853 arc_session_manager()->IsArcPlayStoreEnabled()); |
| 854 } | 854 } |
| 855 | 855 |
| 856 } // namespace arc | 856 } // namespace arc |
| OLD | NEW |