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