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 "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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 private: | 45 private: |
46 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); | 46 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); |
47 }; | 47 }; |
48 | 48 |
49 class MockAudioOutputControllerSyncReader | 49 class MockAudioOutputControllerSyncReader |
50 : public AudioOutputController::SyncReader { | 50 : public AudioOutputController::SyncReader { |
51 public: | 51 public: |
52 MockAudioOutputControllerSyncReader() {} | 52 MockAudioOutputControllerSyncReader() {} |
53 | 53 |
54 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); | 54 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); |
55 MOCK_METHOD1(Read, int(AudioBus* audio_bus)); | 55 MOCK_METHOD2(Read, int(AudioBus* source, AudioBus* dest)); |
56 MOCK_METHOD0(Close, void()); | 56 MOCK_METHOD0(Close, void()); |
57 MOCK_METHOD0(DataReady, bool()); | 57 MOCK_METHOD0(DataReady, bool()); |
58 | 58 |
59 private: | 59 private: |
60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); | 60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); |
61 }; | 61 }; |
62 | 62 |
63 ACTION_P(SignalEvent, event) { | 63 ACTION_P(SignalEvent, event) { |
64 event->Signal(); | 64 event->Signal(); |
65 } | 65 } |
66 | 66 |
67 // Custom action to clear a memory buffer. | 67 // Custom action to clear a memory buffer. |
68 ACTION(ClearBuffer) { | 68 ACTION(ClearBuffer) { |
69 arg0->Zero(); | 69 arg1->Zero(); |
70 } | 70 } |
71 | 71 |
72 // Closes AudioOutputController synchronously. | 72 // Closes AudioOutputController synchronously. |
73 static void CloseAudioController(AudioOutputController* controller) { | 73 static void CloseAudioController(AudioOutputController* controller) { |
74 controller->Close(MessageLoop::QuitClosure()); | 74 controller->Close(MessageLoop::QuitClosure()); |
75 MessageLoop::current()->Run(); | 75 MessageLoop::current()->Run(); |
76 } | 76 } |
77 | 77 |
78 class AudioOutputControllerTest : public testing::Test { | 78 class AudioOutputControllerTest : public testing::Test { |
79 public: | 79 public: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // If OnCreated is called then signal the event. | 123 // If OnCreated is called then signal the event. |
124 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 124 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
125 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); | 125 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); |
126 | 126 |
127 // OnPlaying() will be called only once. | 127 // OnPlaying() will be called only once. |
128 EXPECT_CALL(event_handler, OnPlaying(NotNull())); | 128 EXPECT_CALL(event_handler, OnPlaying(NotNull())); |
129 | 129 |
130 MockAudioOutputControllerSyncReader sync_reader; | 130 MockAudioOutputControllerSyncReader sync_reader; |
131 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) | 131 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) |
132 .Times(AtLeast(2)); | 132 .Times(AtLeast(2)); |
133 EXPECT_CALL(sync_reader, Read(_)) | 133 EXPECT_CALL(sync_reader, Read(_, _)) |
134 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event), | 134 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event), |
135 Return(4))); | 135 Return(4))); |
136 EXPECT_CALL(sync_reader, DataReady()) | 136 EXPECT_CALL(sync_reader, DataReady()) |
137 .WillRepeatedly(Return(true)); | 137 .WillRepeatedly(Return(true)); |
138 EXPECT_CALL(event_handler, OnPaused(NotNull())) | 138 EXPECT_CALL(event_handler, OnPaused(NotNull())) |
139 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); | 139 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); |
140 EXPECT_CALL(sync_reader, Close()); | 140 EXPECT_CALL(sync_reader, Close()); |
141 | 141 |
142 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | 142 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, |
143 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 143 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 .WillOnce(InvokeWithoutArgs(&play_event, &base::WaitableEvent::Signal)); | 195 .WillOnce(InvokeWithoutArgs(&play_event, &base::WaitableEvent::Signal)); |
196 | 196 |
197 // OnPaused() should never be called since the pause during kStarting is | 197 // OnPaused() should never be called since the pause during kStarting is |
198 // dropped when the second play comes in. | 198 // dropped when the second play comes in. |
199 EXPECT_CALL(event_handler, OnPaused(NotNull())) | 199 EXPECT_CALL(event_handler, OnPaused(NotNull())) |
200 .Times(0); | 200 .Times(0); |
201 | 201 |
202 MockAudioOutputControllerSyncReader sync_reader; | 202 MockAudioOutputControllerSyncReader sync_reader; |
203 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) | 203 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) |
204 .Times(AtLeast(1)); | 204 .Times(AtLeast(1)); |
205 EXPECT_CALL(sync_reader, Read(_)) | 205 EXPECT_CALL(sync_reader, Read(_, _)) |
206 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event), Return(4))); | 206 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event), Return(4))); |
207 EXPECT_CALL(sync_reader, DataReady()) | 207 EXPECT_CALL(sync_reader, DataReady()) |
208 .WillRepeatedly(Return(true)); | 208 .WillRepeatedly(Return(true)); |
209 EXPECT_CALL(sync_reader, Close()); | 209 EXPECT_CALL(sync_reader, Close()); |
210 | 210 |
211 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | 211 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, |
212 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 212 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
213 scoped_refptr<AudioOutputController> controller = | 213 scoped_refptr<AudioOutputController> controller = |
214 AudioOutputController::Create( | 214 AudioOutputController::Create( |
215 audio_manager.get(), &event_handler, params, &sync_reader); | 215 audio_manager.get(), &event_handler, params, &sync_reader); |
216 ASSERT_TRUE(controller.get()); | 216 ASSERT_TRUE(controller.get()); |
217 | 217 |
218 // Wait for OnCreated() to be called. | 218 // Wait for OnCreated() to be called. |
219 event.Wait(); | 219 event.Wait(); |
220 | 220 |
221 ASSERT_FALSE(play_event.IsSignaled()); | 221 ASSERT_FALSE(play_event.IsSignaled()); |
222 controller->Play(); | 222 controller->Play(); |
223 controller->Pause(); | 223 controller->Pause(); |
224 controller->Play(); | 224 controller->Play(); |
225 play_event.Wait(); | 225 play_event.Wait(); |
226 | 226 |
227 // Now stop the controller. | 227 // Now stop the controller. |
228 CloseAudioController(controller); | 228 CloseAudioController(controller); |
229 } | 229 } |
230 | 230 |
231 } // namespace media | 231 } // namespace media |
OLD | NEW |