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/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 virtual void StartRecognition( | 65 virtual void StartRecognition( |
66 content::SpeechInputManagerDelegate* delegate, | 66 content::SpeechInputManagerDelegate* delegate, |
67 int caller_id, | 67 int caller_id, |
68 int render_process_id, | 68 int render_process_id, |
69 int render_view_id, | 69 int render_view_id, |
70 const gfx::Rect& element_rect, | 70 const gfx::Rect& element_rect, |
71 const std::string& language, | 71 const std::string& language, |
72 const std::string& grammar, | 72 const std::string& grammar, |
73 const std::string& origin_url, | 73 const std::string& origin_url, |
74 net::URLRequestContextGetter* context_getter, | 74 net::URLRequestContextGetter* context_getter, |
75 content::SpeechInputPreferences* speech_input_prefs, | 75 content::SpeechInputPreferences* speech_input_prefs) OVERRIDE { |
76 AudioManager* audio_manager) OVERRIDE { | |
77 VLOG(1) << "StartRecognition invoked."; | 76 VLOG(1) << "StartRecognition invoked."; |
78 EXPECT_EQ(0, caller_id_); | 77 EXPECT_EQ(0, caller_id_); |
79 EXPECT_EQ(NULL, delegate_); | 78 EXPECT_EQ(NULL, delegate_); |
80 caller_id_ = caller_id; | 79 caller_id_ = caller_id; |
81 delegate_ = delegate; | 80 delegate_ = delegate; |
82 grammar_ = grammar; | 81 grammar_ = grammar; |
83 if (should_send_fake_response_) { | 82 if (should_send_fake_response_) { |
84 // Give the fake result in a short while. | 83 // Give the fake result in a short while. |
85 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 84 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
86 &FakeSpeechInputManager::SetFakeRecognitionResult, | 85 &FakeSpeechInputManager::SetFakeRecognitionResult, |
(...skipping 21 matching lines...) Expand all Loading... |
108 content::SpeechInputManagerDelegate* delegate) OVERRIDE { | 107 content::SpeechInputManagerDelegate* delegate) OVERRIDE { |
109 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; | 108 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; |
110 // delegate_ is set to NULL if a fake result was received (see below), so | 109 // delegate_ is set to NULL if a fake result was received (see below), so |
111 // check that delegate_ matches the incoming parameter only when there is | 110 // check that delegate_ matches the incoming parameter only when there is |
112 // no fake result sent. | 111 // no fake result sent. |
113 EXPECT_TRUE(should_send_fake_response_ || delegate_ == delegate); | 112 EXPECT_TRUE(should_send_fake_response_ || delegate_ == delegate); |
114 did_cancel_all_ = true; | 113 did_cancel_all_ = true; |
115 } | 114 } |
116 | 115 |
117 protected: | 116 protected: |
118 virtual void GetRequestInfo(AudioManager* audio_manager, | 117 virtual void GetRequestInfo(bool* can_report_metrics, |
119 bool* can_report_metrics, | 118 std::string* request_info) OVERRIDE {} |
120 std::string* request_info) OVERRIDE {} | 119 virtual void ShowRecognitionRequested( |
121 virtual void ShowRecognitionRequested(int caller_id, int render_process_id, | 120 int caller_id, int render_process_id, int render_view_id, |
122 int render_view_id, const gfx::Rect& element_rect) OVERRIDE {} | 121 const gfx::Rect& element_rect) OVERRIDE {} |
123 virtual void ShowWarmUp(int caller_id) OVERRIDE {} | 122 virtual void ShowWarmUp(int caller_id) OVERRIDE {} |
124 virtual void ShowRecognizing(int caller_id) OVERRIDE {} | 123 virtual void ShowRecognizing(int caller_id) OVERRIDE {} |
125 virtual void ShowRecording(int caller_id) OVERRIDE {} | 124 virtual void ShowRecording(int caller_id) OVERRIDE {} |
126 virtual void ShowInputVolume(int caller_id, float volume, | 125 virtual void ShowInputVolume( |
127 float noise_volume) OVERRIDE {} | 126 int caller_id, float volume, float noise_volume) OVERRIDE {} |
128 virtual void ShowMicError(int caller_id, | 127 virtual void ShowMicError( |
129 SpeechInputManager::MicError error) OVERRIDE {} | 128 int caller_id, SpeechInputManager::MicError error) OVERRIDE {} |
130 virtual void ShowRecognizerError(int caller_id, | 129 virtual void ShowRecognizerError( |
131 content::SpeechInputError error) OVERRIDE {} | 130 int caller_id, content::SpeechInputError error) OVERRIDE {} |
132 virtual void DoClose(int caller_id) OVERRIDE {} | 131 virtual void DoClose(int caller_id) OVERRIDE {} |
133 | 132 |
134 private: | 133 private: |
135 void SetFakeRecognitionResult() { | 134 void SetFakeRecognitionResult() { |
136 if (caller_id_) { // Do a check in case we were cancelled.. | 135 if (caller_id_) { // Do a check in case we were cancelled.. |
137 VLOG(1) << "Setting fake recognition result."; | 136 VLOG(1) << "Setting fake recognition result."; |
138 delegate_->DidCompleteRecording(caller_id_); | 137 delegate_->DidCompleteRecording(caller_id_); |
139 content::SpeechInputResult results; | 138 content::SpeechInputResult results; |
140 results.hypotheses.push_back(content::SpeechInputHypothesis( | 139 results.hypotheses.push_back(content::SpeechInputHypothesis( |
141 ASCIIToUTF16(kTestResult), 1.0)); | 140 ASCIIToUTF16(kTestResult), 1.0)); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 260 |
262 // Make the renderer crash. This should trigger SpeechInputDispatcherHost to | 261 // Make the renderer crash. This should trigger SpeechInputDispatcherHost to |
263 // cancel all pending sessions. | 262 // cancel all pending sessions. |
264 GURL test_url("about:crash"); | 263 GURL test_url("about:crash"); |
265 ui_test_utils::NavigateToURL(browser(), test_url); | 264 ui_test_utils::NavigateToURL(browser(), test_url); |
266 | 265 |
267 EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all()); | 266 EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all()); |
268 } | 267 } |
269 | 268 |
270 } // namespace speech_input | 269 } // namespace speech_input |
OLD | NEW |