• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
7 
8 #include <deque>
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 #include "content/shell/renderer/test_runner/web_task.h"
13 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h"
14 
15 namespace blink {
16 class WebSpeechRecognitionHandle;
17 class WebSpeechRecognitionParams;
18 class WebSpeechRecognizerClient;
19 }
20 
21 namespace content {
22 
23 class WebTestDelegate;
24 
25 class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer {
26  public:
27   MockWebSpeechRecognizer();
28   virtual ~MockWebSpeechRecognizer();
29 
30   void SetDelegate(WebTestDelegate* delegate);
31 
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);
40 
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);
WasAborted()44   bool WasAborted() const { return was_aborted_; }
45 
46   // Methods accessed from Task objects:
Client()47   blink::WebSpeechRecognizerClient* Client() { return client_; }
Handle()48   blink::WebSpeechRecognitionHandle& Handle() { return handle_; }
mutable_task_list()49   WebTaskList* mutable_task_list() { return &task_list_; }
50 
51   class Task {
52    public:
Task(MockWebSpeechRecognizer * recognizer)53     Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {}
~Task()54     virtual ~Task() {}
55     virtual void run() = 0;
56 
57    protected:
58     MockWebSpeechRecognizer* recognizer_;
59 
60    private:
61     DISALLOW_COPY_AND_ASSIGN(Task);
62   };
63 
64  private:
65   void StartTaskQueue();
66   void ClearTaskQueue();
67 
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_;
73   bool was_aborted_;
74 
75   // Queue of tasks to be run.
76   std::deque<Task*> task_queue_;
77   bool task_queue_running_;
78 
79   WebTestDelegate* delegate_;
80 
81   // Task for stepping the queue.
82   class StepTask : public WebMethodTask<MockWebSpeechRecognizer> {
83    public:
StepTask(MockWebSpeechRecognizer * object)84     StepTask(MockWebSpeechRecognizer* object)
85         : WebMethodTask<MockWebSpeechRecognizer>(object) {}
86     virtual void RunIfValid() OVERRIDE;
87 
88    private:
89     DISALLOW_COPY_AND_ASSIGN(StepTask);
90   };
91 
92   DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer);
93 };
94 
95 }  // namespace content
96 
97 #endif  // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
98