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

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

Issue 1892433002: Moving device description utils from AudioManager[Base] into AudioDeviceDescription; to be shared b… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 4 years, 7 months 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
« no previous file with comments | « media/audio/audio_device_name.cc ('k') | media/audio/audio_input_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) 2012 The Chromium Authors. All rights reserved. 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 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/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/test/test_timeouts.h" 9 #include "base/test/test_timeouts.h"
10 #include "media/audio/audio_device_description.h"
10 #include "media/audio/audio_input_controller.h" 11 #include "media/audio/audio_input_controller.h"
11 #include "media/audio/audio_manager_base.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using ::testing::_; 15 using ::testing::_;
16 using ::testing::AtLeast; 16 using ::testing::AtLeast;
17 using ::testing::Exactly; 17 using ::testing::Exactly;
18 using ::testing::InvokeWithoutArgs; 18 using ::testing::InvokeWithoutArgs;
19 using ::testing::NotNull; 19 using ::testing::NotNull;
20 20
21 namespace media { 21 namespace media {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 TEST_F(AudioInputControllerTest, CreateAndClose) { 90 TEST_F(AudioInputControllerTest, CreateAndClose) {
91 MockAudioInputControllerEventHandler event_handler; 91 MockAudioInputControllerEventHandler event_handler;
92 92
93 // OnCreated() will be posted once. 93 // OnCreated() will be posted once.
94 EXPECT_CALL(event_handler, OnCreated(NotNull())) 94 EXPECT_CALL(event_handler, OnCreated(NotNull()))
95 .WillOnce(QuitMessageLoop(&message_loop_)); 95 .WillOnce(QuitMessageLoop(&message_loop_));
96 96
97 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, 97 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
98 kSampleRate, kBitsPerSample, kSamplesPerPacket); 98 kSampleRate, kBitsPerSample, kSamplesPerPacket);
99 99
100 scoped_refptr<AudioInputController> controller = 100 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
101 AudioInputController::Create(audio_manager_.get(), &event_handler, params, 101 audio_manager_.get(), &event_handler, params,
102 AudioManagerBase::kDefaultDeviceId, NULL); 102 AudioDeviceDescription::kDefaultDeviceId, NULL);
103 ASSERT_TRUE(controller.get()); 103 ASSERT_TRUE(controller.get());
104 104
105 // Wait for OnCreated() to fire. 105 // Wait for OnCreated() to fire.
106 message_loop_.Run(); 106 message_loop_.Run();
107 107
108 // Close the AudioInputController synchronously. 108 // Close the AudioInputController synchronously.
109 CloseAudioController(controller.get()); 109 CloseAudioController(controller.get());
110 } 110 }
111 111
112 // Test a normal call sequence of create, record and close. 112 // Test a normal call sequence of create, record and close.
(...skipping 12 matching lines...) Expand all
125 // OnData() shall be called ten times. 125 // OnData() shall be called ten times.
126 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull())) 126 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull()))
127 .Times(AtLeast(10)) 127 .Times(AtLeast(10))
128 .WillRepeatedly(CheckCountAndPostQuitTask( 128 .WillRepeatedly(CheckCountAndPostQuitTask(
129 &count, 10, message_loop_.task_runner())); 129 &count, 10, message_loop_.task_runner()));
130 130
131 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, 131 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
132 kSampleRate, kBitsPerSample, kSamplesPerPacket); 132 kSampleRate, kBitsPerSample, kSamplesPerPacket);
133 133
134 // Creating the AudioInputController should render an OnCreated() call. 134 // Creating the AudioInputController should render an OnCreated() call.
135 scoped_refptr<AudioInputController> controller = 135 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
136 AudioInputController::Create(audio_manager_.get(), &event_handler, params, 136 audio_manager_.get(), &event_handler, params,
137 AudioManagerBase::kDefaultDeviceId, NULL); 137 AudioDeviceDescription::kDefaultDeviceId, NULL);
138 ASSERT_TRUE(controller.get()); 138 ASSERT_TRUE(controller.get());
139 139
140 // Start recording and trigger one OnRecording() call. 140 // Start recording and trigger one OnRecording() call.
141 controller->Record(); 141 controller->Record();
142 142
143 // Record and wait until ten OnData() callbacks are received. 143 // Record and wait until ten OnData() callbacks are received.
144 message_loop_.Run(); 144 message_loop_.Run();
145 145
146 // Close the AudioInputController synchronously. 146 // Close the AudioInputController synchronously.
147 CloseAudioController(controller.get()); 147 CloseAudioController(controller.get());
(...skipping 26 matching lines...) Expand all
174 // controller is in a recording state. 174 // controller is in a recording state.
175 EXPECT_CALL(event_handler, OnError(NotNull(), 175 EXPECT_CALL(event_handler, OnError(NotNull(),
176 AudioInputController::NO_DATA_ERROR)) 176 AudioInputController::NO_DATA_ERROR))
177 .Times(Exactly(1)) 177 .Times(Exactly(1))
178 .WillOnce(QuitMessageLoop(&message_loop_)); 178 .WillOnce(QuitMessageLoop(&message_loop_));
179 179
180 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, 180 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
181 kSampleRate, kBitsPerSample, kSamplesPerPacket); 181 kSampleRate, kBitsPerSample, kSamplesPerPacket);
182 182
183 // Creating the AudioInputController should render an OnCreated() call. 183 // Creating the AudioInputController should render an OnCreated() call.
184 scoped_refptr<AudioInputController> controller = 184 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
185 AudioInputController::Create(audio_manager_.get(), &event_handler, params, 185 audio_manager_.get(), &event_handler, params,
186 AudioManagerBase::kDefaultDeviceId, NULL); 186 AudioDeviceDescription::kDefaultDeviceId, NULL);
187 ASSERT_TRUE(controller.get()); 187 ASSERT_TRUE(controller.get());
188 188
189 // Start recording and trigger one OnRecording() call. 189 // Start recording and trigger one OnRecording() call.
190 controller->Record(); 190 controller->Record();
191 191
192 // Record and wait until ten OnData() callbacks are received. 192 // Record and wait until ten OnData() callbacks are received.
193 message_loop_.Run(); 193 message_loop_.Run();
194 194
195 // Stop the stream and verify that OnError() is posted. 195 // Stop the stream and verify that OnError() is posted.
196 AudioInputStream* stream = controller->stream_for_testing(); 196 AudioInputStream* stream = controller->stream_for_testing();
(...skipping 11 matching lines...) Expand all
208 208
209 // OnCreated() shall not be called in this test. 209 // OnCreated() shall not be called in this test.
210 EXPECT_CALL(event_handler, OnCreated(NotNull())) 210 EXPECT_CALL(event_handler, OnCreated(NotNull()))
211 .Times(Exactly(0)); 211 .Times(Exactly(0));
212 212
213 AudioParameters params(AudioParameters::AUDIO_FAKE, 213 AudioParameters params(AudioParameters::AUDIO_FAKE,
214 kChannelLayout, 214 kChannelLayout,
215 kSampleRate, 215 kSampleRate,
216 kBitsPerSample, 216 kBitsPerSample,
217 kSamplesPerPacket * 1000); 217 kSamplesPerPacket * 1000);
218 scoped_refptr<AudioInputController> controller = 218 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
219 AudioInputController::Create(audio_manager_.get(), &event_handler, params, 219 audio_manager_.get(), &event_handler, params,
220 AudioManagerBase::kDefaultDeviceId, NULL); 220 AudioDeviceDescription::kDefaultDeviceId, NULL);
221 ASSERT_FALSE(controller.get()); 221 ASSERT_FALSE(controller.get());
222 } 222 }
223 223
224 // Test calling AudioInputController::Close multiple times. 224 // Test calling AudioInputController::Close multiple times.
225 TEST_F(AudioInputControllerTest, CloseTwice) { 225 TEST_F(AudioInputControllerTest, CloseTwice) {
226 MockAudioInputControllerEventHandler event_handler; 226 MockAudioInputControllerEventHandler event_handler;
227 227
228 // OnRecording() will be called only once. 228 // OnRecording() will be called only once.
229 EXPECT_CALL(event_handler, OnCreated(NotNull())); 229 EXPECT_CALL(event_handler, OnCreated(NotNull()));
230 230
231 // OnRecording() will be called only once. 231 // OnRecording() will be called only once.
232 EXPECT_CALL(event_handler, OnRecording(NotNull())) 232 EXPECT_CALL(event_handler, OnRecording(NotNull()))
233 .Times(Exactly(1)); 233 .Times(Exactly(1));
234 234
235 AudioParameters params(AudioParameters::AUDIO_FAKE, 235 AudioParameters params(AudioParameters::AUDIO_FAKE,
236 kChannelLayout, 236 kChannelLayout,
237 kSampleRate, 237 kSampleRate,
238 kBitsPerSample, 238 kBitsPerSample,
239 kSamplesPerPacket); 239 kSamplesPerPacket);
240 scoped_refptr<AudioInputController> controller = 240 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
241 AudioInputController::Create(audio_manager_.get(), &event_handler, params, 241 audio_manager_.get(), &event_handler, params,
242 AudioManagerBase::kDefaultDeviceId, NULL); 242 AudioDeviceDescription::kDefaultDeviceId, NULL);
243 ASSERT_TRUE(controller.get()); 243 ASSERT_TRUE(controller.get());
244 244
245 controller->Record(); 245 controller->Record();
246 246
247 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 247 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
248 base::MessageLoop::current()->Run(); 248 base::MessageLoop::current()->Run();
249 249
250 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 250 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
251 base::MessageLoop::current()->Run(); 251 base::MessageLoop::current()->Run();
252 } 252 }
253 253
254 } // namespace media 254 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_device_name.cc ('k') | media/audio/audio_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698