OLD | NEW |
---|---|
(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/file_util.h" | |
14 #include "base/files/file_path.h" | |
15 #include "base/location.h" | |
16 #include "base/message_loop.h" | |
17 #include "base/path_service.h" | |
18 #include "base/prefs/pref_change_registrar.h" | |
19 #include "base/prefs/pref_service.h" | |
20 #include "base/run_loop.h" | |
21 #include "base/values.h" | |
22 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
23 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | |
24 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | |
25 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | |
26 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | |
27 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
28 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
29 #include "chrome/browser/lifetime/application_lifetime.h" | |
30 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | |
31 #include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h" | |
32 #include "chrome/browser/profiles/profile.h" | |
33 #include "chrome/browser/profiles/profile_manager.h" | |
34 #include "chrome/common/pref_names.h" | |
35 #include "chromeos/chromeos_paths.h" | |
36 #include "chromeos/chromeos_switches.h" | |
37 #include "testing/gtest/include/gtest/gtest.h" | |
38 | |
39 namespace em = enterprise_management; | |
40 | |
41 namespace policy { | |
42 | |
43 namespace { | |
44 | |
45 const em::AccessibilitySettingsProto_ScreenMagnifierType kFullScreenMagnifier = | |
46 em::AccessibilitySettingsProto_ScreenMagnifierType_SCREEN_MAGNIFIER_TYPE_FULL; | |
47 | |
48 // Spins the loop until a notification is received from |prefs| that the value | |
49 // of |pref_name| has changed. If the notification is received before Wait() | |
50 // has been called, Wait() returns immediately and no loop is spun. | |
51 class PrefChangeWatcher { | |
52 public: | |
53 PrefChangeWatcher(const char* pref_name, PrefService* prefs); | |
54 | |
55 void Wait(); | |
56 | |
57 void OnPrefChange(); | |
58 | |
59 private: | |
60 bool pref_changed_; | |
61 | |
62 base::RunLoop run_loop_; | |
63 PrefChangeRegistrar registrar_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(PrefChangeWatcher); | |
66 }; | |
67 | |
68 PrefChangeWatcher::PrefChangeWatcher(const char* pref_name, | |
69 PrefService* prefs) | |
70 : pref_changed_(false) { | |
71 registrar_.Init(prefs); | |
72 registrar_.Add(pref_name, base::Bind(&PrefChangeWatcher::OnPrefChange, | |
73 base::Unretained(this))); | |
74 } | |
75 | |
76 void PrefChangeWatcher::Wait() { | |
77 if (!pref_changed_) | |
78 run_loop_.Run(); | |
79 } | |
80 | |
81 void PrefChangeWatcher::OnPrefChange() { | |
82 pref_changed_ = true; | |
83 run_loop_.Quit(); | |
84 } | |
85 | |
86 } // namespace | |
87 | |
88 class DevicePolicyBrowsertest : public DevicePolicyCrosBrowserTest, | |
Mattias Nissler (ping if slow)
2013/06/12 13:55:16
The name of this class and file is a bit misleadin
bartfab (slow)
2013/06/12 18:57:49
My idea was that we do not have the complete boile
| |
89 public testing::WithParamInterface<bool> { | |
90 protected: | |
91 DevicePolicyBrowsertest(); | |
92 virtual ~DevicePolicyBrowsertest(); | |
93 | |
94 // DevicePolicyCrosBrowserTest: | |
95 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | |
96 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; | |
97 virtual void SetUpOnMainThread() OVERRIDE; | |
98 virtual void CleanUpOnMainThread() OVERRIDE; | |
99 | |
100 const bool logged_in_; | |
101 | |
102 private: | |
103 DISALLOW_COPY_AND_ASSIGN(DevicePolicyBrowsertest); | |
104 }; | |
105 | |
106 DevicePolicyBrowsertest::DevicePolicyBrowsertest() : logged_in_(GetParam()) { | |
107 } | |
108 | |
109 DevicePolicyBrowsertest::~DevicePolicyBrowsertest() { | |
110 } | |
111 | |
112 void DevicePolicyBrowsertest::SetUpCommandLine(CommandLine* command_line) { | |
113 DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line); | |
114 if (logged_in_) | |
Mattias Nissler (ping if slow)
2013/06/12 13:55:16
It seems like logged_in_ behavior and test verific
bartfab (slow)
2013/06/12 18:57:49
Done.
| |
115 return; | |
116 | |
117 command_line->AppendSwitch(chromeos::switches::kLoginManager); | |
118 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | |
119 } | |
120 | |
121 void DevicePolicyBrowsertest::SetUpInProcessBrowserTestFixture() { | |
122 InstallOwnerKey(); | |
123 | |
124 // Mark the device as enterprise-owned. | |
125 cryptohome::SerializedInstallAttributes install_attrs_proto; | |
126 cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL; | |
127 | |
128 attribute = install_attrs_proto.add_attributes(); | |
129 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned); | |
130 attribute->set_value("true"); | |
131 | |
132 attribute = install_attrs_proto.add_attributes(); | |
133 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser); | |
134 attribute->set_value(DevicePolicyBuilder::kFakeUsername); | |
135 | |
136 base::FilePath install_attrs_file = | |
137 temp_dir_.path().AppendASCII("install_attributes.pb"); | |
138 const std::string install_attrs_blob( | |
139 install_attrs_proto.SerializeAsString()); | |
140 ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), | |
141 file_util::WriteFile(install_attrs_file, | |
142 install_attrs_blob.c_str(), | |
143 install_attrs_blob.size())); | |
144 ASSERT_TRUE(PathService::Override(chromeos::FILE_INSTALL_ATTRIBUTES, | |
145 install_attrs_file)); | |
Mattias Nissler (ping if slow)
2013/06/12 13:55:16
Given this is a copy of existing code, we should p
bartfab (slow)
2013/06/12 18:57:49
Done. But I had to make the method static because
| |
146 | |
147 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | |
148 } | |
149 | |
150 void DevicePolicyBrowsertest::SetUpOnMainThread() { | |
151 DevicePolicyCrosBrowserTest::SetUpOnMainThread(); | |
152 | |
153 // Tell the DeviceSettingsService that there is no local owner. | |
154 chromeos::DeviceSettingsService::Get()->SetUsername(std::string()); | |
155 | |
156 if (logged_in_) | |
157 return; | |
158 | |
159 // Set the login screen profile. | |
160 chromeos::AccessibilityManager* accessibility_manager = | |
161 chromeos::AccessibilityManager::Get(); | |
162 ASSERT_TRUE(accessibility_manager); | |
163 accessibility_manager->SetProfileForTest( | |
164 chromeos::ProfileHelper::GetSigninProfile()); | |
165 | |
166 chromeos::MagnificationManager* magnification_manager = | |
167 chromeos::MagnificationManager::Get(); | |
168 ASSERT_TRUE(magnification_manager); | |
169 magnification_manager->SetProfileForTest( | |
170 chromeos::ProfileHelper::GetSigninProfile()); | |
171 } | |
172 | |
173 void DevicePolicyBrowsertest::CleanUpOnMainThread() { | |
174 base::MessageLoop::current()->PostTask(FROM_HERE, | |
175 base::Bind(&chrome::AttemptExit)); | |
176 base::RunLoop().RunUntilIdle(); | |
177 DevicePolicyCrosBrowserTest::CleanUpOnMainThread(); | |
178 } | |
179 | |
180 IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest, | |
181 LoginScreenDefaultLargeCursorEnabled) { | |
182 // Verifies that the default state of the large cursor accessibility feature | |
183 // on the login screen can be controlled through device policy. | |
184 Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile(); | |
185 ASSERT_TRUE(login_profile); | |
186 | |
187 // Enable the large cursor through device policy and wait for the change to | |
188 // take effect. | |
189 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | |
190 proto.mutable_accessibility_settings()-> | |
191 set_login_screen_default_large_cursor_enabled(true); | |
192 PrefChangeWatcher watcher(prefs::kLargeCursorEnabled, | |
193 login_profile->GetPrefs()); | |
194 RefreshDevicePolicy(); | |
195 watcher.Wait(); | |
196 | |
197 Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() : | |
Mattias Nissler (ping if slow)
2013/06/12 13:55:16
style nit: not sure, but I think the colon commonl
bartfab (slow)
2013/06/12 18:57:49
Done.
| |
198 login_profile; | |
199 ASSERT_TRUE(current_profile); | |
200 const PrefService::Preference* pref = | |
201 current_profile->GetPrefs()->FindPreference(prefs::kLargeCursorEnabled); | |
202 ASSERT_TRUE(pref); | |
203 | |
204 // When logged in, verify that the pref which controls the large cursor in | |
205 // the current profile is unchanged. | |
206 // When not logged in, verify that the pref which controls the large cursor | |
207 // in the login profile has changed to the policy-supplied default. | |
208 const base::FundamentalValue expected_value(!logged_in_); | |
209 EXPECT_FALSE(pref->IsManaged()); | |
210 EXPECT_EQ(logged_in_, pref->IsDefaultValue()); | |
211 EXPECT_TRUE(base::Value::Equals(&expected_value, pref->GetValue())); | |
212 const base::Value* recommended_value = pref->GetRecommendedValue(); | |
213 if (logged_in_) | |
214 EXPECT_FALSE(recommended_value); | |
215 else | |
216 EXPECT_TRUE(base::Value::Equals(&expected_value, recommended_value)); | |
217 | |
218 // When logged in, verify that the large cursor is disabled. | |
219 // When not logged in, verify that the large cursor is enabled. | |
220 chromeos::AccessibilityManager* accessibility_manager = | |
221 chromeos::AccessibilityManager::Get(); | |
222 ASSERT_TRUE(accessibility_manager); | |
223 EXPECT_EQ(!logged_in_, accessibility_manager->IsLargeCursorEnabled()); | |
224 } | |
225 | |
226 IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest, | |
227 LoginScreenDefaultSpokenFeedbackEnabled) { | |
228 // Verifies that the default state of the spoken feedback accessibility | |
229 // feature on the login screen can be controlled through device policy. | |
230 Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile(); | |
231 ASSERT_TRUE(login_profile); | |
232 | |
233 // Enable spoken feedback through device policy and wait for the change to | |
234 // take effect. | |
235 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | |
236 proto.mutable_accessibility_settings()-> | |
237 set_login_screen_default_spoken_feedback_enabled(true); | |
238 PrefChangeWatcher watcher(prefs::kSpokenFeedbackEnabled, | |
239 login_profile->GetPrefs()); | |
240 RefreshDevicePolicy(); | |
241 watcher.Wait(); | |
242 | |
243 Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() : | |
244 login_profile; | |
245 ASSERT_TRUE(current_profile); | |
246 const PrefService::Preference* pref = | |
247 current_profile->GetPrefs()->FindPreference( | |
248 prefs::kSpokenFeedbackEnabled); | |
249 ASSERT_TRUE(pref); | |
250 | |
251 // When logged in, verify that the pref which controls spoken feedback in the | |
252 // current profile is unchanged. | |
253 // When not logged in, verify that the pref which controls spoken feedback in | |
254 // the login profile has changed to the policy-supplied default. | |
255 const base::FundamentalValue expected_value(!logged_in_); | |
256 EXPECT_FALSE(pref->IsManaged()); | |
257 EXPECT_EQ(logged_in_, pref->IsDefaultValue()); | |
258 EXPECT_TRUE(base::Value::Equals(&expected_value, pref->GetValue())); | |
259 const base::Value* recommended_value = pref->GetRecommendedValue(); | |
260 if (logged_in_) | |
261 EXPECT_FALSE(recommended_value); | |
262 else | |
263 EXPECT_TRUE(base::Value::Equals(&expected_value, recommended_value)); | |
264 | |
265 // When logged in, verify that spoken feedback is disabled. | |
266 // When not logged in, verify that spoken feedback is enabled. | |
267 chromeos::AccessibilityManager* accessibility_manager = | |
268 chromeos::AccessibilityManager::Get(); | |
269 ASSERT_TRUE(accessibility_manager); | |
270 EXPECT_EQ(!logged_in_, accessibility_manager->IsSpokenFeedbackEnabled()); | |
271 } | |
272 | |
273 IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest, | |
274 LoginScreenDefaultHighContrastEnabled) { | |
275 // Verifies that the default state of the high contrast mode accessibility | |
276 // feature on the login screen can be controlled through device policy. | |
277 Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile(); | |
278 ASSERT_TRUE(login_profile); | |
279 | |
280 // Enable high contrast mode through device policy and wait for the change to | |
281 // take effect. | |
282 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | |
283 proto.mutable_accessibility_settings()-> | |
284 set_login_screen_default_high_contrast_enabled(true); | |
285 PrefChangeWatcher watcher(prefs::kHighContrastEnabled, | |
286 login_profile->GetPrefs()); | |
287 RefreshDevicePolicy(); | |
288 watcher.Wait(); | |
289 | |
290 Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() : | |
291 login_profile; | |
292 ASSERT_TRUE(current_profile); | |
293 const PrefService::Preference* pref = | |
294 current_profile->GetPrefs()->FindPreference(prefs::kHighContrastEnabled); | |
295 ASSERT_TRUE(pref); | |
296 | |
297 // When logged in, verify that the pref which controls high contrast mode in | |
298 // the current profile is unchanged. | |
299 // When not logged in, verify that the pref which controls high contrast mode | |
300 // in the login profile has changed to the policy-supplied default. | |
301 const base::FundamentalValue expected_value(!logged_in_); | |
302 EXPECT_FALSE(pref->IsManaged()); | |
303 EXPECT_EQ(logged_in_, pref->IsDefaultValue()); | |
304 EXPECT_TRUE(base::Value::Equals(&expected_value, pref->GetValue())); | |
305 const base::Value* recommended_value = pref->GetRecommendedValue(); | |
306 if (logged_in_) | |
307 EXPECT_FALSE(recommended_value); | |
308 else | |
309 EXPECT_TRUE(base::Value::Equals(&expected_value, recommended_value)); | |
310 | |
311 // When logged in, verify that high contrast mode is disabled. | |
312 // When not logged in, verify that high contrast mode is enabled. | |
313 chromeos::AccessibilityManager* accessibility_manager = | |
314 chromeos::AccessibilityManager::Get(); | |
315 ASSERT_TRUE(accessibility_manager); | |
316 EXPECT_EQ(!logged_in_, accessibility_manager->IsHighContrastEnabled()); | |
317 } | |
Mattias Nissler (ping if slow)
2013/06/12 13:55:16
The previous 3 test cases are identical in terms o
bartfab (slow)
2013/06/12 18:57:49
Done.
| |
318 | |
319 IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest, | |
320 LoginScreenDefaultScreenMagnifierType) { | |
321 // Verifies that the default screen magnifier type enabled on the login screen | |
322 // can be controlled through device policy. | |
323 Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile(); | |
324 ASSERT_TRUE(login_profile); | |
325 | |
326 // Set the screen magnifier type through device policy and wait for the change | |
327 // to take effect. | |
328 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | |
329 proto.mutable_accessibility_settings()-> | |
330 set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier); | |
331 PrefChangeWatcher watcher(prefs::kScreenMagnifierType, | |
332 login_profile->GetPrefs()); | |
333 RefreshDevicePolicy(); | |
334 watcher.Wait(); | |
335 | |
336 Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() : | |
337 login_profile; | |
338 ASSERT_TRUE(current_profile); | |
339 const PrefService::Preference* enabled_pref = | |
340 current_profile->GetPrefs()->FindPreference( | |
341 prefs::kScreenMagnifierEnabled); | |
342 const PrefService::Preference* type_pref = | |
343 current_profile->GetPrefs()->FindPreference(prefs::kScreenMagnifierType); | |
344 ASSERT_TRUE(enabled_pref); | |
345 ASSERT_TRUE(type_pref); | |
346 | |
347 // When logged in, verify that the prefs which control the screen magnifier | |
348 // are unchanged. | |
349 // When not logged in, verify that the prefs which control the screen | |
350 // magnifier type have changed to the policy-supplied default. | |
351 const base::FundamentalValue expected_enabled(!logged_in_); | |
352 EXPECT_FALSE(enabled_pref->IsManaged()); | |
353 EXPECT_EQ(logged_in_, enabled_pref->IsDefaultValue()); | |
354 EXPECT_TRUE(base::Value::Equals(&expected_enabled, enabled_pref->GetValue())); | |
355 const base::Value* recommended_value = enabled_pref->GetRecommendedValue(); | |
356 if (logged_in_) { | |
357 EXPECT_FALSE(recommended_value); | |
358 } else { | |
359 EXPECT_TRUE(base::Value::Equals(&expected_enabled, recommended_value)); | |
360 } | |
361 | |
362 ash::MagnifierType expected_magnifier_type = | |
363 logged_in_ ? ash::kDefaultMagnifierType : ash::MAGNIFIER_FULL; | |
364 const base::FundamentalValue expected_type(expected_magnifier_type); | |
365 EXPECT_FALSE(type_pref->IsManaged()); | |
366 EXPECT_EQ(logged_in_, type_pref->IsDefaultValue()); | |
367 EXPECT_TRUE(base::Value::Equals(&expected_type, type_pref->GetValue())); | |
368 recommended_value = type_pref->GetRecommendedValue(); | |
369 if (logged_in_) | |
370 EXPECT_FALSE(recommended_value); | |
371 else | |
372 EXPECT_TRUE(base::Value::Equals(&expected_type, recommended_value)); | |
373 | |
374 // When logged in, verify that the screen magnifier is disabled. | |
375 // When not logged in, verify that the full-screen magnifier is enabled. | |
376 chromeos::MagnificationManager* magnification_manager = | |
377 chromeos::MagnificationManager::Get(); | |
378 ASSERT_TRUE(magnification_manager); | |
379 EXPECT_EQ(!logged_in_, magnification_manager->IsMagnifierEnabled()); | |
380 EXPECT_EQ(expected_magnifier_type, magnification_manager->GetMagnifierType()); | |
381 } | |
382 | |
383 INSTANTIATE_TEST_CASE_P(DevicePolicyBrowsertestInstantiation, | |
384 DevicePolicyBrowsertest, | |
385 testing::Bool()); | |
386 | |
387 } // namespace policy | |
OLD | NEW |