Revert 285173 "Removed InProcessBrowserTest::CleanUpOnMainThread()"
[chromium-blink-merge.git] / chrome / browser / chromeos / accessibility / accessibility_manager_browsertest.cc
blobce8ee60074b054918378d237a622475b6ea4ac49
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"
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/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/login_utils.h"
16 #include "chrome/browser/chromeos/login/users/user_manager.h"
17 #include "chrome/browser/chromeos/preferences.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/extensions/api/braille_display_private/mock_braille_controller.h"
20 #include "chrome/browser/prefs/pref_service_syncable.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/pref_names.h"
25 #include "chrome/test/base/in_process_browser_test.h"
26 #include "chrome/test/base/testing_profile.h"
27 #include "chromeos/chromeos_switches.h"
28 #include "chromeos/ime/component_extension_ime_manager.h"
29 #include "chromeos/ime/input_method_manager.h"
30 #include "chromeos/login/user_names.h"
31 #include "content/public/browser/notification_service.h"
32 #include "content/public/test/test_utils.h"
33 #include "testing/gtest/include/gtest/gtest.h"
35 using chromeos::input_method::InputMethodManager;
36 using chromeos::input_method::InputMethodUtil;
37 using chromeos::input_method::InputMethodDescriptors;
38 using content::BrowserThread;
39 using extensions::api::braille_display_private::BrailleObserver;
40 using extensions::api::braille_display_private::DisplayState;
41 using extensions::api::braille_display_private::KeyEvent;
42 using extensions::api::braille_display_private::MockBrailleController;
44 namespace chromeos {
46 namespace {
48 const char kTestUserName[] = "owner@invalid.domain";
50 const int kTestAutoclickDelayMs = 2000;
52 // Test user name for supervised user. The domain part must be matched with
53 // chromeos::login::kSupervisedUserDomain.
54 const char kTestSupervisedUserName[] = "test@locally-managed.localhost";
56 class MockAccessibilityObserver {
57 public:
58 MockAccessibilityObserver() : observed_(false),
59 observed_enabled_(false),
60 observed_type_(-1)
62 AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
63 CHECK(accessibility_manager);
64 accessibility_subscription_ = accessibility_manager->RegisterCallback(
65 base::Bind(&MockAccessibilityObserver::OnAccessibilityStatusChanged,
66 base::Unretained(this)));
69 virtual ~MockAccessibilityObserver() {}
71 bool observed() const { return observed_; }
72 bool observed_enabled() const { return observed_enabled_; }
73 int observed_type() const { return observed_type_; }
75 void reset() { observed_ = false; }
77 private:
78 void OnAccessibilityStatusChanged(
79 const AccessibilityStatusEventDetails& details) {
80 if (details.notification_type != ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER) {
81 observed_type_ = details.notification_type;
82 observed_enabled_ = details.enabled;
83 observed_ = true;
87 bool observed_;
88 bool observed_enabled_;
89 int observed_type_;
91 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
93 DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver);
96 void SetLargeCursorEnabled(bool enabled) {
97 return AccessibilityManager::Get()->EnableLargeCursor(enabled);
100 bool IsLargeCursorEnabled() {
101 return AccessibilityManager::Get()->IsLargeCursorEnabled();
104 bool ShouldShowAccessibilityMenu() {
105 return AccessibilityManager::Get()->ShouldShowAccessibilityMenu();
108 void SetHighContrastEnabled(bool enabled) {
109 return AccessibilityManager::Get()->EnableHighContrast(enabled);
112 bool IsHighContrastEnabled() {
113 return AccessibilityManager::Get()->IsHighContrastEnabled();
116 void SetSpokenFeedbackEnabled(bool enabled) {
117 return AccessibilityManager::Get()->EnableSpokenFeedback(
118 enabled, ash::A11Y_NOTIFICATION_NONE);
121 bool IsSpokenFeedbackEnabled() {
122 return AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
125 void SetAutoclickEnabled(bool enabled) {
126 return AccessibilityManager::Get()->EnableAutoclick(enabled);
129 bool IsAutoclickEnabled() {
130 return AccessibilityManager::Get()->IsAutoclickEnabled();
133 void SetAutoclickDelay(int delay_ms) {
134 return AccessibilityManager::Get()->SetAutoclickDelay(delay_ms);
137 int GetAutoclickDelay() {
138 return AccessibilityManager::Get()->GetAutoclickDelay();
141 void SetVirtualKeyboardEnabled(bool enabled) {
142 return AccessibilityManager::Get()->EnableVirtualKeyboard(enabled);
145 bool IsVirtualKeyboardEnabled() {
146 return AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
149 Profile* GetProfile() {
150 Profile* profile = ProfileManager::GetActiveUserProfile();
151 DCHECK(profile);
152 return profile;
155 PrefService* GetPrefs() {
156 return GetProfile()->GetPrefs();
159 void SetLargeCursorEnabledPref(bool enabled) {
160 GetPrefs()->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, enabled);
163 void SetHighContrastEnabledPref(bool enabled) {
164 GetPrefs()->SetBoolean(prefs::kAccessibilityHighContrastEnabled, enabled);
167 void SetSpokenFeedbackEnabledPref(bool enabled) {
168 GetPrefs()->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, enabled);
171 void SetAutoclickEnabledPref(bool enabled) {
172 GetPrefs()->SetBoolean(prefs::kAccessibilityAutoclickEnabled, enabled);
175 void SetAutoclickDelayPref(int delay_ms) {
176 GetPrefs()->SetInteger(prefs::kAccessibilityAutoclickDelayMs, delay_ms);
179 void SetVirtualKeyboardEnabledPref(bool enabled) {
180 GetPrefs()->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, enabled);
183 bool GetLargeCursorEnabledFromPref() {
184 return GetPrefs()->GetBoolean(prefs::kAccessibilityLargeCursorEnabled);
187 bool GetHighContrastEnabledFromPref() {
188 return GetPrefs()->GetBoolean(prefs::kAccessibilityHighContrastEnabled);
191 bool GetSpokenFeedbackEnabledFromPref() {
192 return GetPrefs()->GetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled);
195 bool GetAutoclickEnabledFromPref() {
196 return GetPrefs()->GetBoolean(prefs::kAccessibilityAutoclickEnabled);
199 int GetAutoclickDelayFromPref() {
200 return GetPrefs()->GetInteger(prefs::kAccessibilityAutoclickDelayMs);
203 bool IsBrailleImeActive() {
204 InputMethodManager* imm = InputMethodManager::Get();
205 scoped_ptr<InputMethodDescriptors> descriptors =
206 imm->GetActiveInputMethods();
207 for (InputMethodDescriptors::const_iterator i = descriptors->begin();
208 i != descriptors->end();
209 ++i) {
210 if (i->id() == extension_misc::kBrailleImeEngineId)
211 return true;
213 return false;
216 bool IsBrailleImeCurrent() {
217 InputMethodManager* imm = InputMethodManager::Get();
218 return imm->GetCurrentInputMethod().id() ==
219 extension_misc::kBrailleImeEngineId;
221 } // anonymous namespace
223 class AccessibilityManagerTest : public InProcessBrowserTest {
224 protected:
225 AccessibilityManagerTest() : default_autoclick_delay_(0) {}
226 virtual ~AccessibilityManagerTest() {}
228 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
229 command_line->AppendSwitch(chromeos::switches::kLoginManager);
230 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
231 TestingProfile::kTestUserProfileDir);
234 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
235 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
238 virtual void SetUpOnMainThread() OVERRIDE {
239 // Sets the login-screen profile.
240 AccessibilityManager::Get()->
241 SetProfileForTest(ProfileHelper::GetSigninProfile());
242 default_autoclick_delay_ = GetAutoclickDelay();
245 virtual void CleanUpOnMainThread() OVERRIDE {
246 AccessibilityManager::SetBrailleControllerForTest(NULL);
249 void SetBrailleDisplayAvailability(bool available) {
250 braille_controller_.SetAvailable(available);
251 braille_controller_.GetObserver()->OnBrailleDisplayStateChanged(
252 *braille_controller_.GetDisplayState());
255 int default_autoclick_delay() const { return default_autoclick_delay_; }
257 int default_autoclick_delay_;
259 content::NotificationRegistrar registrar_;
261 MockBrailleController braille_controller_;
262 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest);
265 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, Login) {
266 // Confirms that a11y features are disabled on the login screen.
267 EXPECT_FALSE(IsLargeCursorEnabled());
268 EXPECT_FALSE(IsSpokenFeedbackEnabled());
269 EXPECT_FALSE(IsHighContrastEnabled());
270 EXPECT_FALSE(IsAutoclickEnabled());
271 EXPECT_FALSE(IsVirtualKeyboardEnabled());
272 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
274 // Logs in.
275 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
277 // Confirms that the features still disabled just after login.
278 EXPECT_FALSE(IsLargeCursorEnabled());
279 EXPECT_FALSE(IsSpokenFeedbackEnabled());
280 EXPECT_FALSE(IsHighContrastEnabled());
281 EXPECT_FALSE(IsAutoclickEnabled());
282 EXPECT_FALSE(IsVirtualKeyboardEnabled());
283 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
285 UserManager::Get()->SessionStarted();
287 // Confirms that the features are still disabled just after login.
288 EXPECT_FALSE(IsLargeCursorEnabled());
289 EXPECT_FALSE(IsSpokenFeedbackEnabled());
290 EXPECT_FALSE(IsHighContrastEnabled());
291 EXPECT_FALSE(IsAutoclickEnabled());
292 EXPECT_FALSE(IsVirtualKeyboardEnabled());
293 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
295 // Enables large cursor.
296 SetLargeCursorEnabled(true);
297 // Confirms that large cursor is enabled.
298 EXPECT_TRUE(IsLargeCursorEnabled());
300 // Enables spoken feedback.
301 SetSpokenFeedbackEnabled(true);
302 // Confirms that the spoken feedback is enabled.
303 EXPECT_TRUE(IsSpokenFeedbackEnabled());
305 // Enables high contrast.
306 SetHighContrastEnabled(true);
307 // Confirms that high cotrast is enabled.
308 EXPECT_TRUE(IsHighContrastEnabled());
310 // Enables autoclick.
311 SetAutoclickEnabled(true);
312 // Confirms that autoclick is enabled.
313 EXPECT_TRUE(IsAutoclickEnabled());
315 // Test that autoclick delay is set properly.
316 SetAutoclickDelay(kTestAutoclickDelayMs);
317 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
319 // Enable on-screen keyboard
320 SetVirtualKeyboardEnabled(true);
321 // Confirm that the on-screen keyboard option is enabled.
322 EXPECT_TRUE(IsVirtualKeyboardEnabled());
325 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, BrailleOnLoginScreen) {
326 EXPECT_FALSE(IsSpokenFeedbackEnabled());
328 // Signal the accessibility manager that a braille display was connected.
329 SetBrailleDisplayAvailability(true);
330 // Confirms that the spoken feedback is enabled.
331 EXPECT_TRUE(IsSpokenFeedbackEnabled());
334 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) {
335 // Logs in.
336 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
337 UserManager::Get()->SessionStarted();
339 // Confirms that the features are disabled just after login.
340 EXPECT_FALSE(IsLargeCursorEnabled());
341 EXPECT_FALSE(IsSpokenFeedbackEnabled());
342 EXPECT_FALSE(IsHighContrastEnabled());
343 EXPECT_FALSE(IsAutoclickEnabled());
344 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
345 EXPECT_FALSE(IsVirtualKeyboardEnabled());
347 // Sets the pref as true to enable the large cursor.
348 SetLargeCursorEnabledPref(true);
349 // Confirms that the large cursor is enabled.
350 EXPECT_TRUE(IsLargeCursorEnabled());
352 // Sets the pref as true to enable the spoken feedback.
353 SetSpokenFeedbackEnabledPref(true);
354 // Confirms that the spoken feedback is enabled.
355 EXPECT_TRUE(IsSpokenFeedbackEnabled());
357 // Sets the pref as true to enable high contrast mode.
358 SetHighContrastEnabledPref(true);
359 // Confirms that the high contrast mode is enabled.
360 EXPECT_TRUE(IsHighContrastEnabled());
362 // Sets the pref as true to enable autoclick.
363 SetAutoclickEnabledPref(true);
364 // Confirms that autoclick is enabled.
365 EXPECT_TRUE(IsAutoclickEnabled());
367 // Set autoclick delay pref.
368 SetAutoclickDelayPref(kTestAutoclickDelayMs);
369 // Confirm that the correct value is set.
370 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
372 // Sets the on-screen keyboard pref.
373 SetVirtualKeyboardEnabledPref(true);
374 // Confirm that the on-screen keyboard option is enabled.
375 EXPECT_TRUE(IsVirtualKeyboardEnabled());
377 SetLargeCursorEnabledPref(false);
378 EXPECT_FALSE(IsLargeCursorEnabled());
380 SetSpokenFeedbackEnabledPref(false);
381 EXPECT_FALSE(IsSpokenFeedbackEnabled());
383 SetHighContrastEnabledPref(false);
384 EXPECT_FALSE(IsHighContrastEnabled());
386 SetAutoclickEnabledPref(false);
387 EXPECT_FALSE(IsAutoclickEnabled());
389 SetVirtualKeyboardEnabledPref(false);
390 EXPECT_FALSE(IsVirtualKeyboardEnabled());
393 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) {
394 // Loads the profile of the user.
395 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
397 // Sets the pref to enable large cursor before login.
398 SetLargeCursorEnabledPref(true);
399 EXPECT_FALSE(IsLargeCursorEnabled());
401 // Sets the pref to enable spoken feedback before login.
402 SetSpokenFeedbackEnabledPref(true);
403 EXPECT_FALSE(IsSpokenFeedbackEnabled());
405 // Sets the pref to enable high contrast before login.
406 SetHighContrastEnabledPref(true);
407 EXPECT_FALSE(IsHighContrastEnabled());
409 // Sets the pref to enable autoclick before login.
410 SetAutoclickEnabledPref(true);
411 EXPECT_FALSE(IsAutoclickEnabled());
413 // Sets the autoclick delay pref before login but the
414 // initial value should not change.
415 SetAutoclickDelayPref(kTestAutoclickDelayMs);
416 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
418 // Sets the pref to enable the on-screen keyboard before login.
419 SetVirtualKeyboardEnabledPref(true);
420 EXPECT_FALSE(IsVirtualKeyboardEnabled());
422 // Logs in.
423 UserManager::Get()->SessionStarted();
425 // Confirms that features are enabled by restoring from pref just after login.
426 EXPECT_TRUE(IsLargeCursorEnabled());
427 EXPECT_TRUE(IsSpokenFeedbackEnabled());
428 EXPECT_TRUE(IsHighContrastEnabled());
429 EXPECT_TRUE(IsAutoclickEnabled());
430 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
431 EXPECT_TRUE(IsVirtualKeyboardEnabled());
434 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
435 ChangingTypeInvokesNotification) {
436 MockAccessibilityObserver observer;
438 // Logs in.
439 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
440 UserManager::Get()->SessionStarted();
442 EXPECT_FALSE(observer.observed());
443 observer.reset();
445 SetSpokenFeedbackEnabled(true);
446 EXPECT_TRUE(observer.observed());
447 EXPECT_TRUE(observer.observed_enabled());
448 EXPECT_EQ(observer.observed_type(),
449 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
450 EXPECT_TRUE(IsSpokenFeedbackEnabled());
452 observer.reset();
453 SetSpokenFeedbackEnabled(false);
454 EXPECT_TRUE(observer.observed());
455 EXPECT_FALSE(observer.observed_enabled());
456 EXPECT_EQ(observer.observed_type(),
457 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
458 EXPECT_FALSE(IsSpokenFeedbackEnabled());
460 observer.reset();
461 SetHighContrastEnabled(true);
462 EXPECT_TRUE(observer.observed());
463 EXPECT_TRUE(observer.observed_enabled());
464 EXPECT_EQ(observer.observed_type(),
465 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
466 EXPECT_TRUE(IsHighContrastEnabled());
468 observer.reset();
469 SetHighContrastEnabled(false);
470 EXPECT_TRUE(observer.observed());
471 EXPECT_FALSE(observer.observed_enabled());
472 EXPECT_EQ(observer.observed_type(),
473 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
474 EXPECT_FALSE(IsHighContrastEnabled());
476 observer.reset();
477 SetVirtualKeyboardEnabled(true);
478 EXPECT_TRUE(observer.observed());
479 EXPECT_TRUE(observer.observed_enabled());
480 EXPECT_EQ(observer.observed_type(),
481 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
482 EXPECT_TRUE(IsVirtualKeyboardEnabled());
484 observer.reset();
485 SetVirtualKeyboardEnabled(false);
486 EXPECT_TRUE(observer.observed());
487 EXPECT_FALSE(observer.observed_enabled());
488 EXPECT_EQ(observer.observed_type(),
489 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
490 EXPECT_FALSE(IsVirtualKeyboardEnabled());
493 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
494 ChangingTypePrefInvokesNotification) {
495 MockAccessibilityObserver observer;
497 // Logs in.
498 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
499 UserManager::Get()->SessionStarted();
501 EXPECT_FALSE(observer.observed());
502 observer.reset();
504 SetSpokenFeedbackEnabledPref(true);
505 EXPECT_TRUE(observer.observed());
506 EXPECT_TRUE(observer.observed_enabled());
507 EXPECT_EQ(observer.observed_type(),
508 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
509 EXPECT_TRUE(IsSpokenFeedbackEnabled());
511 observer.reset();
512 SetSpokenFeedbackEnabledPref(false);
513 EXPECT_TRUE(observer.observed());
514 EXPECT_FALSE(observer.observed_enabled());
515 EXPECT_EQ(observer.observed_type(),
516 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
517 EXPECT_FALSE(IsSpokenFeedbackEnabled());
519 observer.reset();
520 SetHighContrastEnabledPref(true);
521 EXPECT_TRUE(observer.observed());
522 EXPECT_TRUE(observer.observed_enabled());
523 EXPECT_EQ(observer.observed_type(),
524 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
525 EXPECT_TRUE(IsHighContrastEnabled());
527 observer.reset();
528 SetHighContrastEnabledPref(false);
529 EXPECT_TRUE(observer.observed());
530 EXPECT_FALSE(observer.observed_enabled());
531 EXPECT_EQ(observer.observed_type(),
532 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
533 EXPECT_FALSE(IsHighContrastEnabled());
535 observer.reset();
536 SetVirtualKeyboardEnabledPref(true);
537 EXPECT_TRUE(observer.observed());
538 EXPECT_TRUE(observer.observed_enabled());
539 EXPECT_EQ(observer.observed_type(),
540 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
541 EXPECT_TRUE(IsVirtualKeyboardEnabled());
543 observer.reset();
544 SetVirtualKeyboardEnabledPref(false);
545 EXPECT_TRUE(observer.observed());
546 EXPECT_FALSE(observer.observed_enabled());
547 EXPECT_EQ(observer.observed_type(),
548 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
549 EXPECT_FALSE(IsVirtualKeyboardEnabled());
552 class AccessibilityManagerUserTypeTest
553 : public AccessibilityManagerTest,
554 public ::testing::WithParamInterface<const char*> {
555 protected:
556 AccessibilityManagerUserTypeTest() {}
557 virtual ~AccessibilityManagerUserTypeTest() {}
559 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerUserTypeTest);
562 // TODO(yoshiki): Enable a test for retail mode.
563 INSTANTIATE_TEST_CASE_P(
564 UserTypeInstantiation,
565 AccessibilityManagerUserTypeTest,
566 ::testing::Values(kTestUserName,
567 chromeos::login::kGuestUserName,
568 // chromeos::login::kRetailModeUserName,
569 kTestSupervisedUserName));
571 IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest,
572 EnableOnLoginScreenAndLogin) {
573 // Enables large cursor.
574 SetLargeCursorEnabled(true);
575 EXPECT_TRUE(IsLargeCursorEnabled());
576 // Enables spoken feedback.
577 SetSpokenFeedbackEnabled(true);
578 EXPECT_TRUE(IsSpokenFeedbackEnabled());
579 // Enables high contrast.
580 SetHighContrastEnabled(true);
581 EXPECT_TRUE(IsHighContrastEnabled());
582 // Enables autoclick.
583 SetAutoclickEnabled(true);
584 EXPECT_TRUE(IsAutoclickEnabled());
585 // Set autoclick delay.
586 SetAutoclickDelay(kTestAutoclickDelayMs);
587 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
589 // Logs in.
590 const char* user_name = GetParam();
591 UserManager::Get()->UserLoggedIn(user_name, user_name, true);
593 // Confirms that the features are still enabled just after login.
594 EXPECT_TRUE(IsLargeCursorEnabled());
595 EXPECT_TRUE(IsSpokenFeedbackEnabled());
596 EXPECT_TRUE(IsHighContrastEnabled());
597 EXPECT_TRUE(IsAutoclickEnabled());
598 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
600 UserManager::Get()->SessionStarted();
602 // Confirms that the features keep enabled after session starts.
603 EXPECT_TRUE(IsLargeCursorEnabled());
604 EXPECT_TRUE(IsSpokenFeedbackEnabled());
605 EXPECT_TRUE(IsHighContrastEnabled());
606 EXPECT_TRUE(IsAutoclickEnabled());
607 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
609 // Confirms that the prefs have been copied to the user's profile.
610 EXPECT_TRUE(GetLargeCursorEnabledFromPref());
611 EXPECT_TRUE(GetSpokenFeedbackEnabledFromPref());
612 EXPECT_TRUE(GetHighContrastEnabledFromPref());
613 EXPECT_TRUE(GetAutoclickEnabledFromPref());
614 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelayFromPref());
617 IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest, BrailleWhenLoggedIn) {
618 // Logs in.
619 const char* user_name = GetParam();
620 UserManager::Get()->UserLoggedIn(user_name, user_name, true);
621 UserManager::Get()->SessionStarted();
622 // The |ComponentExtensionIMEManager| defers some initialization to the
623 // |FILE| thread. We need to wait for that to finish before continuing.
624 InputMethodManager* imm = InputMethodManager::Get();
625 while (!imm->GetComponentExtensionIMEManager()->IsInitialized()) {
626 content::RunAllPendingInMessageLoop(BrowserThread::FILE);
628 // This object watches for IME preference changes and reflects those in
629 // the IME framework state.
630 chromeos::Preferences prefs;
631 prefs.InitUserPrefsForTesting(PrefServiceSyncable::FromProfile(GetProfile()),
632 UserManager::Get()->GetActiveUser());
634 // Make sure we start in the expected state.
635 EXPECT_FALSE(IsBrailleImeActive());
636 EXPECT_FALSE(IsSpokenFeedbackEnabled());
638 // Signal the accessibility manager that a braille display was connected.
639 SetBrailleDisplayAvailability(true);
641 // Now, both spoken feedback and the Braille IME should be enabled.
642 EXPECT_TRUE(IsSpokenFeedbackEnabled());
643 EXPECT_TRUE(IsBrailleImeActive());
645 // Send a braille dots key event and make sure that the braille IME is
646 // enabled.
647 KeyEvent event;
648 event.command = extensions::api::braille_display_private::KEY_COMMAND_DOTS;
649 event.braille_dots.reset(new int(0));
650 braille_controller_.GetObserver()->OnBrailleKeyEvent(event);
651 EXPECT_TRUE(IsBrailleImeCurrent());
653 // Unplug the display. Spolken feedback remains on, but the Braille IME
654 // should get deactivated.
655 SetBrailleDisplayAvailability(false);
656 EXPECT_TRUE(IsSpokenFeedbackEnabled());
657 EXPECT_FALSE(IsBrailleImeActive());
658 EXPECT_FALSE(IsBrailleImeCurrent());
660 // Plugging in a display while spoken feedback is enabled should activate
661 // the Braille IME.
662 SetBrailleDisplayAvailability(true);
663 EXPECT_TRUE(IsSpokenFeedbackEnabled());
664 EXPECT_TRUE(IsBrailleImeActive());
667 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, AcessibilityMenuVisibility) {
668 // Log in.
669 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
670 UserManager::Get()->SessionStarted();
672 // Confirms that the features are disabled.
673 EXPECT_FALSE(IsLargeCursorEnabled());
674 EXPECT_FALSE(IsSpokenFeedbackEnabled());
675 EXPECT_FALSE(IsHighContrastEnabled());
676 EXPECT_FALSE(IsAutoclickEnabled());
677 EXPECT_FALSE(ShouldShowAccessibilityMenu());
678 EXPECT_FALSE(IsVirtualKeyboardEnabled());
680 // Check large cursor.
681 SetLargeCursorEnabled(true);
682 EXPECT_TRUE(ShouldShowAccessibilityMenu());
683 SetLargeCursorEnabled(false);
684 EXPECT_FALSE(ShouldShowAccessibilityMenu());
686 // Check spoken feedback.
687 SetSpokenFeedbackEnabled(true);
688 EXPECT_TRUE(ShouldShowAccessibilityMenu());
689 SetSpokenFeedbackEnabled(false);
690 EXPECT_FALSE(ShouldShowAccessibilityMenu());
692 // Check high contrast.
693 SetHighContrastEnabled(true);
694 EXPECT_TRUE(ShouldShowAccessibilityMenu());
695 SetHighContrastEnabled(false);
696 EXPECT_FALSE(ShouldShowAccessibilityMenu());
698 // Check autoclick.
699 SetAutoclickEnabled(true);
700 EXPECT_TRUE(ShouldShowAccessibilityMenu());
701 SetAutoclickEnabled(false);
702 EXPECT_FALSE(ShouldShowAccessibilityMenu());
704 // Check on-screen keyboard.
705 SetVirtualKeyboardEnabled(true);
706 EXPECT_TRUE(ShouldShowAccessibilityMenu());
707 SetVirtualKeyboardEnabled(false);
708 EXPECT_FALSE(ShouldShowAccessibilityMenu());
711 } // namespace chromeos