| 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/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 const int channels = | 84 const int channels = |
| 85 ChannelLayoutToChannelCount(SpeechRecognizerImpl::kChannelLayout); | 85 ChannelLayoutToChannelCount(SpeechRecognizerImpl::kChannelLayout); |
| 86 bytes_per_sample_ = SpeechRecognizerImpl::kNumBitsPerAudioSample / 8; | 86 bytes_per_sample_ = SpeechRecognizerImpl::kNumBitsPerAudioSample / 8; |
| 87 const int frames = audio_packet_length_bytes / channels / bytes_per_sample_; | 87 const int frames = audio_packet_length_bytes / channels / bytes_per_sample_; |
| 88 audio_bus_ = media::AudioBus::Create(channels, frames); | 88 audio_bus_ = media::AudioBus::Create(channels, frames); |
| 89 audio_bus_->Zero(); | 89 audio_bus_->Zero(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ~SpeechRecognizerImplTest() override { | 92 ~SpeechRecognizerImplTest() override { |
| 93 // Deleting |audio_manager_| on audio thread. | 93 // Deleting |audio_manager_| on audio thread. |
| 94 audio_system_.reset(); |
| 94 audio_manager_.reset(); | 95 audio_manager_.reset(); |
| 95 audio_thread_.Stop(); | 96 audio_thread_.Stop(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void CheckEventsConsistency() { | 99 void CheckEventsConsistency() { |
| 99 // Note: "!x || y" == "x implies y". | 100 // Note: "!x || y" == "x implies y". |
| 100 EXPECT_TRUE(!recognition_ended_ || recognition_started_); | 101 EXPECT_TRUE(!recognition_ended_ || recognition_started_); |
| 101 EXPECT_TRUE(!audio_ended_ || audio_started_); | 102 EXPECT_TRUE(!audio_ended_ || audio_started_); |
| 102 EXPECT_TRUE(!sound_ended_ || sound_started_); | 103 EXPECT_TRUE(!sound_ended_ || sound_started_); |
| 103 EXPECT_TRUE(!audio_started_ || recognition_started_); | 104 EXPECT_TRUE(!audio_started_ || recognition_started_); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // which means AudioSystem reply containing device parameters is already | 213 // which means AudioSystem reply containing device parameters is already |
| 213 // queued on the main thread. | 214 // queued on the main thread. |
| 214 event.RunAndWait(); | 215 event.RunAndWait(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 protected: | 218 protected: |
| 218 TestBrowserThreadBundle thread_bundle_; | 219 TestBrowserThreadBundle thread_bundle_; |
| 219 scoped_refptr<SpeechRecognizerImpl> recognizer_; | 220 scoped_refptr<SpeechRecognizerImpl> recognizer_; |
| 220 base::Thread audio_thread_; | 221 base::Thread audio_thread_; |
| 221 media::MockAudioManager::UniquePtr audio_manager_; | 222 media::MockAudioManager::UniquePtr audio_manager_; |
| 222 std::unique_ptr<media::AudioSystem> audio_system_; | 223 media::AudioSystem::UniquePtr audio_system_; |
| 223 bool recognition_started_; | 224 bool recognition_started_; |
| 224 bool recognition_ended_; | 225 bool recognition_ended_; |
| 225 bool result_received_; | 226 bool result_received_; |
| 226 bool audio_started_; | 227 bool audio_started_; |
| 227 bool audio_ended_; | 228 bool audio_ended_; |
| 228 bool sound_started_; | 229 bool sound_started_; |
| 229 bool sound_ended_; | 230 bool sound_ended_; |
| 230 SpeechRecognitionErrorCode error_; | 231 SpeechRecognitionErrorCode error_; |
| 231 net::TestURLFetcherFactory url_fetcher_factory_; | 232 net::TestURLFetcherFactory url_fetcher_factory_; |
| 232 TestAudioInputControllerFactory audio_input_controller_factory_; | 233 TestAudioInputControllerFactory audio_input_controller_factory_; |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 649 |
| 649 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 650 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
| 650 EXPECT_FALSE(audio_ended_); | 651 EXPECT_FALSE(audio_ended_); |
| 651 EXPECT_FALSE(recognition_ended_); | 652 EXPECT_FALSE(recognition_ended_); |
| 652 recognizer_->AbortRecognition(); | 653 recognizer_->AbortRecognition(); |
| 653 base::RunLoop().RunUntilIdle(); | 654 base::RunLoop().RunUntilIdle(); |
| 654 CheckFinalEventsConsistency(); | 655 CheckFinalEventsConsistency(); |
| 655 } | 656 } |
| 656 | 657 |
| 657 } // namespace content | 658 } // namespace content |
| OLD | NEW |