1 // Copyright 2014 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.
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
11 #include "base/basictypes.h"
12 #include "content/shell/renderer/test_runner/web_task.h"
13 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h"
16 class WebSpeechRecognitionHandle;
17 class WebSpeechRecognitionParams;
18 class WebSpeechRecognizerClient;
23 class WebTestDelegate;
25 class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer {
27 MockWebSpeechRecognizer();
28 virtual ~MockWebSpeechRecognizer();
30 void SetDelegate(WebTestDelegate* delegate);
32 // WebSpeechRecognizer implementation:
33 virtual void start(const blink::WebSpeechRecognitionHandle& handle,
34 const blink::WebSpeechRecognitionParams& params,
35 blink::WebSpeechRecognizerClient* client);
36 virtual void stop(const blink::WebSpeechRecognitionHandle& handle,
37 blink::WebSpeechRecognizerClient* client);
38 virtual void abort(const blink::WebSpeechRecognitionHandle& handle,
39 blink::WebSpeechRecognizerClient* client);
41 // Methods accessed by layout tests:
42 void AddMockResult(const blink::WebString& transcript, float confidence);
43 void SetError(const blink::WebString& error, const blink::WebString& message);
44 bool WasAborted() const { return was_aborted_; }
46 // Methods accessed from Task objects:
47 blink::WebSpeechRecognizerClient* Client() { return client_; }
48 blink::WebSpeechRecognitionHandle& Handle() { return handle_; }
49 WebTaskList* mutable_task_list() { return &task_list_; }
53 Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {}
55 virtual void run() = 0;
58 MockWebSpeechRecognizer* recognizer_;
61 DISALLOW_COPY_AND_ASSIGN(Task);
65 void StartTaskQueue();
66 void ClearTaskQueue();
68 WebTaskList task_list_;
69 blink::WebSpeechRecognitionHandle handle_;
70 blink::WebSpeechRecognizerClient* client_;
71 std::vector<blink::WebString> mock_transcripts_;
72 std::vector<float> mock_confidences_;
75 // Queue of tasks to be run.
76 std::deque<Task*> task_queue_;
77 bool task_queue_running_;
79 WebTestDelegate* delegate_;
81 // Task for stepping the queue.
82 class StepTask : public WebMethodTask<MockWebSpeechRecognizer> {
84 StepTask(MockWebSpeechRecognizer* object)
85 : WebMethodTask<MockWebSpeechRecognizer>(object) {}
86 void RunIfValid() override;
89 DISALLOW_COPY_AND_ASSIGN(StepTask);
92 DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer);
95 } // namespace content
97 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_