OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ |
| 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "content/shell/renderer/test_runner/TestCommon.h" |
| 13 #include "content/shell/renderer/test_runner/WebTask.h" |
| 14 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" |
| 15 |
| 16 namespace blink { |
| 17 class WebSpeechRecognitionHandle; |
| 18 class WebSpeechRecognitionParams; |
| 19 class WebSpeechRecognizerClient; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 |
| 24 class WebTestDelegate; |
| 25 |
| 26 class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer { |
| 27 public: |
| 28 MockWebSpeechRecognizer(); |
| 29 virtual ~MockWebSpeechRecognizer(); |
| 30 |
| 31 void SetDelegate(WebTestDelegate* delegate); |
| 32 |
| 33 // WebSpeechRecognizer implementation: |
| 34 virtual void start(const blink::WebSpeechRecognitionHandle& handle, |
| 35 const blink::WebSpeechRecognitionParams& params, |
| 36 blink::WebSpeechRecognizerClient* client); |
| 37 virtual void stop(const blink::WebSpeechRecognitionHandle& handle, |
| 38 blink::WebSpeechRecognizerClient* client); |
| 39 virtual void abort(const blink::WebSpeechRecognitionHandle& handle, |
| 40 blink::WebSpeechRecognizerClient* client); |
| 41 |
| 42 // Methods accessed by layout tests: |
| 43 void AddMockResult(const blink::WebString& transcript, float confidence); |
| 44 void SetError(const blink::WebString& error, const blink::WebString& message); |
| 45 bool WasAborted() const { return was_aborted_; } |
| 46 |
| 47 // Methods accessed from Task objects: |
| 48 blink::WebSpeechRecognizerClient* Client() { return client_; } |
| 49 blink::WebSpeechRecognitionHandle& Handle() { return handle_; } |
| 50 WebTaskList* mutable_task_list() { return &task_list_; } |
| 51 |
| 52 class Task { |
| 53 public: |
| 54 Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {} |
| 55 virtual ~Task() {} |
| 56 virtual void run() = 0; |
| 57 |
| 58 protected: |
| 59 MockWebSpeechRecognizer* recognizer_; |
| 60 |
| 61 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(Task); |
| 63 }; |
| 64 |
| 65 private: |
| 66 void StartTaskQueue(); |
| 67 void ClearTaskQueue(); |
| 68 |
| 69 WebTaskList task_list_; |
| 70 blink::WebSpeechRecognitionHandle handle_; |
| 71 blink::WebSpeechRecognizerClient* client_; |
| 72 std::vector<blink::WebString> mock_transcripts_; |
| 73 std::vector<float> mock_confidences_; |
| 74 bool was_aborted_; |
| 75 |
| 76 // Queue of tasks to be run. |
| 77 std::deque<Task*> task_queue_; |
| 78 bool task_queue_running_; |
| 79 |
| 80 WebTestDelegate* delegate_; |
| 81 |
| 82 // Task for stepping the queue. |
| 83 class StepTask : public WebMethodTask<MockWebSpeechRecognizer> { |
| 84 public: |
| 85 StepTask(MockWebSpeechRecognizer* object) |
| 86 : WebMethodTask<MockWebSpeechRecognizer>(object) {} |
| 87 virtual void runIfValid() OVERRIDE; |
| 88 |
| 89 private: |
| 90 DISALLOW_COPY_AND_ASSIGN(StepTask); |
| 91 }; |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer); |
| 94 }; |
| 95 |
| 96 } // namespace content |
| 97 |
| 98 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ |
OLD | NEW |