| 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 "components/test_runner/mock_web_speech_recognizer.h" | 5 #include "components/test_runner/mock_web_speech_recognizer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "components/test_runner/web_task.h" | |
| 14 #include "components/test_runner/web_test_delegate.h" | 13 #include "components/test_runner/web_test_delegate.h" |
| 15 #include "third_party/WebKit/public/web/WebSpeechRecognitionResult.h" | 14 #include "third_party/WebKit/public/web/WebSpeechRecognitionResult.h" |
| 16 #include "third_party/WebKit/public/web/WebSpeechRecognizerClient.h" | 15 #include "third_party/WebKit/public/web/WebSpeechRecognizerClient.h" |
| 17 | 16 |
| 18 namespace test_runner { | 17 namespace test_runner { |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 // Task class for calling a client function that does not take any parameters. | 21 // Task class for calling a client function that does not take any parameters. |
| 23 typedef void (blink::WebSpeechRecognizerClient::*ClientFunctionPointer)( | 22 typedef void (blink::WebSpeechRecognizerClient::*ClientFunctionPointer)( |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 void MockWebSpeechRecognizer::ClearTaskQueue() { | 249 void MockWebSpeechRecognizer::ClearTaskQueue() { |
| 251 while (!task_queue_.empty()) { | 250 while (!task_queue_.empty()) { |
| 252 delete task_queue_.front(); | 251 delete task_queue_.front(); |
| 253 task_queue_.pop_front(); | 252 task_queue_.pop_front(); |
| 254 } | 253 } |
| 255 task_queue_running_ = false; | 254 task_queue_running_ = false; |
| 256 } | 255 } |
| 257 | 256 |
| 258 void MockWebSpeechRecognizer::PostRunTaskFromQueue() { | 257 void MockWebSpeechRecognizer::PostRunTaskFromQueue() { |
| 259 task_queue_running_ = true; | 258 task_queue_running_ = true; |
| 260 delegate_->PostTask(new WebCallbackTask(base::Bind( | 259 delegate_->PostTask(base::Bind(&MockWebSpeechRecognizer::RunTaskFromQueue, |
| 261 &MockWebSpeechRecognizer::RunTaskFromQueue, weak_factory_.GetWeakPtr()))); | 260 weak_factory_.GetWeakPtr())); |
| 262 } | 261 } |
| 263 | 262 |
| 264 void MockWebSpeechRecognizer::RunTaskFromQueue() { | 263 void MockWebSpeechRecognizer::RunTaskFromQueue() { |
| 265 if (task_queue_.empty()) { | 264 if (task_queue_.empty()) { |
| 266 task_queue_running_ = false; | 265 task_queue_running_ = false; |
| 267 return; | 266 return; |
| 268 } | 267 } |
| 269 | 268 |
| 270 MockWebSpeechRecognizer::Task* task = task_queue_.front(); | 269 MockWebSpeechRecognizer::Task* task = task_queue_.front(); |
| 271 task_queue_.pop_front(); | 270 task_queue_.pop_front(); |
| 272 task->run(); | 271 task->run(); |
| 273 delete task; | 272 delete task; |
| 274 | 273 |
| 275 if (task_queue_.empty()) { | 274 if (task_queue_.empty()) { |
| 276 task_queue_running_ = false; | 275 task_queue_running_ = false; |
| 277 return; | 276 return; |
| 278 } | 277 } |
| 279 | 278 |
| 280 PostRunTaskFromQueue(); | 279 PostRunTaskFromQueue(); |
| 281 } | 280 } |
| 282 | 281 |
| 283 } // namespace test_runner | 282 } // namespace test_runner |
| OLD | NEW |