OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // Basic Open() and Close() test. | 205 // Basic Open() and Close() test. |
206 void OpenAndClose(AudioOutputDispatcher* dispatcher) { | 206 void OpenAndClose(AudioOutputDispatcher* dispatcher) { |
207 MockAudioOutputStream stream(&manager_, params_); | 207 MockAudioOutputStream stream(&manager_, params_); |
208 | 208 |
209 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 209 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
210 .WillOnce(Return(&stream)); | 210 .WillOnce(Return(&stream)); |
211 EXPECT_CALL(stream, Open()) | 211 EXPECT_CALL(stream, Open()) |
212 .WillOnce(Return(true)); | 212 .WillOnce(Return(true)); |
213 | 213 |
214 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 214 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
215 EXPECT_TRUE(proxy->Open()); | 215 EXPECT_TRUE(proxy->Open()); |
216 CloseAndWaitForCloseTimer(proxy, &stream); | 216 CloseAndWaitForCloseTimer(proxy, &stream); |
217 } | 217 } |
218 | 218 |
219 // Creates a stream, and then calls Start() and Stop(). | 219 // Creates a stream, and then calls Start() and Stop(). |
220 void StartAndStop(AudioOutputDispatcher* dispatcher) { | 220 void StartAndStop(AudioOutputDispatcher* dispatcher) { |
221 MockAudioOutputStream stream(&manager_, params_); | 221 MockAudioOutputStream stream(&manager_, params_); |
222 | 222 |
223 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 223 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
224 .WillOnce(Return(&stream)); | 224 .WillOnce(Return(&stream)); |
225 EXPECT_CALL(stream, Open()) | 225 EXPECT_CALL(stream, Open()) |
226 .WillOnce(Return(true)); | 226 .WillOnce(Return(true)); |
227 EXPECT_CALL(stream, SetVolume(_)) | 227 EXPECT_CALL(stream, SetVolume(_)) |
228 .Times(1); | 228 .Times(1); |
229 | 229 |
230 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 230 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
231 EXPECT_TRUE(proxy->Open()); | 231 EXPECT_TRUE(proxy->Open()); |
232 | 232 |
233 proxy->Start(&callback_); | 233 proxy->Start(&callback_); |
234 OnStart(); | 234 OnStart(); |
235 proxy->Stop(); | 235 proxy->Stop(); |
236 | 236 |
237 CloseAndWaitForCloseTimer(proxy, &stream); | 237 CloseAndWaitForCloseTimer(proxy, &stream); |
238 EXPECT_TRUE(stream.stop_called()); | 238 EXPECT_TRUE(stream.stop_called()); |
239 EXPECT_TRUE(stream.start_called()); | 239 EXPECT_TRUE(stream.start_called()); |
240 } | 240 } |
241 | 241 |
242 // Verify that the stream is closed after Stop() is called. | 242 // Verify that the stream is closed after Stop() is called. |
243 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { | 243 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { |
244 MockAudioOutputStream stream(&manager_, params_); | 244 MockAudioOutputStream stream(&manager_, params_); |
245 | 245 |
246 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 246 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
247 .WillOnce(Return(&stream)); | 247 .WillOnce(Return(&stream)); |
248 EXPECT_CALL(stream, Open()) | 248 EXPECT_CALL(stream, Open()) |
249 .WillOnce(Return(true)); | 249 .WillOnce(Return(true)); |
250 EXPECT_CALL(stream, SetVolume(_)) | 250 EXPECT_CALL(stream, SetVolume(_)) |
251 .Times(1); | 251 .Times(1); |
252 | 252 |
253 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 253 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
254 EXPECT_TRUE(proxy->Open()); | 254 EXPECT_TRUE(proxy->Open()); |
255 | 255 |
256 proxy->Start(&callback_); | 256 proxy->Start(&callback_); |
257 OnStart(); | 257 OnStart(); |
258 proxy->Stop(); | 258 proxy->Stop(); |
259 | 259 |
260 // Wait for the close timer to fire after StopStream(). | 260 // Wait for the close timer to fire after StopStream(). |
261 WaitForCloseTimer(&stream); | 261 WaitForCloseTimer(&stream); |
262 proxy->Close(); | 262 proxy->Close(); |
263 EXPECT_TRUE(stream.stop_called()); | 263 EXPECT_TRUE(stream.stop_called()); |
264 EXPECT_TRUE(stream.start_called()); | 264 EXPECT_TRUE(stream.start_called()); |
265 } | 265 } |
266 | 266 |
267 // Create two streams, but don't start them. Only one device must be opened. | 267 // Create two streams, but don't start them. Only one device must be opened. |
268 void TwoStreams(AudioOutputDispatcher* dispatcher) { | 268 void TwoStreams(AudioOutputDispatcher* dispatcher) { |
269 MockAudioOutputStream stream(&manager_, params_); | 269 MockAudioOutputStream stream(&manager_, params_); |
270 | 270 |
271 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 271 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
272 .WillOnce(Return(&stream)); | 272 .WillOnce(Return(&stream)); |
273 EXPECT_CALL(stream, Open()) | 273 EXPECT_CALL(stream, Open()) |
274 .WillOnce(Return(true)); | 274 .WillOnce(Return(true)); |
275 | 275 |
276 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 276 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
277 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); | 277 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
278 EXPECT_TRUE(proxy1->Open()); | 278 EXPECT_TRUE(proxy1->Open()); |
279 EXPECT_TRUE(proxy2->Open()); | 279 EXPECT_TRUE(proxy2->Open()); |
280 proxy1->Close(); | 280 proxy1->Close(); |
281 CloseAndWaitForCloseTimer(proxy2, &stream); | 281 CloseAndWaitForCloseTimer(proxy2, &stream); |
282 EXPECT_FALSE(stream.stop_called()); | 282 EXPECT_FALSE(stream.stop_called()); |
283 EXPECT_FALSE(stream.start_called()); | 283 EXPECT_FALSE(stream.start_called()); |
284 } | 284 } |
285 | 285 |
286 // Open() method failed. | 286 // Open() method failed. |
287 void OpenFailed(AudioOutputDispatcher* dispatcher) { | 287 void OpenFailed(AudioOutputDispatcher* dispatcher) { |
288 MockAudioOutputStream stream(&manager_, params_); | 288 MockAudioOutputStream stream(&manager_, params_); |
289 | 289 |
290 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 290 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
291 .WillOnce(Return(&stream)); | 291 .WillOnce(Return(&stream)); |
292 EXPECT_CALL(stream, Open()) | 292 EXPECT_CALL(stream, Open()) |
293 .WillOnce(Return(false)); | 293 .WillOnce(Return(false)); |
294 EXPECT_CALL(stream, Close()) | 294 EXPECT_CALL(stream, Close()) |
295 .Times(1); | 295 .Times(1); |
296 | 296 |
297 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 297 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
298 EXPECT_FALSE(proxy->Open()); | 298 EXPECT_FALSE(proxy->Open()); |
299 proxy->Close(); | 299 proxy->Close(); |
300 EXPECT_FALSE(stream.stop_called()); | 300 EXPECT_FALSE(stream.stop_called()); |
301 EXPECT_FALSE(stream.start_called()); | 301 EXPECT_FALSE(stream.start_called()); |
302 } | 302 } |
303 | 303 |
304 void CreateAndWait(AudioOutputDispatcher* dispatcher) { | 304 void CreateAndWait(AudioOutputDispatcher* dispatcher) { |
305 MockAudioOutputStream stream(&manager_, params_); | 305 MockAudioOutputStream stream(&manager_, params_); |
306 | 306 |
307 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 307 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
308 .WillOnce(Return(&stream)); | 308 .WillOnce(Return(&stream)); |
309 EXPECT_CALL(stream, Open()) | 309 EXPECT_CALL(stream, Open()) |
310 .WillOnce(Return(true)); | 310 .WillOnce(Return(true)); |
311 | 311 |
312 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 312 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
313 EXPECT_TRUE(proxy->Open()); | 313 EXPECT_TRUE(proxy->Open()); |
314 | 314 |
315 WaitForCloseTimer(&stream); | 315 WaitForCloseTimer(&stream); |
316 proxy->Close(); | 316 proxy->Close(); |
317 EXPECT_FALSE(stream.stop_called()); | 317 EXPECT_FALSE(stream.stop_called()); |
318 EXPECT_FALSE(stream.start_called()); | 318 EXPECT_FALSE(stream.start_called()); |
319 } | 319 } |
320 | 320 |
321 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) { | 321 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) { |
322 MockAudioOutputStream stream(&manager_, params_); | 322 MockAudioOutputStream stream(&manager_, params_); |
323 | 323 |
324 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 324 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
325 .WillOnce(Return(&stream)); | 325 .WillOnce(Return(&stream)); |
326 | 326 |
327 EXPECT_CALL(stream, Open()) | 327 EXPECT_CALL(stream, Open()) |
328 .WillOnce(Return(true)); | 328 .WillOnce(Return(true)); |
329 EXPECT_CALL(stream, SetVolume(_)) | 329 EXPECT_CALL(stream, SetVolume(_)) |
330 .Times(2); | 330 .Times(2); |
331 | 331 |
332 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 332 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
333 EXPECT_TRUE(proxy1->Open()); | 333 EXPECT_TRUE(proxy1->Open()); |
334 | 334 |
335 proxy1->Start(&callback_); | 335 proxy1->Start(&callback_); |
336 OnStart(); | 336 OnStart(); |
337 proxy1->Stop(); | 337 proxy1->Stop(); |
338 | 338 |
339 // The stream should now be idle and get reused by |proxy2|. | 339 // The stream should now be idle and get reused by |proxy2|. |
340 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); | 340 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
341 EXPECT_TRUE(proxy2->Open()); | 341 EXPECT_TRUE(proxy2->Open()); |
342 proxy2->Start(&callback_); | 342 proxy2->Start(&callback_); |
343 OnStart(); | 343 OnStart(); |
344 proxy2->Stop(); | 344 proxy2->Stop(); |
345 | 345 |
346 proxy1->Close(); | 346 proxy1->Close(); |
347 CloseAndWaitForCloseTimer(proxy2, &stream); | 347 CloseAndWaitForCloseTimer(proxy2, &stream); |
348 EXPECT_TRUE(stream.stop_called()); | 348 EXPECT_TRUE(stream.stop_called()); |
349 EXPECT_TRUE(stream.start_called()); | 349 EXPECT_TRUE(stream.start_called()); |
350 } | 350 } |
351 | 351 |
352 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { | 352 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { |
353 MockAudioOutputStream stream1(&manager_, params_); | 353 MockAudioOutputStream stream1(&manager_, params_); |
354 MockAudioOutputStream stream2(&manager_, params_); | 354 MockAudioOutputStream stream2(&manager_, params_); |
355 | 355 |
356 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 356 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
357 .WillOnce(Return(&stream1)) | 357 .WillOnce(Return(&stream1)) |
358 .WillOnce(Return(&stream2)); | 358 .WillOnce(Return(&stream2)); |
359 | 359 |
360 EXPECT_CALL(stream1, Open()) | 360 EXPECT_CALL(stream1, Open()) |
361 .WillOnce(Return(true)); | 361 .WillOnce(Return(true)); |
362 EXPECT_CALL(stream1, SetVolume(_)) | 362 EXPECT_CALL(stream1, SetVolume(_)) |
363 .Times(1); | 363 .Times(1); |
364 | 364 |
365 EXPECT_CALL(stream2, Open()) | 365 EXPECT_CALL(stream2, Open()) |
366 .WillOnce(Return(true)); | 366 .WillOnce(Return(true)); |
367 EXPECT_CALL(stream2, SetVolume(_)) | 367 EXPECT_CALL(stream2, SetVolume(_)) |
368 .Times(1); | 368 .Times(1); |
369 | 369 |
370 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 370 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
371 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); | 371 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
372 EXPECT_TRUE(proxy1->Open()); | 372 EXPECT_TRUE(proxy1->Open()); |
373 EXPECT_TRUE(proxy2->Open()); | 373 EXPECT_TRUE(proxy2->Open()); |
374 | 374 |
375 proxy1->Start(&callback_); | 375 proxy1->Start(&callback_); |
376 proxy2->Start(&callback_); | 376 proxy2->Start(&callback_); |
377 OnStart(); | 377 OnStart(); |
378 proxy1->Stop(); | 378 proxy1->Stop(); |
379 CloseAndWaitForCloseTimer(proxy1, &stream1); | 379 CloseAndWaitForCloseTimer(proxy1, &stream1); |
380 | 380 |
381 proxy2->Stop(); | 381 proxy2->Stop(); |
382 CloseAndWaitForCloseTimer(proxy2, &stream2); | 382 CloseAndWaitForCloseTimer(proxy2, &stream2); |
383 | 383 |
384 EXPECT_TRUE(stream1.stop_called()); | 384 EXPECT_TRUE(stream1.stop_called()); |
385 EXPECT_TRUE(stream1.start_called()); | 385 EXPECT_TRUE(stream1.start_called()); |
386 EXPECT_TRUE(stream2.stop_called()); | 386 EXPECT_TRUE(stream2.stop_called()); |
387 EXPECT_TRUE(stream2.start_called()); | 387 EXPECT_TRUE(stream2.start_called()); |
388 } | 388 } |
389 | 389 |
390 void StartFailed(AudioOutputDispatcher* dispatcher) { | 390 void StartFailed(AudioOutputDispatcher* dispatcher) { |
391 MockAudioOutputStream stream(&manager_, params_); | 391 MockAudioOutputStream stream(&manager_, params_); |
392 | 392 |
393 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 393 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
394 .WillOnce(Return(&stream)); | 394 .WillOnce(Return(&stream)); |
395 EXPECT_CALL(stream, Open()) | 395 EXPECT_CALL(stream, Open()) |
396 .WillOnce(Return(true)); | 396 .WillOnce(Return(true)); |
397 | 397 |
398 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 398 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher->AsWeakPtr()); |
399 EXPECT_TRUE(proxy->Open()); | 399 EXPECT_TRUE(proxy->Open()); |
400 | 400 |
401 WaitForCloseTimer(&stream); | 401 WaitForCloseTimer(&stream); |
402 | 402 |
403 // |stream| is closed at this point. Start() should reopen it again. | 403 // |stream| is closed at this point. Start() should reopen it again. |
404 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 404 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
405 .Times(2) | 405 .Times(2) |
406 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); | 406 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
407 | 407 |
408 EXPECT_CALL(callback_, OnError(_)) | 408 EXPECT_CALL(callback_, OnError(_)) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 450 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
451 run_loop.Run(); | 451 run_loop.Run(); |
452 } | 452 } |
453 | 453 |
454 protected: | 454 protected: |
455 AudioParameters resampler_params_; | 455 AudioParameters resampler_params_; |
456 std::unique_ptr<AudioOutputResampler> resampler_; | 456 std::unique_ptr<AudioOutputResampler> resampler_; |
457 }; | 457 }; |
458 | 458 |
459 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 459 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
460 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_.get()); | 460 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_->AsWeakPtr()); |
461 proxy->Close(); | 461 proxy->Close(); |
462 } | 462 } |
463 | 463 |
464 TEST_F(AudioOutputResamplerTest, CreateAndClose) { | 464 TEST_F(AudioOutputResamplerTest, CreateAndClose) { |
465 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 465 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_->AsWeakPtr()); |
466 proxy->Close(); | 466 proxy->Close(); |
467 } | 467 } |
468 | 468 |
469 TEST_F(AudioOutputProxyTest, OpenAndClose) { | 469 TEST_F(AudioOutputProxyTest, OpenAndClose) { |
470 OpenAndClose(dispatcher_impl_.get()); | 470 OpenAndClose(dispatcher_impl_.get()); |
471 } | 471 } |
472 | 472 |
473 TEST_F(AudioOutputResamplerTest, OpenAndClose) { | 473 TEST_F(AudioOutputResamplerTest, OpenAndClose) { |
474 OpenAndClose(resampler_.get()); | 474 OpenAndClose(resampler_.get()); |
475 } | 475 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 // ensure AudioOutputResampler falls back to the high latency path. | 546 // ensure AudioOutputResampler falls back to the high latency path. |
547 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { | 547 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { |
548 MockAudioOutputStream stream(&manager_, params_); | 548 MockAudioOutputStream stream(&manager_, params_); |
549 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 549 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
550 .Times(2) | 550 .Times(2) |
551 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) | 551 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) |
552 .WillRepeatedly(Return(&stream)); | 552 .WillRepeatedly(Return(&stream)); |
553 EXPECT_CALL(stream, Open()) | 553 EXPECT_CALL(stream, Open()) |
554 .WillOnce(Return(true)); | 554 .WillOnce(Return(true)); |
555 | 555 |
556 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 556 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_->AsWeakPtr()); |
557 EXPECT_TRUE(proxy->Open()); | 557 EXPECT_TRUE(proxy->Open()); |
558 CloseAndWaitForCloseTimer(proxy, &stream); | 558 CloseAndWaitForCloseTimer(proxy, &stream); |
559 } | 559 } |
560 | 560 |
561 // Simulate AudioOutputStream::Open() failure with a low latency stream and | 561 // Simulate AudioOutputStream::Open() failure with a low latency stream and |
562 // ensure AudioOutputResampler falls back to the high latency path. | 562 // ensure AudioOutputResampler falls back to the high latency path. |
563 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { | 563 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { |
564 MockAudioOutputStream failed_stream(&manager_, params_); | 564 MockAudioOutputStream failed_stream(&manager_, params_); |
565 MockAudioOutputStream okay_stream(&manager_, params_); | 565 MockAudioOutputStream okay_stream(&manager_, params_); |
566 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 566 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
567 .Times(2) | 567 .Times(2) |
568 .WillOnce(Return(&failed_stream)) | 568 .WillOnce(Return(&failed_stream)) |
569 .WillRepeatedly(Return(&okay_stream)); | 569 .WillRepeatedly(Return(&okay_stream)); |
570 EXPECT_CALL(failed_stream, Open()) | 570 EXPECT_CALL(failed_stream, Open()) |
571 .WillOnce(Return(false)); | 571 .WillOnce(Return(false)); |
572 EXPECT_CALL(failed_stream, Close()) | 572 EXPECT_CALL(failed_stream, Close()) |
573 .Times(1); | 573 .Times(1); |
574 EXPECT_CALL(okay_stream, Open()) | 574 EXPECT_CALL(okay_stream, Open()) |
575 .WillOnce(Return(true)); | 575 .WillOnce(Return(true)); |
576 | 576 |
577 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 577 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_->AsWeakPtr()); |
578 EXPECT_TRUE(proxy->Open()); | 578 EXPECT_TRUE(proxy->Open()); |
579 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 579 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
580 } | 580 } |
581 | 581 |
582 // Simulate failures to open both the low latency and the fallback high latency | 582 // Simulate failures to open both the low latency and the fallback high latency |
583 // stream and ensure AudioOutputResampler falls back to a fake stream. | 583 // stream and ensure AudioOutputResampler falls back to a fake stream. |
584 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { | 584 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { |
585 MockAudioOutputStream okay_stream(&manager_, params_); | 585 MockAudioOutputStream okay_stream(&manager_, params_); |
586 | 586 |
587 // Only Windows has a high latency output driver that is not the same as the low | 587 // Only Windows has a high latency output driver that is not the same as the low |
(...skipping 16 matching lines...) Expand all Loading... |
604 testing::Property(&AudioParameters::sample_rate, | 604 testing::Property(&AudioParameters::sample_rate, |
605 params_.sample_rate()), | 605 params_.sample_rate()), |
606 testing::Property(&AudioParameters::frames_per_buffer, | 606 testing::Property(&AudioParameters::frames_per_buffer, |
607 params_.frames_per_buffer())), | 607 params_.frames_per_buffer())), |
608 _, _)) | 608 _, _)) |
609 .Times(1) | 609 .Times(1) |
610 .WillOnce(Return(&okay_stream)); | 610 .WillOnce(Return(&okay_stream)); |
611 EXPECT_CALL(okay_stream, Open()) | 611 EXPECT_CALL(okay_stream, Open()) |
612 .WillOnce(Return(true)); | 612 .WillOnce(Return(true)); |
613 | 613 |
614 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 614 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_->AsWeakPtr()); |
615 EXPECT_TRUE(proxy->Open()); | 615 EXPECT_TRUE(proxy->Open()); |
616 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 616 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
617 } | 617 } |
618 | 618 |
619 // Simulate failures to open both the low latency, the fallback high latency | 619 // Simulate failures to open both the low latency, the fallback high latency |
620 // stream, and the fake audio output stream and ensure AudioOutputResampler | 620 // stream, and the fake audio output stream and ensure AudioOutputResampler |
621 // terminates normally. | 621 // terminates normally. |
622 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { | 622 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { |
623 // Only Windows has a high latency output driver that is not the same as the low | 623 // Only Windows has a high latency output driver that is not the same as the low |
624 // latency path. | 624 // latency path. |
625 #if defined(OS_WIN) | 625 #if defined(OS_WIN) |
626 static const int kFallbackCount = 3; | 626 static const int kFallbackCount = 3; |
627 #else | 627 #else |
628 static const int kFallbackCount = 2; | 628 static const int kFallbackCount = 2; |
629 #endif | 629 #endif |
630 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 630 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
631 .Times(kFallbackCount) | 631 .Times(kFallbackCount) |
632 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 632 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
633 | 633 |
634 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 634 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_->AsWeakPtr()); |
635 EXPECT_FALSE(proxy->Open()); | 635 EXPECT_FALSE(proxy->Open()); |
636 proxy->Close(); | 636 proxy->Close(); |
637 } | 637 } |
638 | 638 |
639 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls | 639 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls |
640 // eventually followed by one which fails; root cause of http://crbug.com/150619 | 640 // eventually followed by one which fails; root cause of http://crbug.com/150619 |
641 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { | 641 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { |
642 MockAudioOutputStream stream1(&manager_, params_); | 642 MockAudioOutputStream stream1(&manager_, params_); |
643 MockAudioOutputStream stream2(&manager_, params_); | 643 MockAudioOutputStream stream2(&manager_, params_); |
644 | 644 |
645 // Setup the mock such that all three streams are successfully created. | 645 // Setup the mock such that all three streams are successfully created. |
646 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 646 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) |
647 .WillOnce(Return(&stream1)) | 647 .WillOnce(Return(&stream1)) |
648 .WillOnce(Return(&stream2)) | 648 .WillOnce(Return(&stream2)) |
649 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 649 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
650 | 650 |
651 // Stream1 should be able to successfully open and start. | 651 // Stream1 should be able to successfully open and start. |
652 EXPECT_CALL(stream1, Open()) | 652 EXPECT_CALL(stream1, Open()) |
653 .WillOnce(Return(true)); | 653 .WillOnce(Return(true)); |
654 EXPECT_CALL(stream1, SetVolume(_)) | 654 EXPECT_CALL(stream1, SetVolume(_)) |
655 .Times(1); | 655 .Times(1); |
656 | 656 |
657 // Stream2 should also be able to successfully open and start. | 657 // Stream2 should also be able to successfully open and start. |
658 EXPECT_CALL(stream2, Open()) | 658 EXPECT_CALL(stream2, Open()) |
659 .WillOnce(Return(true)); | 659 .WillOnce(Return(true)); |
660 EXPECT_CALL(stream2, SetVolume(_)) | 660 EXPECT_CALL(stream2, SetVolume(_)) |
661 .Times(1); | 661 .Times(1); |
662 | 662 |
663 // Open and start the first proxy and stream. | 663 // Open and start the first proxy and stream. |
664 AudioOutputProxy* proxy1 = new AudioOutputProxy(resampler_.get()); | 664 AudioOutputProxy* proxy1 = new AudioOutputProxy(resampler_->AsWeakPtr()); |
665 EXPECT_TRUE(proxy1->Open()); | 665 EXPECT_TRUE(proxy1->Open()); |
666 proxy1->Start(&callback_); | 666 proxy1->Start(&callback_); |
667 OnStart(); | 667 OnStart(); |
668 | 668 |
669 // Open and start the second proxy and stream. | 669 // Open and start the second proxy and stream. |
670 AudioOutputProxy* proxy2 = new AudioOutputProxy(resampler_.get()); | 670 AudioOutputProxy* proxy2 = new AudioOutputProxy(resampler_->AsWeakPtr()); |
671 EXPECT_TRUE(proxy2->Open()); | 671 EXPECT_TRUE(proxy2->Open()); |
672 proxy2->Start(&callback_); | 672 proxy2->Start(&callback_); |
673 OnStart(); | 673 OnStart(); |
674 | 674 |
675 // Attempt to open the third stream which should fail. | 675 // Attempt to open the third stream which should fail. |
676 AudioOutputProxy* proxy3 = new AudioOutputProxy(resampler_.get()); | 676 AudioOutputProxy* proxy3 = new AudioOutputProxy(resampler_->AsWeakPtr()); |
677 EXPECT_FALSE(proxy3->Open()); | 677 EXPECT_FALSE(proxy3->Open()); |
678 proxy3->Close(); | 678 proxy3->Close(); |
679 | 679 |
680 // Perform the required Stop()/Close() shutdown dance for each proxy. Under | 680 // Perform the required Stop()/Close() shutdown dance for each proxy. Under |
681 // the hood each proxy should correctly call CloseStream() if OpenStream() | 681 // the hood each proxy should correctly call CloseStream() if OpenStream() |
682 // succeeded or not. | 682 // succeeded or not. |
683 proxy2->Stop(); | 683 proxy2->Stop(); |
684 CloseAndWaitForCloseTimer(proxy2, &stream2); | 684 CloseAndWaitForCloseTimer(proxy2, &stream2); |
685 | 685 |
686 proxy1->Stop(); | 686 proxy1->Stop(); |
(...skipping 25 matching lines...) Expand all Loading... |
712 MakeAudioOutputStream( | 712 MakeAudioOutputStream( |
713 AllOf(testing::Property(&AudioParameters::format, | 713 AllOf(testing::Property(&AudioParameters::format, |
714 AudioParameters::AUDIO_FAKE), | 714 AudioParameters::AUDIO_FAKE), |
715 testing::Property(&AudioParameters::sample_rate, | 715 testing::Property(&AudioParameters::sample_rate, |
716 params_.sample_rate()), | 716 params_.sample_rate()), |
717 testing::Property(&AudioParameters::frames_per_buffer, | 717 testing::Property(&AudioParameters::frames_per_buffer, |
718 params_.frames_per_buffer())), | 718 params_.frames_per_buffer())), |
719 _, _)) | 719 _, _)) |
720 .WillOnce(Return(&fake_stream)); | 720 .WillOnce(Return(&fake_stream)); |
721 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); | 721 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); |
722 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 722 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_->AsWeakPtr()); |
723 EXPECT_TRUE(proxy->Open()); | 723 EXPECT_TRUE(proxy->Open()); |
724 CloseAndWaitForCloseTimer(proxy, &fake_stream); | 724 CloseAndWaitForCloseTimer(proxy, &fake_stream); |
725 | 725 |
726 // Once all proxies have been closed, AudioOutputResampler will start the | 726 // Once all proxies have been closed, AudioOutputResampler will start the |
727 // reinitialization timer and execute it after the close delay elapses. | 727 // reinitialization timer and execute it after the close delay elapses. |
728 base::RunLoop run_loop; | 728 base::RunLoop run_loop; |
729 message_loop_.task_runner()->PostDelayedTask( | 729 message_loop_.task_runner()->PostDelayedTask( |
730 FROM_HERE, run_loop.QuitClosure(), | 730 FROM_HERE, run_loop.QuitClosure(), |
731 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); | 731 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); |
732 run_loop.Run(); | 732 run_loop.Run(); |
733 | 733 |
734 // Verify a non-fake stream can be created. | 734 // Verify a non-fake stream can be created. |
735 MockAudioOutputStream real_stream(&manager_, params_); | 735 MockAudioOutputStream real_stream(&manager_, params_); |
736 EXPECT_CALL(manager(), | 736 EXPECT_CALL(manager(), |
737 MakeAudioOutputStream( | 737 MakeAudioOutputStream( |
738 testing::Property(&AudioParameters::format, | 738 testing::Property(&AudioParameters::format, |
739 testing::Ne(AudioParameters::AUDIO_FAKE)), | 739 testing::Ne(AudioParameters::AUDIO_FAKE)), |
740 _, _)) | 740 _, _)) |
741 .WillOnce(Return(&real_stream)); | 741 .WillOnce(Return(&real_stream)); |
742 | 742 |
743 // Stream1 should be able to successfully open and start. | 743 // Stream1 should be able to successfully open and start. |
744 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); | 744 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); |
745 proxy = new AudioOutputProxy(resampler_.get()); | 745 proxy = new AudioOutputProxy(resampler_->AsWeakPtr()); |
746 EXPECT_TRUE(proxy->Open()); | 746 EXPECT_TRUE(proxy->Open()); |
747 CloseAndWaitForCloseTimer(proxy, &real_stream); | 747 CloseAndWaitForCloseTimer(proxy, &real_stream); |
748 } | 748 } |
749 | 749 |
750 } // namespace media | 750 } // namespace media |
OLD | NEW |