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

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

Issue 2690463003: SpeechRecognizerImplTest flakiness fix. (Closed)
Patch Set: procession -> processing. 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 int bytes_per_sample_; 235 int bytes_per_sample_;
236 float volume_; 236 float volume_;
237 float noise_volume_; 237 float noise_volume_;
238 }; 238 };
239 239
240 TEST_F(SpeechRecognizerImplTest, StartNoInputDevices) { 240 TEST_F(SpeechRecognizerImplTest, StartNoInputDevices) {
241 // Check for callbacks when stopping record before any audio gets recorded. 241 // Check for callbacks when stopping record before any audio gets recorded.
242 audio_manager_->SetHasInputDevices(false); 242 audio_manager_->SetHasInputDevices(false);
243 recognizer_->StartRecognition( 243 recognizer_->StartRecognition(
244 media::AudioDeviceDescription::kDefaultDeviceId); 244 media::AudioDeviceDescription::kDefaultDeviceId);
245 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
245 WaitForAudioThreadToPostDeviceInfo(); 246 WaitForAudioThreadToPostDeviceInfo();
246 base::RunLoop().RunUntilIdle(); 247 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
247 EXPECT_TRUE(recognition_started_); 248 EXPECT_TRUE(recognition_started_);
248 EXPECT_FALSE(audio_started_); 249 EXPECT_FALSE(audio_started_);
249 EXPECT_FALSE(result_received_); 250 EXPECT_FALSE(result_received_);
250 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_); 251 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_);
251 CheckFinalEventsConsistency(); 252 CheckFinalEventsConsistency();
252 } 253 }
253 254
254 TEST_F(SpeechRecognizerImplTest, StopBeforeDeviceInfoReceived) { 255 TEST_F(SpeechRecognizerImplTest, StopBeforeDeviceInfoReceived) {
255 // Check for callbacks when stopping record before reply is received from 256 // Check for callbacks when stopping record before reply is received from
256 // AudioSystem. 257 // AudioSystem.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_FALSE(audio_started_); 305 EXPECT_FALSE(audio_started_);
305 EXPECT_FALSE(result_received_); 306 EXPECT_FALSE(result_received_);
306 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); 307 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_);
307 CheckFinalEventsConsistency(); 308 CheckFinalEventsConsistency();
308 } 309 }
309 310
310 TEST_F(SpeechRecognizerImplTest, StopNoData) { 311 TEST_F(SpeechRecognizerImplTest, StopNoData) {
311 // Check for callbacks when stopping record before any audio gets recorded. 312 // Check for callbacks when stopping record before any audio gets recorded.
312 recognizer_->StartRecognition( 313 recognizer_->StartRecognition(
313 media::AudioDeviceDescription::kDefaultDeviceId); 314 media::AudioDeviceDescription::kDefaultDeviceId);
315 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
314 WaitForAudioThreadToPostDeviceInfo(); 316 WaitForAudioThreadToPostDeviceInfo();
315 recognizer_->StopAudioCapture(); 317 recognizer_->StopAudioCapture();
316 base::RunLoop().RunUntilIdle(); 318 base::RunLoop().RunUntilIdle(); // EVENT_START and EVENT_STOP processing.
317 EXPECT_TRUE(recognition_started_); 319 EXPECT_TRUE(recognition_started_);
318 EXPECT_FALSE(audio_started_); 320 EXPECT_FALSE(audio_started_);
319 EXPECT_FALSE(result_received_); 321 EXPECT_FALSE(result_received_);
320 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); 322 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_);
321 CheckFinalEventsConsistency(); 323 CheckFinalEventsConsistency();
322 } 324 }
323 325
324 TEST_F(SpeechRecognizerImplTest, CancelNoData) { 326 TEST_F(SpeechRecognizerImplTest, CancelNoData) {
325 // Check for callbacks when canceling recognition before any audio gets 327 // Check for callbacks when canceling recognition before any audio gets
326 // recorded. 328 // recorded.
327 recognizer_->StartRecognition( 329 recognizer_->StartRecognition(
328 media::AudioDeviceDescription::kDefaultDeviceId); 330 media::AudioDeviceDescription::kDefaultDeviceId);
331 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
329 WaitForAudioThreadToPostDeviceInfo(); 332 WaitForAudioThreadToPostDeviceInfo();
330 recognizer_->AbortRecognition(); 333 recognizer_->AbortRecognition();
331 base::RunLoop().RunUntilIdle(); 334 base::RunLoop().RunUntilIdle(); // EVENT_START and EVENT_ABORT processing.
332 EXPECT_TRUE(recognition_started_); 335 EXPECT_TRUE(recognition_started_);
333 EXPECT_FALSE(audio_started_); 336 EXPECT_FALSE(audio_started_);
334 EXPECT_FALSE(result_received_); 337 EXPECT_FALSE(result_received_);
335 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_); 338 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_);
336 CheckFinalEventsConsistency(); 339 CheckFinalEventsConsistency();
337 } 340 }
338 341
339 TEST_F(SpeechRecognizerImplTest, StopWithData) { 342 TEST_F(SpeechRecognizerImplTest, StopWithData) {
340 // Start recording, give some data and then stop. This should wait for the 343 // Start recording, give some data and then stop. This should wait for the
341 // network callback to arrive before completion. 344 // network callback to arrive before completion.
342 recognizer_->StartRecognition( 345 recognizer_->StartRecognition(
343 media::AudioDeviceDescription::kDefaultDeviceId); 346 media::AudioDeviceDescription::kDefaultDeviceId);
347 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
344 WaitForAudioThreadToPostDeviceInfo(); 348 WaitForAudioThreadToPostDeviceInfo();
345 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
346 TestAudioInputController* controller = 350 TestAudioInputController* controller =
347 audio_input_controller_factory_.controller(); 351 audio_input_controller_factory_.controller();
348 ASSERT_TRUE(controller); 352 ASSERT_TRUE(controller);
349 353
350 // Try sending 5 chunks of mock audio data and verify that each of them 354 // Try sending 5 chunks of mock audio data and verify that each of them
351 // resulted immediately in a packet sent out via the network. This verifies 355 // resulted immediately in a packet sent out via the network. This verifies
352 // that we are streaming out encoded data as chunks without waiting for the 356 // that we are streaming out encoded data as chunks without waiting for the
353 // full recording to complete. 357 // full recording to complete.
354 const size_t kNumChunks = 5; 358 const size_t kNumChunks = 5;
355 for (size_t i = 0; i < kNumChunks; ++i) { 359 for (size_t i = 0; i < kNumChunks; ++i) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 EXPECT_TRUE(recognition_ended_); 401 EXPECT_TRUE(recognition_ended_);
398 EXPECT_TRUE(result_received_); 402 EXPECT_TRUE(result_received_);
399 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); 403 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_);
400 CheckFinalEventsConsistency(); 404 CheckFinalEventsConsistency();
401 } 405 }
402 406
403 TEST_F(SpeechRecognizerImplTest, CancelWithData) { 407 TEST_F(SpeechRecognizerImplTest, CancelWithData) {
404 // Start recording, give some data and then cancel. 408 // Start recording, give some data and then cancel.
405 recognizer_->StartRecognition( 409 recognizer_->StartRecognition(
406 media::AudioDeviceDescription::kDefaultDeviceId); 410 media::AudioDeviceDescription::kDefaultDeviceId);
411 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
407 WaitForAudioThreadToPostDeviceInfo(); 412 WaitForAudioThreadToPostDeviceInfo();
408 base::RunLoop().RunUntilIdle(); 413 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
409 TestAudioInputController* controller = 414 TestAudioInputController* controller =
410 audio_input_controller_factory_.controller(); 415 audio_input_controller_factory_.controller();
411 ASSERT_TRUE(controller); 416 ASSERT_TRUE(controller);
412 OnData(audio_bus_.get()); 417 OnData(audio_bus_.get());
413 base::RunLoop().RunUntilIdle(); 418 base::RunLoop().RunUntilIdle();
414 recognizer_->AbortRecognition(); 419 recognizer_->AbortRecognition();
415 base::RunLoop().RunUntilIdle(); 420 base::RunLoop().RunUntilIdle();
416 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); 421 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0));
417 EXPECT_TRUE(recognition_started_); 422 EXPECT_TRUE(recognition_started_);
418 EXPECT_TRUE(audio_started_); 423 EXPECT_TRUE(audio_started_);
419 EXPECT_FALSE(result_received_); 424 EXPECT_FALSE(result_received_);
420 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_); 425 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_);
421 CheckFinalEventsConsistency(); 426 CheckFinalEventsConsistency();
422 } 427 }
423 428
424 TEST_F(SpeechRecognizerImplTest, ConnectionError) { 429 TEST_F(SpeechRecognizerImplTest, ConnectionError) {
425 // Start recording, give some data and then stop. Issue the network callback 430 // Start recording, give some data and then stop. Issue the network callback
426 // with a connection error and verify that the recognizer bubbles the error up 431 // with a connection error and verify that the recognizer bubbles the error up
427 recognizer_->StartRecognition( 432 recognizer_->StartRecognition(
428 media::AudioDeviceDescription::kDefaultDeviceId); 433 media::AudioDeviceDescription::kDefaultDeviceId);
434 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
429 WaitForAudioThreadToPostDeviceInfo(); 435 WaitForAudioThreadToPostDeviceInfo();
430 base::RunLoop().RunUntilIdle(); 436 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
431 TestAudioInputController* controller = 437 TestAudioInputController* controller =
432 audio_input_controller_factory_.controller(); 438 audio_input_controller_factory_.controller();
433 ASSERT_TRUE(controller); 439 ASSERT_TRUE(controller);
434 OnData(audio_bus_.get()); 440 OnData(audio_bus_.get());
435 base::RunLoop().RunUntilIdle(); 441 base::RunLoop().RunUntilIdle();
436 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 442 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
437 ASSERT_TRUE(fetcher); 443 ASSERT_TRUE(fetcher);
438 444
439 recognizer_->StopAudioCapture(); 445 recognizer_->StopAudioCapture();
440 base::RunLoop().RunUntilIdle(); 446 base::RunLoop().RunUntilIdle();
(...skipping 15 matching lines...) Expand all
456 EXPECT_FALSE(result_received_); 462 EXPECT_FALSE(result_received_);
457 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_); 463 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_);
458 CheckFinalEventsConsistency(); 464 CheckFinalEventsConsistency();
459 } 465 }
460 466
461 TEST_F(SpeechRecognizerImplTest, ServerError) { 467 TEST_F(SpeechRecognizerImplTest, ServerError) {
462 // Start recording, give some data and then stop. Issue the network callback 468 // Start recording, give some data and then stop. Issue the network callback
463 // with a 500 error and verify that the recognizer bubbles the error up 469 // with a 500 error and verify that the recognizer bubbles the error up
464 recognizer_->StartRecognition( 470 recognizer_->StartRecognition(
465 media::AudioDeviceDescription::kDefaultDeviceId); 471 media::AudioDeviceDescription::kDefaultDeviceId);
472 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
466 WaitForAudioThreadToPostDeviceInfo(); 473 WaitForAudioThreadToPostDeviceInfo();
467 base::RunLoop().RunUntilIdle(); 474 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
468 TestAudioInputController* controller = 475 TestAudioInputController* controller =
469 audio_input_controller_factory_.controller(); 476 audio_input_controller_factory_.controller();
470 ASSERT_TRUE(controller); 477 ASSERT_TRUE(controller);
471 OnData(audio_bus_.get()); 478 OnData(audio_bus_.get());
472 base::RunLoop().RunUntilIdle(); 479 base::RunLoop().RunUntilIdle();
473 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 480 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
474 ASSERT_TRUE(fetcher); 481 ASSERT_TRUE(fetcher);
475 482
476 recognizer_->StopAudioCapture(); 483 recognizer_->StopAudioCapture();
477 base::RunLoop().RunUntilIdle(); 484 base::RunLoop().RunUntilIdle();
(...skipping 13 matching lines...) Expand all
491 EXPECT_TRUE(recognition_ended_); 498 EXPECT_TRUE(recognition_ended_);
492 EXPECT_FALSE(result_received_); 499 EXPECT_FALSE(result_received_);
493 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_); 500 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_);
494 CheckFinalEventsConsistency(); 501 CheckFinalEventsConsistency();
495 } 502 }
496 503
497 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorNoData) { 504 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorNoData) {
498 // Check if things tear down properly if AudioInputController threw an error. 505 // Check if things tear down properly if AudioInputController threw an error.
499 recognizer_->StartRecognition( 506 recognizer_->StartRecognition(
500 media::AudioDeviceDescription::kDefaultDeviceId); 507 media::AudioDeviceDescription::kDefaultDeviceId);
508 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
501 WaitForAudioThreadToPostDeviceInfo(); 509 WaitForAudioThreadToPostDeviceInfo();
502 base::RunLoop().RunUntilIdle(); 510 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
503 TestAudioInputController* controller = 511 TestAudioInputController* controller =
504 audio_input_controller_factory_.controller(); 512 audio_input_controller_factory_.controller();
505 ASSERT_TRUE(controller); 513 ASSERT_TRUE(controller);
506 controller->event_handler()->OnError(controller, 514 controller->event_handler()->OnError(controller,
507 AudioInputController::UNKNOWN_ERROR); 515 AudioInputController::UNKNOWN_ERROR);
508 base::RunLoop().RunUntilIdle(); 516 base::RunLoop().RunUntilIdle();
509 EXPECT_TRUE(recognition_started_); 517 EXPECT_TRUE(recognition_started_);
510 EXPECT_FALSE(audio_started_); 518 EXPECT_FALSE(audio_started_);
511 EXPECT_FALSE(result_received_); 519 EXPECT_FALSE(result_received_);
512 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_); 520 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_);
513 CheckFinalEventsConsistency(); 521 CheckFinalEventsConsistency();
514 } 522 }
515 523
516 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorWithData) { 524 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorWithData) {
517 // Check if things tear down properly if AudioInputController threw an error 525 // Check if things tear down properly if AudioInputController threw an error
518 // after giving some audio data. 526 // after giving some audio data.
519 recognizer_->StartRecognition( 527 recognizer_->StartRecognition(
520 media::AudioDeviceDescription::kDefaultDeviceId); 528 media::AudioDeviceDescription::kDefaultDeviceId);
529 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
521 WaitForAudioThreadToPostDeviceInfo(); 530 WaitForAudioThreadToPostDeviceInfo();
522 base::RunLoop().RunUntilIdle(); 531 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
523 TestAudioInputController* controller = 532 TestAudioInputController* controller =
524 audio_input_controller_factory_.controller(); 533 audio_input_controller_factory_.controller();
525 ASSERT_TRUE(controller); 534 ASSERT_TRUE(controller);
526 OnData(audio_bus_.get()); 535 OnData(audio_bus_.get());
527 controller->event_handler()->OnError(controller, 536 controller->event_handler()->OnError(controller,
528 AudioInputController::UNKNOWN_ERROR); 537 AudioInputController::UNKNOWN_ERROR);
529 base::RunLoop().RunUntilIdle(); 538 base::RunLoop().RunUntilIdle();
530 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); 539 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0));
531 EXPECT_TRUE(recognition_started_); 540 EXPECT_TRUE(recognition_started_);
532 EXPECT_TRUE(audio_started_); 541 EXPECT_TRUE(audio_started_);
533 EXPECT_FALSE(result_received_); 542 EXPECT_FALSE(result_received_);
534 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_); 543 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_);
535 CheckFinalEventsConsistency(); 544 CheckFinalEventsConsistency();
536 } 545 }
537 546
538 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackIssued) { 547 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackIssued) {
539 // Start recording and give a lot of packets with audio samples set to zero. 548 // Start recording and give a lot of packets with audio samples set to zero.
540 // This should trigger the no-speech detector and issue a callback. 549 // This should trigger the no-speech detector and issue a callback.
541 recognizer_->StartRecognition( 550 recognizer_->StartRecognition(
542 media::AudioDeviceDescription::kDefaultDeviceId); 551 media::AudioDeviceDescription::kDefaultDeviceId);
552 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
543 WaitForAudioThreadToPostDeviceInfo(); 553 WaitForAudioThreadToPostDeviceInfo();
544 base::RunLoop().RunUntilIdle(); 554 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
545 TestAudioInputController* controller = 555 TestAudioInputController* controller =
546 audio_input_controller_factory_.controller(); 556 audio_input_controller_factory_.controller();
547 ASSERT_TRUE(controller); 557 ASSERT_TRUE(controller);
548 558
549 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / 559 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) /
550 SpeechRecognitionEngine::kAudioPacketIntervalMs + 1; 560 SpeechRecognitionEngine::kAudioPacketIntervalMs + 1;
551 // The vector is already filled with zero value samples on create. 561 // The vector is already filled with zero value samples on create.
552 for (int i = 0; i < num_packets; ++i) { 562 for (int i = 0; i < num_packets; ++i) {
553 OnData(audio_bus_.get()); 563 OnData(audio_bus_.get());
554 } 564 }
555 base::RunLoop().RunUntilIdle(); 565 base::RunLoop().RunUntilIdle();
556 EXPECT_TRUE(recognition_started_); 566 EXPECT_TRUE(recognition_started_);
557 EXPECT_TRUE(audio_started_); 567 EXPECT_TRUE(audio_started_);
558 EXPECT_FALSE(result_received_); 568 EXPECT_FALSE(result_received_);
559 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_); 569 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_);
560 CheckFinalEventsConsistency(); 570 CheckFinalEventsConsistency();
561 } 571 }
562 572
563 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackNotIssued) { 573 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackNotIssued) {
564 // Start recording and give a lot of packets with audio samples set to zero 574 // Start recording and give a lot of packets with audio samples set to zero
565 // and then some more with reasonably loud audio samples. This should be 575 // and then some more with reasonably loud audio samples. This should be
566 // treated as normal speech input and the no-speech detector should not get 576 // treated as normal speech input and the no-speech detector should not get
567 // triggered. 577 // triggered.
568 recognizer_->StartRecognition( 578 recognizer_->StartRecognition(
569 media::AudioDeviceDescription::kDefaultDeviceId); 579 media::AudioDeviceDescription::kDefaultDeviceId);
580 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
570 WaitForAudioThreadToPostDeviceInfo(); 581 WaitForAudioThreadToPostDeviceInfo();
571 base::RunLoop().RunUntilIdle(); 582 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
572 TestAudioInputController* controller = 583 TestAudioInputController* controller =
573 audio_input_controller_factory_.controller(); 584 audio_input_controller_factory_.controller();
574 ASSERT_TRUE(controller); 585 ASSERT_TRUE(controller);
575 controller = audio_input_controller_factory_.controller(); 586 controller = audio_input_controller_factory_.controller();
576 ASSERT_TRUE(controller); 587 ASSERT_TRUE(controller);
577 588
578 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / 589 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) /
579 SpeechRecognitionEngine::kAudioPacketIntervalMs; 590 SpeechRecognitionEngine::kAudioPacketIntervalMs;
580 591
581 // The vector is already filled with zero value samples on create. 592 // The vector is already filled with zero value samples on create.
(...skipping 16 matching lines...) Expand all
598 CheckFinalEventsConsistency(); 609 CheckFinalEventsConsistency();
599 } 610 }
600 611
601 TEST_F(SpeechRecognizerImplTest, SetInputVolumeCallback) { 612 TEST_F(SpeechRecognizerImplTest, SetInputVolumeCallback) {
602 // Start recording and give a lot of packets with audio samples set to zero 613 // Start recording and give a lot of packets with audio samples set to zero
603 // and then some more with reasonably loud audio samples. Check that we don't 614 // and then some more with reasonably loud audio samples. Check that we don't
604 // get the callback during estimation phase, then get zero for the silence 615 // get the callback during estimation phase, then get zero for the silence
605 // samples and proper volume for the loud audio. 616 // samples and proper volume for the loud audio.
606 recognizer_->StartRecognition( 617 recognizer_->StartRecognition(
607 media::AudioDeviceDescription::kDefaultDeviceId); 618 media::AudioDeviceDescription::kDefaultDeviceId);
619 base::RunLoop().RunUntilIdle(); // EVENT_PREPARE processing.
608 WaitForAudioThreadToPostDeviceInfo(); 620 WaitForAudioThreadToPostDeviceInfo();
609 base::RunLoop().RunUntilIdle(); 621 base::RunLoop().RunUntilIdle(); // EVENT_START processing.
610 TestAudioInputController* controller = 622 TestAudioInputController* controller =
611 audio_input_controller_factory_.controller(); 623 audio_input_controller_factory_.controller();
612 ASSERT_TRUE(controller); 624 ASSERT_TRUE(controller);
613 controller = audio_input_controller_factory_.controller(); 625 controller = audio_input_controller_factory_.controller();
614 ASSERT_TRUE(controller); 626 ASSERT_TRUE(controller);
615 627
616 // Feed some samples to begin with for the endpointer to do noise estimation. 628 // Feed some samples to begin with for the endpointer to do noise estimation.
617 int num_packets = SpeechRecognizerImpl::kEndpointerEstimationTimeMs / 629 int num_packets = SpeechRecognizerImpl::kEndpointerEstimationTimeMs /
618 SpeechRecognitionEngine::kAudioPacketIntervalMs; 630 SpeechRecognitionEngine::kAudioPacketIntervalMs;
619 FillPacketWithNoise(); 631 FillPacketWithNoise();
(...skipping 16 matching lines...) Expand all
636 648
637 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); 649 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_);
638 EXPECT_FALSE(audio_ended_); 650 EXPECT_FALSE(audio_ended_);
639 EXPECT_FALSE(recognition_ended_); 651 EXPECT_FALSE(recognition_ended_);
640 recognizer_->AbortRecognition(); 652 recognizer_->AbortRecognition();
641 base::RunLoop().RunUntilIdle(); 653 base::RunLoop().RunUntilIdle();
642 CheckFinalEventsConsistency(); 654 CheckFinalEventsConsistency();
643 } 655 }
644 656
645 } // namespace content 657 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698