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 _for_managed_user.h" | |
| 21 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r.h" | |
| 22 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r_observer.h" | |
| 19 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 23 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 24 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 21 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 25 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 26 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 27 #include "chrome/browser/policy/profile_policy_connector.h" | |
| 28 #include "chrome/browser/policy/profile_policy_connector_factory.h" | |
| 23 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 29 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 31 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 26 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 32 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 27 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
| 29 #include "chromeos/chromeos_switches.h" | 35 #include "chromeos/chromeos_switches.h" |
| 30 #include "chromeos/dbus/dbus_thread_manager.h" | 36 #include "chromeos/dbus/dbus_thread_manager.h" |
| 31 #include "chromeos/dbus/fake_session_manager_client.h" | 37 #include "chromeos/dbus/fake_session_manager_client.h" |
| 32 #include "components/arc/arc_bridge_service.h" | 38 #include "components/arc/arc_bridge_service.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 arc_service_manager_.reset(); | 97 arc_service_manager_.reset(); |
| 92 chromeos::DBusThreadManager::Shutdown(); | 98 chromeos::DBusThreadManager::Shutdown(); |
| 93 } | 99 } |
| 94 | 100 |
| 95 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 101 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 96 return static_cast<chromeos::FakeChromeUserManager*>( | 102 return static_cast<chromeos::FakeChromeUserManager*>( |
| 97 user_manager::UserManager::Get()); | 103 user_manager::UserManager::Get()); |
| 98 } | 104 } |
| 99 | 105 |
| 100 protected: | 106 protected: |
| 101 Profile* profile() { return profile_.get(); } | 107 TestingProfile* profile() { return profile_.get(); } |
| 102 FakeArcBridgeService* bridge_service() { | 108 FakeArcBridgeService* bridge_service() { |
| 103 return static_cast<FakeArcBridgeService*>( | 109 return static_cast<FakeArcBridgeService*>( |
| 104 arc_service_manager_->arc_bridge_service()); | 110 arc_service_manager_->arc_bridge_service()); |
| 105 } | 111 } |
| 106 ArcSessionManager* arc_session_manager() { | 112 ArcSessionManager* arc_session_manager() { |
| 107 return arc_session_manager_.get(); | 113 return arc_session_manager_.get(); |
| 108 } | 114 } |
| 109 | 115 |
| 110 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { | 116 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { |
| 111 if (arc_session_manager()->state() != | 117 if (arc_session_manager()->state() != |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 // and not invoked then, including TearDown(). | 530 // and not invoked then, including TearDown(). |
| 525 bool terminated = false; | 531 bool terminated = false; |
| 526 arc_session_manager()->SetAttemptUserExitCallbackForTesting( | 532 arc_session_manager()->SetAttemptUserExitCallbackForTesting( |
| 527 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); | 533 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); |
| 528 | 534 |
| 529 arc_session_manager()->OnProvisioningFinished( | 535 arc_session_manager()->OnProvisioningFinished( |
| 530 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 536 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 531 EXPECT_TRUE(terminated); | 537 EXPECT_TRUE(terminated); |
| 532 } | 538 } |
| 533 | 539 |
| 540 class ArcSessionOobeManagedUserTest | |
| 541 : public ArcSessionManagerTest, | |
| 542 public chromeos::ArcTermsOfServiceScreenActor { | |
| 543 public: | |
| 544 ArcSessionOobeManagedUserTest() = default; | |
| 545 | |
| 546 void SetUp() override { | |
| 547 ArcSessionManagerTest::SetUp(); | |
| 548 | |
| 549 ArcTermsOfServiceInitialOobeNegotiatorForManagedUser:: | |
| 550 SetArcTermsOfServiceScreenActorForTesting(this); | |
| 551 | |
| 552 GetFakeUserManager()->set_current_user_new(true); | |
| 553 | |
| 554 policy::ProfilePolicyConnector* const connector = | |
| 555 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); | |
| 556 connector->OverrideIsManagedForTesting(true); | |
| 557 | |
| 558 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 559 chromeos::switches::kEnableArcOOBEOptIn); | |
| 560 | |
| 561 profile()->GetTestingPrefService()->SetManagedPref( | |
| 562 prefs::kArcEnabled, new base::FundamentalValue(true)); | |
| 563 } | |
| 564 | |
| 565 void TearDown() override { | |
| 566 ArcSessionManagerTest::TearDown(); | |
|
hidehiko
2016/12/19 15:49:44
Please call this after L568 (in general TearDown s
khmel
2016/12/19 17:48:10
Done.
| |
| 567 | |
| 568 ArcTermsOfServiceInitialOobeNegotiatorForManagedUser:: | |
| 569 SetArcTermsOfServiceScreenActorForTesting(nullptr); | |
| 570 } | |
| 571 | |
| 572 protected: | |
| 573 void ReportResult(bool accepted) { | |
| 574 for (auto& observer : observer_list_) { | |
| 575 if (accepted) | |
| 576 observer.OnAccept(); | |
| 577 else | |
| 578 observer.OnSkip(); | |
| 579 } | |
| 580 base::RunLoop().RunUntilIdle(); | |
| 581 } | |
| 582 | |
| 583 private: | |
| 584 // ArcTermsOfServiceScreenActor: | |
| 585 void AddObserver( | |
| 586 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | |
| 587 observer_list_.AddObserver(observer); | |
| 588 } | |
| 589 | |
| 590 void RemoveObserver( | |
| 591 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | |
| 592 observer_list_.RemoveObserver(observer); | |
| 593 } | |
| 594 | |
| 595 void Show() override {} | |
| 596 void Hide() override {} | |
| 597 | |
| 598 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver> | |
| 599 observer_list_; | |
| 600 | |
| 601 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeManagedUserTest); | |
| 602 }; | |
| 603 | |
| 604 TEST_F(ArcSessionOobeManagedUserTest, OobeTermsAccepted) { | |
| 605 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 606 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 607 arc_session_manager()->state()); | |
| 608 ReportResult(true); | |
| 609 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
| 610 // Correctly stop service. | |
| 611 arc_session_manager()->Shutdown(); | |
| 612 } | |
| 613 | |
| 614 TEST_F(ArcSessionOobeManagedUserTest, OobeTermsRejected) { | |
| 615 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 616 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 617 arc_session_manager()->state()); | |
| 618 ReportResult(false); | |
| 619 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
| 620 // Correctly stop service. | |
| 621 arc_session_manager()->Shutdown(); | |
| 622 } | |
| 623 | |
| 534 } // namespace arc | 624 } // namespace arc |
| OLD | NEW |