Chromium Code Reviews| Index: content/browser/renderer_host/media/service_video_capture_device_launcher_unittest.cc |
| diff --git a/content/browser/renderer_host/media/service_video_capture_device_launcher_unittest.cc b/content/browser/renderer_host/media/service_video_capture_device_launcher_unittest.cc |
| index 65dd139b45bcaa94f96e8702c204f89f4ea98a1b..142ad70411d71c0053c468275cef8bfc88ff6472 100644 |
| --- a/content/browser/renderer_host/media/service_video_capture_device_launcher_unittest.cc |
| +++ b/content/browser/renderer_host/media/service_video_capture_device_launcher_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/test/mock_callback.h" |
| #include "base/test/scoped_task_environment.h" |
| #include "base/threading/thread.h" |
| +#include "content/browser/renderer_host/media/service_launched_video_capture_device.h" |
| #include "mojo/public/cpp/bindings/binding.h" |
| #include "services/video_capture/public/interfaces/device_factory.mojom.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -78,6 +79,7 @@ class ServiceVideoCaptureDeviceLauncherTest : public testing::Test { |
| std::unique_ptr<mojo::Binding<video_capture::mojom::DeviceFactory>> |
| factory_binding_; |
| std::unique_ptr<ServiceVideoCaptureDeviceLauncher> launcher_; |
| + base::MockCallback<base::OnceClosure> connection_lost_cb; |
|
emircan
2017/06/01 18:13:29
s/connection_lost_cb/connection_lost_cb_
chfremer
2017/06/01 19:25:56
Done.
|
| base::MockCallback<base::OnceClosure> done_cb; |
|
emircan
2017/06/01 18:13:29
s/done_cb/done_cb_
chfremer
2017/06/01 19:25:56
Done.
|
| private: |
| @@ -109,6 +111,7 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, LaunchingDeviceSucceeds) { |
| EXPECT_CALL(mock_callbacks_, DoOnDeviceLaunched(_)).Times(1); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchAborted()).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchFailed()).Times(0); |
| + EXPECT_CALL(connection_lost_cb, Run()).Times(0); |
| EXPECT_CALL(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() { |
| run_loop.Quit(); |
| })); |
| @@ -116,7 +119,7 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, LaunchingDeviceSucceeds) { |
| // Exercise |
| launcher_->LaunchDeviceAsync( |
| kStubDeviceId, content::MEDIA_DEVICE_VIDEO_CAPTURE, kArbitraryParams, |
| - kNullReceiver, &mock_callbacks_, done_cb.Get()); |
| + kNullReceiver, connection_lost_cb.Get(), &mock_callbacks_, done_cb.Get()); |
| run_loop.Run(); |
| } |
| @@ -165,6 +168,7 @@ void ServiceVideoCaptureDeviceLauncherTest::RunLaunchingDeviceIsAbortedTest( |
| EXPECT_CALL(mock_callbacks_, DoOnDeviceLaunched(_)).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchAborted()).Times(1); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchFailed()).Times(0); |
| + EXPECT_CALL(connection_lost_cb, Run()).Times(0); |
| EXPECT_CALL(done_cb, Run()).WillOnce(InvokeWithoutArgs([&step_2_run_loop]() { |
| step_2_run_loop.Quit(); |
| })); |
| @@ -172,7 +176,7 @@ void ServiceVideoCaptureDeviceLauncherTest::RunLaunchingDeviceIsAbortedTest( |
| // Exercise |
| launcher_->LaunchDeviceAsync( |
| kStubDeviceId, content::MEDIA_DEVICE_VIDEO_CAPTURE, kArbitraryParams, |
| - kNullReceiver, &mock_callbacks_, done_cb.Get()); |
| + kNullReceiver, connection_lost_cb.Get(), &mock_callbacks_, done_cb.Get()); |
| step_1_run_loop.Run(); |
| launcher_->AbortLaunch(); |
| @@ -208,6 +212,7 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| EXPECT_CALL(mock_callbacks_, DoOnDeviceLaunched(_)).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchAborted()).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchFailed()).Times(1); |
| + EXPECT_CALL(connection_lost_cb, Run()).Times(0); |
| EXPECT_CALL(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() { |
| run_loop.Quit(); |
| })); |
| @@ -215,7 +220,7 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| // Exercise |
| launcher_->LaunchDeviceAsync( |
| kStubDeviceId, content::MEDIA_DEVICE_VIDEO_CAPTURE, kArbitraryParams, |
| - kNullReceiver, &mock_callbacks_, done_cb.Get()); |
| + kNullReceiver, connection_lost_cb.Get(), &mock_callbacks_, done_cb.Get()); |
| run_loop.Run(); |
| } |
| @@ -227,6 +232,7 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| EXPECT_CALL(mock_callbacks_, DoOnDeviceLaunched(_)).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchAborted()).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchFailed()).Times(1); |
| + EXPECT_CALL(connection_lost_cb, Run()).Times(0); |
| EXPECT_CALL(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() { |
| run_loop.Quit(); |
| })); |
| @@ -235,7 +241,7 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| device_factory_.reset(); |
| launcher_->LaunchDeviceAsync( |
| kStubDeviceId, content::MEDIA_DEVICE_VIDEO_CAPTURE, kArbitraryParams, |
| - kNullReceiver, &mock_callbacks_, done_cb.Get()); |
| + kNullReceiver, connection_lost_cb.Get(), &mock_callbacks_, done_cb.Get()); |
| run_loop.Run(); |
| } |
| @@ -260,6 +266,9 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| EXPECT_CALL(mock_callbacks_, DoOnDeviceLaunched(_)).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchAborted()).Times(0); |
| EXPECT_CALL(mock_callbacks_, OnDeviceLaunchFailed()).Times(1); |
| + // Note: |connection_lost_cb| is only meant to be called when the connection |
| + // to a successfully-launched device is lost, which is not the case here. |
| + EXPECT_CALL(connection_lost_cb, Run()).Times(0); |
| EXPECT_CALL(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() { |
| run_loop.Quit(); |
| })); |
| @@ -267,7 +276,7 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| // Exercise |
| launcher_->LaunchDeviceAsync( |
| kStubDeviceId, content::MEDIA_DEVICE_VIDEO_CAPTURE, kArbitraryParams, |
| - kNullReceiver, &mock_callbacks_, done_cb.Get()); |
| + kNullReceiver, connection_lost_cb.Get(), &mock_callbacks_, done_cb.Get()); |
| run_loop.Run(); |
| @@ -280,4 +289,53 @@ TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| create_device_cb.Run(arbitrary_result_code); |
| } |
| +TEST_F(ServiceVideoCaptureDeviceLauncherTest, |
| + ConnectionLostAfterSuccessfulLaunch) { |
| + video_capture::mojom::DeviceRequest device_request_owned_by_service; |
| + EXPECT_CALL(mock_device_factory_, DoCreateDevice(kStubDeviceId, _, _)) |
| + .WillOnce(Invoke([&device_request_owned_by_service]( |
| + const std::string& device_id, |
| + video_capture::mojom::DeviceRequest* device_request, |
| + const video_capture::mojom::DeviceFactory:: |
| + CreateDeviceCallback& callback) { |
| + // The service holds on to the |device_request|. |
| + device_request_owned_by_service = std::move(*device_request); |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, |
| + base::Bind( |
| + [](const video_capture::mojom::DeviceFactory:: |
| + CreateDeviceCallback& callback) { |
| + callback.Run( |
| + video_capture::mojom::DeviceAccessResultCode::SUCCESS); |
| + }, |
| + callback)); |
| + })); |
| + std::unique_ptr<LaunchedVideoCaptureDevice> launched_device; |
| + EXPECT_CALL(mock_callbacks_, DoOnDeviceLaunched(_)) |
| + .WillOnce( |
| + Invoke([&launched_device]( |
| + std::unique_ptr<LaunchedVideoCaptureDevice>* device) { |
| + // We must keep the launched device alive, because otherwise it will |
| + // no longer listen for connection errors. |
| + launched_device = std::move(*device); |
| + })); |
| + base::RunLoop step_1_run_loop; |
| + EXPECT_CALL(done_cb, Run()).WillOnce(InvokeWithoutArgs([&step_1_run_loop]() { |
| + step_1_run_loop.Quit(); |
| + })); |
| + // Exercise step 1 |
| + launcher_->LaunchDeviceAsync( |
| + kStubDeviceId, content::MEDIA_DEVICE_VIDEO_CAPTURE, kArbitraryParams, |
| + kNullReceiver, connection_lost_cb.Get(), &mock_callbacks_, done_cb.Get()); |
| + step_1_run_loop.Run(); |
| + |
| + base::RunLoop step_2_run_loop; |
| + EXPECT_CALL(connection_lost_cb, Run()).WillOnce(Invoke([&step_2_run_loop]() { |
| + step_2_run_loop.Quit(); |
| + })); |
| + // Exercise step 2: The service cuts/loses the connection |
| + device_request_owned_by_service = nullptr; |
| + step_2_run_loop.Run(); |
| +} |
| + |
| } // namespace content |