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/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_FUL
L; |
| 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(const char* pref_name, |
| 203 const base::Value& recommended_value) { |
| 204 const PrefService::Preference* pref = |
| 205 login_profile_->GetPrefs()->FindPreference(pref_name); |
| 206 ASSERT_TRUE(pref); |
| 207 EXPECT_FALSE(pref->IsManaged()); |
| 208 EXPECT_FALSE(pref->IsDefaultValue()); |
| 209 EXPECT_TRUE(base::Value::Equals(&recommended_value, pref->GetValue())); |
| 210 EXPECT_TRUE(base::Value::Equals(&recommended_value, |
| 211 pref->GetRecommendedValue())); |
| 212 } |
| 213 |
| 214 LoginScreenDefaultPolicyInSessionBrowsertest:: |
| 215 LoginScreenDefaultPolicyInSessionBrowsertest() { |
| 216 } |
| 217 |
| 218 LoginScreenDefaultPolicyInSessionBrowsertest:: |
| 219 ~LoginScreenDefaultPolicyInSessionBrowsertest() { |
| 220 } |
| 221 |
| 222 void LoginScreenDefaultPolicyInSessionBrowsertest::SetUpOnMainThread() { |
| 223 LoginScreenDefaultPolicyBrowsertestBase::SetUpOnMainThread(); |
| 224 |
| 225 // Tell the DeviceSettingsService that there is no local owner. |
| 226 chromeos::DeviceSettingsService::Get()->SetUsername(std::string()); |
| 227 } |
| 228 |
| 229 void LoginScreenDefaultPolicyInSessionBrowsertest::VerifyPrefFollowsDefault( |
| 230 const char* pref_name) { |
| 231 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 232 ASSERT_TRUE(profile); |
| 233 const PrefService::Preference* pref = |
| 234 profile->GetPrefs()->FindPreference(pref_name); |
| 235 ASSERT_TRUE(pref); |
| 236 EXPECT_FALSE(pref->IsManaged()); |
| 237 EXPECT_TRUE(pref->IsDefaultValue()); |
| 238 EXPECT_FALSE(pref->GetRecommendedValue()); |
| 239 } |
| 240 |
| 241 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest, |
| 242 DeviceLoginScreenDefaultLargeCursorEnabled) { |
| 243 // Verifies that the default state of the large cursor accessibility feature |
| 244 // on the login screen can be controlled through device policy. |
| 245 |
| 246 // Enable the large cursor through device policy and wait for the change to |
| 247 // take effect. |
| 248 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 249 proto.mutable_accessibility_settings()-> |
| 250 set_login_screen_default_large_cursor_enabled(true); |
| 251 RefreshDevicePolicyAndWaitForPrefChange(prefs::kLargeCursorEnabled); |
| 252 |
| 253 // Verify that the pref which controls the large cursor in the login profile |
| 254 // has changed to the policy-supplied default. |
| 255 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled, |
| 256 base::FundamentalValue(true)); |
| 257 |
| 258 // Verify that the large cursor is enabled. |
| 259 chromeos::AccessibilityManager* accessibility_manager = |
| 260 chromeos::AccessibilityManager::Get(); |
| 261 ASSERT_TRUE(accessibility_manager); |
| 262 EXPECT_TRUE(accessibility_manager->IsLargeCursorEnabled()); |
| 263 } |
| 264 |
| 265 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest, |
| 266 DeviceLoginScreenDefaultSpokenFeedbackEnabled) { |
| 267 // Verifies that the default state of the spoken feedback accessibility |
| 268 // feature on the login screen can be controlled through device policy. |
| 269 |
| 270 // Enable spoken feedback through device policy and wait for the change to |
| 271 // take effect. |
| 272 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 273 proto.mutable_accessibility_settings()-> |
| 274 set_login_screen_default_spoken_feedback_enabled(true); |
| 275 RefreshDevicePolicyAndWaitForPrefChange(prefs::kSpokenFeedbackEnabled); |
| 276 |
| 277 // Verify that the pref which controls spoken feedback in the login profile |
| 278 // has changed to the policy-supplied default. |
| 279 VerifyPrefFollowsRecommendation(prefs::kSpokenFeedbackEnabled, |
| 280 base::FundamentalValue(true)); |
| 281 |
| 282 // Verify that spoken feedback is enabled. |
| 283 chromeos::AccessibilityManager* accessibility_manager = |
| 284 chromeos::AccessibilityManager::Get(); |
| 285 ASSERT_TRUE(accessibility_manager); |
| 286 EXPECT_TRUE(accessibility_manager->IsSpokenFeedbackEnabled()); |
| 287 } |
| 288 |
| 289 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest, |
| 290 DeviceLoginScreenDefaultHighContrastEnabled) { |
| 291 // Verifies that the default state of the high contrast mode accessibility |
| 292 // feature on the login screen can be controlled through device policy. |
| 293 |
| 294 // Enable high contrast mode through device policy and wait for the change to |
| 295 // take effect. |
| 296 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 297 proto.mutable_accessibility_settings()-> |
| 298 set_login_screen_default_high_contrast_enabled(true); |
| 299 RefreshDevicePolicyAndWaitForPrefChange(prefs::kHighContrastEnabled); |
| 300 |
| 301 // Verify that the pref which controls high contrast mode in the login profile |
| 302 // has changed to the policy-supplied default. |
| 303 VerifyPrefFollowsRecommendation(prefs::kHighContrastEnabled, |
| 304 base::FundamentalValue(true)); |
| 305 |
| 306 // Verify that high contrast mode is enabled. |
| 307 chromeos::AccessibilityManager* accessibility_manager = |
| 308 chromeos::AccessibilityManager::Get(); |
| 309 ASSERT_TRUE(accessibility_manager); |
| 310 EXPECT_TRUE(accessibility_manager->IsHighContrastEnabled()); |
| 311 } |
| 312 |
| 313 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest, |
| 314 DeviceLoginScreenDefaultScreenMagnifierType) { |
| 315 // Verifies that the default screen magnifier type enabled on the login screen |
| 316 // can be controlled through device policy. |
| 317 |
| 318 // Set the screen magnifier type through device policy and wait for the change |
| 319 // to take effect. |
| 320 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 321 proto.mutable_accessibility_settings()-> |
| 322 set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier); |
| 323 RefreshDevicePolicyAndWaitForPrefChange(prefs::kScreenMagnifierType); |
| 324 |
| 325 // Verify that the prefs which control the screen magnifier type have changed |
| 326 // to the policy-supplied default. |
| 327 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled, |
| 328 base::FundamentalValue(true)); |
| 329 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, |
| 330 base::FundamentalValue(ash::MAGNIFIER_FULL)); |
| 331 |
| 332 // Verify that the full-screen magnifier is enabled. |
| 333 chromeos::MagnificationManager* magnification_manager = |
| 334 chromeos::MagnificationManager::Get(); |
| 335 ASSERT_TRUE(magnification_manager); |
| 336 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled()); |
| 337 EXPECT_EQ(ash::MAGNIFIER_FULL, magnification_manager->GetMagnifierType()); |
| 338 } |
| 339 |
| 340 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest, |
| 341 DeviceLoginScreenDefaultLargeCursorEnabled) { |
| 342 // Verifies that changing the default state of the large cursor accessibility |
| 343 // feature on the login screen through policy does not affect its state in a |
| 344 // session. |
| 345 |
| 346 // Enable the large cursor through device policy and wait for the change to |
| 347 // take effect. |
| 348 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 349 proto.mutable_accessibility_settings()-> |
| 350 set_login_screen_default_large_cursor_enabled(true); |
| 351 RefreshDevicePolicyAndWaitForPrefChange(prefs::kLargeCursorEnabled); |
| 352 |
| 353 // Verify that the pref which controls the large cursor in the session is |
| 354 // unchanged. |
| 355 VerifyPrefFollowsDefault(prefs::kLargeCursorEnabled); |
| 356 |
| 357 // Verify that the large cursor is disabled. |
| 358 chromeos::AccessibilityManager* accessibility_manager = |
| 359 chromeos::AccessibilityManager::Get(); |
| 360 ASSERT_TRUE(accessibility_manager); |
| 361 EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled()); |
| 362 } |
| 363 |
| 364 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest, |
| 365 DeviceLoginScreenDefaultSpokenFeedbackEnabled) { |
| 366 // Verifies that changing the default state of the spoken feedback |
| 367 // accessibility feature on the login screen through policy does not affect |
| 368 // its state in a session. |
| 369 |
| 370 // Enable spoken feedback through device policy and wait for the change to |
| 371 // take effect. |
| 372 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 373 proto.mutable_accessibility_settings()-> |
| 374 set_login_screen_default_spoken_feedback_enabled(true); |
| 375 RefreshDevicePolicyAndWaitForPrefChange(prefs::kSpokenFeedbackEnabled); |
| 376 |
| 377 // Verify that the pref which controls the spoken feedback in the session is |
| 378 // unchanged. |
| 379 VerifyPrefFollowsDefault(prefs::kSpokenFeedbackEnabled); |
| 380 |
| 381 // Verify that spoken feedback is disabled. |
| 382 chromeos::AccessibilityManager* accessibility_manager = |
| 383 chromeos::AccessibilityManager::Get(); |
| 384 ASSERT_TRUE(accessibility_manager); |
| 385 EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled()); |
| 386 } |
| 387 |
| 388 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest, |
| 389 DeviceLoginScreenDefaultHighContrastEnabled) { |
| 390 // Verifies that changing the default state of the high contrast mode |
| 391 // accessibility feature on the login screen through policy does not affect |
| 392 // its state in a session. |
| 393 |
| 394 // Enable high contrast mode through device policy and wait for the change to |
| 395 // take effect. |
| 396 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 397 proto.mutable_accessibility_settings()-> |
| 398 set_login_screen_default_high_contrast_enabled(true); |
| 399 RefreshDevicePolicyAndWaitForPrefChange(prefs::kHighContrastEnabled); |
| 400 |
| 401 // Verify that the pref which controls high contrast mode in the session is |
| 402 // unchanged. |
| 403 VerifyPrefFollowsDefault(prefs::kHighContrastEnabled); |
| 404 |
| 405 // Verify that high contrast mode is disabled. |
| 406 chromeos::AccessibilityManager* accessibility_manager = |
| 407 chromeos::AccessibilityManager::Get(); |
| 408 ASSERT_TRUE(accessibility_manager); |
| 409 EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled()); |
| 410 } |
| 411 |
| 412 IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest, |
| 413 DeviceLoginScreenDefaultScreenMagnifierType) { |
| 414 // Verifies that changing the default screen magnifier type enabled on the |
| 415 // login screen through policy does not affect its state in a session. |
| 416 |
| 417 // Set the screen magnifier type through device policy and wait for the change |
| 418 // to take effect. |
| 419 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 420 proto.mutable_accessibility_settings()-> |
| 421 set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier); |
| 422 RefreshDevicePolicyAndWaitForPrefChange(prefs::kScreenMagnifierType); |
| 423 |
| 424 // Verify that the prefs which control the screen magnifier in the session are |
| 425 // unchanged. |
| 426 VerifyPrefFollowsDefault(prefs::kScreenMagnifierEnabled); |
| 427 VerifyPrefFollowsDefault(prefs::kScreenMagnifierType); |
| 428 |
| 429 // Verify that the screen magnifier is disabled. |
| 430 chromeos::MagnificationManager* magnification_manager = |
| 431 chromeos::MagnificationManager::Get(); |
| 432 ASSERT_TRUE(magnification_manager); |
| 433 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled()); |
| 434 EXPECT_EQ(ash::kDefaultMagnifierType, |
| 435 magnification_manager->GetMagnifierType()); |
| 436 } |
| 437 |
| 438 } // namespace policy |
OLD | NEW |