accessibility_manager_browsertest.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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/user_manager.h"
17#include "chrome/browser/chromeos/login/user_manager_impl.h"
18#include "chrome/browser/chromeos/profiles/profile_helper.h"
19#include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h"
20#include "chrome/browser/profiles/profile.h"
21#include "chrome/browser/profiles/profile_manager.h"
22#include "chrome/common/pref_names.h"
23#include "chrome/test/base/in_process_browser_test.h"
24#include "chrome/test/base/testing_profile.h"
25#include "chromeos/chromeos_switches.h"
26#include "content/public/browser/notification_service.h"
27#include "testing/gtest/include/gtest/gtest.h"
28
29using extensions::api::braille_display_private::BrailleObserver;
30using extensions::api::braille_display_private::DisplayState;
31using extensions::api::braille_display_private::StubBrailleController;
32
33namespace chromeos {
34
35namespace {
36
37const char kTestUserName[] = "owner@invalid.domain";
38
39const int kTestAutoclickDelayMs = 2000;
40
41// Test user name for locally managed user. The domain part must be matched
42// with UserManager::kLocallyManagedUserDomain.
43const char kTestLocallyManagedUserName[] = "test@locally-managed.localhost";
44
45class MockAccessibilityObserver : public content::NotificationObserver {
46 public:
47  MockAccessibilityObserver() : observed_(false),
48                                observed_enabled_(false),
49                                observed_type_(-1) {
50    registrar_.Add(
51        this,
52        chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK,
53        content::NotificationService::AllSources());
54    registrar_.Add(
55        this,
56        chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE,
57        content::NotificationService::AllSources());
58    registrar_.Add(
59        this,
60        chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD,
61        content::NotificationService::AllSources());
62  }
63  virtual ~MockAccessibilityObserver() {}
64
65  bool observed() const { return observed_; }
66  bool observed_enabled() const { return observed_enabled_; }
67  int observed_type() const { return observed_type_; }
68
69  void reset() { observed_ = false; }
70
71 private:
72  // content::NotificationObserver implimentation:
73  virtual void Observe(int type,
74                       const content::NotificationSource& source,
75                       const content::NotificationDetails& details) OVERRIDE {
76    AccessibilityStatusEventDetails* accessibility_status =
77        content::Details<AccessibilityStatusEventDetails>(
78            details).ptr();
79    ASSERT_FALSE(observed_);
80
81    switch (type) {
82      case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK:
83        observed_ = true;
84        observed_enabled_ = accessibility_status->enabled;
85        observed_type_ = type;
86        break;
87      case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE:
88        observed_ = true;
89        observed_enabled_ = accessibility_status->enabled;
90        observed_type_ = type;
91        break;
92      case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD:
93        observed_ = true;
94        observed_enabled_ = accessibility_status->enabled;
95        observed_type_ = type;
96        break;
97    }
98  }
99
100  bool observed_;
101  bool observed_enabled_;
102  int observed_type_;
103
104  content::NotificationRegistrar registrar_;
105
106  DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver);
107};
108
109class MockBrailleController : public StubBrailleController {
110 public:
111
112  MockBrailleController() : available_(false), observer_(NULL) {}
113
114  virtual scoped_ptr<DisplayState> GetDisplayState() OVERRIDE {
115    scoped_ptr<DisplayState> state(new DisplayState());
116    state->available = available_;
117    return state.Pass();
118  }
119
120  virtual void AddObserver(BrailleObserver* observer) OVERRIDE {
121    ASSERT_EQ(NULL, observer_);
122    observer_ = observer;
123  }
124
125  virtual void RemoveObserver(BrailleObserver* observer) OVERRIDE {
126    ASSERT_EQ(observer_, observer);
127  }
128
129  void SetAvailable(bool available) {
130    available_ = available;
131  }
132
133  BrailleObserver* GetObserver() {
134    return observer_;
135  }
136
137 private:
138  bool available_;
139  BrailleObserver* observer_;
140};
141
142void SetLargeCursorEnabled(bool enabled) {
143  return AccessibilityManager::Get()->EnableLargeCursor(enabled);
144}
145
146bool IsLargeCursorEnabled() {
147  return AccessibilityManager::Get()->IsLargeCursorEnabled();
148}
149
150bool ShouldShowAccessibilityMenu() {
151  return AccessibilityManager::Get()->ShouldShowAccessibilityMenu();
152}
153
154void SetHighContrastEnabled(bool enabled) {
155  return AccessibilityManager::Get()->EnableHighContrast(enabled);
156}
157
158bool IsHighContrastEnabled() {
159  return AccessibilityManager::Get()->IsHighContrastEnabled();
160}
161
162void SetSpokenFeedbackEnabled(bool enabled) {
163  return AccessibilityManager::Get()->EnableSpokenFeedback(
164      enabled, ash::A11Y_NOTIFICATION_NONE);
165}
166
167bool IsSpokenFeedbackEnabled() {
168  return AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
169}
170
171void SetAutoclickEnabled(bool enabled) {
172  return AccessibilityManager::Get()->EnableAutoclick(enabled);
173}
174
175bool IsAutoclickEnabled() {
176  return AccessibilityManager::Get()->IsAutoclickEnabled();
177}
178
179void SetAutoclickDelay(int delay_ms) {
180  return AccessibilityManager::Get()->SetAutoclickDelay(delay_ms);
181}
182
183int GetAutoclickDelay() {
184  return AccessibilityManager::Get()->GetAutoclickDelay();
185}
186
187void SetVirtualKeyboardEnabled(bool enabled) {
188  return AccessibilityManager::Get()->EnableVirtualKeyboard(enabled);
189}
190
191bool IsVirtualKeyboardEnabled() {
192  return AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
193}
194
195Profile* GetProfile() {
196  Profile* profile = ProfileManager::GetActiveUserProfile();
197  DCHECK(profile);
198  return profile;
199}
200
201PrefService* GetPrefs() {
202  return GetProfile()->GetPrefs();
203}
204
205void SetLargeCursorEnabledPref(bool enabled) {
206  GetPrefs()->SetBoolean(prefs::kLargeCursorEnabled, enabled);
207}
208
209void SetHighContrastEnabledPref(bool enabled) {
210  GetPrefs()->SetBoolean(prefs::kHighContrastEnabled, enabled);
211}
212
213void SetSpokenFeedbackEnabledPref(bool enabled) {
214  GetPrefs()->SetBoolean(prefs::kSpokenFeedbackEnabled, enabled);
215}
216
217void SetAutoclickEnabledPref(bool enabled) {
218  GetPrefs()->SetBoolean(prefs::kAutoclickEnabled, enabled);
219}
220
221void SetAutoclickDelayPref(int delay_ms) {
222  GetPrefs()->SetInteger(prefs::kAutoclickDelayMs, delay_ms);
223}
224
225void SetVirtualKeyboardEnabledPref(bool enabled) {
226  GetPrefs()->SetBoolean(prefs::kVirtualKeyboardEnabled, enabled);
227}
228
229bool GetLargeCursorEnabledFromPref() {
230  return GetPrefs()->GetBoolean(prefs::kLargeCursorEnabled);
231}
232
233bool GetHighContrastEnabledFromPref() {
234  return GetPrefs()->GetBoolean(prefs::kHighContrastEnabled);
235}
236
237bool GetSpokenFeedbackEnabledFromPref() {
238  return GetPrefs()->GetBoolean(prefs::kSpokenFeedbackEnabled);
239}
240
241bool GetAutoclickEnabledFromPref() {
242  return GetPrefs()->GetBoolean(prefs::kAutoclickEnabled);
243}
244
245int GetAutoclickDelayFromPref() {
246  return GetPrefs()->GetInteger(prefs::kAutoclickDelayMs);
247}
248
249}  // anonymouse namespace
250
251class AccessibilityManagerTest : public InProcessBrowserTest {
252 protected:
253  AccessibilityManagerTest() : default_autoclick_delay_(0) {}
254  virtual ~AccessibilityManagerTest() {}
255
256  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
257    command_line->AppendSwitch(chromeos::switches::kLoginManager);
258    command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
259                                    TestingProfile::kTestUserProfileDir);
260  }
261
262  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
263    AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
264  }
265
266  virtual void SetUpOnMainThread() OVERRIDE {
267    // Sets the login-screen profile.
268    AccessibilityManager::Get()->
269        SetProfileForTest(ProfileHelper::GetSigninProfile());
270    default_autoclick_delay_ = GetAutoclickDelay();
271  }
272
273  virtual void CleanUpOnMainThread() OVERRIDE {
274    AccessibilityManager::SetBrailleControllerForTest(NULL);
275  }
276
277  int default_autoclick_delay() const { return default_autoclick_delay_; }
278
279  int default_autoclick_delay_;
280
281  content::NotificationRegistrar registrar_;
282
283  MockBrailleController braille_controller_;
284  DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest);
285};
286
287IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, Login) {
288  // Confirms that a11y features are disabled on the login screen.
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  // Logs in.
297  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
298
299  // Confirms that the features still disabled just after login.
300  EXPECT_FALSE(IsLargeCursorEnabled());
301  EXPECT_FALSE(IsSpokenFeedbackEnabled());
302  EXPECT_FALSE(IsHighContrastEnabled());
303  EXPECT_FALSE(IsAutoclickEnabled());
304  EXPECT_FALSE(IsVirtualKeyboardEnabled());
305  EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
306
307  UserManager::Get()->SessionStarted();
308
309  // Confirms that the features are still disabled just after login.
310  EXPECT_FALSE(IsLargeCursorEnabled());
311  EXPECT_FALSE(IsSpokenFeedbackEnabled());
312  EXPECT_FALSE(IsHighContrastEnabled());
313  EXPECT_FALSE(IsAutoclickEnabled());
314  EXPECT_FALSE(IsVirtualKeyboardEnabled());
315  EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
316
317  // Enables large cursor.
318  SetLargeCursorEnabled(true);
319  // Confirms that large cursor is enabled.
320  EXPECT_TRUE(IsLargeCursorEnabled());
321
322  // Enables spoken feedback.
323  SetSpokenFeedbackEnabled(true);
324  // Confirms that the spoken feedback is enabled.
325  EXPECT_TRUE(IsSpokenFeedbackEnabled());
326
327  // Enables high contrast.
328  SetHighContrastEnabled(true);
329  // Confirms that high cotrast is enabled.
330  EXPECT_TRUE(IsHighContrastEnabled());
331
332  // Enables autoclick.
333  SetAutoclickEnabled(true);
334  // Confirms that autoclick is enabled.
335  EXPECT_TRUE(IsAutoclickEnabled());
336
337  // Test that autoclick delay is set properly.
338  SetAutoclickDelay(kTestAutoclickDelayMs);
339  EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
340
341  // Enable on-screen keyboard
342  SetVirtualKeyboardEnabled(true);
343  // Confirm that the on-screen keyboard option is enabled.
344  EXPECT_TRUE(IsVirtualKeyboardEnabled());
345}
346
347IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, BrailleOnLoginScreen) {
348  EXPECT_FALSE(IsSpokenFeedbackEnabled());
349
350  // Signal the accessibility manager that a braille display was connected.
351  braille_controller_.SetAvailable(true);
352  braille_controller_.GetObserver()->OnDisplayStateChanged(
353      *braille_controller_.GetDisplayState());
354
355  // Confirms that the spoken feedback is enabled.
356  EXPECT_TRUE(IsSpokenFeedbackEnabled());
357}
358
359IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) {
360  // Logs in.
361  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
362  UserManager::Get()->SessionStarted();
363
364  // Confirms that the features are disabled just after login.
365  EXPECT_FALSE(IsLargeCursorEnabled());
366  EXPECT_FALSE(IsSpokenFeedbackEnabled());
367  EXPECT_FALSE(IsHighContrastEnabled());
368  EXPECT_FALSE(IsAutoclickEnabled());
369  EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
370  EXPECT_FALSE(IsVirtualKeyboardEnabled());
371
372  // Sets the pref as true to enable the large cursor.
373  SetLargeCursorEnabledPref(true);
374  // Confirms that the large cursor is enabled.
375  EXPECT_TRUE(IsLargeCursorEnabled());
376
377  // Sets the pref as true to enable the spoken feedback.
378  SetSpokenFeedbackEnabledPref(true);
379  // Confirms that the spoken feedback is enabled.
380  EXPECT_TRUE(IsSpokenFeedbackEnabled());
381
382  // Sets the pref as true to enable high contrast mode.
383  SetHighContrastEnabledPref(true);
384  // Confirms that the high contrast mode is enabled.
385  EXPECT_TRUE(IsHighContrastEnabled());
386
387  // Sets the pref as true to enable autoclick.
388  SetAutoclickEnabledPref(true);
389  // Confirms that autoclick is enabled.
390  EXPECT_TRUE(IsAutoclickEnabled());
391
392  // Set autoclick delay pref.
393  SetAutoclickDelayPref(kTestAutoclickDelayMs);
394  // Confirm that the correct value is set.
395  EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
396
397  // Sets the on-screen keyboard pref.
398  SetVirtualKeyboardEnabledPref(true);
399  // Confirm that the on-screen keyboard option is enabled.
400  EXPECT_TRUE(IsVirtualKeyboardEnabled());
401
402  SetLargeCursorEnabledPref(false);
403  EXPECT_FALSE(IsLargeCursorEnabled());
404
405  SetSpokenFeedbackEnabledPref(false);
406  EXPECT_FALSE(IsSpokenFeedbackEnabled());
407
408  SetHighContrastEnabledPref(false);
409  EXPECT_FALSE(IsHighContrastEnabled());
410
411  SetAutoclickEnabledPref(false);
412  EXPECT_FALSE(IsAutoclickEnabled());
413
414  SetVirtualKeyboardEnabledPref(false);
415  EXPECT_FALSE(IsVirtualKeyboardEnabled());
416}
417
418IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) {
419  // Loads the profile of the user.
420  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
421
422  // Sets the pref to enable large cursor before login.
423  SetLargeCursorEnabledPref(true);
424  EXPECT_FALSE(IsLargeCursorEnabled());
425
426  // Sets the pref to enable spoken feedback before login.
427  SetSpokenFeedbackEnabledPref(true);
428  EXPECT_FALSE(IsSpokenFeedbackEnabled());
429
430  // Sets the pref to enable high contrast before login.
431  SetHighContrastEnabledPref(true);
432  EXPECT_FALSE(IsHighContrastEnabled());
433
434  // Sets the pref to enable autoclick before login.
435  SetAutoclickEnabledPref(true);
436  EXPECT_FALSE(IsAutoclickEnabled());
437
438  // Sets the autoclick delay pref before login but the
439  // initial value should not change.
440  SetAutoclickDelayPref(kTestAutoclickDelayMs);
441  EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
442
443  // Sets the pref to enable the on-screen keyboard before login.
444  SetVirtualKeyboardEnabledPref(true);
445  EXPECT_FALSE(IsVirtualKeyboardEnabled());
446
447  // Logs in.
448  UserManager::Get()->SessionStarted();
449
450  // Confirms that features are enabled by restoring from pref just after login.
451  EXPECT_TRUE(IsLargeCursorEnabled());
452  EXPECT_TRUE(IsSpokenFeedbackEnabled());
453  EXPECT_TRUE(IsHighContrastEnabled());
454  EXPECT_TRUE(IsAutoclickEnabled());
455  EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
456  EXPECT_TRUE(IsVirtualKeyboardEnabled());
457}
458
459IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
460                       ChangingTypeInvokesNotification) {
461  MockAccessibilityObserver observer;
462
463  // Logs in.
464  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
465  UserManager::Get()->SessionStarted();
466
467  EXPECT_FALSE(observer.observed());
468  observer.reset();
469
470  SetSpokenFeedbackEnabled(true);
471  EXPECT_TRUE(observer.observed());
472  EXPECT_TRUE(observer.observed_enabled());
473  EXPECT_EQ(observer.observed_type(),
474            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
475  EXPECT_TRUE(IsSpokenFeedbackEnabled());
476
477  observer.reset();
478  SetSpokenFeedbackEnabled(false);
479  EXPECT_TRUE(observer.observed());
480  EXPECT_FALSE(observer.observed_enabled());
481  EXPECT_EQ(observer.observed_type(),
482            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
483  EXPECT_FALSE(IsSpokenFeedbackEnabled());
484
485  observer.reset();
486  SetHighContrastEnabled(true);
487  EXPECT_TRUE(observer.observed());
488  EXPECT_TRUE(observer.observed_enabled());
489  EXPECT_EQ(observer.observed_type(),
490            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
491  EXPECT_TRUE(IsHighContrastEnabled());
492
493  observer.reset();
494  SetHighContrastEnabled(false);
495  EXPECT_TRUE(observer.observed());
496  EXPECT_FALSE(observer.observed_enabled());
497  EXPECT_EQ(observer.observed_type(),
498            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
499  EXPECT_FALSE(IsHighContrastEnabled());
500
501  observer.reset();
502  SetVirtualKeyboardEnabled(true);
503  EXPECT_TRUE(observer.observed());
504  EXPECT_TRUE(observer.observed_enabled());
505  EXPECT_EQ(observer.observed_type(),
506            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
507  EXPECT_TRUE(IsVirtualKeyboardEnabled());
508
509  observer.reset();
510  SetVirtualKeyboardEnabled(false);
511  EXPECT_TRUE(observer.observed());
512  EXPECT_FALSE(observer.observed_enabled());
513  EXPECT_EQ(observer.observed_type(),
514            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
515  EXPECT_FALSE(IsVirtualKeyboardEnabled());
516}
517
518IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
519                       ChangingTypePrefInvokesNotification) {
520  MockAccessibilityObserver observer;
521
522  // Logs in.
523  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
524  UserManager::Get()->SessionStarted();
525
526  EXPECT_FALSE(observer.observed());
527  observer.reset();
528
529  SetSpokenFeedbackEnabledPref(true);
530  EXPECT_TRUE(observer.observed());
531  EXPECT_TRUE(observer.observed_enabled());
532  EXPECT_EQ(observer.observed_type(),
533            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
534  EXPECT_TRUE(IsSpokenFeedbackEnabled());
535
536  observer.reset();
537  SetSpokenFeedbackEnabledPref(false);
538  EXPECT_TRUE(observer.observed());
539  EXPECT_FALSE(observer.observed_enabled());
540  EXPECT_EQ(observer.observed_type(),
541            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
542  EXPECT_FALSE(IsSpokenFeedbackEnabled());
543
544  observer.reset();
545  SetHighContrastEnabledPref(true);
546  EXPECT_TRUE(observer.observed());
547  EXPECT_TRUE(observer.observed_enabled());
548  EXPECT_EQ(observer.observed_type(),
549            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
550  EXPECT_TRUE(IsHighContrastEnabled());
551
552  observer.reset();
553  SetHighContrastEnabledPref(false);
554  EXPECT_TRUE(observer.observed());
555  EXPECT_FALSE(observer.observed_enabled());
556  EXPECT_EQ(observer.observed_type(),
557            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
558  EXPECT_FALSE(IsHighContrastEnabled());
559
560  observer.reset();
561  SetVirtualKeyboardEnabledPref(true);
562  EXPECT_TRUE(observer.observed());
563  EXPECT_TRUE(observer.observed_enabled());
564  EXPECT_EQ(observer.observed_type(),
565            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
566  EXPECT_TRUE(IsVirtualKeyboardEnabled());
567
568  observer.reset();
569  SetVirtualKeyboardEnabledPref(false);
570  EXPECT_TRUE(observer.observed());
571  EXPECT_FALSE(observer.observed_enabled());
572  EXPECT_EQ(observer.observed_type(),
573            chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD);
574  EXPECT_FALSE(IsVirtualKeyboardEnabled());
575}
576
577class AccessibilityManagerUserTypeTest
578    : public AccessibilityManagerTest,
579      public ::testing::WithParamInterface<const char*> {
580 protected:
581  AccessibilityManagerUserTypeTest() {}
582  virtual ~AccessibilityManagerUserTypeTest() {}
583
584  DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerUserTypeTest);
585};
586
587// TODO(yoshiki): Enable a test for retail mode.
588INSTANTIATE_TEST_CASE_P(
589    UserTypeInstantiation,
590    AccessibilityManagerUserTypeTest,
591    ::testing::Values(kTestUserName,
592                      UserManager::kGuestUserName,
593                      //UserManager::kRetailModeUserName,
594                      kTestLocallyManagedUserName));
595
596IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest,
597                       EnableOnLoginScreenAndLogin) {
598  // Enables large cursor.
599  SetLargeCursorEnabled(true);
600  EXPECT_TRUE(IsLargeCursorEnabled());
601  // Enables spoken feedback.
602  SetSpokenFeedbackEnabled(true);
603  EXPECT_TRUE(IsSpokenFeedbackEnabled());
604  // Enables high contrast.
605  SetHighContrastEnabled(true);
606  EXPECT_TRUE(IsHighContrastEnabled());
607  // Enables autoclick.
608  SetAutoclickEnabled(true);
609  EXPECT_TRUE(IsAutoclickEnabled());
610  // Set autoclick delay.
611  SetAutoclickDelay(kTestAutoclickDelayMs);
612  EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
613
614  // Logs in.
615  const char* user_name = GetParam();
616  UserManager::Get()->UserLoggedIn(user_name, user_name, true);
617
618  // Confirms that the features are still enabled just after login.
619  EXPECT_TRUE(IsLargeCursorEnabled());
620  EXPECT_TRUE(IsSpokenFeedbackEnabled());
621  EXPECT_TRUE(IsHighContrastEnabled());
622  EXPECT_TRUE(IsAutoclickEnabled());
623  EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
624
625  UserManager::Get()->SessionStarted();
626
627  // Confirms that the features keep enabled after session starts.
628  EXPECT_TRUE(IsLargeCursorEnabled());
629  EXPECT_TRUE(IsSpokenFeedbackEnabled());
630  EXPECT_TRUE(IsHighContrastEnabled());
631  EXPECT_TRUE(IsAutoclickEnabled());
632  EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
633
634  // Confirms that the prefs have been copied to the user's profile.
635  EXPECT_TRUE(GetLargeCursorEnabledFromPref());
636  EXPECT_TRUE(GetSpokenFeedbackEnabledFromPref());
637  EXPECT_TRUE(GetHighContrastEnabledFromPref());
638  EXPECT_TRUE(GetAutoclickEnabledFromPref());
639  EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelayFromPref());
640}
641
642IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, AcessibilityMenuVisibility) {
643  // Log in.
644  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
645  UserManager::Get()->SessionStarted();
646
647  // Confirms that the features are disabled.
648  EXPECT_FALSE(IsLargeCursorEnabled());
649  EXPECT_FALSE(IsSpokenFeedbackEnabled());
650  EXPECT_FALSE(IsHighContrastEnabled());
651  EXPECT_FALSE(IsAutoclickEnabled());
652  EXPECT_FALSE(ShouldShowAccessibilityMenu());
653  EXPECT_FALSE(IsVirtualKeyboardEnabled());
654
655  // Check large cursor.
656  SetLargeCursorEnabled(true);
657  EXPECT_TRUE(ShouldShowAccessibilityMenu());
658  SetLargeCursorEnabled(false);
659  EXPECT_FALSE(ShouldShowAccessibilityMenu());
660
661  // Check spoken feedback.
662  SetSpokenFeedbackEnabled(true);
663  EXPECT_TRUE(ShouldShowAccessibilityMenu());
664  SetSpokenFeedbackEnabled(false);
665  EXPECT_FALSE(ShouldShowAccessibilityMenu());
666
667  // Check high contrast.
668  SetHighContrastEnabled(true);
669  EXPECT_TRUE(ShouldShowAccessibilityMenu());
670  SetHighContrastEnabled(false);
671  EXPECT_FALSE(ShouldShowAccessibilityMenu());
672
673  // Check autoclick.
674  SetAutoclickEnabled(true);
675  EXPECT_TRUE(ShouldShowAccessibilityMenu());
676  SetAutoclickEnabled(false);
677  EXPECT_FALSE(ShouldShowAccessibilityMenu());
678
679  // Check on-screen keyboard.
680  SetVirtualKeyboardEnabled(true);
681  EXPECT_TRUE(ShouldShowAccessibilityMenu());
682  SetVirtualKeyboardEnabled(false);
683  EXPECT_FALSE(ShouldShowAccessibilityMenu());
684}
685
686}  // namespace chromeos
687