Index: components/audio_modem/audio_player_unittest.cc |
diff --git a/components/audio_modem/audio_player_unittest.cc b/components/audio_modem/audio_player_unittest.cc |
index 153e6c0b23d954e4ffbac0ec2606fc014e9906f2..2a96c0f9b23cda68b64c1de87cf439f93397e8c1 100644 |
--- a/components/audio_modem/audio_player_unittest.cc |
+++ b/components/audio_modem/audio_player_unittest.cc |
@@ -8,11 +8,12 @@ |
#include "base/location.h" |
#include "base/macros.h" |
#include "base/memory/weak_ptr.h" |
-#include "base/single_thread_task_runner.h" |
+#include "base/run_loop.h" |
+#include "base/test/test_message_loop.h" |
+#include "base/thread_task_runner_handle.h" |
#include "components/audio_modem/audio_player_impl.h" |
#include "components/audio_modem/public/audio_modem_types.h" |
#include "components/audio_modem/test/random_samples.h" |
-#include "media/audio/audio_manager.h" |
#include "media/audio/audio_manager_base.h" |
#include "media/base/audio_bus.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -77,8 +78,9 @@ class AudioPlayerTest : public testing::Test, |
public base::SupportsWeakPtr<AudioPlayerTest> { |
public: |
AudioPlayerTest() : buffer_index_(0), player_(nullptr) { |
- if (!media::AudioManager::Get()) |
- media::AudioManager::CreateForTesting(); |
+ audio_manager_ = media::AudioManager::CreateForTesting( |
+ base::ThreadTaskRunnerHandle::Get()); |
+ base::RunLoop().RunUntilIdle(); |
} |
~AudioPlayerTest() override { DeletePlayer(); } |
@@ -91,6 +93,7 @@ class AudioPlayerTest : public testing::Test, |
kMaxFrameCount, |
base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr()))); |
player_->Initialize(); |
+ base::RunLoop().RunUntilIdle(); |
} |
void DeletePlayer() { |
@@ -98,6 +101,7 @@ class AudioPlayerTest : public testing::Test, |
return; |
player_->Finalize(); |
player_ = nullptr; |
+ base::RunLoop().RunUntilIdle(); |
} |
void PlayAndVerifySamples( |
@@ -107,8 +111,8 @@ class AudioPlayerTest : public testing::Test, |
buffer_ = media::AudioBus::Create(1, kMaxFrameCount); |
buffer_index_ = 0; |
player_->Play(samples); |
- player_->FlushAudioLoopForTesting(); |
player_->Stop(); |
+ base::RunLoop().RunUntilIdle(); |
int differences = 0; |
for (int i = 0; i < kMaxFrameCount; ++i) { |
@@ -129,19 +133,20 @@ class AudioPlayerTest : public testing::Test, |
protected: |
bool IsPlaying() { |
- player_->FlushAudioLoopForTesting(); |
+ base::RunLoop().RunUntilIdle(); |
return player_->is_playing_; |
} |
static const int kDefaultFrameCount = 1024; |
static const int kMaxFrameCount = 1024 * 100; |
+ base::TestMessageLoop message_loop_; |
+ media::ScopedAudioManagerPtr audio_manager_; |
scoped_ptr<media::AudioBus> buffer_; |
int buffer_index_; |
// Deleted by calling Finalize() on the object. |
AudioPlayerImpl* player_; |
- base::MessageLoop message_loop_; |
}; |
TEST_F(AudioPlayerTest, BasicPlayAndStop) { |
@@ -151,16 +156,19 @@ TEST_F(AudioPlayerTest, BasicPlayAndStop) { |
player_->Play(samples); |
EXPECT_TRUE(IsPlaying()); |
+ |
player_->Stop(); |
EXPECT_FALSE(IsPlaying()); |
- player_->Play(samples); |
+ player_->Play(samples); |
EXPECT_TRUE(IsPlaying()); |
+ |
player_->Stop(); |
EXPECT_FALSE(IsPlaying()); |
- player_->Play(samples); |
+ player_->Play(samples); |
EXPECT_TRUE(IsPlaying()); |
+ |
player_->Stop(); |
EXPECT_FALSE(IsPlaying()); |