Index: media/video/capture/video_capture_device_unittest.cc |
diff --git a/media/video/capture/video_capture_device_unittest.cc b/media/video/capture/video_capture_device_unittest.cc |
index 50ef2d96779e29cadd87f164fcde2b684f082655..e78fbe153f2da7e8f6e975f5a8b7f6200b107728 100644 |
--- a/media/video/capture/video_capture_device_unittest.cc |
+++ b/media/video/capture/video_capture_device_unittest.cc |
@@ -3,6 +3,8 @@ |
// found in the LICENSE file. |
#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop_proxy.h" |
#include "base/run_loop.h" |
@@ -51,6 +53,9 @@ |
#define MAYBE_CaptureMjpeg CaptureMjpeg |
#endif |
+using ::testing::_; |
+using ::testing::SaveArg; |
+ |
namespace media { |
class MockClient : public media::VideoCaptureDevice::Client { |
@@ -88,6 +93,20 @@ class MockClient : public media::VideoCaptureDevice::Client { |
base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
}; |
+class DeviceEnumerationListener : |
+ public base::RefCounted<DeviceEnumerationListener>{ |
+ public: |
+ MOCK_METHOD1(OnEnumeratedDevicesCallback, |
+ void(media::VideoCaptureDevice::Names& names)); |
+ |
+ void EnumeratedDevicesCallback(media::VideoCaptureDevice::Names& names) { |
+ OnEnumeratedDevicesCallback(names); |
+ } |
+ private: |
+ friend class base::RefCounted<DeviceEnumerationListener>; |
+ ~DeviceEnumerationListener() {} |
+}; |
+ |
class VideoCaptureDeviceTest : public testing::Test { |
protected: |
typedef media::VideoCaptureDevice::Client Client; |
@@ -97,8 +116,10 @@ class VideoCaptureDeviceTest : public testing::Test { |
client_( |
new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
base::Unretained(this)))), |
- video_capture_device_factory_( |
- VideoCaptureDeviceFactory::CreateFactory()) {} |
+ video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( |
+ base::MessageLoopProxy::current())) { |
+ device_enumeration_listener_ = new DeviceEnumerationListener(); |
+ } |
virtual void SetUp() { |
#if defined(OS_ANDROID) |
@@ -122,11 +143,21 @@ class VideoCaptureDeviceTest : public testing::Test { |
run_loop_->Run(); |
} |
+ void EnumerateDevices(VideoCaptureDevice::Names* device_names) { |
+ EXPECT_CALL(*device_enumeration_listener_, OnEnumeratedDevicesCallback(_)) |
+ .WillOnce(SaveArg<0>(device_names)); |
tommi (sloooow) - chröme
2014/05/30 12:37:51
indent
mcasas
2014/05/30 14:08:50
Done.
|
+ |
+ video_capture_device_factory_->EnumerateDeviceNames( |
+ base::Bind(&DeviceEnumerationListener::EnumeratedDevicesCallback, |
+ device_enumeration_listener_)); |
+ base::MessageLoop::current()->RunUntilIdle(); |
+ } |
+ |
const VideoCaptureFormat& last_format() const { return last_format_; } |
scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( |
const VideoPixelFormat& pixel_format) { |
- video_capture_device_factory_->GetDeviceNames(&names_); |
+ EnumerateDevices(&names_); |
if (!names_.size()) { |
DVLOG(1) << "No camera available."; |
return scoped_ptr<VideoCaptureDevice::Name>(); |
@@ -158,6 +189,7 @@ class VideoCaptureDeviceTest : public testing::Test { |
scoped_ptr<base::MessageLoop> loop_; |
scoped_ptr<base::RunLoop> run_loop_; |
scoped_ptr<MockClient> client_; |
+ scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
VideoCaptureFormat last_format_; |
scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; |
}; |
@@ -176,22 +208,19 @@ TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
VideoCaptureDevice::Name device_name("jibberish", "jibberish"); |
#endif |
scoped_ptr<VideoCaptureDevice> device = |
- video_capture_device_factory_->Create( |
- base::MessageLoopProxy::current(), |
- device_name); |
+ video_capture_device_factory_->Create(device_name); |
EXPECT_TRUE(device == NULL); |
} |
TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
- video_capture_device_factory_->GetDeviceNames(&names_); |
+ EnumerateDevices(&names_); |
if (!names_.size()) { |
DVLOG(1) << "No camera available. Exiting test."; |
return; |
} |
scoped_ptr<VideoCaptureDevice> device( |
- video_capture_device_factory_->Create(base::MessageLoopProxy::current(), |
- names_.front())); |
+ video_capture_device_factory_->Create(names_.front())); |
ASSERT_TRUE(device); |
DVLOG(1) << names_.front().id(); |
@@ -212,15 +241,14 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
} |
TEST_F(VideoCaptureDeviceTest, Capture720p) { |
- video_capture_device_factory_->GetDeviceNames(&names_); |
+ EnumerateDevices(&names_); |
if (!names_.size()) { |
DVLOG(1) << "No camera available. Exiting test."; |
return; |
} |
scoped_ptr<VideoCaptureDevice> device( |
- video_capture_device_factory_->Create(base::MessageLoopProxy::current(), |
- names_.front())); |
+ video_capture_device_factory_->Create(names_.front())); |
ASSERT_TRUE(device); |
EXPECT_CALL(*client_, OnErr()) |
@@ -238,14 +266,13 @@ TEST_F(VideoCaptureDeviceTest, Capture720p) { |
} |
TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
- video_capture_device_factory_->GetDeviceNames(&names_); |
+ EnumerateDevices(&names_); |
if (!names_.size()) { |
DVLOG(1) << "No camera available. Exiting test."; |
return; |
} |
scoped_ptr<VideoCaptureDevice> device( |
- video_capture_device_factory_->Create(base::MessageLoopProxy::current(), |
- names_.front())); |
+ video_capture_device_factory_->Create(names_.front())); |
ASSERT_TRUE(device); |
EXPECT_CALL(*client_, OnErr()) |
@@ -264,7 +291,7 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
} |
TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
- video_capture_device_factory_->GetDeviceNames(&names_); |
+ EnumerateDevices(&names_); |
if (!names_.size()) { |
DVLOG(1) << "No camera available. Exiting test."; |
return; |
@@ -274,8 +301,7 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
for (int i = 0; i <= 5; i++) { |
ResetWithNewClient(); |
scoped_ptr<VideoCaptureDevice> device( |
- video_capture_device_factory_->Create(base::MessageLoopProxy::current(), |
- names_.front())); |
+ video_capture_device_factory_->Create(names_.front())); |
gfx::Size resolution; |
if (i % 2) { |
resolution = gfx::Size(640, 480); |
@@ -300,8 +326,7 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
ResetWithNewClient(); |
scoped_ptr<VideoCaptureDevice> device( |
- video_capture_device_factory_->Create(base::MessageLoopProxy::current(), |
- names_.front())); |
+ video_capture_device_factory_->Create(names_.front())); |
device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
WaitForCapturedFrame(); |
@@ -312,14 +337,13 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
} |
TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
- video_capture_device_factory_->GetDeviceNames(&names_); |
+ EnumerateDevices(&names_); |
if (!names_.size()) { |
DVLOG(1) << "No camera available. Exiting test."; |
return; |
} |
scoped_ptr<VideoCaptureDevice> device( |
- video_capture_device_factory_->Create(base::MessageLoopProxy::current(), |
- names_.front())); |
+ video_capture_device_factory_->Create(names_.front())); |
ASSERT_TRUE(device); |
EXPECT_CALL(*client_, OnErr()) |
@@ -348,8 +372,7 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
return; |
} |
scoped_ptr<VideoCaptureDevice> device( |
- video_capture_device_factory_->Create(base::MessageLoopProxy::current(), |
- *name)); |
+ video_capture_device_factory_->Create(*name)); |
ASSERT_TRUE(device); |
EXPECT_CALL(*client_, OnErr()) |