| 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..866eb75dc9aac0d426c2e8ac8117800aaebfda7c 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,7 +79,8 @@ 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> done_cb;
|
| + base::MockCallback<base::OnceClosure> connection_lost_cb_;
|
| + base::MockCallback<base::OnceClosure> done_cb_;
|
|
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(ServiceVideoCaptureDeviceLauncherTest);
|
| @@ -109,14 +111,16 @@ 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(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() {
|
| + EXPECT_CALL(connection_lost_cb_, Run()).Times(0);
|
| + EXPECT_CALL(done_cb_, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() {
|
| run_loop.Quit();
|
| }));
|
|
|
| // 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,14 +169,16 @@ 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(done_cb, Run()).WillOnce(InvokeWithoutArgs([&step_2_run_loop]() {
|
| + EXPECT_CALL(connection_lost_cb_, Run()).Times(0);
|
| + EXPECT_CALL(done_cb_, Run()).WillOnce(InvokeWithoutArgs([&step_2_run_loop]() {
|
| step_2_run_loop.Quit();
|
| }));
|
|
|
| // 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,14 +214,16 @@ 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(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() {
|
| + EXPECT_CALL(connection_lost_cb_, Run()).Times(0);
|
| + EXPECT_CALL(done_cb_, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() {
|
| run_loop.Quit();
|
| }));
|
|
|
| // 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,7 +235,8 @@ 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(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() {
|
| + EXPECT_CALL(connection_lost_cb_, Run()).Times(0);
|
| + EXPECT_CALL(done_cb_, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() {
|
| run_loop.Quit();
|
| }));
|
|
|
| @@ -235,7 +244,8 @@ 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,14 +270,18 @@ 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(done_cb, Run()).WillOnce(InvokeWithoutArgs([&run_loop]() {
|
| + // 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();
|
| }));
|
|
|
| // 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 +294,54 @@ 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
|
|
|