Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: content/browser/speech/speech_recognition_browsertest.cc

Issue 2675713002: Switch Speech Recognition to asynchronous callback-based AudioManager interactions. (Closed)
Patch Set: review comments addressed Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <list> 9 #include <list>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "content/browser/speech/speech_recognition_engine.h" 18 #include "content/browser/speech/speech_recognition_engine.h"
19 #include "content/browser/speech/speech_recognition_manager_impl.h" 19 #include "content/browser/speech/speech_recognition_manager_impl.h"
20 #include "content/browser/speech/speech_recognizer_impl.h" 20 #include "content/browser/speech/speech_recognizer_impl.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
25 #include "content/public/test/content_browser_test.h" 25 #include "content/public/test/content_browser_test.h"
26 #include "content/public/test/content_browser_test_utils.h" 26 #include "content/public/test/content_browser_test_utils.h"
27 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
28 #include "content/shell/browser/shell.h" 28 #include "content/shell/browser/shell.h"
29 #include "content/test/mock_google_streaming_server.h" 29 #include "content/test/mock_google_streaming_server.h"
30 #include "media/audio/audio_system_impl.h"
30 #include "media/audio/mock_audio_manager.h" 31 #include "media/audio/mock_audio_manager.h"
31 #include "media/audio/test_audio_input_controller_factory.h" 32 #include "media/audio/test_audio_input_controller_factory.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 34
34 using base::RunLoop; 35 using base::RunLoop;
35 36
36 namespace content { 37 namespace content {
37 38
38 class SpeechRecognitionBrowserTest : 39 class SpeechRecognitionBrowserTest :
39 public ContentBrowserTest, 40 public ContentBrowserTest,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 media::AudioInputController::set_factory_for_testing( 116 media::AudioInputController::set_factory_for_testing(
116 &test_audio_input_controller_factory_); 117 &test_audio_input_controller_factory_);
117 mock_streaming_server_.reset(new MockGoogleStreamingServer(this)); 118 mock_streaming_server_.reset(new MockGoogleStreamingServer(this));
118 streaming_server_state_ = kIdle; 119 streaming_server_state_ = kIdle;
119 } 120 }
120 121
121 void SetUpOnMainThread() override { 122 void SetUpOnMainThread() override {
122 ASSERT_TRUE(SpeechRecognitionManagerImpl::GetInstance()); 123 ASSERT_TRUE(SpeechRecognitionManagerImpl::GetInstance());
123 media::AudioManager::StartHangMonitorIfNeeded( 124 media::AudioManager::StartHangMonitorIfNeeded(
124 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); 125 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
125 SpeechRecognizerImpl::SetAudioManagerForTesting(new media::MockAudioManager( 126 audio_manager_.reset(new media::MockAudioManager(
126 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); 127 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
128 audio_manager_->SetInputStreamParameters(
129 media::AudioParameters::UnavailableDeviceParams());
130 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
131 SpeechRecognizerImpl::SetAudioSystemForTesting(audio_system_.get());
127 } 132 }
128 133
129 void TearDownOnMainThread() override { 134 void TearDownOnMainThread() override {
130 SpeechRecognizerImpl::SetAudioManagerForTesting(NULL); 135 SpeechRecognizerImpl::SetAudioSystemForTesting(nullptr);
131 } 136 }
132 137
133 void TearDownInProcessBrowserTestFixture() override { 138 void TearDownInProcessBrowserTestFixture() override {
134 test_audio_input_controller_factory_.set_delegate(NULL); 139 test_audio_input_controller_factory_.set_delegate(nullptr);
135 mock_streaming_server_.reset(); 140 mock_streaming_server_.reset();
136 } 141 }
137 142
138 private: 143 private:
139 static void FeedSingleBufferToAudioController( 144 static void FeedSingleBufferToAudioController(
140 scoped_refptr<media::TestAudioInputController> controller, 145 scoped_refptr<media::TestAudioInputController> controller,
141 size_t buffer_size, 146 size_t buffer_size,
142 bool fill_with_noise) { 147 bool fill_with_noise) {
143 DCHECK(controller.get()); 148 DCHECK(controller.get());
144 const media::AudioParameters& audio_params = controller->audio_parameters(); 149 const media::AudioParameters& audio_params = controller->audio_parameters();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 187 }
183 } 188 }
184 189
185 SpeechRecognitionResult GetGoodSpeechResult() { 190 SpeechRecognitionResult GetGoodSpeechResult() {
186 SpeechRecognitionResult result; 191 SpeechRecognitionResult result;
187 result.hypotheses.push_back(SpeechRecognitionHypothesis( 192 result.hypotheses.push_back(SpeechRecognitionHypothesis(
188 base::UTF8ToUTF16("Pictures of the moon"), 1.0F)); 193 base::UTF8ToUTF16("Pictures of the moon"), 1.0F));
189 return result; 194 return result;
190 } 195 }
191 196
197 media::MockAudioManager::UniquePtr audio_manager_;
198 std::unique_ptr<media::AudioSystem> audio_system_;
192 StreamingServerState streaming_server_state_; 199 StreamingServerState streaming_server_state_;
193 std::unique_ptr<MockGoogleStreamingServer> mock_streaming_server_; 200 std::unique_ptr<MockGoogleStreamingServer> mock_streaming_server_;
194 media::TestAudioInputControllerFactory test_audio_input_controller_factory_; 201 media::TestAudioInputControllerFactory test_audio_input_controller_factory_;
195 }; 202 };
196 203
197 // Simply loads the test page and checks if it was able to create a Speech 204 // Simply loads the test page and checks if it was able to create a Speech
198 // Recognition object in JavaScript, to make sure the Web Speech API is enabled. 205 // Recognition object in JavaScript, to make sure the Web Speech API is enabled.
199 // Flaky on all platforms. http://crbug.com/396414. 206 // Flaky on all platforms. http://crbug.com/396414.
200 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, DISABLED_Precheck) { 207 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, DISABLED_Precheck) {
201 NavigateToURLBlockUntilNavigationsComplete( 208 NavigateToURLBlockUntilNavigationsComplete(
202 shell(), GetTestUrlFromFragment("precheck"), 2); 209 shell(), GetTestUrlFromFragment("precheck"), 2);
203 210
204 EXPECT_EQ(kIdle, streaming_server_state()); 211 EXPECT_EQ(kIdle, streaming_server_state());
205 EXPECT_EQ("success", GetPageFragment()); 212 EXPECT_EQ("success", GetPageFragment());
206 } 213 }
207 214
208 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { 215 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) {
209 NavigateToURLBlockUntilNavigationsComplete( 216 NavigateToURLBlockUntilNavigationsComplete(
210 shell(), GetTestUrlFromFragment("oneshot"), 2); 217 shell(), GetTestUrlFromFragment("oneshot"), 2);
211 218
212 EXPECT_EQ(kClientDisconnected, streaming_server_state()); 219 EXPECT_EQ(kClientDisconnected, streaming_server_state());
213 EXPECT_EQ("goodresult1", GetPageFragment()); 220 EXPECT_EQ("goodresult1", GetPageFragment());
214 } 221 }
215 222
216 } // namespace content 223 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698