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 <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
13 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/logging.h" |
14 #include "base/macros.h" | 16 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
16 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
17 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/values.h" |
18 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
19 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 22 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
20 #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" |
21 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" | 24 #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" | 25 #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" | 26 #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" | 27 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
25 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 28 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
26 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 29 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
27 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 30 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
28 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
29 #include "chrome/browser/policy/profile_policy_connector.h" | 32 #include "chrome/browser/policy/profile_policy_connector.h" |
30 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 33 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
31 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 34 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
32 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
33 #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" |
34 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 37 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
35 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
36 #include "chrome/test/base/testing_profile.h" | 39 #include "chrome/test/base/testing_profile.h" |
37 #include "chromeos/chromeos_switches.h" | 40 #include "chromeos/chromeos_switches.h" |
38 #include "chromeos/dbus/dbus_thread_manager.h" | 41 #include "chromeos/dbus/dbus_thread_manager.h" |
39 #include "chromeos/dbus/fake_session_manager_client.h" | 42 #include "chromeos/dbus/fake_session_manager_client.h" |
40 #include "components/arc/arc_service_manager.h" | 43 #include "components/arc/arc_service_manager.h" |
41 #include "components/arc/arc_session_runner.h" | 44 #include "components/arc/arc_session_runner.h" |
42 #include "components/arc/arc_util.h" | 45 #include "components/arc/arc_util.h" |
43 #include "components/arc/test/fake_arc_session.h" | 46 #include "components/arc/test/fake_arc_session.h" |
44 #include "components/prefs/pref_service.h" | 47 #include "components/prefs/pref_service.h" |
| 48 #include "components/prefs/testing_pref_service.h" |
45 #include "components/signin/core/account_id/account_id.h" | 49 #include "components/signin/core/account_id/account_id.h" |
46 #include "components/sync/model/fake_sync_change_processor.h" | 50 #include "components/sync/model/fake_sync_change_processor.h" |
47 #include "components/sync/model/sync_error_factory_mock.h" | 51 #include "components/sync/model/sync_error_factory_mock.h" |
48 #include "components/sync_preferences/testing_pref_service_syncable.h" | 52 #include "components/sync_preferences/testing_pref_service_syncable.h" |
49 #include "components/user_manager/user_manager.h" | 53 #include "components/user_manager/user_manager.h" |
50 #include "components/user_manager/user_names.h" | 54 #include "components/user_manager/user_names.h" |
51 #include "content/public/browser/browser_thread.h" | 55 #include "content/public/browser/browser_thread.h" |
52 #include "content/public/test/test_browser_thread_bundle.h" | 56 #include "content/public/test/test_browser_thread_bundle.h" |
53 #include "google_apis/gaia/gaia_constants.h" | 57 #include "google_apis/gaia/gaia_constants.h" |
54 #include "google_apis/gaia/gaia_urls.h" | 58 #include "google_apis/gaia/gaia_urls.h" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 | 564 |
561 // Try to send another error that stops the bridge if sent first. It should | 565 // Try to send another error that stops the bridge if sent first. It should |
562 // be ignored. | 566 // be ignored. |
563 arc_session_manager()->OnProvisioningFinished( | 567 arc_session_manager()->OnProvisioningFinished( |
564 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 568 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
565 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 569 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
566 | 570 |
567 arc_session_manager()->Shutdown(); | 571 arc_session_manager()->Shutdown(); |
568 } | 572 } |
569 | 573 |
| 574 class ArcSessionManagerPolicyTest |
| 575 : public ArcSessionManagerTest, |
| 576 public testing::WithParamInterface<std::tuple<base::Value, base::Value>> { |
| 577 public: |
| 578 const base::Value& backup_restore_pref_value() const { |
| 579 return std::get<0>(GetParam()); |
| 580 } |
| 581 |
| 582 const base::Value& location_service_pref_value() const { |
| 583 return std::get<1>(GetParam()); |
| 584 } |
| 585 }; |
| 586 |
| 587 TEST_P(ArcSessionManagerPolicyTest, SkippingTerms) { |
| 588 sync_preferences::TestingPrefServiceSyncable* const prefs = |
| 589 profile()->GetTestingPrefService(); |
| 590 |
| 591 // Backup-restore and location-service prefs are off by default. |
| 592 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 593 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcTermsAccepted)); |
| 594 |
| 595 // Set ARC to be managed. |
| 596 prefs->SetManagedPref(prefs::kArcEnabled, new base::Value(true)); |
| 597 |
| 598 // Assign test values to the prefs. |
| 599 if (backup_restore_pref_value().is_bool()) { |
| 600 prefs->SetManagedPref(prefs::kArcBackupRestoreEnabled, |
| 601 backup_restore_pref_value().DeepCopy()); |
| 602 } |
| 603 if (location_service_pref_value().is_bool()) { |
| 604 prefs->SetManagedPref(prefs::kArcLocationServiceEnabled, |
| 605 location_service_pref_value().DeepCopy()); |
| 606 } |
| 607 |
| 608 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 609 EXPECT_TRUE(arc_session_manager()->IsArcPlayStoreEnabled()); |
| 610 EXPECT_TRUE(arc_session_manager()->IsArcManaged()); |
| 611 |
| 612 // Terms of Service should be skipped if both ArcBackupRestoreEnabled and |
| 613 // ArcLocationServiceEnabled are managed. |
| 614 const ArcSessionManager::State expected_state = |
| 615 backup_restore_pref_value().is_bool() && |
| 616 location_service_pref_value().is_bool() |
| 617 ? ArcSessionManager::State::ACTIVE |
| 618 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE; |
| 619 EXPECT_EQ(expected_state, arc_session_manager()->state()); |
| 620 |
| 621 // Managed values for the prefs are unset. |
| 622 prefs->RemoveManagedPref(prefs::kArcBackupRestoreEnabled); |
| 623 prefs->RemoveManagedPref(prefs::kArcLocationServiceEnabled); |
| 624 |
| 625 // The ARC state is preserved. The prefs return to the default false values. |
| 626 EXPECT_EQ(expected_state, arc_session_manager()->state()); |
| 627 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
| 628 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); |
| 629 |
| 630 // Stop ARC and shutdown the service. |
| 631 prefs->RemoveManagedPref(prefs::kArcEnabled); |
| 632 WaitForDataRemoved(ArcSessionManager::State::STOPPED); |
| 633 arc_session_manager()->Shutdown(); |
| 634 } |
| 635 |
| 636 INSTANTIATE_TEST_CASE_P( |
| 637 ArcSessionManagerPolicyTest, |
| 638 ArcSessionManagerPolicyTest, |
| 639 testing::Combine( |
| 640 testing::Values(base::Value(), base::Value(false), base::Value(true)), |
| 641 testing::Values(base::Value(), base::Value(false), base::Value(true)))); |
| 642 |
570 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase { | 643 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase { |
571 public: | 644 public: |
572 ArcSessionManagerKioskTest() = default; | 645 ArcSessionManagerKioskTest() = default; |
573 | 646 |
574 void SetUp() override { | 647 void SetUp() override { |
575 ArcSessionManagerTestBase::SetUp(); | 648 ArcSessionManagerTestBase::SetUp(); |
576 const AccountId account_id( | 649 const AccountId account_id( |
577 AccountId::FromUserEmail(profile()->GetProfileUserName())); | 650 AccountId::FromUserEmail(profile()->GetProfileUserName())); |
578 GetFakeUserManager()->AddArcKioskAppUser(account_id); | 651 GetFakeUserManager()->AddArcKioskAppUser(account_id); |
579 GetFakeUserManager()->LoginUser(account_id); | 652 GetFakeUserManager()->LoginUser(account_id); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 847 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
775 arc_session_manager()->state()); | 848 arc_session_manager()->state()); |
776 CloseLoginDisplayHost(); | 849 CloseLoginDisplayHost(); |
777 ReportActorDestroyed(); | 850 ReportActorDestroyed(); |
778 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 851 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
779 EXPECT_FALSE(!IsManagedUser() && | 852 EXPECT_FALSE(!IsManagedUser() && |
780 arc_session_manager()->IsArcPlayStoreEnabled()); | 853 arc_session_manager()->IsArcPlayStoreEnabled()); |
781 } | 854 } |
782 | 855 |
783 } // namespace arc | 856 } // namespace arc |
OLD | NEW |