Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / accessibility / spoken_feedback_browsertest.cc
bloba9f0e5a73a13e4cfe88c94574bb83d275ea78f6d
1 // Copyright 2014 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 <queue>
7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/accelerators/accelerator_table.h"
9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray.h"
11 #include "base/command_line.h"
12 #include "base/strings/pattern.h"
13 #include "base/strings/string_util.h"
14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
17 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
18 #include "chrome/browser/chromeos/login/login_manager_test.h"
19 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
20 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
21 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h"
24 #include "chrome/browser/speech/tts_controller.h"
25 #include "chrome/browser/speech/tts_platform.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/extensions/extension_constants.h"
32 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/interactive_test_utils.h"
34 #include "chrome/test/base/testing_profile.h"
35 #include "chrome/test/base/ui_test_utils.h"
36 #include "chromeos/chromeos_switches.h"
37 #include "chromeos/login/user_names.h"
38 #include "content/public/common/url_constants.h"
39 #include "content/public/test/browser_test_utils.h"
40 #include "content/public/test/test_utils.h"
41 #include "extensions/browser/extension_host.h"
42 #include "extensions/browser/process_manager.h"
43 #include "testing/gtest/include/gtest/gtest.h"
44 #include "ui/app_list/app_list_switches.h"
45 #include "ui/base/test/ui_controls.h"
46 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
47 #include "ui/views/widget/widget.h"
49 using extensions::api::braille_display_private::StubBrailleController;
51 namespace chromeos {
54 // Spoken feedback tests only in a logged in user's window.
57 class LoggedInSpokenFeedbackTest : public InProcessBrowserTest {
58 protected:
59 LoggedInSpokenFeedbackTest()
60 : animation_mode_(ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) {}
61 ~LoggedInSpokenFeedbackTest() override {}
63 void SetUpInProcessBrowserTestFixture() override {
64 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
67 void TearDownOnMainThread() override {
68 AccessibilityManager::SetBrailleControllerForTest(nullptr);
71 void SendKeyPress(ui::KeyboardCode key) {
72 ASSERT_NO_FATAL_FAILURE(ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
73 nullptr, key, false, false, false, false)));
76 void SendKeyPressWithControl(ui::KeyboardCode key) {
77 ASSERT_NO_FATAL_FAILURE(ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
78 nullptr, key, true, false, false, false)));
81 void SendKeyPressWithSearchAndShift(ui::KeyboardCode key) {
82 ASSERT_NO_FATAL_FAILURE(ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
83 nullptr, key, false, true, false, true)));
86 void RunJavaScriptInChromeVoxBackgroundPage(const std::string& script) {
87 extensions::ExtensionHost* host =
88 extensions::ProcessManager::Get(browser()->profile())
89 ->GetBackgroundHostForExtension(
90 extension_misc::kChromeVoxExtensionId);
91 CHECK(content::ExecuteScript(host->host_contents(), script));
94 void SimulateTouchScreenInChromeVox() {
95 // ChromeVox looks at whether 'ontouchstart' exists to know whether
96 // or not it should respond to hover events. Fake it so that touch
97 // exploration events get spoken.
98 RunJavaScriptInChromeVoxBackgroundPage(
99 "window.ontouchstart = function() {};");
102 bool PerformAcceleratorAction(ash::AcceleratorAction action) {
103 ash::AcceleratorController* controller =
104 ash::Shell::GetInstance()->accelerator_controller();
105 return controller->PerformActionIfEnabled(action);
108 void DisableEarcons() {
109 // Playing earcons from within a test is not only annoying if you're
110 // running the test locally, but seems to cause crashes
111 // (http://crbug.com/396507). Work around this by just telling
112 // ChromeVox to not ever play earcons (prerecorded sound effects).
113 RunJavaScriptInChromeVoxBackgroundPage(
114 "cvox.ChromeVox.earcons.playEarcon = function() {};");
117 void EnableChromeVox() {
118 // Test setup.
119 // Enable ChromeVox, skip welcome message, and disable earcons.
120 ASSERT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
122 AccessibilityManager::Get()->EnableSpokenFeedback(
123 true, ui::A11Y_NOTIFICATION_NONE);
124 EXPECT_TRUE(speech_monitor_.SkipChromeVoxEnabledMessage());
125 DisableEarcons();
128 void LoadChromeVoxAndThenNavigateToURL(const GURL& url) {
129 // The goal of this helper function is to avoid race conditions between
130 // the page loading and the ChromeVox extension loading and fully
131 // initializing. To do this, we first load a test url that repeatedly
132 // asks ChromeVox to speak 'ready', then we load ChromeVox and block
133 // until we get that 'ready' speech.
135 ui_test_utils::NavigateToURL(
136 browser(),
137 GURL("data:text/html;charset=utf-8,"
138 "<script>"
139 "window.setInterval(function() {"
140 " try {"
141 " cvox.Api.speak('ready');"
142 " } catch (e) {}"
143 "}, 100);"
144 "</script>"));
145 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
146 AccessibilityManager::Get()->EnableSpokenFeedback(
147 true, ui::A11Y_NOTIFICATION_NONE);
149 // Block until we get "ready".
150 while (speech_monitor_.GetNextUtterance() != "ready") {
153 // Now load the requested url.
154 ui_test_utils::NavigateToURL(browser(), url);
157 void PressRepeatedlyUntilUtterance(ui::KeyboardCode key,
158 const std::string& expected_utterance) {
159 // This helper function is needed when you want to poll for something
160 // that happens asynchronously. Keep pressing |key|, until
161 // the speech feedback that follows is |expected_utterance|.
162 // Note that this doesn't work if pressing that key doesn't speak anything
163 // at all before the asynchronous event occurred.
164 while (true) {
165 SendKeyPress(key);
166 const std::string& utterance = speech_monitor_.GetNextUtterance();
167 if (utterance == expected_utterance)
168 break;
172 SpeechMonitor speech_monitor_;
174 private:
175 StubBrailleController braille_controller_;
176 ui::ScopedAnimationDurationScaleMode animation_mode_;
178 DISALLOW_COPY_AND_ASSIGN(LoggedInSpokenFeedbackTest);
181 // This test is very flakey with ChromeVox Next since we generate a lot more
182 // utterances for text fields.
183 // TODO(dtseng): Fix properly.
184 IN_PROC_BROWSER_TEST_F(LoggedInSpokenFeedbackTest, DISABLED_AddBookmark) {
185 EnableChromeVox();
186 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR);
188 // Create a bookmark with title "foo".
189 chrome::ExecuteCommand(browser(), IDC_BOOKMARK_PAGE);
190 EXPECT_EQ("Bookmark added! dialog Bookmark name about:blank Edit text",
191 speech_monitor_.GetNextUtterance());
192 EXPECT_EQ("about:blank", speech_monitor_.GetNextUtterance());
194 SendKeyPress(ui::VKEY_F);
195 EXPECT_EQ("f", speech_monitor_.GetNextUtterance());
196 SendKeyPress(ui::VKEY_O);
197 EXPECT_EQ("o", speech_monitor_.GetNextUtterance());
198 SendKeyPress(ui::VKEY_O);
199 EXPECT_EQ("o", speech_monitor_.GetNextUtterance());
201 SendKeyPress(ui::VKEY_TAB);
202 EXPECT_EQ("Bookmark folder combo Box Bookmarks bar",
203 speech_monitor_.GetNextUtterance());
205 SendKeyPress(ui::VKEY_RETURN);
207 EXPECT_TRUE(
208 base::MatchPattern(speech_monitor_.GetNextUtterance(), "*oolbar*"));
209 // Wait for active window change to be announced to avoid interference from
210 // that below.
211 while (speech_monitor_.GetNextUtterance() != "window about blank tab") {
212 // Do nothing.
215 // Focus bookmarks bar and listen for "foo".
216 chrome::ExecuteCommand(browser(), IDC_FOCUS_BOOKMARKS);
217 while (true) {
218 std::string utterance = speech_monitor_.GetNextUtterance();
219 VLOG(0) << "Got utterance: " << utterance;
220 if (utterance == "Bookmarks,")
221 break;
223 EXPECT_EQ("foo,", speech_monitor_.GetNextUtterance());
224 EXPECT_EQ("button", speech_monitor_.GetNextUtterance());
228 // Spoken feedback tests in both a logged in browser window and guest mode.
231 enum SpokenFeedbackTestVariant {
232 kTestAsNormalUser,
233 kTestAsGuestUser
236 class SpokenFeedbackTest
237 : public LoggedInSpokenFeedbackTest,
238 public ::testing::WithParamInterface<SpokenFeedbackTestVariant> {
239 protected:
240 SpokenFeedbackTest() {}
241 virtual ~SpokenFeedbackTest() {}
243 void SetUpCommandLine(base::CommandLine* command_line) override {
244 if (GetParam() == kTestAsGuestUser) {
245 command_line->AppendSwitch(chromeos::switches::kGuestSession);
246 command_line->AppendSwitch(::switches::kIncognito);
247 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
248 "user");
249 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
250 chromeos::login::kGuestUserName);
255 INSTANTIATE_TEST_CASE_P(
256 TestAsNormalAndGuestUser,
257 SpokenFeedbackTest,
258 ::testing::Values(kTestAsNormalUser,
259 kTestAsGuestUser));
261 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, EnableSpokenFeedback) {
262 EnableChromeVox();
265 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, FocusToolbar) {
266 EnableChromeVox();
267 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
268 EXPECT_TRUE(
269 base::MatchPattern(speech_monitor_.GetNextUtterance(), "about:blank*"));
270 EXPECT_EQ("main", speech_monitor_.GetNextUtterance());
271 EXPECT_EQ("Tool bar", speech_monitor_.GetNextUtterance());
272 EXPECT_EQ("Reload", speech_monitor_.GetNextUtterance());
273 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
276 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, TypeInOmnibox) {
277 EnableChromeVox();
279 chrome::ExecuteCommand(browser(), IDC_FOCUS_LOCATION);
280 EXPECT_TRUE(
281 base::MatchPattern(speech_monitor_.GetNextUtterance(), "*about:blank*"));
282 EXPECT_EQ("main", speech_monitor_.GetNextUtterance());
283 EXPECT_EQ("Tool bar", speech_monitor_.GetNextUtterance());
284 EXPECT_EQ("Address and search bar", speech_monitor_.GetNextUtterance());
285 EXPECT_EQ("about:blank", speech_monitor_.GetNextUtterance());
286 EXPECT_EQ("Edit text", speech_monitor_.GetNextUtterance());
288 SendKeyPress(ui::VKEY_X);
289 EXPECT_EQ("x", speech_monitor_.GetNextUtterance());
291 SendKeyPress(ui::VKEY_Y);
292 EXPECT_EQ("y", speech_monitor_.GetNextUtterance());
294 SendKeyPress(ui::VKEY_Z);
295 EXPECT_EQ("z", speech_monitor_.GetNextUtterance());
297 SendKeyPress(ui::VKEY_BACK);
298 EXPECT_EQ("z", speech_monitor_.GetNextUtterance());
301 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, FocusShelf) {
302 EnableChromeVox();
304 EXPECT_TRUE(PerformAcceleratorAction(ash::FOCUS_SHELF));
305 EXPECT_EQ("Shelf", speech_monitor_.GetNextUtterance());
306 EXPECT_EQ("Tool bar", speech_monitor_.GetNextUtterance());
307 if (app_list::switches::IsExperimentalAppListEnabled())
308 EXPECT_EQ("Launcher", speech_monitor_.GetNextUtterance());
309 else
310 EXPECT_EQ("Apps", speech_monitor_.GetNextUtterance());
311 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
313 SendKeyPress(ui::VKEY_TAB);
314 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "*"));
315 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "Button"));
318 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, NavigateAppLauncher) {
319 EnableChromeVox();
321 EXPECT_TRUE(PerformAcceleratorAction(ash::FOCUS_SHELF));
322 while (true) {
323 std::string utterance = speech_monitor_.GetNextUtterance();
324 if (base::MatchPattern(utterance, "Button"))
325 break;
328 SendKeyPress(ui::VKEY_RETURN);
330 EXPECT_EQ("Search or type U R L", speech_monitor_.GetNextUtterance());
331 EXPECT_EQ("Edit text", speech_monitor_.GetNextUtterance());
333 SendKeyPress(ui::VKEY_DOWN);
334 EXPECT_EQ("Dialog", speech_monitor_.GetNextUtterance());
335 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "*"));
336 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
339 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, OpenStatusTray) {
340 EnableChromeVox();
342 EXPECT_TRUE(PerformAcceleratorAction(ash::SHOW_SYSTEM_TRAY_BUBBLE));
343 EXPECT_TRUE(
344 base::MatchPattern(speech_monitor_.GetNextUtterance(), "Status tray*"));
345 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "time *"));
346 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
347 "Battery is*full."));
348 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "*"));
349 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "Button"));
352 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, NavigateSystemTray) {
353 EnableChromeVox();
355 EXPECT_TRUE(PerformAcceleratorAction(ash::SHOW_SYSTEM_TRAY_BUBBLE));
356 while (true) {
357 std::string utterance = speech_monitor_.GetNextUtterance();
358 if (base::MatchPattern(utterance, "Button"))
359 break;
362 SendKeyPress(ui::VKEY_TAB);
363 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "*"));
364 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "Button"));
366 // Compat next element.
367 SendKeyPressWithSearchAndShift(ui::VKEY_RIGHT);
368 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "*"));
369 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "Button"));
371 // Compat next button.
372 SendKeyPressWithSearchAndShift(ui::VKEY_N);
373 SendKeyPressWithSearchAndShift(ui::VKEY_B);
374 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "*"));
375 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "Button"));
377 // Navigate to Bluetooth sub-menu and open it.
378 while (true) {
379 SendKeyPress(ui::VKEY_TAB);
380 std::string content = speech_monitor_.GetNextUtterance();
381 std::string role = speech_monitor_.GetNextUtterance();
382 if (base::MatchPattern(content, "*Bluetooth*") &&
383 base::MatchPattern(role, "Button"))
384 break;
386 SendKeyPress(ui::VKEY_RETURN);
388 // Navigate to return to previous menu button and press it.
389 while (true) {
390 SendKeyPress(ui::VKEY_TAB);
391 std::string utterance = speech_monitor_.GetNextUtterance();
392 if (base::MatchPattern(utterance, "Previous menu"))
393 break;
395 SendKeyPress(ui::VKEY_RETURN);
397 while (true) {
398 std::string utterance = speech_monitor_.GetNextUtterance();
399 if (base::MatchPattern(speech_monitor_.GetNextUtterance(), "*Bluetooth"))
400 break;
404 // See http://crbug.com/443608
405 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, DISABLED_ScreenBrightness) {
406 EnableChromeVox();
408 EXPECT_TRUE(PerformAcceleratorAction(ash::BRIGHTNESS_UP));
409 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
410 "Brightness * percent"));
412 EXPECT_TRUE(PerformAcceleratorAction(ash::BRIGHTNESS_DOWN));
413 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
414 "Brightness * percent"));
417 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, VolumeSlider) {
418 EnableChromeVox();
420 EXPECT_TRUE(PerformAcceleratorAction(ash::VOLUME_UP));
421 EXPECT_TRUE(
422 base::MatchPattern(speech_monitor_.GetNextUtterance(), "* percent*"));
423 EXPECT_EQ("Volume,", speech_monitor_.GetNextUtterance());
424 EXPECT_EQ("slider", speech_monitor_.GetNextUtterance());
427 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, OverviewMode) {
428 EnableChromeVox();
430 EXPECT_TRUE(PerformAcceleratorAction(ash::TOGGLE_OVERVIEW));
431 EXPECT_EQ("Edit text", speech_monitor_.GetNextUtterance());
432 EXPECT_EQ("Alert", speech_monitor_.GetNextUtterance());
433 EXPECT_EQ("Entered window overview mode", speech_monitor_.GetNextUtterance());
435 SendKeyPress(ui::VKEY_TAB);
436 EXPECT_EQ("about:blank", speech_monitor_.GetNextUtterance());
437 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
440 #if defined(MEMORY_SANITIZER)
441 // Fails under MemorySanitizer: http://crbug.com/472125
442 #define MAYBE_ChromeVoxShiftSearch DISABLED_ChromeVoxShiftSearch
443 #else
444 #define MAYBE_ChromeVoxShiftSearch ChromeVoxShiftSearch
445 #endif
446 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, MAYBE_ChromeVoxShiftSearch) {
447 LoadChromeVoxAndThenNavigateToURL(
448 GURL("data:text/html;charset=utf-8,<button autofocus>Click me</button>"));
449 while (true) {
450 std::string utterance = speech_monitor_.GetNextUtterance();
451 if (utterance == "Click me")
452 break;
454 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
456 // Press Search+Shift+/ to enter ChromeVox's "find in page".
457 SendKeyPressWithSearchAndShift(ui::VKEY_OEM_2);
458 EXPECT_EQ("Find in page.", speech_monitor_.GetNextUtterance());
459 EXPECT_EQ("Enter a search query.", speech_monitor_.GetNextUtterance());
462 #if defined(MEMORY_SANITIZER)
463 // Fails under MemorySanitizer: http://crbug.com/472125
464 #define MAYBE_ChromeVoxPrefixKey DISABLED_ChromeVoxPrefixKey
465 #else
466 #define MAYBE_ChromeVoxPrefixKey ChromeVoxPrefixKey
467 #endif
468 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, MAYBE_ChromeVoxPrefixKey) {
469 LoadChromeVoxAndThenNavigateToURL(
470 GURL("data:text/html;charset=utf-8,<button autofocus>Click me</button>"));
471 while (true) {
472 std::string utterance = speech_monitor_.GetNextUtterance();
473 if (utterance == "Click me")
474 break;
476 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
478 // Press the prefix key Ctrl+';' followed by '/'
479 // to enter ChromeVox's "find in page".
480 SendKeyPressWithControl(ui::VKEY_OEM_1);
481 SendKeyPress(ui::VKEY_OEM_2);
482 EXPECT_EQ("Find in page.", speech_monitor_.GetNextUtterance());
483 EXPECT_EQ("Enter a search query.", speech_monitor_.GetNextUtterance());
486 #if defined(MEMORY_SANITIZER)
487 // Fails under MemorySanitizer: http://crbug.com/472125
488 #define MAYBE_ChromeVoxNavigateAndSelect DISABLED_ChromeVoxNavigateAndSelect
489 #else
490 #define MAYBE_ChromeVoxNavigateAndSelect ChromeVoxNavigateAndSelect
491 #endif
492 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, MAYBE_ChromeVoxNavigateAndSelect) {
493 LoadChromeVoxAndThenNavigateToURL(
494 GURL("data:text/html;charset=utf-8,"
495 "<h1>Title</h1>"
496 "<button autofocus>Click me</button>"));
497 while (true) {
498 std::string utterance = speech_monitor_.GetNextUtterance();
499 if (utterance == "Click me")
500 break;
502 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
504 // Press Search+Shift+Up to navigate to the previous item.
505 SendKeyPressWithSearchAndShift(ui::VKEY_UP);
506 EXPECT_EQ("Title", speech_monitor_.GetNextUtterance());
507 EXPECT_EQ("Heading 1", speech_monitor_.GetNextUtterance());
509 // Press Search+Shift+S to select the text.
510 SendKeyPressWithSearchAndShift(ui::VKEY_S);
511 EXPECT_EQ("Start selection", speech_monitor_.GetNextUtterance());
512 EXPECT_EQ("Title", speech_monitor_.GetNextUtterance());
513 EXPECT_EQ(", selected", speech_monitor_.GetNextUtterance());
515 // Press again to end the selection.
516 SendKeyPressWithSearchAndShift(ui::VKEY_S);
517 EXPECT_EQ("End selection", speech_monitor_.GetNextUtterance());
518 EXPECT_EQ("Title", speech_monitor_.GetNextUtterance());
521 // flaky: http://crbug.com/418572
522 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, DISABLED_ChromeVoxStickyMode) {
523 LoadChromeVoxAndThenNavigateToURL(
524 GURL("data:text/html;charset=utf-8,"
525 "<label>Enter your name <input autofocus></label>"
526 "<p>One</p>"
527 "<h2>Two</h2>"));
528 while (speech_monitor_.GetNextUtterance() != "Enter your name") {
530 EXPECT_EQ("Edit text", speech_monitor_.GetNextUtterance());
532 // Press the sticky-key sequence: Search Search.
533 SendKeyPress(ui::VKEY_LWIN);
534 SendKeyPress(ui::VKEY_LWIN);
535 EXPECT_EQ("Sticky mode enabled", speech_monitor_.GetNextUtterance());
537 // Even once we hear "sticky mode enabled" from the ChromeVox background
538 // page, there's a short window of time when the content script still
539 // hasn't switched to sticky mode. That's why we're focused on a text box.
540 // Keep pressing the '/' key. If sticky mode is off, it will echo the word
541 // "slash". If sticky mode is on, it will open "Find in page". Keep pressing
542 // '/' until we get "Find in page.".
543 PressRepeatedlyUntilUtterance(ui::VKEY_OEM_2, "Find in page.");
544 EXPECT_EQ("Enter a search query.", speech_monitor_.GetNextUtterance());
546 // Press Esc to exit Find in Page mode.
547 SendKeyPress(ui::VKEY_ESCAPE);
548 EXPECT_EQ("Exited", speech_monitor_.GetNextUtterance());
549 EXPECT_EQ("Find in page.", speech_monitor_.GetNextUtterance());
551 // Press N H to jump to the next heading. Skip over speech in-between
552 // but make sure we end up at the heading.
553 SendKeyPress(ui::VKEY_N);
554 SendKeyPress(ui::VKEY_H);
555 while (speech_monitor_.GetNextUtterance() != "Two") {
557 EXPECT_EQ("Heading 2", speech_monitor_.GetNextUtterance());
559 // Press the up arrow to go to the previous element.
560 SendKeyPress(ui::VKEY_UP);
561 EXPECT_EQ("One", speech_monitor_.GetNextUtterance());
564 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, TouchExploreStatusTray) {
565 EnableChromeVox();
566 SimulateTouchScreenInChromeVox();
568 // Send an accessibility hover event on the system tray, which is
569 // what we get when you tap it on a touch screen when ChromeVox is on.
570 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
571 tray->NotifyAccessibilityEvent(ui::AX_EVENT_HOVER, true);
573 EXPECT_EQ("Status tray,", speech_monitor_.GetNextUtterance());
574 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(), "time*,"));
575 EXPECT_TRUE(
576 base::MatchPattern(speech_monitor_.GetNextUtterance(), "Battery*"));
577 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
581 // Spoken feedback tests that run only in guest mode.
584 class GuestSpokenFeedbackTest : public LoggedInSpokenFeedbackTest {
585 protected:
586 GuestSpokenFeedbackTest() {}
587 ~GuestSpokenFeedbackTest() override {}
589 void SetUpCommandLine(base::CommandLine* command_line) override {
590 command_line->AppendSwitch(chromeos::switches::kGuestSession);
591 command_line->AppendSwitch(::switches::kIncognito);
592 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
593 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
594 chromeos::login::kGuestUserName);
597 private:
598 DISALLOW_COPY_AND_ASSIGN(GuestSpokenFeedbackTest);
601 IN_PROC_BROWSER_TEST_F(GuestSpokenFeedbackTest, FocusToolbar) {
602 EnableChromeVox();
604 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
606 EXPECT_TRUE(
607 base::MatchPattern(speech_monitor_.GetNextUtterance(), "about:blank*"));
608 EXPECT_EQ("main", speech_monitor_.GetNextUtterance());
609 EXPECT_EQ("Tool bar", speech_monitor_.GetNextUtterance());
610 EXPECT_EQ("Reload", speech_monitor_.GetNextUtterance());
611 EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
615 // Spoken feedback tests of the out-of-box experience.
618 class OobeSpokenFeedbackTest : public LoginManagerTest {
619 protected:
620 OobeSpokenFeedbackTest() : LoginManagerTest(false) {}
621 ~OobeSpokenFeedbackTest() override {}
623 void SetUpCommandLine(base::CommandLine* command_line) override {
624 LoginManagerTest::SetUpCommandLine(command_line);
625 // Many bots don't have keyboard/mice which triggers the HID detection
626 // dialog in the OOBE. Avoid confusing the tests with that.
627 command_line->AppendSwitch(chromeos::switches::kDisableHIDDetectionOnOOBE);
630 SpeechMonitor speech_monitor_;
632 private:
633 DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest);
636 // Test is flaky: http://crbug.com/346797
637 IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, DISABLED_SpokenFeedbackInOobe) {
638 ui_controls::EnableUIControls();
639 ASSERT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
641 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
642 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
643 views::Widget* widget = web_ui_login_view->GetWidget();
644 gfx::NativeWindow window = widget->GetNativeWindow();
646 // We expect to be in the language select dropdown for this test to work,
647 // so make sure that's the case.
648 js_checker().ExecuteAsync("$('language-select').focus()");
649 AccessibilityManager::Get()->EnableSpokenFeedback(
650 true, ui::A11Y_NOTIFICATION_NONE);
651 ASSERT_TRUE(speech_monitor_.SkipChromeVoxEnabledMessage());
652 // There's no guarantee that ChromeVox speaks anything when injected after
653 // the page loads, which is by design. Tab forward and then backward
654 // to make sure we get the right feedback from the language and keyboard
655 // selection fields.
656 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
657 window, ui::VKEY_TAB, false, false, false, false));
659 while (speech_monitor_.GetNextUtterance() != "Select your keyboard:") {
661 EXPECT_EQ("U S", speech_monitor_.GetNextUtterance());
662 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
663 "Combo box * of *"));
664 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
665 window, ui::VKEY_TAB, false, true /*shift*/, false, false));
666 while (speech_monitor_.GetNextUtterance() != "Select your language:") {
668 EXPECT_EQ("English ( United States)", speech_monitor_.GetNextUtterance());
669 EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
670 "Combo box * of *"));
673 } // namespace chromeos