| OLD | NEW |
| 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" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 140 } |
| 141 | 141 |
| 142 void CheckFinalEventsConsistency() { | 142 void CheckFinalEventsConsistency() { |
| 143 // Note: "!(x ^ y)" == "(x && y) || (!x && !x)". | 143 // Note: "!(x ^ y)" == "(x && y) || (!x && !x)". |
| 144 EXPECT_FALSE(recognition_started_ ^ recognition_ended_); | 144 EXPECT_FALSE(recognition_started_ ^ recognition_ended_); |
| 145 EXPECT_FALSE(audio_started_ ^ audio_ended_); | 145 EXPECT_FALSE(audio_started_ ^ audio_ended_); |
| 146 EXPECT_FALSE(sound_started_ ^ sound_ended_); | 146 EXPECT_FALSE(sound_started_ ^ sound_ended_); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Overridden from content::SpeechRecognitionEventListener: | 149 // Overridden from content::SpeechRecognitionEventListener: |
| 150 virtual void OnAudioStart(int caller_id) OVERRIDE { | 150 virtual void OnAudioStart(int session_id) OVERRIDE { |
| 151 audio_started_ = true; | 151 audio_started_ = true; |
| 152 CheckEventsConsistency(); | 152 CheckEventsConsistency(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 virtual void OnAudioEnd(int caller_id) OVERRIDE { | 155 virtual void OnAudioEnd(int session_id) OVERRIDE { |
| 156 audio_ended_ = true; | 156 audio_ended_ = true; |
| 157 CheckEventsConsistency(); | 157 CheckEventsConsistency(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 virtual void OnRecognitionResult( | 160 virtual void OnRecognitionResult( |
| 161 int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE { | 161 int session_id, const content::SpeechRecognitionResult& result) OVERRIDE { |
| 162 result_received_ = true; | 162 result_received_ = true; |
| 163 } | 163 } |
| 164 | 164 |
| 165 virtual void OnRecognitionError( | 165 virtual void OnRecognitionError( |
| 166 int caller_id, const content::SpeechRecognitionError& error) OVERRIDE { | 166 int session_id, const content::SpeechRecognitionError& error) OVERRIDE { |
| 167 EXPECT_TRUE(recognition_started_); | 167 EXPECT_TRUE(recognition_started_); |
| 168 EXPECT_FALSE(recognition_ended_); | 168 EXPECT_FALSE(recognition_ended_); |
| 169 error_ = error.code; | 169 error_ = error.code; |
| 170 } | 170 } |
| 171 | 171 |
| 172 virtual void OnAudioLevelsChange(int caller_id, float volume, | 172 virtual void OnAudioLevelsChange(int session_id, float volume, |
| 173 float noise_volume) OVERRIDE { | 173 float noise_volume) OVERRIDE { |
| 174 volume_ = volume; | 174 volume_ = volume; |
| 175 noise_volume_ = noise_volume; | 175 noise_volume_ = noise_volume; |
| 176 } | 176 } |
| 177 | 177 |
| 178 virtual void OnRecognitionEnd(int caller_id) OVERRIDE { | 178 virtual void OnRecognitionEnd(int session_id) OVERRIDE { |
| 179 recognition_ended_ = true; | 179 recognition_ended_ = true; |
| 180 CheckEventsConsistency(); | 180 CheckEventsConsistency(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 virtual void OnRecognitionStart(int caller_id) OVERRIDE { | 183 virtual void OnRecognitionStart(int session_id) OVERRIDE { |
| 184 recognition_started_ = true; | 184 recognition_started_ = true; |
| 185 CheckEventsConsistency(); | 185 CheckEventsConsistency(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 virtual void OnEnvironmentEstimationComplete(int caller_id) OVERRIDE {} | 188 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE {} |
| 189 | 189 |
| 190 virtual void OnSoundStart(int caller_id) OVERRIDE { | 190 virtual void OnSoundStart(int session_id) OVERRIDE { |
| 191 sound_started_ = true; | 191 sound_started_ = true; |
| 192 CheckEventsConsistency(); | 192 CheckEventsConsistency(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 virtual void OnSoundEnd(int caller_id) OVERRIDE { | 195 virtual void OnSoundEnd(int session_id) OVERRIDE { |
| 196 sound_ended_ = true; | 196 sound_ended_ = true; |
| 197 CheckEventsConsistency(); | 197 CheckEventsConsistency(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 // testing::Test methods. | 200 // testing::Test methods. |
| 201 virtual void SetUp() OVERRIDE { | 201 virtual void SetUp() OVERRIDE { |
| 202 AudioInputController::set_factory_for_testing( | 202 AudioInputController::set_factory_for_testing( |
| 203 &audio_input_controller_factory_); | 203 &audio_input_controller_factory_); |
| 204 } | 204 } |
| 205 | 205 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |