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 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 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 void OnRecognitionResults(int session_id, |
109 int session_id, const SpeechRecognitionResults& results) override { | 109 const SpeechRecognitionResults& results) override { |
110 result_received_ = true; | 110 result_received_ = true; |
111 } | 111 } |
112 | 112 |
113 virtual void OnRecognitionError( | 113 void OnRecognitionError(int session_id, |
114 int session_id, const SpeechRecognitionError& error) override { | 114 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 void OnAudioLevelsChange(int session_id, |
121 float noise_volume) override { | 121 float volume, |
| 122 float noise_volume) override { |
122 volume_ = volume; | 123 volume_ = volume; |
123 noise_volume_ = noise_volume; | 124 noise_volume_ = noise_volume; |
124 } | 125 } |
125 | 126 |
126 virtual void OnRecognitionEnd(int session_id) override { | 127 void OnRecognitionEnd(int session_id) override { |
127 recognition_ended_ = true; | 128 recognition_ended_ = true; |
128 CheckEventsConsistency(); | 129 CheckEventsConsistency(); |
129 } | 130 } |
130 | 131 |
131 virtual void OnRecognitionStart(int session_id) override { | 132 void OnRecognitionStart(int session_id) override { |
132 recognition_started_ = true; | 133 recognition_started_ = true; |
133 CheckEventsConsistency(); | 134 CheckEventsConsistency(); |
134 } | 135 } |
135 | 136 |
136 virtual void OnEnvironmentEstimationComplete(int session_id) override {} | 137 void OnEnvironmentEstimationComplete(int session_id) override {} |
137 | 138 |
138 virtual void OnSoundStart(int session_id) override { | 139 void OnSoundStart(int session_id) override { |
139 sound_started_ = true; | 140 sound_started_ = true; |
140 CheckEventsConsistency(); | 141 CheckEventsConsistency(); |
141 } | 142 } |
142 | 143 |
143 virtual void OnSoundEnd(int session_id) override { | 144 void OnSoundEnd(int session_id) override { |
144 sound_ended_ = true; | 145 sound_ended_ = true; |
145 CheckEventsConsistency(); | 146 CheckEventsConsistency(); |
146 } | 147 } |
147 | 148 |
148 // testing::Test methods. | 149 // testing::Test methods. |
149 virtual void SetUp() override { | 150 virtual void SetUp() override { |
150 AudioInputController::set_factory_for_testing( | 151 AudioInputController::set_factory_for_testing( |
151 &audio_input_controller_factory_); | 152 &audio_input_controller_factory_); |
152 } | 153 } |
153 | 154 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 499 |
499 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 500 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
500 EXPECT_FALSE(audio_ended_); | 501 EXPECT_FALSE(audio_ended_); |
501 EXPECT_FALSE(recognition_ended_); | 502 EXPECT_FALSE(recognition_ended_); |
502 recognizer_->AbortRecognition(); | 503 recognizer_->AbortRecognition(); |
503 base::MessageLoop::current()->RunUntilIdle(); | 504 base::MessageLoop::current()->RunUntilIdle(); |
504 CheckFinalEventsConsistency(); | 505 CheckFinalEventsConsistency(); |
505 } | 506 } |
506 | 507 |
507 } // namespace content | 508 } // namespace content |
OLD | NEW |