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" | |
8 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/speech/speech_input_extension_api.h" | 9 #include "chrome/browser/speech/speech_input_extension_api.h" |
11 #include "chrome/browser/speech/speech_input_extension_manager.h" | 10 #include "chrome/browser/speech/speech_input_extension_manager.h" |
12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
15 #include "content/public/browser/speech_recognizer_delegate.h" | 14 #include "content/browser/speech/speech_recognizer.h" |
16 #include "content/public/common/speech_input_result.h" | 15 #include "content/public/common/speech_input_result.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 | 17 |
19 using content::BrowserThread; | 18 using content::BrowserThread; |
20 | 19 |
21 namespace net { | 20 namespace net { |
22 class URLRequestContextGetter; | 21 class URLRequestContextGetter; |
23 } | 22 } |
24 | 23 |
25 // Mock class used to test the extension speech input API. | 24 // Mock class used to test the extension speech input API. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 content::ResourceContext* resource_context) OVERRIDE { | 63 content::ResourceContext* resource_context) OVERRIDE { |
65 // Only the mock recognizer is supposed to be recording during testing. | 64 // Only the mock recognizer is supposed to be recording during testing. |
66 return HasValidRecognizer(); | 65 return HasValidRecognizer(); |
67 } | 66 } |
68 | 67 |
69 virtual bool HasValidRecognizer() OVERRIDE { | 68 virtual bool HasValidRecognizer() OVERRIDE { |
70 return recognizer_is_valid_; | 69 return recognizer_is_valid_; |
71 } | 70 } |
72 | 71 |
73 virtual void StartRecording( | 72 virtual void StartRecording( |
74 content::SpeechRecognizerDelegate* delegate, | 73 speech_input::SpeechRecognizerDelegate* delegate, |
75 net::URLRequestContextGetter* context_getter, | 74 net::URLRequestContextGetter* context_getter, |
76 content::ResourceContext* resource_context, | 75 content::ResourceContext* resource_context, |
77 int caller_id, | 76 int caller_id, |
78 const std::string& language, | 77 const std::string& language, |
79 const std::string& grammar, | 78 const std::string& grammar, |
80 bool filter_profanities) OVERRIDE; | 79 bool filter_profanities) OVERRIDE; |
81 | 80 |
82 virtual void StopRecording(bool recognition_failed) OVERRIDE; | 81 virtual void StopRecording(bool recognition_failed) OVERRIDE; |
83 | 82 |
84 SpeechInputExtensionManager* GetManager() { | 83 SpeechInputExtensionManager* GetManager() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 : recording_devices_available_(true), | 116 : recording_devices_available_(true), |
118 recognizer_is_valid_(false), | 117 recognizer_is_valid_(false), |
119 next_error_(content::SPEECH_INPUT_ERROR_NONE), | 118 next_error_(content::SPEECH_INPUT_ERROR_NONE), |
120 result_delay_ms_(0) { | 119 result_delay_ms_(0) { |
121 } | 120 } |
122 | 121 |
123 SpeechInputExtensionApiTest::~SpeechInputExtensionApiTest() { | 122 SpeechInputExtensionApiTest::~SpeechInputExtensionApiTest() { |
124 } | 123 } |
125 | 124 |
126 void SpeechInputExtensionApiTest::StartRecording( | 125 void SpeechInputExtensionApiTest::StartRecording( |
127 content::SpeechRecognizerDelegate* delegate, | 126 speech_input::SpeechRecognizerDelegate* delegate, |
128 net::URLRequestContextGetter* context_getter, | 127 net::URLRequestContextGetter* context_getter, |
129 content::ResourceContext* resource_context, | 128 content::ResourceContext* resource_context, |
130 int caller_id, | 129 int caller_id, |
131 const std::string& language, | 130 const std::string& language, |
132 const std::string& grammar, | 131 const std::string& grammar, |
133 bool filter_profanities) { | 132 bool filter_profanities) { |
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
135 recognizer_is_valid_ = true; | 134 recognizer_is_valid_ = true; |
136 | 135 |
137 // Notify that recording started. | 136 // Notify that recording started. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 SetRecognitionResult(result); | 192 SetRecognitionResult(result); |
194 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_; | 193 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_; |
195 } | 194 } |
196 | 195 |
197 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) { | 196 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) { |
198 AutoManagerHook hook(this); | 197 AutoManagerHook hook(this); |
199 | 198 |
200 SetRecognitionError(content::SPEECH_INPUT_ERROR_NETWORK); | 199 SetRecognitionError(content::SPEECH_INPUT_ERROR_NETWORK); |
201 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_; | 200 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_; |
202 } | 201 } |
OLD | NEW |