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

Unified Diff: media/audio/audio_system_impl_unittest.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 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
« no previous file with comments | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/audio_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_system_impl_unittest.cc
diff --git a/media/audio/audio_system_impl_unittest.cc b/media/audio/audio_system_impl_unittest.cc
index 7aa5fbf2efcc5395a65e1bdb02158ad596d28092..7f0037935c21fe8e9b0e588f1604dd106a3c8724 100644
--- a/media/audio/audio_system_impl_unittest.cc
+++ b/media/audio/audio_system_impl_unittest.cc
@@ -12,7 +12,9 @@
#include "base/threading/thread_checker.h"
#include "base/threading/thread_task_runner_handle.h"
#include "media/audio/audio_device_description.h"
+#include "media/audio/audio_thread_impl.h"
#include "media/audio/mock_audio_manager.h"
+#include "media/audio/test_audio_thread.h"
#include "media/base/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -33,7 +35,6 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
public:
AudioSystemImplTest()
: use_audio_thread_(GetParam()),
- audio_thread_("AudioSystemThread"),
input_params_(AudioParameters::AUDIO_PCM_LINEAR,
CHANNEL_LAYOUT_MONO,
AudioParameters::kTelephoneSampleRate,
@@ -49,15 +50,8 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
AudioParameters::kTelephoneSampleRate,
16,
AudioParameters::kTelephoneSampleRate / 30) {
- if (use_audio_thread_) {
- audio_thread_.StartAndWaitForTesting();
- audio_manager_.reset(
- new media::MockAudioManager(audio_thread_.task_runner()));
- } else {
- audio_manager_.reset(new media::MockAudioManager(
- base::ThreadTaskRunnerHandle::Get().get()));
- }
-
+ audio_manager_ = base::MakeUnique<MockAudioManager>(
+ base::MakeUnique<TestAudioThread>(use_audio_thread_));
audio_manager_->SetInputStreamParameters(input_params_);
audio_manager_->SetOutputStreamParameters(output_params_);
audio_manager_->SetDefaultOutputStreamParameters(default_output_params_);
@@ -78,13 +72,7 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
EXPECT_EQ(AudioSystem::Get(), audio_system_.get());
}
- ~AudioSystemImplTest() override {
- // Deleting |audio_manager_| on its thread.
- audio_system_.reset();
- EXPECT_EQ(AudioSystem::Get(), nullptr);
- audio_manager_.reset();
- audio_thread_.Stop();
- }
+ ~AudioSystemImplTest() override { audio_manager_->Shutdown(); }
void OnAudioParams(const AudioParameters& expected,
const AudioParameters& received) {
@@ -133,7 +121,7 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
return;
}
WaitableMessageLoopEvent event;
- audio_thread_.task_runner()->PostTaskAndReply(
+ audio_manager_->GetTaskRunner()->PostTaskAndReply(
FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure());
// Runs the loop and waits for the |audio_thread_| to call event's closure,
// which means AudioSystem reply containing device parameters is already
@@ -154,8 +142,7 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
base::MessageLoop message_loop_;
base::ThreadChecker thread_checker_;
bool use_audio_thread_;
- base::Thread audio_thread_;
- MockAudioManager::UniquePtr audio_manager_;
+ std::unique_ptr<media::MockAudioManager> audio_manager_;
std::unique_ptr<media::AudioSystem> audio_system_;
AudioParameters input_params_;
AudioParameters output_params_;
« no previous file with comments | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/audio_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698