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

Side by Side Diff: chrome/browser/chromeos/policy/login_screen_default_policy_browsertest.cc

Issue 16658015: Add device policies to control accessibility settings on the login screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebaased. Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "ash/magnifier/magnifier_constants.h"
8 #include "base/basictypes.h"
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/command_line.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/scoped_temp_dir.h"
14 #include "base/location.h"
15 #include "base/message_loop.h"
16 #include "base/prefs/pref_change_registrar.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/run_loop.h"
19 #include "base/values.h"
20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
21 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
22 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
23 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
25 #include "chrome/browser/chromeos/settings/device_settings_service.h"
26 #include "chrome/browser/lifetime/application_lifetime.h"
27 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/profiles/profile_manager.h"
30 #include "chrome/common/pref_names.h"
31 #include "chromeos/chromeos_switches.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33
34 namespace em = enterprise_management;
35
36 namespace policy {
37
38 namespace {
39
40 const em::AccessibilitySettingsProto_ScreenMagnifierType kFullScreenMagnifier =
41 em::AccessibilitySettingsProto_ScreenMagnifierType_SCREEN_MAGNIFIER_TYPE_FULL;
Mattias Nissler (ping if slow) 2013/06/20 18:42:10 nit: indentation
bartfab (slow) 2013/06/20 19:35:58 Done.
42
43 // Spins the loop until a notification is received from |prefs| that the value
44 // of |pref_name| has changed. If the notification is received before Wait()
45 // has been called, Wait() returns immediately and no loop is spun.
46 class PrefChangeWatcher {
47 public:
48 PrefChangeWatcher(const char* pref_name, PrefService* prefs);
49
50 void Wait();
51
52 void OnPrefChange();
53
54 private:
55 bool pref_changed_;
56
57 base::RunLoop run_loop_;
58 PrefChangeRegistrar registrar_;
59
60 DISALLOW_COPY_AND_ASSIGN(PrefChangeWatcher);
61 };
62
63 PrefChangeWatcher::PrefChangeWatcher(const char* pref_name,
64 PrefService* prefs)
65 : pref_changed_(false) {
66 registrar_.Init(prefs);
67 registrar_.Add(pref_name, base::Bind(&PrefChangeWatcher::OnPrefChange,
68 base::Unretained(this)));
69 }
70
71 void PrefChangeWatcher::Wait() {
72 if (!pref_changed_)
73 run_loop_.Run();
74 }
75
76 void PrefChangeWatcher::OnPrefChange() {
77 pref_changed_ = true;
78 run_loop_.Quit();
79 }
80
81 } // namespace
82
83 class LoginScreenDefaultPolicyBrowsertestBase
84 : public DevicePolicyCrosBrowserTest {
85 protected:
86 LoginScreenDefaultPolicyBrowsertestBase();
87 virtual ~LoginScreenDefaultPolicyBrowsertestBase();
88
89 // DevicePolicyCrosBrowserTest:
90 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
91 virtual void SetUpOnMainThread() OVERRIDE;
92
93 void RefreshDevicePolicyAndWaitForPrefChange(const char* pref_name);
94
95 Profile* login_profile_;
96
97 private:
98 DISALLOW_COPY_AND_ASSIGN(LoginScreenDefaultPolicyBrowsertestBase);
99 };
100
101 class LoginScreenDefaultPolicyLoginScreenBrowsertest
102 : public LoginScreenDefaultPolicyBrowsertestBase {
103 protected:
104 LoginScreenDefaultPolicyLoginScreenBrowsertest();
105 virtual ~LoginScreenDefaultPolicyLoginScreenBrowsertest();
106
107 // LoginScreenDefaultPolicyBrowsertestBase:
108 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
109 virtual void SetUpOnMainThread() OVERRIDE;
110 virtual void CleanUpOnMainThread() OVERRIDE;
111
112 void VerifyPrefFollowsRecommendation(const char* pref_name,
113 const base::Value& recommended_value);
114
115 private:
116 DISALLOW_COPY_AND_ASSIGN(LoginScreenDefaultPolicyLoginScreenBrowsertest);
117 };
118
119 class LoginScreenDefaultPolicyInSessionBrowsertest
120 : public LoginScreenDefaultPolicyBrowsertestBase {
121 protected:
122 LoginScreenDefaultPolicyInSessionBrowsertest();
123 virtual ~LoginScreenDefaultPolicyInSessionBrowsertest();
124
125 // LoginScreenDefaultPolicyBrowsertestBase:
126 virtual void SetUpOnMainThread() OVERRIDE;
127
128 void VerifyPrefFollowsDefault(const char* pref_name);
129
130 private:
131 DISALLOW_COPY_AND_ASSIGN(LoginScreenDefaultPolicyInSessionBrowsertest);
132 };
133
134 LoginScreenDefaultPolicyBrowsertestBase::
135 LoginScreenDefaultPolicyBrowsertestBase() : login_profile_(NULL) {
136 }
137
138 LoginScreenDefaultPolicyBrowsertestBase::
139 ~LoginScreenDefaultPolicyBrowsertestBase() {
140 }
141
142 void LoginScreenDefaultPolicyBrowsertestBase::
143 SetUpInProcessBrowserTestFixture() {
144 InstallOwnerKey();
145 MarkAsEnterpriseOwned(&temp_dir_);
146 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
147 }
148
149 void LoginScreenDefaultPolicyBrowsertestBase::SetUpOnMainThread() {
150 DevicePolicyCrosBrowserTest::SetUpOnMainThread();
151 login_profile_ = chromeos::ProfileHelper::GetSigninProfile();
152 ASSERT_TRUE(login_profile_);
153 }
154
155 void LoginScreenDefaultPolicyBrowsertestBase::
156 RefreshDevicePolicyAndWaitForPrefChange(const char* pref_name) {
157 PrefChangeWatcher watcher(pref_name, login_profile_->GetPrefs());
158 RefreshDevicePolicy();
159 watcher.Wait();
160 }
161
162 LoginScreenDefaultPolicyLoginScreenBrowsertest::
163 LoginScreenDefaultPolicyLoginScreenBrowsertest() {
164 }
165
166 LoginScreenDefaultPolicyLoginScreenBrowsertest::
167 ~LoginScreenDefaultPolicyLoginScreenBrowsertest() {
168 }
169
170 void LoginScreenDefaultPolicyLoginScreenBrowsertest::SetUpCommandLine(
171 CommandLine* command_line) {
172 LoginScreenDefaultPolicyBrowsertestBase::SetUpCommandLine(command_line);
173 command_line->AppendSwitch(chromeos::switches::kLoginManager);
174 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
175 }
176
177 void LoginScreenDefaultPolicyLoginScreenBrowsertest::SetUpOnMainThread() {
178 LoginScreenDefaultPolicyBrowsertestBase::SetUpOnMainThread();
179
180 // Set the login screen profile.
181 chromeos::AccessibilityManager* accessibility_manager =
182 chromeos::AccessibilityManager::Get();
183 ASSERT_TRUE(accessibility_manager);
184 accessibility_manager->SetProfileForTest(
185 chromeos::ProfileHelper::GetSigninProfile());
186
187 chromeos::MagnificationManager* magnification_manager =
188 chromeos::MagnificationManager::Get();
189 ASSERT_TRUE(magnification_manager);
190 magnification_manager->SetProfileForTest(
191 chromeos::ProfileHelper::GetSigninProfile());
192 }
193
194 void LoginScreenDefaultPolicyLoginScreenBrowsertest::CleanUpOnMainThread() {
195 base::MessageLoop::current()->PostTask(FROM_HERE,
196 base::Bind(&chrome::AttemptExit));
197 base::RunLoop().RunUntilIdle();
198 LoginScreenDefaultPolicyBrowsertestBase::CleanUpOnMainThread();
199 }
200
201 void LoginScreenDefaultPolicyLoginScreenBrowsertest
202 ::VerifyPrefFollowsRecommendation(
Mattias Nissler (ping if slow) 2013/06/20 18:42:10 nit: The :: should go on the line before.
bartfab (slow) 2013/06/20 19:35:58 Done.
203 const char* pref_name,
204 const base::Value& recommended_value) {
205 const PrefService::Preference* pref =
206 login_profile_->GetPrefs()->FindPreference(pref_name);
207 ASSERT_TRUE(pref);
208 EXPECT_FALSE(pref->IsManaged());
209 EXPECT_FALSE(pref->IsDefaultValue());
210 EXPECT_TRUE(base::Value::Equals(&recommended_value, pref->GetValue()));
211 EXPECT_TRUE(base::Value::Equals(&recommended_value,
212 pref->GetRecommendedValue()));
213 }
214
215 LoginScreenDefaultPolicyInSessionBrowsertest::
216 LoginScreenDefaultPolicyInSessionBrowsertest() {
217 }
218
219 LoginScreenDefaultPolicyInSessionBrowsertest::
220 ~LoginScreenDefaultPolicyInSessionBrowsertest() {
221 }
222
223 void LoginScreenDefaultPolicyInSessionBrowsertest::SetUpOnMainThread() {
224 LoginScreenDefaultPolicyBrowsertestBase::SetUpOnMainThread();
225
226 // Tell the DeviceSettingsService that there is no local owner.
227 chromeos::DeviceSettingsService::Get()->SetUsername(std::string());
228 }
229
230 void LoginScreenDefaultPolicyInSessionBrowsertest::VerifyPrefFollowsDefault(
231 const char* pref_name) {
232 Profile* profile = ProfileManager::GetDefaultProfile();
233 ASSERT_TRUE(profile);
234 const PrefService::Preference* pref =
235 profile->GetPrefs()->FindPreference(pref_name);
236 ASSERT_TRUE(pref);
237 EXPECT_FALSE(pref->IsManaged());
238 EXPECT_TRUE(pref->IsDefaultValue());
239 EXPECT_FALSE(pref->GetRecommendedValue());
240 }
241
242 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
243 DeviceLoginScreenDefaultLargeCursorEnabled) {
244 // Verifies that the default state of the large cursor accessibility feature
245 // on the login screen can be controlled through device policy.
246
247 // Enable the large cursor through device policy and wait for the change to
248 // take effect.
249 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
250 proto.mutable_accessibility_settings()->
251 set_login_screen_default_large_cursor_enabled(true);
252 RefreshDevicePolicyAndWaitForPrefChange(prefs::kLargeCursorEnabled);
253
254 // Verify that the pref which controls the large cursor in the login profile
255 // has changed to the policy-supplied default.
256 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled,
257 base::FundamentalValue(true));
258
259 // Verify that the large cursor is enabled.
260 chromeos::AccessibilityManager* accessibility_manager =
261 chromeos::AccessibilityManager::Get();
262 ASSERT_TRUE(accessibility_manager);
263 EXPECT_TRUE(accessibility_manager->IsLargeCursorEnabled());
264 }
265
266 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
267 DeviceLoginScreenDefaultSpokenFeedbackEnabled) {
268 // Verifies that the default state of the spoken feedback accessibility
269 // feature on the login screen can be controlled through device policy.
270
271 // Enable spoken feedback through device policy and wait for the change to
272 // take effect.
273 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
274 proto.mutable_accessibility_settings()->
275 set_login_screen_default_spoken_feedback_enabled(true);
276 RefreshDevicePolicyAndWaitForPrefChange(prefs::kSpokenFeedbackEnabled);
277
278 // Verify that the pref which controls spoken feedback in the login profile
279 // has changed to the policy-supplied default.
280 VerifyPrefFollowsRecommendation(prefs::kSpokenFeedbackEnabled,
281 base::FundamentalValue(true));
282
283 // Verify that spoken feedback is enabled.
284 chromeos::AccessibilityManager* accessibility_manager =
285 chromeos::AccessibilityManager::Get();
286 ASSERT_TRUE(accessibility_manager);
287 EXPECT_TRUE(accessibility_manager->IsSpokenFeedbackEnabled());
288 }
289
290 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
291 DeviceLoginScreenDefaultHighContrastEnabled) {
292 // Verifies that the default state of the high contrast mode accessibility
293 // feature on the login screen can be controlled through device policy.
294
295 // Enable high contrast mode through device policy and wait for the change to
296 // take effect.
297 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
298 proto.mutable_accessibility_settings()->
299 set_login_screen_default_high_contrast_enabled(true);
300 RefreshDevicePolicyAndWaitForPrefChange(prefs::kHighContrastEnabled);
301
302 // Verify that the pref which controls high contrast mode in the login profile
303 // has changed to the policy-supplied default.
304 VerifyPrefFollowsRecommendation(prefs::kHighContrastEnabled,
305 base::FundamentalValue(true));
306
307 // Verify that high contrast mode is enabled.
308 chromeos::AccessibilityManager* accessibility_manager =
309 chromeos::AccessibilityManager::Get();
310 ASSERT_TRUE(accessibility_manager);
311 EXPECT_TRUE(accessibility_manager->IsHighContrastEnabled());
312 }
313
314 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
315 DeviceLoginScreenDefaultScreenMagnifierType) {
316 // Verifies that the default screen magnifier type enabled on the login screen
317 // can be controlled through device policy.
318
319 // Set the screen magnifier type through device policy and wait for the change
320 // to take effect.
321 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
322 proto.mutable_accessibility_settings()->
323 set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier);
324 RefreshDevicePolicyAndWaitForPrefChange(prefs::kScreenMagnifierType);
325
326 // Verify that the prefs which control the screen magnifier type have changed
327 // to the policy-supplied default.
328 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled,
329 base::FundamentalValue(true));
330 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType,
331 base::FundamentalValue(ash::MAGNIFIER_FULL));
332
333 // Verify that the full-screen magnifier is enabled.
334 chromeos::MagnificationManager* magnification_manager =
335 chromeos::MagnificationManager::Get();
336 ASSERT_TRUE(magnification_manager);
337 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled());
338 EXPECT_EQ(ash::MAGNIFIER_FULL, magnification_manager->GetMagnifierType());
339 }
340
341 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
342 DeviceLoginScreenDefaultLargeCursorEnabled) {
343 // Verifies that changing the default state of the large cursor accessibility
344 // feature on the login screen through policy does not affect its state in a
345 // session.
346
347 // Enable the large cursor through device policy and wait for the change to
348 // take effect.
349 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
350 proto.mutable_accessibility_settings()->
351 set_login_screen_default_large_cursor_enabled(true);
352 RefreshDevicePolicyAndWaitForPrefChange(prefs::kLargeCursorEnabled);
353
354 // Verify that the pref which controls the large cursor in the session is
355 // unchanged.
356 VerifyPrefFollowsDefault(prefs::kLargeCursorEnabled);
357
358 // Verify that the large cursor is disabled.
359 chromeos::AccessibilityManager* accessibility_manager =
360 chromeos::AccessibilityManager::Get();
361 ASSERT_TRUE(accessibility_manager);
362 EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled());
363 }
364
365 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
366 DeviceLoginScreenDefaultSpokenFeedbackEnabled) {
367 // Verifies that changing the default state of the spoken feedback
368 // accessibility feature on the login screen through policy does not affect
369 // its state in a session.
370
371 // Enable spoken feedback through device policy and wait for the change to
372 // take effect.
373 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
374 proto.mutable_accessibility_settings()->
375 set_login_screen_default_spoken_feedback_enabled(true);
376 RefreshDevicePolicyAndWaitForPrefChange(prefs::kSpokenFeedbackEnabled);
377
378 // Verify that the pref which controls the spoken feedback in the session is
379 // unchanged.
380 VerifyPrefFollowsDefault(prefs::kSpokenFeedbackEnabled);
381
382 // Verify that spoken feedback is disabled.
383 chromeos::AccessibilityManager* accessibility_manager =
384 chromeos::AccessibilityManager::Get();
385 ASSERT_TRUE(accessibility_manager);
386 EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled());
387 }
388
389 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
390 DeviceLoginScreenDefaultHighContrastEnabled) {
391 // Verifies that changing the default state of the high contrast mode
392 // accessibility feature on the login screen through policy does not affect
393 // its state in a session.
394
395 // Enable high contrast mode through device policy and wait for the change to
396 // take effect.
397 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
398 proto.mutable_accessibility_settings()->
399 set_login_screen_default_high_contrast_enabled(true);
400 RefreshDevicePolicyAndWaitForPrefChange(prefs::kHighContrastEnabled);
401
402 // Verify that the pref which controls high contrast mode in the session is
403 // unchanged.
404 VerifyPrefFollowsDefault(prefs::kHighContrastEnabled);
405
406 // Verify that high contrast mode is disabled.
407 chromeos::AccessibilityManager* accessibility_manager =
408 chromeos::AccessibilityManager::Get();
409 ASSERT_TRUE(accessibility_manager);
410 EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled());
411 }
412
413 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
414 DeviceLoginScreenDefaultScreenMagnifierType) {
415 // Verifies that changing the default screen magnifier type enabled on the
416 // login screen through policy does not affect its state in a session.
417
418 // Set the screen magnifier type through device policy and wait for the change
419 // to take effect.
420 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
421 proto.mutable_accessibility_settings()->
422 set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier);
423 RefreshDevicePolicyAndWaitForPrefChange(prefs::kScreenMagnifierType);
424
425 // Verify that the prefs which control the screen magnifier in the session are
426 // unchanged.
427 VerifyPrefFollowsDefault(prefs::kScreenMagnifierEnabled);
428 VerifyPrefFollowsDefault(prefs::kScreenMagnifierType);
429
430 // Verify that the screen magnifier is disabled.
431 chromeos::MagnificationManager* magnification_manager =
432 chromeos::MagnificationManager::Get();
433 ASSERT_TRUE(magnification_manager);
434 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled());
435 EXPECT_EQ(ash::kDefaultMagnifierType,
436 magnification_manager->GetMagnifierType());
437 }
438
439 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698