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 <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" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 void CheckFinalEventsConsistency() { | 90 void CheckFinalEventsConsistency() { |
91 // Note: "!(x ^ y)" == "(x && y) || (!x && !x)". | 91 // Note: "!(x ^ y)" == "(x && y) || (!x && !x)". |
92 EXPECT_FALSE(recognition_started_ ^ recognition_ended_); | 92 EXPECT_FALSE(recognition_started_ ^ recognition_ended_); |
93 EXPECT_FALSE(audio_started_ ^ audio_ended_); | 93 EXPECT_FALSE(audio_started_ ^ audio_ended_); |
94 EXPECT_FALSE(sound_started_ ^ sound_ended_); | 94 EXPECT_FALSE(sound_started_ ^ sound_ended_); |
95 } | 95 } |
96 | 96 |
97 // Overridden from SpeechRecognitionEventListener: | 97 // Overridden from SpeechRecognitionEventListener: |
98 virtual void OnAudioStart(int session_id) OVERRIDE { | 98 virtual void OnAudioStart(int session_id) override { |
99 audio_started_ = true; | 99 audio_started_ = true; |
100 CheckEventsConsistency(); | 100 CheckEventsConsistency(); |
101 } | 101 } |
102 | 102 |
103 virtual void OnAudioEnd(int session_id) OVERRIDE { | 103 virtual void OnAudioEnd(int session_id) override { |
104 audio_ended_ = true; | 104 audio_ended_ = true; |
105 CheckEventsConsistency(); | 105 CheckEventsConsistency(); |
106 } | 106 } |
107 | 107 |
108 virtual void OnRecognitionResults( | 108 virtual void OnRecognitionResults( |
109 int session_id, const SpeechRecognitionResults& results) OVERRIDE { | 109 int session_id, const SpeechRecognitionResults& results) override { |
110 result_received_ = true; | 110 result_received_ = true; |
111 } | 111 } |
112 | 112 |
113 virtual void OnRecognitionError( | 113 virtual void OnRecognitionError( |
114 int session_id, const SpeechRecognitionError& error) OVERRIDE { | 114 int session_id, const SpeechRecognitionError& error) override { |
115 EXPECT_TRUE(recognition_started_); | 115 EXPECT_TRUE(recognition_started_); |
116 EXPECT_FALSE(recognition_ended_); | 116 EXPECT_FALSE(recognition_ended_); |
117 error_ = error.code; | 117 error_ = error.code; |
118 } | 118 } |
119 | 119 |
120 virtual void OnAudioLevelsChange(int session_id, float volume, | 120 virtual void OnAudioLevelsChange(int session_id, float volume, |
121 float noise_volume) OVERRIDE { | 121 float noise_volume) override { |
122 volume_ = volume; | 122 volume_ = volume; |
123 noise_volume_ = noise_volume; | 123 noise_volume_ = noise_volume; |
124 } | 124 } |
125 | 125 |
126 virtual void OnRecognitionEnd(int session_id) OVERRIDE { | 126 virtual void OnRecognitionEnd(int session_id) override { |
127 recognition_ended_ = true; | 127 recognition_ended_ = true; |
128 CheckEventsConsistency(); | 128 CheckEventsConsistency(); |
129 } | 129 } |
130 | 130 |
131 virtual void OnRecognitionStart(int session_id) OVERRIDE { | 131 virtual void OnRecognitionStart(int session_id) override { |
132 recognition_started_ = true; | 132 recognition_started_ = true; |
133 CheckEventsConsistency(); | 133 CheckEventsConsistency(); |
134 } | 134 } |
135 | 135 |
136 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE {} | 136 virtual void OnEnvironmentEstimationComplete(int session_id) override {} |
137 | 137 |
138 virtual void OnSoundStart(int session_id) OVERRIDE { | 138 virtual void OnSoundStart(int session_id) override { |
139 sound_started_ = true; | 139 sound_started_ = true; |
140 CheckEventsConsistency(); | 140 CheckEventsConsistency(); |
141 } | 141 } |
142 | 142 |
143 virtual void OnSoundEnd(int session_id) OVERRIDE { | 143 virtual void OnSoundEnd(int session_id) override { |
144 sound_ended_ = true; | 144 sound_ended_ = true; |
145 CheckEventsConsistency(); | 145 CheckEventsConsistency(); |
146 } | 146 } |
147 | 147 |
148 // testing::Test methods. | 148 // testing::Test methods. |
149 virtual void SetUp() OVERRIDE { | 149 virtual void SetUp() override { |
150 AudioInputController::set_factory_for_testing( | 150 AudioInputController::set_factory_for_testing( |
151 &audio_input_controller_factory_); | 151 &audio_input_controller_factory_); |
152 } | 152 } |
153 | 153 |
154 virtual void TearDown() OVERRIDE { | 154 virtual void TearDown() override { |
155 AudioInputController::set_factory_for_testing(NULL); | 155 AudioInputController::set_factory_for_testing(NULL); |
156 } | 156 } |
157 | 157 |
158 void CopyPacketToAudioBus() { | 158 void CopyPacketToAudioBus() { |
159 // Copy the created signal into an audio bus in a deinterleaved format. | 159 // Copy the created signal into an audio bus in a deinterleaved format. |
160 audio_bus_->FromInterleaved( | 160 audio_bus_->FromInterleaved( |
161 &audio_packet_[0], audio_bus_->frames(), bytes_per_sample_); | 161 &audio_packet_[0], audio_bus_->frames(), bytes_per_sample_); |
162 } | 162 } |
163 | 163 |
164 void FillPacketWithTestWaveform() { | 164 void FillPacketWithTestWaveform() { |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 498 |
499 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 499 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
500 EXPECT_FALSE(audio_ended_); | 500 EXPECT_FALSE(audio_ended_); |
501 EXPECT_FALSE(recognition_ended_); | 501 EXPECT_FALSE(recognition_ended_); |
502 recognizer_->AbortRecognition(); | 502 recognizer_->AbortRecognition(); |
503 base::MessageLoop::current()->RunUntilIdle(); | 503 base::MessageLoop::current()->RunUntilIdle(); |
504 CheckFinalEventsConsistency(); | 504 CheckFinalEventsConsistency(); |
505 } | 505 } |
506 | 506 |
507 } // namespace content | 507 } // namespace content |
OLD | NEW |