Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: content/browser/speech/speech_input_browsertest.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(AudioManager* audio_manager,
102 std::string* request_info) {} 99 bool* can_report_metrics,
103 virtual void ShowRecognitionRequested(int caller_id, 100 std::string* request_info) OVERRIDE {}
104 int render_process_id, 101 virtual void ShowRecognitionRequested(int caller_id, int render_process_id,
105 int render_view_id, 102 int render_view_id, const gfx::Rect& element_rect) OVERRIDE {}
106 const gfx::Rect& element_rect) {} 103 virtual void ShowWarmUp(int caller_id) OVERRIDE {}
107 virtual void ShowWarmUp(int caller_id) {} 104 virtual void ShowRecognizing(int caller_id) OVERRIDE {}
108 virtual void ShowRecognizing(int caller_id) {} 105 virtual void ShowRecording(int caller_id) OVERRIDE {}
109 virtual void ShowRecording(int caller_id) {} 106 virtual void ShowInputVolume(int caller_id, float volume,
110 virtual void ShowInputVolume(int caller_id, 107 float noise_volume) OVERRIDE {}
111 float volume,
112 float noise_volume) {}
113 virtual void ShowMicError(int caller_id, 108 virtual void ShowMicError(int caller_id,
114 SpeechInputManager::MicError error) {} 109 SpeechInputManager::MicError error) OVERRIDE {}
115 virtual void ShowRecognizerError(int caller_id, 110 virtual void ShowRecognizerError(int caller_id,
116 content::SpeechInputError error) {} 111 content::SpeechInputError error) OVERRIDE {}
117 virtual void DoClose(int caller_id) {} 112 virtual void DoClose(int caller_id) OVERRIDE {}
118 113
119 private: 114 private:
120 void SetFakeRecognitionResult() { 115 void SetFakeRecognitionResult() {
121 if (caller_id_) { // Do a check in case we were cancelled.. 116 if (caller_id_) { // Do a check in case we were cancelled..
122 VLOG(1) << "Setting fake recognition result."; 117 VLOG(1) << "Setting fake recognition result.";
123 delegate_->DidCompleteRecording(caller_id_); 118 delegate_->DidCompleteRecording(caller_id_);
124 content::SpeechInputResult results; 119 content::SpeechInputResult results;
125 results.hypotheses.push_back(content::SpeechInputHypothesis( 120 results.hypotheses.push_back(content::SpeechInputHypothesis(
126 ASCIIToUTF16(kTestResult), 1.0)); 121 ASCIIToUTF16(kTestResult), 1.0));
127 delegate_->SetRecognitionResult(caller_id_, results); 122 delegate_->SetRecognitionResult(caller_id_, results);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 248
254 // Make the renderer crash. This should trigger SpeechInputDispatcherHost to 249 // Make the renderer crash. This should trigger SpeechInputDispatcherHost to
255 // cancel all pending sessions. 250 // cancel all pending sessions.
256 GURL test_url("about:crash"); 251 GURL test_url("about:crash");
257 ui_test_utils::NavigateToURL(browser(), test_url); 252 ui_test_utils::NavigateToURL(browser(), test_url);
258 253
259 EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all()); 254 EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all());
260 } 255 }
261 256
262 } // namespace speech_input 257 } // namespace speech_input
OLDNEW
« no previous file with comments | « content/browser/resource_context.cc ('k') | content/browser/speech/speech_input_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698