| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 bool did_cancel_all() { | 43 bool did_cancel_all() { |
| 44 return did_cancel_all_; | 44 return did_cancel_all_; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void set_send_fake_response(bool send) { | 47 void set_send_fake_response(bool send) { |
| 48 send_fake_response_ = send; | 48 send_fake_response_ = send; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // SpeechInputManager methods. | 51 // SpeechInputManager methods. |
| 52 virtual void StartRecognition(Delegate* delegate, | 52 virtual void StartRecognition(Delegate* delegate, int caller_id, |
| 53 int caller_id, | 53 int render_process_id, int render_view_id, const gfx::Rect& element_rect, |
| 54 int render_process_id, | 54 const std::string& language, const std::string& grammar, |
| 55 int render_view_id, | 55 const std::string& origin_url, |
| 56 const gfx::Rect& element_rect, | 56 net::URLRequestContextGetter* context_getter, |
| 57 const std::string& language, | 57 SpeechInputPreferences* speech_input_prefs, |
| 58 const std::string& grammar, | 58 AudioManager* audio_manager) OVERRIDE { |
| 59 const std::string& origin_url, | |
| 60 net::URLRequestContextGetter* context_getter, | |
| 61 SpeechInputPreferences* speech_input_prefs) { | |
| 62 VLOG(1) << "StartRecognition invoked."; | 59 VLOG(1) << "StartRecognition invoked."; |
| 63 EXPECT_EQ(0, caller_id_); | 60 EXPECT_EQ(0, caller_id_); |
| 64 EXPECT_EQ(NULL, delegate_); | 61 EXPECT_EQ(NULL, delegate_); |
| 65 caller_id_ = caller_id; | 62 caller_id_ = caller_id; |
| 66 delegate_ = delegate; | 63 delegate_ = delegate; |
| 67 grammar_ = grammar; | 64 grammar_ = grammar; |
| 68 if (send_fake_response_) { | 65 if (send_fake_response_) { |
| 69 // Give the fake result in a short while. | 66 // Give the fake result in a short while. |
| 70 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 67 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 71 &FakeSpeechInputManager::SetFakeRecognitionResult, | 68 &FakeSpeechInputManager::SetFakeRecognitionResult, |
| 72 // This class does not need to be refcounted (typically done by | 69 // This class does not need to be refcounted (typically done by |
| 73 // PostTask) since it will outlive the test and gets released only | 70 // PostTask) since it will outlive the test and gets released only |
| 74 // when the test shuts down. Disabling refcounting here saves a bit | 71 // when the test shuts down. Disabling refcounting here saves a bit |
| 75 // of unnecessary code and the factory method can return a plain | 72 // of unnecessary code and the factory method can return a plain |
| 76 // pointer below as required by the real code. | 73 // pointer below as required by the real code. |
| 77 base::Unretained(this))); | 74 base::Unretained(this))); |
| 78 } | 75 } |
| 79 } | 76 } |
| 80 virtual void CancelRecognition(int caller_id) { | 77 virtual void CancelRecognition(int caller_id) OVERRIDE { |
| 81 VLOG(1) << "CancelRecognition invoked."; | 78 VLOG(1) << "CancelRecognition invoked."; |
| 82 EXPECT_EQ(caller_id_, caller_id); | 79 EXPECT_EQ(caller_id_, caller_id); |
| 83 caller_id_ = 0; | 80 caller_id_ = 0; |
| 84 delegate_ = NULL; | 81 delegate_ = NULL; |
| 85 } | 82 } |
| 86 virtual void StopRecording(int caller_id) { | 83 virtual void StopRecording(int caller_id) OVERRIDE { |
| 87 VLOG(1) << "StopRecording invoked."; | 84 VLOG(1) << "StopRecording invoked."; |
| 88 EXPECT_EQ(caller_id_, caller_id); | 85 EXPECT_EQ(caller_id_, caller_id); |
| 89 // Nothing to do here since we aren't really recording. | 86 // Nothing to do here since we aren't really recording. |
| 90 } | 87 } |
| 91 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) { | 88 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) OVERRIDE { |
| 92 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; | 89 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; |
| 93 // delegate_ is set to NULL if a fake result was received (see below), so | 90 // delegate_ is set to NULL if a fake result was received (see below), so |
| 94 // check that delegate_ matches the incoming parameter only when there is | 91 // check that delegate_ matches the incoming parameter only when there is |
| 95 // no fake result sent. | 92 // no fake result sent. |
| 96 EXPECT_TRUE(send_fake_response_ || delegate_ == delegate); | 93 EXPECT_TRUE(send_fake_response_ || delegate_ == delegate); |
| 97 did_cancel_all_ = true; | 94 did_cancel_all_ = true; |
| 98 } | 95 } |
| 99 | 96 |
| 100 protected: | 97 protected: |
| 101 virtual void GetRequestInfo(bool* can_report_metrics, | 98 virtual void GetRequestInfo(bool* can_report_metrics, |
| 102 std::string* request_info) {} | 99 std::string* request_info) OVERRIDE {} |
| 103 virtual void ShowRecognitionRequested(int caller_id, | 100 virtual void ShowRecognitionRequested(int caller_id, int render_process_id, |
| 104 int render_process_id, | 101 int render_view_id, const gfx::Rect& element_rect) OVERRIDE {} |
| 105 int render_view_id, | 102 virtual void ShowWarmUp(int caller_id) OVERRIDE {} |
| 106 const gfx::Rect& element_rect) {} | 103 virtual void ShowRecognizing(int caller_id) OVERRIDE {} |
| 107 virtual void ShowWarmUp(int caller_id) {} | 104 virtual void ShowRecording(int caller_id) OVERRIDE {} |
| 108 virtual void ShowRecognizing(int caller_id) {} | 105 virtual void ShowInputVolume(int caller_id, float volume, |
| 109 virtual void ShowRecording(int caller_id) {} | 106 float noise_volume) OVERRIDE {} |
| 110 virtual void ShowInputVolume(int caller_id, | |
| 111 float volume, | |
| 112 float noise_volume) {} | |
| 113 virtual void ShowMicError(int caller_id, | 107 virtual void ShowMicError(int caller_id, |
| 114 SpeechInputManager::MicError error) {} | 108 SpeechInputManager::MicError error) OVERRIDE {} |
| 115 virtual void ShowRecognizerError(int caller_id, | 109 virtual void ShowRecognizerError(int caller_id, |
| 116 content::SpeechInputError error) {} | 110 content::SpeechInputError error) OVERRIDE {} |
| 117 virtual void DoClose(int caller_id) {} | 111 virtual void DoClose(int caller_id) OVERRIDE {} |
| 118 | 112 |
| 119 private: | 113 private: |
| 120 void SetFakeRecognitionResult() { | 114 void SetFakeRecognitionResult() { |
| 121 if (caller_id_) { // Do a check in case we were cancelled.. | 115 if (caller_id_) { // Do a check in case we were cancelled.. |
| 122 VLOG(1) << "Setting fake recognition result."; | 116 VLOG(1) << "Setting fake recognition result."; |
| 123 delegate_->DidCompleteRecording(caller_id_); | 117 delegate_->DidCompleteRecording(caller_id_); |
| 124 content::SpeechInputResult results; | 118 content::SpeechInputResult results; |
| 125 results.hypotheses.push_back(content::SpeechInputHypothesis( | 119 results.hypotheses.push_back(content::SpeechInputHypothesis( |
| 126 ASCIIToUTF16(kTestResult), 1.0)); | 120 ASCIIToUTF16(kTestResult), 1.0)); |
| 127 delegate_->SetRecognitionResult(caller_id_, results); | 121 delegate_->SetRecognitionResult(caller_id_, results); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 247 |
| 254 // Make the renderer crash. This should trigger SpeechInputDispatcherHost to | 248 // Make the renderer crash. This should trigger SpeechInputDispatcherHost to |
| 255 // cancel all pending sessions. | 249 // cancel all pending sessions. |
| 256 GURL test_url("about:crash"); | 250 GURL test_url("about:crash"); |
| 257 ui_test_utils::NavigateToURL(browser(), test_url); | 251 ui_test_utils::NavigateToURL(browser(), test_url); |
| 258 | 252 |
| 259 EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all()); | 253 EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all()); |
| 260 } | 254 } |
| 261 | 255 |
| 262 } // namespace speech_input | 256 } // namespace speech_input |
| OLD | NEW |