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

Unified Diff: content/shell/renderer/test_runner/mock_web_speech_recognizer.h

Issue 429953002: test_runner: Migrate MockWebSpeechRecognizer to Chromium C++ style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/shell/renderer/test_runner/mock_web_speech_recognizer.h
diff --git a/content/shell/renderer/test_runner/mock_web_speech_recognizer.h b/content/shell/renderer/test_runner/mock_web_speech_recognizer.h
new file mode 100644
index 0000000000000000000000000000000000000000..9c9f5e632dc04b794624a3fc56258ad3c28a958b
--- /dev/null
+++ b/content/shell/renderer/test_runner/mock_web_speech_recognizer.h
@@ -0,0 +1,98 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
+#define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_
+
+#include <deque>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "content/shell/renderer/test_runner/TestCommon.h"
+#include "content/shell/renderer/test_runner/WebTask.h"
+#include "third_party/WebKit/public/web/WebSpeechRecognizer.h"
+
+namespace blink {
+class WebSpeechRecognitionHandle;
+class WebSpeechRecognitionParams;
+class WebSpeechRecognizerClient;
+}
+
+namespace content {
+
+class WebTestDelegate;
+
+class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer {
+ public:
+ MockWebSpeechRecognizer();
+ virtual ~MockWebSpeechRecognizer();
+
+ void SetDelegate(WebTestDelegate* delegate);
+
+ // WebSpeechRecognizer implementation:
+ virtual void start(const blink::WebSpeechRecognitionHandle& handle,
+ const blink::WebSpeechRecognitionParams& params,
+ blink::WebSpeechRecognizerClient* client);
+ virtual void stop(const blink::WebSpeechRecognitionHandle& handle,
+ blink::WebSpeechRecognizerClient* client);
+ virtual void abort(const blink::WebSpeechRecognitionHandle& handle,
+ blink::WebSpeechRecognizerClient* client);
+
+ // Methods accessed by layout tests:
+ void AddMockResult(const blink::WebString& transcript, float confidence);
+ void SetError(const blink::WebString& error, const blink::WebString& message);
+ bool WasAborted() const { return was_aborted_; }
+
+ // Methods accessed from Task objects:
+ blink::WebSpeechRecognizerClient* Client() { return client_; }
+ blink::WebSpeechRecognitionHandle& Handle() { return handle_; }
+ WebTaskList* mutable_task_list() { return &task_list_; }
+
+ class Task {
+ public:
+ Task(MockWebSpeechRecognizer* recognizer) : recognizer_(recognizer) {}
+ virtual ~Task() {}
+ virtual void run() = 0;
+
+ protected:
+ MockWebSpeechRecognizer* recognizer_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Task);
+ };
+
+ private:
+ void StartTaskQueue();
+ void ClearTaskQueue();
+
+ WebTaskList task_list_;
+ blink::WebSpeechRecognitionHandle handle_;
+ blink::WebSpeechRecognizerClient* client_;
+ std::vector<blink::WebString> mock_transcripts_;
+ std::vector<float> mock_confidences_;
+ bool was_aborted_;
+
+ // Queue of tasks to be run.
+ std::deque<Task*> task_queue_;
+ bool task_queue_running_;
+
+ WebTestDelegate* delegate_;
+
+ // Task for stepping the queue.
+ class StepTask : public WebMethodTask<MockWebSpeechRecognizer> {
+ public:
+ StepTask(MockWebSpeechRecognizer* object)
+ : WebMethodTask<MockWebSpeechRecognizer>(object) {}
+ virtual void runIfValid() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(StepTask);
+ };
+
+ DISALLOW_COPY_AND_ASSIGN(MockWebSpeechRecognizer);
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_SPEECH_RECOGNIZER_H_

Powered by Google App Engine
This is Rietveld 408576698