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

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

Issue 2763383002: Switching AudioInputDeviceManager from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: Created 3 years, 9 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 bf3b80a5528b2ecc579ddfedbbb3281c6f043d9b..5be32ea9a27d4081f42bed6cbd9a9a1519b064dd 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
@@ -21,7 +21,9 @@
#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 "media/audio/audio_system_impl.h"
#include "media/base/media_switches.h"
+#include "media/base/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -58,18 +60,21 @@ class MockAudioInputDeviceManagerListener
class MAYBE_AudioInputDeviceManagerTest : public testing::Test {
public:
- MAYBE_AudioInputDeviceManagerTest() {}
+ MAYBE_AudioInputDeviceManagerTest() : audio_thread_("AudioSystemThread") {
+ audio_thread_.StartAndWaitForTesting();
+ }
protected:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kUseFakeDeviceForMediaStream);
- audio_manager_ = media::AudioManager::CreateForTesting(
- base::ThreadTaskRunnerHandle::Get());
+ audio_manager_ =
+ media::AudioManager::CreateForTesting(audio_thread_.task_runner());
// Flush the message loop to ensure proper initialization of AudioManager.
base::RunLoop().RunUntilIdle();
- manager_ = new AudioInputDeviceManager(audio_manager_.get());
+ audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
+ manager_ = new AudioInputDeviceManager(audio_system_.get());
audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
manager_->RegisterListener(audio_input_listener_.get());
@@ -87,10 +92,25 @@ class MAYBE_AudioInputDeviceManagerTest : public testing::Test {
manager_->UnregisterListener(audio_input_listener_.get());
}
+ void WaitForOpenCompletion() {
+ // 5 cycles are enough to cover all reposts done by DeviceOpener.
+ for (int i = 0; i < 5; ++i) {
+ media::WaitableMessageLoopEvent event;
+ audio_thread_.task_runner()->PostTaskAndReply(
+ FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure());
+ // Runs the loop and waits for the |audio_thread_| to call event's
+ // closure.
+ event.RunAndWait();
+ base::RunLoop().RunUntilIdle();
+ }
+ }
+
TestBrowserThreadBundle thread_bundle_;
+ base::Thread audio_thread_;
scoped_refptr<AudioInputDeviceManager> manager_;
std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
media::ScopedAudioManagerPtr audio_manager_;
+ media::AudioSystem::UniquePtr audio_system_;
StreamDeviceInfoArray devices_;
private:
@@ -113,7 +133,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenAndCloseDevice) {
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ WaitForOpenCompletion();
manager_->Close(session_id);
EXPECT_CALL(*audio_input_listener_,
@@ -146,7 +166,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenMultipleDevices) {
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ WaitForOpenCompletion();
}
// Checks if the session_ids are unique.
@@ -183,7 +203,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenNotExistingDevice) {
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ WaitForOpenCompletion();
}
// Opens default device twice.
@@ -205,7 +225,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenDeviceTwice) {
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
.Times(1);
// Waits for the callback.
- base::RunLoop().RunUntilIdle();
+ WaitForOpenCompletion();
manager_->Close(first_session_id);
manager_->Close(second_session_id);
@@ -238,7 +258,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessAndCloseSession) {
EXPECT_CALL(*audio_input_listener_,
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
.Times(1);
- base::RunLoop().RunUntilIdle();
+ WaitForOpenCompletion();
const StreamDeviceInfo* info = manager_->GetOpenedDeviceInfoById(
session_id[index]);
@@ -262,7 +282,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessInvalidSession) {
EXPECT_CALL(*audio_input_listener_,
Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
.Times(1);
- base::RunLoop().RunUntilIdle();
+ WaitForOpenCompletion();
// Access a non-opened device.
// This should fail and return an empty StreamDeviceInfo.
@@ -278,4 +298,14 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessInvalidSession) {
base::RunLoop().RunUntilIdle();
}
+// No crash during shutdown while Open() is in progress (i.e there are tasks
+// queued on audio thread).
+TEST_F(MAYBE_AudioInputDeviceManagerTest, NoCrashOnShutdown) {
+ // Loops through the devices and calls Open() for each device.
+ for (StreamDeviceInfoArray::const_iterator iter = devices_.begin();
+ iter != devices_.end(); ++iter) {
+ manager_->Open(iter->device);
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698