Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: media/audio/audio_output_controller_unittest.cc

Issue 8371013: Harden audio output controller making it safe to call Pause() before (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
272
273 // OnPlaying() will be called only once.
274 EXPECT_CALL(event_handler, OnPlaying(NotNull()));
275
276 MockAudioOutputControllerSyncReader sync_reader;
277 EXPECT_CALL(sync_reader, UpdatePendingBytes(_))
278 .Times(AtLeast(2));
279 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize))
280 .WillRepeatedly(DoAll(SignalEvent(&event),
281 Return(4)));
282 EXPECT_CALL(event_handler, OnPaused(NotNull()))
283 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
284 EXPECT_CALL(sync_reader, Close());
285
286 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
287 kSampleRate, kBitsPerSample, kSamplesPerPacket);
288 scoped_refptr<AudioOutputController> controller =
289 AudioOutputController::CreateLowLatency(&event_handler,
290 params,
291 &sync_reader);
292 ASSERT_TRUE(controller.get());
293
294 // Wait for OnCreated() to be called.
295 event.Wait();
296
297 ASSERT_FALSE(pause_event.IsSignaled());
298 controller->Play();
299 controller->Pause();
300 pause_event.Wait();
301
302 // Now stop the controller.
303 CloseAudioController(controller);
304 }
305
261 TEST(AudioOutputControllerTest, PlayPausePlay) { 306 TEST(AudioOutputControllerTest, PlayPausePlay) {
262 if (!HasAudioOutputDevices() || IsRunningHeadless()) 307 if (!HasAudioOutputDevices() || IsRunningHeadless())
263 return; 308 return;
264 309
265 MockAudioOutputControllerEventHandler event_handler; 310 MockAudioOutputControllerEventHandler event_handler;
266 base::WaitableEvent event(false, false); 311 base::WaitableEvent event(false, false);
267 base::WaitableEvent pause_event(false, false); 312 base::WaitableEvent pause_event(false, false);
268 313
269 // If OnCreated is called then signal the event. 314 // If OnCreated is called then signal the event.
270 EXPECT_CALL(event_handler, OnCreated(NotNull())) 315 EXPECT_CALL(event_handler, OnCreated(NotNull()))
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_1)); 423 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_1));
379 424
380 base::WaitableEvent closed_event_2(true, false); 425 base::WaitableEvent closed_event_2(true, false);
381 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_2)); 426 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_2));
382 427
383 closed_event_1.Wait(); 428 closed_event_1.Wait();
384 closed_event_2.Wait(); 429 closed_event_2.Wait();
385 } 430 }
386 431
387 } // namespace media 432 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698