Index: media/audio/audio_output_controller_unittest.cc |
=================================================================== |
--- media/audio/audio_output_controller_unittest.cc (revision 104976) |
+++ media/audio/audio_output_controller_unittest.cc (working copy) |
@@ -14,6 +14,7 @@ |
using ::testing::_; |
using ::testing::AtLeast; |
+using ::testing::DoAll; |
using ::testing::Exactly; |
using ::testing::InvokeWithoutArgs; |
using ::testing::NotNull; |
@@ -54,6 +55,7 @@ |
MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); |
MOCK_METHOD2(Read, uint32(void* data, uint32 size)); |
MOCK_METHOD0(Close, void()); |
+ MOCK_METHOD0(DataReady, bool()); |
private: |
DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); |
@@ -150,6 +152,58 @@ |
CloseAudioController(controller); |
} |
+TEST(AudioOutputControllerTest, PlayAndCloseLowLatency) { |
+ if (!HasAudioOutputDevices() || IsRunningHeadless()) |
+ return; |
+ |
+ MockAudioOutputControllerEventHandler event_handler; |
+ base::WaitableEvent event(false, false); |
+ |
+ // If OnCreated is called then signal the event. |
+ EXPECT_CALL(event_handler, OnCreated(NotNull())) |
+ .WillOnce(SignalEvent(&event)); |
+ |
+ // OnPlaying() will be called only once. |
+ EXPECT_CALL(event_handler, OnPlaying(NotNull())) |
+ .Times(Exactly(1)); |
+ |
+ MockAudioOutputControllerSyncReader sync_reader; |
+ EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) |
+ .Times(AtLeast(10)); |
+ EXPECT_CALL(sync_reader, DataReady()) |
+ .WillOnce(Return(false)) |
+ .WillOnce(Return(false)) |
+ .WillRepeatedly(Return(true)); |
+ EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize)) |
+ .Times(AtLeast(10)) |
+ .WillRepeatedly(DoAll(SignalEvent(&event), |
+ Return(1))); |
+ EXPECT_CALL(sync_reader, Close()); |
+ |
+ AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, |
+ kSampleRate, kBitsPerSample, kSamplesPerPacket); |
+ scoped_refptr<AudioOutputController> controller = |
+ AudioOutputController::CreateLowLatency(&event_handler, |
+ params, |
+ &sync_reader); |
+ ASSERT_TRUE(controller.get()); |
+ |
+ // Wait for OnCreated() to be called. |
+ event.Wait(); |
+ |
+ controller->Play(); |
+ |
+ // Wait until the date is requested at least 10 times. |
+ for (int i = 0; i < 10; i++) { |
+ event.Wait(); |
+ uint8 buf[1]; |
+ controller->EnqueueData(buf, 0); |
+ } |
+ |
+ // Now stop the controller. |
+ CloseAudioController(controller); |
+} |
+ |
TEST(AudioOutputControllerTest, PlayPauseClose) { |
if (!HasAudioOutputDevices() || IsRunningHeadless()) |
return; |