| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/magnifier/magnification_controller.h" | 5 #include "ash/magnifier/magnification_controller.h" |
| 6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "ash/system/tray/system_tray.h" | 7 #include "ash/system/tray/system_tray.h" |
| 8 #include "ash/system/tray_accessibility.h" | 8 #include "ash/system/tray_accessibility.h" |
| 9 #include "ash/system/user/login_status.h" | 9 #include "ash/system/user/login_status.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 16 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 16 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 17 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
| 17 #include "chrome/browser/chromeos/login/helper.h" | 18 #include "chrome/browser/chromeos/login/helper.h" |
| 18 #include "chrome/browser/chromeos/login/login_utils.h" | 19 #include "chrome/browser/chromeos/login/login_utils.h" |
| 19 #include "chrome/browser/chromeos/login/startup_utils.h" | 20 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 20 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
| 21 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 22 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 23 #include "chrome/browser/extensions/api/braille_display_private/mock_braille_con
troller.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 28 #include "chromeos/chromeos_switches.h" | 30 #include "chromeos/chromeos_switches.h" |
| 29 #include "components/policy/core/browser/browser_policy_connector.h" | 31 #include "components/policy/core/browser/browser_policy_connector.h" |
| 30 #include "components/policy/core/common/external_data_fetcher.h" | 32 #include "components/policy/core/common/external_data_fetcher.h" |
| 31 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 33 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 32 #include "components/policy/core/common/policy_map.h" | 34 #include "components/policy/core/common/policy_map.h" |
| 33 #include "components/policy/core/common/policy_types.h" | 35 #include "components/policy/core/common/policy_types.h" |
| 34 #include "content/public/test/test_utils.h" | 36 #include "content/public/test/test_utils.h" |
| 35 #include "policy/policy_constants.h" | 37 #include "policy/policy_constants.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 #include "ui/views/controls/label.h" |
| 37 #include "ui/views/widget/widget.h" | 40 #include "ui/views/widget/widget.h" |
| 38 | 41 |
| 42 using extensions::api::braille_display_private::BrailleObserver; |
| 43 using extensions::api::braille_display_private::DisplayState; |
| 44 using extensions::api::braille_display_private::MockBrailleController; |
| 39 using testing::Return; | 45 using testing::Return; |
| 40 using testing::_; | 46 using testing::_; |
| 41 using testing::WithParamInterface; | 47 using testing::WithParamInterface; |
| 42 | 48 |
| 43 namespace chromeos { | 49 namespace chromeos { |
| 44 | 50 |
| 45 enum PrefSettingMechanism { | 51 enum PrefSettingMechanism { |
| 46 PREF_SERVICE, | 52 PREF_SERVICE, |
| 47 POLICY, | 53 POLICY, |
| 48 }; | 54 }; |
| 49 | 55 |
| 50 void SetMagnifierEnabled(bool enabled) { | 56 void SetMagnifierEnabled(bool enabled) { |
| 51 MagnificationManager::Get()->SetMagnifierEnabled(enabled); | 57 MagnificationManager::Get()->SetMagnifierEnabled(enabled); |
| 52 } | 58 } |
| 53 | 59 |
| 54 class TrayAccessibilityTest | 60 class TrayAccessibilityTest |
| 55 : public InProcessBrowserTest, | 61 : public InProcessBrowserTest, |
| 56 public WithParamInterface<PrefSettingMechanism> { | 62 public WithParamInterface<PrefSettingMechanism> { |
| 57 protected: | 63 protected: |
| 58 TrayAccessibilityTest() {} | 64 TrayAccessibilityTest() {} |
| 59 virtual ~TrayAccessibilityTest() {} | 65 virtual ~TrayAccessibilityTest() {} |
| 60 | 66 |
| 61 // The profile which should be used by tese tests. | 67 // The profile which should be used by these tests. |
| 62 Profile* GetProfile() { return ProfileManager::GetActiveUserProfile(); } | 68 Profile* GetProfile() { return ProfileManager::GetActiveUserProfile(); } |
| 63 | 69 |
| 64 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 70 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 65 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 71 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 66 .WillRepeatedly(Return(true)); | 72 .WillRepeatedly(Return(true)); |
| 67 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 73 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 74 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_); |
| 68 } | 75 } |
| 69 | 76 |
| 70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 77 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 71 command_line->AppendSwitch(switches::kLoginManager); | 78 command_line->AppendSwitch(switches::kLoginManager); |
| 72 command_line->AppendSwitchASCII(switches::kLoginProfile, | 79 command_line->AppendSwitchASCII(switches::kLoginProfile, |
| 73 TestingProfile::kTestUserProfileDir); | 80 TestingProfile::kTestUserProfileDir); |
| 74 } | 81 } |
| 75 | 82 |
| 76 virtual void SetUpOnMainThread() OVERRIDE { | 83 virtual void SetUpOnMainThread() OVERRIDE { |
| 77 AccessibilityManager::Get()->SetProfileForTest(GetProfile()); | 84 AccessibilityManager::Get()->SetProfileForTest(GetProfile()); |
| 78 MagnificationManager::Get()->SetProfileForTest(GetProfile()); | 85 MagnificationManager::Get()->SetProfileForTest(GetProfile()); |
| 79 } | 86 } |
| 80 | 87 |
| 81 virtual void RunTestOnMainThreadLoop() OVERRIDE { | 88 virtual void RunTestOnMainThreadLoop() OVERRIDE { |
| 82 // Need to mark oobe completed to show detailed views. | 89 // Need to mark oobe completed to show detailed views. |
| 83 StartupUtils::MarkOobeCompleted(); | 90 StartupUtils::MarkOobeCompleted(); |
| 84 InProcessBrowserTest::RunTestOnMainThreadLoop(); | 91 InProcessBrowserTest::RunTestOnMainThreadLoop(); |
| 85 } | 92 } |
| 86 | 93 |
| 94 virtual void CleanUpOnMainThread() OVERRIDE { |
| 95 AccessibilityManager::SetBrailleControllerForTest(NULL); |
| 96 } |
| 97 |
| 87 void SetShowAccessibilityOptionsInSystemTrayMenu(bool value) { | 98 void SetShowAccessibilityOptionsInSystemTrayMenu(bool value) { |
| 88 if (GetParam() == PREF_SERVICE) { | 99 if (GetParam() == PREF_SERVICE) { |
| 89 PrefService* prefs = GetProfile()->GetPrefs(); | 100 PrefService* prefs = GetProfile()->GetPrefs(); |
| 90 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, value); | 101 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, value); |
| 91 } else if (GetParam() == POLICY) { | 102 } else if (GetParam() == POLICY) { |
| 92 policy::PolicyMap policy_map; | 103 policy::PolicyMap policy_map; |
| 93 policy_map.Set(policy::key::kShowAccessibilityOptionsInSystemTrayMenu, | 104 policy_map.Set(policy::key::kShowAccessibilityOptionsInSystemTrayMenu, |
| 94 policy::POLICY_LEVEL_MANDATORY, | 105 policy::POLICY_LEVEL_MANDATORY, |
| 95 policy::POLICY_SCOPE_USER, | 106 policy::POLICY_SCOPE_USER, |
| 96 base::Value::CreateBooleanValue(value), | 107 base::Value::CreateBooleanValue(value), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 226 } |
| 216 | 227 |
| 217 bool IsAutoclickMenuShownOnDetailMenu() { | 228 bool IsAutoclickMenuShownOnDetailMenu() { |
| 218 return tray()->detailed_menu_->autoclick_view_; | 229 return tray()->detailed_menu_->autoclick_view_; |
| 219 } | 230 } |
| 220 | 231 |
| 221 bool IsVirtualKeyboardMenuShownOnDetailMenu() { | 232 bool IsVirtualKeyboardMenuShownOnDetailMenu() { |
| 222 return tray()->detailed_menu_->virtual_keyboard_view_; | 233 return tray()->detailed_menu_->virtual_keyboard_view_; |
| 223 } | 234 } |
| 224 | 235 |
| 236 bool NotificationShown() { |
| 237 return (tray()->detailed_popup_ && |
| 238 !tray()->detailed_popup_->GetWidget()->IsClosed()); |
| 239 } |
| 240 |
| 241 base::string16 GetNotificationText() { |
| 242 if (NotificationShown()) |
| 243 return tray()->detailed_popup_->GetLabelForTest()->text(); |
| 244 else |
| 245 return base::string16(); |
| 246 } |
| 247 |
| 248 void SetBrailleConnected(bool connected) { |
| 249 braille_controller_.SetAvailable(connected); |
| 250 braille_controller_.GetObserver()->OnDisplayStateChanged( |
| 251 *braille_controller_.GetDisplayState()); |
| 252 } |
| 253 |
| 225 policy::MockConfigurationPolicyProvider provider_; | 254 policy::MockConfigurationPolicyProvider provider_; |
| 255 MockBrailleController braille_controller_; |
| 226 }; | 256 }; |
| 227 | 257 |
| 228 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, LoginStatus) { | 258 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, LoginStatus) { |
| 229 EXPECT_EQ(ash::user::LOGGED_IN_NONE, GetLoginStatus()); | 259 EXPECT_EQ(ash::user::LOGGED_IN_NONE, GetLoginStatus()); |
| 230 | 260 |
| 231 UserManager::Get()->UserLoggedIn( | 261 UserManager::Get()->UserLoggedIn( |
| 232 "owner@invalid.domain", "owner@invalid.domain", true); | 262 "owner@invalid.domain", "owner@invalid.domain", true); |
| 233 UserManager::Get()->SessionStarted(); | 263 UserManager::Get()->SessionStarted(); |
| 234 | 264 |
| 235 EXPECT_EQ(ash::user::LOGGED_IN_USER, GetLoginStatus()); | 265 EXPECT_EQ(ash::user::LOGGED_IN_USER, GetLoginStatus()); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 531 |
| 502 // Confirms that the menu remains visible. | 532 // Confirms that the menu remains visible. |
| 503 EXPECT_TRUE(CanCreateMenuItem()); | 533 EXPECT_TRUE(CanCreateMenuItem()); |
| 504 | 534 |
| 505 SetShowAccessibilityOptionsInSystemTrayMenu(false); | 535 SetShowAccessibilityOptionsInSystemTrayMenu(false); |
| 506 | 536 |
| 507 // Confirms that the menu remains visible. | 537 // Confirms that the menu remains visible. |
| 508 EXPECT_TRUE(CanCreateMenuItem()); | 538 EXPECT_TRUE(CanCreateMenuItem()); |
| 509 } | 539 } |
| 510 | 540 |
| 541 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowNotification) { |
| 542 const base::string16 BRAILLE_CONNECTED = |
| 543 base::ASCIIToUTF16("Braille display connected."); |
| 544 const base::string16 CHROMEVOX_ENABLED = base::ASCIIToUTF16( |
| 545 "ChromeVox (spoken feedback) is enabled.\nPress Ctrl+Alt+Z to disable."); |
| 546 const base::string16 BRAILLE_CONNECTED_AND_CHROMEVOX_ENABLED( |
| 547 BRAILLE_CONNECTED + base::ASCIIToUTF16(" ") + CHROMEVOX_ENABLED); |
| 548 |
| 549 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 550 |
| 551 // Enabling spoken feedback should show the notification. |
| 552 AccessibilityManager::Get()->EnableSpokenFeedback( |
| 553 true, ash::A11Y_NOTIFICATION_SHOW); |
| 554 EXPECT_EQ(CHROMEVOX_ENABLED, GetNotificationText()); |
| 555 |
| 556 // Connecting a braille display when spoken feedback is already enabled |
| 557 // should only show the message about the braille display. |
| 558 SetBrailleConnected(true); |
| 559 EXPECT_EQ(BRAILLE_CONNECTED, GetNotificationText()); |
| 560 |
| 561 // Neither disconnecting a braille display, nor disabling spoken feedback |
| 562 // should show any notification. |
| 563 SetBrailleConnected(false); |
| 564 EXPECT_TRUE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 565 EXPECT_FALSE(NotificationShown()); |
| 566 AccessibilityManager::Get()->EnableSpokenFeedback( |
| 567 false, ash::A11Y_NOTIFICATION_SHOW); |
| 568 EXPECT_FALSE(NotificationShown()); |
| 569 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 570 |
| 571 // Connecting a braille display should enable spoken feedback and show |
| 572 // both messages. |
| 573 SetBrailleConnected(true); |
| 574 EXPECT_TRUE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 575 EXPECT_EQ(BRAILLE_CONNECTED_AND_CHROMEVOX_ENABLED, GetNotificationText()); |
| 576 } |
| 577 |
| 511 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) { | 578 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) { |
| 512 // Enables high contrast mode. | 579 // Enables high contrast mode. |
| 513 AccessibilityManager::Get()->EnableHighContrast(true); | 580 AccessibilityManager::Get()->EnableHighContrast(true); |
| 514 EXPECT_TRUE(CanCreateMenuItem()); | 581 EXPECT_TRUE(CanCreateMenuItem()); |
| 515 | 582 |
| 516 // Locks the screen. | 583 // Locks the screen. |
| 517 SetLoginStatus(ash::user::LOGGED_IN_LOCKED); | 584 SetLoginStatus(ash::user::LOGGED_IN_LOCKED); |
| 518 EXPECT_TRUE(CanCreateMenuItem()); | 585 EXPECT_TRUE(CanCreateMenuItem()); |
| 519 | 586 |
| 520 // Disables high contrast mode. | 587 // Disables high contrast mode. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu()); | 869 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu()); |
| 803 CloseDetailMenu(); | 870 CloseDetailMenu(); |
| 804 } | 871 } |
| 805 | 872 |
| 806 INSTANTIATE_TEST_CASE_P(TrayAccessibilityTestInstance, | 873 INSTANTIATE_TEST_CASE_P(TrayAccessibilityTestInstance, |
| 807 TrayAccessibilityTest, | 874 TrayAccessibilityTest, |
| 808 testing::Values(PREF_SERVICE, | 875 testing::Values(PREF_SERVICE, |
| 809 POLICY)); | 876 POLICY)); |
| 810 | 877 |
| 811 } // namespace chromeos | 878 } // namespace chromeos |
| OLD | NEW |