Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: components/test_runner/mock_web_speech_recognizer.h

Issue 1852603002: Replacing most of web_task.h with base::Closure + base::WeakPtrFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-mocks-to-test-runner
Patch Set: Rebasing... Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ 5 #ifndef COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
6 #define COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ 6 #define COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "components/test_runner/web_task.h" 12 #include "base/memory/weak_ptr.h"
13 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" 13 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h"
14 14
15 namespace blink { 15 namespace blink {
16 class WebSpeechRecognitionHandle; 16 class WebSpeechRecognitionHandle;
17 class WebSpeechRecognitionParams; 17 class WebSpeechRecognitionParams;
18 class WebSpeechRecognizerClient; 18 class WebSpeechRecognizerClient;
19 class WebString; 19 class WebString;
20 } 20 }
21 21
22 namespace test_runner { 22 namespace test_runner {
(...skipping 17 matching lines...) Expand all
40 blink::WebSpeechRecognizerClient* client) override; 40 blink::WebSpeechRecognizerClient* client) override;
41 41
42 // Methods accessed by layout tests: 42 // Methods accessed by layout tests:
43 void AddMockResult(const blink::WebString& transcript, float confidence); 43 void AddMockResult(const blink::WebString& transcript, float confidence);
44 void SetError(const blink::WebString& error, const blink::WebString& message); 44 void SetError(const blink::WebString& error, const blink::WebString& message);
45 bool WasAborted() const { return was_aborted_; } 45 bool WasAborted() const { return was_aborted_; }
46 46
47 // Methods accessed from Task objects: 47 // Methods accessed from Task objects:
48 blink::WebSpeechRecognizerClient* Client() { return client_; } 48 blink::WebSpeechRecognizerClient* Client() { return client_; }
49 blink::WebSpeechRecognitionHandle& Handle() { return handle_; } 49 blink::WebSpeechRecognitionHandle& Handle() { return handle_; }
50 WebTaskList* mutable_task_list() { return &task_list_; }
51 50
52 class Task { 51 class Task {
53 public: 52 public:
54 Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {} 53 Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {}
55 virtual ~Task() {} 54 virtual ~Task() {}
56 virtual void run() = 0; 55 virtual void run() = 0;
57 56
58 protected: 57 protected:
59 MockWebSpeechRecognizer* recognizer_; 58 MockWebSpeechRecognizer* recognizer_;
60 59
61 private: 60 private:
62 DISALLOW_COPY_AND_ASSIGN(Task); 61 DISALLOW_COPY_AND_ASSIGN(Task);
63 }; 62 };
64 63
65 private: 64 private:
66 void StartTaskQueue(); 65 void StartTaskQueue();
67 void ClearTaskQueue(); 66 void ClearTaskQueue();
67 void PostRunTaskFromQueue();
68 void RunTaskFromQueue();
68 69
69 WebTaskList task_list_;
70 blink::WebSpeechRecognitionHandle handle_; 70 blink::WebSpeechRecognitionHandle handle_;
71 blink::WebSpeechRecognizerClient* client_; 71 blink::WebSpeechRecognizerClient* client_;
72 std::vector<blink::WebString> mock_transcripts_; 72 std::vector<blink::WebString> mock_transcripts_;
73 std::vector<float> mock_confidences_; 73 std::vector<float> mock_confidences_;
74 bool was_aborted_; 74 bool was_aborted_;
75 75
76 // Queue of tasks to be run. 76 // Queue of tasks to be run.
77 std::deque<Task*> task_queue_; 77 std::deque<Task*> task_queue_;
78 bool task_queue_running_; 78 bool task_queue_running_;
79 79
80 WebTestDelegate* delegate_; 80 WebTestDelegate* delegate_;
81 81
82 // Task for stepping the queue. 82 base::WeakPtrFactory<MockWebSpeechRecognizer> weak_factory_;
83 class StepTask : public WebMethodTask<MockWebSpeechRecognizer> {
84 public:
85 StepTask(MockWebSpeechRecognizer* object)
86 : WebMethodTask<MockWebSpeechRecognizer>(object) {}
87 void RunIfValid() override;
88
89 private:
90 DISALLOW_COPY_AND_ASSIGN(StepTask);
91 };
92 83
93 DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer); 84 DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer);
94 }; 85 };
95 86
96 } // namespace test_runner 87 } // namespace test_runner
97 88
98 #endif // COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_ 89 #endif // COMPONENTS_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
OLDNEW
« no previous file with comments | « components/test_runner/mock_web_midi_accessor.cc ('k') | components/test_runner/mock_web_speech_recognizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698