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_MOCKWEBSPEECHRECOGNIZER_H_ 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBSPEECHRECOGNIZER_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*); 32 33 // WebSpeechRecognizer implementation: 34 virtual void start(const blink::WebSpeechRecognitionHandle&, const blink::WebSpeechRecognitionParams&, blink::WebSpeechRecognizerClient*) OVERRIDE; 35 virtual void stop(const blink::WebSpeechRecognitionHandle&, blink::WebSpeechRecognizerClient*) OVERRIDE; 36 virtual void abort(const blink::WebSpeechRecognitionHandle&, blink::WebSpeechRecognizerClient*) 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* mutable_task_list() { 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<MockWebSpeechRecognizer>(object) { } 78 virtual void runIfValid() OVERRIDE; 79 }; 80 81 DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer); 82 }; 83 84 } // namespace content 85 86 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBSPEECHRECOGNIZER_H_ 87