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.
5 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
7 #include "ash/magnifier/magnification_controller.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/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
14 #include "chrome/browser/chromeos/login/helper.h"
15 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
16 #include "chrome/browser/chromeos/preferences.h"
17 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/extensions/api/braille_display_private/mock_braille_controller.h"
19 #include "chrome/browser/prefs/pref_service_syncable_util.h"
20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/common/extensions/extension_constants.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "chromeos/chromeos_switches.h"
27 #include "chromeos/login/user_names.h"
28 #include "components/syncable_prefs/pref_service_syncable.h"
29 #include "components/user_manager/user_manager.h"
30 #include "content/public/browser/notification_service.h"
31 #include "content/public/test/test_utils.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "ui/base/ime/chromeos/component_extension_ime_manager.h"
34 #include "ui/base/ime/chromeos/input_method_manager.h"
36 using chromeos::input_method::InputMethodManager
;
37 using chromeos::input_method::InputMethodUtil
;
38 using chromeos::input_method::InputMethodDescriptors
;
39 using content::BrowserThread
;
40 using extensions::api::braille_display_private::BrailleObserver
;
41 using extensions::api::braille_display_private::DisplayState
;
42 using extensions::api::braille_display_private::KeyEvent
;
43 using extensions::api::braille_display_private::MockBrailleController
;
49 const char kTestUserName
[] = "owner@invalid.domain";
51 const int kTestAutoclickDelayMs
= 2000;
53 // Test user name for supervised user. The domain part must be matched with
54 // chromeos::login::kSupervisedUserDomain.
55 const char kTestSupervisedUserName
[] = "test@locally-managed.localhost";
57 class MockAccessibilityObserver
{
59 MockAccessibilityObserver() : observed_(false),
60 observed_enabled_(false),
63 AccessibilityManager
* accessibility_manager
= AccessibilityManager::Get();
64 CHECK(accessibility_manager
);
65 accessibility_subscription_
= accessibility_manager
->RegisterCallback(
66 base::Bind(&MockAccessibilityObserver::OnAccessibilityStatusChanged
,
67 base::Unretained(this)));
70 virtual ~MockAccessibilityObserver() {}
72 bool observed() const { return observed_
; }
73 bool observed_enabled() const { return observed_enabled_
; }
74 int observed_type() const { return observed_type_
; }
76 void reset() { observed_
= false; }
79 void OnAccessibilityStatusChanged(
80 const AccessibilityStatusEventDetails
& details
) {
81 if (details
.notification_type
!= ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER
) {
82 observed_type_
= details
.notification_type
;
83 observed_enabled_
= details
.enabled
;
89 bool observed_enabled_
;
92 scoped_ptr
<AccessibilityStatusSubscription
> accessibility_subscription_
;
94 DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver
);
97 void SetLargeCursorEnabled(bool enabled
) {
98 return AccessibilityManager::Get()->EnableLargeCursor(enabled
);
101 bool IsLargeCursorEnabled() {
102 return AccessibilityManager::Get()->IsLargeCursorEnabled();
105 bool ShouldShowAccessibilityMenu() {
106 return AccessibilityManager::Get()->ShouldShowAccessibilityMenu();
109 void SetHighContrastEnabled(bool enabled
) {
110 return AccessibilityManager::Get()->EnableHighContrast(enabled
);
113 bool IsHighContrastEnabled() {
114 return AccessibilityManager::Get()->IsHighContrastEnabled();
117 void SetSpokenFeedbackEnabled(bool enabled
) {
118 return AccessibilityManager::Get()->EnableSpokenFeedback(
119 enabled
, ui::A11Y_NOTIFICATION_NONE
);
122 bool IsSpokenFeedbackEnabled() {
123 return AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
126 void SetAutoclickEnabled(bool enabled
) {
127 return AccessibilityManager::Get()->EnableAutoclick(enabled
);
130 bool IsAutoclickEnabled() {
131 return AccessibilityManager::Get()->IsAutoclickEnabled();
134 void SetAutoclickDelay(int delay_ms
) {
135 return AccessibilityManager::Get()->SetAutoclickDelay(delay_ms
);
138 int GetAutoclickDelay() {
139 return AccessibilityManager::Get()->GetAutoclickDelay();
142 void SetVirtualKeyboardEnabled(bool enabled
) {
143 return AccessibilityManager::Get()->EnableVirtualKeyboard(enabled
);
146 bool IsVirtualKeyboardEnabled() {
147 return AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
150 Profile
* GetProfile() {
151 Profile
* profile
= ProfileManager::GetActiveUserProfile();
156 PrefService
* GetPrefs() {
157 return GetProfile()->GetPrefs();
160 void SetLargeCursorEnabledPref(bool enabled
) {
161 GetPrefs()->SetBoolean(prefs::kAccessibilityLargeCursorEnabled
, enabled
);
164 void SetHighContrastEnabledPref(bool enabled
) {
165 GetPrefs()->SetBoolean(prefs::kAccessibilityHighContrastEnabled
, enabled
);
168 void SetSpokenFeedbackEnabledPref(bool enabled
) {
169 GetPrefs()->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled
, enabled
);
172 void SetAutoclickEnabledPref(bool enabled
) {
173 GetPrefs()->SetBoolean(prefs::kAccessibilityAutoclickEnabled
, enabled
);
176 void SetAutoclickDelayPref(int delay_ms
) {
177 GetPrefs()->SetInteger(prefs::kAccessibilityAutoclickDelayMs
, delay_ms
);
180 void SetVirtualKeyboardEnabledPref(bool enabled
) {
181 GetPrefs()->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled
, enabled
);
184 bool GetLargeCursorEnabledFromPref() {
185 return GetPrefs()->GetBoolean(prefs::kAccessibilityLargeCursorEnabled
);
188 bool GetHighContrastEnabledFromPref() {
189 return GetPrefs()->GetBoolean(prefs::kAccessibilityHighContrastEnabled
);
192 bool GetSpokenFeedbackEnabledFromPref() {
193 return GetPrefs()->GetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled
);
196 bool GetAutoclickEnabledFromPref() {
197 return GetPrefs()->GetBoolean(prefs::kAccessibilityAutoclickEnabled
);
200 int GetAutoclickDelayFromPref() {
201 return GetPrefs()->GetInteger(prefs::kAccessibilityAutoclickDelayMs
);
204 bool 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();
211 if (i
->id() == extension_misc::kBrailleImeEngineId
)
217 bool IsBrailleImeCurrent() {
218 InputMethodManager
* imm
= InputMethodManager::Get();
219 return imm
->GetActiveIMEState()->GetCurrentInputMethod().id() ==
220 extension_misc::kBrailleImeEngineId
;
222 } // anonymous namespace
224 class AccessibilityManagerTest
: public InProcessBrowserTest
{
226 AccessibilityManagerTest() : default_autoclick_delay_(0) {}
227 ~AccessibilityManagerTest() override
{}
229 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
230 command_line
->AppendSwitch(chromeos::switches::kLoginManager
);
231 command_line
->AppendSwitchASCII(chromeos::switches::kLoginProfile
,
232 TestingProfile::kTestUserProfileDir
);
235 void SetUpInProcessBrowserTestFixture() override
{
236 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_
);
239 void SetUpOnMainThread() override
{
240 // Sets the login-screen profile.
241 AccessibilityManager::Get()->
242 SetProfileForTest(ProfileHelper::GetSigninProfile());
243 default_autoclick_delay_
= GetAutoclickDelay();
246 void TearDownOnMainThread() override
{
247 AccessibilityManager::SetBrailleControllerForTest(NULL
);
250 void SetBrailleDisplayAvailability(bool available
) {
251 braille_controller_
.SetAvailable(available
);
252 braille_controller_
.GetObserver()->OnBrailleDisplayStateChanged(
253 *braille_controller_
.GetDisplayState());
256 int default_autoclick_delay() const { return default_autoclick_delay_
; }
258 int default_autoclick_delay_
;
260 content::NotificationRegistrar registrar_
;
262 MockBrailleController braille_controller_
;
263 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest
);
266 IN_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());
276 user_manager::UserManager::Get()->UserLoggedIn(
277 kTestUserName
, kTestUserName
, true);
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());
287 user_manager::UserManager::Get()->SessionStarted();
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());
297 // Enables large cursor.
298 SetLargeCursorEnabled(true);
299 // Confirms that large cursor is enabled.
300 EXPECT_TRUE(IsLargeCursorEnabled());
302 // Enables spoken feedback.
303 SetSpokenFeedbackEnabled(true);
304 // Confirms that the spoken feedback is enabled.
305 EXPECT_TRUE(IsSpokenFeedbackEnabled());
307 // Enables high contrast.
308 SetHighContrastEnabled(true);
309 // Confirms that high cotrast is enabled.
310 EXPECT_TRUE(IsHighContrastEnabled());
312 // Enables autoclick.
313 SetAutoclickEnabled(true);
314 // Confirms that autoclick is enabled.
315 EXPECT_TRUE(IsAutoclickEnabled());
317 // Test that autoclick delay is set properly.
318 SetAutoclickDelay(kTestAutoclickDelayMs
);
319 EXPECT_EQ(kTestAutoclickDelayMs
, GetAutoclickDelay());
321 // Enable on-screen keyboard
322 SetVirtualKeyboardEnabled(true);
323 // Confirm that the on-screen keyboard option is enabled.
324 EXPECT_TRUE(IsVirtualKeyboardEnabled());
327 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest
, BrailleOnLoginScreen
) {
328 EXPECT_FALSE(IsSpokenFeedbackEnabled());
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());
336 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest
, TypePref
) {
338 user_manager::UserManager::Get()->UserLoggedIn(
339 kTestUserName
, kTestUserName
, true);
340 user_manager::UserManager::Get()->SessionStarted();
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());
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());
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());
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());
365 // Sets the pref as true to enable autoclick.
366 SetAutoclickEnabledPref(true);
367 // Confirms that autoclick is enabled.
368 EXPECT_TRUE(IsAutoclickEnabled());
370 // Set autoclick delay pref.
371 SetAutoclickDelayPref(kTestAutoclickDelayMs
);
372 // Confirm that the correct value is set.
373 EXPECT_EQ(kTestAutoclickDelayMs
, GetAutoclickDelay());
375 // Sets the on-screen keyboard pref.
376 SetVirtualKeyboardEnabledPref(true);
377 // Confirm that the on-screen keyboard option is enabled.
378 EXPECT_TRUE(IsVirtualKeyboardEnabled());
380 SetLargeCursorEnabledPref(false);
381 EXPECT_FALSE(IsLargeCursorEnabled());
383 SetSpokenFeedbackEnabledPref(false);
384 EXPECT_FALSE(IsSpokenFeedbackEnabled());
386 SetHighContrastEnabledPref(false);
387 EXPECT_FALSE(IsHighContrastEnabled());
389 SetAutoclickEnabledPref(false);
390 EXPECT_FALSE(IsAutoclickEnabled());
392 SetVirtualKeyboardEnabledPref(false);
393 EXPECT_FALSE(IsVirtualKeyboardEnabled());
396 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest
, ResumeSavedPref
) {
397 // Loads the profile of the user.
398 user_manager::UserManager::Get()->UserLoggedIn(
399 kTestUserName
, kTestUserName
, true);
401 // Sets the pref to enable large cursor before login.
402 SetLargeCursorEnabledPref(true);
403 EXPECT_FALSE(IsLargeCursorEnabled());
405 // Sets the pref to enable spoken feedback before login.
406 SetSpokenFeedbackEnabledPref(true);
407 EXPECT_FALSE(IsSpokenFeedbackEnabled());
409 // Sets the pref to enable high contrast before login.
410 SetHighContrastEnabledPref(true);
411 EXPECT_FALSE(IsHighContrastEnabled());
413 // Sets the pref to enable autoclick before login.
414 SetAutoclickEnabledPref(true);
415 EXPECT_FALSE(IsAutoclickEnabled());
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());
422 // Sets the pref to enable the on-screen keyboard before login.
423 SetVirtualKeyboardEnabledPref(true);
424 EXPECT_FALSE(IsVirtualKeyboardEnabled());
427 user_manager::UserManager::Get()->SessionStarted();
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());
438 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest
,
439 ChangingTypeInvokesNotification
) {
440 MockAccessibilityObserver observer
;
443 user_manager::UserManager::Get()->UserLoggedIn(
444 kTestUserName
, kTestUserName
, true);
445 user_manager::UserManager::Get()->SessionStarted();
447 EXPECT_FALSE(observer
.observed());
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());
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());
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());
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());
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());
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());
498 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest
,
499 ChangingTypePrefInvokesNotification
) {
500 MockAccessibilityObserver observer
;
503 user_manager::UserManager::Get()->UserLoggedIn(
504 kTestUserName
, kTestUserName
, true);
505 user_manager::UserManager::Get()->SessionStarted();
507 EXPECT_FALSE(observer
.observed());
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());
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());
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());
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());
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());
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());
558 class AccessibilityManagerUserTypeTest
559 : public AccessibilityManagerTest
,
560 public ::testing::WithParamInterface
<const char*> {
562 AccessibilityManagerUserTypeTest() {}
563 virtual ~AccessibilityManagerUserTypeTest() {}
565 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerUserTypeTest
);
568 // TODO(yoshiki): Enable a test for retail mode.
569 INSTANTIATE_TEST_CASE_P(
570 UserTypeInstantiation
,
571 AccessibilityManagerUserTypeTest
,
572 ::testing::Values(kTestUserName
,
573 chromeos::login::kGuestUserName
,
574 // chromeos::login::kRetailModeUserName,
575 kTestSupervisedUserName
));
577 IN_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());
596 const char* user_name
= GetParam();
597 user_manager::UserManager::Get()->UserLoggedIn(user_name
, user_name
, true);
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());
606 user_manager::UserManager::Get()->SessionStarted();
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());
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());
623 IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest
, BrailleWhenLoggedIn
) {
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 PrefServiceSyncableFromProfile(GetProfile()),
633 user_manager::UserManager::Get()->GetActiveUser(),
634 UserSessionManager::GetInstance()->GetDefaultIMEState(GetProfile()));
636 // Make sure we start in the expected state.
637 EXPECT_FALSE(IsBrailleImeActive());
638 EXPECT_FALSE(IsSpokenFeedbackEnabled());
640 // Signal the accessibility manager that a braille display was connected.
641 SetBrailleDisplayAvailability(true);
643 // Now, both spoken feedback and the Braille IME should be enabled.
644 EXPECT_TRUE(IsSpokenFeedbackEnabled());
645 EXPECT_TRUE(IsBrailleImeActive());
647 // Send a braille dots key event and make sure that the braille IME is
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());
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());
662 // Plugging in a display while spoken feedback is enabled should activate
664 SetBrailleDisplayAvailability(true);
665 EXPECT_TRUE(IsSpokenFeedbackEnabled());
666 EXPECT_TRUE(IsBrailleImeActive());
669 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest
, AccessibilityMenuVisibility
) {
671 user_manager::UserManager::Get()->UserLoggedIn(
672 kTestUserName
, kTestUserName
, true);
673 user_manager::UserManager::Get()->SessionStarted();
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());
683 // Check large cursor.
684 SetLargeCursorEnabled(true);
685 EXPECT_TRUE(ShouldShowAccessibilityMenu());
686 SetLargeCursorEnabled(false);
687 EXPECT_FALSE(ShouldShowAccessibilityMenu());
689 // Check spoken feedback.
690 SetSpokenFeedbackEnabled(true);
691 EXPECT_TRUE(ShouldShowAccessibilityMenu());
692 SetSpokenFeedbackEnabled(false);
693 EXPECT_FALSE(ShouldShowAccessibilityMenu());
695 // Check high contrast.
696 SetHighContrastEnabled(true);
697 EXPECT_TRUE(ShouldShowAccessibilityMenu());
698 SetHighContrastEnabled(false);
699 EXPECT_FALSE(ShouldShowAccessibilityMenu());
702 SetAutoclickEnabled(true);
703 EXPECT_TRUE(ShouldShowAccessibilityMenu());
704 SetAutoclickEnabled(false);
705 EXPECT_FALSE(ShouldShowAccessibilityMenu());
707 // Check on-screen keyboard.
708 SetVirtualKeyboardEnabled(true);
709 EXPECT_TRUE(ShouldShowAccessibilityMenu());
710 SetVirtualKeyboardEnabled(false);
711 EXPECT_FALSE(ShouldShowAccessibilityMenu());
714 } // namespace chromeos