fake_speech_recognition_manager.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.
4
5#ifndef CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNTION_MANAGER_H_
6#define CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNTION_MANAGER_H_
7
8#include "base/synchronization/waitable_event.h"
9#include "content/public/browser/speech_recognition_manager.h"
10#include "content/public/browser/speech_recognition_session_config.h"
11#include "content/public/browser/speech_recognition_session_context.h"
12
13namespace content {
14
15// Fake SpeechRecognitionManager class that can be used for tests.
16// By default the recognition manager will respond with "Pictures of the moon"
17// as recognized result from speech. This result can be overridden by calling
18// SetFakeResult().
19class FakeSpeechRecognitionManager : public SpeechRecognitionManager {
20 public:
21  FakeSpeechRecognitionManager();
22  virtual ~FakeSpeechRecognitionManager();
23
24  const std::string& grammar() const {
25    return grammar_;
26  }
27
28  bool did_cancel_all() {
29    return did_cancel_all_;
30  }
31
32  void set_should_send_fake_response(bool send) {
33    should_send_fake_response_ = send;
34  }
35
36  bool should_send_fake_response() {
37    return should_send_fake_response_;
38  }
39
40  base::WaitableEvent& recognition_started_event() {
41    return recognition_started_event_;
42  }
43
44  void SetFakeResult(const std::string& result);
45
46  // SpeechRecognitionManager methods.
47  virtual int CreateSession(
48      const SpeechRecognitionSessionConfig& config) OVERRIDE;
49  virtual void StartSession(int session_id) OVERRIDE;
50  virtual void AbortSession(int session_id) OVERRIDE;
51  virtual void StopAudioCaptureForSession(int session_id) OVERRIDE;
52  virtual void AbortAllSessionsForListener(
53      SpeechRecognitionEventListener* listener) OVERRIDE;
54  virtual void AbortAllSessionsForRenderView(int render_process_id,
55                                             int render_view_id) OVERRIDE;
56  virtual bool HasAudioInputDevices() OVERRIDE;
57  virtual bool IsCapturingAudio() OVERRIDE;
58  virtual string16 GetAudioInputDeviceModel() OVERRIDE;
59  virtual void ShowAudioInputSettings() OVERRIDE {}
60  virtual int GetSession(int render_process_id,
61                         int render_view_id,
62                         int request_id) const OVERRIDE;
63  virtual const SpeechRecognitionSessionConfig& GetSessionConfig(
64      int session_id) const OVERRIDE;
65  virtual SpeechRecognitionSessionContext GetSessionContext(
66      int session_id) const OVERRIDE;
67
68 private:
69  void SetFakeRecognitionResult();
70
71  int session_id_;
72  SpeechRecognitionEventListener* listener_;
73  SpeechRecognitionSessionConfig session_config_;
74  SpeechRecognitionSessionContext session_ctx_;
75  std::string fake_result_;
76  std::string grammar_;
77  bool did_cancel_all_;
78  bool should_send_fake_response_;
79  base::WaitableEvent recognition_started_event_;
80
81  DISALLOW_COPY_AND_ASSIGN(FakeSpeechRecognitionManager);
82};
83
84}  // namespace content
85
86#endif  // CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNTION_MANAGER_H_
87