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

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
« no previous file with comments | « no previous file | chrome/browser/speech/speech_input_dispatcher_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const std::string& origin_url) { 52 const std::string& origin_url) {
53 VLOG(1) << "StartRecognition invoked."; 53 VLOG(1) << "StartRecognition invoked.";
54 EXPECT_EQ(0, caller_id_); 54 EXPECT_EQ(0, caller_id_);
55 EXPECT_EQ(NULL, delegate_); 55 EXPECT_EQ(NULL, delegate_);
56 caller_id_ = caller_id; 56 caller_id_ = caller_id;
57 delegate_ = delegate; 57 delegate_ = delegate;
58 grammar_ = grammar; 58 grammar_ = grammar;
59 // Give the fake result in a short while. 59 // Give the fake result in a short while.
60 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, 60 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
61 &FakeSpeechInputManager::SetFakeRecognitionResult)); 61 &FakeSpeechInputManager::SetFakeRecognitionResult));
62 } 62 }
63 void CancelRecognition(int caller_id) { 63 virtual void CancelRecognition(int caller_id) {
64 VLOG(1) << "CancelRecognition invoked."; 64 VLOG(1) << "CancelRecognition invoked.";
65 EXPECT_EQ(caller_id_, caller_id); 65 EXPECT_EQ(caller_id_, caller_id);
66 caller_id_ = 0; 66 caller_id_ = 0;
67 delegate_ = NULL; 67 delegate_ = NULL;
68 } 68 }
69 void StopRecording(int caller_id) { 69 virtual void StopRecording(int caller_id) {
70 VLOG(1) << "StopRecording invoked."; 70 VLOG(1) << "StopRecording invoked.";
71 EXPECT_EQ(caller_id_, caller_id); 71 EXPECT_EQ(caller_id_, caller_id);
72 // Nothing to do here since we aren't really recording. 72 // Nothing to do here since we aren't really recording.
73 } 73 }
74 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) {
75 VLOG(1) << "CancelAllRequestsWithDelegate invoked.";
76 }
74 77
75 private: 78 private:
76 void SetFakeRecognitionResult() { 79 void SetFakeRecognitionResult() {
77 if (caller_id_) { // Do a check in case we were cancelled.. 80 if (caller_id_) { // Do a check in case we were cancelled..
78 VLOG(1) << "Setting fake recognition result."; 81 VLOG(1) << "Setting fake recognition result.";
79 delegate_->DidCompleteRecording(caller_id_); 82 delegate_->DidCompleteRecording(caller_id_);
80 SpeechInputResultArray results; 83 SpeechInputResultArray results;
81 results.push_back(SpeechInputResultItem(ASCIIToUTF16(kTestResult), 1.0)); 84 results.push_back(SpeechInputResultItem(ASCIIToUTF16(kTestResult), 1.0));
82 delegate_->SetRecognitionResult(caller_id_, results); 85 delegate_->SetRecognitionResult(caller_id_, results);
83 delegate_->DidCompleteRecognition(caller_id_); 86 delegate_->DidCompleteRecognition(caller_id_);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 }; 163 };
161 164
162 SpeechInputManager* SpeechInputBrowserTest::speech_input_manager_ = NULL; 165 SpeechInputManager* SpeechInputBrowserTest::speech_input_manager_ = NULL;
163 166
164 // Marked as FLAKY due to http://crbug.com/51337 167 // Marked as FLAKY due to http://crbug.com/51337
165 // 168 //
166 // TODO(satish): Once this flakiness has been fixed, add a second test here to 169 // TODO(satish): Once this flakiness has been fixed, add a second test here to
167 // check for sending many clicks in succession to the speech button and verify 170 // check for sending many clicks in succession to the speech button and verify
168 // that it doesn't cause any crash but works as expected. This should act as the 171 // that it doesn't cause any crash but works as expected. This should act as the
169 // test for http://crbug.com/59173 172 // test for http://crbug.com/59173
173 //
174 // TODO(satish): Similar to above, once this flakiness has been fixed add
175 // another test here to check that when speech recognition is in progress and
176 // a renderer crashes, we get a call to
177 // SpeechInputManager::CancelAllRequestsWithDelegate.
170 #if defined(OS_WIN) 178 #if defined(OS_WIN)
171 #define MAYBE_TestBasicRecognition FLAKY_TestBasicRecognition 179 #define MAYBE_TestBasicRecognition FLAKY_TestBasicRecognition
172 #else 180 #else
173 #define MAYBE_TestBasicRecognition TestBasicRecognition 181 #define MAYBE_TestBasicRecognition TestBasicRecognition
174 #endif 182 #endif
175 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) { 183 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) {
176 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); 184 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html"));
177 EXPECT_TRUE(fake_speech_input_manager_.grammar().empty()); 185 EXPECT_TRUE(fake_speech_input_manager_.grammar().empty());
178 } 186 }
179 187
180 // Marked as FLAKY due to http://crbug.com/51337 188 // Marked as FLAKY due to http://crbug.com/51337
181 #if defined(OS_WIN) 189 #if defined(OS_WIN)
182 #define MAYBE_GrammarAttribute FLAKY_GrammarAttribute 190 #define MAYBE_GrammarAttribute FLAKY_GrammarAttribute
183 #else 191 #else
184 #define MAYBE_GrammarAttribute GrammarAttribute 192 #define MAYBE_GrammarAttribute GrammarAttribute
185 #endif 193 #endif
186 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_GrammarAttribute) { 194 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_GrammarAttribute) {
187 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html")); 195 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html"));
188 EXPECT_EQ("http://example.com/grammar.xml", 196 EXPECT_EQ("http://example.com/grammar.xml",
189 fake_speech_input_manager_.grammar()); 197 fake_speech_input_manager_.grammar());
190 } 198 }
191 199
192 } // namespace speech_input 200 } // namespace speech_input
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/speech/speech_input_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698