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/common/chrome_switches.h"
25 #include "chrome/test/base/in_process_browser_test.h"
26 #include "chrome/test/base/testing_profile.h"
27 #include "chrome/test/base/ui_test_utils.h"
28 #include "chromeos/chromeos_switches.h"
29 #include "content/public/common/url_constants.h"
30 #include "content/public/test/test_utils.h"
31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "ui/base/test/ui_controls.h"
33 #include "ui/views/widget/widget.h"
35 using extensions::api::braille_display_private::StubBrailleController;
40 // Spoken feedback tests in a normal browser window.
43 enum SpokenFeedbackTestVariant {
48 class SpokenFeedbackTest
49 : public InProcessBrowserTest,
50 public ::testing::WithParamInterface<SpokenFeedbackTestVariant> {
52 SpokenFeedbackTest() {}
53 virtual ~SpokenFeedbackTest() {}
55 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
56 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
59 virtual void CleanUpOnMainThread() OVERRIDE {
60 AccessibilityManager::SetBrailleControllerForTest(NULL);
63 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
64 if (GetParam() == kTestAsGuestUser) {
65 command_line->AppendSwitch(chromeos::switches::kGuestSession);
66 command_line->AppendSwitch(::switches::kIncognito);
67 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
69 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
70 chromeos::UserManager::kGuestUserName);
75 StubBrailleController braille_controller_;
76 DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest);
79 INSTANTIATE_TEST_CASE_P(
80 TestAsNormalAndGuestUser,
82 ::testing::Values(kTestAsNormalUser,
85 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, EnableSpokenFeedback) {
86 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
88 SpeechMonitor monitor;
89 AccessibilityManager::Get()->EnableSpokenFeedback(
90 true, ash::A11Y_NOTIFICATION_NONE);
91 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
94 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, FocusToolbar) {
95 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
97 SpeechMonitor monitor;
98 AccessibilityManager::Get()->EnableSpokenFeedback(
99 true, ash::A11Y_NOTIFICATION_NONE);
100 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
102 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
103 // Might be "Google Chrome Toolbar" or "Chromium Toolbar".
104 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*"));
105 EXPECT_EQ("Reload,", monitor.GetNextUtterance());
106 EXPECT_EQ("button", monitor.GetNextUtterance());
109 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, TypeInOmnibox) {
110 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
112 SpeechMonitor monitor;
113 AccessibilityManager::Get()->EnableSpokenFeedback(
114 true, ash::A11Y_NOTIFICATION_NONE);
115 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
117 chrome::ExecuteCommand(browser(), IDC_FOCUS_LOCATION);
119 gfx::NativeWindow window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
120 ui_controls::SendKeyPress(window, ui::VKEY_X, false, false, false, false);
122 std::string utterance = monitor.GetNextUtterance();
123 VLOG(0) << "Got utterance: " << utterance;
124 if (utterance == "x")
128 ui_controls::SendKeyPress(window, ui::VKEY_Y, false, false, false, false);
129 EXPECT_EQ("y", monitor.GetNextUtterance());
131 ui_controls::SendKeyPress(window, ui::VKEY_Z, false, false, false, false);
132 EXPECT_EQ("z", monitor.GetNextUtterance());
134 ui_controls::SendKeyPress(window, ui::VKEY_BACK, false, false, false, false);
135 EXPECT_EQ("z", monitor.GetNextUtterance());
139 // Spoken feedback tests that run in guest mode.
142 class GuestSpokenFeedbackTest : public SpokenFeedbackTest {
144 GuestSpokenFeedbackTest() {}
145 virtual ~GuestSpokenFeedbackTest() {}
147 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
148 command_line->AppendSwitch(chromeos::switches::kGuestSession);
149 command_line->AppendSwitch(::switches::kIncognito);
150 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
151 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
152 chromeos::UserManager::kGuestUserName);
156 DISALLOW_COPY_AND_ASSIGN(GuestSpokenFeedbackTest);
159 IN_PROC_BROWSER_TEST_F(GuestSpokenFeedbackTest, FocusToolbar) {
160 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
162 SpeechMonitor monitor;
163 AccessibilityManager::Get()->EnableSpokenFeedback(
164 true, ash::A11Y_NOTIFICATION_NONE);
165 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
167 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
168 // Might be "Google Chrome Toolbar" or "Chromium Toolbar".
169 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*"));
170 EXPECT_EQ("Reload,", monitor.GetNextUtterance());
171 EXPECT_EQ("button", monitor.GetNextUtterance());
175 // Spoken feedback tests of the out-of-box experience.
178 class OobeSpokenFeedbackTest : public InProcessBrowserTest {
180 OobeSpokenFeedbackTest() {}
181 virtual ~OobeSpokenFeedbackTest() {}
183 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
184 command_line->AppendSwitch(chromeos::switches::kLoginManager);
185 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
186 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
189 virtual void SetUpOnMainThread() OVERRIDE {
190 AccessibilityManager::Get()->
191 SetProfileForTest(ProfileHelper::GetSigninProfile());
195 DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest);
198 // Test is flaky: http://crbug.com/346797
199 IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, DISABLED_SpokenFeedbackInOobe) {
200 ui_controls::EnableUIControls();
201 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
203 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
204 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
205 views::Widget* widget = web_ui_login_view->GetWidget();
206 gfx::NativeWindow window = widget->GetNativeWindow();
208 SpeechMonitor monitor;
209 AccessibilityManager::Get()->EnableSpokenFeedback(
210 true, ash::A11Y_NOTIFICATION_NONE);
211 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
213 EXPECT_EQ("Select your language:", monitor.GetNextUtterance());
214 EXPECT_EQ("English ( United States)", monitor.GetNextUtterance());
215 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *"));
216 ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false);
217 EXPECT_EQ("Select your keyboard:", monitor.GetNextUtterance());
220 } // namespace chromeos