Chromium Code Reviews| 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..ea66cc2d871ecd410dfa93cf5801590a3ab1c912 100644 |
| --- a/chrome/browser/chromeos/arc/arc_util_unittest.cc |
| +++ b/chrome/browser/chromeos/arc/arc_util_unittest.cc |
| @@ -17,10 +17,14 @@ |
| #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/device_settings_service.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_service.h" |
| #include "components/prefs/testing_pref_service.h" |
| #include "components/signin/core/account_id/account_id.h" |
| @@ -88,6 +92,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() |
| @@ -474,5 +494,44 @@ TEST_F(ChromeArcUtilTest, AreArcAllOptInPreferencesManagedForProfile) { |
| EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile())); |
| } |
| +class ArcMigrationTest : public testing::Test { |
| + protected: |
| + ArcMigrationTest() { |
| + auto attributes = base::MakeUnique<FakeInstallAttributesManaged>(); |
| + attributes_ = attributes.get(); |
| + policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( |
| + attributes.release()); |
| + } |
| + ~ArcMigrationTest() override {} |
| + |
| + void SetUp() override { chromeos::DeviceSettingsService::Initialize(); } |
| + |
| + void TearDown() override { chromeos::DeviceSettingsService::Shutdown(); } |
| + |
| + void SetDeviceIsEnterpriseManaged(bool is_managed) { |
| + attributes_->SetIsManaged(is_managed); |
| + } |
| + |
| + FakeInstallAttributesManaged* attributes_; |
| +}; |
| + |
| +TEST_F(ArcMigrationTest, 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(ArcMigrationTest, IsMigrationAllowedNoPolicy) { |
|
bartfab (slow)
2017/06/21 21:31:16
You used to have tests for policy set to disallow/
igorcov
2017/06/22 09:31:23
Yes, I've removed the tests that involved the poli
|
| + 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()); |
| +} |
| + |
| } // namespace util |
| } // namespace arc |