Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/environment.h" | 6 #include "base/environment.h" |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 | 251 |
| 252 // And then wait for pause to complete. | 252 // And then wait for pause to complete. |
| 253 ASSERT_FALSE(pause_event.IsSignaled()); | 253 ASSERT_FALSE(pause_event.IsSignaled()); |
| 254 controller->Pause(); | 254 controller->Pause(); |
| 255 pause_event.Wait(); | 255 pause_event.Wait(); |
| 256 | 256 |
| 257 // Now stop the controller. | 257 // Now stop the controller. |
| 258 CloseAudioController(controller); | 258 CloseAudioController(controller); |
| 259 } | 259 } |
| 260 | 260 |
| 261 TEST(AudioOutputControllerTest, PlayPauseCloseLowLatency) { | |
| 262 if (!HasAudioOutputDevices() || IsRunningHeadless()) | |
| 263 return; | |
| 264 | |
| 265 MockAudioOutputControllerEventHandler event_handler; | |
| 266 base::WaitableEvent event(false, false); | |
| 267 base::WaitableEvent pause_event(false, false); | |
| 268 | |
| 269 // If OnCreated is called then signal the event. | |
| 270 EXPECT_CALL(event_handler, OnCreated(NotNull())) | |
| 271 .Times(Exactly(1)) | |
|
acolwell GONE FROM CHROMIUM
2011/10/24 03:47:15
I don't think you need the Times(Exactly(1)). I be
enal1
2011/10/24 16:28:29
Done.
| |
| 272 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); | |
| 273 | |
| 274 // OnPlaying() will be called only once. | |
| 275 EXPECT_CALL(event_handler, OnPlaying(NotNull())) | |
| 276 .Times(Exactly(1)); | |
|
acolwell GONE FROM CHROMIUM
2011/10/24 03:47:15
ditto
enal1
2011/10/24 16:28:29
Done.
| |
| 277 | |
| 278 MockAudioOutputControllerSyncReader sync_reader; | |
| 279 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) | |
| 280 .Times(AtLeast(2)); | |
| 281 EXPECT_CALL(sync_reader, DataReady()) | |
| 282 .WillOnce(Return(false)) | |
| 283 .WillOnce(Return(false)) | |
| 284 .WillRepeatedly(Return(true)); | |
| 285 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize)) | |
| 286 .WillRepeatedly(DoAll(SignalEvent(&event), | |
| 287 Return(4))); | |
| 288 EXPECT_CALL(event_handler, OnPaused(NotNull())) | |
| 289 .Times(Exactly(1)) | |
|
acolwell GONE FROM CHROMIUM
2011/10/24 03:47:15
ditto
enal1
2011/10/24 16:28:29
Done.
| |
| 290 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); | |
| 291 EXPECT_CALL(sync_reader, Close()); | |
| 292 | |
| 293 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | |
| 294 kSampleRate, kBitsPerSample, kSamplesPerPacket); | |
| 295 scoped_refptr<AudioOutputController> controller = | |
| 296 AudioOutputController::CreateLowLatency(&event_handler, | |
| 297 params, | |
| 298 &sync_reader); | |
| 299 ASSERT_TRUE(controller.get()); | |
| 300 | |
| 301 // Wait for OnCreated() to be called. | |
| 302 event.Wait(); | |
| 303 | |
| 304 ASSERT_FALSE(pause_event.IsSignaled()); | |
| 305 controller->Play(); | |
| 306 controller->Pause(); | |
| 307 pause_event.Wait(); | |
| 308 | |
| 309 // Now stop the controller. | |
| 310 CloseAudioController(controller); | |
| 311 } | |
| 312 | |
| 261 TEST(AudioOutputControllerTest, PlayPausePlay) { | 313 TEST(AudioOutputControllerTest, PlayPausePlay) { |
| 262 if (!HasAudioOutputDevices() || IsRunningHeadless()) | 314 if (!HasAudioOutputDevices() || IsRunningHeadless()) |
| 263 return; | 315 return; |
| 264 | 316 |
| 265 MockAudioOutputControllerEventHandler event_handler; | 317 MockAudioOutputControllerEventHandler event_handler; |
| 266 base::WaitableEvent event(false, false); | 318 base::WaitableEvent event(false, false); |
| 267 base::WaitableEvent pause_event(false, false); | 319 base::WaitableEvent pause_event(false, false); |
| 268 | 320 |
| 269 // If OnCreated is called then signal the event. | 321 // If OnCreated is called then signal the event. |
| 270 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 322 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_1)); | 430 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_1)); |
| 379 | 431 |
| 380 base::WaitableEvent closed_event_2(true, false); | 432 base::WaitableEvent closed_event_2(true, false); |
| 381 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_2)); | 433 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_2)); |
| 382 | 434 |
| 383 closed_event_1.Wait(); | 435 closed_event_1.Wait(); |
| 384 closed_event_2.Wait(); | 436 closed_event_2.Wait(); |
| 385 } | 437 } |
| 386 | 438 |
| 387 } // namespace media | 439 } // namespace media |
| OLD | NEW |