diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-17 22:51:16 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-17 22:51:16 +0000 |
commit | 7307035b2c12088ba241dc49098204d4beff52d4 (patch) | |
tree | 9511385010f72b15bf355f0e3c0a841257a87077 /media/audio/audio_output_controller_unittest.cc | |
parent | 8e4040197b15b7af9d1510e47a7fea1d72ec6a06 (diff) | |
download | chromium_src-7307035b2c12088ba241dc49098204d4beff52d4.zip chromium_src-7307035b2c12088ba241dc49098204d4beff52d4.tar.gz chromium_src-7307035b2c12088ba241dc49098204d4beff52d4.tar.bz2 |
Make AudioOutputController.Close() truly asynchronous.
Added closed_task parameter in this method. This parameter is used to
notify the caller when the stream is actually closed. Callbacks may
be called until closed_task is executed.
BUG=55755
TEST=Unittests, audio still works, doesn't crash
Review URL: http://codereview.chromium.org/3415007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_output_controller_unittest.cc')
-rw-r--r-- | media/audio/audio_output_controller_unittest.cc | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index db1716c..b479974d 100644 --- a/media/audio/audio_output_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -5,6 +5,7 @@ #include "base/environment.h" #include "base/basictypes.h" #include "base/logging.h" +#include "base/task.h" #include "base/waitable_event.h" #include "media/audio/audio_output_controller.h" #include "testing/gmock/include/gmock/gmock.h" @@ -80,6 +81,18 @@ ACTION_P3(SignalEvent, event, count, limit) { } } +// Helper functions used to close audio controller. +static void SignalClosedEvent(base::WaitableEvent* event) { + event->Signal(); +} + +// Closes AudioOutputController synchronously. +static void CloseAudioController(AudioOutputController* controller) { + base::WaitableEvent closed_event(true, false); + controller->Close(NewRunnableFunction(&SignalClosedEvent, &closed_event)); + closed_event.Wait(); +} + TEST(AudioOutputControllerTest, CreateAndClose) { if (!HasAudioOutputDevices() || IsRunningHeadless()) return; @@ -92,11 +105,8 @@ TEST(AudioOutputControllerTest, CreateAndClose) { kHardwareBufferSize, kBufferCapacity); ASSERT_TRUE(controller.get()); - // Close the controller immediately. At this point, chances are that - // DoCreate() hasn't been called yet. In any case, it should be safe to call - // Close() and it should not try to call |event_handler| later (the test - // would crash otherwise). - controller->Close(); + // Close the controller immediately. + CloseAudioController(controller); } TEST(AudioOutputControllerTest, PlayAndClose) { @@ -134,9 +144,8 @@ TEST(AudioOutputControllerTest, PlayAndClose) { controller->Play(); event.Wait(); - // Now stop the controller. The object is freed later after DoClose() is - // executed. - controller->Close(); + // Now stop the controller. + CloseAudioController(controller); } TEST(AudioOutputControllerTest, PlayPauseClose) { @@ -186,9 +195,8 @@ TEST(AudioOutputControllerTest, PlayPauseClose) { controller->Pause(); event.Wait(); - // Now stop the controller. The object is freed later after DoClose() is - // executed. - controller->Close(); + // Now stop the controller. + CloseAudioController(controller); } TEST(AudioOutputControllerTest, PlayPausePlay) { @@ -250,9 +258,8 @@ TEST(AudioOutputControllerTest, PlayPausePlay) { controller->Play(); event.Wait(); - // Now stop the controller. The object is freed later after DoClose() is - // executed. - controller->Close(); + // Now stop the controller. + CloseAudioController(controller); } TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { @@ -302,8 +309,14 @@ TEST(AudioOutputControllerTest, CloseTwice) { // Wait for OnMoreData() to be called. event.Wait(); - controller->Close(); - controller->Close(); + base::WaitableEvent closed_event_1(true, false); + controller->Close(NewRunnableFunction(&SignalClosedEvent, &closed_event_1)); + + base::WaitableEvent closed_event_2(true, false); + controller->Close(NewRunnableFunction(&SignalClosedEvent, &closed_event_2)); + + closed_event_1.Wait(); + closed_event_2.Wait(); } } // namespace media |