Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / accessibility / spoken_feedback_browsertest.cc
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/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"
34
35 using extensions::api::braille_display_private::StubBrailleController;
36
37 namespace chromeos {
38
39 //
40 // Spoken feedback tests in a normal browser window.
41 //
42
43 enum SpokenFeedbackTestVariant {
44   kTestAsNormalUser,
45   kTestAsGuestUser
46 };
47
48 class SpokenFeedbackTest
49     : public InProcessBrowserTest,
50       public ::testing::WithParamInterface<SpokenFeedbackTestVariant> {
51  protected:
52   SpokenFeedbackTest() {}
53   virtual ~SpokenFeedbackTest() {}
54
55   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
56     AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
57   }
58
59   virtual void CleanUpOnMainThread() OVERRIDE {
60     AccessibilityManager::SetBrailleControllerForTest(NULL);
61   }
62
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,
68                                       "user");
69       command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
70                                       chromeos::UserManager::kGuestUserName);
71     }
72   }
73
74  private:
75   StubBrailleController braille_controller_;
76   DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest);
77 };
78
79 INSTANTIATE_TEST_CASE_P(
80     TestAsNormalAndGuestUser,
81     SpokenFeedbackTest,
82     ::testing::Values(kTestAsNormalUser,
83                       kTestAsGuestUser));
84
85 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, EnableSpokenFeedback) {
86   EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
87
88   SpeechMonitor monitor;
89   AccessibilityManager::Get()->EnableSpokenFeedback(
90       true, ash::A11Y_NOTIFICATION_NONE);
91   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
92 }
93
94 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, FocusToolbar) {
95   EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
96
97   SpeechMonitor monitor;
98   AccessibilityManager::Get()->EnableSpokenFeedback(
99       true, ash::A11Y_NOTIFICATION_NONE);
100   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
101
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());
107 }
108
109 IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, TypeInOmnibox) {
110   EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
111
112   SpeechMonitor monitor;
113   AccessibilityManager::Get()->EnableSpokenFeedback(
114       true, ash::A11Y_NOTIFICATION_NONE);
115   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
116
117   chrome::ExecuteCommand(browser(), IDC_FOCUS_LOCATION);
118
119   gfx::NativeWindow window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
120   ui_controls::SendKeyPress(window, ui::VKEY_X, false, false, false, false);
121   while (true) {
122     std::string utterance = monitor.GetNextUtterance();
123     VLOG(0) << "Got utterance: " << utterance;
124     if (utterance == "x")
125       break;
126   }
127
128   ui_controls::SendKeyPress(window, ui::VKEY_Y, false, false, false, false);
129   EXPECT_EQ("y", monitor.GetNextUtterance());
130
131   ui_controls::SendKeyPress(window, ui::VKEY_Z, false, false, false, false);
132   EXPECT_EQ("z", monitor.GetNextUtterance());
133
134   ui_controls::SendKeyPress(window, ui::VKEY_BACK, false, false, false, false);
135   EXPECT_EQ("z", monitor.GetNextUtterance());
136 }
137
138 //
139 // Spoken feedback tests that run in guest mode.
140 //
141
142 class GuestSpokenFeedbackTest : public SpokenFeedbackTest {
143  protected:
144   GuestSpokenFeedbackTest() {}
145   virtual ~GuestSpokenFeedbackTest() {}
146
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);
153   }
154
155  private:
156   DISALLOW_COPY_AND_ASSIGN(GuestSpokenFeedbackTest);
157 };
158
159 IN_PROC_BROWSER_TEST_F(GuestSpokenFeedbackTest, FocusToolbar) {
160   EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
161
162   SpeechMonitor monitor;
163   AccessibilityManager::Get()->EnableSpokenFeedback(
164       true, ash::A11Y_NOTIFICATION_NONE);
165   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
166
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());
172 }
173
174 //
175 // Spoken feedback tests of the out-of-box experience.
176 //
177
178 class OobeSpokenFeedbackTest : public InProcessBrowserTest {
179  protected:
180   OobeSpokenFeedbackTest() {}
181   virtual ~OobeSpokenFeedbackTest() {}
182
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");
187   }
188
189   virtual void SetUpOnMainThread() OVERRIDE {
190     AccessibilityManager::Get()->
191         SetProfileForTest(ProfileHelper::GetSigninProfile());
192   }
193
194  private:
195   DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest);
196 };
197
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());
202
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();
207
208   SpeechMonitor monitor;
209   AccessibilityManager::Get()->EnableSpokenFeedback(
210       true, ash::A11Y_NOTIFICATION_NONE);
211   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
212
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());
218 }
219
220 }  // namespace chromeos