OLD | NEW |
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 #include "content/shell/renderer/test_runner/mock_web_speech_recognizer.h" | 5 #include "content/shell/renderer/test_runner/mock_web_speech_recognizer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/shell/renderer/test_runner/web_test_delegate.h" | 8 #include "content/shell/renderer/test_runner/web_test_delegate.h" |
9 #include "third_party/WebKit/public/web/WebSpeechRecognitionResult.h" | 9 #include "third_party/WebKit/public/web/WebSpeechRecognitionResult.h" |
10 #include "third_party/WebKit/public/web/WebSpeechRecognizerClient.h" | 10 #include "third_party/WebKit/public/web/WebSpeechRecognizerClient.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Task class for calling a client function that does not take any parameters. | 16 // Task class for calling a client function that does not take any parameters. |
17 typedef void (blink::WebSpeechRecognizerClient::*ClientFunctionPointer)( | 17 typedef void (blink::WebSpeechRecognizerClient::*ClientFunctionPointer)( |
18 const blink::WebSpeechRecognitionHandle&); | 18 const blink::WebSpeechRecognitionHandle&); |
19 class ClientCallTask : public MockWebSpeechRecognizer::Task { | 19 class ClientCallTask : public MockWebSpeechRecognizer::Task { |
20 public: | 20 public: |
21 ClientCallTask(MockWebSpeechRecognizer* mock, ClientFunctionPointer function) | 21 ClientCallTask(MockWebSpeechRecognizer* mock, ClientFunctionPointer function) |
22 : MockWebSpeechRecognizer::Task(mock), function_(function) {} | 22 : MockWebSpeechRecognizer::Task(mock), function_(function) {} |
23 | 23 |
24 virtual ~ClientCallTask() {} | 24 virtual ~ClientCallTask() {} |
25 | 25 |
26 virtual void run() OVERRIDE { | 26 virtual void run() override { |
27 (recognizer_->Client()->*function_)(recognizer_->Handle()); | 27 (recognizer_->Client()->*function_)(recognizer_->Handle()); |
28 } | 28 } |
29 | 29 |
30 private: | 30 private: |
31 ClientFunctionPointer function_; | 31 ClientFunctionPointer function_; |
32 | 32 |
33 DISALLOW_COPY_AND_ASSIGN(ClientCallTask); | 33 DISALLOW_COPY_AND_ASSIGN(ClientCallTask); |
34 }; | 34 }; |
35 | 35 |
36 // Task for delivering a result event. | 36 // Task for delivering a result event. |
37 class ResultTask : public MockWebSpeechRecognizer::Task { | 37 class ResultTask : public MockWebSpeechRecognizer::Task { |
38 public: | 38 public: |
39 ResultTask(MockWebSpeechRecognizer* mock, | 39 ResultTask(MockWebSpeechRecognizer* mock, |
40 const blink::WebString transcript, | 40 const blink::WebString transcript, |
41 float confidence) | 41 float confidence) |
42 : MockWebSpeechRecognizer::Task(mock), | 42 : MockWebSpeechRecognizer::Task(mock), |
43 transcript_(transcript), | 43 transcript_(transcript), |
44 confidence_(confidence) {} | 44 confidence_(confidence) {} |
45 | 45 |
46 virtual ~ResultTask() {} | 46 virtual ~ResultTask() {} |
47 | 47 |
48 virtual void run() OVERRIDE { | 48 virtual void run() override { |
49 blink::WebVector<blink::WebString> transcripts(static_cast<size_t>(1)); | 49 blink::WebVector<blink::WebString> transcripts(static_cast<size_t>(1)); |
50 blink::WebVector<float> confidences(static_cast<size_t>(1)); | 50 blink::WebVector<float> confidences(static_cast<size_t>(1)); |
51 transcripts[0] = transcript_; | 51 transcripts[0] = transcript_; |
52 confidences[0] = confidence_; | 52 confidences[0] = confidence_; |
53 blink::WebVector<blink::WebSpeechRecognitionResult> final_results( | 53 blink::WebVector<blink::WebSpeechRecognitionResult> final_results( |
54 static_cast<size_t>(1)); | 54 static_cast<size_t>(1)); |
55 blink::WebVector<blink::WebSpeechRecognitionResult> interim_results; | 55 blink::WebVector<blink::WebSpeechRecognitionResult> interim_results; |
56 final_results[0].assign(transcripts, confidences, true); | 56 final_results[0].assign(transcripts, confidences, true); |
57 | 57 |
58 recognizer_->Client()->didReceiveResults( | 58 recognizer_->Client()->didReceiveResults( |
59 recognizer_->Handle(), final_results, interim_results); | 59 recognizer_->Handle(), final_results, interim_results); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 blink::WebString transcript_; | 63 blink::WebString transcript_; |
64 float confidence_; | 64 float confidence_; |
65 | 65 |
66 DISALLOW_COPY_AND_ASSIGN(ResultTask); | 66 DISALLOW_COPY_AND_ASSIGN(ResultTask); |
67 }; | 67 }; |
68 | 68 |
69 // Task for delivering a nomatch event. | 69 // Task for delivering a nomatch event. |
70 class NoMatchTask : public MockWebSpeechRecognizer::Task { | 70 class NoMatchTask : public MockWebSpeechRecognizer::Task { |
71 public: | 71 public: |
72 NoMatchTask(MockWebSpeechRecognizer* mock) | 72 NoMatchTask(MockWebSpeechRecognizer* mock) |
73 : MockWebSpeechRecognizer::Task(mock) {} | 73 : MockWebSpeechRecognizer::Task(mock) {} |
74 | 74 |
75 virtual ~NoMatchTask() {} | 75 virtual ~NoMatchTask() {} |
76 | 76 |
77 virtual void run() OVERRIDE { | 77 virtual void run() override { |
78 recognizer_->Client()->didReceiveNoMatch( | 78 recognizer_->Client()->didReceiveNoMatch( |
79 recognizer_->Handle(), blink::WebSpeechRecognitionResult()); | 79 recognizer_->Handle(), blink::WebSpeechRecognitionResult()); |
80 } | 80 } |
81 | 81 |
82 private: | 82 private: |
83 DISALLOW_COPY_AND_ASSIGN(NoMatchTask); | 83 DISALLOW_COPY_AND_ASSIGN(NoMatchTask); |
84 }; | 84 }; |
85 | 85 |
86 // Task for delivering an error event. | 86 // Task for delivering an error event. |
87 class ErrorTask : public MockWebSpeechRecognizer::Task { | 87 class ErrorTask : public MockWebSpeechRecognizer::Task { |
88 public: | 88 public: |
89 ErrorTask(MockWebSpeechRecognizer* mock, | 89 ErrorTask(MockWebSpeechRecognizer* mock, |
90 blink::WebSpeechRecognizerClient::ErrorCode code, | 90 blink::WebSpeechRecognizerClient::ErrorCode code, |
91 const blink::WebString& message) | 91 const blink::WebString& message) |
92 : MockWebSpeechRecognizer::Task(mock), code_(code), message_(message) {} | 92 : MockWebSpeechRecognizer::Task(mock), code_(code), message_(message) {} |
93 | 93 |
94 virtual ~ErrorTask() {} | 94 virtual ~ErrorTask() {} |
95 | 95 |
96 virtual void run() OVERRIDE { | 96 virtual void run() override { |
97 recognizer_->Client()->didReceiveError( | 97 recognizer_->Client()->didReceiveError( |
98 recognizer_->Handle(), message_, code_); | 98 recognizer_->Handle(), message_, code_); |
99 } | 99 } |
100 | 100 |
101 private: | 101 private: |
102 blink::WebSpeechRecognizerClient::ErrorCode code_; | 102 blink::WebSpeechRecognizerClient::ErrorCode code_; |
103 blink::WebString message_; | 103 blink::WebString message_; |
104 | 104 |
105 DISALLOW_COPY_AND_ASSIGN(ErrorTask); | 105 DISALLOW_COPY_AND_ASSIGN(ErrorTask); |
106 }; | 106 }; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 if (object_->task_queue_.empty()) { | 245 if (object_->task_queue_.empty()) { |
246 object_->task_queue_running_ = false; | 246 object_->task_queue_running_ = false; |
247 return; | 247 return; |
248 } | 248 } |
249 | 249 |
250 object_->delegate_->PostTask(new StepTask(object_)); | 250 object_->delegate_->PostTask(new StepTask(object_)); |
251 } | 251 } |
252 | 252 |
253 } // namespace content | 253 } // namespace content |
OLD | NEW |