| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_thread.h" | 7 #include "chrome/browser/chrome_thread.h" |
| 8 #include "chrome/browser/speech/speech_recognizer.h" | 8 #include "chrome/browser/speech/speech_recognizer.h" |
| 9 #include "chrome/common/net/test_url_fetcher_factory.h" | 9 #include "chrome/common/net/test_url_fetcher_factory.h" |
| 10 #include "media/audio/test_audio_input_controller_factory.h" | 10 #include "media/audio/test_audio_input_controller_factory.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 162 } |
| 163 | 163 |
| 164 TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { | 164 TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { |
| 165 // Check if things tear down properly if AudioInputController threw an error. | 165 // Check if things tear down properly if AudioInputController threw an error. |
| 166 EXPECT_TRUE(recognizer_->StartRecording()); | 166 EXPECT_TRUE(recognizer_->StartRecording()); |
| 167 TestAudioInputController* controller = | 167 TestAudioInputController* controller = |
| 168 audio_input_controller_factory_.controller(); | 168 audio_input_controller_factory_.controller(); |
| 169 ASSERT_TRUE(controller); | 169 ASSERT_TRUE(controller); |
| 170 controller->event_handler()->OnError(controller, 0); | 170 controller->event_handler()->OnError(controller, 0); |
| 171 MessageLoop::current()->RunAllPending(); | 171 MessageLoop::current()->RunAllPending(); |
| 172 EXPECT_TRUE(recording_complete_); | 172 EXPECT_FALSE(recording_complete_); |
| 173 EXPECT_TRUE(recognition_complete_); | 173 EXPECT_FALSE(recognition_complete_); |
| 174 EXPECT_FALSE(result_received_); | 174 EXPECT_FALSE(result_received_); |
| 175 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE, error_); | 175 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE, error_); |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { | 178 TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { |
| 179 // Check if things tear down properly if AudioInputController threw an error | 179 // Check if things tear down properly if AudioInputController threw an error |
| 180 // after giving some audio data. | 180 // after giving some audio data. |
| 181 EXPECT_TRUE(recognizer_->StartRecording()); | 181 EXPECT_TRUE(recognizer_->StartRecording()); |
| 182 TestAudioInputController* controller = | 182 TestAudioInputController* controller = |
| 183 audio_input_controller_factory_.controller(); | 183 audio_input_controller_factory_.controller(); |
| 184 ASSERT_TRUE(controller); | 184 ASSERT_TRUE(controller); |
| 185 controller->event_handler()->OnData(controller, &audio_packet_[0], | 185 controller->event_handler()->OnData(controller, &audio_packet_[0], |
| 186 audio_packet_.size()); | 186 audio_packet_.size()); |
| 187 controller->event_handler()->OnError(controller, 0); | 187 controller->event_handler()->OnError(controller, 0); |
| 188 MessageLoop::current()->RunAllPending(); | 188 MessageLoop::current()->RunAllPending(); |
| 189 EXPECT_EQ(NULL, url_fetcher_factory_.GetFetcherByID(0)); | 189 EXPECT_EQ(NULL, url_fetcher_factory_.GetFetcherByID(0)); |
| 190 EXPECT_TRUE(recording_complete_); | 190 EXPECT_FALSE(recording_complete_); |
| 191 EXPECT_TRUE(recognition_complete_); | 191 EXPECT_FALSE(recognition_complete_); |
| 192 EXPECT_FALSE(result_received_); | 192 EXPECT_FALSE(result_received_); |
| 193 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE, error_); | 193 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE, error_); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { | 196 TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { |
| 197 // Start recording and give a lot of packets with audio samples set to zero. | 197 // Start recording and give a lot of packets with audio samples set to zero. |
| 198 // This should trigger the no-speech detector and issue a callback. | 198 // This should trigger the no-speech detector and issue a callback. |
| 199 EXPECT_TRUE(recognizer_->StartRecording()); | 199 EXPECT_TRUE(recognizer_->StartRecording()); |
| 200 TestAudioInputController* controller = | 200 TestAudioInputController* controller = |
| 201 audio_input_controller_factory_.controller(); | 201 audio_input_controller_factory_.controller(); |
| 202 ASSERT_TRUE(controller); | 202 ASSERT_TRUE(controller); |
| 203 controller = audio_input_controller_factory_.controller(); | 203 controller = audio_input_controller_factory_.controller(); |
| 204 ASSERT_TRUE(controller); | 204 ASSERT_TRUE(controller); |
| 205 | 205 |
| 206 int num_packets = (SpeechRecognizer::kNoSpeechTimeoutSec * 1000) / | 206 int num_packets = (SpeechRecognizer::kNoSpeechTimeoutSec * 1000) / |
| 207 SpeechRecognizer::kAudioPacketIntervalMs; | 207 SpeechRecognizer::kAudioPacketIntervalMs; |
| 208 // The vector is already filled with zero value samples on create. | 208 // The vector is already filled with zero value samples on create. |
| 209 for (int i = 0; i < num_packets; ++i) { | 209 for (int i = 0; i < num_packets; ++i) { |
| 210 controller->event_handler()->OnData(controller, &audio_packet_[0], | 210 controller->event_handler()->OnData(controller, &audio_packet_[0], |
| 211 audio_packet_.size()); | 211 audio_packet_.size()); |
| 212 } | 212 } |
| 213 MessageLoop::current()->RunAllPending(); | 213 MessageLoop::current()->RunAllPending(); |
| 214 EXPECT_TRUE(recording_complete_); | 214 EXPECT_FALSE(recording_complete_); |
| 215 EXPECT_TRUE(recognition_complete_); | 215 EXPECT_FALSE(recognition_complete_); |
| 216 EXPECT_FALSE(result_received_); | 216 EXPECT_FALSE(result_received_); |
| 217 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NO_SPEECH, error_); | 217 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NO_SPEECH, error_); |
| 218 } | 218 } |
| 219 | 219 |
| 220 TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { | 220 TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { |
| 221 // Start recording and give a lot of packets with audio samples set to zero | 221 // Start recording and give a lot of packets with audio samples set to zero |
| 222 // and then some more with reasonably loud audio samples. This should be | 222 // and then some more with reasonably loud audio samples. This should be |
| 223 // treated as normal speech input and the no-speech detector should not get | 223 // treated as normal speech input and the no-speech detector should not get |
| 224 // triggered. | 224 // triggered. |
| 225 EXPECT_TRUE(recognizer_->StartRecording()); | 225 EXPECT_TRUE(recognizer_->StartRecording()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 246 } | 246 } |
| 247 | 247 |
| 248 MessageLoop::current()->RunAllPending(); | 248 MessageLoop::current()->RunAllPending(); |
| 249 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); | 249 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); |
| 250 EXPECT_FALSE(recording_complete_); | 250 EXPECT_FALSE(recording_complete_); |
| 251 EXPECT_FALSE(recognition_complete_); | 251 EXPECT_FALSE(recognition_complete_); |
| 252 recognizer_->CancelRecognition(); | 252 recognizer_->CancelRecognition(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace speech_input | 255 } // namespace speech_input |
| OLD | NEW |