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.
8 #include "base/command_line.h"
9 #include "base/strings/string_util.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
12 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
13 #include "chrome/browser/chromeos/login/login_display_host.h"
14 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/chromeos/login/webui_login_view.h"
17 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h"
19 #include "chrome/browser/speech/tts_controller.h"
20 #include "chrome/browser/speech/tts_platform.h"
21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_commands.h"
23 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/ui_test_utils.h"
27 #include "chromeos/chromeos_switches.h"
28 #include "content/public/common/url_constants.h"
29 #include "content/public/test/test_utils.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/test/ui_controls.h"
32 #include "ui/views/widget/widget.h"
34 using extensions::api::braille_display_private::StubBrailleController;
39 // Spoken feedback tests in a normal browser window.
42 class SpokenFeedbackTest : public InProcessBrowserTest {
44 SpokenFeedbackTest() {}
45 virtual ~SpokenFeedbackTest() {}
47 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
48 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
51 virtual void CleanUpOnMainThread() OVERRIDE {
52 AccessibilityManager::SetBrailleControllerForTest(NULL);
56 StubBrailleController braille_controller_;
57 DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest);
60 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) {
61 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
63 SpeechMonitor monitor;
64 AccessibilityManager::Get()->EnableSpokenFeedback(
65 true, ash::A11Y_NOTIFICATION_NONE);
66 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
69 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) {
70 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
72 SpeechMonitor monitor;
73 AccessibilityManager::Get()->EnableSpokenFeedback(
74 true, ash::A11Y_NOTIFICATION_NONE);
75 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
77 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
78 // Might be "Google Chrome Toolbar" or "Chromium Toolbar".
79 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*"));
80 EXPECT_EQ("Reload,", monitor.GetNextUtterance());
81 EXPECT_EQ("button", monitor.GetNextUtterance());
84 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, TypeInOmnibox) {
85 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
87 SpeechMonitor monitor;
88 AccessibilityManager::Get()->EnableSpokenFeedback(
89 true, ash::A11Y_NOTIFICATION_NONE);
90 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
92 chrome::ExecuteCommand(browser(), IDC_FOCUS_LOCATION);
94 gfx::NativeWindow window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
95 ui_controls::SendKeyPress(window, ui::VKEY_X, false, false, false, false);
97 std::string utterance = monitor.GetNextUtterance();
98 VLOG(0) << "Got utterance: " << utterance;
103 ui_controls::SendKeyPress(window, ui::VKEY_Y, false, false, false, false);
104 EXPECT_EQ("y", monitor.GetNextUtterance());
106 ui_controls::SendKeyPress(window, ui::VKEY_Z, false, false, false, false);
107 EXPECT_EQ("z", monitor.GetNextUtterance());
109 ui_controls::SendKeyPress(window, ui::VKEY_BACK, false, false, false, false);
110 EXPECT_EQ("z", monitor.GetNextUtterance());
114 // Spoken feedback tests of the out-of-box experience.
117 class OobeSpokenFeedbackTest : public InProcessBrowserTest {
119 OobeSpokenFeedbackTest() {}
120 virtual ~OobeSpokenFeedbackTest() {}
122 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
123 command_line->AppendSwitch(chromeos::switches::kLoginManager);
124 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
125 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
128 virtual void SetUpOnMainThread() OVERRIDE {
129 AccessibilityManager::Get()->
130 SetProfileForTest(ProfileHelper::GetSigninProfile());
134 DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest);
137 // Test is flaky: http://crbug.com/346797
138 IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, DISABLED_SpokenFeedbackInOobe) {
139 ui_controls::EnableUIControls();
140 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
142 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
143 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
144 views::Widget* widget = web_ui_login_view->GetWidget();
145 gfx::NativeWindow window = widget->GetNativeWindow();
147 SpeechMonitor monitor;
148 AccessibilityManager::Get()->EnableSpokenFeedback(
149 true, ash::A11Y_NOTIFICATION_NONE);
150 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
152 EXPECT_EQ("Select your language:", monitor.GetNextUtterance());
153 EXPECT_EQ("English ( United States)", monitor.GetNextUtterance());
154 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *"));
155 ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false);
156 EXPECT_EQ("Select your keyboard:", monitor.GetNextUtterance());
159 } // namespace chromeos