Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / accessibility / accessibility_manager_browsertest.cc
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/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.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/ime/component_extension_ime_manager.h"
28 #include "chromeos/ime/input_method_manager.h"
29 #include "chromeos/login/user_names.h"
30 #include "components/user_manager/user_manager.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"
34
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;
43
44 namespace chromeos {
45
46 namespace {
47
48 const char kTestUserName[] = "owner@invalid.domain";
49
50 const int kTestAutoclickDelayMs = 2000;
51
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";
55
56 class MockAccessibilityObserver {
57  public:
58   MockAccessibilityObserver() : observed_(false),
59                                 observed_enabled_(false),
60                                 observed_type_(-1)
61   {
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)));
67   }
68
69   virtual ~MockAccessibilityObserver() {}
70
71   bool observed() const { return observed_; }
72   bool observed_enabled() const { return observed_enabled_; }
73   int observed_type() const { return observed_type_; }
74
75   void reset() { observed_ = false; }
76
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;
84     }
85   }
86
87   bool observed_;
88   bool observed_enabled_;
89   int observed_type_;
90
91   scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
92
93   DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver);
94 };
95
96 void SetLargeCursorEnabled(bool enabled) {
97   return AccessibilityManager::Get()->EnableLargeCursor(enabled);
98 }
99
100 bool IsLargeCursorEnabled() {
101   return AccessibilityManager::Get()->IsLargeCursorEnabled();
102 }
103
104 bool ShouldShowAccessibilityMenu() {
105   return AccessibilityManager::Get()->ShouldShowAccessibilityMenu();
106 }
107
108 void SetHighContrastEnabled(bool enabled) {
109   return AccessibilityManager::Get()->EnableHighContrast(enabled);
110 }
111
112 bool IsHighContrastEnabled() {
113   return AccessibilityManager::Get()->IsHighContrastEnabled();
114 }
115
116 void SetSpokenFeedbackEnabled(bool enabled) {
117   return AccessibilityManager::Get()->EnableSpokenFeedback(
118       enabled, ash::A11Y_NOTIFICATION_NONE);
119 }
120
121 bool IsSpokenFeedbackEnabled() {
122   return AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
123 }
124
125 void SetAutoclickEnabled(bool enabled) {
126   return AccessibilityManager::Get()->EnableAutoclick(enabled);
127 }
128
129 bool IsAutoclickEnabled() {
130   return AccessibilityManager::Get()->IsAutoclickEnabled();
131 }
132
133 void SetAutoclickDelay(int delay_ms) {
134   return AccessibilityManager::Get()->SetAutoclickDelay(delay_ms);
135 }
136
137 int GetAutoclickDelay() {
138   return AccessibilityManager::Get()->GetAutoclickDelay();
139 }
140
141 void SetVirtualKeyboardEnabled(bool enabled) {
142   return AccessibilityManager::Get()->EnableVirtualKeyboard(enabled);
143 }
144
145 bool IsVirtualKeyboardEnabled() {
146   return AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
147 }
148
149 Profile* GetProfile() {
150   Profile* profile = ProfileManager::GetActiveUserProfile();
151   DCHECK(profile);
152   return profile;
153 }
154
155 PrefService* GetPrefs() {
156   return GetProfile()->GetPrefs();
157 }
158
159 void SetLargeCursorEnabledPref(bool enabled) {
160   GetPrefs()->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, enabled);
161 }
162
163 void SetHighContrastEnabledPref(bool enabled) {
164   GetPrefs()->SetBoolean(prefs::kAccessibilityHighContrastEnabled, enabled);
165 }
166
167 void SetSpokenFeedbackEnabledPref(bool enabled) {
168   GetPrefs()->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, enabled);
169 }
170
171 void SetAutoclickEnabledPref(bool enabled) {
172   GetPrefs()->SetBoolean(prefs::kAccessibilityAutoclickEnabled, enabled);
173 }
174
175 void SetAutoclickDelayPref(int delay_ms) {
176   GetPrefs()->SetInteger(prefs::kAccessibilityAutoclickDelayMs, delay_ms);
177 }
178
179 void SetVirtualKeyboardEnabledPref(bool enabled) {
180   GetPrefs()->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, enabled);
181 }
182
183 bool GetLargeCursorEnabledFromPref() {
184   return GetPrefs()->GetBoolean(prefs::kAccessibilityLargeCursorEnabled);
185 }
186
187 bool GetHighContrastEnabledFromPref() {
188   return GetPrefs()->GetBoolean(prefs::kAccessibilityHighContrastEnabled);
189 }
190
191 bool GetSpokenFeedbackEnabledFromPref() {
192   return GetPrefs()->GetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled);
193 }
194
195 bool GetAutoclickEnabledFromPref() {
196   return GetPrefs()->GetBoolean(prefs::kAccessibilityAutoclickEnabled);
197 }
198
199 int GetAutoclickDelayFromPref() {
200   return GetPrefs()->GetInteger(prefs::kAccessibilityAutoclickDelayMs);
201 }
202
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;
212   }
213   return false;
214 }
215
216 bool IsBrailleImeCurrent() {
217   InputMethodManager* imm = InputMethodManager::Get();
218   return imm->GetCurrentInputMethod().id() ==
219          extension_misc::kBrailleImeEngineId;
220 }
221 }  // anonymous namespace
222
223 class AccessibilityManagerTest : public InProcessBrowserTest {
224  protected:
225   AccessibilityManagerTest() : default_autoclick_delay_(0) {}
226   virtual ~AccessibilityManagerTest() {}
227
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);
232   }
233
234   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
235     AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
236   }
237
238   virtual void SetUpOnMainThread() OVERRIDE {
239     // Sets the login-screen profile.
240     AccessibilityManager::Get()->
241         SetProfileForTest(ProfileHelper::GetSigninProfile());
242     default_autoclick_delay_ = GetAutoclickDelay();
243   }
244
245   virtual void TearDownOnMainThread() OVERRIDE {
246     AccessibilityManager::SetBrailleControllerForTest(NULL);
247   }
248
249   void SetBrailleDisplayAvailability(bool available) {
250     braille_controller_.SetAvailable(available);
251     braille_controller_.GetObserver()->OnBrailleDisplayStateChanged(
252         *braille_controller_.GetDisplayState());
253   }
254
255   int default_autoclick_delay() const { return default_autoclick_delay_; }
256
257   int default_autoclick_delay_;
258
259   content::NotificationRegistrar registrar_;
260
261   MockBrailleController braille_controller_;
262   DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest);
263 };
264
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());
273
274   // Logs in.
275   user_manager::UserManager::Get()->UserLoggedIn(
276       kTestUserName, kTestUserName, true);
277
278   // Confirms that the features still disabled just after login.
279   EXPECT_FALSE(IsLargeCursorEnabled());
280   EXPECT_FALSE(IsSpokenFeedbackEnabled());
281   EXPECT_FALSE(IsHighContrastEnabled());
282   EXPECT_FALSE(IsAutoclickEnabled());
283   EXPECT_FALSE(IsVirtualKeyboardEnabled());
284   EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
285
286   user_manager::UserManager::Get()->SessionStarted();
287
288   // Confirms that the features are still disabled just after login.
289   EXPECT_FALSE(IsLargeCursorEnabled());
290   EXPECT_FALSE(IsSpokenFeedbackEnabled());
291   EXPECT_FALSE(IsHighContrastEnabled());
292   EXPECT_FALSE(IsAutoclickEnabled());
293   EXPECT_FALSE(IsVirtualKeyboardEnabled());
294   EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
295
296   // Enables large cursor.
297   SetLargeCursorEnabled(true);
298   // Confirms that large cursor is enabled.
299   EXPECT_TRUE(IsLargeCursorEnabled());
300
301   // Enables spoken feedback.
302   SetSpokenFeedbackEnabled(true);
303   // Confirms that the spoken feedback is enabled.
304   EXPECT_TRUE(IsSpokenFeedbackEnabled());
305
306   // Enables high contrast.
307   SetHighContrastEnabled(true);
308   // Confirms that high cotrast is enabled.
309   EXPECT_TRUE(IsHighContrastEnabled());
310
311   // Enables autoclick.
312   SetAutoclickEnabled(true);
313   // Confirms that autoclick is enabled.
314   EXPECT_TRUE(IsAutoclickEnabled());
315
316   // Test that autoclick delay is set properly.
317   SetAutoclickDelay(kTestAutoclickDelayMs);
318   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
319
320   // Enable on-screen keyboard
321   SetVirtualKeyboardEnabled(true);
322   // Confirm that the on-screen keyboard option is enabled.
323   EXPECT_TRUE(IsVirtualKeyboardEnabled());
324 }
325
326 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, BrailleOnLoginScreen) {
327   EXPECT_FALSE(IsSpokenFeedbackEnabled());
328
329   // Signal the accessibility manager that a braille display was connected.
330   SetBrailleDisplayAvailability(true);
331   // Confirms that the spoken feedback is enabled.
332   EXPECT_TRUE(IsSpokenFeedbackEnabled());
333 }
334
335 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) {
336   // Logs in.
337   user_manager::UserManager::Get()->UserLoggedIn(
338       kTestUserName, kTestUserName, true);
339   user_manager::UserManager::Get()->SessionStarted();
340
341   // Confirms that the features are disabled just after login.
342   EXPECT_FALSE(IsLargeCursorEnabled());
343   EXPECT_FALSE(IsSpokenFeedbackEnabled());
344   EXPECT_FALSE(IsHighContrastEnabled());
345   EXPECT_FALSE(IsAutoclickEnabled());
346   EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
347   EXPECT_FALSE(IsVirtualKeyboardEnabled());
348
349   // Sets the pref as true to enable the large cursor.
350   SetLargeCursorEnabledPref(true);
351   // Confirms that the large cursor is enabled.
352   EXPECT_TRUE(IsLargeCursorEnabled());
353
354   // Sets the pref as true to enable the spoken feedback.
355   SetSpokenFeedbackEnabledPref(true);
356   // Confirms that the spoken feedback is enabled.
357   EXPECT_TRUE(IsSpokenFeedbackEnabled());
358
359   // Sets the pref as true to enable high contrast mode.
360   SetHighContrastEnabledPref(true);
361   // Confirms that the high contrast mode is enabled.
362   EXPECT_TRUE(IsHighContrastEnabled());
363
364   // Sets the pref as true to enable autoclick.
365   SetAutoclickEnabledPref(true);
366   // Confirms that autoclick is enabled.
367   EXPECT_TRUE(IsAutoclickEnabled());
368
369   // Set autoclick delay pref.
370   SetAutoclickDelayPref(kTestAutoclickDelayMs);
371   // Confirm that the correct value is set.
372   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
373
374   // Sets the on-screen keyboard pref.
375   SetVirtualKeyboardEnabledPref(true);
376   // Confirm that the on-screen keyboard option is enabled.
377   EXPECT_TRUE(IsVirtualKeyboardEnabled());
378
379   SetLargeCursorEnabledPref(false);
380   EXPECT_FALSE(IsLargeCursorEnabled());
381
382   SetSpokenFeedbackEnabledPref(false);
383   EXPECT_FALSE(IsSpokenFeedbackEnabled());
384
385   SetHighContrastEnabledPref(false);
386   EXPECT_FALSE(IsHighContrastEnabled());
387
388   SetAutoclickEnabledPref(false);
389   EXPECT_FALSE(IsAutoclickEnabled());
390
391   SetVirtualKeyboardEnabledPref(false);
392   EXPECT_FALSE(IsVirtualKeyboardEnabled());
393 }
394
395 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) {
396   // Loads the profile of the user.
397   user_manager::UserManager::Get()->UserLoggedIn(
398       kTestUserName, kTestUserName, true);
399
400   // Sets the pref to enable large cursor before login.
401   SetLargeCursorEnabledPref(true);
402   EXPECT_FALSE(IsLargeCursorEnabled());
403
404   // Sets the pref to enable spoken feedback before login.
405   SetSpokenFeedbackEnabledPref(true);
406   EXPECT_FALSE(IsSpokenFeedbackEnabled());
407
408   // Sets the pref to enable high contrast before login.
409   SetHighContrastEnabledPref(true);
410   EXPECT_FALSE(IsHighContrastEnabled());
411
412   // Sets the pref to enable autoclick before login.
413   SetAutoclickEnabledPref(true);
414   EXPECT_FALSE(IsAutoclickEnabled());
415
416   // Sets the autoclick delay pref before login but the
417   // initial value should not change.
418   SetAutoclickDelayPref(kTestAutoclickDelayMs);
419   EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
420
421   // Sets the pref to enable the on-screen keyboard before login.
422   SetVirtualKeyboardEnabledPref(true);
423   EXPECT_FALSE(IsVirtualKeyboardEnabled());
424
425   // Logs in.
426   user_manager::UserManager::Get()->SessionStarted();
427
428   // Confirms that features are enabled by restoring from pref just after login.
429   EXPECT_TRUE(IsLargeCursorEnabled());
430   EXPECT_TRUE(IsSpokenFeedbackEnabled());
431   EXPECT_TRUE(IsHighContrastEnabled());
432   EXPECT_TRUE(IsAutoclickEnabled());
433   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
434   EXPECT_TRUE(IsVirtualKeyboardEnabled());
435 }
436
437 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
438                        ChangingTypeInvokesNotification) {
439   MockAccessibilityObserver observer;
440
441   // Logs in.
442   user_manager::UserManager::Get()->UserLoggedIn(
443       kTestUserName, kTestUserName, true);
444   user_manager::UserManager::Get()->SessionStarted();
445
446   EXPECT_FALSE(observer.observed());
447   observer.reset();
448
449   SetSpokenFeedbackEnabled(true);
450   EXPECT_TRUE(observer.observed());
451   EXPECT_TRUE(observer.observed_enabled());
452   EXPECT_EQ(observer.observed_type(),
453             ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
454   EXPECT_TRUE(IsSpokenFeedbackEnabled());
455
456   observer.reset();
457   SetSpokenFeedbackEnabled(false);
458   EXPECT_TRUE(observer.observed());
459   EXPECT_FALSE(observer.observed_enabled());
460   EXPECT_EQ(observer.observed_type(),
461             ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
462   EXPECT_FALSE(IsSpokenFeedbackEnabled());
463
464   observer.reset();
465   SetHighContrastEnabled(true);
466   EXPECT_TRUE(observer.observed());
467   EXPECT_TRUE(observer.observed_enabled());
468   EXPECT_EQ(observer.observed_type(),
469             ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
470   EXPECT_TRUE(IsHighContrastEnabled());
471
472   observer.reset();
473   SetHighContrastEnabled(false);
474   EXPECT_TRUE(observer.observed());
475   EXPECT_FALSE(observer.observed_enabled());
476   EXPECT_EQ(observer.observed_type(),
477             ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
478   EXPECT_FALSE(IsHighContrastEnabled());
479
480   observer.reset();
481   SetVirtualKeyboardEnabled(true);
482   EXPECT_TRUE(observer.observed());
483   EXPECT_TRUE(observer.observed_enabled());
484   EXPECT_EQ(observer.observed_type(),
485             ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
486   EXPECT_TRUE(IsVirtualKeyboardEnabled());
487
488   observer.reset();
489   SetVirtualKeyboardEnabled(false);
490   EXPECT_TRUE(observer.observed());
491   EXPECT_FALSE(observer.observed_enabled());
492   EXPECT_EQ(observer.observed_type(),
493             ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
494   EXPECT_FALSE(IsVirtualKeyboardEnabled());
495 }
496
497 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
498                        ChangingTypePrefInvokesNotification) {
499   MockAccessibilityObserver observer;
500
501   // Logs in.
502   user_manager::UserManager::Get()->UserLoggedIn(
503       kTestUserName, kTestUserName, true);
504   user_manager::UserManager::Get()->SessionStarted();
505
506   EXPECT_FALSE(observer.observed());
507   observer.reset();
508
509   SetSpokenFeedbackEnabledPref(true);
510   EXPECT_TRUE(observer.observed());
511   EXPECT_TRUE(observer.observed_enabled());
512   EXPECT_EQ(observer.observed_type(),
513             ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
514   EXPECT_TRUE(IsSpokenFeedbackEnabled());
515
516   observer.reset();
517   SetSpokenFeedbackEnabledPref(false);
518   EXPECT_TRUE(observer.observed());
519   EXPECT_FALSE(observer.observed_enabled());
520   EXPECT_EQ(observer.observed_type(),
521             ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
522   EXPECT_FALSE(IsSpokenFeedbackEnabled());
523
524   observer.reset();
525   SetHighContrastEnabledPref(true);
526   EXPECT_TRUE(observer.observed());
527   EXPECT_TRUE(observer.observed_enabled());
528   EXPECT_EQ(observer.observed_type(),
529             ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
530   EXPECT_TRUE(IsHighContrastEnabled());
531
532   observer.reset();
533   SetHighContrastEnabledPref(false);
534   EXPECT_TRUE(observer.observed());
535   EXPECT_FALSE(observer.observed_enabled());
536   EXPECT_EQ(observer.observed_type(),
537             ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
538   EXPECT_FALSE(IsHighContrastEnabled());
539
540   observer.reset();
541   SetVirtualKeyboardEnabledPref(true);
542   EXPECT_TRUE(observer.observed());
543   EXPECT_TRUE(observer.observed_enabled());
544   EXPECT_EQ(observer.observed_type(),
545             ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
546   EXPECT_TRUE(IsVirtualKeyboardEnabled());
547
548   observer.reset();
549   SetVirtualKeyboardEnabledPref(false);
550   EXPECT_TRUE(observer.observed());
551   EXPECT_FALSE(observer.observed_enabled());
552   EXPECT_EQ(observer.observed_type(),
553             ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
554   EXPECT_FALSE(IsVirtualKeyboardEnabled());
555 }
556
557 class AccessibilityManagerUserTypeTest
558     : public AccessibilityManagerTest,
559       public ::testing::WithParamInterface<const char*> {
560  protected:
561   AccessibilityManagerUserTypeTest() {}
562   virtual ~AccessibilityManagerUserTypeTest() {}
563
564   DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerUserTypeTest);
565 };
566
567 // TODO(yoshiki): Enable a test for retail mode.
568 INSTANTIATE_TEST_CASE_P(
569     UserTypeInstantiation,
570     AccessibilityManagerUserTypeTest,
571     ::testing::Values(kTestUserName,
572                       chromeos::login::kGuestUserName,
573                       // chromeos::login::kRetailModeUserName,
574                       kTestSupervisedUserName));
575
576 IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest,
577                        EnableOnLoginScreenAndLogin) {
578   // Enables large cursor.
579   SetLargeCursorEnabled(true);
580   EXPECT_TRUE(IsLargeCursorEnabled());
581   // Enables spoken feedback.
582   SetSpokenFeedbackEnabled(true);
583   EXPECT_TRUE(IsSpokenFeedbackEnabled());
584   // Enables high contrast.
585   SetHighContrastEnabled(true);
586   EXPECT_TRUE(IsHighContrastEnabled());
587   // Enables autoclick.
588   SetAutoclickEnabled(true);
589   EXPECT_TRUE(IsAutoclickEnabled());
590   // Set autoclick delay.
591   SetAutoclickDelay(kTestAutoclickDelayMs);
592   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
593
594   // Logs in.
595   const char* user_name = GetParam();
596   user_manager::UserManager::Get()->UserLoggedIn(user_name, user_name, true);
597
598   // Confirms that the features are still enabled just after login.
599   EXPECT_TRUE(IsLargeCursorEnabled());
600   EXPECT_TRUE(IsSpokenFeedbackEnabled());
601   EXPECT_TRUE(IsHighContrastEnabled());
602   EXPECT_TRUE(IsAutoclickEnabled());
603   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
604
605   user_manager::UserManager::Get()->SessionStarted();
606
607   // Confirms that the features keep enabled after session starts.
608   EXPECT_TRUE(IsLargeCursorEnabled());
609   EXPECT_TRUE(IsSpokenFeedbackEnabled());
610   EXPECT_TRUE(IsHighContrastEnabled());
611   EXPECT_TRUE(IsAutoclickEnabled());
612   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
613
614   // Confirms that the prefs have been copied to the user's profile.
615   EXPECT_TRUE(GetLargeCursorEnabledFromPref());
616   EXPECT_TRUE(GetSpokenFeedbackEnabledFromPref());
617   EXPECT_TRUE(GetHighContrastEnabledFromPref());
618   EXPECT_TRUE(GetAutoclickEnabledFromPref());
619   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelayFromPref());
620 }
621
622 IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest, BrailleWhenLoggedIn) {
623   // Logs in.
624   const char* user_name = GetParam();
625   user_manager::UserManager::Get()->UserLoggedIn(user_name, user_name, true);
626   user_manager::UserManager::Get()->SessionStarted();
627   // This object watches for IME preference changes and reflects those in
628   // the IME framework state.
629   chromeos::Preferences prefs;
630   prefs.InitUserPrefsForTesting(
631       PrefServiceSyncable::FromProfile(GetProfile()),
632       user_manager::UserManager::Get()->GetActiveUser());
633
634   // Make sure we start in the expected state.
635   EXPECT_FALSE(IsBrailleImeActive());
636   EXPECT_FALSE(IsSpokenFeedbackEnabled());
637
638   // Signal the accessibility manager that a braille display was connected.
639   SetBrailleDisplayAvailability(true);
640
641   // Now, both spoken feedback and the Braille IME should be enabled.
642   EXPECT_TRUE(IsSpokenFeedbackEnabled());
643   EXPECT_TRUE(IsBrailleImeActive());
644
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());
652
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());
659
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());
665 }
666
667 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, AcessibilityMenuVisibility) {
668   // Log in.
669   user_manager::UserManager::Get()->UserLoggedIn(
670       kTestUserName, kTestUserName, true);
671   user_manager::UserManager::Get()->SessionStarted();
672
673   // Confirms that the features are disabled.
674   EXPECT_FALSE(IsLargeCursorEnabled());
675   EXPECT_FALSE(IsSpokenFeedbackEnabled());
676   EXPECT_FALSE(IsHighContrastEnabled());
677   EXPECT_FALSE(IsAutoclickEnabled());
678   EXPECT_FALSE(ShouldShowAccessibilityMenu());
679   EXPECT_FALSE(IsVirtualKeyboardEnabled());
680
681   // Check large cursor.
682   SetLargeCursorEnabled(true);
683   EXPECT_TRUE(ShouldShowAccessibilityMenu());
684   SetLargeCursorEnabled(false);
685   EXPECT_FALSE(ShouldShowAccessibilityMenu());
686
687   // Check spoken feedback.
688   SetSpokenFeedbackEnabled(true);
689   EXPECT_TRUE(ShouldShowAccessibilityMenu());
690   SetSpokenFeedbackEnabled(false);
691   EXPECT_FALSE(ShouldShowAccessibilityMenu());
692
693   // Check high contrast.
694   SetHighContrastEnabled(true);
695   EXPECT_TRUE(ShouldShowAccessibilityMenu());
696   SetHighContrastEnabled(false);
697   EXPECT_FALSE(ShouldShowAccessibilityMenu());
698
699   // Check autoclick.
700   SetAutoclickEnabled(true);
701   EXPECT_TRUE(ShouldShowAccessibilityMenu());
702   SetAutoclickEnabled(false);
703   EXPECT_FALSE(ShouldShowAccessibilityMenu());
704
705   // Check on-screen keyboard.
706   SetVirtualKeyboardEnabled(true);
707   EXPECT_TRUE(ShouldShowAccessibilityMenu());
708   SetVirtualKeyboardEnabled(false);
709   EXPECT_FALSE(ShouldShowAccessibilityMenu());
710 }
711
712 }  // namespace chromeos