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

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

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: fixes content_browsertests and content_unittests Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "media/audio/audio_system_impl.h" 5 #include "media/audio/audio_system_impl.h"
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 base::Unretained(&input_device_descriptions_))); 71 base::Unretained(&input_device_descriptions_)));
72 audio_manager_->SetOutputDeviceDescriptionsCallback( 72 audio_manager_->SetOutputDeviceDescriptionsCallback(
73 base::Bind(get_device_descriptions, 73 base::Bind(get_device_descriptions,
74 base::Unretained(&output_device_descriptions_))); 74 base::Unretained(&output_device_descriptions_)));
75 75
76 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 76 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
77 EXPECT_EQ(AudioSystem::Get(), audio_system_.get()); 77 EXPECT_EQ(AudioSystem::Get(), audio_system_.get());
78 } 78 }
79 79
80 ~AudioSystemImplTest() override { 80 ~AudioSystemImplTest() override {
81 // Deleting |audio_manager_| on its thread.
82 audio_system_.reset(); 81 audio_system_.reset();
83 EXPECT_EQ(AudioSystem::Get(), nullptr); 82 EXPECT_EQ(AudioSystem::Get(), nullptr);
84 audio_manager_.reset(); 83
85 audio_thread_.Stop(); 84 audio_manager_->GetTaskRunner()->PostTask(
85 FROM_HERE, base::Bind(&media::AudioManager::Shutdown,
86 base::Unretained(audio_manager_.get())));
86 } 87 }
87 88
88 void OnAudioParams(const AudioParameters& expected, 89 void OnAudioParams(const AudioParameters& expected,
89 const AudioParameters& received) { 90 const AudioParameters& received) {
90 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); 91 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
91 EXPECT_EQ(expected.AsHumanReadableString(), 92 EXPECT_EQ(expected.AsHumanReadableString(),
92 received.AsHumanReadableString()); 93 received.AsHumanReadableString());
93 AudioParametersReceived(); 94 AudioParametersReceived();
94 } 95 }
95 96
(...skipping 27 matching lines...) Expand all
123 124
124 // Mocks to verify that AudioSystem replied with an expected callback. 125 // Mocks to verify that AudioSystem replied with an expected callback.
125 MOCK_METHOD0(AudioParametersReceived, void(void)); 126 MOCK_METHOD0(AudioParametersReceived, void(void));
126 MOCK_METHOD1(HasInputDevicesCallback, void(bool)); 127 MOCK_METHOD1(HasInputDevicesCallback, void(bool));
127 MOCK_METHOD0(DeviceDescriptionsReceived, void(void)); 128 MOCK_METHOD0(DeviceDescriptionsReceived, void(void));
128 129
129 protected: 130 protected:
130 base::MessageLoop message_loop_; 131 base::MessageLoop message_loop_;
131 base::ThreadChecker thread_checker_; 132 base::ThreadChecker thread_checker_;
132 bool use_audio_thread_; 133 bool use_audio_thread_;
134 std::unique_ptr<media::MockAudioManager> audio_manager_;
135 std::unique_ptr<media::AudioSystem> audio_system_;
133 base::Thread audio_thread_; 136 base::Thread audio_thread_;
134 MockAudioManager::UniquePtr audio_manager_;
135 std::unique_ptr<media::AudioSystem> audio_system_;
136 AudioParameters input_params_; 137 AudioParameters input_params_;
137 AudioParameters output_params_; 138 AudioParameters output_params_;
138 AudioParameters default_output_params_; 139 AudioParameters default_output_params_;
139 AudioDeviceDescriptions input_device_descriptions_; 140 AudioDeviceDescriptions input_device_descriptions_;
140 AudioDeviceDescriptions output_device_descriptions_; 141 AudioDeviceDescriptions output_device_descriptions_;
141 }; 142 };
142 143
143 TEST_P(AudioSystemImplTest, GetInputStreamParameters) { 144 TEST_P(AudioSystemImplTest, GetInputStreamParameters) {
144 EXPECT_CALL(*this, AudioParametersReceived()); 145 EXPECT_CALL(*this, AudioParametersReceived());
145 audio_system_->GetInputStreamParameters( 146 audio_system_->GetInputStreamParameters(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 audio_system_->GetDeviceDescriptions( 265 audio_system_->GetDeviceDescriptions(
265 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions, 266 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions,
266 base::Unretained(this), output_device_descriptions_), 267 base::Unretained(this), output_device_descriptions_),
267 false); 268 false);
268 WaitForCallback(); 269 WaitForCallback();
269 } 270 }
270 271
271 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true)); 272 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true));
272 273
273 } // namespace media 274 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698