OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ | |
6 #define COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ | |
7 | |
8 #include <deque> | |
9 #include <vector> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" | |
14 | |
15 namespace blink { | |
16 class WebSpeechRecognitionHandle; | |
17 class WebSpeechRecognitionParams; | |
18 class WebSpeechRecognizerClient; | |
19 class WebString; | |
20 } | |
21 | |
22 namespace test_runner { | |
23 | |
24 class WebTestDelegate; | |
25 | |
26 class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer { | |
27 public: | |
28 MockWebSpeechRecognizer(); | |
29 ~MockWebSpeechRecognizer() override; | |
30 | |
31 void SetDelegate(WebTestDelegate* delegate); | |
32 | |
33 // WebSpeechRecognizer implementation: | |
34 void start(const blink::WebSpeechRecognitionHandle& handle, | |
35 const blink::WebSpeechRecognitionParams& params, | |
36 blink::WebSpeechRecognizerClient* client) override; | |
37 void stop(const blink::WebSpeechRecognitionHandle& handle, | |
38 blink::WebSpeechRecognizerClient* client) override; | |
39 void abort(const blink::WebSpeechRecognitionHandle& handle, | |
40 blink::WebSpeechRecognizerClient* client) override; | |
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 | |
51 void SetClientContext(const blink::WebSpeechRecognitionHandle&, | |
52 blink::WebSpeechRecognizerClient*); | |
53 | |
54 class Task { | |
55 public: | |
56 Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {} | |
57 virtual ~Task() {} | |
58 virtual void run() = 0; | |
59 virtual bool isNewContextTask() const; | |
60 | |
61 protected: | |
62 MockWebSpeechRecognizer* recognizer_; | |
63 | |
64 private: | |
65 DISALLOW_COPY_AND_ASSIGN(Task); | |
66 }; | |
67 | |
68 private: | |
69 void StartTaskQueue(); | |
70 void ClearTaskQueue(); | |
71 void PostRunTaskFromQueue(); | |
72 void RunTaskFromQueue(); | |
73 | |
74 bool HasPendingNewContextTasks() const; | |
75 | |
76 blink::WebSpeechRecognitionHandle handle_; | |
77 blink::WebSpeechRecognizerClient* client_; | |
78 std::vector<blink::WebString> mock_transcripts_; | |
79 std::vector<float> mock_confidences_; | |
80 bool was_aborted_; | |
81 | |
82 // Queue of tasks to be run. | |
83 std::deque<Task*> task_queue_; | |
84 bool task_queue_running_; | |
85 | |
86 WebTestDelegate* delegate_; | |
87 | |
88 base::WeakPtrFactory<MockWebSpeechRecognizer> weak_factory_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer); | |
91 }; | |
92 | |
93 } // namespace test_runner | |
94 | |
95 #endif // COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ | |
OLD | NEW |