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 MockWebSpeechRecognizer_h |
| 6 #define MockWebSpeechRecognizer_h |
| 7 |
| 8 #include <deque> |
| 9 #include <vector> |
| 10 |
| 11 #include "content/shell/renderer/test_runner/TestCommon.h" |
| 12 #include "content/shell/renderer/test_runner/WebTask.h" |
| 13 #include "third_party/WebKit/public/platform/WebNonCopyable.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 WebTestRunner { |
| 23 |
| 24 class WebTestDelegate; |
| 25 |
| 26 class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer, public blink:
:WebNonCopyable { |
| 27 public: |
| 28 MockWebSpeechRecognizer(); |
| 29 ~MockWebSpeechRecognizer(); |
| 30 |
| 31 void setDelegate(WebTestDelegate*); |
| 32 |
| 33 // WebSpeechRecognizer implementation: |
| 34 virtual void start(const blink::WebSpeechRecognitionHandle&, const blink::We
bSpeechRecognitionParams&, blink::WebSpeechRecognizerClient*) OVERRIDE; |
| 35 virtual void stop(const blink::WebSpeechRecognitionHandle&, blink::WebSpeech
RecognizerClient*) OVERRIDE; |
| 36 virtual void abort(const blink::WebSpeechRecognitionHandle&, blink::WebSpeec
hRecognizerClient*) OVERRIDE; |
| 37 |
| 38 // Methods accessed by layout tests: |
| 39 void addMockResult(const blink::WebString& transcript, float confidence); |
| 40 void setError(const blink::WebString& error, const blink::WebString& message
); |
| 41 bool wasAborted() const { return m_wasAborted; } |
| 42 |
| 43 // Methods accessed from Task objects: |
| 44 blink::WebSpeechRecognizerClient* client() { return m_client; } |
| 45 blink::WebSpeechRecognitionHandle& handle() { return m_handle; } |
| 46 WebTaskList* taskList() { return &m_taskList; } |
| 47 |
| 48 class Task { |
| 49 public: |
| 50 Task(MockWebSpeechRecognizer* recognizer) : m_recognizer(recognizer) { } |
| 51 virtual ~Task() { } |
| 52 virtual void run() = 0; |
| 53 protected: |
| 54 MockWebSpeechRecognizer* m_recognizer; |
| 55 }; |
| 56 |
| 57 private: |
| 58 void startTaskQueue(); |
| 59 void clearTaskQueue(); |
| 60 |
| 61 WebTaskList m_taskList; |
| 62 blink::WebSpeechRecognitionHandle m_handle; |
| 63 blink::WebSpeechRecognizerClient* m_client; |
| 64 std::vector<blink::WebString> m_mockTranscripts; |
| 65 std::vector<float> m_mockConfidences; |
| 66 bool m_wasAborted; |
| 67 |
| 68 // Queue of tasks to be run. |
| 69 std::deque<Task*> m_taskQueue; |
| 70 bool m_taskQueueRunning; |
| 71 |
| 72 WebTestDelegate* m_delegate; |
| 73 |
| 74 // Task for stepping the queue. |
| 75 class StepTask : public WebMethodTask<MockWebSpeechRecognizer> { |
| 76 public: |
| 77 StepTask(MockWebSpeechRecognizer* object) : WebMethodTask<MockWebSpeechR
ecognizer>(object) { } |
| 78 virtual void runIfValid() OVERRIDE; |
| 79 }; |
| 80 }; |
| 81 |
| 82 } |
| 83 |
| 84 #endif // MockWebSpeechRecognizer_h |
OLD | NEW |