| 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/speech_recognition_event_listener.h" | 11 #include "content/public/browser/speech_recognition_event_listener.h" |
| 11 #include "content/public/common/speech_recognition_result.h" | 12 #include "content/public/common/speech_recognition_result.h" |
| 12 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 const char kTestResult[] = "Pictures of the moon"; | 17 const char kTestResult[] = "Pictures of the moon"; |
| 17 | 18 |
| 18 void RunCallback(const base::Closure recognition_started_closure) { | 19 void RunCallback(const base::Closure recognition_started_closure) { |
| 19 recognition_started_closure.Run(); | 20 recognition_started_closure.Run(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 session_id_ = 0; | 92 session_id_ = 0; |
| 92 listener_ = NULL; | 93 listener_ = NULL; |
| 93 } | 94 } |
| 94 | 95 |
| 95 void FakeSpeechRecognitionManager::StopAudioCaptureForSession(int session_id) { | 96 void FakeSpeechRecognitionManager::StopAudioCaptureForSession(int session_id) { |
| 96 VLOG(1) << "StopRecording invoked."; | 97 VLOG(1) << "StopRecording invoked."; |
| 97 EXPECT_EQ(session_id_, session_id); | 98 EXPECT_EQ(session_id_, session_id); |
| 98 // Nothing to do here since we aren't really recording. | 99 // Nothing to do here since we aren't really recording. |
| 99 } | 100 } |
| 100 | 101 |
| 101 void FakeSpeechRecognitionManager::AbortAllSessionsForRenderProcess( | 102 void FakeSpeechRecognitionManager::AbortAllSessionsForRenderFrame( |
| 102 int render_process_id) { | 103 int render_process_id, int render_frame_id) { |
| 103 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; | 104 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; |
| 104 EXPECT_TRUE(should_send_fake_response_ || | 105 EXPECT_TRUE(should_send_fake_response_ || |
| 105 session_ctx_.render_process_id == render_process_id); | 106 (session_ctx_.render_process_id == render_process_id && |
| 107 session_ctx_.render_frame_id == render_frame_id)); |
| 106 did_cancel_all_ = true; | 108 did_cancel_all_ = true; |
| 107 } | 109 } |
| 108 | 110 |
| 109 void FakeSpeechRecognitionManager::AbortAllSessionsForRenderView( | |
| 110 int render_process_id, int render_view_id) { | |
| 111 NOTREACHED(); | |
| 112 } | |
| 113 | |
| 114 bool FakeSpeechRecognitionManager::HasAudioInputDevices() { return true; } | 111 bool FakeSpeechRecognitionManager::HasAudioInputDevices() { return true; } |
| 115 | 112 |
| 116 base::string16 FakeSpeechRecognitionManager::GetAudioInputDeviceModel() { | 113 base::string16 FakeSpeechRecognitionManager::GetAudioInputDeviceModel() { |
| 117 return base::string16(); | 114 return base::string16(); |
| 118 } | 115 } |
| 119 | 116 |
| 120 int FakeSpeechRecognitionManager::GetSession(int render_process_id, | 117 int FakeSpeechRecognitionManager::GetSession(int render_process_id, |
| 121 int render_view_id, | 118 int render_frame_id, |
| 122 int request_id) const { | 119 int request_id) const { |
| 123 return session_ctx_.render_process_id == render_process_id && | 120 return session_ctx_.render_process_id == render_process_id && |
| 124 session_ctx_.render_view_id == render_view_id && | 121 session_ctx_.render_frame_id == render_frame_id && |
| 125 session_ctx_.request_id == request_id; | 122 session_ctx_.request_id == request_id; |
| 126 } | 123 } |
| 127 | 124 |
| 128 const SpeechRecognitionSessionConfig& | 125 const SpeechRecognitionSessionConfig& |
| 129 FakeSpeechRecognitionManager::GetSessionConfig(int session_id) const { | 126 FakeSpeechRecognitionManager::GetSessionConfig(int session_id) const { |
| 130 EXPECT_EQ(session_id, session_id_); | 127 EXPECT_EQ(session_id, session_id_); |
| 131 return session_config_; | 128 return session_config_; |
| 132 } | 129 } |
| 133 | 130 |
| 134 SpeechRecognitionSessionContext FakeSpeechRecognitionManager::GetSessionContext( | 131 SpeechRecognitionSessionContext FakeSpeechRecognitionManager::GetSessionContext( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 149 SpeechRecognitionResults results; | 146 SpeechRecognitionResults results; |
| 150 results.push_back(result); | 147 results.push_back(result); |
| 151 listener_->OnRecognitionResults(session_id_, results); | 148 listener_->OnRecognitionResults(session_id_, results); |
| 152 listener_->OnRecognitionEnd(session_id_); | 149 listener_->OnRecognitionEnd(session_id_); |
| 153 session_id_ = 0; | 150 session_id_ = 0; |
| 154 listener_ = NULL; | 151 listener_ = NULL; |
| 155 VLOG(1) << "Finished setting fake recognition result."; | 152 VLOG(1) << "Finished setting fake recognition result."; |
| 156 } | 153 } |
| 157 | 154 |
| 158 } // namespace content | 155 } // namespace content |
| OLD | NEW |