| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/public/test/fake_speech_recognition_manager.h" | 5 #include "content/public/test/fake_speech_recognition_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/thread_task_runner_handle.h" | |
| 12 #include "content/public/browser/speech_recognition_event_listener.h" | 10 #include "content/public/browser/speech_recognition_event_listener.h" |
| 13 #include "content/public/browser/speech_recognition_manager_delegate.h" | 11 #include "content/public/browser/speech_recognition_manager_delegate.h" |
| 14 #include "content/public/common/speech_recognition_result.h" | 12 #include "content/public/common/speech_recognition_result.h" |
| 15 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 15 |
| 18 namespace { | 16 namespace { |
| 19 const char kTestResult[] = "Pictures of the moon"; | 17 const char kTestResult[] = "Pictures of the moon"; |
| 20 | 18 |
| 21 void RunCallback(const base::Closure recognition_started_closure) { | 19 void RunCallback(const base::Closure recognition_started_closure) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void FakeSpeechRecognitionManager::StartSession(int session_id) { | 72 void FakeSpeechRecognitionManager::StartSession(int session_id) { |
| 75 VLOG(1) << "FAKE StartSession invoked."; | 73 VLOG(1) << "FAKE StartSession invoked."; |
| 76 EXPECT_EQ(session_id, session_id_); | 74 EXPECT_EQ(session_id, session_id_); |
| 77 EXPECT_TRUE(listener_ != NULL); | 75 EXPECT_TRUE(listener_ != NULL); |
| 78 | 76 |
| 79 if (delegate_) | 77 if (delegate_) |
| 80 delegate_->GetEventListener()->OnRecognitionStart(session_id_); | 78 delegate_->GetEventListener()->OnRecognitionStart(session_id_); |
| 81 | 79 |
| 82 if (should_send_fake_response_) { | 80 if (should_send_fake_response_) { |
| 83 // Give the fake result in a short while. | 81 // Give the fake result in a short while. |
| 84 base::ThreadTaskRunnerHandle::Get()->PostTask( | 82 base::MessageLoop::current()->PostTask( |
| 85 FROM_HERE, | 83 FROM_HERE, |
| 86 base::Bind( | 84 base::Bind( |
| 87 &FakeSpeechRecognitionManager::SetFakeRecognitionResult, | 85 &FakeSpeechRecognitionManager::SetFakeRecognitionResult, |
| 88 // This class does not need to be refcounted (typically done by | 86 // This class does not need to be refcounted (typically done by |
| 89 // PostTask) since it will outlive the test and gets released only | 87 // PostTask) since it will outlive the test and gets released only |
| 90 // when the test shuts down. Disabling refcounting here saves a bit | 88 // when the test shuts down. Disabling refcounting here saves a bit |
| 91 // of unnecessary code and the factory method can return a plain | 89 // of unnecessary code and the factory method can return a plain |
| 92 // pointer below as required by the real code. | 90 // pointer below as required by the real code. |
| 93 base::Unretained(this))); | 91 base::Unretained(this))); |
| 94 } | 92 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 SpeechRecognitionResults results; | 162 SpeechRecognitionResults results; |
| 165 results.push_back(result); | 163 results.push_back(result); |
| 166 listener_->OnRecognitionResults(session_id_, results); | 164 listener_->OnRecognitionResults(session_id_, results); |
| 167 listener_->OnRecognitionEnd(session_id_); | 165 listener_->OnRecognitionEnd(session_id_); |
| 168 session_id_ = 0; | 166 session_id_ = 0; |
| 169 listener_ = NULL; | 167 listener_ = NULL; |
| 170 VLOG(1) << "Finished setting fake recognition result."; | 168 VLOG(1) << "Finished setting fake recognition result."; |
| 171 } | 169 } |
| 172 | 170 |
| 173 } // namespace content | 171 } // namespace content |
| OLD | NEW |