Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 EXPECT_EQ(delegate_, delegate); | |
| 76 } | |
| 73 | 77 |
| 74 private: | 78 private: |
| 75 void SetFakeRecognitionResult() { | 79 void SetFakeRecognitionResult() { |
| 76 if (caller_id_) { // Do a check in case we were cancelled.. | 80 if (caller_id_) { // Do a check in case we were cancelled.. |
| 77 VLOG(1) << "Setting fake recognition result."; | 81 VLOG(1) << "Setting fake recognition result."; |
| 78 delegate_->DidCompleteRecording(caller_id_); | 82 delegate_->DidCompleteRecording(caller_id_); |
| 79 SpeechInputResultArray results; | 83 SpeechInputResultArray results; |
| 80 results.push_back(SpeechInputResultItem(ASCIIToUTF16(kTestResult), 1.0)); | 84 results.push_back(SpeechInputResultItem(ASCIIToUTF16(kTestResult), 1.0)); |
| 81 delegate_->SetRecognitionResult(caller_id_, results); | 85 delegate_->SetRecognitionResult(caller_id_, results); |
| 82 delegate_->DidCompleteRecognition(caller_id_); | 86 delegate_->DidCompleteRecognition(caller_id_); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 }; | 163 }; |
| 160 | 164 |
| 161 SpeechInputManager* SpeechInputBrowserTest::speech_input_manager_ = NULL; | 165 SpeechInputManager* SpeechInputBrowserTest::speech_input_manager_ = NULL; |
| 162 | 166 |
| 163 // Marked as FLAKY due to http://crbug.com/51337 | 167 // Marked as FLAKY due to http://crbug.com/51337 |
| 164 // | 168 // |
| 165 // 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 |
| 166 // 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 |
| 167 // 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 |
| 168 // 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 // the a renderer crashes, we get a call to | |
|
bulach
2011/01/20 14:47:20
s/the //
Satish
2011/01/20 15:09:03
Done.
| |
| 177 // SpeechInputManager::CancelAllRequestsWithDelegate. | |
| 169 #if defined(OS_WIN) | 178 #if defined(OS_WIN) |
| 170 #define MAYBE_TestBasicRecognition FLAKY_TestBasicRecognition | 179 #define MAYBE_TestBasicRecognition FLAKY_TestBasicRecognition |
| 171 #else | 180 #else |
| 172 #define MAYBE_TestBasicRecognition TestBasicRecognition | 181 #define MAYBE_TestBasicRecognition TestBasicRecognition |
| 173 #endif | 182 #endif |
| 174 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) { | 183 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) { |
| 175 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); | 184 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); |
| 176 EXPECT_TRUE(fake_speech_input_manager_.grammar().empty()); | 185 EXPECT_TRUE(fake_speech_input_manager_.grammar().empty()); |
| 177 } | 186 } |
| 178 | 187 |
| 179 // Marked as FLAKY due to http://crbug.com/51337 | 188 // Marked as FLAKY due to http://crbug.com/51337 |
| 180 #if defined(OS_WIN) | 189 #if defined(OS_WIN) |
| 181 #define MAYBE_GrammarAttribute FLAKY_GrammarAttribute | 190 #define MAYBE_GrammarAttribute FLAKY_GrammarAttribute |
| 182 #else | 191 #else |
| 183 #define MAYBE_GrammarAttribute GrammarAttribute | 192 #define MAYBE_GrammarAttribute GrammarAttribute |
| 184 #endif | 193 #endif |
| 185 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_GrammarAttribute) { | 194 IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_GrammarAttribute) { |
| 186 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html")); | 195 LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html")); |
| 187 EXPECT_EQ("http://example.com/grammar.xml", | 196 EXPECT_EQ("http://example.com/grammar.xml", |
| 188 fake_speech_input_manager_.grammar()); | 197 fake_speech_input_manager_.grammar()); |
| 189 } | 198 } |
| 190 | 199 |
| 191 } // namespace speech_input | 200 } // namespace speech_input |
| OLD | NEW |