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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/speech/speech_input_extension_api.h" | 10 #include "chrome/browser/speech/speech_input_extension_api.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 content::SpeechRecognizerDelegate* delegate, | 124 content::SpeechRecognizerDelegate* delegate, |
125 net::URLRequestContextGetter* context_getter, | 125 net::URLRequestContextGetter* context_getter, |
126 int caller_id, | 126 int caller_id, |
127 const std::string& language, | 127 const std::string& language, |
128 const std::string& grammar, | 128 const std::string& grammar, |
129 bool filter_profanities) { | 129 bool filter_profanities) { |
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
131 recognizer_is_valid_ = true; | 131 recognizer_is_valid_ = true; |
132 | 132 |
133 // Notify that recording started. | 133 // Notify that recording started. |
134 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 134 MessageLoop::current()->PostDelayedTask( |
| 135 FROM_HERE, |
135 base::Bind(&SpeechInputExtensionManager::DidStartReceivingAudio, | 136 base::Bind(&SpeechInputExtensionManager::DidStartReceivingAudio, |
136 GetManager(), caller_id), 0); | 137 GetManager(), |
| 138 caller_id), |
| 139 base::TimeDelta()); |
137 | 140 |
138 // Notify sound start in the input device. | 141 // Notify sound start in the input device. |
139 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 142 MessageLoop::current()->PostDelayedTask( |
| 143 FROM_HERE, |
140 base::Bind(&SpeechInputExtensionManager::DidStartReceivingSpeech, | 144 base::Bind(&SpeechInputExtensionManager::DidStartReceivingSpeech, |
141 GetManager(), caller_id), 0); | 145 GetManager(), |
| 146 caller_id), |
| 147 base::TimeDelta()); |
142 | 148 |
143 if (result_delay_ms_ != kDontDispatchCall) { | 149 if (result_delay_ms_ != kDontDispatchCall) { |
144 // Dispatch the recognition results. | 150 // Dispatch the recognition results. |
145 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 151 MessageLoop::current()->PostDelayedTask( |
146 base::Bind(&SpeechInputExtensionApiTest::ProvideResults, this, | 152 FROM_HERE, |
147 caller_id), result_delay_ms_); | 153 base::Bind(&SpeechInputExtensionApiTest::ProvideResults, |
| 154 this, |
| 155 caller_id), |
| 156 base::TimeDelta::FromMilliseconds(result_delay_ms_)); |
148 } | 157 } |
149 } | 158 } |
150 | 159 |
151 void SpeechInputExtensionApiTest::StopRecording(bool recognition_failed) { | 160 void SpeechInputExtensionApiTest::StopRecording(bool recognition_failed) { |
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
153 recognizer_is_valid_ = false; | 162 recognizer_is_valid_ = false; |
154 } | 163 } |
155 | 164 |
156 void SpeechInputExtensionApiTest::ProvideResults(int caller_id) { | 165 void SpeechInputExtensionApiTest::ProvideResults(int caller_id) { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 SetRecognitionResult(result); | 198 SetRecognitionResult(result); |
190 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_; | 199 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_; |
191 } | 200 } |
192 | 201 |
193 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) { | 202 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) { |
194 AutoManagerHook hook(this); | 203 AutoManagerHook hook(this); |
195 | 204 |
196 SetRecognitionError(content::SPEECH_INPUT_ERROR_NETWORK); | 205 SetRecognitionError(content::SPEECH_INPUT_ERROR_NETWORK); |
197 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_; | 206 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_; |
198 } | 207 } |
OLD | NEW |