Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/chromeos/system/tray_accessibility_browsertest.cc

Issue 11519036: A11y: Add a browser test of TrayAccessibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase (r172817) Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
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/tray_views.h"
9 #include "ash/system/tray_accessibility.h"
10 #include "ash/system/user/login_status.h"
11 #include "base/command_line.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
14 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
15 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
16 #include "chrome/browser/chromeos/login/helper.h"
17 #include "chrome/browser/chromeos/login/login_utils.h"
18 #include "chrome/browser/chromeos/login/user_manager.h"
19 #include "chrome/browser/chromeos/login/user_manager_impl.h"
20 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h"
26 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/test/test_utils.h"
29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "ui/views/widget/widget.h"
31
32 namespace chromeos {
33
34 namespace {
35 ui::MouseEvent& dummyEvent = *((ui::MouseEvent*)0);
36 }
37
38 class TrayAccessibilityTest : public CrosInProcessBrowserTest {
39 protected:
40 TrayAccessibilityTest() {}
41 virtual ~TrayAccessibilityTest() {}
42 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
43 command_line->AppendSwitch(switches::kLoginManager);
44 command_line->AppendSwitchASCII(switches::kLoginProfile,
45 TestingProfile::kTestUserProfileDir);
46 }
47
48 ash::internal::TrayAccessibility* tray() {
49 return ash::Shell::GetInstance()->GetPrimarySystemTray()->
50 GetTrayAccessibilityForTest();
51 }
52
53 views::View* tray_icon() {
54 return tray()->tray_view();
55 }
56
57 bool IsTrayIconVisible() {
58 return tray()->tray_icon_visible_;
59 }
60
61 views::View* CreateMenuItem() {
62 return tray()->CreateDefaultView(GetLoginStatus());
63 }
64
65 void DestroyMenuItem() {
66 return tray()->DestroyDefaultView();
67 }
68
69 bool CanCreateMenuItem() {
70 views::View* menu_item_view = CreateMenuItem();
71 DestroyMenuItem();
72 return menu_item_view != NULL;
73 }
74
75 void SetLoginStatus(ash::user::LoginStatus status) {
76 tray()->UpdateAfterLoginStatusChange(status);
77 }
78
79 ash::user::LoginStatus GetLoginStatus() {
80 return tray()->login_;
81 }
82
83 bool CreateDetailedMenu() {
84 detail_menu_ = tray()->CreateDetailedMenu();
85 EXPECT_TRUE(detail_menu_);
86 return detail_menu_ != NULL;
87 }
88
89 void CloseDetailMenu() {
90 CHECK(detail_menu_);
91 tray()->DestroyDetailedView();
92 detail_menu_ = NULL;
93 }
94
95 void ClickSpokenFeedbackOnDetailMenu() {
96 views::View* button = detail_menu_->spoken_feedback_view_;
97 detail_menu_->ClickedOn(button);
98 }
99
100 void ClickHighContrastOnDetailMenu() {
101 views::View* button = detail_menu_->high_contrast_view_;
102 EXPECT_TRUE(button);
103 detail_menu_->ClickedOn(button);
104 }
105
106 void ClickScreenMagnifierOnDetailMenu() {
107 views::View* button = detail_menu_->screen_magnifier_view_;
108 EXPECT_TRUE(button);
109 detail_menu_->ClickedOn(button);
110 }
111
112 bool IsSpokenFeedbackEnabledOnDetailMenu() {
113 return detail_menu_->spoken_feedback_enabled_;
114 }
115
116 bool IsHighContrastEnabledOnDetailMenu() {
117 return detail_menu_->high_contrast_enabled_;
118 }
119
120 bool IsScreenMagnifierEnabledOnDetailMenu() {
121 return detail_menu_->screen_magnifier_enabled_;
122 }
123
124 ash::internal::tray::AccessibilityDetailedView* detail_menu_;
125 };
126
127 IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, LoginStatus) {
128 EXPECT_EQ(ash::user::LOGGED_IN_NONE, GetLoginStatus());
129
130 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true);
131 UserManager::Get()->SessionStarted();
132
133 EXPECT_EQ(ash::user::LOGGED_IN_USER, GetLoginStatus());
134 }
135
136 IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowTrayIcon) {
137 SetLoginStatus(ash::user::LOGGED_IN_NONE);
138
139 // Confirms that the icon is invisible before login.
140 EXPECT_FALSE(tray_icon()->visible());
141
142 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true);
143 UserManager::Get()->SessionStarted();
144
145 // Confirms that the icon is invisible just after login.
146 EXPECT_FALSE(tray_icon()->visible());
147
148 // Toggling spoken feedback changes the visibillity of the icon.
149 accessibility::EnableSpokenFeedback(true, NULL);
150 EXPECT_TRUE(IsTrayIconVisible());
151 accessibility::EnableSpokenFeedback(false, NULL);
152 EXPECT_FALSE(IsTrayIconVisible());
153
154 // Toggling high contrast the visibillity of the icon.
155 accessibility::EnableHighContrast(true);
156 EXPECT_TRUE(IsTrayIconVisible());
157 accessibility::EnableHighContrast(false);
158 EXPECT_FALSE(IsTrayIconVisible());
159
160 // Toggling magnifier the visibillity of the icon.
161 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
162 EXPECT_TRUE(IsTrayIconVisible());
163 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
164 EXPECT_FALSE(IsTrayIconVisible());
165
166 // Enabling all accessibility features.
167 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
168 EXPECT_TRUE(IsTrayIconVisible());
169 accessibility::EnableHighContrast(true);
170 EXPECT_TRUE(IsTrayIconVisible());
171 accessibility::EnableSpokenFeedback(true, NULL);
172 EXPECT_TRUE(IsTrayIconVisible());
173 accessibility::EnableSpokenFeedback(false, NULL);
174 EXPECT_TRUE(IsTrayIconVisible());
175 accessibility::EnableHighContrast(false);
176 EXPECT_TRUE(IsTrayIconVisible());
177 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
178 EXPECT_FALSE(IsTrayIconVisible());
179
180 // Confirms that prefs::kShouldAlwaysShowAccessibilityMenu doesn't affect
181 // the icon on the tray.
182 Profile* profile = ProfileManager::GetDefaultProfile();
183 PrefService* prefs = profile->GetPrefs();
184 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, true);
185 prefs->CommitPendingWrite();
186 accessibility::EnableHighContrast(true);
187 EXPECT_TRUE(IsTrayIconVisible());
188 accessibility::EnableHighContrast(false);
189 EXPECT_FALSE(IsTrayIconVisible());
190 }
191
192 IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenu) {
193 // Login
194 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true);
195 UserManager::Get()->SessionStarted();
196
197 // Sets prefs::kShouldAlwaysShowAccessibilityMenu = false.
198 Profile* profile = ProfileManager::GetDefaultProfile();
199 PrefService* prefs = profile->GetPrefs();
200 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, false);
201 prefs->CommitPendingWrite();
202
203 // Confirms that the menu is hidden.
204 EXPECT_FALSE(CanCreateMenuItem());
205
206 // Toggling spoken feedback changes the visibillity of the menu.
207 accessibility::EnableSpokenFeedback(true, NULL);
208 EXPECT_TRUE(CanCreateMenuItem());
209 accessibility::EnableSpokenFeedback(false, NULL);
210 EXPECT_FALSE(CanCreateMenuItem());
211
212 // Toggling high contrast changes the visibillity of the menu.
213 accessibility::EnableHighContrast(true);
214 EXPECT_TRUE(CanCreateMenuItem());
215 accessibility::EnableHighContrast(false);
216 EXPECT_FALSE(CanCreateMenuItem());
217
218 // Toggling screen magnifier changes the visibillity of the menu.
219 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
220 EXPECT_TRUE(CanCreateMenuItem());
221 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
222 EXPECT_FALSE(CanCreateMenuItem());
223
224 // Enabling all accessibility features.
225 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
226 EXPECT_TRUE(CanCreateMenuItem());
227 accessibility::EnableHighContrast(true);
228 EXPECT_TRUE(CanCreateMenuItem());
229 accessibility::EnableSpokenFeedback(true, NULL);
230 EXPECT_TRUE(CanCreateMenuItem());
231 accessibility::EnableSpokenFeedback(false, NULL);
232 EXPECT_TRUE(CanCreateMenuItem());
233 accessibility::EnableHighContrast(false);
234 EXPECT_TRUE(CanCreateMenuItem());
235 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
236 EXPECT_FALSE(CanCreateMenuItem());
237 }
238
239 IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowMenuOption) {
240 // Login
241 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true);
242 UserManager::Get()->SessionStarted();
243
244 // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true.
245 Profile* profile = ProfileManager::GetDefaultProfile();
246 PrefService* prefs = profile->GetPrefs();
247 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, true);
248 prefs->CommitPendingWrite();
249
250 // Confirms that the menu is visible.
251 EXPECT_TRUE(CanCreateMenuItem());
252
253 // The menu is keeping visible regardless of toggling spoken feedback.
254 accessibility::EnableSpokenFeedback(true, NULL);
255 EXPECT_TRUE(CanCreateMenuItem());
256 accessibility::EnableSpokenFeedback(false, NULL);
257 EXPECT_TRUE(CanCreateMenuItem());
258
259 // The menu is keeping visible regardless of toggling high contrast.
260 accessibility::EnableHighContrast(true);
261 EXPECT_TRUE(CanCreateMenuItem());
262 accessibility::EnableHighContrast(false);
263 EXPECT_TRUE(CanCreateMenuItem());
264
265 // The menu is keeping visible regardless of toggling screen magnifier.
266 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
267 EXPECT_TRUE(CanCreateMenuItem());
268 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
269 EXPECT_TRUE(CanCreateMenuItem());
270
271 // Enabling all accessibility features.
272 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
273 EXPECT_TRUE(CanCreateMenuItem());
274 accessibility::EnableHighContrast(true);
275 EXPECT_TRUE(CanCreateMenuItem());
276 accessibility::EnableSpokenFeedback(true, NULL);
277 EXPECT_TRUE(CanCreateMenuItem());
278 accessibility::EnableSpokenFeedback(false, NULL);
279 EXPECT_TRUE(CanCreateMenuItem());
280 accessibility::EnableHighContrast(false);
281 EXPECT_TRUE(CanCreateMenuItem());
282 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
283 EXPECT_TRUE(CanCreateMenuItem());
284
285 // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true.
286 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, false);
287
288 // Confirms that the menu is invisible.
289 EXPECT_FALSE(CanCreateMenuItem());
290 }
291
292 IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowOnLoginScreen) {
293 SetLoginStatus(ash::user::LOGGED_IN_NONE);
294
295 // Confirms that the menu is visible.
296 EXPECT_TRUE(CanCreateMenuItem());
297
298 // The menu is keeping visible regardless of toggling spoken feedback.
299 accessibility::EnableSpokenFeedback(true, NULL);
300 EXPECT_TRUE(CanCreateMenuItem());
301 accessibility::EnableSpokenFeedback(false, NULL);
302 EXPECT_TRUE(CanCreateMenuItem());
303
304 // The menu is keeping visible regardless of toggling high contrast.
305 accessibility::EnableHighContrast(true);
306 EXPECT_TRUE(CanCreateMenuItem());
307 accessibility::EnableHighContrast(false);
308 EXPECT_TRUE(CanCreateMenuItem());
309
310 // The menu is keeping visible regardless of toggling screen magnifier.
311 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
312 EXPECT_TRUE(CanCreateMenuItem());
313 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
314 EXPECT_TRUE(CanCreateMenuItem());
315
316 // Enabling all accessibility features.
317 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
318 EXPECT_TRUE(CanCreateMenuItem());
319 accessibility::EnableHighContrast(true);
320 EXPECT_TRUE(CanCreateMenuItem());
321 accessibility::EnableSpokenFeedback(true, NULL);
322 EXPECT_TRUE(CanCreateMenuItem());
323 accessibility::EnableSpokenFeedback(false, NULL);
324 EXPECT_TRUE(CanCreateMenuItem());
325 accessibility::EnableHighContrast(false);
326 EXPECT_TRUE(CanCreateMenuItem());
327 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
328 EXPECT_TRUE(CanCreateMenuItem());
329
330 // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true.
331 Profile* profile = ProfileManager::GetDefaultProfile();
332 PrefService* prefs = profile->GetPrefs();
333 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, true);
334 prefs->CommitPendingWrite();
335
336 // Confirms that the menu is keeping visible.
337 EXPECT_TRUE(CanCreateMenuItem());
338
339 // Sets prefs::kShouldAlwaysShowAccessibilityMenu = false.
340 prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, false);
341 prefs->CommitPendingWrite();
342
343 // Confirms that the menu is keeping visible.
344 EXPECT_TRUE(CanCreateMenuItem());
345 }
346
347 IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ClickDetailMenu) {
348 // Confirms that the check item toggles the spoken feedback.
349 EXPECT_FALSE(accessibility::IsSpokenFeedbackEnabled());
350
351 EXPECT_TRUE(CreateDetailedMenu());
352 ClickSpokenFeedbackOnDetailMenu();
353 EXPECT_TRUE(accessibility::IsSpokenFeedbackEnabled());
354
355 EXPECT_TRUE(CreateDetailedMenu());
356 ClickSpokenFeedbackOnDetailMenu();
357 EXPECT_FALSE(accessibility::IsSpokenFeedbackEnabled());
358
359 // Confirms that the check item toggles the high contrast.
360 EXPECT_FALSE(accessibility::IsHighContrastEnabled());
361
362 EXPECT_TRUE(CreateDetailedMenu());
363 ClickHighContrastOnDetailMenu();
364 EXPECT_TRUE(accessibility::IsHighContrastEnabled());
365
366 EXPECT_TRUE(CreateDetailedMenu());
367 ClickHighContrastOnDetailMenu();
368 EXPECT_FALSE(accessibility::IsHighContrastEnabled());
369
370 // Confirms that the check item toggles the magnifier.
371 EXPECT_FALSE(accessibility::IsHighContrastEnabled());
372
373 EXPECT_EQ(ash::MAGNIFIER_OFF,
374 MagnificationManager::Get()->GetMagnifierType());
375 EXPECT_TRUE(CreateDetailedMenu());
376 ClickScreenMagnifierOnDetailMenu();
377 EXPECT_EQ(ash::MAGNIFIER_FULL,
378 MagnificationManager::Get()->GetMagnifierType());
379
380 EXPECT_TRUE(CreateDetailedMenu());
381 ClickScreenMagnifierOnDetailMenu();
382 EXPECT_EQ(ash::MAGNIFIER_OFF,
383 MagnificationManager::Get()->GetMagnifierType());
384 }
385
386 IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) {
387 // At first, all of the check is unchecked.
388 EXPECT_TRUE(CreateDetailedMenu());
389 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
390 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
391 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
392 CloseDetailMenu();
393
394 // Enabling spoken feedback.
395 accessibility::EnableSpokenFeedback(true, NULL);
396 EXPECT_TRUE(CreateDetailedMenu());
397 EXPECT_TRUE(IsSpokenFeedbackEnabledOnDetailMenu());
398 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
399 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
400 CloseDetailMenu();
401
402 // Disabling spoken feedback.
403 accessibility::EnableSpokenFeedback(false, NULL);
404 EXPECT_TRUE(CreateDetailedMenu());
405 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
406 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
407 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
408 CloseDetailMenu();
409
410 // Enabling high contrast.
411 accessibility::EnableHighContrast(true);
412 EXPECT_TRUE(CreateDetailedMenu());
413 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
414 EXPECT_TRUE(IsHighContrastEnabledOnDetailMenu());
415 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
416 CloseDetailMenu();
417
418 // Disabling high contrast.
419 accessibility::EnableHighContrast(false);
420 EXPECT_TRUE(CreateDetailedMenu());
421 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
422 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
423 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
424 CloseDetailMenu();
425
426 // Enabling full screen magnifier.
427 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
428 EXPECT_TRUE(CreateDetailedMenu());
429 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
430 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
431 EXPECT_TRUE(IsScreenMagnifierEnabledOnDetailMenu());
432 CloseDetailMenu();
433
434 // Disabling screen magnifier.
435 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
436 EXPECT_TRUE(CreateDetailedMenu());
437 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
438 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
439 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
440 CloseDetailMenu();
441
442 // Enabling all of the a11y features.
443 accessibility::EnableSpokenFeedback(true, NULL);
444 accessibility::EnableHighContrast(true);
445 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL);
446 EXPECT_TRUE(CreateDetailedMenu());
447 EXPECT_TRUE(IsSpokenFeedbackEnabledOnDetailMenu());
448 EXPECT_TRUE(IsHighContrastEnabledOnDetailMenu());
449 EXPECT_TRUE(IsScreenMagnifierEnabledOnDetailMenu());
450 CloseDetailMenu();
451
452 // Disabling all of the a11y features.
453 accessibility::EnableSpokenFeedback(false, NULL);
454 accessibility::EnableHighContrast(false);
455 MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF);
456 EXPECT_TRUE(CreateDetailedMenu());
457 EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu());
458 EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu());
459 EXPECT_FALSE(IsScreenMagnifierEnabledOnDetailMenu());
460 CloseDetailMenu();
461 }
462
463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698