Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager_unittest.cc

Issue 2700303002: cros: Unify oobe View/Actor naming to just View. (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/arc_util.h" 23 #include "chrome/browser/chromeos/arc/arc_util.h"
24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .h" 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .h"
25 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" 25 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h"
26 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r.h" 26 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_view .h"
27 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r_observer.h" 27 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_view _observer.h"
28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
29 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 29 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
31 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 31 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
32 #include "chrome/browser/chromeos/profiles/profile_helper.h" 32 #include "chrome/browser/chromeos/profiles/profile_helper.h"
33 #include "chrome/browser/policy/profile_policy_connector.h" 33 #include "chrome/browser/policy/profile_policy_connector.h"
34 #include "chrome/browser/policy/profile_policy_connector_factory.h" 34 #include "chrome/browser/policy/profile_policy_connector_factory.h"
35 #include "chrome/browser/prefs/pref_service_syncable_util.h" 35 #include "chrome/browser/prefs/pref_service_syncable_util.h"
36 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 37 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 CloseLoginDisplayHost(); 667 CloseLoginDisplayHost();
668 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); 668 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive());
669 GetFakeUserManager()->set_current_user_new(true); 669 GetFakeUserManager()->set_current_user_new(true);
670 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); 670 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive());
671 CreateLoginDisplayHost(); 671 CreateLoginDisplayHost();
672 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive()); 672 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive());
673 } 673 }
674 674
675 class ArcSessionOobeOptInNegotiatorTest 675 class ArcSessionOobeOptInNegotiatorTest
676 : public ArcSessionOobeOptInTest, 676 : public ArcSessionOobeOptInTest,
677 public chromeos::ArcTermsOfServiceScreenActor, 677 public chromeos::ArcTermsOfServiceScreenView,
678 public testing::WithParamInterface<bool> { 678 public testing::WithParamInterface<bool> {
679 public: 679 public:
680 ArcSessionOobeOptInNegotiatorTest() = default; 680 ArcSessionOobeOptInNegotiatorTest() = default;
681 681
682 void SetUp() override { 682 void SetUp() override {
683 ArcSessionOobeOptInTest::SetUp(); 683 ArcSessionOobeOptInTest::SetUp();
684 684
685 AppendEnableArcOOBEOptInSwitch(); 685 AppendEnableArcOOBEOptInSwitch();
686 686
687 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( 687 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting(
688 this); 688 this);
689 689
690 GetFakeUserManager()->set_current_user_new(true); 690 GetFakeUserManager()->set_current_user_new(true);
691 691
692 CreateLoginDisplayHost(); 692 CreateLoginDisplayHost();
693 693
694 if (IsManagedUser()) { 694 if (IsManagedUser()) {
695 policy::ProfilePolicyConnector* const connector = 695 policy::ProfilePolicyConnector* const connector =
696 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( 696 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(
697 profile()); 697 profile());
698 connector->OverrideIsManagedForTesting(true); 698 connector->OverrideIsManagedForTesting(true);
699 699
700 profile()->GetTestingPrefService()->SetManagedPref( 700 profile()->GetTestingPrefService()->SetManagedPref(
701 prefs::kArcEnabled, new base::FundamentalValue(true)); 701 prefs::kArcEnabled, new base::FundamentalValue(true));
702 } 702 }
703 703
704 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 704 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
705 } 705 }
706 706
707 void TearDown() override { 707 void TearDown() override {
708 // Correctly stop service. 708 // Correctly stop service.
709 arc_session_manager()->Shutdown(); 709 arc_session_manager()->Shutdown();
710 710
711 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( 711 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting(
712 nullptr); 712 nullptr);
713 713
714 ArcSessionOobeOptInTest::TearDown(); 714 ArcSessionOobeOptInTest::TearDown();
715 } 715 }
716 716
717 protected: 717 protected:
718 bool IsManagedUser() { return GetParam(); } 718 bool IsManagedUser() { return GetParam(); }
719 719
720 void ReportResult(bool accepted) { 720 void ReportResult(bool accepted) {
721 for (auto& observer : observer_list_) { 721 for (auto& observer : observer_list_) {
722 if (accepted) 722 if (accepted)
723 observer.OnAccept(); 723 observer.OnAccept();
724 else 724 else
725 observer.OnSkip(); 725 observer.OnSkip();
726 } 726 }
727 base::RunLoop().RunUntilIdle(); 727 base::RunLoop().RunUntilIdle();
728 } 728 }
729 729
730 void ReportActorDestroyed() { 730 void ReportViewDestroyed() {
731 for (auto& observer : observer_list_) 731 for (auto& observer : observer_list_)
732 observer.OnActorDestroyed(this); 732 observer.OnViewDestroyed(this);
733 base::RunLoop().RunUntilIdle(); 733 base::RunLoop().RunUntilIdle();
734 } 734 }
735 735
736 void MaybeWaitForDataRemoved() { 736 void MaybeWaitForDataRemoved() {
737 // In case of managed user we no need to wait data removal because 737 // In case of managed user we no need to wait data removal because
738 // ArcSessionManager is initialized with arc.enabled = true already and 738 // ArcSessionManager is initialized with arc.enabled = true already and
739 // request to remove ARC data is not issued. 739 // request to remove ARC data is not issued.
740 if (IsManagedUser()) 740 if (IsManagedUser())
741 return; 741 return;
742 742
743 DCHECK_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, 743 DCHECK_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
744 ArcSessionManager::Get()->state()); 744 ArcSessionManager::Get()->state());
745 ArcDataRemovedWaiter().Wait(); 745 ArcDataRemovedWaiter().Wait();
746 } 746 }
747 747
748 chromeos::ArcTermsOfServiceScreenActor* actor() { return this; } 748 chromeos::ArcTermsOfServiceScreenView* view() { return this; }
749 749
750 private: 750 private:
751 // ArcTermsOfServiceScreenActor: 751 // ArcTermsOfServiceScreenView:
752 void AddObserver( 752 void AddObserver(
753 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { 753 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override {
754 observer_list_.AddObserver(observer); 754 observer_list_.AddObserver(observer);
755 } 755 }
756 756
757 void RemoveObserver( 757 void RemoveObserver(
758 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { 758 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override {
759 observer_list_.RemoveObserver(observer); 759 observer_list_.RemoveObserver(observer);
760 } 760 }
761 761
762 void Show() override { 762 void Show() override {
763 // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is 763 // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is
764 // set to true on showing UI. 764 // set to true on showing UI.
765 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 765 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
766 } 766 }
767 767
768 void Hide() override {} 768 void Hide() override {}
769 769
770 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver> 770 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver>
771 observer_list_; 771 observer_list_;
772 772
773 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); 773 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest);
774 }; 774 };
775 775
776 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, 776 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl,
777 ArcSessionOobeOptInNegotiatorTest, 777 ArcSessionOobeOptInNegotiatorTest,
778 ::testing::Values(true, false)); 778 ::testing::Values(true, false));
779 779
780 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { 780 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) {
781 actor()->Show(); 781 view()->Show();
782 MaybeWaitForDataRemoved(); 782 MaybeWaitForDataRemoved();
783 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 783 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
784 arc_session_manager()->state()); 784 arc_session_manager()->state());
785 ReportResult(true); 785 ReportResult(true);
786 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 786 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
787 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); 787 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile()));
788 } 788 }
789 789
790 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) { 790 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsRejected) {
791 actor()->Show(); 791 view()->Show();
792 MaybeWaitForDataRemoved(); 792 MaybeWaitForDataRemoved();
793 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 793 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
794 arc_session_manager()->state()); 794 arc_session_manager()->state());
795 ReportResult(false); 795 ReportResult(false);
796 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 796 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
797 if (!IsManagedUser()) 797 if (!IsManagedUser())
798 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); 798 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile()));
799 } 799 }
800 800
801 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsActorDestroyed) { 801 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsViewDestroyed) {
802 actor()->Show(); 802 view()->Show();
803 MaybeWaitForDataRemoved(); 803 MaybeWaitForDataRemoved();
804 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 804 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
805 arc_session_manager()->state()); 805 arc_session_manager()->state());
806 CloseLoginDisplayHost(); 806 CloseLoginDisplayHost();
807 ReportActorDestroyed(); 807 ReportViewDestroyed();
808 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 808 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
809 if (!IsManagedUser()) 809 if (!IsManagedUser())
810 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); 810 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile()));
811 } 811 }
812 812
813 } // namespace arc 813 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698