| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "services/video_capture/test/mock_device_test.h" | 6 #include "services/video_capture/test/mock_device_test.h" |
| 7 | 7 |
| 8 using testing::_; | 8 using testing::_; |
| 9 using testing::Invoke; | 9 using testing::Invoke; |
| 10 | 10 |
| 11 namespace video_capture { | 11 namespace video_capture { |
| 12 | 12 |
| 13 // This alias ensures test output is easily attributed to this service's tests. | 13 // This alias ensures test output is easily attributed to this service's tests. |
| 14 // TODO(rockot/chfremer): Consider just renaming the type. | 14 // TODO(rockot/chfremer): Consider just renaming the type. |
| 15 using MockVideoCaptureDeviceTest = MockDeviceTest; | 15 using MockVideoCaptureDeviceTest = MockDeviceTest; |
| 16 | 16 |
| 17 // Tests that the service stops the capture device when the client closes the | 17 // Tests that the service stops the capture device when the client closes the |
| 18 // connection to the device proxy. | 18 // connection to the device proxy. |
| 19 TEST_F(MockVideoCaptureDeviceTest, | 19 TEST_F(MockVideoCaptureDeviceTest, DeviceIsStoppedWhenDiscardingDeviceProxy) { |
| 20 DISABLED_DeviceIsStoppedWhenDiscardingDeviceProxy) { | |
| 21 base::RunLoop wait_loop; | 20 base::RunLoop wait_loop; |
| 22 | 21 |
| 23 // The mock device must hold on to the device client that is passed to it. | 22 EXPECT_CALL(mock_device_, DoStopAndDeAllocate()) |
| 24 std::unique_ptr<media::VideoCaptureDevice::Client> device_client; | |
| 25 EXPECT_CALL(mock_device_, DoAllocateAndStart(_, _)) | |
| 26 .WillOnce(Invoke([&device_client]( | |
| 27 const media::VideoCaptureParams& params, | |
| 28 std::unique_ptr<media::VideoCaptureDevice::Client>* client) { | |
| 29 device_client.reset(client->release()); | |
| 30 })); | |
| 31 EXPECT_CALL(mock_device_, StopAndDeAllocate()) | |
| 32 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); })); | 23 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); })); |
| 33 | 24 |
| 34 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_)); | 25 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_)); |
| 35 device_proxy_.reset(); | 26 device_proxy_.reset(); |
| 36 | 27 |
| 37 wait_loop.Run(); | 28 wait_loop.Run(); |
| 38 } | 29 } |
| 39 | 30 |
| 40 // Tests that the service stops the capture device when the client closes the | 31 // Tests that the service stops the capture device when the client closes the |
| 41 // connection to the client proxy it provided to the service. | 32 // connection to the client proxy it provided to the service. |
| 42 TEST_F(MockVideoCaptureDeviceTest, | 33 TEST_F(MockVideoCaptureDeviceTest, DeviceIsStoppedWhenDiscardingDeviceClient) { |
| 43 DISABLED_DeviceIsStoppedWhenDiscardingDeviceClient) { | |
| 44 base::RunLoop wait_loop; | 34 base::RunLoop wait_loop; |
| 45 | 35 |
| 46 // The mock device must hold on to the device client that is passed to it. | 36 EXPECT_CALL(mock_device_, DoStopAndDeAllocate()) |
| 47 std::unique_ptr<media::VideoCaptureDevice::Client> device_client; | |
| 48 EXPECT_CALL(mock_device_, DoAllocateAndStart(_, _)) | |
| 49 .WillOnce(Invoke([&device_client]( | |
| 50 const media::VideoCaptureParams& params, | |
| 51 std::unique_ptr<media::VideoCaptureDevice::Client>* client) { | |
| 52 device_client.reset(client->release()); | |
| 53 })); | |
| 54 EXPECT_CALL(mock_device_, StopAndDeAllocate()) | |
| 55 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); })); | 37 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); })); |
| 56 | 38 |
| 57 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_)); | 39 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_)); |
| 58 mock_receiver_.reset(); | 40 mock_receiver_.reset(); |
| 59 | 41 |
| 60 wait_loop.Run(); | 42 wait_loop.Run(); |
| 61 } | 43 } |
| 62 | 44 |
| 45 // Tests that a utilization reported to a video_capture.mojom.Device via |
| 46 // OnReceiverReportingUtilization() arrives at the corresponding |
| 47 // media::VideoCaptureDevice. |
| 48 TEST_F(MockVideoCaptureDeviceTest, ReceiverUtilizationIsForwardedToDevice) { |
| 49 base::RunLoop run_loop; |
| 50 const media::VideoCaptureFormat stub_frame_format(gfx::Size(320, 200), 25.0f, |
| 51 media::PIXEL_FORMAT_I420); |
| 52 const int arbitrary_rotation = 0; |
| 53 const int arbitrary_frame_feedback_id = 654; |
| 54 const double arbitrary_utilization = 0.12345; |
| 55 |
| 56 EXPECT_CALL(*mock_receiver_, DoOnFrameReadyInBuffer(_, _, _, _)) |
| 57 .WillOnce(Invoke([this, &arbitrary_utilization]( |
| 58 int32_t buffer_id, int32_t frame_feedback_id, |
| 59 mojom::ScopedAccessPermissionPtr*, |
| 60 media::mojom::VideoFrameInfoPtr*) { |
| 61 device_proxy_->OnReceiverReportingUtilization(frame_feedback_id, |
| 62 arbitrary_utilization); |
| 63 })); |
| 64 |
| 65 EXPECT_CALL(mock_device_, OnUtilizationReport(arbitrary_frame_feedback_id, |
| 66 arbitrary_utilization)) |
| 67 .Times(1); |
| 68 |
| 69 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_)); |
| 70 run_loop.RunUntilIdle(); |
| 71 |
| 72 // Simulate device sending a frame, which should trigger |mock_receiver| |
| 73 // DoOnFrameReadyInBuffer() getting called. |
| 74 base::RunLoop run_loop_2; |
| 75 mock_device_.SendStubFrame(stub_frame_format, arbitrary_rotation, |
| 76 arbitrary_frame_feedback_id); |
| 77 run_loop_2.RunUntilIdle(); |
| 78 |
| 79 base::RunLoop run_loop_3; |
| 80 mock_receiver_.reset(); |
| 81 run_loop_3.RunUntilIdle(); |
| 82 } |
| 83 |
| 63 } // namespace video_capture | 84 } // namespace video_capture |
| OLD | NEW |