Commit 9fcf57a3 authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

Use ScopedTaskEnvironment instead of MessageLoop

MessageLoop will go away, eventually.

ScopedTaskEnvironment will per default start a ThreadPool, which should
be fine in most of the cases. If you belive your test needs to make sure
that no ThreadPool runs let me know and I will update the patch.

BUG=891670
This CL was uploaded by git cl split.

R=maxmorin@chromium.org

Change-Id: I32710534bd1ce31feda549e8fea8b7e4156c933b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636355
Auto-Submit: Carlos Caballero <carlscab@google.com>
Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Commit-Queue: Max Morin <maxmorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665064}
parent 10399622
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "media/audio/audio_manager.h" #include "media/audio/audio_manager.h"
#include "media/audio/fake_audio_input_stream.h" #include "media/audio/fake_audio_input_stream.h"
...@@ -144,7 +144,7 @@ class AudioInputControllerTest : public testing::TestWithParam<bool> { ...@@ -144,7 +144,7 @@ class AudioInputControllerTest : public testing::TestWithParam<bool> {
run_loop.Run(); run_loop.Run();
} }
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
// Parameterize tests to run AudioInputController either on audio thread // Parameterize tests to run AudioInputController either on audio thread
// (synchronously), or on a different thread (non-blocking). // (synchronously), or on a different thread (non-blocking).
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "media/audio/audio_manager.h" #include "media/audio/audio_manager.h"
...@@ -488,7 +488,7 @@ class AudioOutputProxyTest : public testing::Test { ...@@ -488,7 +488,7 @@ class AudioOutputProxyTest : public testing::Test {
proxy->Close(); proxy->Close();
} }
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
MockAudioManager manager_; MockAudioManager manager_;
std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_impl_; std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_impl_;
MockAudioSourceCallback callback_; MockAudioSourceCallback callback_;
...@@ -511,7 +511,7 @@ class AudioOutputResamplerTest : public AudioOutputProxyTest { ...@@ -511,7 +511,7 @@ class AudioOutputResamplerTest : public AudioOutputProxyTest {
void OnStart() override { void OnStart() override {
// Let Start() run for a bit. // Let Start() run for a bit.
base::RunLoop run_loop; base::RunLoop run_loop;
message_loop_.task_runner()->PostDelayedTask( scoped_task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); base::TimeDelta::FromMilliseconds(kStartRunTimeMs));
run_loop.Run(); run_loop.Run();
...@@ -824,7 +824,7 @@ TEST_F(AudioOutputResamplerTest, FallbackRecovery) { ...@@ -824,7 +824,7 @@ TEST_F(AudioOutputResamplerTest, FallbackRecovery) {
// Once all proxies have been closed, AudioOutputResampler will start the // Once all proxies have been closed, AudioOutputResampler will start the
// reinitialization timer and execute it after the close delay elapses. // reinitialization timer and execute it after the close delay elapses.
base::RunLoop run_loop; base::RunLoop run_loop;
message_loop_.task_runner()->PostDelayedTask( scoped_task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs));
run_loop.Run(); run_loop.Run();
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "media/audio/audio_system_impl.h" #include "media/audio/audio_system_impl.h"
#include "base/message_loop/message_loop.h" #include "base/test/scoped_task_environment.h"
#include "media/audio/audio_system_test_util.h" #include "media/audio/audio_system_test_util.h"
#include "media/audio/audio_thread_impl.h" #include "media/audio/audio_thread_impl.h"
#include "media/audio/mock_audio_manager.h" #include "media/audio/mock_audio_manager.h"
...@@ -35,7 +35,7 @@ class AudioSystemImplTestBase : public testing::Test { ...@@ -35,7 +35,7 @@ class AudioSystemImplTestBase : public testing::Test {
MockAudioManager* audio_manager() { return audio_manager_.get(); } MockAudioManager* audio_manager() { return audio_manager_.get(); }
AudioSystem* audio_system() { return audio_system_.get(); } AudioSystem* audio_system() { return audio_system_.get(); }
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<MockAudioManager> audio_manager_; std::unique_ptr<MockAudioManager> audio_manager_;
std::unique_ptr<AudioSystem> audio_system_; std::unique_ptr<AudioSystem> audio_system_;
// AudioSystemTester tester_; // AudioSystemTester tester_;
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "media/base/bind_to_current_loop.h" #include "media/base/bind_to_current_loop.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -25,7 +25,7 @@ class AudioDeviceListenerMacTest : public testing::Test { ...@@ -25,7 +25,7 @@ class AudioDeviceListenerMacTest : public testing::Test {
AudioDeviceListenerMacTest() { AudioDeviceListenerMacTest() {
// It's important to create the device listener from the message loop in // It's important to create the device listener from the message loop in
// order to ensure we don't end up with unbalanced TaskObserver calls. // order to ensure we don't end up with unbalanced TaskObserver calls.
message_loop_.task_runner()->PostTask( scoped_task_environment_.GetMainThreadTaskRunner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&AudioDeviceListenerMacTest::CreateDeviceListener, base::BindOnce(&AudioDeviceListenerMacTest::CreateDeviceListener,
base::Unretained(this))); base::Unretained(this)));
...@@ -35,7 +35,7 @@ class AudioDeviceListenerMacTest : public testing::Test { ...@@ -35,7 +35,7 @@ class AudioDeviceListenerMacTest : public testing::Test {
virtual ~AudioDeviceListenerMacTest() { virtual ~AudioDeviceListenerMacTest() {
// It's important to destroy the device listener from the message loop in // It's important to destroy the device listener from the message loop in
// order to ensure we don't end up with unbalanced TaskObserver calls. // order to ensure we don't end up with unbalanced TaskObserver calls.
message_loop_.task_runner()->PostTask( scoped_task_environment_.GetMainThreadTaskRunner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&AudioDeviceListenerMacTest::DestroyDeviceListener, base::BindOnce(&AudioDeviceListenerMacTest::DestroyDeviceListener,
base::Unretained(this))); base::Unretained(this)));
...@@ -98,7 +98,7 @@ class AudioDeviceListenerMacTest : public testing::Test { ...@@ -98,7 +98,7 @@ class AudioDeviceListenerMacTest : public testing::Test {
MOCK_METHOD0(OnDeviceChange, void()); MOCK_METHOD0(OnDeviceChange, void());
protected: protected:
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<AudioDeviceListenerMac> device_listener_; std::unique_ptr<AudioDeviceListenerMac> device_listener_;
DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerMacTest); DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerMacTest);
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/environment.h" #include "base/environment.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "media/audio/audio_device_description.h" #include "media/audio/audio_device_description.h"
...@@ -33,9 +33,9 @@ using ::testing::NotNull; ...@@ -33,9 +33,9 @@ using ::testing::NotNull;
namespace media { namespace media {
ACTION_P4(CheckCountAndPostQuitTask, count, limit, loop, closure) { ACTION_P4(CheckCountAndPostQuitTask, count, limit, task_runner, closure) {
if (++*count >= limit) { if (++*count >= limit) {
loop->task_runner()->PostTask(FROM_HERE, closure); task_runner->PostTask(FROM_HERE, closure);
} }
} }
...@@ -113,7 +113,8 @@ class WriteToFileAudioSink : public AudioInputStream::AudioInputCallback { ...@@ -113,7 +113,8 @@ class WriteToFileAudioSink : public AudioInputStream::AudioInputCallback {
class MacAudioInputTest : public testing::Test { class MacAudioInputTest : public testing::Test {
protected: protected:
MacAudioInputTest() MacAudioInputTest()
: message_loop_(base::MessageLoop::TYPE_UI), : scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI),
audio_manager_(AudioManager::CreateForTesting( audio_manager_(AudioManager::CreateForTesting(
std::make_unique<TestAudioThread>())) { std::make_unique<TestAudioThread>())) {
// Wait for the AudioManager to finish any initialization on the audio loop. // Wait for the AudioManager to finish any initialization on the audio loop.
...@@ -158,7 +159,7 @@ class MacAudioInputTest : public testing::Test { ...@@ -158,7 +159,7 @@ class MacAudioInputTest : public testing::Test {
void OnLogMessage(const std::string& message) { log_message_ = message; } void OnLogMessage(const std::string& message) { log_message_ = message; }
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<AudioManager> audio_manager_; std::unique_ptr<AudioManager> audio_manager_;
std::string log_message_; std::string log_message_;
}; };
...@@ -217,7 +218,8 @@ TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyMonoRecording) { ...@@ -217,7 +218,8 @@ TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyMonoRecording) {
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_CALL(sink, OnData(NotNull(), _, _)) EXPECT_CALL(sink, OnData(NotNull(), _, _))
.Times(AtLeast(10)) .Times(AtLeast(10))
.WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &message_loop_, .WillRepeatedly(CheckCountAndPostQuitTask(
&count, 10, scoped_task_environment_.GetMainThreadTaskRunner(),
run_loop.QuitClosure())); run_loop.QuitClosure()));
ais->Start(&sink); ais->Start(&sink);
run_loop.Run(); run_loop.Run();
...@@ -252,7 +254,8 @@ TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyStereoRecording) { ...@@ -252,7 +254,8 @@ TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyStereoRecording) {
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_CALL(sink, OnData(NotNull(), _, _)) EXPECT_CALL(sink, OnData(NotNull(), _, _))
.Times(AtLeast(10)) .Times(AtLeast(10))
.WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &message_loop_, .WillRepeatedly(CheckCountAndPostQuitTask(
&count, 10, scoped_task_environment_.GetMainThreadTaskRunner(),
run_loop.QuitClosure())); run_loop.QuitClosure()));
ais->Start(&sink); ais->Start(&sink);
run_loop.Run(); run_loop.Run();
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
#include "base/environment.h" #include "base/environment.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "base/win/scoped_com_initializer.h" #include "base/win/scoped_com_initializer.h"
#include "media/audio/audio_device_description.h" #include "media/audio/audio_device_description.h"
...@@ -268,7 +268,7 @@ class WinAudioInputTest : public ::testing::Test { ...@@ -268,7 +268,7 @@ class WinAudioInputTest : public ::testing::Test {
~WinAudioInputTest() override { audio_manager_->Shutdown(); } ~WinAudioInputTest() override { audio_manager_->Shutdown(); }
protected: protected:
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<AudioManager> audio_manager_; std::unique_ptr<AudioManager> audio_manager_;
}; };
...@@ -413,8 +413,8 @@ TEST_F(WinAudioInputTest, WASAPIAudioInputStreamTestPacketSizes) { ...@@ -413,8 +413,8 @@ TEST_F(WinAudioInputTest, WASAPIAudioInputStreamTestPacketSizes) {
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_CALL(sink, OnData(NotNull(), _, _)) EXPECT_CALL(sink, OnData(NotNull(), _, _))
.Times(AtLeast(10)) .Times(AtLeast(10))
.WillRepeatedly( .WillRepeatedly(CheckCountAndPostQuitTask(
CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner(), &count, 10, scoped_task_environment_.GetMainThreadTaskRunner(),
run_loop.QuitWhenIdleClosure())); run_loop.QuitWhenIdleClosure()));
ais->Start(&sink); ais->Start(&sink);
run_loop.Run(); run_loop.Run();
...@@ -438,8 +438,8 @@ TEST_F(WinAudioInputTest, WASAPIAudioInputStreamTestPacketSizes) { ...@@ -438,8 +438,8 @@ TEST_F(WinAudioInputTest, WASAPIAudioInputStreamTestPacketSizes) {
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_CALL(sink, OnData(NotNull(), _, _)) EXPECT_CALL(sink, OnData(NotNull(), _, _))
.Times(AtLeast(10)) .Times(AtLeast(10))
.WillRepeatedly( .WillRepeatedly(CheckCountAndPostQuitTask(
CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner(), &count, 10, scoped_task_environment_.GetMainThreadTaskRunner(),
run_loop.QuitWhenIdleClosure())); run_loop.QuitWhenIdleClosure()));
ais->Start(&sink); ais->Start(&sink);
run_loop.Run(); run_loop.Run();
...@@ -459,8 +459,8 @@ TEST_F(WinAudioInputTest, WASAPIAudioInputStreamTestPacketSizes) { ...@@ -459,8 +459,8 @@ TEST_F(WinAudioInputTest, WASAPIAudioInputStreamTestPacketSizes) {
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_CALL(sink, OnData(NotNull(), _, _)) EXPECT_CALL(sink, OnData(NotNull(), _, _))
.Times(AtLeast(10)) .Times(AtLeast(10))
.WillRepeatedly( .WillRepeatedly(CheckCountAndPostQuitTask(
CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner(), &count, 10, scoped_task_environment_.GetMainThreadTaskRunner(),
run_loop.QuitWhenIdleClosure())); run_loop.QuitWhenIdleClosure()));
ais->Start(&sink); ais->Start(&sink);
run_loop.Run(); run_loop.Run();
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
#include "base/base_paths.h" #include "base/base_paths.h"
#include "base/memory/aligned_memory.h" #include "base/memory/aligned_memory.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/sync_socket.h" #include "base/sync_socket.h"
#include "base/test/scoped_task_environment.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/win/scoped_com_initializer.h" #include "base/win/scoped_com_initializer.h"
#include "media/audio/audio_device_info_accessor_for_tests.h" #include "media/audio/audio_device_info_accessor_for_tests.h"
...@@ -164,7 +164,7 @@ class WinAudioTest : public ::testing::Test { ...@@ -164,7 +164,7 @@ class WinAudioTest : public ::testing::Test {
~WinAudioTest() override { audio_manager_->Shutdown(); } ~WinAudioTest() override { audio_manager_->Shutdown(); }
protected: protected:
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<AudioManager> audio_manager_; std::unique_ptr<AudioManager> audio_manager_;
std::unique_ptr<AudioDeviceInfoAccessorForTests> audio_manager_device_info_; std::unique_ptr<AudioDeviceInfoAccessorForTests> audio_manager_device_info_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment