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), |
97 NULL); | 108 NULL); |
98 provider_.UpdateChromePolicy(policy_map); | 109 provider_.UpdateChromePolicy(policy_map); |
99 base::RunLoop().RunUntilIdle(); | 110 base::RunLoop().RunUntilIdle(); |
100 } else { | 111 } else { |
101 FAIL() << "Unknown test parameterization"; | 112 FAIL() << "Unknown test parameterization"; |
102 } | 113 } |
103 } | 114 } |
104 | 115 |
105 ash::internal::TrayAccessibility* tray() { | 116 ash::internal::TrayAccessibility* tray() { |
106 return ash::Shell::GetInstance()->GetPrimarySystemTray()-> | 117 return ash::Shell::GetInstance()->GetPrimarySystemTray()-> |
107 GetTrayAccessibilityForTest(); | 118 GetTrayAccessibilityForTest(); |
108 } | 119 } |
109 | 120 |
110 bool IsTrayIconVisible() { | 121 const ash::internal::TrayAccessibility* tray() const { |
111 return tray()->tray_icon_visible_; | 122 return ash::Shell::GetInstance() |
| 123 ->GetPrimarySystemTray() |
| 124 ->GetTrayAccessibilityForTest(); |
112 } | 125 } |
113 | 126 |
| 127 bool IsTrayIconVisible() const { return tray()->tray_icon_visible_; } |
| 128 |
114 views::View* CreateMenuItem() { | 129 views::View* CreateMenuItem() { |
115 return tray()->CreateDefaultView(GetLoginStatus()); | 130 return tray()->CreateDefaultView(GetLoginStatus()); |
116 } | 131 } |
117 | 132 |
118 void DestroyMenuItem() { | 133 void DestroyMenuItem() { |
119 return tray()->DestroyDefaultView(); | 134 return tray()->DestroyDefaultView(); |
120 } | 135 } |
121 | 136 |
122 bool CanCreateMenuItem() { | 137 bool CanCreateMenuItem() { |
123 views::View* menu_item_view = CreateMenuItem(); | 138 views::View* menu_item_view = CreateMenuItem(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ASSERT_TRUE(button); | 182 ASSERT_TRUE(button); |
168 tray()->detailed_menu_->OnViewClicked(button); | 183 tray()->detailed_menu_->OnViewClicked(button); |
169 } | 184 } |
170 | 185 |
171 void ClickVirtualKeyboardOnDetailMenu() { | 186 void ClickVirtualKeyboardOnDetailMenu() { |
172 views::View* button = tray()->detailed_menu_->virtual_keyboard_view_; | 187 views::View* button = tray()->detailed_menu_->virtual_keyboard_view_; |
173 ASSERT_TRUE(button); | 188 ASSERT_TRUE(button); |
174 tray()->detailed_menu_->OnViewClicked(button); | 189 tray()->detailed_menu_->OnViewClicked(button); |
175 } | 190 } |
176 | 191 |
177 bool IsSpokenFeedbackEnabledOnDetailMenu() { | 192 bool IsSpokenFeedbackEnabledOnDetailMenu() const { |
178 return tray()->detailed_menu_->spoken_feedback_enabled_; | 193 return tray()->detailed_menu_->spoken_feedback_enabled_; |
179 } | 194 } |
180 | 195 |
181 bool IsHighContrastEnabledOnDetailMenu() { | 196 bool IsHighContrastEnabledOnDetailMenu() const { |
182 return tray()->detailed_menu_->high_contrast_enabled_; | 197 return tray()->detailed_menu_->high_contrast_enabled_; |
183 } | 198 } |
184 | 199 |
185 bool IsScreenMagnifierEnabledOnDetailMenu() { | 200 bool IsScreenMagnifierEnabledOnDetailMenu() const { |
186 return tray()->detailed_menu_->screen_magnifier_enabled_; | 201 return tray()->detailed_menu_->screen_magnifier_enabled_; |
187 } | 202 } |
188 | 203 |
189 bool IsLargeCursorEnabledOnDetailMenu() { | 204 bool IsLargeCursorEnabledOnDetailMenu() const { |
190 return tray()->detailed_menu_->large_cursor_enabled_; | 205 return tray()->detailed_menu_->large_cursor_enabled_; |
191 } | 206 } |
192 | 207 |
193 bool IsAutoclickEnabledOnDetailMenu() { | 208 bool IsAutoclickEnabledOnDetailMenu() const { |
194 return tray()->detailed_menu_->autoclick_enabled_; | 209 return tray()->detailed_menu_->autoclick_enabled_; |
195 } | 210 } |
196 | 211 |
197 bool IsVirtualKeyboardEnabledOnDetailMenu() { | 212 bool IsVirtualKeyboardEnabledOnDetailMenu() const { |
198 return tray()->detailed_menu_->virtual_keyboard_enabled_; | 213 return tray()->detailed_menu_->virtual_keyboard_enabled_; |
199 } | 214 } |
200 | 215 |
201 bool IsSpokenFeedbackMenuShownOnDetailMenu() { | 216 bool IsSpokenFeedbackMenuShownOnDetailMenu() const { |
202 return tray()->detailed_menu_->spoken_feedback_view_; | 217 return tray()->detailed_menu_->spoken_feedback_view_; |
203 } | 218 } |
204 | 219 |
205 bool IsHighContrastMenuShownOnDetailMenu() { | 220 bool IsHighContrastMenuShownOnDetailMenu() const { |
206 return tray()->detailed_menu_->high_contrast_view_; | 221 return tray()->detailed_menu_->high_contrast_view_; |
207 } | 222 } |
208 | 223 |
209 bool IsScreenMagnifierMenuShownOnDetailMenu() { | 224 bool IsScreenMagnifierMenuShownOnDetailMenu() const { |
210 return tray()->detailed_menu_->screen_magnifier_view_; | 225 return tray()->detailed_menu_->screen_magnifier_view_; |
211 } | 226 } |
212 | 227 |
213 bool IsLargeCursorMenuShownOnDetailMenu() { | 228 bool IsLargeCursorMenuShownOnDetailMenu() const { |
214 return tray()->detailed_menu_->large_cursor_view_; | 229 return tray()->detailed_menu_->large_cursor_view_; |
215 } | 230 } |
216 | 231 |
217 bool IsAutoclickMenuShownOnDetailMenu() { | 232 bool IsAutoclickMenuShownOnDetailMenu() const { |
218 return tray()->detailed_menu_->autoclick_view_; | 233 return tray()->detailed_menu_->autoclick_view_; |
219 } | 234 } |
220 | 235 |
221 bool IsVirtualKeyboardMenuShownOnDetailMenu() { | 236 bool IsVirtualKeyboardMenuShownOnDetailMenu() const { |
222 return tray()->detailed_menu_->virtual_keyboard_view_; | 237 return tray()->detailed_menu_->virtual_keyboard_view_; |
223 } | 238 } |
224 | 239 |
| 240 bool IsNotificationShown() const { |
| 241 return (tray()->detailed_popup_ && |
| 242 !tray()->detailed_popup_->GetWidget()->IsClosed()); |
| 243 } |
| 244 |
| 245 base::string16 GetNotificationText() const { |
| 246 if (IsNotificationShown()) |
| 247 return tray()->detailed_popup_->label_for_test()->text(); |
| 248 else |
| 249 return base::string16(); |
| 250 } |
| 251 |
| 252 void SetBrailleConnected(bool connected) { |
| 253 braille_controller_.SetAvailable(connected); |
| 254 braille_controller_.GetObserver()->OnDisplayStateChanged( |
| 255 *braille_controller_.GetDisplayState()); |
| 256 } |
| 257 |
225 policy::MockConfigurationPolicyProvider provider_; | 258 policy::MockConfigurationPolicyProvider provider_; |
| 259 MockBrailleController braille_controller_; |
226 }; | 260 }; |
227 | 261 |
228 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, LoginStatus) { | 262 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, LoginStatus) { |
229 EXPECT_EQ(ash::user::LOGGED_IN_NONE, GetLoginStatus()); | 263 EXPECT_EQ(ash::user::LOGGED_IN_NONE, GetLoginStatus()); |
230 | 264 |
231 UserManager::Get()->UserLoggedIn( | 265 UserManager::Get()->UserLoggedIn( |
232 "owner@invalid.domain", "owner@invalid.domain", true); | 266 "owner@invalid.domain", "owner@invalid.domain", true); |
233 UserManager::Get()->SessionStarted(); | 267 UserManager::Get()->SessionStarted(); |
234 | 268 |
235 EXPECT_EQ(ash::user::LOGGED_IN_USER, GetLoginStatus()); | 269 EXPECT_EQ(ash::user::LOGGED_IN_USER, GetLoginStatus()); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 535 |
502 // Confirms that the menu remains visible. | 536 // Confirms that the menu remains visible. |
503 EXPECT_TRUE(CanCreateMenuItem()); | 537 EXPECT_TRUE(CanCreateMenuItem()); |
504 | 538 |
505 SetShowAccessibilityOptionsInSystemTrayMenu(false); | 539 SetShowAccessibilityOptionsInSystemTrayMenu(false); |
506 | 540 |
507 // Confirms that the menu remains visible. | 541 // Confirms that the menu remains visible. |
508 EXPECT_TRUE(CanCreateMenuItem()); | 542 EXPECT_TRUE(CanCreateMenuItem()); |
509 } | 543 } |
510 | 544 |
| 545 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowNotification) { |
| 546 const base::string16 BRAILLE_CONNECTED = |
| 547 base::ASCIIToUTF16("Braille display connected."); |
| 548 const base::string16 CHROMEVOX_ENABLED = base::ASCIIToUTF16( |
| 549 "ChromeVox (spoken feedback) is enabled.\nPress Ctrl+Alt+Z to disable."); |
| 550 const base::string16 BRAILLE_CONNECTED_AND_CHROMEVOX_ENABLED( |
| 551 BRAILLE_CONNECTED + base::ASCIIToUTF16(" ") + CHROMEVOX_ENABLED); |
| 552 |
| 553 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 554 |
| 555 // Enabling spoken feedback should show the notification. |
| 556 AccessibilityManager::Get()->EnableSpokenFeedback( |
| 557 true, ash::A11Y_NOTIFICATION_SHOW); |
| 558 EXPECT_EQ(CHROMEVOX_ENABLED, GetNotificationText()); |
| 559 |
| 560 // Connecting a braille display when spoken feedback is already enabled |
| 561 // should only show the message about the braille display. |
| 562 SetBrailleConnected(true); |
| 563 EXPECT_EQ(BRAILLE_CONNECTED, GetNotificationText()); |
| 564 |
| 565 // Neither disconnecting a braille display, nor disabling spoken feedback |
| 566 // should show any notification. |
| 567 SetBrailleConnected(false); |
| 568 EXPECT_TRUE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 569 EXPECT_FALSE(IsNotificationShown()); |
| 570 AccessibilityManager::Get()->EnableSpokenFeedback( |
| 571 false, ash::A11Y_NOTIFICATION_SHOW); |
| 572 EXPECT_FALSE(IsNotificationShown()); |
| 573 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 574 |
| 575 // Connecting a braille display should enable spoken feedback and show |
| 576 // both messages. |
| 577 SetBrailleConnected(true); |
| 578 EXPECT_TRUE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 579 EXPECT_EQ(BRAILLE_CONNECTED_AND_CHROMEVOX_ENABLED, GetNotificationText()); |
| 580 } |
| 581 |
511 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) { | 582 IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) { |
512 // Enables high contrast mode. | 583 // Enables high contrast mode. |
513 AccessibilityManager::Get()->EnableHighContrast(true); | 584 AccessibilityManager::Get()->EnableHighContrast(true); |
514 EXPECT_TRUE(CanCreateMenuItem()); | 585 EXPECT_TRUE(CanCreateMenuItem()); |
515 | 586 |
516 // Locks the screen. | 587 // Locks the screen. |
517 SetLoginStatus(ash::user::LOGGED_IN_LOCKED); | 588 SetLoginStatus(ash::user::LOGGED_IN_LOCKED); |
518 EXPECT_TRUE(CanCreateMenuItem()); | 589 EXPECT_TRUE(CanCreateMenuItem()); |
519 | 590 |
520 // Disables high contrast mode. | 591 // Disables high contrast mode. |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu()); | 873 EXPECT_TRUE(IsVirtualKeyboardMenuShownOnDetailMenu()); |
803 CloseDetailMenu(); | 874 CloseDetailMenu(); |
804 } | 875 } |
805 | 876 |
806 INSTANTIATE_TEST_CASE_P(TrayAccessibilityTestInstance, | 877 INSTANTIATE_TEST_CASE_P(TrayAccessibilityTestInstance, |
807 TrayAccessibilityTest, | 878 TrayAccessibilityTest, |
808 testing::Values(PREF_SERVICE, | 879 testing::Values(PREF_SERVICE, |
809 POLICY)); | 880 POLICY)); |
810 | 881 |
811 } // namespace chromeos | 882 } // namespace chromeos |
OLD | NEW |