| Index: content/browser/renderer_host/media/video_capture_host_unittest.cc
|
| diff --git a/content/browser/renderer_host/media/video_capture_host_unittest.cc b/content/browser/renderer_host/media/video_capture_host_unittest.cc
|
| index 873135540f01c5bfd0fd9506f21e569399bf2ca6..7dfeed85379ff374bca3c09a826db0cbfa1c8c60 100644
|
| --- a/content/browser/renderer_host/media/video_capture_host_unittest.cc
|
| +++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc
|
| @@ -84,33 +84,6 @@ class MockMediaStreamRequester : public MediaStreamRequester {
|
| DISALLOW_COPY_AND_ASSIGN(MockMediaStreamRequester);
|
| };
|
|
|
| -class MockVideoCaptureHost : public VideoCaptureHost {
|
| - public:
|
| - MockVideoCaptureHost(MediaStreamManager* manager)
|
| - : VideoCaptureHost(manager) {}
|
| -
|
| - MOCK_METHOD4(OnNewBufferCreated,
|
| - void(int device_id,
|
| - base::SharedMemoryHandle handle,
|
| - int length,
|
| - int buffer_id));
|
| -
|
| - private:
|
| - ~MockVideoCaptureHost() override {}
|
| -
|
| - bool Send(IPC::Message* message) override {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureHost, *message)
|
| - IPC_MESSAGE_HANDLER(VideoCaptureMsg_NewBuffer, OnNewBufferCreated)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - EXPECT_TRUE(handled);
|
| -
|
| - delete message;
|
| - return true;
|
| - }
|
| -};
|
| -
|
| ACTION_P2(ExitMessageLoop, task_runner, quit_closure) {
|
| task_runner->PostTask(FROM_HERE, quit_closure);
|
| }
|
| @@ -139,7 +112,7 @@ class VideoCaptureHostTest : public testing::Test,
|
| media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
|
|
|
| // Create a Host and connect it to a simulated IPC channel.
|
| - host_ = new MockVideoCaptureHost(media_stream_manager_.get());
|
| + host_ = new VideoCaptureHost(media_stream_manager_.get());
|
| host_->OnChannelConnected(base::GetCurrentProcId());
|
|
|
| OpenSession();
|
| @@ -228,6 +201,11 @@ class VideoCaptureHostTest : public testing::Test,
|
| protected:
|
| // mojom::VideoCaptureObserver implementation.
|
| MOCK_METHOD1(OnStateChanged, void(mojom::VideoCaptureState));
|
| + void OnBufferCreated(int32_t buffer_id,
|
| + mojo::ScopedSharedBufferHandle handle) override {
|
| + DoOnBufferCreated(buffer_id);
|
| + }
|
| + MOCK_METHOD1(DoOnBufferCreated, void(int32_t));
|
| void OnBufferReady(int32_t buffer_id,
|
| mojom::VideoFrameInfoPtr info) override {
|
| DoOnBufferReady(buffer_id);
|
| @@ -242,12 +220,12 @@ class VideoCaptureHostTest : public testing::Test,
|
| gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420);
|
|
|
| EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::STARTED));
|
| - EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _))
|
| + EXPECT_CALL(*this, DoOnBufferCreated(_))
|
| .Times(AnyNumber())
|
| .WillRepeatedly(Return());
|
| EXPECT_CALL(*this, DoOnBufferReady(_))
|
| .Times(AnyNumber())
|
| - .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure()));
|
| + .WillRepeatedly(ExitMessageLoop(task_runner_, run_loop.QuitClosure()));
|
|
|
| host_->Start(kDeviceId, opened_session_id_, params,
|
| observer_binding_.CreateInterfacePtrAndBind());
|
| @@ -255,7 +233,7 @@ class VideoCaptureHostTest : public testing::Test,
|
| run_loop.Run();
|
| }
|
|
|
| - void StartStopCapture() {
|
| + void StartAndImmediateStopCapture() {
|
| // Quickly start and then stop capture, without giving much chance for
|
| // asynchronous capture operations to produce frames.
|
| InSequence s;
|
| @@ -272,7 +250,6 @@ class VideoCaptureHostTest : public testing::Test,
|
| EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::STOPPED));
|
| host_->Stop(kDeviceId);
|
| run_loop.RunUntilIdle();
|
| - WaitForVideoDeviceThread();
|
| }
|
|
|
| void PauseResumeCapture() {
|
| @@ -289,7 +266,6 @@ class VideoCaptureHostTest : public testing::Test,
|
| EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::RESUMED));
|
| host_->Resume(kDeviceId, opened_session_id_, params);
|
| run_loop.RunUntilIdle();
|
| - WaitForVideoDeviceThread();
|
| }
|
|
|
| void StopCapture() {
|
| @@ -321,18 +297,6 @@ class VideoCaptureHostTest : public testing::Test,
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| - void WaitForVideoDeviceThread() {
|
| - base::RunLoop run_loop;
|
| - media_stream_manager_->video_capture_manager()->device_task_runner()
|
| - ->PostTaskAndReply(
|
| - FROM_HERE,
|
| - base::Bind(&base::DoNothing),
|
| - run_loop.QuitClosure());
|
| - run_loop.Run();
|
| - }
|
| -
|
| - scoped_refptr<MockVideoCaptureHost> host_;
|
| -
|
| private:
|
| // |media_stream_manager_| needs to outlive |thread_bundle_| because it is a
|
| // MessageLoop::DestructionObserver.
|
| @@ -348,39 +312,33 @@ class VideoCaptureHostTest : public testing::Test,
|
| int opened_session_id_;
|
| std::string opened_device_label_;
|
|
|
| + scoped_refptr<VideoCaptureHost> host_;
|
| mojo::Binding<mojom::VideoCaptureObserver> observer_binding_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest);
|
| };
|
|
|
| -TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) {
|
| - StartCapture();
|
| +// Construct and destruct all objects. This is a non trivial sequence.
|
| +TEST_F(VideoCaptureHostTest, ConstructAndDestruct) {}
|
|
|
| - // When the session is closed via the stream without stopping capture, the
|
| - // ENDED event is sent.
|
| - EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::ENDED));
|
| - CloseSession();
|
| - base::RunLoop().RunUntilIdle();
|
| +TEST_F(VideoCaptureHostTest, StartAndImmediateStop) {
|
| + StartAndImmediateStopCapture();
|
| }
|
|
|
| -TEST_F(VideoCaptureHostTest, StopWhileStartPending) {
|
| - StartStopCapture();
|
| -}
|
| -
|
| -TEST_F(VideoCaptureHostTest, StartCapturePlayStop) {
|
| +TEST_F(VideoCaptureHostTest, StartAndCaptureAndStop) {
|
| StartCapture();
|
| WaitForOneCapturedBuffer();
|
| WaitForOneCapturedBuffer();
|
| StopCapture();
|
| }
|
|
|
| -TEST_F(VideoCaptureHostTest, StartCaptureErrorStop) {
|
| +TEST_F(VideoCaptureHostTest, StartAndErrorAndStop) {
|
| StartCapture();
|
| SimulateError();
|
| StopCapture();
|
| }
|
|
|
| -TEST_F(VideoCaptureHostTest, StartCaptureError) {
|
| +TEST_F(VideoCaptureHostTest, StartAndCaptureAndError) {
|
| EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::STOPPED))
|
| .Times(0);
|
| StartCapture();
|
| @@ -389,10 +347,20 @@ TEST_F(VideoCaptureHostTest, StartCaptureError) {
|
| base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200));
|
| }
|
|
|
| -TEST_F(VideoCaptureHostTest, PauseResumeCapture) {
|
| +TEST_F(VideoCaptureHostTest, StartAndPauseAndResumeAndStop) {
|
| StartCapture();
|
| PauseResumeCapture();
|
| StopCapture();
|
| }
|
|
|
| +TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) {
|
| + StartCapture();
|
| +
|
| + // When the session is closed via the stream without stopping capture, the
|
| + // ENDED event is sent.
|
| + EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::ENDED));
|
| + CloseSession();
|
| + base::RunLoop().RunUntilIdle();
|
| +}
|
| +
|
| } // namespace content
|
|
|