accessibility_manager_browsertest.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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/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/session/user_session_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 "components/user_manager/user_manager.h"
32#include "content/public/browser/notification_service.h"
33#include "content/public/test/test_utils.h"
34#include "testing/gtest/include/gtest/gtest.h"
35
36using chromeos::input_method::InputMethodManager;
37using chromeos::input_method::InputMethodUtil;
38using chromeos::input_method::InputMethodDescriptors;
39using content::BrowserThread;
40using extensions::api::braille_display_private::BrailleObserver;
41using extensions::api::braille_display_private::DisplayState;
42using extensions::api::braille_display_private::KeyEvent;
43using extensions::api::braille_display_private::MockBrailleController;
44
45namespace chromeos {
46
47namespace {
48
49const char kTestUserName[] = "owner@invalid.domain";
50
51const int kTestAutoclickDelayMs = 2000;
52
53// Test user name for supervised user. The domain part must be matched with
54// chromeos::login::kSupervisedUserDomain.
55const char kTestSupervisedUserName[] = "test@locally-managed.localhost";
56
57class MockAccessibilityObserver {
58 public:
59  MockAccessibilityObserver() : observed_(false),
60                                observed_enabled_(false),
61                                observed_type_(-1)
62  {
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)));
68  }
69
70  virtual ~MockAccessibilityObserver() {}
71
72  bool observed() const { return observed_; }
73  bool observed_enabled() const { return observed_enabled_; }
74  int observed_type() const { return observed_type_; }
75
76  void reset() { observed_ = false; }
77
78 private:
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;
84      observed_ = true;
85    }
86  }
87
88  bool observed_;
89  bool observed_enabled_;
90  int observed_type_;
91
92  scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
93
94  DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver);
95};
96
97void SetLargeCursorEnabled(bool enabled) {
98  return AccessibilityManager::Get()->EnableLargeCursor(enabled);
99}
100
101bool IsLargeCursorEnabled() {
102  return AccessibilityManager::Get()->IsLargeCursorEnabled();
103}
104
105bool ShouldShowAccessibilityMenu() {
106  return AccessibilityManager::Get()->ShouldShowAccessibilityMenu();
107}
108
109void SetHighContrastEnabled(bool enabled) {
110  return AccessibilityManager::Get()->EnableHighContrast(enabled);
111}
112
113bool IsHighContrastEnabled() {
114  return AccessibilityManager::Get()->IsHighContrastEnabled();
115}
116
117void SetSpokenFeedbackEnabled(bool enabled) {
118  return AccessibilityManager::Get()->EnableSpokenFeedback(
119      enabled, ash::A11Y_NOTIFICATION_NONE);
120}
121
122bool IsSpokenFeedbackEnabled() {
123  return AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
124}
125
126void SetAutoclickEnabled(bool enabled) {
127  return AccessibilityManager::Get()->EnableAutoclick(enabled);
128}
129
130bool IsAutoclickEnabled() {
131  return AccessibilityManager::Get()->IsAutoclickEnabled();
132}
133
134void SetAutoclickDelay(int delay_ms) {
135  return AccessibilityManager::Get()->SetAutoclickDelay(delay_ms);
136}
137
138int GetAutoclickDelay() {
139  return AccessibilityManager::Get()->GetAutoclickDelay();
140}
141
142void SetVirtualKeyboardEnabled(bool enabled) {
143  return AccessibilityManager::Get()->EnableVirtualKeyboard(enabled);
144}
145
146bool IsVirtualKeyboardEnabled() {
147  return AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
148}
149
150Profile* GetProfile() {
151  Profile* profile = ProfileManager::GetActiveUserProfile();
152  DCHECK(profile);
153  return profile;
154}
155
156PrefService* GetPrefs() {
157  return GetProfile()->GetPrefs();
158}
159
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