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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/speech/speech_input_extension_api.h" | 9 #include "chrome/browser/speech/speech_input_extension_api.h" |
10 #include "chrome/browser/speech/speech_input_extension_manager.h" | 10 #include "chrome/browser/speech/speech_input_extension_manager.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 static const int kDontDispatchCall = -1; | 48 static const int kDontDispatchCall = -1; |
49 | 49 |
50 // ExtensionApiTest methods. | 50 // ExtensionApiTest methods. |
51 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 51 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
52 ExtensionApiTest::SetUpCommandLine(command_line); | 52 ExtensionApiTest::SetUpCommandLine(command_line); |
53 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 53 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
54 } | 54 } |
55 | 55 |
56 // SpeechInputExtensionInterface methods. | 56 // SpeechInputExtensionInterface methods. |
57 virtual bool HasAudioInputDevices( | 57 virtual bool HasAudioInputDevices( |
58 const content::ResourceContext* resource_context) OVERRIDE { | 58 content::ResourceContext* resource_context) OVERRIDE { |
59 return recording_devices_available_; | 59 return recording_devices_available_; |
60 } | 60 } |
61 | 61 |
62 virtual bool IsRecordingInProcess( | 62 virtual bool IsRecordingInProcess( |
63 const content::ResourceContext* resource_context) OVERRIDE { | 63 content::ResourceContext* resource_context) OVERRIDE { |
64 // Only the mock recognizer is supposed to be recording during testing. | 64 // Only the mock recognizer is supposed to be recording during testing. |
65 return HasValidRecognizer(); | 65 return HasValidRecognizer(); |
66 } | 66 } |
67 | 67 |
68 virtual bool HasValidRecognizer() OVERRIDE { | 68 virtual bool HasValidRecognizer() OVERRIDE { |
69 return recognizer_is_valid_; | 69 return recognizer_is_valid_; |
70 } | 70 } |
71 | 71 |
72 virtual void StartRecording( | 72 virtual void StartRecording( |
73 speech_input::SpeechRecognizerDelegate* delegate, | 73 speech_input::SpeechRecognizerDelegate* delegate, |
74 net::URLRequestContextGetter* context_getter, | 74 net::URLRequestContextGetter* context_getter, |
75 const content::ResourceContext* resource_context, | 75 content::ResourceContext* resource_context, |
76 int caller_id, | 76 int caller_id, |
77 const std::string& language, | 77 const std::string& language, |
78 const std::string& grammar, | 78 const std::string& grammar, |
79 bool filter_profanities) OVERRIDE; | 79 bool filter_profanities) OVERRIDE; |
80 | 80 |
81 virtual void StopRecording(bool recognition_failed) OVERRIDE; | 81 virtual void StopRecording(bool recognition_failed) OVERRIDE; |
82 | 82 |
83 SpeechInputExtensionManager* GetManager() { | 83 SpeechInputExtensionManager* GetManager() { |
84 return SpeechInputExtensionManager::GetForProfile(browser()->profile()); | 84 return SpeechInputExtensionManager::GetForProfile(browser()->profile()); |
85 } | 85 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 next_error_(content::SPEECH_INPUT_ERROR_NONE), | 118 next_error_(content::SPEECH_INPUT_ERROR_NONE), |
119 result_delay_ms_(0) { | 119 result_delay_ms_(0) { |
120 } | 120 } |
121 | 121 |
122 SpeechInputExtensionApiTest::~SpeechInputExtensionApiTest() { | 122 SpeechInputExtensionApiTest::~SpeechInputExtensionApiTest() { |
123 } | 123 } |
124 | 124 |
125 void SpeechInputExtensionApiTest::StartRecording( | 125 void SpeechInputExtensionApiTest::StartRecording( |
126 speech_input::SpeechRecognizerDelegate* delegate, | 126 speech_input::SpeechRecognizerDelegate* delegate, |
127 net::URLRequestContextGetter* context_getter, | 127 net::URLRequestContextGetter* context_getter, |
128 const content::ResourceContext* resource_context, | 128 content::ResourceContext* resource_context, |
129 int caller_id, | 129 int caller_id, |
130 const std::string& language, | 130 const std::string& language, |
131 const std::string& grammar, | 131 const std::string& grammar, |
132 bool filter_profanities) { | 132 bool filter_profanities) { |
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
134 recognizer_is_valid_ = true; | 134 recognizer_is_valid_ = true; |
135 | 135 |
136 // Notify that recording started. | 136 // Notify that recording started. |
137 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 137 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
138 base::Bind(&SpeechInputExtensionManager::DidStartReceivingAudio, | 138 base::Bind(&SpeechInputExtensionManager::DidStartReceivingAudio, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 SetRecognitionResult(result); | 192 SetRecognitionResult(result); |
193 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_; | 193 ASSERT_TRUE(RunExtensionTest("speech_input/recognition")) << message_; |
194 } | 194 } |
195 | 195 |
196 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) { | 196 IN_PROC_BROWSER_TEST_F(SpeechInputExtensionApiTest, RecognitionError) { |
197 AutoManagerHook hook(this); | 197 AutoManagerHook hook(this); |
198 | 198 |
199 SetRecognitionError(content::SPEECH_INPUT_ERROR_NETWORK); | 199 SetRecognitionError(content::SPEECH_INPUT_ERROR_NETWORK); |
200 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_; | 200 ASSERT_TRUE(RunExtensionTest("speech_input/recognition_error")) << message_; |
201 } | 201 } |
OLD | NEW |