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

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

Issue 10662049: Move the device enumerate/open/close work to device thread from IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed Magnus' comments. Created 8 years, 6 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 fe57150d6747de15616b50c29d8ad9b4a1fd0b82..5e5719fc9a42ad2f869270e525f3d8b9f10b3354 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
@@ -8,13 +8,17 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "content/browser/browser_main_loop.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/renderer_host/media/audio_input_device_manager.h"
#include "content/browser/renderer_host/media/audio_input_device_manager_event_handler.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/common/main_function_params.h"
#include "media/audio/audio_manager_base.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using content::BrowserMainLoop;
using content::BrowserThread;
using content::BrowserThreadImpl;
using media_stream::AudioInputDeviceManager;
@@ -88,26 +92,31 @@ ACTION_P(ExitMessageLoop, message_loop) {
class AudioInputDeviceManagerTest : public testing::Test {
public:
AudioInputDeviceManagerTest()
- : message_loop_(),
- io_thread_(),
+ : io_thread_(),
manager_(),
audio_input_listener_() {
}
- // Returns true iff machine has an audio input device.
+ // Returns true if machine has an audio input device.
tommi (sloooow) - chröme 2012/07/02 13:36:36 I don't think that 'iff' was a typo if that's what
no longer working on chromium 2012/07/04 12:35:25 Good to know, thanks. Done.
bool CanRunAudioInputDeviceTests() {
- return audio_manager_->HasAudioInputDevices();
+ return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices();
}
protected:
virtual void SetUp() {
tommi (sloooow) - chröme 2012/07/02 13:36:36 OVERRIDE?
no longer working on chromium 2012/07/04 12:35:25 Done.
+ CommandLine command_line = CommandLine(CommandLine::NO_PROGRAM);
+ content::MainFunctionParams params_=
+ content::MainFunctionParams(command_line);
+ main_loop_.reset(new content::BrowserMainLoop(params_));
+ main_loop_->Init();
+ main_loop_->MainMessageLoopStart();
+
// The test must run on Browser::IO.
- message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
- message_loop_.get()));
- audio_manager_.reset(media::AudioManager::Create());
+ MessageLoop::current()));
- manager_ = new AudioInputDeviceManager(audio_manager_.get());
+ manager_ = new AudioInputDeviceManager(
+ MessageLoop::current()->message_loop_proxy());
audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
manager_->Register(audio_input_listener_.get());
@@ -116,8 +125,8 @@ class AudioInputDeviceManagerTest : public testing::Test {
EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_))
.Times(1);
- // Waits for the callback.
- message_loop_->RunAllPending();
+ // Wait until we get the list.
+ MessageLoop::current()->RunAllPending();
}
virtual void TearDown() {
@@ -125,11 +134,11 @@ class AudioInputDeviceManagerTest : public testing::Test {
io_thread_.reset();
}
- scoped_ptr<MessageLoop> message_loop_;
scoped_ptr<BrowserThreadImpl> io_thread_;
scoped_refptr<AudioInputDeviceManager> manager_;
scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
scoped_ptr<media::AudioManager> audio_manager_;
+ scoped_ptr<content::BrowserMainLoop> main_loop_;
private:
DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest);
@@ -161,8 +170,7 @@ TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) {
session_id))
.Times(1);
- // Waits for the callback.
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
}
@@ -192,8 +200,7 @@ TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) {
session_id[index]))
.Times(1);
- // Waits for the callback.
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
// Checks if the session_ids are unique.
@@ -211,8 +218,7 @@ TEST_F(AudioInputDeviceManagerTest, OpenMultipleDevices) {
session_id[i]))
.Times(1);
- // Waits for the callback.
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
}
@@ -233,8 +239,7 @@ TEST_F(AudioInputDeviceManagerTest, OpenNotExistingDevice) {
session_id))
.Times(1);
- // Waits for the callback.
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
// Opens default device twice.
@@ -273,8 +278,7 @@ TEST_F(AudioInputDeviceManagerTest, OpenDeviceTwice) {
second_session_id))
.Times(1);
- // Waits for the callback.
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
// Starts and closes the sessions after opening the devices.
@@ -293,7 +297,7 @@ TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) {
// Creates the EventHandler for the sessions.
scoped_ptr<MockAudioInputDeviceManagerEventHandler>
audio_input_event_handler(
- new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
+ new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
// Loops through the devices and calls Open()/Start()/Stop()/Close() for
// each device.
@@ -307,13 +311,13 @@ TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) {
Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id[index]))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
manager_->Start(session_id[index], audio_input_event_handler.get());
EXPECT_CALL(*audio_input_event_handler,
DeviceStarted(session_id[index], iter->device_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
manager_->Stop(session_id[index]);
manager_->Close(session_id[index]);
@@ -321,7 +325,7 @@ TEST_F(AudioInputDeviceManagerTest, StartAndStopSession) {
Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id[index]))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
}
@@ -341,7 +345,7 @@ TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) {
// Creates the EventHandlers for the sessions.
scoped_ptr<MockAudioInputDeviceManagerEventHandler>
audio_input_event_handler(
- new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
+ new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
// Loop through the devices, and calls Open()/Start()/Close() for the devices.
// Note that we do not call stop.
@@ -354,13 +358,13 @@ TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) {
Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id[index]))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
manager_->Start(session_id[index], audio_input_event_handler.get());
EXPECT_CALL(*audio_input_event_handler,
DeviceStarted(session_id[index], iter->device_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
// Event Handler should get a stop device notification as no stop is called
// before closing the device.
@@ -372,7 +376,7 @@ TEST_F(AudioInputDeviceManagerTest, CloseWithoutStopSession) {
Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id[index]))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
}
@@ -388,10 +392,10 @@ TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
// Create one EventHandler for each session.
scoped_ptr<MockAudioInputDeviceManagerEventHandler>
first_event_handler(
- new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
+ new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
scoped_ptr<MockAudioInputDeviceManagerEventHandler>
second_event_handler(
- new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
+ new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
// Open the default device twice.
StreamDeviceInfoArray::const_iterator iter =
@@ -407,7 +411,7 @@ TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
second_session_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
// Calls Start()/Stop()/Close() for the default device twice.
manager_->Start(first_session_id, first_event_handler.get());
@@ -420,7 +424,7 @@ TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
DeviceStarted(second_session_id,
media::AudioManagerBase::kDefaultDeviceId))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
manager_->Stop(first_session_id);
manager_->Stop(second_session_id);
@@ -434,7 +438,7 @@ TEST_F(AudioInputDeviceManagerTest, StartDeviceTwice) {
Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
second_session_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
// Starts an invalid session.
@@ -446,7 +450,7 @@ TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) {
// Creates the EventHandlers for the sessions.
scoped_ptr<MockAudioInputDeviceManagerEventHandler>
audio_input_event_handler(
- new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
+ new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
// Opens the first device.
StreamDeviceInfoArray::const_iterator iter =
@@ -456,7 +460,7 @@ TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) {
Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
// Starts a non-opened device.
// This should fail and trigger error code 'kDeviceNotAvailable'.
@@ -466,14 +470,14 @@ TEST_F(AudioInputDeviceManagerTest, StartInvalidSession) {
DeviceStarted(invalid_session_id,
AudioInputDeviceManager::kInvalidDeviceId))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
manager_->Close(session_id);
EXPECT_CALL(*audio_input_listener_,
Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
// Starts a session twice, the first time should succeed, while the second
@@ -486,7 +490,7 @@ TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
// Creates the EventHandlers for the sessions.
scoped_ptr<MockAudioInputDeviceManagerEventHandler>
audio_input_event_handler(
- new MockAudioInputDeviceManagerEventHandler(message_loop_.get()));
+ new MockAudioInputDeviceManagerEventHandler(MessageLoop::current()));
// Opens the first device.
StreamDeviceInfoArray::const_iterator iter =
@@ -496,7 +500,7 @@ TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
// Starts the session, it should succeed.
manager_->Start(session_id, audio_input_event_handler.get());
@@ -504,7 +508,7 @@ TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
DeviceStarted(session_id,
media::AudioManagerBase::kDefaultDeviceId))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
// Starts the session for the second time, it should fail.
manager_->Start(session_id, audio_input_event_handler.get());
@@ -519,7 +523,7 @@ TEST_F(AudioInputDeviceManagerTest, StartSessionTwice) {
Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
session_id))
.Times(1);
- message_loop_->RunAllPending();
+ MessageLoop::current()->RunAllPending();
}
} // namespace media_stream

Powered by Google App Engine
This is Rietveld 408576698