Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/speech/speech_input_extension_apitest.cc

Issue 9568002: Renamed speech input implementation from to speech_recognition_*. The namespace has been renamed fr… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed nits according to reviewers and renamed x-webkit-speech related stuff to InputTagSpeech*. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/speech/speech_input_extension_manager.h" 11 #include "chrome/browser/speech/speech_input_extension_manager.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "content/public/browser/speech_recognizer_delegate.h" 15 #include "content/public/browser/speech_recognizer_delegate.h"
16 #include "content/public/common/speech_input_result.h" 16 #include "content/public/common/speech_recognition_result.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using content::BrowserThread; 19 using content::BrowserThread;
20 20
21 namespace net { 21 namespace net {
22 class URLRequestContextGetter; 22 class URLRequestContextGetter;
23 } 23 }
24 24
25 // Mock class used to test the extension speech input API. 25 // Mock class used to test the extension speech input API.
26 class SpeechInputExtensionApiTest : public ExtensionApiTest, 26 class SpeechInputExtensionApiTest : public ExtensionApiTest,
27 public SpeechInputExtensionInterface { 27 public SpeechInputExtensionInterface {
28 public: 28 public:
29 SpeechInputExtensionApiTest(); 29 SpeechInputExtensionApiTest();
30 virtual ~SpeechInputExtensionApiTest(); 30 virtual ~SpeechInputExtensionApiTest();
31 31
32 void SetRecordingDevicesAvailable(bool available) { 32 void SetRecordingDevicesAvailable(bool available) {
33 recording_devices_available_ = available; 33 recording_devices_available_ = available;
34 } 34 }
35 35
36 void SetRecognitionError(content::SpeechInputError error) { 36 void SetRecognitionError(content::SpeechRecognitionErrorCode error) {
37 next_error_ = error; 37 next_error_ = error;
38 } 38 }
39 39
40 void SetRecognitionResult(const content::SpeechInputResult& result) { 40 void SetRecognitionResult(const content::SpeechRecognitionResult& result) {
41 next_result_ = result; 41 next_result_ = result;
42 } 42 }
43 43
44 void SetRecognitionDelay(int result_delay_ms) { 44 void SetRecognitionDelay(int result_delay_ms) {
45 result_delay_ms_ = result_delay_ms; 45 result_delay_ms_ = result_delay_ms;
46 } 46 }
47 47
48 // Used as delay when the corresponding call should not be dispatched. 48 // Used as delay when the corresponding call should not be dispatched.
49 static const int kDontDispatchCall = -1; 49 static const int kDontDispatchCall = -1;
50 50
51 // ExtensionApiTest methods. 51 // ExtensionApiTest methods.
52 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 52 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
53 ExtensionApiTest::SetUpCommandLine(command_line); 53 ExtensionApiTest::SetUpCommandLine(command_line);
54 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 54 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
55 } 55 }
56 56
57 // SpeechInputExtensionInterface methods. 57 // SpeechInputExtensionInterface methods.
58 virtual bool HasAudioInputDevices() OVERRIDE { 58 virtual bool HasAudioInputDevices() OVERRIDE {
59 return recording_devices_available_; 59 return recording_devices_available_;
60 } 60 }
61 61
62 virtual bool IsRecordingInProcess() OVERRIDE { 62 virtual bool IsCapturingAudio() OVERRIDE {
63 // Only the mock recognizer is supposed to be recording during testing. 63 // Only the mock recognizer is supposed to be recording during testing.
64 return HasValidRecognizer(); 64 return HasValidRecognizer();
65 } 65 }
66 66
67 virtual bool HasValidRecognizer() OVERRIDE { 67 virtual bool HasValidRecognizer() OVERRIDE {
68 return recognizer_is_valid_; 68 return recognizer_is_valid_;
69 } 69 }
70 70
71 virtual void StartRecording( 71 virtual void StartRecording(
72 content::SpeechRecognizerDelegate* delegate, 72 content::SpeechRecognizerDelegate* delegate,
(...skipping 25 matching lines...) Expand all
98 98
99 private: 99 private:
100 SpeechInputExtensionApiTest* test_; 100 SpeechInputExtensionApiTest* test_;
101 }; 101 };
102 102
103 private: 103 private:
104 void ProvideResults(int caller_id); 104 void ProvideResults(int caller_id);
105 105
106 bool recording_devices_available_; 106 bool recording_devices_available_;
107 bool recognizer_is_valid_; 107 bool recognizer_is_valid_;
108 content::SpeechInputError next_error_; 108 content::SpeechRecognitionErrorCode next_error_;
109 content::SpeechInputResult next_result_; 109 content::SpeechRecognitionResult next_result_;
110 int result_delay_ms_; 110 int result_delay_ms_;
111 }; 111 };
112 112
113 SpeechInputExtensionApiTest::SpeechInputExtensionApiTest() 113 SpeechInputExtensionApiTest::SpeechInputExtensionApiTest()
114 : recording_devices_available_(true), 114 : recording_devices_available_(true),
115 recognizer_is_valid_(false), 115 recognizer_is_valid_(false),
116 next_error_(content::SPEECH_INPUT_ERROR_NONE), 116 next_error_(content::SPEECH_RECOGNITION_ERROR_NONE),
117 result_delay_ms_(0) { 117 result_delay_ms_(0) {
118 } 118 }
119 119
120 SpeechInputExtensionApiTest::~SpeechInputExtensionApiTest() { 120 SpeechInputExtensionApiTest::~SpeechInputExtensionApiTest() {
121 } 121 }
122 122
123 void SpeechInputExtensionApiTest::StartRecording( 123 void SpeechInputExtensionApiTest::StartRecording(
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,
(...skipping 22 matching lines...) Expand all
149 } 149 }
150 150
151 void SpeechInputExtensionApiTest::StopRecording(bool recognition_failed) { 151 void SpeechInputExtensionApiTest::StopRecording(bool recognition_failed) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
153 recognizer_is_valid_ = false; 153 recognizer_is_valid_ = false;
154 } 154 }
155 155
156 void SpeechInputExtensionApiTest::ProvideResults(int caller_id) { 156 void SpeechInputExtensionApiTest::ProvideResults(int caller_id) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
158 158
159 if (next_error_ != content::SPEECH_INPUT_ERROR_NONE) { 159 if (next_error_ != content::SPEECH_RECOGNITION_ERROR_NONE) {
160 GetManager()->OnRecognizerError(caller_id, next_error_); 160 GetManager()->OnRecognizerError(caller_id, next_error_);
161 return; 161 return;
162 } 162 }
163 163
164 GetManager()->DidStopReceivingSpeech(caller_id); 164 GetManager()->DidStopReceivingSpeech(caller_id);
165 GetManager()->SetRecognitionResult(caller_id, next_result_); 165 GetManager()->SetRecognitionResult(caller_id, next_result_);
166 } 166 }
167 167
168 // Every test should leave the manager in the idle state when finished. 168 // Every test should leave the manager in the idle state when finished.
169 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, StartStopTest) { 169 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, StartStopTest) {
170 AutoManagerHook hook(this); 170 AutoManagerHook hook(this);
171 171
172 SetRecognitionDelay(kDontDispatchCall); 172 SetRecognitionDelay(kDontDispatchCall);
173 ASSERT_TRUE(RunExtensionTest("speech_input/start_stop")) << message_; 173 ASSERT_TRUE(RunExtensionTest("speech_input/start_stop")) << message_;
174 } 174 }
175 175
176 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, NoDevicesAvailable) { 176 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, NoDevicesAvailable) {
177 AutoManagerHook hook(this); 177 AutoManagerHook hook(this);
178 178
179 SetRecordingDevicesAvailable(false); 179 SetRecordingDevicesAvailable(false);
180 ASSERT_TRUE(RunExtensionTest("speech_input/start_error")) << message_; 180 ASSERT_TRUE(RunExtensionTest("speech_input/start_error")) << message_;
181 } 181 }
182 182
183 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionSuccessful) { 183 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionSuccessful) {
184 AutoManagerHook hook(this); 184 AutoManagerHook hook(this);
185 185
186 content::SpeechInputResult result; 186 content::SpeechRecognitionResult result;
187 result.hypotheses.push_back( 187 result.hypotheses.push_back(
188 content::SpeechInputHypothesis(UTF8ToUTF16("this is a test"), 0.99)); 188 content::SpeechRecognitionHypothesis(
189 UTF8ToUTF16("this is a test"), 0.99));
189 SetRecognitionResult(result); 190 SetRecognitionResult(result);
190 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_; 191 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_;
191 } 192 }
192 193
193 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) { 194 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) {
194 AutoManagerHook hook(this); 195 AutoManagerHook hook(this);
195 196
196 SetRecognitionError(content::SPEECH_INPUT_ERROR_NETWORK); 197 SetRecognitionError(content::SPEECH_RECOGNITION_ERROR_NETWORK);
197 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_; 198 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_;
198 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698