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

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

Issue 9691001: Audio software mixer. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
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 <string>
6
5 #include "base/message_loop.h" 7 #include "base/message_loop.h"
6 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
7 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
8 #include "media/audio/audio_output_dispatcher.h" 10 #include "media/audio/audio_output_dispatcher_impl.h"
11 #include "media/audio/audio_output_mixer.h"
9 #include "media/audio/audio_output_proxy.h" 12 #include "media/audio/audio_output_proxy.h"
10 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
11 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 16
14 using ::testing::_; 17 using ::testing::_;
15 using ::testing::Mock; 18 using ::testing::Mock;
16 using ::testing::Return; 19 using ::testing::Return;
17 20
18 static const int kTestCloseDelayMs = 100; 21 static const int kTestCloseDelayMs = 100;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 class AudioOutputProxyTest : public testing::Test { 71 class AudioOutputProxyTest : public testing::Test {
69 protected: 72 protected:
70 virtual void SetUp() { 73 virtual void SetUp() {
71 EXPECT_CALL(manager_, GetMessageLoop()) 74 EXPECT_CALL(manager_, GetMessageLoop())
72 .WillRepeatedly(Return(message_loop_.message_loop_proxy())); 75 .WillRepeatedly(Return(message_loop_.message_loop_proxy()));
73 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); 76 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
74 } 77 }
75 78
76 virtual void TearDown() { 79 virtual void TearDown() {
77 // All paused proxies should have been closed at this point. 80 // All paused proxies should have been closed at this point.
78 EXPECT_EQ(0u, dispatcher_->paused_proxies_); 81 EXPECT_EQ(0u, dispatcher_impl_->paused_proxies_);
79 82
80 // This is necessary to free all proxy objects that have been 83 // This is necessary to free all proxy objects that have been
81 // closed by the test. 84 // closed by the test.
82 message_loop_.RunAllPending(); 85 message_loop_.RunAllPending();
83 } 86 }
84 87
85 void InitDispatcher(base::TimeDelta close_delay) { 88 void InitDispatcher(base::TimeDelta close_delay) {
86 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 89 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, false,
87 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); 90 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024);
88 dispatcher_ = new AudioOutputDispatcher(&manager(), params, close_delay); 91 dispatcher_impl_ = new AudioOutputDispatcherImpl(
92 &manager(),
93 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false,
94 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024),
95 close_delay);
96 mixer_ = new AudioOutputMixer(
97 &manager(),
98 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, true,
99 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024),
100 close_delay);
89 101
90 // Necessary to know how long the dispatcher will wait before posting 102 // Necessary to know how long the dispatcher will wait before posting
91 // StopStreamTask. 103 // StopStreamTask.
92 pause_delay_ = dispatcher_->pause_delay_; 104 pause_delay_ = dispatcher_impl_->pause_delay_;
93 } 105 }
94 106
95 MockAudioManager& manager() { 107 MockAudioManager& manager() {
96 return manager_; 108 return manager_;
97 } 109 }
98 110
111 // Methods that do actual tests.
112 void OpenAndClose(AudioOutputDispatcher* dispatcher) {
113 MockAudioOutputStream stream;
114
115 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
116 .WillOnce(Return(&stream));
117 EXPECT_CALL(stream, Open())
118 .WillOnce(Return(true));
119 EXPECT_CALL(stream, Close())
120 .Times(1);
121
122 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
123 EXPECT_TRUE(proxy->Open());
124 proxy->Close();
125
126 // Wait for the close timer to fire.
127 base::PlatformThread::Sleep(
128 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
129 message_loop_.RunAllPending();
130 }
131
132 // Create a stream, and then calls Start() and Stop().
133 void StartAndStop(AudioOutputDispatcher* dispatcher) {
134 MockAudioOutputStream stream;
135
136 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
137 .WillOnce(Return(&stream));
138 EXPECT_CALL(stream, Open())
139 .WillOnce(Return(true));
140 EXPECT_CALL(stream, Start(_))
141 .Times(1);
142 EXPECT_CALL(stream, SetVolume(_))
143 .Times(1);
144 EXPECT_CALL(stream, Stop())
145 .Times(1);
146 EXPECT_CALL(stream, Close())
147 .Times(1);
148
149 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
150 EXPECT_TRUE(proxy->Open());
151
152 proxy->Start(&callback_);
153 proxy->Stop();
154
155 proxy->Close();
156
157 // Wait for the close timer to fire.
158 base::PlatformThread::Sleep(
159 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
160 message_loop_.RunAllPending();
161 }
162
163 // Verify that the stream is closed after Stop is called.
164 void CloseAfterStop(AudioOutputDispatcher* dispatcher) {
165 MockAudioOutputStream stream;
166
167 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
168 .WillOnce(Return(&stream));
169 EXPECT_CALL(stream, Open())
170 .WillOnce(Return(true));
171 EXPECT_CALL(stream, Start(_))
172 .Times(1);
173 EXPECT_CALL(stream, SetVolume(_))
174 .Times(1);
175 EXPECT_CALL(stream, Stop())
176 .Times(1);
177 EXPECT_CALL(stream, Close())
178 .Times(1);
179
180 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
181 EXPECT_TRUE(proxy->Open());
182
183 proxy->Start(&callback_);
184 proxy->Stop();
185
186 // Wait for StreamStopped() to post StopStreamTask().
187 base::PlatformThread::Sleep(pause_delay_ * 2);
188 message_loop_.RunAllPending();
189
190 // Wait for the close timer to fire.
191 base::PlatformThread::Sleep(
192 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
193 message_loop_.RunAllPending();
194
195 // Verify expectation before calling Close().
196 Mock::VerifyAndClear(&stream);
197
198 proxy->Close();
199 }
200
201 // Create two streams, but don't start them. Only one device must be open.
202 void TwoStreams(AudioOutputDispatcher* dispatcher) {
203 MockAudioOutputStream stream;
204
205 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
206 .WillOnce(Return(&stream));
207 EXPECT_CALL(stream, Open())
208 .WillOnce(Return(true));
209 EXPECT_CALL(stream, Close())
210 .Times(1);
211
212 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher);
213 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher);
214 EXPECT_TRUE(proxy1->Open());
215 EXPECT_TRUE(proxy2->Open());
216 proxy1->Close();
217 proxy2->Close();
218
219 // Wait for the close timer to fire.
220 base::PlatformThread::Sleep(
221 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
222 message_loop_.RunAllPending();
223 }
224
225 // Open() method failed.
226 void OpenFailed(AudioOutputDispatcher* dispatcher) {
227 MockAudioOutputStream stream;
228
229 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
230 .WillOnce(Return(&stream));
231 EXPECT_CALL(stream, Open())
232 .WillOnce(Return(false));
233 EXPECT_CALL(stream, Close())
234 .Times(1);
235
236 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
237 EXPECT_FALSE(proxy->Open());
238 proxy->Close();
239
240 // Wait for the close timer to fire.
241 base::PlatformThread::Sleep(
242 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
243 message_loop_.RunAllPending();
244 }
245
99 MessageLoop message_loop_; 246 MessageLoop message_loop_;
100 scoped_refptr<AudioOutputDispatcher> dispatcher_; 247 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_;
248 scoped_refptr<AudioOutputMixer> mixer_;
101 base::TimeDelta pause_delay_; 249 base::TimeDelta pause_delay_;
102 MockAudioManager manager_; 250 MockAudioManager manager_;
103 MockAudioSourceCallback callback_; 251 MockAudioSourceCallback callback_;
104 }; 252 };
105 253
106 TEST_F(AudioOutputProxyTest, CreateAndClose) { 254 TEST_F(AudioOutputProxyTest, CreateAndClose) {
107 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); 255 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
256 proxy->Close();
257 }
258
259 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) {
260 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_);
108 proxy->Close(); 261 proxy->Close();
109 } 262 }
110 263
111 TEST_F(AudioOutputProxyTest, OpenAndClose) { 264 TEST_F(AudioOutputProxyTest, OpenAndClose) {
112 MockAudioOutputStream stream; 265 OpenAndClose(dispatcher_impl_);
266 }
113 267
114 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 268 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) {
115 .WillOnce(Return(&stream)); 269 OpenAndClose(mixer_);
116 EXPECT_CALL(stream, Open())
117 .WillOnce(Return(true));
118 EXPECT_CALL(stream, Close())
119 .Times(1);
120
121 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_);
122 EXPECT_TRUE(proxy->Open());
123 proxy->Close();
124 } 270 }
125 271
126 // Create a stream, and verify that it is closed after kTestCloseDelayMs. 272 // Create a stream, and verify that it is closed after kTestCloseDelayMs.
127 // if it doesn't start playing. 273 // if it doesn't start playing.
128 TEST_F(AudioOutputProxyTest, CreateAndWait) { 274 TEST_F(AudioOutputProxyTest, CreateAndWait) {
129 MockAudioOutputStream stream; 275 MockAudioOutputStream stream;
130 276
131 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 277 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
132 .WillOnce(Return(&stream)); 278 .WillOnce(Return(&stream));
133 EXPECT_CALL(stream, Open()) 279 EXPECT_CALL(stream, Open())
134 .WillOnce(Return(true)); 280 .WillOnce(Return(true));
135 EXPECT_CALL(stream, Close()) 281 EXPECT_CALL(stream, Close())
136 .Times(1); 282 .Times(1);
137 283
138 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); 284 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
139 EXPECT_TRUE(proxy->Open()); 285 EXPECT_TRUE(proxy->Open());
140 286
141 // Simulate a delay. 287 // Simulate a delay.
142 base::PlatformThread::Sleep( 288 base::PlatformThread::Sleep(
143 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); 289 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
144 message_loop_.RunAllPending(); 290 message_loop_.RunAllPending();
145 291
146 // Verify expectation before calling Close(). 292 // Verify expectation before calling Close().
147 Mock::VerifyAndClear(&stream); 293 Mock::VerifyAndClear(&stream);
148 294
149 proxy->Close(); 295 proxy->Close();
150 } 296 }
151 297
152 // Create a stream, and then calls Start() and Stop().
153 TEST_F(AudioOutputProxyTest, StartAndStop) { 298 TEST_F(AudioOutputProxyTest, StartAndStop) {
154 MockAudioOutputStream stream; 299 StartAndStop(dispatcher_impl_);
155
156 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
157 .WillOnce(Return(&stream));
158 EXPECT_CALL(stream, Open())
159 .WillOnce(Return(true));
160 EXPECT_CALL(stream, Start(_))
161 .Times(1);
162 EXPECT_CALL(stream, SetVolume(_))
163 .Times(1);
164 EXPECT_CALL(stream, Stop())
165 .Times(1);
166 EXPECT_CALL(stream, Close())
167 .Times(1);
168
169 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_);
170 EXPECT_TRUE(proxy->Open());
171
172 proxy->Start(&callback_);
173 proxy->Stop();
174
175 proxy->Close();
176 } 300 }
177 301
178 // Verify that the stream is closed after Stop is called. 302 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) {
179 TEST_F(AudioOutputProxyTest, CloseAfterStop) { 303 StartAndStop(mixer_);
180 MockAudioOutputStream stream;
181
182 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
183 .WillOnce(Return(&stream));
184 EXPECT_CALL(stream, Open())
185 .WillOnce(Return(true));
186 EXPECT_CALL(stream, Start(_))
187 .Times(1);
188 EXPECT_CALL(stream, SetVolume(_))
189 .Times(1);
190 EXPECT_CALL(stream, Stop())
191 .Times(1);
192 EXPECT_CALL(stream, Close())
193 .Times(1);
194
195 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_);
196 EXPECT_TRUE(proxy->Open());
197
198 proxy->Start(&callback_);
199 proxy->Stop();
200
201 // Wait for StreamStopped() to post StopStreamTask().
202 base::PlatformThread::Sleep(pause_delay_ * 2);
203 message_loop_.RunAllPending();
204
205 // Wait for the close timer to fire.
206 base::PlatformThread::Sleep(
207 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
208 message_loop_.RunAllPending();
209
210 // Verify expectation before calling Close().
211 Mock::VerifyAndClear(&stream);
212
213 proxy->Close();
214 } 304 }
215 305
216 // Create two streams, but don't start them. Only one device must be open. 306 TEST_F(AudioOutputProxyTest, CloseAfterStop) {
307 CloseAfterStop(dispatcher_impl_);
308 }
309
310 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) {
311 CloseAfterStop(mixer_);
312 }
313
217 TEST_F(AudioOutputProxyTest, TwoStreams) { 314 TEST_F(AudioOutputProxyTest, TwoStreams) {
218 MockAudioOutputStream stream; 315 TwoStreams(dispatcher_impl_);
316 }
219 317
220 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 318 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) {
221 .WillOnce(Return(&stream)); 319 TwoStreams(mixer_);
222 EXPECT_CALL(stream, Open())
223 .WillOnce(Return(true));
224 EXPECT_CALL(stream, Close())
225 .Times(1);
226
227 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_);
228 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_);
229 EXPECT_TRUE(proxy1->Open());
230 EXPECT_TRUE(proxy2->Open());
231 proxy1->Close();
232 proxy2->Close();
233 } 320 }
234 321
235 // Two streams: verify that second stream is allocated when the first 322 // Two streams: verify that second stream is allocated when the first
236 // starts playing. 323 // starts playing.
237 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { 324 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) {
238 MockAudioOutputStream stream1; 325 MockAudioOutputStream stream1;
239 MockAudioOutputStream stream2; 326 MockAudioOutputStream stream2;
240 327
241 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 328 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
242 329
(...skipping 10 matching lines...) Expand all
253 EXPECT_CALL(stream1, Stop()) 340 EXPECT_CALL(stream1, Stop())
254 .Times(1); 341 .Times(1);
255 EXPECT_CALL(stream1, Close()) 342 EXPECT_CALL(stream1, Close())
256 .Times(1); 343 .Times(1);
257 344
258 EXPECT_CALL(stream2, Open()) 345 EXPECT_CALL(stream2, Open())
259 .WillOnce(Return(true)); 346 .WillOnce(Return(true));
260 EXPECT_CALL(stream2, Close()) 347 EXPECT_CALL(stream2, Close())
261 .Times(1); 348 .Times(1);
262 349
263 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_); 350 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_);
264 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_); 351 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_);
265 EXPECT_TRUE(proxy1->Open()); 352 EXPECT_TRUE(proxy1->Open());
266 EXPECT_TRUE(proxy2->Open()); 353 EXPECT_TRUE(proxy2->Open());
267 354
268 proxy1->Start(&callback_); 355 proxy1->Start(&callback_);
269 message_loop_.RunAllPending(); 356 message_loop_.RunAllPending();
270 proxy1->Stop(); 357 proxy1->Stop();
271 358
272 proxy1->Close(); 359 proxy1->Close();
273 proxy2->Close(); 360 proxy2->Close();
274 } 361 }
275 362
363 // Two streams: verify that only one device will be created.
364 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) {
365 MockAudioOutputStream stream;
366
367 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
368
369 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
370 .WillOnce(Return(&stream));
371
372 EXPECT_CALL(stream, Open())
373 .WillOnce(Return(true));
374 EXPECT_CALL(stream, Start(_))
375 .Times(1);
376 EXPECT_CALL(stream, SetVolume(_))
377 .Times(1);
378 EXPECT_CALL(stream, Stop())
379 .Times(1);
380 EXPECT_CALL(stream, Close())
381 .Times(1);
382
383 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
384 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
385 EXPECT_TRUE(proxy1->Open());
386 EXPECT_TRUE(proxy2->Open());
387
388 proxy1->Start(&callback_);
389 proxy1->Stop();
390
391 proxy1->Close();
392 proxy2->Close();
393
394 // Wait for the close timer to fire.
395 base::PlatformThread::Sleep(
396 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
397 message_loop_.RunAllPending();
398 }
399
276 // Two streams, both are playing. Dispatcher should not open a third stream. 400 // Two streams, both are playing. Dispatcher should not open a third stream.
277 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { 401 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) {
278 MockAudioOutputStream stream1; 402 MockAudioOutputStream stream1;
279 MockAudioOutputStream stream2; 403 MockAudioOutputStream stream2;
280 404
281 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 405 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
282 406
283 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 407 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
284 .WillOnce(Return(&stream1)) 408 .WillOnce(Return(&stream1))
285 .WillOnce(Return(&stream2)); 409 .WillOnce(Return(&stream2));
(...skipping 13 matching lines...) Expand all
299 .WillOnce(Return(true)); 423 .WillOnce(Return(true));
300 EXPECT_CALL(stream2, Start(_)) 424 EXPECT_CALL(stream2, Start(_))
301 .Times(1); 425 .Times(1);
302 EXPECT_CALL(stream2, SetVolume(_)) 426 EXPECT_CALL(stream2, SetVolume(_))
303 .Times(1); 427 .Times(1);
304 EXPECT_CALL(stream2, Stop()) 428 EXPECT_CALL(stream2, Stop())
305 .Times(1); 429 .Times(1);
306 EXPECT_CALL(stream2, Close()) 430 EXPECT_CALL(stream2, Close())
307 .Times(1); 431 .Times(1);
308 432
309 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_); 433 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_);
310 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_); 434 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_);
311 EXPECT_TRUE(proxy1->Open()); 435 EXPECT_TRUE(proxy1->Open());
312 EXPECT_TRUE(proxy2->Open()); 436 EXPECT_TRUE(proxy2->Open());
313 437
314 proxy1->Start(&callback_); 438 proxy1->Start(&callback_);
315 proxy2->Start(&callback_); 439 proxy2->Start(&callback_);
316 proxy1->Stop(); 440 proxy1->Stop();
317 proxy2->Stop(); 441 proxy2->Stop();
318 442
319 proxy1->Close(); 443 proxy1->Close();
320 proxy2->Close(); 444 proxy2->Close();
321 } 445 }
322 446
323 // Open() method failed. 447 // Two streams, both are playing. Still have to use single device.
324 TEST_F(AudioOutputProxyTest, OpenFailed) { 448 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) {
325 MockAudioOutputStream stream; 449 MockAudioOutputStream stream;
326 450
451 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
452
327 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 453 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
328 .WillOnce(Return(&stream)); 454 .WillOnce(Return(&stream));
455
329 EXPECT_CALL(stream, Open()) 456 EXPECT_CALL(stream, Open())
330 .WillOnce(Return(false)); 457 .WillOnce(Return(true));
458 EXPECT_CALL(stream, Start(_))
459 .Times(1);
460 EXPECT_CALL(stream, SetVolume(_))
461 .Times(1);
462 EXPECT_CALL(stream, Stop())
463 .Times(1);
331 EXPECT_CALL(stream, Close()) 464 EXPECT_CALL(stream, Close())
332 .Times(1); 465 .Times(1);
333 466
334 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); 467 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
335 EXPECT_FALSE(proxy->Open()); 468 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
336 proxy->Close(); 469 EXPECT_TRUE(proxy1->Open());
470 EXPECT_TRUE(proxy2->Open());
471
472 proxy1->Start(&callback_);
473 proxy2->Start(&callback_);
474 proxy1->Stop();
475 proxy2->Stop();
476
477 proxy1->Close();
478 proxy2->Close();
479
480 // Wait for the close timer to fire.
481 base::PlatformThread::Sleep(
482 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
483 message_loop_.RunAllPending();
484 }
485
486 TEST_F(AudioOutputProxyTest, OpenFailed) {
487 OpenFailed(dispatcher_impl_);
488 }
489
490 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) {
491 OpenFailed(mixer_);
337 } 492 }
338 493
339 // Start() method failed. 494 // Start() method failed.
340 TEST_F(AudioOutputProxyTest, StartFailed) { 495 TEST_F(AudioOutputProxyTest, StartFailed) {
341 MockAudioOutputStream stream; 496 MockAudioOutputStream stream;
342 497
343 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 498 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
344 .WillOnce(Return(&stream)); 499 .WillOnce(Return(&stream));
345 EXPECT_CALL(stream, Open()) 500 EXPECT_CALL(stream, Open())
346 .WillOnce(Return(true)); 501 .WillOnce(Return(true));
347 EXPECT_CALL(stream, Close()) 502 EXPECT_CALL(stream, Close())
348 .Times(1); 503 .Times(1);
349 504
350 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); 505 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
351 EXPECT_TRUE(proxy->Open()); 506 EXPECT_TRUE(proxy->Open());
352 507
353 // Simulate a delay. 508 // Simulate a delay.
354 base::PlatformThread::Sleep( 509 base::PlatformThread::Sleep(
355 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); 510 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
356 message_loop_.RunAllPending(); 511 message_loop_.RunAllPending();
357 512
358 // Verify expectation before calling Close(). 513 // Verify expectation before calling Close().
359 Mock::VerifyAndClear(&stream); 514 Mock::VerifyAndClear(&stream);
360 515
361 // |stream| is closed at this point. Start() should reopen it again. 516 // |stream| is closed at this point. Start() should reopen it again.
362 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 517 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
363 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); 518 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
364 519
365 EXPECT_CALL(callback_, OnError(_, _)) 520 EXPECT_CALL(callback_, OnError(_, _))
366 .Times(1); 521 .Times(1);
367 522
368 proxy->Start(&callback_); 523 proxy->Start(&callback_);
369 524
370 Mock::VerifyAndClear(&callback_); 525 Mock::VerifyAndClear(&callback_);
371 526
372 proxy->Close(); 527 proxy->Close();
373 } 528 }
529
530 // Start() method failed.
531 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) {
532 MockAudioOutputStream stream;
533
534 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
535 .WillOnce(Return(&stream));
536 EXPECT_CALL(stream, Open())
537 .WillOnce(Return(true));
538 EXPECT_CALL(stream, Close())
539 .Times(1);
540 EXPECT_CALL(stream, Start(_))
541 .Times(1);
542 EXPECT_CALL(stream, SetVolume(_))
543 .Times(1);
544 EXPECT_CALL(stream, Stop())
545 .Times(1);
546
547 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
548 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
549 EXPECT_TRUE(proxy1->Open());
550 EXPECT_TRUE(proxy2->Open());
551 proxy1->Start(&callback_);
552 proxy1->Stop();
553 proxy1->Close();
554
555 // Wait for the close timer to fire.
556 base::PlatformThread::Sleep(
557 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
558 message_loop_.RunAllPending();
559
560 // Verify expectation before continueing.
561 Mock::VerifyAndClear(&stream);
562
563 // |stream| is closed at this point. Start() should reopen it again.
564 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
565 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
566
567 EXPECT_CALL(callback_, OnError(_, _))
568 .Times(1);
569
570 proxy2->Start(&callback_);
571
572 Mock::VerifyAndClear(&callback_);
573
574 proxy2->Close();
575
576 // Wait for the close timer to fire.
577 base::PlatformThread::Sleep(
578 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
579 message_loop_.RunAllPending();
580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698