OLD | NEW |
| (Empty) |
1 // Copyright (c) 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 "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/login/login_display_host.h" | |
12 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | |
13 #include "chrome/browser/chromeos/login/user_manager.h" | |
14 #include "chrome/browser/chromeos/login/webui_login_view.h" | |
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
16 #include "chrome/browser/speech/tts_controller.h" | |
17 #include "chrome/browser/speech/tts_platform.h" | |
18 #include "chrome/browser/ui/browser.h" | |
19 #include "chrome/browser/ui/browser_commands.h" | |
20 #include "chrome/browser/ui/browser_window.h" | |
21 #include "chrome/test/base/in_process_browser_test.h" | |
22 #include "chrome/test/base/testing_profile.h" | |
23 #include "chrome/test/base/ui_test_utils.h" | |
24 #include "chromeos/chromeos_switches.h" | |
25 #include "content/public/common/url_constants.h" | |
26 #include "content/public/test/test_utils.h" | |
27 #include "testing/gtest/include/gtest/gtest.h" | |
28 #include "ui/base/test/ui_controls.h" | |
29 #include "ui/views/widget/widget.h" | |
30 | |
31 namespace chromeos { | |
32 | |
33 namespace { | |
34 const char kChromeVoxEnabledMessage[] = "chrome vox spoken feedback is ready"; | |
35 } // anonymous namespace | |
36 | |
37 // Installs itself as the platform speech synthesis engine, allowing it to | |
38 // intercept all speech calls, and then provides a method to block until the | |
39 // next utterance is spoken. | |
40 class SpeechMonitor : public TtsPlatformImpl { | |
41 public: | |
42 SpeechMonitor(); | |
43 virtual ~SpeechMonitor(); | |
44 | |
45 // Blocks until the next utterance is spoken, and returns its text. | |
46 std::string GetNextUtterance(); | |
47 | |
48 // TtsPlatformImpl implementation. | |
49 virtual bool PlatformImplAvailable() OVERRIDE { return true; } | |
50 virtual bool Speak( | |
51 int utterance_id, | |
52 const std::string& utterance, | |
53 const std::string& lang, | |
54 const VoiceData& voice, | |
55 const UtteranceContinuousParameters& params) OVERRIDE { | |
56 TtsController::GetInstance()->OnTtsEvent( | |
57 utterance_id, | |
58 TTS_EVENT_END, | |
59 static_cast<int>(utterance.size()), | |
60 std::string()); | |
61 return true; | |
62 } | |
63 virtual bool StopSpeaking() OVERRIDE { return true; } | |
64 virtual bool IsSpeaking() OVERRIDE { return false; } | |
65 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE { | |
66 out_voices->push_back(VoiceData()); | |
67 VoiceData& voice = out_voices->back(); | |
68 voice.native = true; | |
69 voice.name = "SpeechMonitor"; | |
70 voice.events.insert(TTS_EVENT_END); | |
71 } | |
72 virtual void Pause() OVERRIDE {} | |
73 virtual void Resume() OVERRIDE {} | |
74 virtual std::string error() OVERRIDE { return ""; } | |
75 virtual void clear_error() OVERRIDE {} | |
76 virtual void set_error(const std::string& error) OVERRIDE {} | |
77 virtual void WillSpeakUtteranceWithVoice( | |
78 const Utterance* utterance, const VoiceData& voice_data) OVERRIDE; | |
79 | |
80 private: | |
81 scoped_refptr<content::MessageLoopRunner> loop_runner_; | |
82 std::deque<std::string> utterance_queue_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(SpeechMonitor); | |
85 }; | |
86 | |
87 SpeechMonitor::SpeechMonitor() { | |
88 TtsController::GetInstance()->SetPlatformImpl(this); | |
89 } | |
90 | |
91 SpeechMonitor::~SpeechMonitor() { | |
92 TtsController::GetInstance()->SetPlatformImpl(TtsPlatformImpl::GetInstance()); | |
93 } | |
94 | |
95 void SpeechMonitor::WillSpeakUtteranceWithVoice(const Utterance* utterance, | |
96 const VoiceData& voice_data) { | |
97 utterance_queue_.push_back(utterance->text()); | |
98 if (loop_runner_.get()) | |
99 loop_runner_->Quit(); | |
100 } | |
101 | |
102 std::string SpeechMonitor::GetNextUtterance() { | |
103 if (utterance_queue_.empty()) { | |
104 loop_runner_ = new content::MessageLoopRunner(); | |
105 loop_runner_->Run(); | |
106 loop_runner_ = NULL; | |
107 } | |
108 std::string result = utterance_queue_.front(); | |
109 utterance_queue_.pop_front(); | |
110 return result; | |
111 } | |
112 | |
113 // | |
114 // Spoken feedback tests in a normal browser window. | |
115 // | |
116 | |
117 class SpokenFeedbackTest : public InProcessBrowserTest { | |
118 protected: | |
119 SpokenFeedbackTest() {} | |
120 virtual ~SpokenFeedbackTest() {} | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest); | |
123 }; | |
124 | |
125 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) { | |
126 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); | |
127 | |
128 SpeechMonitor monitor; | |
129 AccessibilityManager::Get()->EnableSpokenFeedback( | |
130 true, ash::A11Y_NOTIFICATION_NONE); | |
131 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); | |
132 } | |
133 | |
134 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) { | |
135 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); | |
136 | |
137 SpeechMonitor monitor; | |
138 AccessibilityManager::Get()->EnableSpokenFeedback( | |
139 true, ash::A11Y_NOTIFICATION_NONE); | |
140 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); | |
141 | |
142 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR); | |
143 // Might be "Google Chrome Toolbar" or "Chromium Toolbar". | |
144 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*")); | |
145 EXPECT_EQ("Reload,", monitor.GetNextUtterance()); | |
146 EXPECT_EQ("button", monitor.GetNextUtterance()); | |
147 } | |
148 | |
149 // | |
150 // Spoken feedback tests of the out-of-box experience. | |
151 // | |
152 | |
153 class OobeSpokenFeedbackTest : public InProcessBrowserTest { | |
154 protected: | |
155 OobeSpokenFeedbackTest() {} | |
156 virtual ~OobeSpokenFeedbackTest() {} | |
157 | |
158 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
159 command_line->AppendSwitch(chromeos::switches::kLoginManager); | |
160 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | |
161 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); | |
162 } | |
163 | |
164 virtual void SetUpOnMainThread() OVERRIDE { | |
165 AccessibilityManager::Get()-> | |
166 SetProfileForTest(ProfileHelper::GetSigninProfile()); | |
167 } | |
168 | |
169 private: | |
170 DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest); | |
171 }; | |
172 | |
173 IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, SpokenFeedbackInOobe) { | |
174 ui_controls::EnableUIControls(); | |
175 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); | |
176 | |
177 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host(); | |
178 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView(); | |
179 views::Widget* widget = web_ui_login_view->GetWidget(); | |
180 gfx::NativeWindow window = widget->GetNativeWindow(); | |
181 | |
182 SpeechMonitor monitor; | |
183 AccessibilityManager::Get()->EnableSpokenFeedback( | |
184 true, ash::A11Y_NOTIFICATION_NONE); | |
185 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); | |
186 | |
187 ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false); | |
188 EXPECT_EQ("Select your language:", monitor.GetNextUtterance()); | |
189 EXPECT_EQ("English ( United States)", monitor.GetNextUtterance()); | |
190 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *")); | |
191 } | |
192 | |
193 } // namespace chromeos | |
OLD | NEW |