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

Unified Diff: media/video/capture/fake_video_capture_device_unittest.cc

Issue 294893006: VideoCaptureDeviceFactory: Change device enumeration to callback + QTKit enumerates in UI thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tommi@s comments. ConsolidateDevicesInfoOnDeviceThread() uses a const&. Created 6 years, 7 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: media/video/capture/fake_video_capture_device_unittest.cc
diff --git a/media/video/capture/fake_video_capture_device_unittest.cc b/media/video/capture/fake_video_capture_device_unittest.cc
index 929f5ecddbf3e24984703c64587b32b8e9a915ff..c3b38e97d290d41d45203d2dff40d58cc150a148 100644
--- a/media/video/capture/fake_video_capture_device_unittest.cc
+++ b/media/video/capture/fake_video_capture_device_unittest.cc
@@ -15,6 +15,7 @@
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
+using ::testing::SaveArg;
namespace media {
@@ -53,6 +54,17 @@ class MockClient : public media::VideoCaptureDevice::Client {
base::Callback<void(const VideoCaptureFormat&)> frame_cb_;
};
+class DeviceEnumerationListener :
+ public base::RefCounted<DeviceEnumerationListener> {
+ public:
+ MOCK_METHOD1(OnEnumeratedDevicesCallback,
+ void(const media::VideoCaptureDevice::Names& names));
+
+ private:
+ friend class base::RefCounted<DeviceEnumerationListener>;
+ virtual ~DeviceEnumerationListener() {}
+};
+
class FakeVideoCaptureDeviceTest : public testing::Test {
protected:
typedef media::VideoCaptureDevice::Client Client;
@@ -62,7 +74,9 @@ class FakeVideoCaptureDeviceTest : public testing::Test {
client_(new MockClient(
base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured,
base::Unretained(this)))),
- video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {}
+ video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {
+ device_enumeration_listener_ = new DeviceEnumerationListener();
+ }
virtual void SetUp() {
}
@@ -77,12 +91,23 @@ class FakeVideoCaptureDeviceTest : public testing::Test {
run_loop_->Run();
}
+ void EnumerateDevices(VideoCaptureDevice::Names* device_names) {
+ EXPECT_CALL(*device_enumeration_listener_, OnEnumeratedDevicesCallback(_))
+ .WillOnce(SaveArg<0>(device_names));
+
+ video_capture_device_factory_->EnumerateDeviceNames(
+ base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback,
+ device_enumeration_listener_));
+ base::MessageLoop::current()->RunUntilIdle();
+ }
+
const VideoCaptureFormat& last_format() const { return last_format_; }
VideoCaptureDevice::Names names_;
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_;
};
@@ -90,13 +115,12 @@ class FakeVideoCaptureDeviceTest : public testing::Test {
TEST_F(FakeVideoCaptureDeviceTest, Capture) {
VideoCaptureDevice::Names names;
- video_capture_device_factory_->GetDeviceNames(&names);
+ EnumerateDevices(&names);
ASSERT_GT(static_cast<int>(names.size()), 0);
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()).Times(0);
@@ -116,7 +140,7 @@ TEST_F(FakeVideoCaptureDeviceTest, Capture) {
TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) {
VideoCaptureDevice::Names names;
- video_capture_device_factory_->GetDeviceNames(&names);
+ EnumerateDevices(&names);
VideoCaptureFormats supported_formats;
VideoCaptureDevice::Names::iterator names_iterator;
@@ -144,7 +168,7 @@ TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) {
TEST_F(FakeVideoCaptureDeviceTest, CaptureVariableResolution) {
VideoCaptureDevice::Names names;
- video_capture_device_factory_->GetDeviceNames(&names);
+ EnumerateDevices(&names);
VideoCaptureParams capture_params;
capture_params.requested_format.frame_size.SetSize(640, 480);
capture_params.requested_format.frame_rate = 30;
@@ -154,8 +178,7 @@ TEST_F(FakeVideoCaptureDeviceTest, CaptureVariableResolution) {
ASSERT_GT(static_cast<int>(names.size()), 0);
scoped_ptr<VideoCaptureDevice> device(
- video_capture_device_factory_->Create(
- base::MessageLoopProxy::current(), names.front()));
+ video_capture_device_factory_->Create(names.front()));
ASSERT_TRUE(device);
// Configure the FakeVideoCaptureDevice to use all its formats as roster.

Powered by Google App Engine
This is Rietveld 408576698