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

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

Issue 10581012: Move test_url_fetcher_factory.* from content/ to net/url_request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove export annotations Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/speech/google_one_shot_remote_engine.h" 8 #include "content/browser/speech/google_one_shot_remote_engine.h"
9 #include "content/browser/speech/speech_recognizer_impl.h" 9 #include "content/browser/speech/speech_recognizer_impl.h"
10 #include "content/public/browser/speech_recognition_event_listener.h" 10 #include "content/public/browser/speech_recognition_event_listener.h"
11 #include "content/public/test/test_url_fetcher_factory.h"
12 #include "media/audio/audio_manager.h" 11 #include "media/audio/audio_manager.h"
13 #include "media/audio/fake_audio_input_stream.h" 12 #include "media/audio/fake_audio_input_stream.h"
14 #include "media/audio/fake_audio_output_stream.h" 13 #include "media/audio/fake_audio_output_stream.h"
15 #include "media/audio/test_audio_input_controller_factory.h" 14 #include "media/audio/test_audio_input_controller_factory.h"
16 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/url_request/test_url_fetcher_factory.h"
17 #include "net/url_request/url_request_status.h" 17 #include "net/url_request/url_request_status.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using base::MessageLoopProxy; 20 using base::MessageLoopProxy;
21 using content::BrowserThread; 21 using content::BrowserThread;
22 using content::BrowserThreadImpl; 22 using content::BrowserThreadImpl;
23 using media::AudioInputController; 23 using media::AudioInputController;
24 using media::AudioInputStream; 24 using media::AudioInputStream;
25 using media::AudioManager; 25 using media::AudioManager;
26 using media::AudioOutputStream; 26 using media::AudioOutputStream;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 scoped_refptr<SpeechRecognizerImpl> recognizer_; 228 scoped_refptr<SpeechRecognizerImpl> recognizer_;
229 scoped_ptr<AudioManager> audio_manager_; 229 scoped_ptr<AudioManager> audio_manager_;
230 bool recognition_started_; 230 bool recognition_started_;
231 bool recognition_ended_; 231 bool recognition_ended_;
232 bool result_received_; 232 bool result_received_;
233 bool audio_started_; 233 bool audio_started_;
234 bool audio_ended_; 234 bool audio_ended_;
235 bool sound_started_; 235 bool sound_started_;
236 bool sound_ended_; 236 bool sound_ended_;
237 content::SpeechRecognitionErrorCode error_; 237 content::SpeechRecognitionErrorCode error_;
238 TestURLFetcherFactory url_fetcher_factory_; 238 net::TestURLFetcherFactory url_fetcher_factory_;
239 TestAudioInputControllerFactory audio_input_controller_factory_; 239 TestAudioInputControllerFactory audio_input_controller_factory_;
240 std::vector<uint8> audio_packet_; 240 std::vector<uint8> audio_packet_;
241 float volume_; 241 float volume_;
242 float noise_volume_; 242 float noise_volume_;
243 }; 243 };
244 244
245 TEST_F(SpeechRecognizerImplTest, StopNoData) { 245 TEST_F(SpeechRecognizerImplTest, StopNoData) {
246 // Check for callbacks when stopping record before any audio gets recorded. 246 // Check for callbacks when stopping record before any audio gets recorded.
247 recognizer_->StartRecognition(); 247 recognizer_->StartRecognition();
248 recognizer_->StopAudioCapture(); 248 recognizer_->StopAudioCapture();
(...skipping 29 matching lines...) Expand all
278 278
279 // Try sending 5 chunks of mock audio data and verify that each of them 279 // Try sending 5 chunks of mock audio data and verify that each of them
280 // resulted immediately in a packet sent out via the network. This verifies 280 // resulted immediately in a packet sent out via the network. This verifies
281 // that we are streaming out encoded data as chunks without waiting for the 281 // that we are streaming out encoded data as chunks without waiting for the
282 // full recording to complete. 282 // full recording to complete.
283 const size_t kNumChunks = 5; 283 const size_t kNumChunks = 5;
284 for (size_t i = 0; i < kNumChunks; ++i) { 284 for (size_t i = 0; i < kNumChunks; ++i) {
285 controller->event_handler()->OnData(controller, &audio_packet_[0], 285 controller->event_handler()->OnData(controller, &audio_packet_[0],
286 audio_packet_.size()); 286 audio_packet_.size());
287 MessageLoop::current()->RunAllPending(); 287 MessageLoop::current()->RunAllPending();
288 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 288 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
289 ASSERT_TRUE(fetcher); 289 ASSERT_TRUE(fetcher);
290 EXPECT_EQ(i + 1, fetcher->upload_chunks().size()); 290 EXPECT_EQ(i + 1, fetcher->upload_chunks().size());
291 } 291 }
292 292
293 recognizer_->StopAudioCapture(); 293 recognizer_->StopAudioCapture();
294 MessageLoop::current()->RunAllPending(); 294 MessageLoop::current()->RunAllPending();
295 EXPECT_TRUE(audio_started_); 295 EXPECT_TRUE(audio_started_);
296 EXPECT_TRUE(audio_ended_); 296 EXPECT_TRUE(audio_ended_);
297 EXPECT_FALSE(recognition_ended_); 297 EXPECT_FALSE(recognition_ended_);
298 EXPECT_FALSE(result_received_); 298 EXPECT_FALSE(result_received_);
299 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); 299 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_);
300 300
301 // Issue the network callback to complete the process. 301 // Issue the network callback to complete the process.
302 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 302 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
303 ASSERT_TRUE(fetcher); 303 ASSERT_TRUE(fetcher);
304 304
305 fetcher->set_url(fetcher->GetOriginalURL()); 305 fetcher->set_url(fetcher->GetOriginalURL());
306 net::URLRequestStatus status; 306 net::URLRequestStatus status;
307 status.set_status(net::URLRequestStatus::SUCCESS); 307 status.set_status(net::URLRequestStatus::SUCCESS);
308 fetcher->set_status(status); 308 fetcher->set_status(status);
309 fetcher->set_response_code(200); 309 fetcher->set_response_code(200);
310 fetcher->SetResponseString( 310 fetcher->SetResponseString(
311 "{\"status\":0,\"hypotheses\":[{\"utterance\":\"123\"}]}"); 311 "{\"status\":0,\"hypotheses\":[{\"utterance\":\"123\"}]}");
312 fetcher->delegate()->OnURLFetchComplete(fetcher); 312 fetcher->delegate()->OnURLFetchComplete(fetcher);
(...skipping 28 matching lines...) Expand all
341 // Start recording, give some data and then stop. Issue the network callback 341 // Start recording, give some data and then stop. Issue the network callback
342 // with a connection error and verify that the recognizer bubbles the error up 342 // with a connection error and verify that the recognizer bubbles the error up
343 recognizer_->StartRecognition(); 343 recognizer_->StartRecognition();
344 MessageLoop::current()->RunAllPending(); 344 MessageLoop::current()->RunAllPending();
345 TestAudioInputController* controller = 345 TestAudioInputController* controller =
346 audio_input_controller_factory_.controller(); 346 audio_input_controller_factory_.controller();
347 ASSERT_TRUE(controller); 347 ASSERT_TRUE(controller);
348 controller->event_handler()->OnData(controller, &audio_packet_[0], 348 controller->event_handler()->OnData(controller, &audio_packet_[0],
349 audio_packet_.size()); 349 audio_packet_.size());
350 MessageLoop::current()->RunAllPending(); 350 MessageLoop::current()->RunAllPending();
351 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 351 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
352 ASSERT_TRUE(fetcher); 352 ASSERT_TRUE(fetcher);
353 353
354 recognizer_->StopAudioCapture(); 354 recognizer_->StopAudioCapture();
355 MessageLoop::current()->RunAllPending(); 355 MessageLoop::current()->RunAllPending();
356 EXPECT_TRUE(audio_started_); 356 EXPECT_TRUE(audio_started_);
357 EXPECT_TRUE(audio_ended_); 357 EXPECT_TRUE(audio_ended_);
358 EXPECT_FALSE(recognition_ended_); 358 EXPECT_FALSE(recognition_ended_);
359 EXPECT_FALSE(result_received_); 359 EXPECT_FALSE(result_received_);
360 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); 360 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_);
361 361
(...skipping 17 matching lines...) Expand all
379 // Start recording, give some data and then stop. Issue the network callback 379 // Start recording, give some data and then stop. Issue the network callback
380 // with a 500 error and verify that the recognizer bubbles the error up 380 // with a 500 error and verify that the recognizer bubbles the error up
381 recognizer_->StartRecognition(); 381 recognizer_->StartRecognition();
382 MessageLoop::current()->RunAllPending(); 382 MessageLoop::current()->RunAllPending();
383 TestAudioInputController* controller = 383 TestAudioInputController* controller =
384 audio_input_controller_factory_.controller(); 384 audio_input_controller_factory_.controller();
385 ASSERT_TRUE(controller); 385 ASSERT_TRUE(controller);
386 controller->event_handler()->OnData(controller, &audio_packet_[0], 386 controller->event_handler()->OnData(controller, &audio_packet_[0],
387 audio_packet_.size()); 387 audio_packet_.size());
388 MessageLoop::current()->RunAllPending(); 388 MessageLoop::current()->RunAllPending();
389 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 389 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
390 ASSERT_TRUE(fetcher); 390 ASSERT_TRUE(fetcher);
391 391
392 recognizer_->StopAudioCapture(); 392 recognizer_->StopAudioCapture();
393 MessageLoop::current()->RunAllPending(); 393 MessageLoop::current()->RunAllPending();
394 EXPECT_TRUE(audio_started_); 394 EXPECT_TRUE(audio_started_);
395 EXPECT_TRUE(audio_ended_); 395 EXPECT_TRUE(audio_ended_);
396 EXPECT_FALSE(recognition_ended_); 396 EXPECT_FALSE(recognition_ended_);
397 EXPECT_FALSE(result_received_); 397 EXPECT_FALSE(result_received_);
398 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); 398 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_);
399 399
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 549
550 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); 550 EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_);
551 EXPECT_FALSE(audio_ended_); 551 EXPECT_FALSE(audio_ended_);
552 EXPECT_FALSE(recognition_ended_); 552 EXPECT_FALSE(recognition_ended_);
553 recognizer_->AbortRecognition(); 553 recognizer_->AbortRecognition();
554 MessageLoop::current()->RunAllPending(); 554 MessageLoop::current()->RunAllPending();
555 CheckFinalEventsConsistency(); 555 CheckFinalEventsConsistency();
556 } 556 }
557 557
558 } // namespace speech 558 } // namespace speech
OLDNEW
« no previous file with comments | « content/browser/speech/google_one_shot_remote_engine_unittest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698