1 // Copyright (c) 2012 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 MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
6 #define MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
9 #include "media/audio/audio_input_controller.h"
13 class UserInputMonitor
;
14 class TestAudioInputControllerFactory
;
16 // TestAudioInputController and TestAudioInputControllerFactory are used for
17 // testing consumers of AudioInputController. TestAudioInputControllerFactory
18 // is a AudioInputController::Factory that creates TestAudioInputControllers.
20 // TestAudioInputController::Record and Close are overriden to do nothing. It is
21 // expected that you'll grab the EventHandler from the TestAudioInputController
22 // and invoke the callback methods when appropriate. In this way it's easy to
23 // mock a AudioInputController.
26 // // Create and register factory.
27 // TestAudioInputControllerFactory factory;
28 // AudioInputController::set_factory_for_testing(&factory);
30 // // Do something that triggers creation of an AudioInputController.
31 // TestAudioInputController* controller = factory.last_controller();
32 // DCHECK(controller);
34 // // Notify event handler with whatever data you want.
35 // controller->event_handler()->OnCreated(...);
37 // // Do something that triggers AudioInputController::Record to be called.
38 // controller->event_handler()->OnData(...);
39 // controller->event_handler()->OnError(...);
41 // // Make sure consumer of AudioInputController does the right thing.
44 // AudioInputController::set_factory_for_testing(NULL);
46 class TestAudioInputController
: public AudioInputController
{
50 virtual void TestAudioControllerOpened(
51 TestAudioInputController
* controller
) = 0;
52 virtual void TestAudioControllerClosed(
53 TestAudioInputController
* controller
) = 0;
56 TestAudioInputController(TestAudioInputControllerFactory
* factory
,
57 AudioManager
* audio_manager
,
58 const AudioParameters
& audio_parameters
,
59 EventHandler
* event_handler
,
60 SyncWriter
* sync_writer
,
61 UserInputMonitor
* user_input_monitor
);
63 // Returns the event handler installed on the AudioInputController.
64 EventHandler
* event_handler() const { return event_handler_
; }
66 // Notifies the TestAudioControllerOpened() event to the delegate (if any).
67 void Record() override
;
69 // Ensure that the closure is run on the audio-manager thread.
70 void Close(const base::Closure
& closed_task
) override
;
72 const AudioParameters
& audio_parameters() const {
73 return audio_parameters_
;
77 ~TestAudioInputController() override
;
80 AudioParameters audio_parameters_
;
82 // These are not owned by us and expected to be valid for this object's
84 TestAudioInputControllerFactory
* factory_
;
85 EventHandler
* event_handler_
;
87 DISALLOW_COPY_AND_ASSIGN(TestAudioInputController
);
90 typedef TestAudioInputController::Delegate TestAudioInputControllerDelegate
;
92 // Simple AudioInputController::Factory method that creates
93 // TestAudioInputControllers.
94 class TestAudioInputControllerFactory
: public AudioInputController::Factory
{
96 TestAudioInputControllerFactory();
97 ~TestAudioInputControllerFactory() override
;
99 // AudioInputController::Factory methods.
100 AudioInputController
* Create(
101 AudioManager
* audio_manager
,
102 AudioInputController::EventHandler
* event_handler
,
103 AudioParameters params
,
104 UserInputMonitor
* user_input_monitor
) override
;
106 void set_delegate(TestAudioInputControllerDelegate
* delegate
) {
107 delegate_
= delegate
;
110 TestAudioInputController
* controller() const { return controller_
; }
113 friend class TestAudioInputController
;
115 // Invoked by a TestAudioInputController when it gets destroyed.
116 void OnTestAudioInputControllerDestroyed(
117 TestAudioInputController
* controller
);
119 // The caller of Create owns this object.
120 TestAudioInputController
* controller_
;
122 // The delegate for tests for receiving audio controller events.
123 TestAudioInputControllerDelegate
* delegate_
;
125 DISALLOW_COPY_AND_ASSIGN(TestAudioInputControllerFactory
);
130 #endif // MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_