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

Side by Side Diff: chrome/browser/chromeos/system/device_disabling_manager_unittest.cc

Issue 711433002: Enable device disabling during normal operation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_4_425574_add_device_disabling_manager
Patch Set: Address one more comment I had missed. Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
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/memory/scoped_ptr.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/prefs/testing_pref_service.h" 12 #include "base/prefs/testing_pref_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "chrome/browser/browser_process_platform_part.h" 14 #include "chrome/browser/browser_process_platform_part.h"
15 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
16 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" 17 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
18 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
17 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" 19 #include "chrome/browser/chromeos/policy/server_backed_device_state.h"
18 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" 20 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
21 #include "chrome/browser/chromeos/settings/device_settings_service.h"
22 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
19 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
21 #include "chromeos/chromeos_switches.h" 25 #include "chromeos/chromeos_switches.h"
26 #include "components/ownership/mock_owner_key_util.h"
22 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 27 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
28 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "policy/proto/device_management_backend.pb.h"
30 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
24 32
33 using testing::_;
34 using testing::Mock;
35
25 namespace chromeos { 36 namespace chromeos {
26 namespace system { 37 namespace system {
27 38
28 namespace { 39 namespace {
29 40
30 const char kDisabledMessage[] = "Device disabled."; 41 const char kTestUser[] = "user@example.com";
42 const char kDisabledMessage1[] = "Device disabled 1.";
43 const char kDisabledMessage2[] = "Device disabled 2.";
31 44
32 } 45 }
33 46
34 class DeviceDisablingManagerTest : public testing::Test { 47 class DeviceDisablingManagerTestBase : public testing::Test,
48 public DeviceDisablingManager::Delegate {
35 public: 49 public:
36 DeviceDisablingManagerTest(); 50 DeviceDisablingManagerTestBase();
37 51
38 // testing::Test: 52 // testing::Test:
53 void TearDown() override;
54
55 virtual void CreateDeviceDisablingManager();
56 virtual void DestroyDeviceDisablingManager();
57
58 void SetRegistrationUser(const std::string& registration_user);
59 void SetDeviceMode(policy::DeviceMode device_mode);
60 void LogIn();
61
62 // DeviceDisablingManager::Delegate:
63 MOCK_METHOD0(RestartToLoginScreen, void());
64 MOCK_METHOD0(ShowDeviceDisabledScreen, void());
65
66 DeviceDisablingManager* GetDeviceDisablingManager() {
67 return device_disabling_manager_.get();
68 }
69
70 private:
71 policy::ScopedStubEnterpriseInstallAttributes install_attributes_;
72 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
73 chromeos::ScopedTestCrosSettings test_cros_settings_;
74 FakeUserManager fake_user_manager_;
75 scoped_ptr<DeviceDisablingManager> device_disabling_manager_;
76
77 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManagerTestBase);
78 };
79
80 DeviceDisablingManagerTestBase::DeviceDisablingManagerTestBase()
81 : install_attributes_("", "", "", policy::DEVICE_MODE_NOT_SET) {
82 }
83
84 void DeviceDisablingManagerTestBase::TearDown() {
85 DestroyDeviceDisablingManager();
86 }
87
88 void DeviceDisablingManagerTestBase::CreateDeviceDisablingManager() {
89 device_disabling_manager_.reset(new DeviceDisablingManager(
90 this,
91 CrosSettings::Get(),
92 &fake_user_manager_));
93 }
94
95 void DeviceDisablingManagerTestBase::DestroyDeviceDisablingManager() {
96 device_disabling_manager_.reset();
97 }
98
99 void DeviceDisablingManagerTestBase::SetRegistrationUser(
100 const std::string& registration_user) {
101 reinterpret_cast<policy::StubEnterpriseInstallAttributes*>(
102 TestingBrowserProcess::GetGlobal()->platform_part()->
103 browser_policy_connector_chromeos()->GetInstallAttributes())->
104 SetRegistrationUser(registration_user);
105 }
106
107 void DeviceDisablingManagerTestBase::SetDeviceMode(
108 policy::DeviceMode device_mode) {
109 reinterpret_cast<policy::StubEnterpriseInstallAttributes*>(
110 TestingBrowserProcess::GetGlobal()->platform_part()->
111 browser_policy_connector_chromeos()->GetInstallAttributes())->
112 SetMode(device_mode);
113 }
114
115 void DeviceDisablingManagerTestBase::LogIn() {
116 fake_user_manager_.AddUser(kTestUser);
117 }
118
119 // Base class for tests that verify device disabling behavior during OOBE, when
120 // the device is not owned yet.
121 class DeviceDisablingManagerOOBETest : public DeviceDisablingManagerTestBase {
122 public:
123 DeviceDisablingManagerOOBETest();
124
125 // DeviceDisablingManagerTestBase:
39 void SetUp() override; 126 void SetUp() override;
40 void TearDown() override; 127 void TearDown() override;
41 128
42 bool device_disabled() const { return device_disabled_; } 129 bool device_disabled() const { return device_disabled_; }
43 const std::string& GetDisabledMessage() const;
44 130
45 void CheckWhetherDeviceDisabledDuringOOBE(); 131 void CheckWhetherDeviceDisabledDuringOOBE();
46 132
47 void SetDeviceDisabled(bool disabled); 133 void SetDeviceDisabled(bool disabled);
48 void SetDeviceMode(policy::DeviceMode device_mode);
49 134
50 private: 135 private:
51 void OnDeviceDisabledChecked(bool device_disabled); 136 void OnDeviceDisabledChecked(bool device_disabled);
52 137
53 policy::ScopedStubEnterpriseInstallAttributes install_attributes_;
54 TestingPrefServiceSimple local_state_; 138 TestingPrefServiceSimple local_state_;
55 139
56 scoped_ptr<DeviceDisablingManager> device_disabling_manager_;
57
58 base::RunLoop run_loop_; 140 base::RunLoop run_loop_;
59 bool device_disabled_; 141 bool device_disabled_;
60 142
61 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManagerTest); 143 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManagerOOBETest);
62 }; 144 };
63 145
64 DeviceDisablingManagerTest::DeviceDisablingManagerTest() 146 DeviceDisablingManagerOOBETest::DeviceDisablingManagerOOBETest()
65 : install_attributes_("", "", "", policy::DEVICE_MODE_NOT_SET), 147 : device_disabled_(false) {
66 device_disabled_(false) { 148 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
149 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
67 } 150 }
68 151
69 void DeviceDisablingManagerTest::SetUp() { 152 void DeviceDisablingManagerOOBETest::SetUp() {
70 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); 153 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
71 policy::DeviceCloudPolicyManagerChromeOS::RegisterPrefs( 154 policy::DeviceCloudPolicyManagerChromeOS::RegisterPrefs(
72 local_state_.registry()); 155 local_state_.registry());
73 156 CreateDeviceDisablingManager();
74 device_disabling_manager_.reset(new DeviceDisablingManager(
75 TestingBrowserProcess::GetGlobal()->platform_part()->
76 browser_policy_connector_chromeos()));
77 } 157 }
78 158
79 void DeviceDisablingManagerTest::TearDown() { 159 void DeviceDisablingManagerOOBETest::TearDown() {
160 DeviceDisablingManagerTestBase::TearDown();
80 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); 161 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
81 } 162 }
82 163
83 const std::string& DeviceDisablingManagerTest::GetDisabledMessage() const { 164 void DeviceDisablingManagerOOBETest::CheckWhetherDeviceDisabledDuringOOBE() {
84 return device_disabling_manager_->disabled_message(); 165 GetDeviceDisablingManager()->CheckWhetherDeviceDisabledDuringOOBE(
85 166 base::Bind(&DeviceDisablingManagerOOBETest::OnDeviceDisabledChecked,
86 }
87
88 void DeviceDisablingManagerTest::CheckWhetherDeviceDisabledDuringOOBE() {
89 device_disabling_manager_->CheckWhetherDeviceDisabledDuringOOBE(
90 base::Bind(&DeviceDisablingManagerTest::OnDeviceDisabledChecked,
91 base::Unretained(this))); 167 base::Unretained(this)));
92 run_loop_.Run(); 168 run_loop_.Run();
93 } 169 }
94 170
95 void DeviceDisablingManagerTest::SetDeviceDisabled(bool disabled) { 171 void DeviceDisablingManagerOOBETest::SetDeviceDisabled(bool disabled) {
96 DictionaryPrefUpdate dict(&local_state_, prefs::kServerBackedDeviceState); 172 DictionaryPrefUpdate dict(&local_state_, prefs::kServerBackedDeviceState);
97 if (disabled) { 173 if (disabled) {
98 dict->SetString(policy::kDeviceStateRestoreMode, 174 dict->SetString(policy::kDeviceStateRestoreMode,
99 policy::kDeviceStateRestoreModeDisabled); 175 policy::kDeviceStateRestoreModeDisabled);
100 } else { 176 } else {
101 dict->Remove(policy::kDeviceStateRestoreMode, nullptr); 177 dict->Remove(policy::kDeviceStateRestoreMode, nullptr);
102 } 178 }
103 dict->SetString(policy::kDeviceStateDisabledMessage, kDisabledMessage); 179 dict->SetString(policy::kDeviceStateDisabledMessage, kDisabledMessage1);
104 } 180 }
105 181
106 void DeviceDisablingManagerTest::SetDeviceMode(policy::DeviceMode device_mode) { 182 void DeviceDisablingManagerOOBETest::OnDeviceDisabledChecked(
107 reinterpret_cast<policy::StubEnterpriseInstallAttributes*>( 183 bool device_disabled) {
108 TestingBrowserProcess::GetGlobal()->platform_part()->
109 browser_policy_connector_chromeos()->GetInstallAttributes())->
110 SetMode(device_mode);
111 }
112
113 void DeviceDisablingManagerTest::OnDeviceDisabledChecked(bool device_disabled) {
114 device_disabled_ = device_disabled; 184 device_disabled_ = device_disabled;
115 run_loop_.Quit(); 185 run_loop_.Quit();
116 } 186 }
117 187
118 // Verifies that the device is not considered disabled during OOBE by default. 188 // Verifies that the device is not considered disabled during OOBE by default.
119 TEST_F(DeviceDisablingManagerTest, NotDisabledByDefault) { 189 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledByDefault) {
120 CheckWhetherDeviceDisabledDuringOOBE(); 190 CheckWhetherDeviceDisabledDuringOOBE();
121 EXPECT_FALSE(device_disabled()); 191 EXPECT_FALSE(device_disabled());
122 } 192 }
123 193
124 // Verifies that the device is not considered disabled during OOBE when it is 194 // Verifies that the device is not considered disabled during OOBE when it is
125 // explicitly marked as not disabled. 195 // explicitly marked as not disabled.
126 TEST_F(DeviceDisablingManagerTest, NotDisabledWhenExplicitlyNotDisabled) { 196 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenExplicitlyNotDisabled) {
127 SetDeviceDisabled(false); 197 SetDeviceDisabled(false);
128 CheckWhetherDeviceDisabledDuringOOBE(); 198 CheckWhetherDeviceDisabledDuringOOBE();
129 EXPECT_FALSE(device_disabled()); 199 EXPECT_FALSE(device_disabled());
130 } 200 }
131 201
132 // Verifies that the device is not considered disabled during OOBE when device 202 // Verifies that the device is not considered disabled during OOBE when device
133 // disabling is turned off by flag, even if the device is marked as disabled. 203 // disabling is turned off by flag, even if the device is marked as disabled.
134 TEST_F(DeviceDisablingManagerTest, NotDisabledWhenTurnedOffByFlag) { 204 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenTurnedOffByFlag) {
135 CommandLine::ForCurrentProcess()->AppendSwitch( 205 CommandLine::ForCurrentProcess()->AppendSwitch(
136 switches::kDisableDeviceDisabling); 206 switches::kDisableDeviceDisabling);
137 SetDeviceDisabled(true); 207 SetDeviceDisabled(true);
138 CheckWhetherDeviceDisabledDuringOOBE(); 208 CheckWhetherDeviceDisabledDuringOOBE();
139 EXPECT_FALSE(device_disabled()); 209 EXPECT_FALSE(device_disabled());
140 } 210 }
141 211
142 // Verifies that the device is not considered disabled during OOBE when it is 212 // Verifies that the device is not considered disabled during OOBE when it is
143 // already enrolled, even if the device is marked as disabled. 213 // already enrolled, even if the device is marked as disabled.
144 TEST_F(DeviceDisablingManagerTest, DoNotShowWhenEnterpriseOwned) { 214 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenEnterpriseOwned) {
145 SetDeviceMode(policy::DEVICE_MODE_ENTERPRISE); 215 SetDeviceMode(policy::DEVICE_MODE_ENTERPRISE);
146 SetDeviceDisabled(true); 216 SetDeviceDisabled(true);
147 CheckWhetherDeviceDisabledDuringOOBE(); 217 CheckWhetherDeviceDisabledDuringOOBE();
148 EXPECT_FALSE(device_disabled()); 218 EXPECT_FALSE(device_disabled());
149 } 219 }
150 220
151 // Verifies that the device is not considered disabled during OOBE when it is 221 // Verifies that the device is not considered disabled during OOBE when it is
152 // already owned by a consumer, even if the device is marked as disabled. 222 // already owned by a consumer, even if the device is marked as disabled.
153 TEST_F(DeviceDisablingManagerTest, DoNotShowWhenConsumerOwned) { 223 TEST_F(DeviceDisablingManagerOOBETest, NotDisabledWhenConsumerOwned) {
154 SetDeviceMode(policy::DEVICE_MODE_CONSUMER); 224 SetDeviceMode(policy::DEVICE_MODE_CONSUMER);
155 SetDeviceDisabled(true); 225 SetDeviceDisabled(true);
156 CheckWhetherDeviceDisabledDuringOOBE(); 226 CheckWhetherDeviceDisabledDuringOOBE();
157 EXPECT_FALSE(device_disabled()); 227 EXPECT_FALSE(device_disabled());
158 } 228 }
159 229
160 // Verifies that the device is considered disabled during OOBE when it is marked 230 // Verifies that the device is considered disabled during OOBE when it is marked
161 // as disabled, device disabling is not turned off by flag and the device is not 231 // as disabled, device disabling is not turned off by flag and the device is not
162 // owned yet. 232 // owned yet.
163 TEST_F(DeviceDisablingManagerTest, ShowWhenDisabledAndNotOwned) { 233 TEST_F(DeviceDisablingManagerOOBETest, ShowWhenDisabledAndNotOwned) {
164 SetDeviceDisabled(true); 234 SetDeviceDisabled(true);
165 CheckWhetherDeviceDisabledDuringOOBE(); 235 CheckWhetherDeviceDisabledDuringOOBE();
166 EXPECT_TRUE(device_disabled()); 236 EXPECT_TRUE(device_disabled());
167 EXPECT_EQ(kDisabledMessage, GetDisabledMessage()); 237 EXPECT_EQ(kDisabledMessage1, GetDeviceDisablingManager()->disabled_message());
238 }
239
240 // Base class for tests that verify device disabling behavior once the device is
241 // owned.
242 class DeviceDisablingManagerTest : public DeviceDisablingManagerTestBase,
243 public DeviceDisablingManager::Observer {
244 public:
245 DeviceDisablingManagerTest();
246
247 // DeviceDisablingManagerTestBase:
248 void TearDown() override;
249 void CreateDeviceDisablingManager() override;
250 void DestroyDeviceDisablingManager() override;
251
252 //DeviceDisablingManager::Observer:
253 MOCK_METHOD1(OnDisabledMessageChanged, void(const std::string&));
254
255 void SetUnowned();
256 void SetEnterpriseOwned();
257 void SetConsumerOwned();
258 void MakeCrosSettingsTrusted();
259
260 void SetDeviceDisabled(bool disabled);
261 void SetDisabledMessage(const std::string& disabled_message);
262
263 private:
264 void SimulatePolicyFetch();
265
266 content::TestBrowserThreadBundle thread_bundle_;
267 chromeos::DeviceSettingsTestHelper device_settings_test_helper_;
268 policy::DevicePolicyBuilder device_policy_;
269
270 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManagerTest);
271 };
272
273 DeviceDisablingManagerTest::DeviceDisablingManagerTest() {
274 }
275
276 void DeviceDisablingManagerTest::TearDown() {
277 chromeos::DeviceSettingsService::Get()->UnsetSessionManager();
278 DeviceDisablingManagerTestBase::TearDown();
279 }
280
281 void DeviceDisablingManagerTest::CreateDeviceDisablingManager() {
282 DeviceDisablingManagerTestBase::CreateDeviceDisablingManager();
283 GetDeviceDisablingManager()->AddObserver(this);
284 }
285
286 void DeviceDisablingManagerTest::DestroyDeviceDisablingManager() {
287 if (GetDeviceDisablingManager())
288 GetDeviceDisablingManager()->RemoveObserver(this);
289 DeviceDisablingManagerTestBase::DestroyDeviceDisablingManager();
290 }
291
292 void DeviceDisablingManagerTest::SetUnowned() {
293 SetRegistrationUser(std::string());
294 SetDeviceMode(policy::DEVICE_MODE_NOT_SET);
295 }
296
297 void DeviceDisablingManagerTest::SetEnterpriseOwned() {
298 SetRegistrationUser(kTestUser);
299 SetDeviceMode(policy::DEVICE_MODE_ENTERPRISE);
300 }
301
302 void DeviceDisablingManagerTest::SetConsumerOwned() {
303 SetDeviceMode(policy::DEVICE_MODE_CONSUMER);
304 }
305
306 void DeviceDisablingManagerTest::MakeCrosSettingsTrusted() {
307 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util(
308 new ownership::MockOwnerKeyUtil);
309 owner_key_util->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey());
310 chromeos::DeviceSettingsService::Get()->SetSessionManager(
311 &device_settings_test_helper_,
312 owner_key_util);
313 SimulatePolicyFetch();
314 }
315
316 void DeviceDisablingManagerTest::SetDeviceDisabled(bool disabled) {
317 if (disabled) {
318 device_policy_.policy_data().mutable_device_state()->set_device_mode(
319 enterprise_management::DeviceState::DEVICE_MODE_DISABLED);
320 } else {
321 device_policy_.policy_data().mutable_device_state()->clear_device_mode();
322 }
323 SimulatePolicyFetch();
324 }
325
326 void DeviceDisablingManagerTest::SetDisabledMessage(
327 const std::string& disabled_message) {
328 device_policy_.policy_data().mutable_device_state()->
329 mutable_disabled_state()->set_message(disabled_message);
330 SimulatePolicyFetch();
331 }
332
333 void DeviceDisablingManagerTest::SimulatePolicyFetch() {
334 device_policy_.Build();
335 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
336 chromeos::DeviceSettingsService::Get()->OwnerKeySet(true);
337 device_settings_test_helper_.Flush();
338 }
339
340 // Verifies that the device is not considered disabled by default when it is
341 // enrolled for enterprise management.
342 TEST_F(DeviceDisablingManagerTest, NotDisabledByDefault) {
343 SetEnterpriseOwned();
344 MakeCrosSettingsTrusted();
345
346 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
347 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
348 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
349 CreateDeviceDisablingManager();
350 }
351
352 // Verifies that the device is not considered disabled when it is explicitly
353 // marked as not disabled.
354 TEST_F(DeviceDisablingManagerTest, NotDisabledWhenExplicitlyNotDisabled) {
355 SetEnterpriseOwned();
356 MakeCrosSettingsTrusted();
357 SetDeviceDisabled(false);
358
359 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
360 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
361 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
362 CreateDeviceDisablingManager();
363 }
364
365 // Verifies that the device is not considered disabled when device disabling is
366 // turned off by flag, even if the device is marked as disabled.
367 TEST_F(DeviceDisablingManagerTest, NotDisabledWhenTurnedOffByFlag) {
368 CommandLine::ForCurrentProcess()->AppendSwitch(
369 switches::kDisableDeviceDisabling);
370 SetEnterpriseOwned();
371 MakeCrosSettingsTrusted();
372 SetDeviceDisabled(true);
373
374 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
375 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
376 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
377 CreateDeviceDisablingManager();
378 }
379
380 // Verifies that the device is not considered disabled when it is owned by a
381 // consumer, even if the device is marked as disabled.
382 TEST_F(DeviceDisablingManagerTest, NotDisabledWhenConsumerOwned) {
383 SetConsumerOwned();
384 MakeCrosSettingsTrusted();
385 SetDeviceDisabled(true);
386
387 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
388 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
389 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
390 CreateDeviceDisablingManager();
391 }
392
393 // Verifies that the device disabled screen is shown immediately when the device
394 // is already marked as disabled on start-up.
395 TEST_F(DeviceDisablingManagerTest, DisabledOnLoginScreen) {
396 SetEnterpriseOwned();
397 MakeCrosSettingsTrusted();
398 SetDisabledMessage(kDisabledMessage1);
399 SetDeviceDisabled(true);
400
401 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
402 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(1);
403 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
404 CreateDeviceDisablingManager();
405 EXPECT_EQ(kDisabledMessage1, GetDeviceDisablingManager()->disabled_message());
406 }
407
408 // Verifies that the device disabled screen is shown immediately when the device
409 // becomes disabled while the login screen is showing. Also verifies that Chrome
410 // restarts when the device becomes enabled again.
411 TEST_F(DeviceDisablingManagerTest, DisableAndReEnableOnLoginScreen) {
412 SetEnterpriseOwned();
413 MakeCrosSettingsTrusted();
414 SetDisabledMessage(kDisabledMessage1);
415
416 // Verify that initially, the disabled screen is not shown and Chrome does not
417 // restart.
418 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
419 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
420 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
421 CreateDeviceDisablingManager();
422 Mock::VerifyAndClearExpectations(this);
423
424 // Mark the device as disabled. Verify that the device disabled screen is
425 // shown.
426 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
427 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(1);
428 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
429 EXPECT_CALL(*this, OnDisabledMessageChanged(kDisabledMessage1)).Times(1);
430 SetDeviceDisabled(true);
431 Mock::VerifyAndClearExpectations(this);
432 EXPECT_EQ(kDisabledMessage1, GetDeviceDisablingManager()->disabled_message());
433
434 // Update the disabled message. Verify that the device disabled screen is
435 // updated.
436 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
437 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
438 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
439 EXPECT_CALL(*this, OnDisabledMessageChanged(kDisabledMessage2)).Times(1);
440 SetDisabledMessage(kDisabledMessage2);
441 Mock::VerifyAndClearExpectations(this);
442 EXPECT_EQ(kDisabledMessage2, GetDeviceDisablingManager()->disabled_message());
443
444 // Mark the device as enabled again. Verify that Chrome restarts.
445 EXPECT_CALL(*this, RestartToLoginScreen()).Times(1);
446 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
447 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
448 SetDeviceDisabled(false);
449 }
450
451 // Verifies that Chrome restarts when the device becomes disabled while a
452 // session is in progress.
453 TEST_F(DeviceDisablingManagerTest, DisableDuringSession) {
454 SetEnterpriseOwned();
455 MakeCrosSettingsTrusted();
456 SetDisabledMessage(kDisabledMessage1);
457 LogIn();
458
459 // Verify that initially, the disabled screen is not shown and Chrome does not
460 // restart.
461 EXPECT_CALL(*this, RestartToLoginScreen()).Times(0);
462 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
463 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
464 CreateDeviceDisablingManager();
465 Mock::VerifyAndClearExpectations(this);
466
467 // Mark the device as disabled. Verify that Chrome restarts.
468 EXPECT_CALL(*this, RestartToLoginScreen()).Times(1);
469 EXPECT_CALL(*this, ShowDeviceDisabledScreen()).Times(0);
470 EXPECT_CALL(*this, OnDisabledMessageChanged(_)).Times(0);
471 EXPECT_CALL(*this, OnDisabledMessageChanged(kDisabledMessage1)).Times(1);
472 SetDeviceDisabled(true);
473 }
474
475 // Verifies that the HonorDeviceDisablingDuringNormalOperation() method returns
476 // true iff the device is enterprise enrolled and device disabling is not turned
477 // off by flag.
478 TEST_F(DeviceDisablingManagerTest, HonorDeviceDisablingDuringNormalOperation) {
479 // Not enterprise owned, not disabled by flag.
480 EXPECT_FALSE(
481 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation());
482
483 // Enterprise owned, not disabled by flag.
484 SetEnterpriseOwned();
485 EXPECT_TRUE(
486 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation());
487
488 // Enterprise owned, disabled by flag.
489 CommandLine::ForCurrentProcess()->AppendSwitch(
490 switches::kDisableDeviceDisabling);
491 EXPECT_FALSE(
492 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation());
493
494 // Not enterprise owned, disabled by flag.
495 SetUnowned();
496 EXPECT_FALSE(
497 DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation());
168 } 498 }
169 499
170 } // namespace system 500 } // namespace system
171 } // namespace chromeos 501 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698