1600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang// Use of this source code is governed by a BSD-style license that can be 3600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang// found in the LICENSE file. 4600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 5600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 6600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 7600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "ash/magnifier/magnification_controller.h" 8600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "ash/shell.h" 9600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "base/command_line.h" 10600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "base/prefs/pref_service.h" 11600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/browser_process.h" 12600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chrome_notification_types.h" 13600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chromeos/accessibility/magnification_manager.h" 14600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chromeos/login/helper.h" 15600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chromeos/login/login_utils.h" 16600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chromeos/login/session/user_session_manager.h" 17600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chromeos/preferences.h" 18600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/chromeos/profiles/profile_helper.h" 19600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/extensions/api/braille_display_private/mock_braille_controller.h" 20600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/prefs/pref_service_syncable.h" 21600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/profiles/profile.h" 22600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/browser/profiles/profile_manager.h" 23600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/common/extensions/extension_constants.h" 24600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/common/pref_names.h" 25600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/test/base/in_process_browser_test.h" 26600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chrome/test/base/testing_profile.h" 27600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chromeos/chromeos_switches.h" 28600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chromeos/ime/component_extension_ime_manager.h" 29600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chromeos/ime/input_method_manager.h" 30600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "chromeos/login/user_names.h" 31600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "components/user_manager/user_manager.h" 32600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "content/public/browser/notification_service.h" 33600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "content/public/test/test_utils.h" 34600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang#include "testing/gtest/include/gtest/gtest.h" 35600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 36600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing chromeos::input_method::InputMethodManager; 37600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing chromeos::input_method::InputMethodUtil; 38600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing chromeos::input_method::InputMethodDescriptors; 39600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing content::BrowserThread; 40600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing extensions::api::braille_display_private::BrailleObserver; 41600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing extensions::api::braille_display_private::DisplayState; 42600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing extensions::api::braille_display_private::KeyEvent; 43600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangusing extensions::api::braille_display_private::MockBrailleController; 44600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 45600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangnamespace chromeos { 46600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 47600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangnamespace { 48600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 49600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangconst char kTestUserName[] = "owner@invalid.domain"; 50600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 51600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangconst int kTestAutoclickDelayMs = 2000; 52600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 53600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang// Test user name for supervised user. The domain part must be matched with 54600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang// chromeos::login::kSupervisedUserDomain. 55600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangconst char kTestSupervisedUserName[] = "test@locally-managed.localhost"; 56600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 57600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangclass MockAccessibilityObserver { 58600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public: 59600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang MockAccessibilityObserver() : observed_(false), 60600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang observed_enabled_(false), 61600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang observed_type_(-1) 62600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang { 63600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang AccessibilityManager* accessibility_manager = AccessibilityManager::Get(); 64600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang CHECK(accessibility_manager); 65600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang accessibility_subscription_ = accessibility_manager->RegisterCallback( 66600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang base::Bind(&MockAccessibilityObserver::OnAccessibilityStatusChanged, 67600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang base::Unretained(this))); 68600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 69600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 70600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang virtual ~MockAccessibilityObserver() {} 71600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 72600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang bool observed() const { return observed_; } 73600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang bool observed_enabled() const { return observed_enabled_; } 74600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang int observed_type() const { return observed_type_; } 75600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 76600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang void reset() { observed_ = false; } 77600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 78600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang private: 79600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang void OnAccessibilityStatusChanged( 80600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang const AccessibilityStatusEventDetails& details) { 81600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (details.notification_type != ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER) { 82600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang observed_type_ = details.notification_type; 83600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang observed_enabled_ = details.enabled; 84600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang observed_ = true; 85600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 86600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 87600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 88600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang bool observed_; 89600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang bool observed_enabled_; 90600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang int observed_type_; 91600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 92600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_; 93600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 94600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver); 95600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang}; 96600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 97600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangvoid SetLargeCursorEnabled(bool enabled) { 98600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->EnableLargeCursor(enabled); 99600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 100600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 101600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangbool IsLargeCursorEnabled() { 102600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->IsLargeCursorEnabled(); 103600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 104600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 105600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangbool ShouldShowAccessibilityMenu() { 106600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->ShouldShowAccessibilityMenu(); 107600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 108600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 109600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangvoid SetHighContrastEnabled(bool enabled) { 110600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->EnableHighContrast(enabled); 111600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 112600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 113600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangbool IsHighContrastEnabled() { 114600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->IsHighContrastEnabled(); 115600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 116600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 117600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangvoid SetSpokenFeedbackEnabled(bool enabled) { 118600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->EnableSpokenFeedback( 119600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang enabled, ash::A11Y_NOTIFICATION_NONE); 120600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 121600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 122600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangbool IsSpokenFeedbackEnabled() { 123600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->IsSpokenFeedbackEnabled(); 124600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 125600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 126600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangvoid SetAutoclickEnabled(bool enabled) { 127600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->EnableAutoclick(enabled); 128600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 129600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 130600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangbool IsAutoclickEnabled() { 131600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->IsAutoclickEnabled(); 132600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 133600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 134600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangvoid SetAutoclickDelay(int delay_ms) { 135600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->SetAutoclickDelay(delay_ms); 136600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 137600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 138600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangint GetAutoclickDelay() { 139600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->GetAutoclickDelay(); 140600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 141600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 142600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangvoid SetVirtualKeyboardEnabled(bool enabled) { 143600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->EnableVirtualKeyboard(enabled); 144600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 145600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 146600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangbool IsVirtualKeyboardEnabled() { 147600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return AccessibilityManager::Get()->IsVirtualKeyboardEnabled(); 148600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 149600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 150600c7a4bbc7348167293eac928192e695b4ad5baChung-yih WangProfile* GetProfile() { 151600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang Profile* profile = ProfileManager::GetActiveUserProfile(); 152600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang DCHECK(profile); 153600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return profile; 154600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 155600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 156600c7a4bbc7348167293eac928192e695b4ad5baChung-yih WangPrefService* GetPrefs() { 157600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return GetProfile()->GetPrefs(); 158600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 159600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 160void SetLargeCursorEnabledPref(bool enabled) { 161 GetPrefs()->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, enabled); 162} 163 164void SetHighContrastEnabledPref(bool enabled) { 165 GetPrefs()->SetBoolean(prefs::kAccessibilityHighContrastEnabled, enabled); 166} 167 168void SetSpokenFeedbackEnabledPref(bool enabled) { 169 GetPrefs()->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, enabled); 170} 171 172void SetAutoclickEnabledPref(bool enabled) { 173 GetPrefs()->SetBoolean(prefs::kAccessibilityAutoclickEnabled, enabled); 174} 175 176void SetAutoclickDelayPref(int delay_ms) { 177 GetPrefs()->SetInteger(prefs::kAccessibilityAutoclickDelayMs, delay_ms); 178} 179 180void SetVirtualKeyboardEnabledPref(bool enabled) { 181 GetPrefs()->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, enabled); 182} 183 184bool GetLargeCursorEnabledFromPref() { 185 return GetPrefs()->GetBoolean(prefs::kAccessibilityLargeCursorEnabled); 186} 187 188bool GetHighContrastEnabledFromPref() { 189 return GetPrefs()->GetBoolean(prefs::kAccessibilityHighContrastEnabled); 190} 191 192bool GetSpokenFeedbackEnabledFromPref() { 193 return GetPrefs()->GetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled); 194} 195 196bool GetAutoclickEnabledFromPref() { 197 return GetPrefs()->GetBoolean(prefs::kAccessibilityAutoclickEnabled); 198} 199 200int GetAutoclickDelayFromPref() { 201 return GetPrefs()->GetInteger(prefs::kAccessibilityAutoclickDelayMs); 202} 203 204bool IsBrailleImeActive() { 205 InputMethodManager* imm = InputMethodManager::Get(); 206 scoped_ptr<InputMethodDescriptors> descriptors = 207 imm->GetActiveIMEState()->GetActiveInputMethods(); 208 for (InputMethodDescriptors::const_iterator i = descriptors->begin(); 209 i != descriptors->end(); 210 ++i) { 211 if (i->id() == extension_misc::kBrailleImeEngineId) 212 return true; 213 } 214 return false; 215} 216 217bool IsBrailleImeCurrent() { 218 InputMethodManager* imm = InputMethodManager::Get(); 219 return imm->GetActiveIMEState()->GetCurrentInputMethod().id() == 220 extension_misc::kBrailleImeEngineId; 221} 222} // anonymous namespace 223 224class AccessibilityManagerTest : public InProcessBrowserTest { 225 protected: 226 AccessibilityManagerTest() : default_autoclick_delay_(0) {} 227 virtual ~AccessibilityManagerTest() {} 228 229 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 230 command_line->AppendSwitch(chromeos::switches::kLoginManager); 231 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, 232 TestingProfile::kTestUserProfileDir); 233 } 234 235 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 236 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_); 237 } 238 239 virtual void SetUpOnMainThread() OVERRIDE { 240 // Sets the login-screen profile. 241 AccessibilityManager::Get()-> 242 SetProfileForTest(ProfileHelper::GetSigninProfile()); 243 default_autoclick_delay_ = GetAutoclickDelay(); 244 } 245 246 virtual void TearDownOnMainThread() OVERRIDE { 247 AccessibilityManager::SetBrailleControllerForTest(NULL); 248 } 249 250 void SetBrailleDisplayAvailability(bool available) { 251 braille_controller_.SetAvailable(available); 252 braille_controller_.GetObserver()->OnBrailleDisplayStateChanged( 253 *braille_controller_.GetDisplayState()); 254 } 255 256 int default_autoclick_delay() const { return default_autoclick_delay_; } 257 258 int default_autoclick_delay_; 259 260 content::NotificationRegistrar registrar_; 261 262 MockBrailleController braille_controller_; 263 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest); 264}; 265 266IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, Login) { 267 // Confirms that a11y features are disabled on the login screen. 268 EXPECT_FALSE(IsLargeCursorEnabled()); 269 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 270 EXPECT_FALSE(IsHighContrastEnabled()); 271 EXPECT_FALSE(IsAutoclickEnabled()); 272 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 273 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 274 275 // Logs in. 276 user_manager::UserManager::Get()->UserLoggedIn( 277 kTestUserName, kTestUserName, true); 278 279 // Confirms that the features still disabled just after login. 280 EXPECT_FALSE(IsLargeCursorEnabled()); 281 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 282 EXPECT_FALSE(IsHighContrastEnabled()); 283 EXPECT_FALSE(IsAutoclickEnabled()); 284 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 285 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 286 287 user_manager::UserManager::Get()->SessionStarted(); 288 289 // Confirms that the features are still disabled just after login. 290 EXPECT_FALSE(IsLargeCursorEnabled()); 291 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 292 EXPECT_FALSE(IsHighContrastEnabled()); 293 EXPECT_FALSE(IsAutoclickEnabled()); 294 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 295 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 296 297 // Enables large cursor. 298 SetLargeCursorEnabled(true); 299 // Confirms that large cursor is enabled. 300 EXPECT_TRUE(IsLargeCursorEnabled()); 301 302 // Enables spoken feedback. 303 SetSpokenFeedbackEnabled(true); 304 // Confirms that the spoken feedback is enabled. 305 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 306 307 // Enables high contrast. 308 SetHighContrastEnabled(true); 309 // Confirms that high cotrast is enabled. 310 EXPECT_TRUE(IsHighContrastEnabled()); 311 312 // Enables autoclick. 313 SetAutoclickEnabled(true); 314 // Confirms that autoclick is enabled. 315 EXPECT_TRUE(IsAutoclickEnabled()); 316 317 // Test that autoclick delay is set properly. 318 SetAutoclickDelay(kTestAutoclickDelayMs); 319 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 320 321 // Enable on-screen keyboard 322 SetVirtualKeyboardEnabled(true); 323 // Confirm that the on-screen keyboard option is enabled. 324 EXPECT_TRUE(IsVirtualKeyboardEnabled()); 325} 326 327IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, BrailleOnLoginScreen) { 328 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 329 330 // Signal the accessibility manager that a braille display was connected. 331 SetBrailleDisplayAvailability(true); 332 // Confirms that the spoken feedback is enabled. 333 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 334} 335 336IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) { 337 // Logs in. 338 user_manager::UserManager::Get()->UserLoggedIn( 339 kTestUserName, kTestUserName, true); 340 user_manager::UserManager::Get()->SessionStarted(); 341 342 // Confirms that the features are disabled just after login. 343 EXPECT_FALSE(IsLargeCursorEnabled()); 344 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 345 EXPECT_FALSE(IsHighContrastEnabled()); 346 EXPECT_FALSE(IsAutoclickEnabled()); 347 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 348 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 349 350 // Sets the pref as true to enable the large cursor. 351 SetLargeCursorEnabledPref(true); 352 // Confirms that the large cursor is enabled. 353 EXPECT_TRUE(IsLargeCursorEnabled()); 354 355 // Sets the pref as true to enable the spoken feedback. 356 SetSpokenFeedbackEnabledPref(true); 357 // Confirms that the spoken feedback is enabled. 358 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 359 360 // Sets the pref as true to enable high contrast mode. 361 SetHighContrastEnabledPref(true); 362 // Confirms that the high contrast mode is enabled. 363 EXPECT_TRUE(IsHighContrastEnabled()); 364 365 // Sets the pref as true to enable autoclick. 366 SetAutoclickEnabledPref(true); 367 // Confirms that autoclick is enabled. 368 EXPECT_TRUE(IsAutoclickEnabled()); 369 370 // Set autoclick delay pref. 371 SetAutoclickDelayPref(kTestAutoclickDelayMs); 372 // Confirm that the correct value is set. 373 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 374 375 // Sets the on-screen keyboard pref. 376 SetVirtualKeyboardEnabledPref(true); 377 // Confirm that the on-screen keyboard option is enabled. 378 EXPECT_TRUE(IsVirtualKeyboardEnabled()); 379 380 SetLargeCursorEnabledPref(false); 381 EXPECT_FALSE(IsLargeCursorEnabled()); 382 383 SetSpokenFeedbackEnabledPref(false); 384 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 385 386 SetHighContrastEnabledPref(false); 387 EXPECT_FALSE(IsHighContrastEnabled()); 388 389 SetAutoclickEnabledPref(false); 390 EXPECT_FALSE(IsAutoclickEnabled()); 391 392 SetVirtualKeyboardEnabledPref(false); 393 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 394} 395 396IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) { 397 // Loads the profile of the user. 398 user_manager::UserManager::Get()->UserLoggedIn( 399 kTestUserName, kTestUserName, true); 400 401 // Sets the pref to enable large cursor before login. 402 SetLargeCursorEnabledPref(true); 403 EXPECT_FALSE(IsLargeCursorEnabled()); 404 405 // Sets the pref to enable spoken feedback before login. 406 SetSpokenFeedbackEnabledPref(true); 407 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 408 409 // Sets the pref to enable high contrast before login. 410 SetHighContrastEnabledPref(true); 411 EXPECT_FALSE(IsHighContrastEnabled()); 412 413 // Sets the pref to enable autoclick before login. 414 SetAutoclickEnabledPref(true); 415 EXPECT_FALSE(IsAutoclickEnabled()); 416 417 // Sets the autoclick delay pref before login but the 418 // initial value should not change. 419 SetAutoclickDelayPref(kTestAutoclickDelayMs); 420 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 421 422 // Sets the pref to enable the on-screen keyboard before login. 423 SetVirtualKeyboardEnabledPref(true); 424 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 425 426 // Logs in. 427 user_manager::UserManager::Get()->SessionStarted(); 428 429 // Confirms that features are enabled by restoring from pref just after login. 430 EXPECT_TRUE(IsLargeCursorEnabled()); 431 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 432 EXPECT_TRUE(IsHighContrastEnabled()); 433 EXPECT_TRUE(IsAutoclickEnabled()); 434 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 435 EXPECT_TRUE(IsVirtualKeyboardEnabled()); 436} 437 438IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, 439 ChangingTypeInvokesNotification) { 440 MockAccessibilityObserver observer; 441 442 // Logs in. 443 user_manager::UserManager::Get()->UserLoggedIn( 444 kTestUserName, kTestUserName, true); 445 user_manager::UserManager::Get()->SessionStarted(); 446 447 EXPECT_FALSE(observer.observed()); 448 observer.reset(); 449 450 SetSpokenFeedbackEnabled(true); 451 EXPECT_TRUE(observer.observed()); 452 EXPECT_TRUE(observer.observed_enabled()); 453 EXPECT_EQ(observer.observed_type(), 454 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); 455 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 456 457 observer.reset(); 458 SetSpokenFeedbackEnabled(false); 459 EXPECT_TRUE(observer.observed()); 460 EXPECT_FALSE(observer.observed_enabled()); 461 EXPECT_EQ(observer.observed_type(), 462 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); 463 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 464 465 observer.reset(); 466 SetHighContrastEnabled(true); 467 EXPECT_TRUE(observer.observed()); 468 EXPECT_TRUE(observer.observed_enabled()); 469 EXPECT_EQ(observer.observed_type(), 470 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); 471 EXPECT_TRUE(IsHighContrastEnabled()); 472 473 observer.reset(); 474 SetHighContrastEnabled(false); 475 EXPECT_TRUE(observer.observed()); 476 EXPECT_FALSE(observer.observed_enabled()); 477 EXPECT_EQ(observer.observed_type(), 478 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); 479 EXPECT_FALSE(IsHighContrastEnabled()); 480 481 observer.reset(); 482 SetVirtualKeyboardEnabled(true); 483 EXPECT_TRUE(observer.observed()); 484 EXPECT_TRUE(observer.observed_enabled()); 485 EXPECT_EQ(observer.observed_type(), 486 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); 487 EXPECT_TRUE(IsVirtualKeyboardEnabled()); 488 489 observer.reset(); 490 SetVirtualKeyboardEnabled(false); 491 EXPECT_TRUE(observer.observed()); 492 EXPECT_FALSE(observer.observed_enabled()); 493 EXPECT_EQ(observer.observed_type(), 494 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); 495 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 496} 497 498IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, 499 ChangingTypePrefInvokesNotification) { 500 MockAccessibilityObserver observer; 501 502 // Logs in. 503 user_manager::UserManager::Get()->UserLoggedIn( 504 kTestUserName, kTestUserName, true); 505 user_manager::UserManager::Get()->SessionStarted(); 506 507 EXPECT_FALSE(observer.observed()); 508 observer.reset(); 509 510 SetSpokenFeedbackEnabledPref(true); 511 EXPECT_TRUE(observer.observed()); 512 EXPECT_TRUE(observer.observed_enabled()); 513 EXPECT_EQ(observer.observed_type(), 514 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); 515 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 516 517 observer.reset(); 518 SetSpokenFeedbackEnabledPref(false); 519 EXPECT_TRUE(observer.observed()); 520 EXPECT_FALSE(observer.observed_enabled()); 521 EXPECT_EQ(observer.observed_type(), 522 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); 523 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 524 525 observer.reset(); 526 SetHighContrastEnabledPref(true); 527 EXPECT_TRUE(observer.observed()); 528 EXPECT_TRUE(observer.observed_enabled()); 529 EXPECT_EQ(observer.observed_type(), 530 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); 531 EXPECT_TRUE(IsHighContrastEnabled()); 532 533 observer.reset(); 534 SetHighContrastEnabledPref(false); 535 EXPECT_TRUE(observer.observed()); 536 EXPECT_FALSE(observer.observed_enabled()); 537 EXPECT_EQ(observer.observed_type(), 538 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); 539 EXPECT_FALSE(IsHighContrastEnabled()); 540 541 observer.reset(); 542 SetVirtualKeyboardEnabledPref(true); 543 EXPECT_TRUE(observer.observed()); 544 EXPECT_TRUE(observer.observed_enabled()); 545 EXPECT_EQ(observer.observed_type(), 546 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); 547 EXPECT_TRUE(IsVirtualKeyboardEnabled()); 548 549 observer.reset(); 550 SetVirtualKeyboardEnabledPref(false); 551 EXPECT_TRUE(observer.observed()); 552 EXPECT_FALSE(observer.observed_enabled()); 553 EXPECT_EQ(observer.observed_type(), 554 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); 555 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 556} 557 558class AccessibilityManagerUserTypeTest 559 : public AccessibilityManagerTest, 560 public ::testing::WithParamInterface<const char*> { 561 protected: 562 AccessibilityManagerUserTypeTest() {} 563 virtual ~AccessibilityManagerUserTypeTest() {} 564 565 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerUserTypeTest); 566}; 567 568// TODO(yoshiki): Enable a test for retail mode. 569INSTANTIATE_TEST_CASE_P( 570 UserTypeInstantiation, 571 AccessibilityManagerUserTypeTest, 572 ::testing::Values(kTestUserName, 573 chromeos::login::kGuestUserName, 574 // chromeos::login::kRetailModeUserName, 575 kTestSupervisedUserName)); 576 577IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest, 578 EnableOnLoginScreenAndLogin) { 579 // Enables large cursor. 580 SetLargeCursorEnabled(true); 581 EXPECT_TRUE(IsLargeCursorEnabled()); 582 // Enables spoken feedback. 583 SetSpokenFeedbackEnabled(true); 584 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 585 // Enables high contrast. 586 SetHighContrastEnabled(true); 587 EXPECT_TRUE(IsHighContrastEnabled()); 588 // Enables autoclick. 589 SetAutoclickEnabled(true); 590 EXPECT_TRUE(IsAutoclickEnabled()); 591 // Set autoclick delay. 592 SetAutoclickDelay(kTestAutoclickDelayMs); 593 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 594 595 // Logs in. 596 const char* user_name = GetParam(); 597 user_manager::UserManager::Get()->UserLoggedIn(user_name, user_name, true); 598 599 // Confirms that the features are still enabled just after login. 600 EXPECT_TRUE(IsLargeCursorEnabled()); 601 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 602 EXPECT_TRUE(IsHighContrastEnabled()); 603 EXPECT_TRUE(IsAutoclickEnabled()); 604 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 605 606 user_manager::UserManager::Get()->SessionStarted(); 607 608 // Confirms that the features keep enabled after session starts. 609 EXPECT_TRUE(IsLargeCursorEnabled()); 610 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 611 EXPECT_TRUE(IsHighContrastEnabled()); 612 EXPECT_TRUE(IsAutoclickEnabled()); 613 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 614 615 // Confirms that the prefs have been copied to the user's profile. 616 EXPECT_TRUE(GetLargeCursorEnabledFromPref()); 617 EXPECT_TRUE(GetSpokenFeedbackEnabledFromPref()); 618 EXPECT_TRUE(GetHighContrastEnabledFromPref()); 619 EXPECT_TRUE(GetAutoclickEnabledFromPref()); 620 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelayFromPref()); 621} 622 623IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest, BrailleWhenLoggedIn) { 624 // Logs in. 625 const char* user_name = GetParam(); 626 user_manager::UserManager::Get()->UserLoggedIn(user_name, user_name, true); 627 user_manager::UserManager::Get()->SessionStarted(); 628 // This object watches for IME preference changes and reflects those in 629 // the IME framework state. 630 chromeos::Preferences prefs; 631 prefs.InitUserPrefsForTesting( 632 PrefServiceSyncable::FromProfile(GetProfile()), 633 user_manager::UserManager::Get()->GetActiveUser(), 634 UserSessionManager::GetInstance()->GetDefaultIMEState(GetProfile())); 635 636 // Make sure we start in the expected state. 637 EXPECT_FALSE(IsBrailleImeActive()); 638 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 639 640 // Signal the accessibility manager that a braille display was connected. 641 SetBrailleDisplayAvailability(true); 642 643 // Now, both spoken feedback and the Braille IME should be enabled. 644 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 645 EXPECT_TRUE(IsBrailleImeActive()); 646 647 // Send a braille dots key event and make sure that the braille IME is 648 // enabled. 649 KeyEvent event; 650 event.command = extensions::api::braille_display_private::KEY_COMMAND_DOTS; 651 event.braille_dots.reset(new int(0)); 652 braille_controller_.GetObserver()->OnBrailleKeyEvent(event); 653 EXPECT_TRUE(IsBrailleImeCurrent()); 654 655 // Unplug the display. Spolken feedback remains on, but the Braille IME 656 // should get deactivated. 657 SetBrailleDisplayAvailability(false); 658 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 659 EXPECT_FALSE(IsBrailleImeActive()); 660 EXPECT_FALSE(IsBrailleImeCurrent()); 661 662 // Plugging in a display while spoken feedback is enabled should activate 663 // the Braille IME. 664 SetBrailleDisplayAvailability(true); 665 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 666 EXPECT_TRUE(IsBrailleImeActive()); 667} 668 669IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, AcessibilityMenuVisibility) { 670 // Log in. 671 user_manager::UserManager::Get()->UserLoggedIn( 672 kTestUserName, kTestUserName, true); 673 user_manager::UserManager::Get()->SessionStarted(); 674 675 // Confirms that the features are disabled. 676 EXPECT_FALSE(IsLargeCursorEnabled()); 677 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 678 EXPECT_FALSE(IsHighContrastEnabled()); 679 EXPECT_FALSE(IsAutoclickEnabled()); 680 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 681 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 682 683 // Check large cursor. 684 SetLargeCursorEnabled(true); 685 EXPECT_TRUE(ShouldShowAccessibilityMenu()); 686 SetLargeCursorEnabled(false); 687 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 688 689 // Check spoken feedback. 690 SetSpokenFeedbackEnabled(true); 691 EXPECT_TRUE(ShouldShowAccessibilityMenu()); 692 SetSpokenFeedbackEnabled(false); 693 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 694 695 // Check high contrast. 696 SetHighContrastEnabled(true); 697 EXPECT_TRUE(ShouldShowAccessibilityMenu()); 698 SetHighContrastEnabled(false); 699 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 700 701 // Check autoclick. 702 SetAutoclickEnabled(true); 703 EXPECT_TRUE(ShouldShowAccessibilityMenu()); 704 SetAutoclickEnabled(false); 705 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 706 707 // Check on-screen keyboard. 708 SetVirtualKeyboardEnabled(true); 709 EXPECT_TRUE(ShouldShowAccessibilityMenu()); 710 SetVirtualKeyboardEnabled(false); 711 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 712} 713 714} // namespace chromeos 715