Revert of Add source column to chrome://policy showing the origins of policies. ...
[chromium-blink-merge.git] / chrome / browser / chromeos / system / tray_accessibility_browsertest.cc
blobf09b6b972a587bfda6ededd292585b3ed1b3aeb1
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/magnifier/magnification_controller.h"
6 #include "ash/shell.h"
7 #include "ash/system/tray/system_tray.h"
8 #include "ash/system/tray_accessibility.h"
9 #include "ash/system/user/login_status.h"
10 #include "ash/test/shell_test_api.h"
11 #include "ash/test/test_session_state_delegate.h"
12 #include "base/callback.h"
13 #include "base/command_line.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
19 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
20 #include "chrome/browser/chromeos/login/helper.h"
21 #include "chrome/browser/chromeos/login/startup_utils.h"
22 #include "chrome/browser/extensions/api/braille_display_private/mock_braille_controller.h"
23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/in_process_browser_test.h"
28 #include "chrome/test/base/testing_profile.h"
29 #include "chromeos/chromeos_switches.h"
30 #include "components/policy/core/browser/browser_policy_connector.h"
31 #include "components/policy/core/common/external_data_fetcher.h"
32 #include "components/policy/core/common/mock_configuration_policy_provider.h"
33 #include "components/policy/core/common/policy_map.h"
34 #include "components/policy/core/common/policy_types.h"
35 #include "components/user_manager/user_manager.h"
36 #include "content/public/test/test_utils.h"
37 #include "policy/policy_constants.h"
38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "ui/views/controls/label.h"
40 #include "ui/views/widget/widget.h"
42 using extensions::api::braille_display_private::BrailleObserver;
43 using extensions::api::braille_display_private::DisplayState;
44 using extensions::api::braille_display_private::MockBrailleController;
45 using testing::Return;
46 using testing::_;
47 using testing::WithParamInterface;
49 namespace chromeos {
51 enum PrefSettingMechanism {
52 PREF_SERVICE,
53 POLICY,
56 void SetMagnifierEnabled(bool enabled) {
57 MagnificationManager::Get()->SetMagnifierEnabled(enabled);
60 class TrayAccessibilityTest
61 : public InProcessBrowserTest,
62 public WithParamInterface<PrefSettingMechanism> {
63 protected:
64 TrayAccessibilityTest() {}
65 virtual ~TrayAccessibilityTest() {}
67 // The profile which should be used by these tests.
68 Profile* GetProfile() { return ProfileManager::GetActiveUserProfile(); }
70 void SetUpInProcessBrowserTestFixture() override {
71 EXPECT_CALL(provider_, IsInitializationComplete(_))
72 .WillRepeatedly(Return(true));
73 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
74 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
77 void SetUpCommandLine(base::CommandLine* command_line) override {
78 command_line->AppendSwitch(switches::kLoginManager);
79 command_line->AppendSwitchASCII(switches::kLoginProfile,
80 TestingProfile::kTestUserProfileDir);
83 void SetUpOnMainThread() override {
84 AccessibilityManager::Get()->SetProfileForTest(GetProfile());
85 MagnificationManager::Get()->SetProfileForTest(GetProfile());
88 void RunTestOnMainThreadLoop() override {
89 // Need to mark oobe completed to show detailed views.
90 StartupUtils::MarkOobeCompleted();
91 InProcessBrowserTest::RunTestOnMainThreadLoop();
94 void TearDownOnMainThread() override {
95 AccessibilityManager::SetBrailleControllerForTest(NULL);
98 void SetShowAccessibilityOptionsInSystemTrayMenu(bool value) {
99 if (GetParam() == PREF_SERVICE) {
100 PrefService* prefs = GetProfile()->GetPrefs();
101 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, value);
102 } else if (GetParam() == POLICY) {
103 policy::PolicyMap policy_map;
104 policy_map.Set(policy::key::kShowAccessibilityOptionsInSystemTrayMenu,
105 policy::POLICY_LEVEL_MANDATORY,
106 policy::POLICY_SCOPE_USER,
107 new base::FundamentalValue(value),
108 NULL);
109 provider_.UpdateChromePolicy(policy_map);
110 base::RunLoop().RunUntilIdle();
111 } else {
112 FAIL() << "Unknown test parameterization";
116 ash::TrayAccessibility* tray() {
117 return ash::Shell::GetInstance()->GetPrimarySystemTray()->
118 GetTrayAccessibilityForTest();
121 const ash::TrayAccessibility* tray() const {
122 return ash::Shell::GetInstance()
123 ->GetPrimarySystemTray()
124 ->GetTrayAccessibilityForTest();
127 bool IsTrayIconVisible() const { return tray()->tray_icon_visible_; }
129 views::View* CreateMenuItem() {
130 return tray()->CreateDefaultView(GetLoginStatus());
133 void DestroyMenuItem() {
134 return tray()->DestroyDefaultView();
137 bool CanCreateMenuItem() {
138 views::View* menu_item_view = CreateMenuItem();
139 DestroyMenuItem();
140 return menu_item_view != NULL;
143 void SetLoginStatus(ash::user::LoginStatus status) {
144 tray()->UpdateAfterLoginStatusChange(status);
147 ash::user::LoginStatus GetLoginStatus() {
148 return tray()->login_;
151 bool CreateDetailedMenu() {
152 tray()->PopupDetailedView(0, false);
153 return tray()->detailed_menu_ != NULL;
156 void CloseDetailMenu() {
157 CHECK(tray()->detailed_menu_);
158 tray()->DestroyDetailedView();
159 tray()->detailed_menu_ = NULL;
162 void ClickSpokenFeedbackOnDetailMenu() {
163 views::View* button = tray()->detailed_menu_->spoken_feedback_view_;
164 ASSERT_TRUE(button);
165 tray()->detailed_menu_->OnViewClicked(button);
168 void ClickHighContrastOnDetailMenu() {
169 views::View* button = tray()->detailed_menu_->high_contrast_view_;
170 ASSERT_TRUE(button);
171 tray()->detailed_menu_->OnViewClicked(button);
174 void ClickScreenMagnifierOnDetailMenu() {
175 views::View* button = tray()->detailed_menu_->screen_magnifier_view_;
176 ASSERT_TRUE(button);
177 tray()->detailed_menu_->OnViewClicked(button);
180 void ClickAutoclickOnDetailMenu() {
181 views::View* button = tray()->detailed_menu_->autoclick_view_;
182 ASSERT_TRUE(button);
183 tray()->detailed_menu_->OnViewClicked(button);
186 void ClickVirtualKeyboardOnDetailMenu() {
187 views::View* button = tray()->detailed_menu_->virtual_keyboard_view_;
188 ASSERT_TRUE(button);
189 tray()->detailed_menu_->OnViewClicked(button);
192 bool IsSpokenFeedbackEnabledOnDetailMenu() const {
193 return tray()->detailed_menu_->spoken_feedback_enabled_;
196 bool IsHighContrastEnabledOnDetailMenu() const {
197 return tray()->detailed_menu_->high_contrast_enabled_;
200 bool IsScreenMagnifierEnabledOnDetailMenu() const {
201 return tray()->detailed_menu_->screen_magnifier_enabled_;
204 bool IsLargeCursorEnabledOnDetailMenu() const {
205 return tray()->detailed_menu_->large_cursor_enabled_;
208 bool IsAutoclickEnabledOnDetailMenu() const {
209 return tray()->detailed_menu_->autoclick_enabled_;
212 bool IsVirtualKeyboardEnabledOnDetailMenu() const {
213 return tray()->detailed_menu_->virtual_keyboard_enabled_;
216 bool IsSpokenFeedbackMenuShownOnDetailMenu() const {
217 return tray()->detailed_menu_->spoken_feedback_view_;
220 bool IsHighContrastMenuShownOnDetailMenu() const {
221 return tray()->detailed_menu_->high_contrast_view_;
224 bool IsScreenMagnifierMenuShownOnDetailMenu() const {
225 return tray()->detailed_menu_->screen_magnifier_view_;
228 bool IsLargeCursorMenuShownOnDetailMenu() const {
229 return tray()->detailed_menu_->large_cursor_view_;
232 bool IsAutoclickMenuShownOnDetailMenu() const {
233 return tray()->detailed_menu_->autoclick_view_;
236 bool IsVirtualKeyboardMenuShownOnDetailMenu() const {
237 return tray()->detailed_menu_->virtual_keyboard_view_;
240 bool IsHelpShownOnDetailMenu() const {
241 return tray()->detailed_menu_->help_view_;
244 bool IsSettingsShownOnDetailMenu() const {
245 return tray()->detailed_menu_->settings_view_;
248 bool IsNotificationShown() const {
249 return (tray()->detailed_popup_ &&
250 !tray()->detailed_popup_->GetWidget()->IsClosed());
253 base::string16 GetNotificationText() const {
254 if (IsNotificationShown())
255 return tray()->detailed_popup_->label_for_test()->text();
256 else
257 return base::string16();
260 void SetBrailleConnected(bool connected) {
261 braille_controller_.SetAvailable(connected);
262 braille_controller_.GetObserver()->OnBrailleDisplayStateChanged(
263 *braille_controller_.GetDisplayState());
266 policy::MockConfigurationPolicyProvider provider_;
267 MockBrailleController braille_controller_;
270 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, LoginStatus) {
271 EXPECT_EQ(ash::user::LOGGED_IN_NONE, GetLoginStatus());
273 user_manager::UserManager::Get()->UserLoggedIn(
274 "owner@invalid.domain", "owner@invalid.domain", true);
275 user_manager::UserManager::Get()->SessionStarted();
277 EXPECT_EQ(ash::user::LOGGED_IN_USER, GetLoginStatus());
280 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowTrayIcon) {
281 SetLoginStatus(ash::user::LOGGED_IN_NONE);
283 // Confirms that the icon is invisible before login.
284 EXPECT_FALSE(IsTrayIconVisible());
286 user_manager::UserManager::Get()->UserLoggedIn(
287 "owner@invalid.domain", "owner@invalid.domain", true);
288 user_manager::UserManager::Get()->SessionStarted();
290 // Confirms that the icon is invisible just after login.
291 EXPECT_FALSE(IsTrayIconVisible());
293 // Toggling spoken feedback changes the visibillity of the icon.
294 AccessibilityManager::Get()->EnableSpokenFeedback(
295 true, ui::A11Y_NOTIFICATION_NONE);
296 EXPECT_TRUE(IsTrayIconVisible());
297 AccessibilityManager::Get()->EnableSpokenFeedback(
298 false, ui::A11Y_NOTIFICATION_NONE);
299 EXPECT_FALSE(IsTrayIconVisible());
301 // Toggling high contrast the visibillity of the icon.
302 AccessibilityManager::Get()->EnableHighContrast(true);
303 EXPECT_TRUE(IsTrayIconVisible());
304 AccessibilityManager::Get()->EnableHighContrast(false);
305 EXPECT_FALSE(IsTrayIconVisible());
307 // Toggling magnifier the visibility of the icon.
308 SetMagnifierEnabled(true);
309 EXPECT_TRUE(IsTrayIconVisible());
310 SetMagnifierEnabled(false);
311 EXPECT_FALSE(IsTrayIconVisible());
313 // Toggling the virtual keyboard setting changes the visibility of the a11y
314 // icon.
315 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
316 EXPECT_TRUE(IsTrayIconVisible());
317 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
318 EXPECT_FALSE(IsTrayIconVisible());
320 // Enabling all accessibility features.
321 SetMagnifierEnabled(true);
322 EXPECT_TRUE(IsTrayIconVisible());
323 AccessibilityManager::Get()->EnableHighContrast(true);
324 EXPECT_TRUE(IsTrayIconVisible());
325 AccessibilityManager::Get()->EnableSpokenFeedback(
326 true, ui::A11Y_NOTIFICATION_NONE);
327 EXPECT_TRUE(IsTrayIconVisible());
328 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
329 EXPECT_TRUE(IsTrayIconVisible());
330 AccessibilityManager::Get()->EnableSpokenFeedback(
331 false, ui::A11Y_NOTIFICATION_NONE);
332 EXPECT_TRUE(IsTrayIconVisible());
333 AccessibilityManager::Get()->EnableHighContrast(false);
334 EXPECT_TRUE(IsTrayIconVisible());
335 SetMagnifierEnabled(false);
336 EXPECT_TRUE(IsTrayIconVisible());
337 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
338 EXPECT_FALSE(IsTrayIconVisible());
340 // Confirms that prefs::kShouldAlwaysShowAccessibilityMenu doesn't affect
341 // the icon on the tray.
342 SetShowAccessibilityOptionsInSystemTrayMenu(true);
343 AccessibilityManager::Get()->EnableHighContrast(true);
344 EXPECT_TRUE(IsTrayIconVisible());
345 AccessibilityManager::Get()->EnableHighContrast(false);
346 EXPECT_FALSE(IsTrayIconVisible());
349 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowMenu) {
350 // Login
351 user_manager::UserManager::Get()->UserLoggedIn(
352 "owner@invalid.domain", "owner@invalid.domain", true);
353 user_manager::UserManager::Get()->SessionStarted();
355 SetShowAccessibilityOptionsInSystemTrayMenu(false);
357 // Confirms that the menu is hidden.
358 EXPECT_FALSE(CanCreateMenuItem());
360 // Toggling spoken feedback changes the visibillity of the menu.
361 AccessibilityManager::Get()->EnableSpokenFeedback(
362 true, ui::A11Y_NOTIFICATION_NONE);
363 EXPECT_TRUE(CanCreateMenuItem());
364 AccessibilityManager::Get()->EnableSpokenFeedback(
365 false, ui::A11Y_NOTIFICATION_NONE);
366 EXPECT_FALSE(CanCreateMenuItem());
368 // Toggling high contrast changes the visibillity of the menu.
369 AccessibilityManager::Get()->EnableHighContrast(true);
370 EXPECT_TRUE(CanCreateMenuItem());
371 AccessibilityManager::Get()->EnableHighContrast(false);
372 EXPECT_FALSE(CanCreateMenuItem());
374 // Toggling screen magnifier changes the visibility of the menu.
375 SetMagnifierEnabled(true);
376 EXPECT_TRUE(CanCreateMenuItem());
377 SetMagnifierEnabled(false);
378 EXPECT_FALSE(CanCreateMenuItem());
380 // Toggling autoclick changes the visibility of the menu.
381 AccessibilityManager::Get()->EnableAutoclick(true);
382 EXPECT_TRUE(CanCreateMenuItem());
383 AccessibilityManager::Get()->EnableAutoclick(false);
384 EXPECT_FALSE(CanCreateMenuItem());
386 // Toggling virtual keyboard changes the visibility of the menu.
387 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
388 EXPECT_TRUE(CanCreateMenuItem());
389 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
390 EXPECT_FALSE(CanCreateMenuItem());
392 // Enabling all accessibility features.
393 SetMagnifierEnabled(true);
394 EXPECT_TRUE(CanCreateMenuItem());
395 AccessibilityManager::Get()->EnableHighContrast(true);
396 EXPECT_TRUE(CanCreateMenuItem());
397 AccessibilityManager::Get()->EnableSpokenFeedback(
398 true, ui::A11Y_NOTIFICATION_NONE);
399 EXPECT_TRUE(CanCreateMenuItem());
400 AccessibilityManager::Get()->EnableAutoclick(true);
401 EXPECT_TRUE(CanCreateMenuItem());
402 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
403 EXPECT_TRUE(CanCreateMenuItem());
404 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
405 EXPECT_TRUE(CanCreateMenuItem());
406 AccessibilityManager::Get()->EnableAutoclick(false);
407 EXPECT_TRUE(CanCreateMenuItem());
408 AccessibilityManager::Get()->EnableSpokenFeedback(
409 false, ui::A11Y_NOTIFICATION_NONE);
410 EXPECT_TRUE(CanCreateMenuItem());
411 AccessibilityManager::Get()->EnableHighContrast(false);
412 EXPECT_TRUE(CanCreateMenuItem());
413 SetMagnifierEnabled(false);
414 EXPECT_FALSE(CanCreateMenuItem());
417 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowMenuWithShowMenuOption) {
418 // Login
419 user_manager::UserManager::Get()->UserLoggedIn(
420 "owner@invalid.domain", "owner@invalid.domain", true);
421 user_manager::UserManager::Get()->SessionStarted();
423 SetShowAccessibilityOptionsInSystemTrayMenu(true);
425 // Confirms that the menu is visible.
426 EXPECT_TRUE(CanCreateMenuItem());
428 // The menu remains visible regardless of toggling spoken feedback.
429 AccessibilityManager::Get()->EnableSpokenFeedback(
430 true, ui::A11Y_NOTIFICATION_NONE);
431 EXPECT_TRUE(CanCreateMenuItem());
432 AccessibilityManager::Get()->EnableSpokenFeedback(
433 false, ui::A11Y_NOTIFICATION_NONE);
434 EXPECT_TRUE(CanCreateMenuItem());
436 // The menu remains visible regardless of toggling high contrast.
437 AccessibilityManager::Get()->EnableHighContrast(true);
438 EXPECT_TRUE(CanCreateMenuItem());
439 AccessibilityManager::Get()->EnableHighContrast(false);
440 EXPECT_TRUE(CanCreateMenuItem());
442 // The menu remains visible regardless of toggling screen magnifier.
443 SetMagnifierEnabled(true);
444 EXPECT_TRUE(CanCreateMenuItem());
445 SetMagnifierEnabled(false);
446 EXPECT_TRUE(CanCreateMenuItem());
448 // The menu remains visible regardless of toggling autoclick.
449 AccessibilityManager::Get()->EnableAutoclick(true);
450 EXPECT_TRUE(CanCreateMenuItem());
451 AccessibilityManager::Get()->EnableAutoclick(false);
452 EXPECT_TRUE(CanCreateMenuItem());
454 // The menu remains visible regardless of toggling on-screen keyboard.
455 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
456 EXPECT_TRUE(CanCreateMenuItem());
457 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
458 EXPECT_TRUE(CanCreateMenuItem());
460 // Enabling all accessibility features.
461 SetMagnifierEnabled(true);
462 EXPECT_TRUE(CanCreateMenuItem());
463 AccessibilityManager::Get()->EnableHighContrast(true);
464 EXPECT_TRUE(CanCreateMenuItem());
465 AccessibilityManager::Get()->EnableSpokenFeedback(
466 true, ui::A11Y_NOTIFICATION_NONE);
467 EXPECT_TRUE(CanCreateMenuItem());
468 AccessibilityManager::Get()->EnableAutoclick(true);
469 EXPECT_TRUE(CanCreateMenuItem());
470 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
471 EXPECT_TRUE(CanCreateMenuItem());
472 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
473 EXPECT_TRUE(CanCreateMenuItem());
474 AccessibilityManager::Get()->EnableAutoclick(false);
475 EXPECT_TRUE(CanCreateMenuItem());
476 AccessibilityManager::Get()->EnableSpokenFeedback(
477 false, ui::A11Y_NOTIFICATION_NONE);
478 EXPECT_TRUE(CanCreateMenuItem());
479 AccessibilityManager::Get()->EnableHighContrast(false);
480 EXPECT_TRUE(CanCreateMenuItem());
481 SetMagnifierEnabled(false);
482 EXPECT_TRUE(CanCreateMenuItem());
484 SetShowAccessibilityOptionsInSystemTrayMenu(false);
486 // Confirms that the menu is invisible.
487 EXPECT_FALSE(CanCreateMenuItem());
490 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowMenuWithShowOnLoginScreen) {
491 SetLoginStatus(ash::user::LOGGED_IN_NONE);
493 // Confirms that the menu is visible.
494 EXPECT_TRUE(CanCreateMenuItem());
496 // The menu remains visible regardless of toggling spoken feedback.
497 AccessibilityManager::Get()->EnableSpokenFeedback(
498 true, ui::A11Y_NOTIFICATION_NONE);
499 EXPECT_TRUE(CanCreateMenuItem());
500 AccessibilityManager::Get()->EnableSpokenFeedback(
501 false, ui::A11Y_NOTIFICATION_NONE);
502 EXPECT_TRUE(CanCreateMenuItem());
504 // The menu remains visible regardless of toggling high contrast.
505 AccessibilityManager::Get()->EnableHighContrast(true);
506 EXPECT_TRUE(CanCreateMenuItem());
507 AccessibilityManager::Get()->EnableHighContrast(false);
508 EXPECT_TRUE(CanCreateMenuItem());
510 // The menu remains visible regardless of toggling screen magnifier.
511 SetMagnifierEnabled(true);
512 EXPECT_TRUE(CanCreateMenuItem());
513 SetMagnifierEnabled(false);
514 EXPECT_TRUE(CanCreateMenuItem());
516 // The menu remains visible regardless of toggling on-screen keyboard.
517 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
518 EXPECT_TRUE(CanCreateMenuItem());
519 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
520 EXPECT_TRUE(CanCreateMenuItem());
522 // Enabling all accessibility features.
523 SetMagnifierEnabled(true);
524 EXPECT_TRUE(CanCreateMenuItem());
525 AccessibilityManager::Get()->EnableHighContrast(true);
526 EXPECT_TRUE(CanCreateMenuItem());
527 AccessibilityManager::Get()->EnableSpokenFeedback(
528 true, ui::A11Y_NOTIFICATION_NONE);
529 EXPECT_TRUE(CanCreateMenuItem());
530 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
531 EXPECT_TRUE(CanCreateMenuItem());
532 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
533 EXPECT_TRUE(CanCreateMenuItem());
534 AccessibilityManager::Get()->EnableSpokenFeedback(
535 false, ui::A11Y_NOTIFICATION_NONE);
536 EXPECT_TRUE(CanCreateMenuItem());
537 AccessibilityManager::Get()->EnableHighContrast(false);
538 EXPECT_TRUE(CanCreateMenuItem());
539 SetMagnifierEnabled(false);
540 EXPECT_TRUE(CanCreateMenuItem());
542 SetShowAccessibilityOptionsInSystemTrayMenu(true);
544 // Confirms that the menu remains visible.
545 EXPECT_TRUE(CanCreateMenuItem());
547 SetShowAccessibilityOptionsInSystemTrayMenu(false);
549 // Confirms that the menu remains visible.
550 EXPECT_TRUE(CanCreateMenuItem());
553 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowNotification) {
554 const base::string16 BRAILLE_CONNECTED =
555 base::ASCIIToUTF16("Braille display connected.");
556 const base::string16 CHROMEVOX_ENABLED = base::ASCIIToUTF16(
557 "ChromeVox (spoken feedback) is enabled.\nPress Ctrl+Alt+Z to disable.");
558 const base::string16 BRAILLE_CONNECTED_AND_CHROMEVOX_ENABLED(
559 BRAILLE_CONNECTED + base::ASCIIToUTF16(" ") + CHROMEVOX_ENABLED);
561 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
563 // Enabling spoken feedback should show the notification.
564 AccessibilityManager::Get()->EnableSpokenFeedback(
565 true, ui::A11Y_NOTIFICATION_SHOW);
566 EXPECT_EQ(CHROMEVOX_ENABLED, GetNotificationText());
568 // Connecting a braille display when spoken feedback is already enabled
569 // should only show the message about the braille display.
570 SetBrailleConnected(true);
571 EXPECT_EQ(BRAILLE_CONNECTED, GetNotificationText());
573 // Neither disconnecting a braille display, nor disabling spoken feedback
574 // should show any notification.
575 SetBrailleConnected(false);
576 EXPECT_TRUE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
577 EXPECT_FALSE(IsNotificationShown());
578 AccessibilityManager::Get()->EnableSpokenFeedback(
579 false, ui::A11Y_NOTIFICATION_SHOW);
580 EXPECT_FALSE(IsNotificationShown());
581 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
583 // Connecting a braille display should enable spoken feedback and show
584 // both messages.
585 SetBrailleConnected(true);
586 EXPECT_TRUE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
587 EXPECT_EQ(BRAILLE_CONNECTED_AND_CHROMEVOX_ENABLED, GetNotificationText());
590 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) {
591 // Enables high contrast mode.
592 AccessibilityManager::Get()->EnableHighContrast(true);
593 EXPECT_TRUE(CanCreateMenuItem());
595 // Locks the screen.
596 SetLoginStatus(ash::user::LOGGED_IN_LOCKED);
597 EXPECT_TRUE(CanCreateMenuItem());
599 // Disables high contrast mode.
600 AccessibilityManager::Get()->EnableHighContrast(false);
602 // Confirms that the menu is still visible.
603 EXPECT_TRUE(CanCreateMenuItem());
606 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ClickDetailMenu) {
607 SetLoginStatus(ash::user::LOGGED_IN_USER);
609 // Confirms that the check item toggles the spoken feedback.
610 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
612 EXPECT_TRUE(CreateDetailedMenu());
613 ClickSpokenFeedbackOnDetailMenu();
614 EXPECT_TRUE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
616 EXPECT_TRUE(CreateDetailedMenu());
617 ClickSpokenFeedbackOnDetailMenu();
618 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
620 // Confirms that the check item toggles the high contrast.
621 EXPECT_FALSE(AccessibilityManager::Get()->IsHighContrastEnabled());
623 EXPECT_TRUE(CreateDetailedMenu());
624 ClickHighContrastOnDetailMenu();
625 EXPECT_TRUE(AccessibilityManager::Get()->IsHighContrastEnabled());
627 EXPECT_TRUE(CreateDetailedMenu());
628 ClickHighContrastOnDetailMenu();
629 EXPECT_FALSE(AccessibilityManager::Get()->IsHighContrastEnabled());
631 // Confirms that the check item toggles the magnifier.
632 EXPECT_FALSE(AccessibilityManager::Get()->IsHighContrastEnabled());
634 EXPECT_FALSE(MagnificationManager::Get()->IsMagnifierEnabled());
635 EXPECT_TRUE(CreateDetailedMenu());
636 ClickScreenMagnifierOnDetailMenu();
637 EXPECT_TRUE(MagnificationManager::Get()->IsMagnifierEnabled());
639 EXPECT_TRUE(CreateDetailedMenu());
640 ClickScreenMagnifierOnDetailMenu();
641 EXPECT_FALSE(MagnificationManager::Get()->IsMagnifierEnabled());
643 // Confirms that the check item toggles autoclick.
644 EXPECT_FALSE(AccessibilityManager::Get()->IsAutoclickEnabled());
646 EXPECT_TRUE(CreateDetailedMenu());
647 ClickAutoclickOnDetailMenu();
648 EXPECT_TRUE(AccessibilityManager::Get()->IsAutoclickEnabled());
650 EXPECT_TRUE(CreateDetailedMenu());
651 ClickAutoclickOnDetailMenu();
652 EXPECT_FALSE(AccessibilityManager::Get()->IsAutoclickEnabled());
654 // Confirms that the check item toggles on-screen keyboard.
655 EXPECT_FALSE(AccessibilityManager::Get()->IsVirtualKeyboardEnabled());
657 EXPECT_TRUE(CreateDetailedMenu());
658 ClickVirtualKeyboardOnDetailMenu();
659 EXPECT_TRUE(AccessibilityManager::Get()->IsVirtualKeyboardEnabled());
661 EXPECT_TRUE(CreateDetailedMenu());
662 ClickVirtualKeyboardOnDetailMenu();
663 EXPECT_FALSE(AccessibilityManager::Get()->IsVirtualKeyboardEnabled());
666 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, CheckMarksOnDetailMenu) {
667 SetLoginStatus(ash::user::LOGGED_IN_NONE);
669 // At first, all of the check is unchecked.
670 EXPECT_TRUE(CreateDetailedMenu());
671 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
672 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
673 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
674 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
675 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
676 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
677 CloseDetailMenu();
679 // Enabling spoken feedback.
680 AccessibilityManager::Get()->EnableSpokenFeedback(
681 true, ui::A11Y_NOTIFICATION_NONE);
682 EXPECT_TRUE(CreateDetailedMenu());
683 EXPECT_TRUE(IsSpokenFeedbackEnabledOnDetailMenu());
684 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
685 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
686 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
687 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
688 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
689 CloseDetailMenu();
691 // Disabling spoken feedback.
692 AccessibilityManager::Get()->EnableSpokenFeedback(
693 false, ui::A11Y_NOTIFICATION_NONE);
694 EXPECT_TRUE(CreateDetailedMenu());
695 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
696 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
697 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
698 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
699 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
700 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
701 CloseDetailMenu();
703 // Enabling high contrast.
704 AccessibilityManager::Get()->EnableHighContrast(true);
705 EXPECT_TRUE(CreateDetailedMenu());
706 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
707 EXPECT_TRUE(IsHighContrastEnabledOnDetailMenu());
708 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
709 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
710 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
711 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
712 CloseDetailMenu();
714 // Disabling high contrast.
715 AccessibilityManager::Get()->EnableHighContrast(false);
716 EXPECT_TRUE(CreateDetailedMenu());
717 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
718 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
719 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
720 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
721 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
722 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
723 CloseDetailMenu();
725 // Enabling full screen magnifier.
726 SetMagnifierEnabled(true);
727 EXPECT_TRUE(CreateDetailedMenu());
728 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
729 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
730 EXPECT_TRUE(IsScreenMagnifierEnabledOnDetailMenu());
731 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
732 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
733 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
734 CloseDetailMenu();
736 // Disabling screen magnifier.
737 SetMagnifierEnabled(false);
738 EXPECT_TRUE(CreateDetailedMenu());
739 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
740 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
741 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
742 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
743 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
744 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
745 CloseDetailMenu();
747 // Enabling large cursor.
748 AccessibilityManager::Get()->EnableLargeCursor(true);
749 EXPECT_TRUE(CreateDetailedMenu());
750 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
751 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
752 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
753 EXPECT_TRUE(IsLargeCursorEnabledOnDetailMenu());
754 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
755 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
756 CloseDetailMenu();
758 // Disabling large cursor.
759 AccessibilityManager::Get()->EnableLargeCursor(false);
760 EXPECT_TRUE(CreateDetailedMenu());
761 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
762 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
763 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
764 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
765 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
766 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
767 CloseDetailMenu();
769 // Enable on-screen keyboard.
770 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
771 EXPECT_TRUE(CreateDetailedMenu());
772 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
773 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
774 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
775 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
776 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
777 EXPECT_TRUE(IsVirtualKeyboardEnabledOnDetailMenu());
778 CloseDetailMenu();
780 // Disable on-screen keyboard.
781 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
782 EXPECT_TRUE(CreateDetailedMenu());
783 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
784 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
785 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
786 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
787 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
788 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
789 CloseDetailMenu();
791 // Enabling all of the a11y features.
792 AccessibilityManager::Get()->EnableSpokenFeedback(
793 true, ui::A11Y_NOTIFICATION_NONE);
794 AccessibilityManager::Get()->EnableHighContrast(true);
795 SetMagnifierEnabled(true);
796 AccessibilityManager::Get()->EnableLargeCursor(true);
797 AccessibilityManager::Get()->EnableVirtualKeyboard(true);
798 EXPECT_TRUE(CreateDetailedMenu());
799 EXPECT_TRUE(IsSpokenFeedbackEnabledOnDetailMenu());
800 EXPECT_TRUE(IsHighContrastEnabledOnDetailMenu());
801 EXPECT_TRUE(IsScreenMagnifierEnabledOnDetailMenu());
802 EXPECT_TRUE(IsLargeCursorEnabledOnDetailMenu());
803 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
804 EXPECT_TRUE(IsVirtualKeyboardEnabledOnDetailMenu());
805 CloseDetailMenu();
807 // Disabling all of the a11y features.
808 AccessibilityManager::Get()->EnableSpokenFeedback(
809 false, ui::A11Y_NOTIFICATION_NONE);
810 AccessibilityManager::Get()->EnableHighContrast(false);
811 SetMagnifierEnabled(false);
812 AccessibilityManager::Get()->EnableLargeCursor(false);
813 AccessibilityManager::Get()->EnableVirtualKeyboard(false);
814 EXPECT_TRUE(CreateDetailedMenu());
815 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
816 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
817 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
818 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
819 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
820 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
821 CloseDetailMenu();
823 // Autoclick is disabled on login screen.
824 SetLoginStatus(ash::user::LOGGED_IN_USER);
826 // Enabling autoclick.
827 AccessibilityManager::Get()->EnableAutoclick(true);
828 EXPECT_TRUE(CreateDetailedMenu());
829 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
830 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
831 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
832 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
833 EXPECT_TRUE(IsAutoclickEnabledOnDetailMenu());
834 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
835 CloseDetailMenu();
837 // Disabling autoclick.
838 AccessibilityManager::Get()->EnableAutoclick(false);
839 EXPECT_TRUE(CreateDetailedMenu());
840 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
841 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
842 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
843 EXPECT_FALSE(IsLargeCursorEnabledOnDetailMenu());
844 EXPECT_FALSE(IsAutoclickEnabledOnDetailMenu());
845 EXPECT_FALSE(IsVirtualKeyboardEnabledOnDetailMenu());
846 CloseDetailMenu();
849 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, CheckMenuVisibilityOnDetailMenu) {
850 SetLoginStatus(ash::user::LOGGED_IN_NONE);
851 EXPECT_TRUE(CreateDetailedMenu());
852 EXPECT_TRUE(IsSpokenFeedbackMenuShownOnDetailMenu());
853 EXPECT_TRUE(IsHighContrastMenuShownOnDetailMenu());
854 EXPECT_TRUE(IsScreenMagnifierMenuShownOnDetailMenu());
855 EXPECT_TRUE(IsLargeCursorMenuShownOnDetailMenu());
856 EXPECT_FALSE(IsAutoclickMenuShownOnDetailMenu());
857 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu());
858 EXPECT_FALSE(IsHelpShownOnDetailMenu());
859 EXPECT_FALSE(IsSettingsShownOnDetailMenu());
860 CloseDetailMenu();
862 SetLoginStatus(ash::user::LOGGED_IN_USER);
863 EXPECT_TRUE(CreateDetailedMenu());
864 EXPECT_TRUE(IsSpokenFeedbackMenuShownOnDetailMenu());
865 EXPECT_TRUE(IsHighContrastMenuShownOnDetailMenu());
866 EXPECT_TRUE(IsScreenMagnifierMenuShownOnDetailMenu());
867 EXPECT_FALSE(IsLargeCursorMenuShownOnDetailMenu());
868 EXPECT_TRUE(IsAutoclickMenuShownOnDetailMenu());
869 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu());
870 EXPECT_TRUE(IsHelpShownOnDetailMenu());
871 EXPECT_TRUE(IsSettingsShownOnDetailMenu());
872 CloseDetailMenu();
874 SetLoginStatus(ash::user::LOGGED_IN_LOCKED);
875 EXPECT_TRUE(CreateDetailedMenu());
876 EXPECT_TRUE(IsSpokenFeedbackMenuShownOnDetailMenu());
877 EXPECT_TRUE(IsHighContrastMenuShownOnDetailMenu());
878 EXPECT_TRUE(IsScreenMagnifierMenuShownOnDetailMenu());
879 EXPECT_FALSE(IsLargeCursorMenuShownOnDetailMenu());
880 EXPECT_TRUE(IsAutoclickMenuShownOnDetailMenu());
881 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu());
882 EXPECT_FALSE(IsHelpShownOnDetailMenu());
883 EXPECT_FALSE(IsSettingsShownOnDetailMenu());
884 CloseDetailMenu();
886 ash::test::TestSessionStateDelegate* session_state_delegate =
887 new ash::test::TestSessionStateDelegate;
888 ash::test::ShellTestApi test_api(ash::Shell::GetInstance());
889 test_api.SetSessionStateDelegate(session_state_delegate);
890 session_state_delegate->SetUserAddingScreenRunning(true);
891 SetLoginStatus(ash::user::LOGGED_IN_USER);
892 EXPECT_TRUE(CreateDetailedMenu());
893 EXPECT_TRUE(IsSpokenFeedbackMenuShownOnDetailMenu());
894 EXPECT_TRUE(IsHighContrastMenuShownOnDetailMenu());
895 EXPECT_TRUE(IsScreenMagnifierMenuShownOnDetailMenu());
896 EXPECT_FALSE(IsLargeCursorMenuShownOnDetailMenu());
897 EXPECT_TRUE(IsAutoclickMenuShownOnDetailMenu());
898 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu());
899 EXPECT_FALSE(IsHelpShownOnDetailMenu());
900 EXPECT_FALSE(IsSettingsShownOnDetailMenu());
901 CloseDetailMenu();
904 INSTANTIATE_TEST_CASE_P(TrayAccessibilityTestInstance,
905 TrayAccessibilityTest,
906 testing::Values(PREF_SERVICE,
907 POLICY));
909 } // namespace chromeos