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/arc_session_manager_data_removed_waiter.h" | |
| 21 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .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/mock_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/test/fake_arc_session.h" | 42 #include "components/arc/test/fake_arc_session.h" |
| 35 #include "components/prefs/pref_service.h" | 43 #include "components/prefs/pref_service.h" |
| 36 #include "components/signin/core/account_id/account_id.h" | 44 #include "components/signin/core/account_id/account_id.h" |
| 37 #include "components/sync/model/fake_sync_change_processor.h" | 45 #include "components/sync/model/fake_sync_change_processor.h" |
| 38 #include "components/sync/model/sync_error_factory_mock.h" | 46 #include "components/sync/model/sync_error_factory_mock.h" |
| 39 #include "components/sync_preferences/testing_pref_service_syncable.h" | 47 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 40 #include "components/user_manager/user_manager.h" | 48 #include "components/user_manager/user_manager.h" |
| 41 #include "components/user_manager/user_names.h" | 49 #include "components/user_manager/user_names.h" |
| 42 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/test/test_browser_thread_bundle.h" | 51 #include "content/public/test/test_browser_thread_bundle.h" |
| 44 #include "google_apis/gaia/gaia_constants.h" | 52 #include "google_apis/gaia/gaia_constants.h" |
| 45 #include "google_apis/gaia/gaia_urls.h" | 53 #include "google_apis/gaia/gaia_urls.h" |
| 46 #include "net/http/http_status_code.h" | 54 #include "net/http/http_status_code.h" |
| 47 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
| 48 | 56 |
| 49 namespace arc { | 57 namespace arc { |
| 50 | 58 |
| 51 class ArcSessionManagerTestBase : public testing::Test { | 59 namespace { |
| 60 | |
| 61 class FakeLoginDisplayHost : public chromeos::MockLoginDisplayHost { | |
|
hidehiko
2017/01/30 10:12:35
In Chrome, AFAIK, "Fake" is used meaning the light
khmel
2017/01/31 02:47:08
Done.
| |
| 62 public: | |
| 63 FakeLoginDisplayHost() { | |
| 64 DCHECK(!chromeos::LoginDisplayHost::default_host_); | |
| 65 chromeos::LoginDisplayHost::default_host_ = this; | |
| 66 } | |
| 67 | |
| 68 ~FakeLoginDisplayHost() override { | |
| 69 DCHECK_EQ(chromeos::LoginDisplayHost::default_host_, this); | |
| 70 chromeos::LoginDisplayHost::default_host_ = nullptr; | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 DISALLOW_COPY_AND_ASSIGN(FakeLoginDisplayHost); | |
| 75 }; | |
| 76 | |
| 77 } // namespace | |
| 78 | |
| 79 class ArcSessionManagerTestBase : public testing::TestWithParam<bool> { | |
|
hidehiko
2017/01/30 10:12:35
Because the param is not used in this base, please
khmel
2017/01/31 02:47:08
On 2017/01/30 10:12:35, hidehiko wrote:
> Because
| |
| 52 public: | 80 public: |
| 53 ArcSessionManagerTestBase() | 81 ArcSessionManagerTestBase() |
| 54 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 82 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 55 user_manager_enabler_(new chromeos::FakeChromeUserManager()) {} | 83 user_manager_enabler_(new chromeos::FakeChromeUserManager()) {} |
| 56 ~ArcSessionManagerTestBase() override = default; | 84 ~ArcSessionManagerTestBase() override = default; |
| 57 | 85 |
| 58 void SetUp() override { | 86 void SetUp() override { |
| 59 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 87 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 60 base::MakeUnique<chromeos::FakeSessionManagerClient>()); | 88 base::MakeUnique<chromeos::FakeSessionManagerClient>()); |
| 61 | 89 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 89 arc_service_manager_.reset(); | 117 arc_service_manager_.reset(); |
| 90 chromeos::DBusThreadManager::Shutdown(); | 118 chromeos::DBusThreadManager::Shutdown(); |
| 91 } | 119 } |
| 92 | 120 |
| 93 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 121 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 94 return static_cast<chromeos::FakeChromeUserManager*>( | 122 return static_cast<chromeos::FakeChromeUserManager*>( |
| 95 user_manager::UserManager::Get()); | 123 user_manager::UserManager::Get()); |
| 96 } | 124 } |
| 97 | 125 |
| 98 protected: | 126 protected: |
| 99 Profile* profile() { return profile_.get(); } | 127 TestingProfile* profile() { return profile_.get(); } |
| 100 | 128 |
| 101 ArcSessionManager* arc_session_manager() { | 129 ArcSessionManager* arc_session_manager() { |
| 102 return arc_session_manager_.get(); | 130 return arc_session_manager_.get(); |
| 103 } | 131 } |
| 104 | 132 |
| 105 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { | 133 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { |
| 106 if (arc_session_manager()->state() != | 134 if (arc_session_manager()->state() != |
| 107 ArcSessionManager::State::REMOVING_DATA_DIR) | 135 ArcSessionManager::State::REMOVING_DATA_DIR) |
| 108 return false; | 136 return false; |
| 109 | 137 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 // and not invoked then, including TearDown(). | 547 // and not invoked then, including TearDown(). |
| 520 bool terminated = false; | 548 bool terminated = false; |
| 521 arc_session_manager()->SetAttemptUserExitCallbackForTesting( | 549 arc_session_manager()->SetAttemptUserExitCallbackForTesting( |
| 522 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); | 550 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); |
| 523 | 551 |
| 524 arc_session_manager()->OnProvisioningFinished( | 552 arc_session_manager()->OnProvisioningFinished( |
| 525 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 553 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 526 EXPECT_TRUE(terminated); | 554 EXPECT_TRUE(terminated); |
| 527 } | 555 } |
| 528 | 556 |
| 557 class ArcSessionOobeOptInTest : public ArcSessionManagerTest, | |
| 558 public chromeos::ArcTermsOfServiceScreenActor { | |
| 559 public: | |
| 560 ArcSessionOobeOptInTest() = default; | |
| 561 | |
| 562 void SetUp() override { | |
| 563 ArcSessionManagerTest::SetUp(); | |
| 564 | |
| 565 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( | |
| 566 this); | |
| 567 | |
| 568 GetFakeUserManager()->set_current_user_new(true); | |
| 569 | |
| 570 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 571 chromeos::switches::kEnableArcOOBEOptIn); | |
| 572 | |
| 573 fake_login_display_host_.reset(new FakeLoginDisplayHost()); | |
|
hidehiko
2017/01/30 10:12:35
MakeUnique, please.
khmel
2017/01/31 02:47:08
Done.
| |
| 574 | |
| 575 if (IsManagedUser()) { | |
| 576 policy::ProfilePolicyConnector* const connector = | |
| 577 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | |
| 578 profile()); | |
| 579 connector->OverrideIsManagedForTesting(true); | |
| 580 | |
| 581 profile()->GetTestingPrefService()->SetManagedPref( | |
| 582 prefs::kArcEnabled, new base::FundamentalValue(true)); | |
| 583 } | |
| 584 } | |
| 585 | |
| 586 void TearDown() override { | |
| 587 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( | |
| 588 nullptr); | |
| 589 | |
| 590 ArcSessionManagerTest::TearDown(); | |
| 591 } | |
| 592 | |
| 593 protected: | |
| 594 bool IsManagedUser() { return GetParam(); } | |
| 595 | |
| 596 void ReportResult(bool accepted) { | |
| 597 for (auto& observer : observer_list_) { | |
| 598 if (accepted) | |
| 599 observer.OnAccept(); | |
| 600 else | |
| 601 observer.OnSkip(); | |
| 602 } | |
| 603 base::RunLoop().RunUntilIdle(); | |
| 604 } | |
| 605 | |
| 606 void MaybeWaitForDataRemoved() { | |
| 607 if (IsManagedUser()) | |
|
hidehiko
2017/01/30 10:12:35
Could you comment why managed user does not need t
khmel
2017/01/31 02:47:08
Done.
| |
| 608 return; | |
| 609 | |
| 610 DCHECK_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | |
| 611 ArcSessionManager::Get()->state()); | |
| 612 ArcSessionManagerDataRemovedWaiter().Wait(); | |
| 613 } | |
| 614 | |
| 615 chromeos::ArcTermsOfServiceScreenActor* actor() { return this; } | |
| 616 | |
| 617 private: | |
| 618 // ArcTermsOfServiceScreenActor: | |
| 619 void AddObserver( | |
| 620 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | |
| 621 observer_list_.AddObserver(observer); | |
| 622 } | |
| 623 | |
| 624 void RemoveObserver( | |
| 625 chromeos::ArcTermsOfServiceScreenActorObserver* observer) override { | |
| 626 observer_list_.RemoveObserver(observer); | |
| 627 } | |
| 628 | |
| 629 void Show() override { | |
| 630 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | |
|
hidehiko
2017/01/30 10:12:35
Setting the preference and the Show() method name
khmel
2017/01/31 02:47:08
Done.
| |
| 631 } | |
| 632 | |
| 633 void Hide() override {} | |
| 634 | |
| 635 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver> | |
| 636 observer_list_; | |
| 637 std::unique_ptr<FakeLoginDisplayHost> fake_login_display_host_; | |
|
hidehiko
2017/01/30 10:12:35
This is only for let default_host() return true, r
khmel
2017/01/31 02:47:08
Done.
| |
| 638 | |
| 639 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInTest); | |
| 640 }; | |
| 641 | |
| 642 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInTestImpl, | |
| 643 ArcSessionOobeOptInTest, | |
| 644 ::testing::Values(true, false)); | |
| 645 | |
| 646 TEST_P(ArcSessionOobeOptInTest, OobeTermsAccepted) { | |
| 647 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
|
hidehiko
2017/01/30 10:12:35
L647 - L649 looks a part of SetUp() and L656 looks
khmel
2017/01/31 02:47:08
Done.
| |
| 648 actor()->Show(); | |
| 649 MaybeWaitForDataRemoved(); | |
| 650 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 651 arc_session_manager()->state()); | |
| 652 ReportResult(true); | |
| 653 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
| 654 EXPECT_TRUE(arc_session_manager()->IsArcEnabled()); | |
| 655 // Correctly stop service. | |
| 656 arc_session_manager()->Shutdown(); | |
| 657 } | |
| 658 | |
| 659 TEST_P(ArcSessionOobeOptInTest, OobeTermsRejected) { | |
| 660 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 661 actor()->Show(); | |
| 662 MaybeWaitForDataRemoved(); | |
| 663 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 664 arc_session_manager()->state()); | |
| 665 ReportResult(false); | |
| 666 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
| 667 EXPECT_FALSE(!IsManagedUser() && arc_session_manager()->IsArcEnabled()); | |
| 668 // Correctly stop service. | |
| 669 arc_session_manager()->Shutdown(); | |
| 670 } | |
| 671 | |
| 529 } // namespace arc | 672 } // namespace arc |
| OLD | NEW |