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

Unified Diff: content/browser/renderer_host/media/audio_input_device_manager_unittest.cc

Issue 1901583005: Revert of Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
diff --git a/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc b/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
index a465a63a4cda1415e19fc613c550213d39c3ee0d..dd387bbdf23bba4b201a66c60b27c49763e97fec 100644
--- a/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
+++ b/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
@@ -13,12 +13,11 @@
#include "base/location.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
-#include "base/thread_task_runner_handle.h"
+#include "base/synchronization/waitable_event.h"
#include "build/build_config.h"
+#include "content/browser/browser_thread_impl.h"
#include "content/public/common/media_stream_request.h"
-#include "content/public/test/test_browser_thread_bundle.h"
#include "media/audio/audio_manager_base.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -63,16 +62,22 @@
protected:
void SetUp() override {
- audio_manager_ = media::AudioManager::CreateForTesting(
- base::ThreadTaskRunnerHandle::Get());
- // Flush the message loop to ensure proper initialization of AudioManager.
- base::RunLoop().RunUntilIdle();
-
+ // The test must run on Browser::IO.
+ message_loop_.reset(new base::MessageLoopForIO);
+ io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
+ message_loop_.get()));
+ audio_manager_.reset(media::AudioManager::CreateForTesting());
+ // Wait for audio thread initialization to complete. Otherwise the
+ // enumeration type may not have been set yet.
+ base::WaitableEvent event(false, false);
+ audio_manager_->GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
+ &base::WaitableEvent::Signal, base::Unretained(&event)));
+ event.Wait();
manager_ = new AudioInputDeviceManager(audio_manager_.get());
manager_->UseFakeDevice();
audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
manager_->Register(audio_input_listener_.get(),
- audio_manager_->GetTaskRunner());
+ message_loop_->task_runner().get());
// Gets the enumerated device list from the AudioInputDeviceManager.
manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE);
@@ -82,17 +87,19 @@
.WillOnce(SaveArg<1>(&devices_));
// Wait until we get the list.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
void TearDown() override {
manager_->Unregister();
- }
-
- TestBrowserThreadBundle thread_bundle_;
+ io_thread_.reset();
+ }
+
+ std::unique_ptr<base::MessageLoop> message_loop_;
+ std::unique_ptr<BrowserThreadImpl> io_thread_;
scoped_refptr<AudioInputDeviceManager> manager_;
std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
- media::ScopedAudioManagerPtr audio_manager_;
+ std::unique_ptr<media::AudioManager> audio_manager_;
StreamDeviceInfoArray devices_;
private:
@@ -116,7 +123,7 @@
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
manager_->Close(session_id);
EXPECT_CALL(*audio_input_listener_,
@@ -124,7 +131,7 @@
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
}
@@ -149,7 +156,7 @@
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
// Checks if the session_ids are unique.
@@ -167,7 +174,7 @@
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
}
@@ -189,7 +196,7 @@
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
// Opens default device twice.
@@ -211,7 +218,7 @@
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
manager_->Close(first_session_id);
manager_->Close(second_session_id);
@@ -222,7 +229,7 @@
Closed(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
// Accesses then closes the sessions after opening the devices.
@@ -244,7 +251,7 @@
EXPECT_CALL(*audio_input_listener_,
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
.Times(1);
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
const StreamDeviceInfo* info = manager_->GetOpenedDeviceInfoById(
session_id[index]);
@@ -254,7 +261,7 @@
EXPECT_CALL(*audio_input_listener_,
Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
.Times(1);
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
}
@@ -268,7 +275,7 @@
EXPECT_CALL(*audio_input_listener_,
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
.Times(1);
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
// Access a non-opened device.
// This should fail and return an empty StreamDeviceInfo.
@@ -281,7 +288,7 @@
EXPECT_CALL(*audio_input_listener_,
Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
.Times(1);
- base::RunLoop().RunUntilIdle();
+ message_loop_->RunUntilIdle();
}
} // namespace content
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/browser/renderer_host/media/audio_output_device_enumerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698