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

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

Issue 6358007: Cancel any pending speech recognitions when the dispatcher host terminates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 months 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/renderer_host/render_view_host.h" 9 #include "chrome/browser/renderer_host/render_view_host.h"
10 #include "chrome/browser/speech/speech_input_dispatcher_host.h" 10 #include "chrome/browser/speech/speech_input_dispatcher_host.h"
(...skipping 24 matching lines...) Expand all
35 FakeSpeechInputManager() 35 FakeSpeechInputManager()
36 : caller_id_(0), 36 : caller_id_(0),
37 delegate_(NULL) { 37 delegate_(NULL) {
38 } 38 }
39 39
40 std::string grammar() { 40 std::string grammar() {
41 return grammar_; 41 return grammar_;
42 } 42 }
43 43
44 // SpeechInputManager methods. 44 // SpeechInputManager methods.
45 void StartRecognition(Delegate* delegate, 45 virtual void StartRecognition(Delegate* delegate,
46 int caller_id, 46 int caller_id,
47 int render_process_id, 47 int render_process_id,
48 int render_view_id, 48 int render_view_id,
49 const gfx::Rect& element_rect, 49 const gfx::Rect& element_rect,
50 const std::string& language, 50 const std::string& language,
51 const std::string& grammar) { 51 const std::string& grammar) {
52 VLOG(1) << "StartRecognition invoked."; 52 VLOG(1) << "StartRecognition invoked.";
53 EXPECT_EQ(0, caller_id_); 53 EXPECT_EQ(0, caller_id_);
54 EXPECT_EQ(NULL, delegate_); 54 EXPECT_EQ(NULL, delegate_);
55 caller_id_ = caller_id; 55 caller_id_ = caller_id;
56 delegate_ = delegate; 56 delegate_ = delegate;
57 grammar_ = grammar; 57 grammar_ = grammar;
58 // Give the fake result in a short while. 58 // Give the fake result in a short while.
59 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, 59 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
60 &FakeSpeechInputManager::SetFakeRecognitionResult)); 60 &FakeSpeechInputManager::SetFakeRecognitionResult));
61 } 61 }
62 void CancelRecognition(int caller_id) { 62 virtual void CancelRecognition(int caller_id) {
63 VLOG(1) << "CancelRecognition invoked."; 63 VLOG(1) << "CancelRecognition invoked.";
64 EXPECT_EQ(caller_id_, caller_id); 64 EXPECT_EQ(caller_id_, caller_id);
65 caller_id_ = 0; 65 caller_id_ = 0;
66 delegate_ = NULL; 66 delegate_ = NULL;
67 } 67 }
68 void StopRecording(int caller_id) { 68 virtual void StopRecording(int caller_id) {
69 VLOG(1) << "StopRecording invoked."; 69 VLOG(1) << "StopRecording invoked.";
70 EXPECT_EQ(caller_id_, caller_id); 70 EXPECT_EQ(caller_id_, caller_id);
71 // Nothing to do here since we aren't really recording. 71 // Nothing to do here since we aren't really recording.
72 } 72 }
73 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) {
74 VLOG(1) << "CancelAllRequestsWithDelegate invoked.";
75 }
73 76
74 private: 77 private:
75 void SetFakeRecognitionResult() { 78 void SetFakeRecognitionResult() {
76 if (caller_id_) { // Do a check in case we were cancelled.. 79 if (caller_id_) { // Do a check in case we were cancelled..
77 VLOG(1) << "Setting fake recognition result."; 80 VLOG(1) << "Setting fake recognition result.";
78 delegate_->DidCompleteRecording(caller_id_); 81 delegate_->DidCompleteRecording(caller_id_);
79 SpeechInputResultArray results; 82 SpeechInputResultArray results;
80 results.push_back(SpeechInputResultItem(ASCIIToUTF16(kTestResult), 1.0)); 83 results.push_back(SpeechInputResultItem(ASCIIToUTF16(kTestResult), 1.0));
81 delegate_->SetRecognitionResult(caller_id_, results); 84 delegate_->SetRecognitionResult(caller_id_, results);
82 delegate_->DidCompleteRecognition(caller_id_); 85 delegate_->DidCompleteRecognition(caller_id_);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 }; 162 };
160 163
161 SpeechInputManager* SpeechInputBrowserTest::speech_input_manager_ = NULL; 164 SpeechInputManager* SpeechInputBrowserTest::speech_input_manager_ = NULL;
162 165
163 // Marked as FLAKY due to http://crbug.com/51337 166 // Marked as FLAKY due to http://crbug.com/51337
164 // 167 //
165 // TODO(satish): Once this flakiness has been fixed, add a second test here to 168 // TODO(satish): Once this flakiness has been fixed, add a second test here to
166 // check for sending many clicks in succession to the speech button and verify 169 // check for sending many clicks in succession to the speech button and verify
167 // that it doesn't cause any crash but works as expected. This should act as the 170 // that it doesn't cause any crash but works as expected. This should act as the
168 // test for http://crbug.com/59173 171 // test for http://crbug.com/59173
172 //
173 // TODO(satish): Similar to above, once this flakiness has been fixed add
174 // another test here to check that when speech recognition is in progress and
175 // the a renderer crashes, we get a call to
176 // SpeechInputManager::CancelAllRequestsWithDelegate.
169 #if defined(OS_WIN) 177 #if defined(OS_WIN)
170 #define MAYBE_TestBasicRecognition FLAKY_TestBasicRecognition 178 #define MAYBE_TestBasicRecognition FLAKY_TestBasicRecognition
171 #else 179 #else
172 #define MAYBE_TestBasicRecognition TestBasicRecognition 180 #define MAYBE_TestBasicRecognition TestBasicRecognition
173 #endif 181 #endif
174 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) { 182 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) {
175 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); 183 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html"));
176 EXPECT_TRUE(fake_speech_input_manager_.grammar().empty()); 184 EXPECT_TRUE(fake_speech_input_manager_.grammar().empty());
177 } 185 }
178 186
179 // Marked as FLAKY due to http://crbug.com/51337 187 // Marked as FLAKY due to http://crbug.com/51337
180 #if defined(OS_WIN) 188 #if defined(OS_WIN)
181 #define MAYBE_GrammarAttribute FLAKY_GrammarAttribute 189 #define MAYBE_GrammarAttribute FLAKY_GrammarAttribute
182 #else 190 #else
183 #define MAYBE_GrammarAttribute GrammarAttribute 191 #define MAYBE_GrammarAttribute GrammarAttribute
184 #endif 192 #endif
185 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_GrammarAttribute) { 193 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_GrammarAttribute) {
186 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html")); 194 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html"));
187 EXPECT_EQ("http://example.com/grammar.xml", 195 EXPECT_EQ("http://example.com/grammar.xml",
188 fake_speech_input_manager_.grammar()); 196 fake_speech_input_manager_.grammar());
189 } 197 }
190 198
191 } // namespace speech_input 199 } // namespace speech_input
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698