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 "media/audio/audio_output_controller.h" | 5 #include "media/audio/audio_output_controller.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 controller_->StopDiverting(); | 237 controller_->StopDiverting(); |
238 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
239 } | 239 } |
240 | 240 |
241 void StopDuplicating(MockAudioPushSink* sink) { | 241 void StopDuplicating(MockAudioPushSink* sink) { |
242 EXPECT_CALL(*sink, Close()); | 242 EXPECT_CALL(*sink, Close()); |
243 controller_->StopDuplicating(sink); | 243 controller_->StopDuplicating(sink); |
244 base::RunLoop().RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
245 } | 245 } |
246 | 246 |
247 void SwitchDevice(bool diverting) { | |
248 if (!diverting) { | |
249 // Expect the current stream to close and a new stream to start | |
250 // playing if not diverting. When diverting, nothing happens | |
251 // until diverting is stopped. | |
252 EXPECT_CALL(mock_event_handler_, OnControllerPlaying()); | |
253 } | |
254 | |
255 controller_->SwitchOutputDevice( | |
256 AudioDeviceDescription::GetDefaultDeviceName(), | |
257 base::Bind(&base::DoNothing)); | |
258 base::RunLoop().RunUntilIdle(); | |
259 } | |
260 | |
261 void Close() { | 247 void Close() { |
262 EXPECT_CALL(mock_sync_reader_, Close()); | 248 EXPECT_CALL(mock_sync_reader_, Close()); |
263 | 249 |
264 base::RunLoop run_loop; | 250 base::RunLoop run_loop; |
265 base::ThreadTaskRunnerHandle::Get()->PostTask( | 251 base::ThreadTaskRunnerHandle::Get()->PostTask( |
266 FROM_HERE, base::Bind(&AudioOutputController::Close, controller_, | 252 FROM_HERE, base::Bind(&AudioOutputController::Close, controller_, |
267 run_loop.QuitClosure())); | 253 run_loop.QuitClosure())); |
268 run_loop.Run(); | 254 run_loop.Run(); |
269 } | 255 } |
270 | 256 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 Close(); | 303 Close(); |
318 } | 304 } |
319 | 305 |
320 TEST_F(AudioOutputControllerTest, PlayDeviceChangeClose) { | 306 TEST_F(AudioOutputControllerTest, PlayDeviceChangeClose) { |
321 Create(kSamplesPerPacket); | 307 Create(kSamplesPerPacket); |
322 Play(); | 308 Play(); |
323 ChangeDevice(); | 309 ChangeDevice(); |
324 Close(); | 310 Close(); |
325 } | 311 } |
326 | 312 |
327 TEST_F(AudioOutputControllerTest, PlaySwitchDeviceClose) { | |
328 Create(kSamplesPerPacket); | |
329 Play(); | |
330 SwitchDevice(false); | |
331 Close(); | |
332 } | |
333 | |
334 TEST_F(AudioOutputControllerTest, PlayDivertRevertClose) { | 313 TEST_F(AudioOutputControllerTest, PlayDivertRevertClose) { |
335 Create(kSamplesPerPacket); | 314 Create(kSamplesPerPacket); |
336 Play(); | 315 Play(); |
337 DivertWhilePlaying(); | 316 DivertWhilePlaying(); |
338 ReadDivertedAudioData(); | 317 ReadDivertedAudioData(); |
339 RevertWhilePlaying(); | 318 RevertWhilePlaying(); |
340 Close(); | 319 Close(); |
341 } | 320 } |
342 | 321 |
343 TEST_F(AudioOutputControllerTest, PlayDivertSwitchDeviceRevertClose) { | |
344 Create(kSamplesPerPacket); | |
345 Play(); | |
346 DivertWhilePlaying(); | |
347 SwitchDevice(true); | |
348 ReadDivertedAudioData(); | |
349 RevertWhilePlaying(); | |
350 Close(); | |
351 } | |
352 | |
353 TEST_F(AudioOutputControllerTest, PlayDivertRevertDivertRevertClose) { | 322 TEST_F(AudioOutputControllerTest, PlayDivertRevertDivertRevertClose) { |
354 Create(kSamplesPerPacket); | 323 Create(kSamplesPerPacket); |
355 Play(); | 324 Play(); |
356 DivertWhilePlaying(); | 325 DivertWhilePlaying(); |
357 ReadDivertedAudioData(); | 326 ReadDivertedAudioData(); |
358 RevertWhilePlaying(); | 327 RevertWhilePlaying(); |
359 DivertWhilePlaying(); | 328 DivertWhilePlaying(); |
360 ReadDivertedAudioData(); | 329 ReadDivertedAudioData(); |
361 RevertWhilePlaying(); | 330 RevertWhilePlaying(); |
362 Close(); | 331 Close(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 382 |
414 // When diverted stream pulls data, it would trigger a push to sink. | 383 // When diverted stream pulls data, it would trigger a push to sink. |
415 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); | 384 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); |
416 ReadDivertedAudioData(); | 385 ReadDivertedAudioData(); |
417 | 386 |
418 StopDuplicating(&mock_sink); | 387 StopDuplicating(&mock_sink); |
419 RevertWhilePlaying(); | 388 RevertWhilePlaying(); |
420 Close(); | 389 Close(); |
421 } | 390 } |
422 | 391 |
423 TEST_F(AudioOutputControllerTest, DuplicateSwitchDeviceInteract) { | |
424 Create(kSamplesPerPacket); | |
425 MockAudioPushSink mock_sink; | |
426 Play(); | |
427 StartDuplicating(&mock_sink); | |
428 ReadDuplicatedAudioData({&mock_sink}); | |
429 | |
430 // Switching device would trigger a read, and in turn it would trigger a push | |
431 // to sink. | |
432 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); | |
433 SwitchDevice(false); | |
434 | |
435 StopDuplicating(&mock_sink); | |
436 Close(); | |
437 } | |
438 | |
439 } // namespace media | 392 } // namespace media |
OLD | NEW |