| Index: media/audio/audio_manager_unittest.cc
|
| diff --git a/media/audio/audio_manager_unittest.cc b/media/audio/audio_manager_unittest.cc
|
| index 894f8617c5bfa963bef00bf0dfd24622ade2c357..92846716f9927f7b2af57ecb8171d9ca3b269696 100644
|
| --- a/media/audio/audio_manager_unittest.cc
|
| +++ b/media/audio/audio_manager_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #include "media/audio/audio_manager.h"
|
| #include "media/audio/audio_manager_base.h"
|
| #include "media/audio/audio_output_proxy.h"
|
| +#include "media/audio/audio_thread.h"
|
| #include "media/audio/audio_unittest_util.h"
|
| #include "media/audio/fake_audio_log_factory.h"
|
| #include "media/audio/fake_audio_manager.h"
|
| @@ -32,6 +33,41 @@
|
|
|
| namespace media {
|
|
|
| +namespace {
|
| +template <typename T>
|
| +struct AudioManagerFactory {
|
| + static AudioManager* Create(AudioLogFactory* audio_log_factory) {
|
| + base::Thread* audio_thread = AudioThread::Get();
|
| + return new T(audio_thread->task_runner(), audio_thread->task_runner(),
|
| + audio_log_factory);
|
| + };
|
| +};
|
| +
|
| +#if defined(USE_PULSEAUDIO)
|
| +template <>
|
| +struct AudioManagerFactory<AudioManagerPulse> {
|
| + static AudioManager* Create(AudioLogFactory* audio_log_factory) {
|
| + base::Thread* audio_thread = AudioThread::Get();
|
| + AudioManagerPulse* manager =
|
| + new AudioManagerPulse(audio_thread->task_runner(),
|
| + audio_thread->task_runner(), audio_log_factory);
|
| + if (!manager->Init()) {
|
| + AudioManager::Destroy(manager);
|
| + manager = nullptr;
|
| + }
|
| + return manager;
|
| + };
|
| +};
|
| +#endif // defined(USE_PULSEAUDIO)
|
| +
|
| +template <>
|
| +struct AudioManagerFactory<std::nullptr_t> {
|
| + static AudioManager* Create(AudioLogFactory* audio_log_factory) {
|
| + return AudioManager::Create(audio_log_factory);
|
| + };
|
| +};
|
| +} // namespace
|
| +
|
| // Test fixture which allows us to override the default enumeration API on
|
| // Windows.
|
| class AudioManagerTest : public ::testing::Test {
|
| @@ -77,13 +113,10 @@ class AudioManagerTest : public ::testing::Test {
|
| }
|
|
|
| protected:
|
| - AudioManagerTest() : audio_manager_(AudioManager::CreateForTesting()) {
|
| - // Wait for audio thread initialization to complete. Otherwise the
|
| - // enumeration type may not have been set yet.
|
| - base::WaitableEvent event(false, false);
|
| - audio_manager_->GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
|
| - &base::WaitableEvent::Signal, base::Unretained(&event)));
|
| - event.Wait();
|
| + AudioManagerTest() { CreateAudioManagerForTesting(); }
|
| + ~AudioManagerTest() override {
|
| + if (audio_manager_)
|
| + AudioManager::Destroy(audio_manager_.release());
|
| }
|
|
|
| #if defined(OS_WIN)
|
| @@ -171,15 +204,15 @@ class AudioManagerTest : public ::testing::Test {
|
| return has_devices;
|
| }
|
|
|
| -#if defined(USE_ALSA) || defined(USE_PULSEAUDIO)
|
| - template <class T>
|
| + template <typename T = std::nullptr_t>
|
| void CreateAudioManagerForTesting() {
|
| // Only one AudioManager may exist at a time, so destroy the one we're
|
| // currently holding before creating a new one.
|
| - audio_manager_.reset();
|
| - audio_manager_.reset(T::Create(&fake_audio_log_factory_));
|
| + if (audio_manager_)
|
| + AudioManager::Destroy(audio_manager_.release());
|
| + audio_manager_.reset(
|
| + AudioManagerFactory<T>::Create(&fake_audio_log_factory_));
|
| }
|
| -#endif
|
|
|
| // Synchronously runs the provided callback/closure on the audio thread.
|
| void RunOnAudioThread(const base::Closure& closure) {
|
| @@ -211,7 +244,7 @@ class AudioManagerTest : public ::testing::Test {
|
| TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) {
|
| // Use a fake manager so we can makeup device ids, this will still use the
|
| // AudioManagerBase code.
|
| - audio_manager_.reset(new FakeAudioManager(&fake_audio_log_factory_));
|
| + CreateAudioManagerForTesting<FakeAudioManager>();
|
| RunOnAudioThread(base::Bind(&AudioManagerTest::HandleDefaultDeviceIDsTest,
|
| base::Unretained(this)));
|
| }
|
|
|