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

Unified Diff: media/audio/audio_manager_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: implemented ScopedAudioManagerPtr Created 4 years, 9 months 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 side-by-side diff with in-line comments
Download patch
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..7344b8c1ba10ab753691031bc9e480227a1738f4 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,40 @@
namespace media {
+namespace {
+template <typename T>
+struct AudioManagerFactory {
+ static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) {
+ base::Thread* audio_thread = AudioThread::Get();
+ return ScopedAudioManagerPtr(new T(audio_thread->task_runner(),
+ audio_thread->task_runner(),
+ audio_log_factory));
+ };
+};
+
+#if defined(USE_PULSEAUDIO)
+template <>
+struct AudioManagerFactory<AudioManagerPulse> {
+ static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) {
+ base::Thread* audio_thread = AudioThread::Get();
+ scoped_ptr<AudioManagerPulse, AudioManagerDeleter> manager(
+ new AudioManagerPulse(audio_thread->task_runner(),
+ audio_thread->task_runner(), audio_log_factory));
+ if (!manager->Init())
+ manager.reset();
+ return std::move(manager);
+ };
+};
+#endif // defined(USE_PULSEAUDIO)
+
+template <>
+struct AudioManagerFactory<std::nullptr_t> {
+ static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) {
+ return AudioManager::Create(nullptr, nullptr, nullptr, audio_log_factory);
+ };
+};
+} // namespace
+
// Test fixture which allows us to override the default enumeration API on
// Windows.
class AudioManagerTest : public ::testing::Test {
@@ -77,14 +112,8 @@ 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 defined(OS_WIN)
bool SetMMDeviceEnumeration() {
@@ -171,15 +200,13 @@ 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_));
+ audio_manager_ = AudioManagerFactory<T>::Create(&fake_audio_log_factory_);
}
-#endif
// Synchronously runs the provided callback/closure on the audio thread.
void RunOnAudioThread(const base::Closure& closure) {
@@ -205,13 +232,13 @@ class AudioManagerTest : public ::testing::Test {
}
FakeAudioLogFactory fake_audio_log_factory_;
- scoped_ptr<AudioManager> audio_manager_;
+ ScopedAudioManagerPtr audio_manager_;
};
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)));
}

Powered by Google App Engine
This is Rietveld 408576698