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/speech_recognition_event_listener.h" | 10 #include "content/public/browser/speech_recognition_event_listener.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 void FakeSpeechRecognitionManager::SetFakeResult(const std::string& value) { | 44 void FakeSpeechRecognitionManager::SetFakeResult(const std::string& value) { |
45 fake_result_ = value; | 45 fake_result_ = value; |
46 } | 46 } |
47 | 47 |
48 int FakeSpeechRecognitionManager::CreateSession( | 48 int FakeSpeechRecognitionManager::CreateSession( |
49 const SpeechRecognitionSessionConfig& config) { | 49 const SpeechRecognitionSessionConfig& config) { |
50 VLOG(1) << "FAKE CreateSession invoked."; | 50 VLOG(1) << "FAKE CreateSession invoked."; |
51 EXPECT_EQ(0, session_id_); | 51 EXPECT_EQ(0, session_id_); |
52 EXPECT_EQ(NULL, listener_); | 52 EXPECT_EQ(NULL, listener_); |
53 listener_ = config.event_listener; | 53 listener_ = config.event_listener.get(); |
54 if (config.grammars.size() > 0) | 54 if (config.grammars.size() > 0) |
55 grammar_ = config.grammars[0].url; | 55 grammar_ = config.grammars[0].url; |
56 session_ctx_ = config.initial_context; | 56 session_ctx_ = config.initial_context; |
57 session_config_ = config; | 57 session_config_ = config; |
58 session_id_ = 1; | 58 session_id_ = 1; |
59 return session_id_; | 59 return session_id_; |
60 } | 60 } |
61 | 61 |
62 void FakeSpeechRecognitionManager::StartSession(int session_id) { | 62 void FakeSpeechRecognitionManager::StartSession(int session_id) { |
63 VLOG(1) << "FAKE StartSession invoked."; | 63 VLOG(1) << "FAKE StartSession invoked."; |
(...skipping 27 matching lines...) Expand all Loading... |
91 session_id_ = 0; | 91 session_id_ = 0; |
92 listener_ = NULL; | 92 listener_ = NULL; |
93 } | 93 } |
94 | 94 |
95 void FakeSpeechRecognitionManager::StopAudioCaptureForSession(int session_id) { | 95 void FakeSpeechRecognitionManager::StopAudioCaptureForSession(int session_id) { |
96 VLOG(1) << "StopRecording invoked."; | 96 VLOG(1) << "StopRecording invoked."; |
97 EXPECT_EQ(session_id_, session_id); | 97 EXPECT_EQ(session_id_, session_id); |
98 // Nothing to do here since we aren't really recording. | 98 // Nothing to do here since we aren't really recording. |
99 } | 99 } |
100 | 100 |
101 void FakeSpeechRecognitionManager::AbortAllSessionsForListener( | 101 void FakeSpeechRecognitionManager::AbortAllSessionsForRenderProcess( |
102 SpeechRecognitionEventListener* listener) { | 102 int render_process_id) { |
103 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; | 103 VLOG(1) << "CancelAllRequestsWithDelegate invoked."; |
104 // listener_ is set to NULL if a fake result was received (see below), so | 104 EXPECT_TRUE(should_send_fake_response_ || |
105 // check that listener_ matches the incoming parameter only when there is | 105 session_ctx_.render_process_id == render_process_id); |
106 // no fake result sent. | |
107 EXPECT_TRUE(should_send_fake_response_ || listener_ == listener); | |
108 did_cancel_all_ = true; | 106 did_cancel_all_ = true; |
109 } | 107 } |
110 | 108 |
111 void FakeSpeechRecognitionManager::AbortAllSessionsForRenderView( | 109 void FakeSpeechRecognitionManager::AbortAllSessionsForRenderView( |
112 int render_process_id, int render_view_id) { | 110 int render_process_id, int render_view_id) { |
113 NOTREACHED(); | 111 NOTREACHED(); |
114 } | 112 } |
115 | 113 |
116 bool FakeSpeechRecognitionManager::HasAudioInputDevices() { return true; } | 114 bool FakeSpeechRecognitionManager::HasAudioInputDevices() { return true; } |
117 | 115 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 SpeechRecognitionResults results; | 149 SpeechRecognitionResults results; |
152 results.push_back(result); | 150 results.push_back(result); |
153 listener_->OnRecognitionResults(session_id_, results); | 151 listener_->OnRecognitionResults(session_id_, results); |
154 listener_->OnRecognitionEnd(session_id_); | 152 listener_->OnRecognitionEnd(session_id_); |
155 session_id_ = 0; | 153 session_id_ = 0; |
156 listener_ = NULL; | 154 listener_ = NULL; |
157 VLOG(1) << "Finished setting fake recognition result."; | 155 VLOG(1) << "Finished setting fake recognition result."; |
158 } | 156 } |
159 | 157 |
160 } // namespace content | 158 } // namespace content |
OLD | NEW |