Home | History | Annotate | Download | only in accessibility
      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/users/user_manager.h"
     17 #include "chrome/browser/chromeos/login/users/user_manager_impl.h"
     18 #include "chrome/browser/chromeos/preferences.h"
     19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
     20 #include "chrome/browser/extensions/api/braille_display_private/mock_braille_controller.h"
     21 #include "chrome/browser/prefs/pref_service_syncable.h"
     22 #include "chrome/browser/profiles/profile.h"
     23 #include "chrome/browser/profiles/profile_manager.h"
     24 #include "chrome/common/extensions/extension_constants.h"
     25 #include "chrome/common/pref_names.h"
     26 #include "chrome/test/base/in_process_browser_test.h"
     27 #include "chrome/test/base/testing_profile.h"
     28 #include "chromeos/chromeos_switches.h"
     29 #include "chromeos/ime/component_extension_ime_manager.h"
     30 #include "chromeos/ime/input_method_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 (at) invalid.domain";
     49 
     50 const int kTestAutoclickDelayMs = 2000;
     51 
     52 // Test user name for locally managed user. The domain part must be matched
     53 // with UserManager::kLocallyManagedUserDomain.
     54 const char kTestLocallyManagedUserName[] = "test (at) 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 CleanUpOnMainThread() 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   UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
    276 
    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());
    284 
    285   UserManager::Get()->SessionStarted();
    286 
    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());
    294 
    295   // Enables large cursor.
    296   SetLargeCursorEnabled(true);
    297   // Confirms that large cursor is enabled.
    298   EXPECT_TRUE(IsLargeCursorEnabled());
    299 
    300   // Enables spoken feedback.
    301   SetSpokenFeedbackEnabled(true);
    302   // Confirms that the spoken feedback is enabled.
    303   EXPECT_TRUE(IsSpokenFeedbackEnabled());
    304 
    305   // Enables high contrast.
    306   SetHighContrastEnabled(true);
    307   // Confirms that high cotrast is enabled.
    308   EXPECT_TRUE(IsHighContrastEnabled());
    309 
    310   // Enables autoclick.
    311   SetAutoclickEnabled(true);
    312   // Confirms that autoclick is enabled.
    313   EXPECT_TRUE(IsAutoclickEnabled());
    314 
    315   // Test that autoclick delay is set properly.
    316   SetAutoclickDelay(kTestAutoclickDelayMs);
    317   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
    318 
    319   // Enable on-screen keyboard
    320   SetVirtualKeyboardEnabled(true);
    321   // Confirm that the on-screen keyboard option is enabled.
    322   EXPECT_TRUE(IsVirtualKeyboardEnabled());
    323 }
    324 
    325 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, BrailleOnLoginScreen) {
    326   EXPECT_FALSE(IsSpokenFeedbackEnabled());
    327 
    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());
    332 }
    333 
    334 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) {
    335   // Logs in.
    336   UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
    337   UserManager::Get()->SessionStarted();
    338 
    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());
    346 
    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());
    351 
    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());
    356 
    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());
    361 
    362   // Sets the pref as true to enable autoclick.
    363   SetAutoclickEnabledPref(true);
    364   // Confirms that autoclick is enabled.
    365   EXPECT_TRUE(IsAutoclickEnabled());
    366 
    367   // Set autoclick delay pref.
    368   SetAutoclickDelayPref(kTestAutoclickDelayMs);
    369   // Confirm that the correct value is set.
    370   EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
    371 
    372   // Sets the on-screen keyboard pref.
    373   SetVirtualKeyboardEnabledPref(true);
    374   // Confirm that the on-screen keyboard option is enabled.
    375   EXPECT_TRUE(IsVirtualKeyboardEnabled());
    376 
    377   SetLargeCursorEnabledPref(false);
    378   EXPECT_FALSE(IsLargeCursorEnabled());
    379 
    380   SetSpokenFeedbackEnabledPref(false);
    381   EXPECT_FALSE(IsSpokenFeedbackEnabled());
    382 
    383   SetHighContrastEnabledPref(false);
    384   EXPECT_FALSE(IsHighContrastEnabled());
    385 
    386   SetAutoclickEnabledPref(false);
    387   EXPECT_FALSE(IsAutoclickEnabled());
    388 
    389   SetVirtualKeyboardEnabledPref(false);
    390   EXPECT_FALSE(IsVirtualKeyboardEnabled());
    391 }
    392 
    393 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) {
    394   // Loads the profile of the user.
    395   UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
    396 
    397   // Sets the pref to enable large cursor before login.
    398   SetLargeCursorEnabledPref(true);
    399   EXPECT_FALSE(IsLargeCursorEnabled());
    400 
    401   // Sets the pref to enable spoken feedback before login.
    402   SetSpokenFeedbackEnabledPref(true);
    403   EXPECT_FALSE(IsSpokenFeedbackEnabled());
    404 
    405   // Sets the pref to enable high contrast before login.
    406   SetHighContrastEnabledPref(true);
    407   EXPECT_FALSE(IsHighContrastEnabled());
    408 
    409   // Sets the pref to enable autoclick before login.
    410   SetAutoclickEnabledPref(true);
    411   EXPECT_FALSE(IsAutoclickEnabled());
    412 
    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());
    417 
    418   // Sets the pref to enable the on-screen keyboard before login.
    419   SetVirtualKeyboardEnabledPref(true);
    420   EXPECT_FALSE(IsVirtualKeyboardEnabled());
    421 
    422   // Logs in.
    423   UserManager::Get()->SessionStarted();
    424 
    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());
    432 }
    433 
    434 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
    435                        ChangingTypeInvokesNotification) {
    436   MockAccessibilityObserver observer;
    437 
    438   // Logs in.
    439   UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
    440   UserManager::Get()->SessionStarted();
    441 
    442   EXPECT_FALSE(observer.observed());
    443   observer.reset();
    444 
    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());
    451 
    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());
    459 
    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());
    467 
    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());
    475 
    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());
    483 
    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());
    491 }
    492 
    493 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
    494                        ChangingTypePrefInvokesNotification) {
    495   MockAccessibilityObserver observer;
    496 
    497   // Logs in.
    498   UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
    499   UserManager::Get()->SessionStarted();
    500 
    501   EXPECT_FALSE(observer.observed());
    502   observer.reset();
    503 
    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());
    510 
    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());
    518 
    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());
    526 
    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());
    534 
    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());
    542 
    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());
    550 }
    551 
    552 class AccessibilityManagerUserTypeTest
    553     : public AccessibilityManagerTest,
    554       public ::testing::WithParamInterface<const char*> {
    555  protected:
    556   AccessibilityManagerUserTypeTest() {}
    557   virtual ~AccessibilityManagerUserTypeTest() {}
    558 
    559   DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerUserTypeTest);
    560 };
    561 
    562 // TODO(yoshiki): Enable a test for retail mode.
    563 INSTANTIATE_TEST_CASE_P(
    564     UserTypeInstantiation,
    565     AccessibilityManagerUserTypeTest,
    566     ::testing::Values(kTestUserName,
    567                       UserManager::kGuestUserName,
    568                       //UserManager::kRetailModeUserName,
    569                       kTestLocallyManagedUserName));
    570 
    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());
    588 
    589   // Logs in.
    590   const char* user_name = GetParam();
    591   UserManager::Get()->UserLoggedIn(user_name, user_name, true);
    592 
    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());
    599 
    600   UserManager::Get()->SessionStarted();
    601 
    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());
    608 
    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());
    615 }
    616 
    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);
    627   }
    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());
    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   UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
    670   UserManager::Get()->SessionStarted();
    671 
    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());
    679 
    680   // Check large cursor.
    681   SetLargeCursorEnabled(true);
    682   EXPECT_TRUE(ShouldShowAccessibilityMenu());
    683   SetLargeCursorEnabled(false);
    684   EXPECT_FALSE(ShouldShowAccessibilityMenu());
    685 
    686   // Check spoken feedback.
    687   SetSpokenFeedbackEnabled(true);
    688   EXPECT_TRUE(ShouldShowAccessibilityMenu());
    689   SetSpokenFeedbackEnabled(false);
    690   EXPECT_FALSE(ShouldShowAccessibilityMenu());
    691 
    692   // Check high contrast.
    693   SetHighContrastEnabled(true);
    694   EXPECT_TRUE(ShouldShowAccessibilityMenu());
    695   SetHighContrastEnabled(false);
    696   EXPECT_FALSE(ShouldShowAccessibilityMenu());
    697 
    698   // Check autoclick.
    699   SetAutoclickEnabled(true);
    700   EXPECT_TRUE(ShouldShowAccessibilityMenu());
    701   SetAutoclickEnabled(false);
    702   EXPECT_FALSE(ShouldShowAccessibilityMenu());
    703 
    704   // Check on-screen keyboard.
    705   SetVirtualKeyboardEnabled(true);
    706   EXPECT_TRUE(ShouldShowAccessibilityMenu());
    707   SetVirtualKeyboardEnabled(false);
    708   EXPECT_FALSE(ShouldShowAccessibilityMenu());
    709 }
    710 
    711 }  // namespace chromeos
    712