spoken_feedback_browsertest.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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.
4
5#include <queue>
6
7#include "ash/shell.h"
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"
33
34using extensions::api::braille_display_private::StubBrailleController;
35
36namespace chromeos {
37
38//
39// Spoken feedback tests in a normal browser window.
40//
41
42class SpokenFeedbackTest : public InProcessBrowserTest {
43 protected:
44  SpokenFeedbackTest() {}
45  virtual ~SpokenFeedbackTest() {}
46
47  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
48    AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
49  }
50
51  virtual void CleanUpOnMainThread() OVERRIDE {
52    AccessibilityManager::SetBrailleControllerForTest(NULL);
53  }
54
55 private:
56  StubBrailleController braille_controller_;
57  DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest);
58};
59
60IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) {
61  EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
62
63  SpeechMonitor monitor;
64  AccessibilityManager::Get()->EnableSpokenFeedback(
65      true, ash::A11Y_NOTIFICATION_NONE);
66  EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
67}
68
69IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) {
70  EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
71
72  SpeechMonitor monitor;
73  AccessibilityManager::Get()->EnableSpokenFeedback(
74      true, ash::A11Y_NOTIFICATION_NONE);
75  EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
76
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());
82}
83
84IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, TypeInOmnibox) {
85  EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
86
87  SpeechMonitor monitor;
88  AccessibilityManager::Get()->EnableSpokenFeedback(
89      true, ash::A11Y_NOTIFICATION_NONE);
90  EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
91
92  chrome::ExecuteCommand(browser(), IDC_FOCUS_LOCATION);
93
94  gfx::NativeWindow window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
95  ui_controls::SendKeyPress(window, ui::VKEY_X, false, false, false, false);
96  while (true) {
97    std::string utterance = monitor.GetNextUtterance();
98    VLOG(0) << "Got utterance: " << utterance;
99    if (utterance == "x")
100      break;
101  }
102
103  ui_controls::SendKeyPress(window, ui::VKEY_Y, false, false, false, false);
104  EXPECT_EQ("y", monitor.GetNextUtterance());
105
106  ui_controls::SendKeyPress(window, ui::VKEY_Z, false, false, false, false);
107  EXPECT_EQ("z", monitor.GetNextUtterance());
108
109  ui_controls::SendKeyPress(window, ui::VKEY_BACK, false, false, false, false);
110  EXPECT_EQ("z", monitor.GetNextUtterance());
111}
112
113//
114// Spoken feedback tests of the out-of-box experience.
115//
116
117class OobeSpokenFeedbackTest : public InProcessBrowserTest {
118 protected:
119  OobeSpokenFeedbackTest() {}
120  virtual ~OobeSpokenFeedbackTest() {}
121
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");
126  }
127
128  virtual void SetUpOnMainThread() OVERRIDE {
129    AccessibilityManager::Get()->
130        SetProfileForTest(ProfileHelper::GetSigninProfile());
131  }
132
133 private:
134  DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest);
135};
136
137// Test is flaky: http://crbug.com/346797
138IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, DISABLED_SpokenFeedbackInOobe) {
139  ui_controls::EnableUIControls();
140  EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
141
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();
146
147  SpeechMonitor monitor;
148  AccessibilityManager::Get()->EnableSpokenFeedback(
149      true, ash::A11Y_NOTIFICATION_NONE);
150  EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
151
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());
157}
158
159}  // namespace chromeos
160