Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: media/audio/audio_input_controller_unittest.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/audio/audio_input_device_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/synchronization/waitable_event.h" 6 #include "base/synchronization/waitable_event.h"
7 #include "media/audio/audio_input_controller.h" 7 #include "media/audio/audio_input_controller.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 }; 44 };
45 45
46 // Test AudioInputController for create and close without recording audio. 46 // Test AudioInputController for create and close without recording audio.
47 TEST(AudioInputControllerTest, CreateAndClose) { 47 TEST(AudioInputControllerTest, CreateAndClose) {
48 MockAudioInputControllerEventHandler event_handler; 48 MockAudioInputControllerEventHandler event_handler;
49 base::WaitableEvent event(false, false); 49 base::WaitableEvent event(false, false);
50 // If OnCreated is called then signal the event. 50 // If OnCreated is called then signal the event.
51 EXPECT_CALL(event_handler, OnCreated(NotNull())) 51 EXPECT_CALL(event_handler, OnCreated(NotNull()))
52 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 52 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
53 53
54 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
54 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, 55 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout,
55 kSampleRate, kBitsPerSample, kSamplesPerPacket); 56 kSampleRate, kBitsPerSample, kSamplesPerPacket);
56 scoped_refptr<AudioInputController> controller = 57 scoped_refptr<AudioInputController> controller =
57 AudioInputController::Create(&event_handler, params); 58 AudioInputController::Create(audio_manager, &event_handler, params);
58 ASSERT_TRUE(controller.get()); 59 ASSERT_TRUE(controller.get());
59 60
60 // Wait for OnCreated() to be called. 61 // Wait for OnCreated() to be called.
61 event.Wait(); 62 event.Wait();
62 63
63 controller->Close(); 64 controller->Close();
64 } 65 }
65 66
66 // Test a normal call sequence of create, record and close. 67 // Test a normal call sequence of create, record and close.
67 TEST(AudioInputControllerTest, RecordAndClose) { 68 TEST(AudioInputControllerTest, RecordAndClose) {
68 MockAudioInputControllerEventHandler event_handler; 69 MockAudioInputControllerEventHandler event_handler;
69 base::WaitableEvent event(false, false); 70 base::WaitableEvent event(false, false);
70 int count = 0; 71 int count = 0;
71 72
72 // If OnCreated is called then signal the event. 73 // If OnCreated is called then signal the event.
73 EXPECT_CALL(event_handler, OnCreated(NotNull())) 74 EXPECT_CALL(event_handler, OnCreated(NotNull()))
74 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 75 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
75 76
76 // OnRecording() will be called only once. 77 // OnRecording() will be called only once.
77 EXPECT_CALL(event_handler, OnRecording(NotNull())) 78 EXPECT_CALL(event_handler, OnRecording(NotNull()))
78 .Times(Exactly(1)); 79 .Times(Exactly(1));
79 80
80 // If OnData is called enough then signal the event. 81 // If OnData is called enough then signal the event.
81 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _)) 82 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _))
82 .Times(AtLeast(10)) 83 .Times(AtLeast(10))
83 .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event)); 84 .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event));
84 85
86 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
85 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, 87 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout,
86 kSampleRate, kBitsPerSample, kSamplesPerPacket); 88 kSampleRate, kBitsPerSample, kSamplesPerPacket);
87 scoped_refptr<AudioInputController> controller = 89 scoped_refptr<AudioInputController> controller =
88 AudioInputController::Create(&event_handler, params); 90 AudioInputController::Create(audio_manager, &event_handler, params);
89 ASSERT_TRUE(controller.get()); 91 ASSERT_TRUE(controller.get());
90 92
91 // Wait for OnCreated() to be called. 93 // Wait for OnCreated() to be called.
92 event.Wait(); 94 event.Wait();
93 event.Reset(); 95 event.Reset();
94 96
95 // Record and then wait for the event to be signaled. 97 // Record and then wait for the event to be signaled.
96 controller->Record(); 98 controller->Record();
97 event.Wait(); 99 event.Wait();
98 100
(...skipping 17 matching lines...) Expand all
116 118
117 // If OnData is called enough then signal the event. 119 // If OnData is called enough then signal the event.
118 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _)) 120 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _))
119 .Times(AtLeast(10)) 121 .Times(AtLeast(10))
120 .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event)); 122 .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event));
121 123
122 // OnError will be called after the data stream stops. 124 // OnError will be called after the data stream stops.
123 EXPECT_CALL(event_handler, OnError(NotNull(), 0)) 125 EXPECT_CALL(event_handler, OnError(NotNull(), 0))
124 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 126 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
125 127
128 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
126 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, 129 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout,
127 kSampleRate, kBitsPerSample, kSamplesPerPacket); 130 kSampleRate, kBitsPerSample, kSamplesPerPacket);
128 scoped_refptr<AudioInputController> controller = 131 scoped_refptr<AudioInputController> controller =
129 AudioInputController::Create(&event_handler, params); 132 AudioInputController::Create(audio_manager, &event_handler, params);
130 ASSERT_TRUE(controller.get()); 133 ASSERT_TRUE(controller.get());
131 134
132 // Wait for OnCreated() to be called. 135 // Wait for OnCreated() to be called.
133 event.Wait(); 136 event.Wait();
134 event.Reset(); 137 event.Reset();
135 138
136 // Record and then wait for the event to be signaled. 139 // Record and then wait for the event to be signaled.
137 controller->Record(); 140 controller->Record();
138 event.Wait(); 141 event.Wait();
139 event.Reset(); 142 event.Reset();
140 143
141 // Wait for the stream to be stopped. 144 // Wait for the stream to be stopped.
142 AudioInputStream* stream = controller->stream_for_testing(); 145 AudioInputStream* stream = controller->stream_for_testing();
143 stream->Stop(); 146 stream->Stop();
144 event.Wait(); 147 event.Wait();
145 148
146 controller->Close(); 149 controller->Close();
147 } 150 }
148 151
149 // Test that AudioInputController rejects insanely large packet sizes. 152 // Test that AudioInputController rejects insanely large packet sizes.
150 TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) { 153 TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) {
151 // Create an audio device with a very large packet size. 154 // Create an audio device with a very large packet size.
152 MockAudioInputControllerEventHandler event_handler; 155 MockAudioInputControllerEventHandler event_handler;
153 156
157 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
154 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, 158 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout,
155 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); 159 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000);
156 scoped_refptr<AudioInputController> controller = AudioInputController::Create( 160 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
157 &event_handler, params); 161 audio_manager, &event_handler, params);
158 ASSERT_FALSE(controller); 162 ASSERT_FALSE(controller);
159 } 163 }
160 164
161 // Test calling AudioInputController::Close multiple times. 165 // Test calling AudioInputController::Close multiple times.
162 TEST(AudioInputControllerTest, CloseTwice) { 166 TEST(AudioInputControllerTest, CloseTwice) {
163 MockAudioInputControllerEventHandler event_handler; 167 MockAudioInputControllerEventHandler event_handler;
164 EXPECT_CALL(event_handler, OnCreated(NotNull())); 168 EXPECT_CALL(event_handler, OnCreated(NotNull()));
169 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
165 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, 170 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout,
166 kSampleRate, kBitsPerSample, kSamplesPerPacket); 171 kSampleRate, kBitsPerSample, kSamplesPerPacket);
167 scoped_refptr<AudioInputController> controller = 172 scoped_refptr<AudioInputController> controller =
168 AudioInputController::Create(&event_handler, params); 173 AudioInputController::Create(audio_manager, &event_handler, params);
169 ASSERT_TRUE(controller.get()); 174 ASSERT_TRUE(controller.get());
170 175
171 controller->Close(); 176 controller->Close();
172 controller->Close(); 177 controller->Close();
173 } 178 }
174 179
175 } // namespace media 180 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/audio/audio_input_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698