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

Unified Diff: media/audio/audio_input_controller_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/android/audio_manager_android.cc ('k') | media/audio/audio_input_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_input_controller_unittest.cc
diff --git a/media/audio/audio_input_controller_unittest.cc b/media/audio/audio_input_controller_unittest.cc
index 545cd1d615fcb5304122beefdfd5308a427f0f9e..2aaaec71d51245c4afb8c07fc7c5b718097a0610 100644
--- a/media/audio/audio_input_controller_unittest.cc
+++ b/media/audio/audio_input_controller_unittest.cc
@@ -2,15 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "media/audio/audio_input_controller.h"
#include "base/bind.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread.h"
#include "media/audio/audio_device_description.h"
-#include "media/audio/audio_input_controller.h"
+#include "media/audio/audio_thread_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -80,22 +82,15 @@ class MockSyncWriter : public AudioInputController::SyncWriter {
class AudioInputControllerTest : public testing::Test {
public:
AudioInputControllerTest()
- : audio_thread_("AudioThread"),
- suspend_event_(WaitableEvent::ResetPolicy::AUTOMATIC,
+ : suspend_event_(WaitableEvent::ResetPolicy::AUTOMATIC,
WaitableEvent::InitialState::NOT_SIGNALED) {
- audio_thread_.StartAndWaitForTesting();
audio_manager_ =
- AudioManager::CreateForTesting(audio_thread_.task_runner());
- }
- ~AudioInputControllerTest() override {
- audio_task_runner()->PostTask(
- FROM_HERE, base::Bind(&AudioInputControllerTest::DeleteAudioManager,
- base::Unretained(this)));
- audio_thread_.Stop();
+ AudioManager::CreateForTesting(base::MakeUnique<AudioThreadImpl>());
}
+ ~AudioInputControllerTest() override { audio_manager_->Shutdown(); }
scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner() const {
- return audio_thread_.task_runner();
+ return audio_manager_->GetTaskRunner();
}
void SuspendAudioThread() {
@@ -107,13 +102,11 @@ class AudioInputControllerTest : public testing::Test {
void ResumeAudioThread() { suspend_event_.Signal(); }
private:
- void DeleteAudioManager() { audio_manager_.reset(); }
void WaitForResume() { suspend_event_.Wait(); }
protected:
- base::Thread audio_thread_;
base::MessageLoop message_loop_;
- ScopedAudioManagerPtr audio_manager_;
+ std::unique_ptr<AudioManager> audio_manager_;
WaitableEvent suspend_event_;
private:
@@ -142,8 +135,6 @@ TEST_F(AudioInputControllerTest, CreateAndClose) {
ResumeAudioThread();
CloseAudioController(controller.get());
-
- audio_thread_.FlushForTesting();
}
// Test a normal call sequence of create, record and close.
« no previous file with comments | « media/audio/android/audio_manager_android.cc ('k') | media/audio/audio_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698