Update net/third_party/nss/ssl to NSS 3.15.1.
[chromium-blink-merge.git] / media / audio / test_audio_input_controller_factory.h
blob0a179473c1ce8e18775988be0408d4d9a952ed7f
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_
8 #include "base/bind.h"
9 #include "media/audio/audio_input_controller.h"
11 namespace media {
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.
24 // Typical usage:
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.
41 // ...
42 // // Reset factory.
43 // AudioInputController::set_factory_for_testing(NULL);
45 class TestAudioInputController : public AudioInputController {
46 public:
47 class Delegate {
48 public:
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;
70 protected:
71 virtual ~TestAudioInputController();
73 private:
74 AudioParameters audio_parameters_;
76 // These are not owned by us and expected to be valid for this object's
77 // lifetime.
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 {
89 public:
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_; }
103 private:
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);
119 } // namespace media
121 #endif // MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_