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.
7 #include "base/command_line.h"
8 #include "base/strings/string_util.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
11 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
12 #include "chrome/browser/chromeos/login/login_display_host.h"
13 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/user_manager.h"
15 #include "chrome/browser/chromeos/login/webui_login_view.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h"
18 #include "chrome/browser/speech/tts_controller.h"
19 #include "chrome/browser/speech/tts_platform.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/testing_profile.h"
25 #include "chrome/test/base/ui_test_utils.h"
26 #include "chromeos/chromeos_switches.h"
27 #include "content/public/common/url_constants.h"
28 #include "content/public/test/test_utils.h"
29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "ui/base/test/ui_controls.h"
31 #include "ui/views/widget/widget.h"
33 using extensions::api::braille_display_private::StubBrailleController;
38 // Spoken feedback tests in a normal browser window.
41 class SpokenFeedbackTest : public InProcessBrowserTest {
43 SpokenFeedbackTest() {}
44 virtual ~SpokenFeedbackTest() {}
46 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
47 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
50 virtual void CleanUpOnMainThread() OVERRIDE {
51 AccessibilityManager::SetBrailleControllerForTest(NULL);
55 StubBrailleController braille_controller_;
56 DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest);
59 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) {
60 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
62 SpeechMonitor monitor;
63 AccessibilityManager::Get()->EnableSpokenFeedback(
64 true, ash::A11Y_NOTIFICATION_NONE);
65 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
68 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) {
69 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
71 SpeechMonitor monitor;
72 AccessibilityManager::Get()->EnableSpokenFeedback(
73 true, ash::A11Y_NOTIFICATION_NONE);
74 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
76 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
77 // Might be "Google Chrome Toolbar" or "Chromium Toolbar".
78 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*"));
79 EXPECT_EQ("Reload,", monitor.GetNextUtterance());
80 EXPECT_EQ("button", monitor.GetNextUtterance());
84 // Spoken feedback tests of the out-of-box experience.
87 class OobeSpokenFeedbackTest : public InProcessBrowserTest {
89 OobeSpokenFeedbackTest() {}
90 virtual ~OobeSpokenFeedbackTest() {}
92 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
93 command_line->AppendSwitch(chromeos::switches::kLoginManager);
94 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
95 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
98 virtual void SetUpOnMainThread() OVERRIDE {
99 AccessibilityManager::Get()->
100 SetProfileForTest(ProfileHelper::GetSigninProfile());
104 DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest);
107 IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, SpokenFeedbackInOobe) {
108 ui_controls::EnableUIControls();
109 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
111 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
112 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
113 views::Widget* widget = web_ui_login_view->GetWidget();
114 gfx::NativeWindow window = widget->GetNativeWindow();
116 SpeechMonitor monitor;
117 AccessibilityManager::Get()->EnableSpokenFeedback(
118 true, ash::A11Y_NOTIFICATION_NONE);
119 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
121 EXPECT_EQ("Select your language:", monitor.GetNextUtterance());
122 EXPECT_EQ("English ( United States)", monitor.GetNextUtterance());
123 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *"));
124 ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false);
125 EXPECT_EQ("Select your keyboard:", monitor.GetNextUtterance());
128 } // namespace chromeos