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