| Index: chrome/browser/chromeos/arc/arc_util_unittest.cc
|
| diff --git a/chrome/browser/chromeos/arc/arc_util_unittest.cc b/chrome/browser/chromeos/arc/arc_util_unittest.cc
|
| index 92daee101c29c72f2f400ee6dac39c9d3462f048..86667654340548ad6057a6469a733eb3061c2c94 100644
|
| --- a/chrome/browser/chromeos/arc/arc_util_unittest.cc
|
| +++ b/chrome/browser/chromeos/arc/arc_util_unittest.cc
|
| @@ -17,12 +17,18 @@
|
| #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
|
| #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
|
| #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
|
| +#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
|
| #include "chrome/browser/chromeos/profiles/profile_helper.h"
|
| +#include "chrome/browser/chromeos/settings/install_attributes.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "components/policy/core/common/cloud/cloud_policy_constants.h"
|
| +#include "components/prefs/pref_registry_simple.h"
|
| #include "components/prefs/pref_service.h"
|
| +#include "components/prefs/pref_service_factory.h"
|
| #include "components/prefs/testing_pref_service.h"
|
| +#include "components/prefs/testing_pref_store.h"
|
| #include "components/signin/core/account_id/account_id.h"
|
| #include "components/sync_preferences/testing_pref_service_syncable.h"
|
| #include "components/user_manager/known_user.h"
|
| @@ -39,6 +45,12 @@ namespace {
|
| constexpr char kTestProfileName[] = "user@gmail.com";
|
| constexpr char kTestGaiaId[] = "1234567890";
|
|
|
| +// The constants matching the values from DeviceEcryptfsMigrationStrategy
|
| +// policy.
|
| +constexpr int kMigrationAllowedPolicyUnset = 0;
|
| +constexpr int kMigrationAllowedPolicyDisabled = 1;
|
| +constexpr int kMigrationAllowedPolicyEnabled = 2;
|
| +
|
| class ScopedLogIn {
|
| public:
|
| ScopedLogIn(
|
| @@ -88,6 +100,22 @@ class ScopedLogIn {
|
| DISALLOW_COPY_AND_ASSIGN(ScopedLogIn);
|
| };
|
|
|
| +class FakeInstallAttributesManaged : public chromeos::InstallAttributes {
|
| + public:
|
| + FakeInstallAttributesManaged() : chromeos::InstallAttributes(nullptr) {
|
| + device_locked_ = true;
|
| + }
|
| +
|
| + ~FakeInstallAttributesManaged() {
|
| + policy::BrowserPolicyConnectorChromeOS::RemoveInstallAttributesForTesting();
|
| + }
|
| +
|
| + void SetIsManaged(bool is_managed) {
|
| + registration_mode_ = is_managed ? policy::DEVICE_MODE_ENTERPRISE
|
| + : policy::DEVICE_MODE_CONSUMER;
|
| + }
|
| +};
|
| +
|
| class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager {
|
| public:
|
| FakeUserManagerWithLocalState()
|
| @@ -96,11 +124,16 @@ class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager {
|
| }
|
|
|
| PrefService* GetLocalState() const override {
|
| + if (local_state_)
|
| + return local_state_;
|
| return test_local_state_.get();
|
| }
|
|
|
| + void SetLocalState(PrefService* local_state) { local_state_ = local_state; }
|
| +
|
| private:
|
| std::unique_ptr<TestingPrefServiceSimple> test_local_state_;
|
| + PrefService* local_state_ = nullptr;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(FakeUserManagerWithLocalState);
|
| };
|
| @@ -109,7 +142,13 @@ class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager {
|
|
|
| class ChromeArcUtilTest : public testing::Test {
|
| public:
|
| - ChromeArcUtilTest() = default;
|
| + ChromeArcUtilTest() {
|
| + auto attributes = base::MakeUnique<FakeInstallAttributesManaged>();
|
| + attributes_ = attributes.get();
|
| + policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
|
| + attributes.release());
|
| + }
|
| +
|
| ~ChromeArcUtilTest() override = default;
|
|
|
| void SetUp() override {
|
| @@ -137,6 +176,15 @@ class ChromeArcUtilTest : public testing::Test {
|
| user_manager::UserManager::Get());
|
| }
|
|
|
| + FakeUserManagerWithLocalState* GetFakeUserManagerWithLocalState() const {
|
| + return static_cast<FakeUserManagerWithLocalState*>(
|
| + user_manager::UserManager::Get());
|
| + }
|
| +
|
| + void SetDeviceIsEnterpriseManaged(bool is_managed) {
|
| + attributes_->SetIsManaged(is_managed);
|
| + }
|
| +
|
| void LogIn() {
|
| const auto account_id = AccountId::FromUserEmailGaiaId(
|
| profile()->GetProfileUserName(), kTestGaiaId);
|
| @@ -144,11 +192,42 @@ class ChromeArcUtilTest : public testing::Test {
|
| GetFakeUserManager()->LoginUser(account_id);
|
| }
|
|
|
| + void SetMigrationPolicy(bool migration_allowed) {
|
| + const int pref_value = migration_allowed ? kMigrationAllowedPolicyEnabled
|
| + : kMigrationAllowedPolicyDisabled;
|
| + auto* const command_line = base::CommandLine::ForCurrentProcess();
|
| + command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
|
| + "--arc-availability=officially-supported"});
|
| + SetDeviceIsEnterpriseManaged(true);
|
| + FakeUserManagerWithLocalState* const fake_user_manager =
|
| + GetFakeUserManagerWithLocalState();
|
| + PrefServiceFactory pref_service_factory;
|
| + managed_pref_store_ =
|
| + scoped_refptr<TestingPrefStore>(new TestingPrefStore());
|
| + user_pref_store_ = scoped_refptr<TestingPrefStore>(new TestingPrefStore());
|
| + managed_pref_store_->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
|
| + pref_value);
|
| + pref_service_factory.set_managed_prefs(managed_pref_store_.get());
|
| + pref_service_factory.set_user_prefs(user_pref_store_.get());
|
| + scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
|
| + registry->RegisterIntegerPref(prefs::kDeviceEcryptfsMigrationStrategy,
|
| + kMigrationAllowedPolicyUnset);
|
| + pref_service_ = std::unique_ptr<PrefService>(
|
| + pref_service_factory.Create(registry.get()));
|
| + pref_service_->SetInteger(prefs::kDeviceEcryptfsMigrationStrategy,
|
| + pref_value);
|
| + fake_user_manager->SetLocalState(pref_service_.get());
|
| + }
|
| +
|
| private:
|
| std::unique_ptr<base::test::ScopedCommandLine> command_line_;
|
| content::TestBrowserThreadBundle thread_bundle_;
|
| std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
|
| std::unique_ptr<TestingProfile> profile_;
|
| + FakeInstallAttributesManaged* attributes_;
|
| + scoped_refptr<TestingPrefStore> managed_pref_store_;
|
| + scoped_refptr<TestingPrefStore> user_pref_store_;
|
| + std::unique_ptr<PrefService> pref_service_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ChromeArcUtilTest);
|
| };
|
| @@ -474,5 +553,38 @@ TEST_F(ChromeArcUtilTest, AreArcAllOptInPreferencesManagedForProfile) {
|
| EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile()));
|
| }
|
|
|
| +TEST_F(ChromeArcUtilTest, IsMigrationAllowedConsumerOwned) {
|
| + ResetArcMigrationAllowedForTesting();
|
| + auto* const command_line = base::CommandLine::ForCurrentProcess();
|
| + command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
|
| + "--arc-availability=officially-supported"});
|
| + SetDeviceIsEnterpriseManaged(false);
|
| + EXPECT_TRUE(IsArcMigrationAllowed());
|
| +}
|
| +
|
| +TEST_F(ChromeArcUtilTest, IsMigrationAllowedNoPolicy) {
|
| + ResetArcMigrationAllowedForTesting();
|
| + auto* const command_line = base::CommandLine::ForCurrentProcess();
|
| + command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
|
| + "--arc-availability=officially-supported"});
|
| + SetDeviceIsEnterpriseManaged(true);
|
| +
|
| + EXPECT_FALSE(IsArcMigrationAllowed());
|
| +}
|
| +
|
| +TEST_F(ChromeArcUtilTest, IsMigrationAllowedPolicyAllowed) {
|
| + ResetArcMigrationAllowedForTesting();
|
| + SetMigrationPolicy(true);
|
| +
|
| + EXPECT_TRUE(IsArcMigrationAllowed());
|
| +}
|
| +
|
| +TEST_F(ChromeArcUtilTest, IsMigrationAllowedPolicyDisabled) {
|
| + ResetArcMigrationAllowedForTesting();
|
| + SetMigrationPolicy(false);
|
| +
|
| + EXPECT_FALSE(IsArcMigrationAllowed());
|
| +}
|
| +
|
| } // namespace util
|
| } // namespace arc
|
|
|