| Index: content/browser/renderer_host/media/video_capture_manager_unittest.cc
|
| diff --git a/content/browser/renderer_host/media/video_capture_manager_unittest.cc b/content/browser/renderer_host/media/video_capture_manager_unittest.cc
|
| index c2cc9c700711e08b7782fa6940280dc10261d7bc..82c3e71c179d0fe5973cc982696f2c325e9406c7 100644
|
| --- a/content/browser/renderer_host/media/video_capture_manager_unittest.cc
|
| +++ b/content/browser/renderer_host/media/video_capture_manager_unittest.cc
|
| @@ -41,8 +41,6 @@ class MockMediaStreamProviderListener : public MediaStreamProviderListener {
|
|
|
| MOCK_METHOD2(Opened, void(MediaStreamType, int));
|
| MOCK_METHOD2(Closed, void(MediaStreamType, int));
|
| - MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType,
|
| - const StreamDeviceInfoArray&));
|
| MOCK_METHOD2(Aborted, void(MediaStreamType, int));
|
| }; // class MockMediaStreamProviderListener
|
|
|
| @@ -73,6 +71,18 @@ class VideoCaptureManagerTest : public testing::Test {
|
| VideoCaptureManagerTest() : next_client_id_(1) {}
|
| ~VideoCaptureManagerTest() override {}
|
|
|
| + void HandleEnumerationResult(
|
| + const base::Closure& quit_closure,
|
| + const media::VideoCaptureDeviceDescriptors& descriptors) {
|
| + StreamDeviceInfoArray devices;
|
| + for (const auto& descriptor : descriptors) {
|
| + devices.emplace_back(MEDIA_DEVICE_VIDEO_CAPTURE,
|
| + descriptor.GetNameAndModel(), descriptor.device_id);
|
| + }
|
| + devices_ = std::move(devices);
|
| + quit_closure.Run();
|
| + }
|
| +
|
| protected:
|
| void SetUp() override {
|
| listener_.reset(new MockMediaStreamProviderListener());
|
| @@ -91,6 +101,13 @@ class VideoCaptureManagerTest : public testing::Test {
|
| video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices);
|
| vcm_->Register(listener_.get(), message_loop_->task_runner().get());
|
| frame_observer_.reset(new MockFrameObserver());
|
| +
|
| + base::RunLoop run_loop;
|
| + vcm_->EnumerateDevices(
|
| + base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult,
|
| + base::Unretained(this), run_loop.QuitClosure()));
|
| + run_loop.Run();
|
| + ASSERT_GE(devices_.size(), 2u);
|
| }
|
|
|
| void TearDown() override {}
|
| @@ -174,6 +191,7 @@ class VideoCaptureManagerTest : public testing::Test {
|
| std::unique_ptr<BrowserThreadImpl> io_thread_;
|
| std::unique_ptr<MockFrameObserver> frame_observer_;
|
| media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_;
|
| + StreamDeviceInfoArray devices_;
|
|
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest);
|
| @@ -183,20 +201,11 @@ class VideoCaptureManagerTest : public testing::Test {
|
|
|
| // Try to open, start, stop and close a device.
|
| TEST_F(VideoCaptureManagerTest, CreateAndClose) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| - int video_session_id = vcm_->Open(devices.front());
|
| + int video_session_id = vcm_->Open(devices_.front());
|
| VideoCaptureControllerID client_id = StartClient(video_session_id, true);
|
|
|
| StopClient(client_id);
|
| @@ -208,21 +217,11 @@ TEST_F(VideoCaptureManagerTest, CreateAndClose) {
|
| }
|
|
|
| TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| -
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| for (int i = 1 ; i < 3 ; ++i) {
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i));
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i));
|
| - int video_session_id = vcm_->Open(devices.front());
|
| + int video_session_id = vcm_->Open(devices_.front());
|
| VideoCaptureControllerID client_id = StartClient(video_session_id, true);
|
|
|
| StopClient(client_id);
|
| @@ -236,20 +235,11 @@ TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) {
|
|
|
| // Try to open, start, and abort a device.
|
| TEST_F(VideoCaptureManagerTest, CreateAndAbort) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| - int video_session_id = vcm_->Open(devices.front());
|
| + int video_session_id = vcm_->Open(devices_.front());
|
| VideoCaptureControllerID client_id = StartClient(video_session_id, true);
|
|
|
| // Wait for device opened.
|
| @@ -265,24 +255,15 @@ TEST_F(VideoCaptureManagerTest, CreateAndAbort) {
|
|
|
| // Open the same device twice.
|
| TEST_F(VideoCaptureManagerTest, OpenTwice) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| - int video_session_id_first = vcm_->Open(devices.front());
|
| + int video_session_id_first = vcm_->Open(devices_.front());
|
|
|
| // This should trigger an error callback with error code
|
| // 'kDeviceAlreadyInUse'.
|
| - int video_session_id_second = vcm_->Open(devices.front());
|
| + int video_session_id_second = vcm_->Open(devices_.front());
|
| EXPECT_NE(video_session_id_first, video_session_id_second);
|
|
|
| vcm_->Close(video_session_id_first);
|
| @@ -295,32 +276,26 @@ TEST_F(VideoCaptureManagerTest, OpenTwice) {
|
|
|
| // Connect and disconnect devices.
|
| TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) {
|
| - StreamDeviceInfoArray devices;
|
| int number_of_devices_keep =
|
| video_capture_device_factory_->number_of_devices();
|
|
|
| - InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| - base::RunLoop().RunUntilIdle();
|
| - ASSERT_EQ(devices.size(), 2u);
|
| -
|
| // Simulate we remove 1 fake device.
|
| video_capture_device_factory_->set_number_of_devices(1);
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| - base::RunLoop().RunUntilIdle();
|
| - ASSERT_EQ(devices.size(), 1u);
|
| + base::RunLoop run_loop;
|
| + vcm_->EnumerateDevices(
|
| + base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult,
|
| + base::Unretained(this), run_loop.QuitClosure()));
|
| + run_loop.Run();
|
| + ASSERT_EQ(devices_.size(), 1u);
|
|
|
| // Simulate we add 2 fake devices.
|
| video_capture_device_factory_->set_number_of_devices(3);
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| - base::RunLoop().RunUntilIdle();
|
| - ASSERT_EQ(devices.size(), 3u);
|
| + base::RunLoop run_loop2;
|
| + vcm_->EnumerateDevices(
|
| + base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult,
|
| + base::Unretained(this), run_loop2.QuitClosure()));
|
| + run_loop2.Run();
|
| + ASSERT_EQ(devices_.size(), 3u);
|
|
|
| vcm_->Unregister();
|
| video_capture_device_factory_->set_number_of_devices(number_of_devices_keep);
|
| @@ -330,8 +305,6 @@ TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) {
|
| // formats. Then start the opened device. The capability list should stay the
|
| // same. Finally stop the device and check that the capabilities stay unchanged.
|
| TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| // Before enumerating the devices, requesting formats should return false.
|
| int video_session_id = 0;
|
| media::VideoCaptureFormats supported_formats;
|
| @@ -340,14 +313,8 @@ TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
|
| vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats));
|
|
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| - base::RunLoop().RunUntilIdle();
|
| - ASSERT_GE(devices.size(), 2u);
|
| -
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| - video_session_id = vcm_->Open(devices.front());
|
| + video_session_id = vcm_->Open(devices_.front());
|
| base::RunLoop().RunUntilIdle();
|
|
|
| // Right after opening the device, we should see all its formats.
|
| @@ -400,17 +367,9 @@ TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
|
| // starting the device). Finally stop the device and check that the formats in
|
| // use is an empty vector.
|
| TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| - base::RunLoop().RunUntilIdle();
|
| - ASSERT_GE(devices.size(), 2u);
|
| -
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| - int video_session_id = vcm_->Open(devices.front());
|
| + int video_session_id = vcm_->Open(devices_.front());
|
| base::RunLoop().RunUntilIdle();
|
|
|
| // Right after opening the device, we should see no format in use.
|
| @@ -446,20 +405,11 @@ TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) {
|
|
|
| // Open two different devices.
|
| TEST_F(VideoCaptureManagerTest, OpenTwo) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| - StreamDeviceInfoArray::iterator it = devices.begin();
|
| + StreamDeviceInfoArray::iterator it = devices_.begin();
|
|
|
| int video_session_id_first = vcm_->Open(*it);
|
| ++it;
|
| @@ -475,20 +425,11 @@ TEST_F(VideoCaptureManagerTest, OpenTwo) {
|
|
|
| // Try open a non-existing device.
|
| TEST_F(VideoCaptureManagerTest, OpenNotExisting) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| EXPECT_CALL(*frame_observer_, OnError(_));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE;
|
| std::string device_name("device_doesnt_exist");
|
| std::string device_id("id_doesnt_exist");
|
| @@ -517,23 +458,11 @@ TEST_F(VideoCaptureManagerTest, StartInvalidSession) {
|
|
|
| // Open and start a device, close it before calling Stop.
|
| TEST_F(VideoCaptureManagerTest, CloseWithoutStop) {
|
| - StreamDeviceInfoArray devices;
|
| - base::RunLoop run_loop;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(
|
| - DoAll(SaveArg<1>(&devices),
|
| - InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - run_loop.Run();
|
| - ASSERT_FALSE(devices.empty());
|
| - int video_session_id = vcm_->Open(devices.front());
|
| + int video_session_id = vcm_->Open(devices_.front());
|
|
|
| VideoCaptureControllerID client_id = StartClient(video_session_id, true);
|
|
|
| @@ -549,20 +478,11 @@ TEST_F(VideoCaptureManagerTest, CloseWithoutStop) {
|
|
|
| // Try to open, start, pause and resume a device.
|
| TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| - int video_session_id = vcm_->Open(devices.front());
|
| + int video_session_id = vcm_->Open(devices_.front());
|
| VideoCaptureControllerID client_id = StartClient(video_session_id, true);
|
|
|
| // Resume client a second time should cause no problem.
|
| @@ -581,20 +501,11 @@ TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) {
|
| #if defined(OS_ANDROID)
|
| // Try to open, start, pause and resume a device.
|
| TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) {
|
| - StreamDeviceInfoArray devices;
|
| -
|
| InSequence s;
|
| - EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
|
| - .WillOnce(SaveArg<1>(&devices));
|
| EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
| EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
|
|
|
| - vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
|
| -
|
| - // Wait to get device callback.
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| - int video_session_id = vcm_->Open(devices.front());
|
| + int video_session_id = vcm_->Open(devices_.front());
|
| VideoCaptureControllerID client_id = StartClient(video_session_id, true);
|
|
|
| // Release/ResumeDevices according to ApplicationStatus. Should cause no
|
|
|