From 3299e1cf26232b831441987ae90d442b21ab6def Mon Sep 17 00:00:00 2001 From: dmazzoni Date: Wed, 3 Sep 2014 17:22:19 -0700 Subject: [PATCH] Add test for ChromeVox keyboard commands. This is just a couple of quick sanity checks to prevent future regressions like the one in the linked bug. It tests both a Search+Shift shortcut and the corresponding Prefix Key shortcut. Adds support for sending the meta modifier key in aura/x11 tests. BUG=404470 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=291547 Review URL: https://codereview.chromium.org/490443002 Cr-Commit-Position: refs/heads/master@{#293234} --- .../accessibility/spoken_feedback_browsertest.cc | 110 ++++++++++++++++++++- ui/aura/test/ui_controls_factory_aurax11.cc | 6 +- ui/aura/test/ui_controls_factory_ozone.cc | 10 ++ 3 files changed, 119 insertions(+), 7 deletions(-) diff --git a/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc b/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc index ef47cedcffd9..76ee1fe067d7 100644 --- a/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc +++ b/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc @@ -60,11 +60,24 @@ class LoggedInSpokenFeedbackTest : public InProcessBrowserTest { } void SendKeyPress(ui::KeyboardCode key) { - gfx::NativeWindow root_window = - ash::Shell::GetInstance()->GetPrimaryRootWindow(); - ASSERT_TRUE( - ui_test_utils::SendKeyPressToWindowSync( - root_window, key, false, false, false, false)); + ASSERT_NO_FATAL_FAILURE( + ASSERT_TRUE( + ui_test_utils::SendKeyPressToWindowSync( + NULL, key, false, false, false, false))); + } + + void SendKeyPressWithControl(ui::KeyboardCode key) { + ASSERT_NO_FATAL_FAILURE( + ASSERT_TRUE( + ui_test_utils::SendKeyPressToWindowSync( + NULL, key, true, false, false, false))); + } + + void SendKeyPressWithSearchAndShift(ui::KeyboardCode key) { + ASSERT_NO_FATAL_FAILURE( + ASSERT_TRUE( + ui_test_utils::SendKeyPressToWindowSync( + NULL, key, false, true, false, true))); } void RunJavaScriptInChromeVoxBackgroundPage(const std::string& script) { @@ -238,6 +251,93 @@ IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, TypeInOmnibox) { EXPECT_EQ("z", monitor.GetNextUtterance()); } +IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, ChromeVoxShiftSearch) { + EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); + + SpeechMonitor monitor; + AccessibilityManager::Get()->EnableSpokenFeedback( + true, ash::A11Y_NOTIFICATION_NONE); + EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage()); + + ui_test_utils::NavigateToURL( + browser(), + GURL("data:text/html;charset=utf-8,")); + while (true) { + std::string utterance = monitor.GetNextUtterance(); + if (utterance == "Click me") + break; + } + EXPECT_EQ("Button", monitor.GetNextUtterance()); + + // Press Search+Shift+/ to enter ChromeVox's "find in page". + SendKeyPressWithSearchAndShift(ui::VKEY_OEM_2); + EXPECT_EQ("Find in page.", monitor.GetNextUtterance()); + EXPECT_EQ("Enter a search query.", monitor.GetNextUtterance()); +} + +IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, ChromeVoxPrefixKey) { + EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); + + SpeechMonitor monitor; + AccessibilityManager::Get()->EnableSpokenFeedback( + true, ash::A11Y_NOTIFICATION_NONE); + EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage()); + + ui_test_utils::NavigateToURL( + browser(), + GURL("data:text/html;charset=utf-8,")); + while (true) { + std::string utterance = monitor.GetNextUtterance(); + if (utterance == "Click me") + break; + } + EXPECT_EQ("Button", monitor.GetNextUtterance()); + + // Press the prefix key Ctrl+';' followed by '/' + // to enter ChromeVox's "find in page". + SendKeyPressWithControl(ui::VKEY_OEM_1); + SendKeyPress(ui::VKEY_OEM_2); + EXPECT_EQ("Find in page.", monitor.GetNextUtterance()); + EXPECT_EQ("Enter a search query.", monitor.GetNextUtterance()); +} + +IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, ChromeVoxNavigateAndSelect) { + EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); + + SpeechMonitor monitor; + AccessibilityManager::Get()->EnableSpokenFeedback( + true, ash::A11Y_NOTIFICATION_NONE); + EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage()); + + ui_test_utils::NavigateToURL( + browser(), + GURL("data:text/html;charset=utf-8," + "

Title

" + "")); + while (true) { + std::string utterance = monitor.GetNextUtterance(); + if (utterance == "Click me") + break; + } + EXPECT_EQ("Button", monitor.GetNextUtterance()); + + // Press Search+Shift+Up to navigate to the previous item. + SendKeyPressWithSearchAndShift(ui::VKEY_UP); + EXPECT_EQ("Title", monitor.GetNextUtterance()); + EXPECT_EQ("Heading 1", monitor.GetNextUtterance()); + + // Press Search+Shift+S to select the text. + SendKeyPressWithSearchAndShift(ui::VKEY_S); + EXPECT_EQ("Start selection", monitor.GetNextUtterance()); + EXPECT_EQ("Title", monitor.GetNextUtterance()); + EXPECT_EQ(", selected", monitor.GetNextUtterance()); + + // Press again to end the selection. + SendKeyPressWithSearchAndShift(ui::VKEY_S); + EXPECT_EQ("End selection", monitor.GetNextUtterance()); + EXPECT_EQ("Title", monitor.GetNextUtterance()); +} + IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, TouchExploreStatusTray) { EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); diff --git a/ui/aura/test/ui_controls_factory_aurax11.cc b/ui/aura/test/ui_controls_factory_aurax11.cc index 06a94398e5c3..383d0734049e 100644 --- a/ui/aura/test/ui_controls_factory_aurax11.cc +++ b/ui/aura/test/ui_controls_factory_aurax11.cc @@ -56,7 +56,6 @@ class UIControlsX11 : public UIControlsAura { bool shift, bool alt, bool command) OVERRIDE { - DCHECK(!command); // No command key on Aura return SendKeyPressNotifyWhenDone( window, key, control, shift, alt, command, base::Closure()); } @@ -68,7 +67,6 @@ class UIControlsX11 : public UIControlsAura { bool alt, bool command, const base::Closure& closure) OVERRIDE { - DCHECK(!command); // No command key on Aura XEvent xevent = {0}; xevent.xkey.type = KeyPress; if (control) @@ -77,6 +75,8 @@ class UIControlsX11 : public UIControlsAura { SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); if (alt) SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); + if (command) + SetKeycodeAndSendThenMask(&xevent, XK_Super_L, Mod4Mask); xevent.xkey.keycode = XKeysymToKeycode(gfx::GetXDisplay(), ui::XKeysymForWindowsKeyCode(key, shift)); @@ -91,6 +91,8 @@ class UIControlsX11 : public UIControlsAura { UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); if (control) UnmaskAndSetKeycodeThenSend(&xevent, ControlMask, XK_Control_L); + if (command) + UnmaskAndSetKeycodeThenSend(&xevent, Mod4Mask, XK_Super_L); DCHECK(!xevent.xkey.state); RunClosureAfterAllPendingUIEvents(closure); return true; diff --git a/ui/aura/test/ui_controls_factory_ozone.cc b/ui/aura/test/ui_controls_factory_ozone.cc index 5179360e6fbe..056a591792bc 100644 --- a/ui/aura/test/ui_controls_factory_ozone.cc +++ b/ui/aura/test/ui_controls_factory_ozone.cc @@ -55,6 +55,11 @@ class UIControlsOzone : public ui_controls::UIControlsAura { PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_MENU, flags); } + if (command) { + flags |= ui::EF_COMMAND_DOWN; + PostKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_LWIN, flags); + } + PostKeyEvent(ui::ET_KEY_PRESSED, key, flags); PostKeyEvent(ui::ET_KEY_RELEASED, key, flags); @@ -73,6 +78,11 @@ class UIControlsOzone : public ui_controls::UIControlsAura { PostKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_CONTROL, flags); } + if (command) { + flags &= ~ui::EF_COMMAND_DOWN; + PostKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_LWIN, flags); + } + RunClosureAfterAllPendingUIEvents(closure); return true; } -- 2.11.4.GIT