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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNITION_MANAGER_H_
6 #define CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNITION_MANAGER_H_
8 #include "base/callback_forward.h"
9 #include "content/public/browser/speech_recognition_event_listener.h"
10 #include "content/public/browser/speech_recognition_manager.h"
11 #include "content/public/browser/speech_recognition_session_config.h"
12 #include "content/public/browser/speech_recognition_session_context.h"
16 class SpeechRecognitionManagerDelegate
;
18 // Fake SpeechRecognitionManager class that can be used for tests.
19 // By default the recognition manager will respond with "Pictures of the moon"
20 // as recognized result from speech. This result can be overridden by calling
22 class FakeSpeechRecognitionManager
: public SpeechRecognitionManager
,
23 public SpeechRecognitionEventListener
{
25 FakeSpeechRecognitionManager();
26 ~FakeSpeechRecognitionManager() override
;
28 const std::string
& grammar() const {
32 bool did_cancel_all() {
33 return did_cancel_all_
;
36 void set_should_send_fake_response(bool send
) {
37 should_send_fake_response_
= send
;
40 bool should_send_fake_response() {
41 return should_send_fake_response_
;
44 void WaitForRecognitionStarted();
46 void SetFakeResult(const std::string
& result
);
48 // SpeechRecognitionManager methods.
49 int CreateSession(const SpeechRecognitionSessionConfig
& config
) override
;
50 void StartSession(int session_id
) override
;
51 void AbortSession(int session_id
) override
;
52 void StopAudioCaptureForSession(int session_id
) override
;
53 void AbortAllSessionsForRenderProcess(int render_process_id
) override
;
54 void AbortAllSessionsForRenderView(int render_process_id
,
55 int render_view_id
) override
;
56 bool HasAudioInputDevices() override
;
57 base::string16
GetAudioInputDeviceModel() override
;
58 void ShowAudioInputSettings() override
{}
59 int GetSession(int render_process_id
,
61 int request_id
) const override
;
62 const SpeechRecognitionSessionConfig
& GetSessionConfig(
63 int session_id
) const override
;
64 SpeechRecognitionSessionContext
GetSessionContext(
65 int session_id
) const override
;
67 // SpeechRecognitionEventListener implementation.
68 void OnRecognitionStart(int session_id
) override
{}
69 void OnAudioStart(int session_id
) override
{}
70 void OnEnvironmentEstimationComplete(int session_id
) override
{}
71 void OnSoundStart(int session_id
) override
{}
72 void OnSoundEnd(int session_id
) override
{}
73 void OnAudioEnd(int session_id
) override
{}
74 void OnRecognitionEnd(int session_id
) override
{}
75 void OnRecognitionResults(int session_id
,
76 const SpeechRecognitionResults
& result
) override
{}
77 void OnRecognitionError(int session_id
,
78 const SpeechRecognitionError
& error
) override
{}
79 void OnAudioLevelsChange(int session_id
,
81 float noise_volume
) override
{}
83 void SetDelegate(SpeechRecognitionManagerDelegate
* delegate
);
86 void SetFakeRecognitionResult();
89 SpeechRecognitionEventListener
* listener_
;
90 SpeechRecognitionSessionConfig session_config_
;
91 SpeechRecognitionSessionContext session_ctx_
;
92 std::string fake_result_
;
95 bool should_send_fake_response_
;
96 base::Closure recognition_started_closure_
;
97 SpeechRecognitionManagerDelegate
* delegate_
; // Not owned.
99 DISALLOW_COPY_AND_ASSIGN(FakeSpeechRecognitionManager
);
102 } // namespace content
104 #endif // CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNITION_MANAGER_H_