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

Unified Diff: chrome/browser/chromeos/arc/arc_util_unittest.cc

Issue 2890843002: Policy implementation for encryptfs to ext4 migration strategy (Closed)
Patch Set: Fixed review comments Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
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..186725e0c58cf20ab933ad2d9619bf801c9e86c5 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) {
+ int pref_value = migration_allowed ? kMigrationAllowedPolicyEnabled
bartfab (slow) 2017/06/13 09:56:02 Nit: const
igorcov 2017/06/16 11:13:04 Done.
+ : kMigrationAllowedPolicyDisabled;
+ auto* command_line = base::CommandLine::ForCurrentProcess();
bartfab (slow) 2017/06/13 09:56:02 Nit: const pointer
igorcov 2017/06/16 11:13:04 Done.
+ command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
+ "--arc-availability=officially-supported"});
+ SetDeviceIsEnterpriseManaged(true);
+ FakeUserManagerWithLocalState* 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* 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* 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

Powered by Google App Engine
This is Rietveld 408576698