| Index: trunk/src/content/renderer/media/video_capture_impl_unittest.cc
|
| ===================================================================
|
| --- trunk/src/content/renderer/media/video_capture_impl_unittest.cc (revision 244357)
|
| +++ trunk/src/content/renderer/media/video_capture_impl_unittest.cc (working copy)
|
| @@ -3,18 +3,15 @@
|
| // 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::InvokeWithoutArgs;
|
| -using media::MockVideoCaptureEventHandler;
|
| +using ::testing::Return;
|
|
|
| namespace content {
|
|
|
| @@ -32,13 +29,36 @@
|
| 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, filter) {}
|
| + : VideoCaptureImpl(id, ml_proxy.get(), filter) {}
|
| virtual ~MockVideoCaptureImpl() {}
|
|
|
| // Override Send() to mimic device to send events.
|
| @@ -82,13 +102,15 @@
|
| 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_filter_.get());
|
| + session_id_, message_loop_proxy_, message_filter_.get());
|
|
|
| video_capture_impl_->device_id_ = 2;
|
| }
|
| @@ -97,13 +119,9 @@
|
| delete video_capture_impl_;
|
| }
|
|
|
| - void Quit() {
|
| - message_loop_.PostTask(FROM_HERE, run_loop_.QuitClosure());
|
| - }
|
| -
|
| protected:
|
| - base::MessageLoop message_loop_;
|
| - base::RunLoop run_loop_;
|
| + scoped_ptr<base::MessageLoop> message_loop_;
|
| + scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
|
| scoped_ptr<ChildProcess> child_process_;
|
| scoped_refptr<MockVideoCaptureMessageFilter> message_filter_;
|
| media::VideoCaptureSessionId session_id_;
|
| @@ -117,85 +135,141 @@
|
|
|
| TEST_F(VideoCaptureImplTest, Simple) {
|
| // Execute SetCapture() and StopCapture() for one client.
|
| - scoped_ptr<MockVideoCaptureEventHandler> client(
|
| - new MockVideoCaptureEventHandler);
|
| + scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
|
|
|
| - EXPECT_CALL(*client, OnStarted(_));
|
| - EXPECT_CALL(*client, OnStopped(_));
|
| + 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(InvokeWithoutArgs(this, &VideoCaptureImplTest::Quit));
|
| + .WillOnce(Return());
|
|
|
| - video_capture_impl_->StartCapture(client.get(), params_small_);
|
| video_capture_impl_->StopCapture(client.get());
|
| - run_loop_.Run();
|
| + message_loop_->RunUntilIdle();
|
| }
|
|
|
| TEST_F(VideoCaptureImplTest, TwoClientsInSequence) {
|
| // Execute SetCapture() and StopCapture() for 2 clients in sequence.
|
| - scoped_ptr<MockVideoCaptureEventHandler> client1(
|
| - new MockVideoCaptureEventHandler);
|
| - scoped_ptr<MockVideoCaptureEventHandler> client2(
|
| - new MockVideoCaptureEventHandler);
|
| + scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
|
|
|
| - 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));
|
| + EXPECT_CALL(*client, OnStarted(_))
|
| + .WillOnce(Return());
|
|
|
| - 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();
|
| + 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());
|
| +
|
| + video_capture_impl_->StopCapture(client.get());
|
| + message_loop_->RunUntilIdle();
|
| }
|
|
|
| TEST_F(VideoCaptureImplTest, LargeAndSmall) {
|
| // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
|
| // The large client starts first and stops first.
|
| - scoped_ptr<MockVideoCaptureEventHandler> client_small(
|
| - new MockVideoCaptureEventHandler);
|
| - scoped_ptr<MockVideoCaptureEventHandler> client_large(
|
| - new MockVideoCaptureEventHandler);
|
| + scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
|
| + scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
|
|
|
| - 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));
|
| + EXPECT_CALL(*client_large, OnStarted(_))
|
| + .WillOnce(Return());
|
| + EXPECT_CALL(*client_small, OnStarted(_))
|
| + .WillOnce(Return());
|
|
|
| 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());
|
| - run_loop_.Run();
|
| + message_loop_->RunUntilIdle();
|
| }
|
|
|
| TEST_F(VideoCaptureImplTest, SmallAndLarge) {
|
| // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
|
| // The small client starts first and stops first.
|
| - scoped_ptr<MockVideoCaptureEventHandler> client_small(
|
| - new MockVideoCaptureEventHandler);
|
| - scoped_ptr<MockVideoCaptureEventHandler> client_large(
|
| - new MockVideoCaptureEventHandler);
|
| + scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
|
| + scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
|
|
|
| - 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));
|
| + EXPECT_CALL(*client_large, OnStarted(_))
|
| + .WillOnce(Return());
|
| + EXPECT_CALL(*client_small, OnStarted(_))
|
| + .WillOnce(Return());
|
|
|
| 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());
|
| - run_loop_.Run();
|
| + 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();
|
| +}
|
| +
|
| } // namespace content
|
|
|