Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / components / test_runner / mock_web_speech_recognizer.h
blob8624660ca32de2ee92836587f85383405904fb87
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 COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
6 #define COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
8 #include <deque>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "components/test_runner/web_task.h"
13 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h"
15 namespace blink {
16 class WebSpeechRecognitionHandle;
17 class WebSpeechRecognitionParams;
18 class WebSpeechRecognizerClient;
19 class WebString;
22 namespace test_runner {
24 class WebTestDelegate;
26 class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer {
27 public:
28 MockWebSpeechRecognizer();
29 virtual ~MockWebSpeechRecognizer();
31 void SetDelegate(WebTestDelegate* delegate);
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);
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_; }
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_; }
52 class Task {
53 public:
54 Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {}
55 virtual ~Task() {}
56 virtual void run() = 0;
58 protected:
59 MockWebSpeechRecognizer* recognizer_;
61 private:
62 DISALLOW_COPY_AND_ASSIGN(Task);
65 private:
66 void StartTaskQueue();
67 void ClearTaskQueue();
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_;
76 // Queue of tasks to be run.
77 std::deque<Task*> task_queue_;
78 bool task_queue_running_;
80 WebTestDelegate* delegate_;
82 // Task for stepping the queue.
83 class StepTask : public WebMethodTask<MockWebSpeechRecognizer> {
84 public:
85 StepTask(MockWebSpeechRecognizer* object)
86 : WebMethodTask<MockWebSpeechRecognizer>(object) {}
87 void RunIfValid() override;
89 private:
90 DISALLOW_COPY_AND_ASSIGN(StepTask);
93 DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer);
96 } // namespace test_runner
98 #endif // COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_