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 TestAudioInputControllerFactory
;
15 // TestAudioInputController and TestAudioInputControllerFactory are used for
16 // testing consumers of AudioInputController. TestAudioInputControllerFactory
17 // is a AudioInputController::Factory that creates TestAudioInputControllers.
19 // TestAudioInputController::Record and Close are overriden to do nothing. It is
20 // expected that you'll grab the EventHandler from the TestAudioInputController
21 // and invoke the callback methods when appropriate. In this way it's easy to
22 // mock a AudioInputController.
25 // // Create and register factory.
26 // TestAudioInputControllerFactory factory;
27 // AudioInputController::set_factory_for_testing(&factory);
29 // // Do something that triggers creation of an AudioInputController.
30 // TestAudioInputController* controller = factory.last_controller();
31 // DCHECK(controller);
33 // // Notify event handler with whatever data you want.
34 // controller->event_handler()->OnCreated(...);
36 // // Do something that triggers AudioInputController::Record to be called.
37 // controller->event_handler()->OnData(...);
38 // controller->event_handler()->OnError(...);
40 // // Make sure consumer of AudioInputController does the right thing.
43 // AudioInputController::set_factory_for_testing(NULL);
45 class TestAudioInputController
: public AudioInputController
{
49 virtual void TestAudioControllerOpened(
50 TestAudioInputController
* controller
) = 0;
51 virtual void TestAudioControllerClosed(
52 TestAudioInputController
* controller
) = 0;
55 TestAudioInputController(TestAudioInputControllerFactory
* factory
,
56 AudioManager
* audio_manager
,
57 const AudioParameters
& audio_parameters
,
58 EventHandler
* event_handler
,
59 SyncWriter
* sync_writer
);
61 // Returns the event handler installed on the AudioInputController.
62 EventHandler
* event_handler() const { return event_handler_
; }
64 // Notifies the TestAudioControllerOpened() event to the delegate (if any).
65 virtual void Record() OVERRIDE
;
67 // Ensure that the closure is run on the audio-manager thread.
68 virtual void Close(const base::Closure
& closed_task
) OVERRIDE
;
71 virtual ~TestAudioInputController();
74 AudioParameters audio_parameters_
;
76 // These are not owned by us and expected to be valid for this object's
78 TestAudioInputControllerFactory
* factory_
;
79 EventHandler
* event_handler_
;
81 DISALLOW_COPY_AND_ASSIGN(TestAudioInputController
);
84 typedef TestAudioInputController::Delegate TestAudioInputControllerDelegate
;
86 // Simple AudioInputController::Factory method that creates
87 // TestAudioInputControllers.
88 class TestAudioInputControllerFactory
: public AudioInputController::Factory
{
90 TestAudioInputControllerFactory();
91 virtual ~TestAudioInputControllerFactory();
93 // AudioInputController::Factory methods.
94 virtual AudioInputController
* Create(
95 AudioManager
* audio_manager
,
96 AudioInputController::EventHandler
* event_handler
,
97 AudioParameters params
) OVERRIDE
;
99 void SetDelegateForTests(TestAudioInputControllerDelegate
* delegate
);
101 TestAudioInputController
* controller() const { return controller_
; }
104 friend class TestAudioInputController
;
106 // Invoked by a TestAudioInputController when it gets destroyed.
107 void OnTestAudioInputControllerDestroyed(
108 TestAudioInputController
* controller
);
110 // The caller of Create owns this object.
111 TestAudioInputController
* controller_
;
113 // The delegate for tests for receiving audio controller events.
114 TestAudioInputControllerDelegate
* delegate_
;
116 DISALLOW_COPY_AND_ASSIGN(TestAudioInputControllerFactory
);
121 #endif // MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_