| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/system/device_disabling_manager.h" | 5 #include "chrome/browser/chromeos/system/device_disabling_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 class DeviceDisablingManagerTestBase : public testing::Test, | 49 class DeviceDisablingManagerTestBase : public testing::Test, |
| 50 public DeviceDisablingManager::Delegate { | 50 public DeviceDisablingManager::Delegate { |
| 51 public: | 51 public: |
| 52 DeviceDisablingManagerTestBase(); | 52 DeviceDisablingManagerTestBase(); |
| 53 | 53 |
| 54 // testing::Test: | 54 // testing::Test: |
| 55 void TearDown() override; | 55 void TearDown() override; |
| 56 | 56 |
| 57 virtual void CreateDeviceDisablingManager(); | 57 virtual void CreateDeviceDisablingManager(); |
| 58 virtual void DestroyDeviceDisablingManager(); | 58 virtual void DestroyDeviceDisablingManager(); |
| 59 | |
| 60 void UpdateInstallAttributes(const std::string& enrollment_domain, | |
| 61 const std::string& registration_user, | |
| 62 policy::DeviceMode device_mode); | |
| 63 void LogIn(); | 59 void LogIn(); |
| 64 | 60 |
| 65 // DeviceDisablingManager::Delegate: | 61 // DeviceDisablingManager::Delegate: |
| 66 MOCK_METHOD0(RestartToLoginScreen, void()); | 62 MOCK_METHOD0(RestartToLoginScreen, void()); |
| 67 MOCK_METHOD0(ShowDeviceDisabledScreen, void()); | 63 MOCK_METHOD0(ShowDeviceDisabledScreen, void()); |
| 68 | 64 |
| 69 DeviceDisablingManager* GetDeviceDisablingManager() { | 65 DeviceDisablingManager* GetDeviceDisablingManager() { |
| 70 return device_disabling_manager_.get(); | 66 return device_disabling_manager_.get(); |
| 71 } | 67 } |
| 72 | 68 |
| 69 // Configure install attributes. |
| 70 void SetUnowned(); |
| 71 void SetEnterpriseOwned(); |
| 72 void SetConsumerOwned(); |
| 73 |
| 73 private: | 74 private: |
| 75 chromeos::StubInstallAttributes* GetInstallAttributes(); |
| 76 |
| 74 chromeos::ScopedStubInstallAttributes install_attributes_; | 77 chromeos::ScopedStubInstallAttributes install_attributes_; |
| 75 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 78 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 76 chromeos::ScopedTestCrosSettings test_cros_settings_; | 79 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 77 user_manager::FakeUserManager fake_user_manager_; | 80 user_manager::FakeUserManager fake_user_manager_; |
| 78 std::unique_ptr<DeviceDisablingManager> device_disabling_manager_; | 81 std::unique_ptr<DeviceDisablingManager> device_disabling_manager_; |
| 79 | 82 |
| 80 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManagerTestBase); | 83 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManagerTestBase); |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 DeviceDisablingManagerTestBase::DeviceDisablingManagerTestBase() | 86 DeviceDisablingManagerTestBase::DeviceDisablingManagerTestBase() |
| 84 : install_attributes_("", "", "", policy::DEVICE_MODE_NOT_SET) { | 87 : install_attributes_(ScopedStubInstallAttributes::CreateUnset()) { |
| 85 } | 88 } |
| 86 | 89 |
| 87 void DeviceDisablingManagerTestBase::TearDown() { | 90 void DeviceDisablingManagerTestBase::TearDown() { |
| 88 DestroyDeviceDisablingManager(); | 91 DestroyDeviceDisablingManager(); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void DeviceDisablingManagerTestBase::CreateDeviceDisablingManager() { | 94 void DeviceDisablingManagerTestBase::CreateDeviceDisablingManager() { |
| 92 device_disabling_manager_.reset(new DeviceDisablingManager( | 95 device_disabling_manager_.reset(new DeviceDisablingManager( |
| 93 this, | 96 this, |
| 94 CrosSettings::Get(), | 97 CrosSettings::Get(), |
| 95 &fake_user_manager_)); | 98 &fake_user_manager_)); |
| 96 } | 99 } |
| 97 | 100 |
| 98 void DeviceDisablingManagerTestBase::DestroyDeviceDisablingManager() { | 101 void DeviceDisablingManagerTestBase::DestroyDeviceDisablingManager() { |
| 99 device_disabling_manager_.reset(); | 102 device_disabling_manager_.reset(); |
| 100 } | 103 } |
| 101 | 104 |
| 102 void DeviceDisablingManagerTestBase::UpdateInstallAttributes( | |
| 103 const std::string& enrollment_domain, | |
| 104 const std::string& registration_user, | |
| 105 policy::DeviceMode device_mode) { | |
| 106 chromeos::StubInstallAttributes* install_attributes = | |
| 107 static_cast<chromeos::StubInstallAttributes*>( | |
| 108 TestingBrowserProcess::GetGlobal() | |
| 109 ->platform_part() | |
| 110 ->browser_policy_connector_chromeos() | |
| 111 ->GetInstallAttributes()); | |
| 112 install_attributes->SetDomain(enrollment_domain); | |
| 113 install_attributes->SetRegistrationUser(registration_user); | |
| 114 install_attributes->SetMode(device_mode); | |
| 115 } | |
| 116 | |
| 117 void DeviceDisablingManagerTestBase::LogIn() { | 105 void DeviceDisablingManagerTestBase::LogIn() { |
| 118 fake_user_manager_.AddUser(AccountId::FromUserEmail(kTestUser)); | 106 fake_user_manager_.AddUser(AccountId::FromUserEmail(kTestUser)); |
| 119 } | 107 } |
| 120 | 108 |
| 109 void DeviceDisablingManagerTestBase::SetUnowned() { |
| 110 GetInstallAttributes()->Clear(); |
| 111 } |
| 112 |
| 113 void DeviceDisablingManagerTestBase::SetEnterpriseOwned() { |
| 114 GetInstallAttributes()->SetEnterprise(kEnrollmentDomain, "fake-id"); |
| 115 } |
| 116 |
| 117 void DeviceDisablingManagerTestBase::SetConsumerOwned() { |
| 118 GetInstallAttributes()->SetConsumer(); |
| 119 } |
| 120 |
| 121 chromeos::StubInstallAttributes* |
| 122 DeviceDisablingManagerTestBase::GetInstallAttributes() { |
| 123 return static_cast<chromeos::StubInstallAttributes*>( |
| 124 TestingBrowserProcess::GetGlobal() |
| 125 ->platform_part() |
| 126 ->browser_policy_connector_chromeos() |
| 127 ->GetInstallAttributes()); |
| 128 } |
| 129 |
| 121 // Base class for tests that verify device disabling behavior during OOBE, when | 130 // Base class for tests that verify device disabling behavior during OOBE, when |
| 122 // the device is not owned yet. | 131 // the device is not owned yet. |
| 123 class DeviceDisablingManagerOOBETest : public DeviceDisablingManagerTestBase { | 132 class DeviceDisablingManagerOOBETest : public DeviceDisablingManagerTestBase { |
| 124 public: | 133 public: |
| 125 DeviceDisablingManagerOOBETest(); | 134 DeviceDisablingManagerOOBETest(); |
| 126 | 135 |
| 127 // DeviceDisablingManagerTestBase: | 136 // DeviceDisablingManagerTestBase: |
| 128 void SetUp() override; | 137 void SetUp() override; |
| 129 void TearDown() override; | 138 void TearDown() override; |
| 130 | 139 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 218 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 210 switches::kDisableDeviceDisabling); | 219 switches::kDisableDeviceDisabling); |
| 211 SetDeviceDisabled(true); | 220 SetDeviceDisabled(true); |
| 212 CheckWhetherDeviceDisabledDuringOOBE(); | 221 CheckWhetherDeviceDisabledDuringOOBE(); |
| 213 EXPECT_FALSE(device_disabled()); | 222 EXPECT_FALSE(device_disabled()); |
| 214 } | 223 } |
| 215 | 224 |
| 216 // Verifies that the device is not considered disabled during OOBE when it is | 225 // Verifies that the device is not considered disabled during OOBE when it is |
| 217 // already enrolled, even if the device is marked as disabled. | 226 // already enrolled, even if the device is marked as disabled. |
| 218 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenEnterpriseOwned) { | 227 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenEnterpriseOwned) { |
| 219 UpdateInstallAttributes(kEnrollmentDomain, | 228 SetEnterpriseOwned(); |
| 220 kTestUser, | |
| 221 policy::DEVICE_MODE_ENTERPRISE); | |
| 222 SetDeviceDisabled(true); | 229 SetDeviceDisabled(true); |
| 223 CheckWhetherDeviceDisabledDuringOOBE(); | 230 CheckWhetherDeviceDisabledDuringOOBE(); |
| 224 EXPECT_FALSE(device_disabled()); | 231 EXPECT_FALSE(device_disabled()); |
| 225 } | 232 } |
| 226 | 233 |
| 227 // Verifies that the device is not considered disabled during OOBE when it is | 234 // Verifies that the device is not considered disabled during OOBE when it is |
| 228 // already owned by a consumer, even if the device is marked as disabled. | 235 // already owned by a consumer, even if the device is marked as disabled. |
| 229 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenConsumerOwned) { | 236 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenConsumerOwned) { |
| 230 UpdateInstallAttributes(std::string() /* enrollment_domain */, | 237 SetConsumerOwned(); |
| 231 std::string() /* registration_user */, | |
| 232 policy::DEVICE_MODE_CONSUMER); | |
| 233 SetDeviceDisabled(true); | 238 SetDeviceDisabled(true); |
| 234 CheckWhetherDeviceDisabledDuringOOBE(); | 239 CheckWhetherDeviceDisabledDuringOOBE(); |
| 235 EXPECT_FALSE(device_disabled()); | 240 EXPECT_FALSE(device_disabled()); |
| 236 } | 241 } |
| 237 | 242 |
| 238 // Verifies that the device is considered disabled during OOBE when it is marked | 243 // Verifies that the device is considered disabled during OOBE when it is marked |
| 239 // as disabled, device disabling is not turned off by flag and the device is not | 244 // as disabled, device disabling is not turned off by flag and the device is not |
| 240 // owned yet. | 245 // owned yet. |
| 241 TEST_F(DeviceDisablingManagerOOBETest, ShowWhenDisabledAndNotOwned) { | 246 TEST_F(DeviceDisablingManagerOOBETest, ShowWhenDisabledAndNotOwned) { |
| 242 SetDeviceDisabled(true); | 247 SetDeviceDisabled(true); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 255 DeviceDisablingManagerTest(); | 260 DeviceDisablingManagerTest(); |
| 256 | 261 |
| 257 // DeviceDisablingManagerTestBase: | 262 // DeviceDisablingManagerTestBase: |
| 258 void TearDown() override; | 263 void TearDown() override; |
| 259 void CreateDeviceDisablingManager() override; | 264 void CreateDeviceDisablingManager() override; |
| 260 void DestroyDeviceDisablingManager() override; | 265 void DestroyDeviceDisablingManager() override; |
| 261 | 266 |
| 262 // DeviceDisablingManager::Observer: | 267 // DeviceDisablingManager::Observer: |
| 263 MOCK_METHOD1(OnDisabledMessageChanged, void(const std::string&)); | 268 MOCK_METHOD1(OnDisabledMessageChanged, void(const std::string&)); |
| 264 | 269 |
| 265 void SetUnowned(); | |
| 266 void SetEnterpriseOwned(); | |
| 267 void SetConsumerOwned(); | |
| 268 void MakeCrosSettingsTrusted(); | 270 void MakeCrosSettingsTrusted(); |
| 269 | 271 |
| 270 void SetDeviceDisabled(bool disabled); | 272 void SetDeviceDisabled(bool disabled); |
| 271 void SetDisabledMessage(const std::string& disabled_message); | 273 void SetDisabledMessage(const std::string& disabled_message); |
| 272 | 274 |
| 273 private: | 275 private: |
| 274 void SimulatePolicyFetch(); | 276 void SimulatePolicyFetch(); |
| 275 | 277 |
| 276 content::TestBrowserThreadBundle thread_bundle_; | 278 content::TestBrowserThreadBundle thread_bundle_; |
| 277 chromeos::DeviceSettingsTestHelper device_settings_test_helper_; | 279 chromeos::DeviceSettingsTestHelper device_settings_test_helper_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 292 DeviceDisablingManagerTestBase::CreateDeviceDisablingManager(); | 294 DeviceDisablingManagerTestBase::CreateDeviceDisablingManager(); |
| 293 GetDeviceDisablingManager()->AddObserver(this); | 295 GetDeviceDisablingManager()->AddObserver(this); |
| 294 } | 296 } |
| 295 | 297 |
| 296 void DeviceDisablingManagerTest::DestroyDeviceDisablingManager() { | 298 void DeviceDisablingManagerTest::DestroyDeviceDisablingManager() { |
| 297 if (GetDeviceDisablingManager()) | 299 if (GetDeviceDisablingManager()) |
| 298 GetDeviceDisablingManager()->RemoveObserver(this); | 300 GetDeviceDisablingManager()->RemoveObserver(this); |
| 299 DeviceDisablingManagerTestBase::DestroyDeviceDisablingManager(); | 301 DeviceDisablingManagerTestBase::DestroyDeviceDisablingManager(); |
| 300 } | 302 } |
| 301 | 303 |
| 302 void DeviceDisablingManagerTest::SetUnowned() { | |
| 303 UpdateInstallAttributes(std::string() /* enrollment_domain */, | |
| 304 std::string() /* registration_user */, | |
| 305 policy::DEVICE_MODE_NOT_SET); | |
| 306 } | |
| 307 | |
| 308 void DeviceDisablingManagerTest::SetEnterpriseOwned() { | |
| 309 UpdateInstallAttributes(kEnrollmentDomain, | |
| 310 kTestUser, | |
| 311 policy::DEVICE_MODE_ENTERPRISE); | |
| 312 } | |
| 313 | |
| 314 void DeviceDisablingManagerTest::SetConsumerOwned() { | |
| 315 UpdateInstallAttributes(std::string() /* enrollment_domain */, | |
| 316 std::string() /* registration_user */, | |
| 317 policy::DEVICE_MODE_CONSUMER); | |
| 318 } | |
| 319 | |
| 320 void DeviceDisablingManagerTest::MakeCrosSettingsTrusted() { | 304 void DeviceDisablingManagerTest::MakeCrosSettingsTrusted() { |
| 321 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util( | 305 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util( |
| 322 new ownership::MockOwnerKeyUtil); | 306 new ownership::MockOwnerKeyUtil); |
| 323 owner_key_util->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); | 307 owner_key_util->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); |
| 324 chromeos::DeviceSettingsService::Get()->SetSessionManager( | 308 chromeos::DeviceSettingsService::Get()->SetSessionManager( |
| 325 &device_settings_test_helper_, | 309 &device_settings_test_helper_, |
| 326 owner_key_util); | 310 owner_key_util); |
| 327 SimulatePolicyFetch(); | 311 SimulatePolicyFetch(); |
| 328 } | 312 } |
| 329 | 313 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation()); | 494 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation()); |
| 511 | 495 |
| 512 // Not enterprise owned, disabled by flag. | 496 // Not enterprise owned, disabled by flag. |
| 513 SetUnowned(); | 497 SetUnowned(); |
| 514 EXPECT_FALSE( | 498 EXPECT_FALSE( |
| 515 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation()); | 499 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation()); |
| 516 } | 500 } |
| 517 | 501 |
| 518 } // namespace system | 502 } // namespace system |
| 519 } // namespace chromeos | 503 } // namespace chromeos |
| OLD | NEW |