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 "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 6 |
| 7 #include "ash/magnifier/magnification_controller.h" |
| 8 #include "ash/shell.h" |
| 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
| 13 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
| 14 #include "chrome/browser/chromeos/login/helper.h" |
| 15 #include "chrome/browser/chromeos/login/login_utils.h" |
| 16 #include "chrome/browser/chromeos/login/user_manager.h" |
| 17 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/test/base/testing_profile.h" |
| 23 #include "chromeos/chromeos_switches.h" |
| 24 #include "content/public/browser/notification_service.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 |
| 27 namespace chromeos { |
| 28 |
| 29 namespace { |
| 30 |
| 31 const char kTestUserName[] = "owner@invalid.domain"; |
| 32 |
| 33 class MockAccessibilityObserver : public content::NotificationObserver { |
| 34 public: |
| 35 MockAccessibilityObserver() : observed_(false), |
| 36 observed_enabled_(false), |
| 37 observed_type_(-1) { |
| 38 registrar_.Add( |
| 39 this, |
| 40 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK, |
| 41 content::NotificationService::AllSources()); |
| 42 registrar_.Add( |
| 43 this, |
| 44 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE, |
| 45 content::NotificationService::AllSources()); |
| 46 } |
| 47 virtual ~MockAccessibilityObserver() {} |
| 48 |
| 49 bool observed() const { return observed_; } |
| 50 bool observed_enabled() const { return observed_enabled_; } |
| 51 int observed_type() const { return observed_type_; } |
| 52 |
| 53 void reset() { observed_ = false; } |
| 54 |
| 55 private: |
| 56 // content::NotificationObserver implimentation: |
| 57 virtual void Observe(int type, |
| 58 const content::NotificationSource& source, |
| 59 const content::NotificationDetails& details) OVERRIDE { |
| 60 AccessibilityStatusEventDetails* accessibility_status = |
| 61 content::Details<AccessibilityStatusEventDetails>( |
| 62 details).ptr(); |
| 63 ASSERT_FALSE(observed_); |
| 64 |
| 65 switch (type) { |
| 66 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK: |
| 67 observed_ = true; |
| 68 observed_enabled_ = accessibility_status->enabled; |
| 69 observed_type_ = type; |
| 70 break; |
| 71 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE: |
| 72 observed_ = true; |
| 73 observed_enabled_ = accessibility_status->enabled; |
| 74 observed_type_ = type; |
| 75 break; |
| 76 } |
| 77 } |
| 78 |
| 79 bool observed_; |
| 80 bool observed_enabled_; |
| 81 int observed_type_; |
| 82 |
| 83 content::NotificationRegistrar registrar_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver); |
| 86 }; |
| 87 |
| 88 void SetHighContrastEnabled(bool enabled) { |
| 89 return AccessibilityManager::Get()->EnableHighContrast(enabled); |
| 90 } |
| 91 |
| 92 bool IsHighContrastEnabled() { |
| 93 return AccessibilityManager::Get()->IsHighContrastEnabled(); |
| 94 } |
| 95 |
| 96 void SetSpokenFeedbackEnabled(bool enabled) { |
| 97 return AccessibilityManager::Get()->EnableSpokenFeedback( |
| 98 enabled, NULL, ash::A11Y_NOTIFICATION_NONE); |
| 99 } |
| 100 |
| 101 bool IsSpokenFeedbackEnabled() { |
| 102 return AccessibilityManager::Get()->IsSpokenFeedbackEnabled(); |
| 103 } |
| 104 |
| 105 Profile* GetProfile() { |
| 106 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 107 DCHECK(profile); |
| 108 return profile; |
| 109 } |
| 110 |
| 111 PrefService* GetPrefs() { |
| 112 return GetProfile()->GetPrefs(); |
| 113 } |
| 114 |
| 115 void SetHighContrastEnabledToPref(bool enabled) { |
| 116 GetPrefs()->SetBoolean(prefs::kHighContrastEnabled, enabled); |
| 117 } |
| 118 |
| 119 void SetSpokenFeedbackEnabledToPref(bool enabled) { |
| 120 GetPrefs()->SetBoolean(prefs::kSpokenFeedbackEnabled, enabled); |
| 121 } |
| 122 |
| 123 } // anonymouse namespace |
| 124 |
| 125 class AccessibilityManagerTest : public CrosInProcessBrowserTest { |
| 126 protected: |
| 127 AccessibilityManagerTest() {} |
| 128 virtual ~AccessibilityManagerTest() {} |
| 129 |
| 130 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 131 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| 132 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 133 TestingProfile::kTestUserProfileDir); |
| 134 } |
| 135 |
| 136 virtual void SetUpOnMainThread() OVERRIDE { |
| 137 } |
| 138 |
| 139 content::NotificationRegistrar registrar_; |
| 140 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest); |
| 141 }; |
| 142 |
| 143 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, Login) { |
| 144 // Confirms that a11y features are disabled on the login screen. |
| 145 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 146 EXPECT_FALSE(IsHighContrastEnabled()); |
| 147 |
| 148 // Logs in. |
| 149 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 150 |
| 151 // Confirms that the features still disabled just after login. |
| 152 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 153 EXPECT_FALSE(IsHighContrastEnabled()); |
| 154 |
| 155 UserManager::Get()->SessionStarted(); |
| 156 |
| 157 // Confirms that the features are still disabled just after login. |
| 158 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 159 EXPECT_FALSE(IsHighContrastEnabled()); |
| 160 |
| 161 // Enables spoken feedback. |
| 162 SetSpokenFeedbackEnabled(true); |
| 163 // Confirms that the spoken feedback is enabled. |
| 164 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 165 |
| 166 // Enables high contrast. |
| 167 SetHighContrastEnabled(true); |
| 168 // Confirms that high cotrast is enabled. |
| 169 EXPECT_TRUE(IsHighContrastEnabled()); |
| 170 } |
| 171 |
| 172 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) { |
| 173 // Logs in. |
| 174 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 175 UserManager::Get()->SessionStarted(); |
| 176 |
| 177 // Confirms that the features are disabled just after login. |
| 178 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 179 EXPECT_FALSE(IsHighContrastEnabled()); |
| 180 |
| 181 // Sets the pref as true to enable the spoken feedback. |
| 182 SetSpokenFeedbackEnabledToPref(true); |
| 183 // Confirms that the spoken feedback is enabled. |
| 184 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 185 |
| 186 // Enables the high contrast mode. |
| 187 SetHighContrastEnabled(true); |
| 188 // Confirms that the high contrast mode is enabled. |
| 189 EXPECT_TRUE(IsHighContrastEnabled()); |
| 190 |
| 191 SetSpokenFeedbackEnabledToPref(false); |
| 192 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 193 |
| 194 SetHighContrastEnabledToPref(false); |
| 195 EXPECT_FALSE(IsHighContrastEnabled()); |
| 196 } |
| 197 |
| 198 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) { |
| 199 // Loads the profile of the user. |
| 200 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 201 |
| 202 // Sets the pref to enable spoken feedback before login. |
| 203 SetSpokenFeedbackEnabledToPref(true); |
| 204 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 205 |
| 206 // Sets the pref to enable high contrast before login. |
| 207 SetHighContrastEnabledToPref(true); |
| 208 EXPECT_FALSE(IsHighContrastEnabled()); |
| 209 |
| 210 // Logs in. |
| 211 UserManager::Get()->SessionStarted(); |
| 212 |
| 213 // Confirms that features are enabled by restring from pref just after login. |
| 214 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 215 EXPECT_TRUE(IsHighContrastEnabled()); |
| 216 } |
| 217 |
| 218 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, |
| 219 ChangingTypeInvokesNotification) { |
| 220 MockAccessibilityObserver observer; |
| 221 |
| 222 // Logs in. |
| 223 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 224 UserManager::Get()->SessionStarted(); |
| 225 |
| 226 EXPECT_FALSE(observer.observed()); |
| 227 observer.reset(); |
| 228 |
| 229 SetSpokenFeedbackEnabled(true); |
| 230 EXPECT_TRUE(observer.observed()); |
| 231 EXPECT_TRUE(observer.observed_enabled()); |
| 232 EXPECT_EQ(observer.observed_type(), |
| 233 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 234 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 235 |
| 236 observer.reset(); |
| 237 SetSpokenFeedbackEnabled(false); |
| 238 EXPECT_TRUE(observer.observed()); |
| 239 EXPECT_FALSE(observer.observed_enabled()); |
| 240 EXPECT_EQ(observer.observed_type(), |
| 241 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 242 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 243 |
| 244 observer.reset(); |
| 245 SetHighContrastEnabled(true); |
| 246 EXPECT_TRUE(observer.observed()); |
| 247 EXPECT_TRUE(observer.observed_enabled()); |
| 248 EXPECT_EQ(observer.observed_type(), |
| 249 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 250 EXPECT_TRUE(IsHighContrastEnabled()); |
| 251 |
| 252 observer.reset(); |
| 253 SetHighContrastEnabled(false); |
| 254 EXPECT_TRUE(observer.observed()); |
| 255 EXPECT_FALSE(observer.observed_enabled()); |
| 256 EXPECT_EQ(observer.observed_type(), |
| 257 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 258 EXPECT_FALSE(IsHighContrastEnabled()); |
| 259 } |
| 260 |
| 261 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, |
| 262 ChangingTypePrefInvokesNotification) { |
| 263 MockAccessibilityObserver observer; |
| 264 |
| 265 // Logs in. |
| 266 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 267 UserManager::Get()->SessionStarted(); |
| 268 |
| 269 EXPECT_FALSE(observer.observed()); |
| 270 observer.reset(); |
| 271 |
| 272 SetSpokenFeedbackEnabledToPref(true); |
| 273 EXPECT_TRUE(observer.observed()); |
| 274 EXPECT_TRUE(observer.observed_enabled()); |
| 275 EXPECT_EQ(observer.observed_type(), |
| 276 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 277 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 278 |
| 279 observer.reset(); |
| 280 SetSpokenFeedbackEnabledToPref(false); |
| 281 EXPECT_TRUE(observer.observed()); |
| 282 EXPECT_FALSE(observer.observed_enabled()); |
| 283 EXPECT_EQ(observer.observed_type(), |
| 284 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 285 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 286 |
| 287 observer.reset(); |
| 288 SetHighContrastEnabledToPref(true); |
| 289 EXPECT_TRUE(observer.observed()); |
| 290 EXPECT_TRUE(observer.observed_enabled()); |
| 291 EXPECT_EQ(observer.observed_type(), |
| 292 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 293 EXPECT_TRUE(IsHighContrastEnabled()); |
| 294 |
| 295 observer.reset(); |
| 296 SetHighContrastEnabledToPref(false); |
| 297 EXPECT_TRUE(observer.observed()); |
| 298 EXPECT_FALSE(observer.observed_enabled()); |
| 299 EXPECT_EQ(observer.observed_type(), |
| 300 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 301 EXPECT_FALSE(IsHighContrastEnabled()); |
| 302 } |
| 303 |
| 304 } // namespace chromeos |
OLD | NEW |