| 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
| 9 #include "chrome/browser/speech/speech_input_dispatcher_host.h" | 9 #include "chrome/browser/speech/speech_input_dispatcher_host.h" |
| 10 #include "chrome/browser/speech/speech_input_manager.h" | 10 #include "chrome/browser/speech/speech_input_manager.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Disabling refcounting here saves a bit of unnecessary code and the factory | 22 // Disabling refcounting here saves a bit of unnecessary code and the factory |
| 23 // method can return a plain pointer below as required by the real code. | 23 // method can return a plain pointer below as required by the real code. |
| 24 DISABLE_RUNNABLE_METHOD_REFCOUNT(speech_input::FakeSpeechInputManager); | 24 DISABLE_RUNNABLE_METHOD_REFCOUNT(speech_input::FakeSpeechInputManager); |
| 25 | 25 |
| 26 namespace speech_input { | 26 namespace speech_input { |
| 27 | 27 |
| 28 const char* kTestResult = "Pictures of the moon"; | 28 const char* kTestResult = "Pictures of the moon"; |
| 29 | 29 |
| 30 class FakeSpeechInputManager : public SpeechInputManager { | 30 class FakeSpeechInputManager : public SpeechInputManager { |
| 31 public: | 31 public: |
| 32 explicit FakeSpeechInputManager(Listener* listener) | 32 explicit FakeSpeechInputManager(Delegate* delegate) |
| 33 : render_view_id_(0), | 33 : render_view_id_(0), |
| 34 listener_(listener) { | 34 delegate_(delegate) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 // SpeechInputManager methods. | 37 // SpeechInputManager methods. |
| 38 void StartRecognition(int render_view_id) { | 38 void StartRecognition(int render_view_id) { |
| 39 EXPECT_EQ(0, render_view_id_); | 39 EXPECT_EQ(0, render_view_id_); |
| 40 render_view_id_ = render_view_id; | 40 render_view_id_ = render_view_id; |
| 41 // Give the fake result in a short while. | 41 // Give the fake result in a short while. |
| 42 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, | 42 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 43 &FakeSpeechInputManager::SetFakeRecognitionResult)); | 43 &FakeSpeechInputManager::SetFakeRecognitionResult)); |
| 44 } | 44 } |
| 45 void CancelRecognition(int render_view_id) { | 45 void CancelRecognition(int render_view_id) { |
| 46 EXPECT_EQ(render_view_id_, render_view_id); | 46 EXPECT_EQ(render_view_id_, render_view_id); |
| 47 render_view_id_ = 0; | 47 render_view_id_ = 0; |
| 48 } | 48 } |
| 49 void StopRecording(int render_view_id) { | 49 void StopRecording(int render_view_id) { |
| 50 EXPECT_EQ(render_view_id_, render_view_id); | 50 EXPECT_EQ(render_view_id_, render_view_id); |
| 51 // Nothing to do here since we aren't really recording. | 51 // Nothing to do here since we aren't really recording. |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 void SetFakeRecognitionResult() { | 55 void SetFakeRecognitionResult() { |
| 56 if (render_view_id_) { // Do a check in case we were cancelled.. | 56 if (render_view_id_) { // Do a check in case we were cancelled.. |
| 57 listener_->DidCompleteRecording(render_view_id_); | 57 delegate_->DidCompleteRecording(render_view_id_); |
| 58 listener_->SetRecognitionResult(render_view_id_, | 58 delegate_->SetRecognitionResult(render_view_id_, |
| 59 ASCIIToUTF16(kTestResult)); | 59 ASCIIToUTF16(kTestResult)); |
| 60 listener_->DidCompleteRecognition(render_view_id_); | 60 delegate_->DidCompleteRecognition(render_view_id_); |
| 61 render_view_id_ = 0; | 61 render_view_id_ = 0; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 int render_view_id_; | 65 int render_view_id_; |
| 66 Listener* listener_; | 66 Delegate* delegate_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 // Factory method. | 69 // Factory method. |
| 70 SpeechInputManager* fakeManagerFactory(SpeechInputManager::Listener* listener) { | 70 SpeechInputManager* fakeManagerFactory(SpeechInputManager::Delegate* delegate) { |
| 71 return new FakeSpeechInputManager(listener); | 71 return new FakeSpeechInputManager(delegate); |
| 72 } | 72 } |
| 73 | 73 |
| 74 class SpeechInputBrowserTest : public InProcessBrowserTest { | 74 class SpeechInputBrowserTest : public InProcessBrowserTest { |
| 75 public: | 75 public: |
| 76 // InProcessBrowserTest methods | 76 // InProcessBrowserTest methods |
| 77 virtual void SetUpCommandLine(CommandLine* command_line) { | 77 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 78 command_line->AppendSwitch(switches::kEnableSpeechInput); | 78 command_line->AppendSwitch(switches::kEnableSpeechInput); |
| 79 } | 79 } |
| 80 | 80 |
| 81 GURL testUrl(const FilePath::CharType* filename) { | 81 GURL testUrl(const FilePath::CharType* filename) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 95 GURL test_url = testUrl(FILE_PATH_LITERAL("basic_recognition.html")); | 95 GURL test_url = testUrl(FILE_PATH_LITERAL("basic_recognition.html")); |
| 96 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 96 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
| 97 test_url, | 97 test_url, |
| 98 2); | 98 2); |
| 99 | 99 |
| 100 // Check that the page got the result it expected. | 100 // Check that the page got the result it expected. |
| 101 EXPECT_EQ("pass", browser()->GetSelectedTabContents()->GetURL().ref()); | 101 EXPECT_EQ("pass", browser()->GetSelectedTabContents()->GetURL().ref()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace speech_input | 104 } // namespace speech_input |
| OLD | NEW |