| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 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 /* |
| 6 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions |
| 10 * are met: |
| 11 * |
| 12 * 1. Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. |
| 14 * 2. Redistributions in binary form must reproduce the above copyright |
| 15 * notice, this list of conditions and the following disclaimer in the |
| 16 * documentation and/or other materials provided with the distribution. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ |
| 29 |
| 30 #ifndef MockWebSpeechRecognizer_h |
| 31 #define MockWebSpeechRecognizer_h |
| 32 |
| 33 #include <deque> |
| 34 #include <vector> |
| 35 |
| 36 #include "content/public/test/layout_tests/WebTask.h" |
| 37 #include "content/test/layout_tests/runner/TestCommon.h" |
| 38 #include "third_party/WebKit/public/platform/WebNonCopyable.h" |
| 39 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" |
| 40 |
| 41 namespace blink { |
| 42 class WebSpeechRecognitionHandle; |
| 43 class WebSpeechRecognitionParams; |
| 44 class WebSpeechRecognizerClient; |
| 45 } |
| 46 |
| 47 namespace WebTestRunner { |
| 48 |
| 49 class WebTestDelegate; |
| 50 |
| 51 class MockWebSpeechRecognizer : public blink::WebSpeechRecognizer, public blink:
:WebNonCopyable { |
| 52 public: |
| 53 MockWebSpeechRecognizer(); |
| 54 ~MockWebSpeechRecognizer(); |
| 55 |
| 56 void setDelegate(WebTestDelegate*); |
| 57 |
| 58 // WebSpeechRecognizer implementation: |
| 59 virtual void start(const blink::WebSpeechRecognitionHandle&, const blink::We
bSpeechRecognitionParams&, blink::WebSpeechRecognizerClient*) OVERRIDE; |
| 60 virtual void stop(const blink::WebSpeechRecognitionHandle&, blink::WebSpeech
RecognizerClient*) OVERRIDE; |
| 61 virtual void abort(const blink::WebSpeechRecognitionHandle&, blink::WebSpeec
hRecognizerClient*) OVERRIDE; |
| 62 |
| 63 // Methods accessed by layout tests: |
| 64 void addMockResult(const blink::WebString& transcript, float confidence); |
| 65 void setError(const blink::WebString& error, const blink::WebString& message
); |
| 66 bool wasAborted() const { return m_wasAborted; } |
| 67 |
| 68 // Methods accessed from Task objects: |
| 69 blink::WebSpeechRecognizerClient* client() { return m_client; } |
| 70 blink::WebSpeechRecognitionHandle& handle() { return m_handle; } |
| 71 WebTaskList* taskList() { return &m_taskList; } |
| 72 |
| 73 class Task { |
| 74 public: |
| 75 Task(MockWebSpeechRecognizer* recognizer) : m_recognizer(recognizer) { } |
| 76 virtual ~Task() { } |
| 77 virtual void run() = 0; |
| 78 protected: |
| 79 MockWebSpeechRecognizer* m_recognizer; |
| 80 }; |
| 81 |
| 82 private: |
| 83 void startTaskQueue(); |
| 84 void clearTaskQueue(); |
| 85 |
| 86 WebTaskList m_taskList; |
| 87 blink::WebSpeechRecognitionHandle m_handle; |
| 88 blink::WebSpeechRecognizerClient* m_client; |
| 89 std::vector<blink::WebString> m_mockTranscripts; |
| 90 std::vector<float> m_mockConfidences; |
| 91 bool m_wasAborted; |
| 92 |
| 93 // Queue of tasks to be run. |
| 94 std::deque<Task*> m_taskQueue; |
| 95 bool m_taskQueueRunning; |
| 96 |
| 97 WebTestDelegate* m_delegate; |
| 98 |
| 99 // Task for stepping the queue. |
| 100 class StepTask : public WebMethodTask<MockWebSpeechRecognizer> { |
| 101 public: |
| 102 StepTask(MockWebSpeechRecognizer* object) : WebMethodTask<MockWebSpeechR
ecognizer>(object) { } |
| 103 virtual void runIfValid() OVERRIDE; |
| 104 }; |
| 105 }; |
| 106 |
| 107 } |
| 108 |
| 109 #endif // MockWebSpeechRecognizer_h |
| OLD | NEW |