OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
| 11 #include "content/browser/browser_thread_impl.h" |
11 #include "content/browser/speech/proto/google_streaming_api.pb.h" | 12 #include "content/browser/speech/proto/google_streaming_api.pb.h" |
12 #include "content/browser/speech/speech_recognition_engine.h" | 13 #include "content/browser/speech/speech_recognition_engine.h" |
13 #include "content/browser/speech/speech_recognizer_impl.h" | 14 #include "content/browser/speech/speech_recognizer_impl.h" |
14 #include "content/public/browser/speech_recognition_event_listener.h" | 15 #include "content/public/browser/speech_recognition_event_listener.h" |
15 #include "content/public/test/test_browser_thread_bundle.h" | |
16 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_manager_base.h" |
17 #include "media/audio/fake_audio_input_stream.h" | 17 #include "media/audio/fake_audio_input_stream.h" |
18 #include "media/audio/fake_audio_output_stream.h" | 18 #include "media/audio/fake_audio_output_stream.h" |
19 #include "media/audio/mock_audio_manager.h" | 19 #include "media/audio/mock_audio_manager.h" |
20 #include "media/audio/test_audio_input_controller_factory.h" | 20 #include "media/audio/test_audio_input_controller_factory.h" |
21 #include "media/base/audio_bus.h" | 21 #include "media/base/audio_bus.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/url_request/test_url_fetcher_factory.h" | 23 #include "net/url_request/test_url_fetcher_factory.h" |
24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 using media::AudioInputController; | 27 using media::AudioInputController; |
28 using media::AudioInputStream; | 28 using media::AudioInputStream; |
| 29 using media::AudioManager; |
29 using media::AudioOutputStream; | 30 using media::AudioOutputStream; |
30 using media::AudioParameters; | 31 using media::AudioParameters; |
31 using media::TestAudioInputController; | 32 using media::TestAudioInputController; |
32 using media::TestAudioInputControllerFactory; | 33 using media::TestAudioInputControllerFactory; |
33 | 34 |
34 namespace content { | 35 namespace content { |
35 | 36 |
36 class SpeechRecognizerImplTest : public SpeechRecognitionEventListener, | 37 class SpeechRecognizerImplTest : public SpeechRecognitionEventListener, |
37 public testing::Test { | 38 public testing::Test { |
38 public: | 39 public: |
39 SpeechRecognizerImplTest() | 40 SpeechRecognizerImplTest() |
40 : recognition_started_(false), | 41 : io_thread_(BrowserThread::IO, &message_loop_), |
| 42 recognition_started_(false), |
41 recognition_ended_(false), | 43 recognition_ended_(false), |
42 result_received_(false), | 44 result_received_(false), |
43 audio_started_(false), | 45 audio_started_(false), |
44 audio_ended_(false), | 46 audio_ended_(false), |
45 sound_started_(false), | 47 sound_started_(false), |
46 sound_ended_(false), | 48 sound_ended_(false), |
47 error_(SPEECH_RECOGNITION_ERROR_NONE), | 49 error_(SPEECH_RECOGNITION_ERROR_NONE), |
48 volume_(-1.0f) { | 50 volume_(-1.0f) { |
49 // SpeechRecognizer takes ownership of sr_engine. | 51 // SpeechRecognizer takes ownership of sr_engine. |
50 SpeechRecognitionEngine* sr_engine = | 52 SpeechRecognitionEngine* sr_engine = |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 int value = 0; | 177 int value = 0; |
176 int factor = 175; | 178 int factor = 175; |
177 for (size_t i = 0; i < audio_packet_.size(); ++i) { | 179 for (size_t i = 0; i < audio_packet_.size(); ++i) { |
178 value += factor; | 180 value += factor; |
179 audio_packet_[i] = value % 100; | 181 audio_packet_[i] = value % 100; |
180 } | 182 } |
181 CopyPacketToAudioBus(); | 183 CopyPacketToAudioBus(); |
182 } | 184 } |
183 | 185 |
184 protected: | 186 protected: |
185 TestBrowserThreadBundle thread_bundle_; | 187 base::MessageLoopForIO message_loop_; |
| 188 BrowserThreadImpl io_thread_; |
186 scoped_refptr<SpeechRecognizerImpl> recognizer_; | 189 scoped_refptr<SpeechRecognizerImpl> recognizer_; |
187 media::ScopedAudioManagerPtr audio_manager_; | 190 std::unique_ptr<AudioManager> audio_manager_; |
188 bool recognition_started_; | 191 bool recognition_started_; |
189 bool recognition_ended_; | 192 bool recognition_ended_; |
190 bool result_received_; | 193 bool result_received_; |
191 bool audio_started_; | 194 bool audio_started_; |
192 bool audio_ended_; | 195 bool audio_ended_; |
193 bool sound_started_; | 196 bool sound_started_; |
194 bool sound_ended_; | 197 bool sound_ended_; |
195 SpeechRecognitionErrorCode error_; | 198 SpeechRecognitionErrorCode error_; |
196 net::TestURLFetcherFactory url_fetcher_factory_; | 199 net::TestURLFetcherFactory url_fetcher_factory_; |
197 TestAudioInputControllerFactory audio_input_controller_factory_; | 200 TestAudioInputControllerFactory audio_input_controller_factory_; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 512 |
510 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 513 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
511 EXPECT_FALSE(audio_ended_); | 514 EXPECT_FALSE(audio_ended_); |
512 EXPECT_FALSE(recognition_ended_); | 515 EXPECT_FALSE(recognition_ended_); |
513 recognizer_->AbortRecognition(); | 516 recognizer_->AbortRecognition(); |
514 base::MessageLoop::current()->RunUntilIdle(); | 517 base::MessageLoop::current()->RunUntilIdle(); |
515 CheckFinalEventsConsistency(); | 518 CheckFinalEventsConsistency(); |
516 } | 519 } |
517 | 520 |
518 } // namespace content | 521 } // namespace content |
OLD | NEW |