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