| Index: content/renderer/media/video_capture_impl_unittest.cc
|
| diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc
|
| index 713b3a06d4fba6ac7c0e51812e909fdf7cf2e4f4..1d4cb50d632aa88f59ba40295b9ff8d0e27e323d 100644
|
| --- a/content/renderer/media/video_capture_impl_unittest.cc
|
| +++ b/content/renderer/media/video_capture_impl_unittest.cc
|
| @@ -3,15 +3,18 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/message_loop/message_loop.h"
|
| +#include "base/run_loop.h"
|
| #include "content/child/child_process.h"
|
| #include "content/common/media/video_capture_messages.h"
|
| #include "content/renderer/media/video_capture_impl.h"
|
| +#include "media/video/capture/mock_video_capture_event_handler.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| using ::testing::_;
|
| using ::testing::AtLeast;
|
| -using ::testing::Return;
|
| +using ::testing::InvokeWithoutArgs;
|
| +using media::MockVideoCaptureEventHandler;
|
|
|
| namespace content {
|
|
|
| @@ -29,36 +32,13 @@ class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
|
| DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter);
|
| };
|
|
|
| -class MockVideoCaptureClient : public media::VideoCapture::EventHandler {
|
| - public:
|
| - MockVideoCaptureClient() {}
|
| - virtual ~MockVideoCaptureClient() {}
|
| -
|
| - // EventHandler implementation.
|
| - MOCK_METHOD1(OnStarted, void(media::VideoCapture* capture));
|
| - MOCK_METHOD1(OnStopped, void(media::VideoCapture* capture));
|
| - MOCK_METHOD1(OnPaused, void(media::VideoCapture* capture));
|
| - MOCK_METHOD2(OnError, void(media::VideoCapture* capture, int error_code));
|
| - MOCK_METHOD1(OnRemoved, void(media::VideoCapture* capture));
|
| - MOCK_METHOD2(OnFrameReady,
|
| - void(media::VideoCapture* capture,
|
| - const scoped_refptr<media::VideoFrame>& frame));
|
| - MOCK_METHOD2(OnDeviceInfoReceived,
|
| - void(media::VideoCapture* capture,
|
| - const media::VideoCaptureFormat& device_info));
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureClient);
|
| -};
|
| -
|
| class VideoCaptureImplTest : public ::testing::Test {
|
| public:
|
| class MockVideoCaptureImpl : public VideoCaptureImpl {
|
| public:
|
| MockVideoCaptureImpl(const media::VideoCaptureSessionId id,
|
| - scoped_refptr<base::MessageLoopProxy> ml_proxy,
|
| VideoCaptureMessageFilter* filter)
|
| - : VideoCaptureImpl(id, ml_proxy.get(), filter) {}
|
| + : VideoCaptureImpl(id, filter) {}
|
| virtual ~MockVideoCaptureImpl() {}
|
|
|
| // Override Send() to mimic device to send events.
|
| @@ -102,15 +82,13 @@ class VideoCaptureImplTest : public ::testing::Test {
|
| params_large_.requested_format = media::VideoCaptureFormat(
|
| gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
|
|
|
| - message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO));
|
| - message_loop_proxy_ = base::MessageLoopProxy::current().get();
|
| child_process_.reset(new ChildProcess());
|
|
|
| message_filter_ = new MockVideoCaptureMessageFilter;
|
| session_id_ = 1;
|
|
|
| video_capture_impl_ = new MockVideoCaptureImpl(
|
| - session_id_, message_loop_proxy_, message_filter_.get());
|
| + session_id_, message_filter_.get());
|
|
|
| video_capture_impl_->device_id_ = 2;
|
| }
|
| @@ -119,9 +97,13 @@ class VideoCaptureImplTest : public ::testing::Test {
|
| delete video_capture_impl_;
|
| }
|
|
|
| + void Quit() {
|
| + message_loop_.PostTask(FROM_HERE, run_loop_.QuitClosure());
|
| + }
|
| +
|
| protected:
|
| - scoped_ptr<base::MessageLoop> message_loop_;
|
| - scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
|
| + base::MessageLoop message_loop_;
|
| + base::RunLoop run_loop_;
|
| scoped_ptr<ChildProcess> child_process_;
|
| scoped_refptr<MockVideoCaptureMessageFilter> message_filter_;
|
| media::VideoCaptureSessionId session_id_;
|
| @@ -135,141 +117,85 @@ class VideoCaptureImplTest : public ::testing::Test {
|
|
|
| TEST_F(VideoCaptureImplTest, Simple) {
|
| // Execute SetCapture() and StopCapture() for one client.
|
| - scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
|
| + scoped_ptr<MockVideoCaptureEventHandler> client(
|
| + new MockVideoCaptureEventHandler);
|
|
|
| - EXPECT_CALL(*client, OnStarted(_))
|
| - .WillOnce(Return());
|
| -
|
| - video_capture_impl_->StartCapture(client.get(), params_small_);
|
| - message_loop_->RunUntilIdle();
|
| -
|
| - EXPECT_CALL(*client, OnStopped(_))
|
| - .WillOnce(Return());
|
| + EXPECT_CALL(*client, OnStarted(_));
|
| + EXPECT_CALL(*client, OnStopped(_));
|
| EXPECT_CALL(*client, OnRemoved(_))
|
| - .WillOnce(Return());
|
| + .WillOnce(InvokeWithoutArgs(this, &VideoCaptureImplTest::Quit));
|
|
|
| + video_capture_impl_->StartCapture(client.get(), params_small_);
|
| video_capture_impl_->StopCapture(client.get());
|
| - message_loop_->RunUntilIdle();
|
| + run_loop_.Run();
|
| }
|
|
|
| TEST_F(VideoCaptureImplTest, TwoClientsInSequence) {
|
| // Execute SetCapture() and StopCapture() for 2 clients in sequence.
|
| - scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
|
| -
|
| - EXPECT_CALL(*client, OnStarted(_))
|
| - .WillOnce(Return());
|
| -
|
| - video_capture_impl_->StartCapture(client.get(), params_small_);
|
| - message_loop_->RunUntilIdle();
|
| -
|
| - EXPECT_CALL(*client, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client, OnRemoved(_))
|
| - .WillOnce(Return());
|
| -
|
| - video_capture_impl_->StopCapture(client.get());
|
| - message_loop_->RunUntilIdle();
|
| -
|
| - EXPECT_CALL(*client, OnStarted(_))
|
| - .WillOnce(Return());
|
| -
|
| - video_capture_impl_->StartCapture(client.get(), params_small_);
|
| - message_loop_->RunUntilIdle();
|
| -
|
| - EXPECT_CALL(*client, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client, OnRemoved(_))
|
| - .WillOnce(Return());
|
| + scoped_ptr<MockVideoCaptureEventHandler> client1(
|
| + new MockVideoCaptureEventHandler);
|
| + scoped_ptr<MockVideoCaptureEventHandler> client2(
|
| + new MockVideoCaptureEventHandler);
|
| +
|
| + EXPECT_CALL(*client1, OnStarted(_));
|
| + EXPECT_CALL(*client1, OnStopped(_));
|
| + EXPECT_CALL(*client1, OnRemoved(_));
|
| + EXPECT_CALL(*client2, OnStarted(_));
|
| + EXPECT_CALL(*client2, OnStopped(_));
|
| + EXPECT_CALL(*client2, OnRemoved(_))
|
| + .WillOnce(InvokeWithoutArgs(this, &VideoCaptureImplTest::Quit));
|
|
|
| - video_capture_impl_->StopCapture(client.get());
|
| - message_loop_->RunUntilIdle();
|
| + video_capture_impl_->StartCapture(client1.get(), params_small_);
|
| + video_capture_impl_->StopCapture(client1.get());
|
| + video_capture_impl_->StartCapture(client2.get(), params_small_);
|
| + video_capture_impl_->StopCapture(client2.get());
|
| + run_loop_.Run();
|
| }
|
|
|
| TEST_F(VideoCaptureImplTest, LargeAndSmall) {
|
| // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
|
| // The large client starts first and stops first.
|
| - scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
|
| - scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
|
| -
|
| - EXPECT_CALL(*client_large, OnStarted(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_small, OnStarted(_))
|
| - .WillOnce(Return());
|
| + scoped_ptr<MockVideoCaptureEventHandler> client_small(
|
| + new MockVideoCaptureEventHandler);
|
| + scoped_ptr<MockVideoCaptureEventHandler> client_large(
|
| + new MockVideoCaptureEventHandler);
|
| +
|
| + EXPECT_CALL(*client_large, OnStarted(_));
|
| + EXPECT_CALL(*client_small, OnStarted(_));
|
| + EXPECT_CALL(*client_large, OnStopped(_));
|
| + EXPECT_CALL(*client_large, OnRemoved(_));
|
| + EXPECT_CALL(*client_small, OnStopped(_));
|
| + EXPECT_CALL(*client_small, OnRemoved(_))
|
| + .WillOnce(InvokeWithoutArgs(this, &VideoCaptureImplTest::Quit));
|
|
|
| video_capture_impl_->StartCapture(client_large.get(), params_large_);
|
| video_capture_impl_->StartCapture(client_small.get(), params_small_);
|
| - message_loop_->RunUntilIdle();
|
| -
|
| - EXPECT_CALL(*client_large, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_large, OnRemoved(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_small, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_small, OnRemoved(_))
|
| - .WillOnce(Return());
|
| -
|
| video_capture_impl_->StopCapture(client_large.get());
|
| video_capture_impl_->StopCapture(client_small.get());
|
| - message_loop_->RunUntilIdle();
|
| + run_loop_.Run();
|
| }
|
|
|
| TEST_F(VideoCaptureImplTest, SmallAndLarge) {
|
| // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
|
| // The small client starts first and stops first.
|
| - scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
|
| - scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
|
| -
|
| - EXPECT_CALL(*client_large, OnStarted(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_small, OnStarted(_))
|
| - .WillOnce(Return());
|
| + scoped_ptr<MockVideoCaptureEventHandler> client_small(
|
| + new MockVideoCaptureEventHandler);
|
| + scoped_ptr<MockVideoCaptureEventHandler> client_large(
|
| + new MockVideoCaptureEventHandler);
|
| +
|
| + EXPECT_CALL(*client_small, OnStarted(_));
|
| + EXPECT_CALL(*client_large, OnStarted(_));
|
| + EXPECT_CALL(*client_small, OnStopped(_));
|
| + EXPECT_CALL(*client_small, OnRemoved(_));
|
| + EXPECT_CALL(*client_large, OnStopped(_));
|
| + EXPECT_CALL(*client_large, OnRemoved(_))
|
| + .WillOnce(InvokeWithoutArgs(this, &VideoCaptureImplTest::Quit));
|
|
|
| video_capture_impl_->StartCapture(client_small.get(), params_small_);
|
| video_capture_impl_->StartCapture(client_large.get(), params_large_);
|
| - message_loop_->RunUntilIdle();
|
| -
|
| - EXPECT_CALL(*client_large, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_large, OnRemoved(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_small, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client_small, OnRemoved(_))
|
| - .WillOnce(Return());
|
| -
|
| video_capture_impl_->StopCapture(client_small.get());
|
| video_capture_impl_->StopCapture(client_large.get());
|
| - message_loop_->RunUntilIdle();
|
| -}
|
| -
|
| -TEST_F(VideoCaptureImplTest, TwoClientsWithSameSize) {
|
| - // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
|
| - // The client1 starts first and stops first.
|
| - scoped_ptr<MockVideoCaptureClient> client1(new MockVideoCaptureClient);
|
| - scoped_ptr<MockVideoCaptureClient> client2(new MockVideoCaptureClient);
|
| -
|
| - EXPECT_CALL(*client1, OnStarted(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client2, OnStarted(_))
|
| - .WillOnce(Return());
|
| -
|
| - video_capture_impl_->StartCapture(client1.get(), params_small_);
|
| - video_capture_impl_->StartCapture(client2.get(), params_small_);
|
| - message_loop_->RunUntilIdle();
|
| -
|
| - EXPECT_CALL(*client1, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client1, OnRemoved(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client2, OnStopped(_))
|
| - .WillOnce(Return());
|
| - EXPECT_CALL(*client2, OnRemoved(_))
|
| - .WillOnce(Return());
|
| -
|
| - video_capture_impl_->StopCapture(client1.get());
|
| - video_capture_impl_->StopCapture(client2.get());
|
| - message_loop_->RunUntilIdle();
|
| + run_loop_.Run();
|
| }
|
|
|
| } // namespace content
|
|
|