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_
11 #include "base/basictypes.h"
12 #include "components/test_runner/web_task.h"
13 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h"
16 class WebSpeechRecognitionHandle
;
17 class WebSpeechRecognitionParams
;
18 class WebSpeechRecognizerClient
;
22 namespace test_runner
{
24 class WebTestDelegate
;
26 class MockWebSpeechRecognizer
: public blink::WebSpeechRecognizer
{
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_
; }
54 Task(MockWebSpeechRecognizer
* recognizer
) : recognizer_(recognizer
) {}
56 virtual void run() = 0;
59 MockWebSpeechRecognizer
* recognizer_
;
62 DISALLOW_COPY_AND_ASSIGN(Task
);
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_
;
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
> {
85 StepTask(MockWebSpeechRecognizer
* object
)
86 : WebMethodTask
<MockWebSpeechRecognizer
>(object
) {}
87 void RunIfValid() override
;
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_