Chromium Code Reviews| 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 a986e0bc3702eca982798687eb0dbc9f17821b82..cd549154bf254349e85b9c23345ce9a9a01d2d77 100644 |
| --- a/content/browser/renderer_host/media/video_capture_manager_unittest.cc |
| +++ b/content/browser/renderer_host/media/video_capture_manager_unittest.cc |
| @@ -40,6 +40,9 @@ class MockMediaStreamProviderListener : public MediaStreamProviderListener { |
| const StreamDeviceInfoArray&)); |
| MOCK_METHOD3(Error, void(MediaStreamType, int, |
| MediaStreamProviderError)); |
| + MOCK_METHOD2( |
| + DeviceCapabilitiesEnumerated, |
| + void(const StreamDeviceInfo&, const media::VideoCaptureCapabilities&)); |
| }; // class MockMediaStreamProviderListener |
| // Needed as an input argument to StartCaptureForClient(). |
| @@ -161,6 +164,129 @@ TEST_F(VideoCaptureManagerTest, CreateAndClose) { |
| vcm_->Unregister(); |
| } |
| +// Try to enumerate all devices, then check their capture capabilities. |
| +TEST_F(VideoCaptureManagerTest, EnumerateDevicesAndCheckCapabilities) { |
|
perkj_chrome
2013/10/29 12:13:36
You don't need to be able to enumerate all devices
|
| + StreamDeviceInfoArray devices; |
| + |
| + InSequence s; |
| + EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| + .Times(1).WillOnce(SaveArg<1>(&devices)); |
| + vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| + message_loop_->RunUntilIdle(); |
| + |
| + media::VideoCaptureCapabilities device_capabilities; |
| + StreamDeviceInfoArray::iterator device_it; |
| + for (device_it = devices.begin(); device_it != devices.end(); ++device_it) { |
| + device_capabilities.clear(); |
| + EXPECT_CALL(*listener_, DeviceCapabilitiesEnumerated(_, _)) |
| + .Times(1).WillOnce(SaveArg<1>(&device_capabilities)); |
| + |
| + // Enumerate the device capabilities for a single device identified by its |
| + // unique name. Result is left in DeviceCapabilitiesEnumerated() parameter. |
| + // For fake device, there are two capabilities. |
| + vcm_->EnumerateDeviceCapabilities(*device_it); |
| + message_loop_->RunUntilIdle(); |
| + EXPECT_EQ(device_capabilities.size(), 2u); |
| + |
| + media::VideoCaptureCapabilities::const_iterator format; |
| + for (format = device_capabilities.begin(); |
| + format != device_capabilities.end(); |
| + ++format) { |
| + EXPECT_GE(format->width, 1); |
| + EXPECT_GE(format->height, 1); |
| + EXPECT_GE(format->frame_rate, 1); |
| + DVLOG(1) << " Device name: " << device_it->device.name << ", format (" |
| + << format->width << "x" << format->height << ")@" |
| + << format->frame_rate << "fps"; |
| + } |
| + } |
| +} |
| + |
| +// Open and start one of the enumerated devices. The capability list should be |
| +// reduced to just one format, and this should be the one used when |
| +// configuring-starting the device. |
| +TEST_F(VideoCaptureManagerTest, StartDeviceAndCheckCapabilities) { |
| + StreamDeviceInfoArray devices; |
| + |
| + InSequence s; |
| + EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| + .Times(1) |
| + .WillOnce(SaveArg<1>(&devices)); |
| + vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| + message_loop_->RunUntilIdle(); |
| + |
| + EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| + int video_session_id = vcm_->Open(devices.front()); |
| + VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| + message_loop_->RunUntilIdle(); |
| + |
| + media::VideoCaptureCapabilities device_capabilities; |
| + EXPECT_CALL(*listener_, DeviceCapabilitiesEnumerated(_, _)) |
| + .Times(1).WillOnce(SaveArg<1>(&device_capabilities)); |
| + // After StartClient(), the device's list of capabilities should be reduced |
| + // to just one, coinciding with the one configured inside that method. |
| + vcm_->EnumerateDeviceCapabilities(devices.front()); |
| + message_loop_->RunUntilIdle(); |
| + EXPECT_EQ(device_capabilities.size(), 1u); |
| + |
| + media::VideoCaptureCapabilities::const_iterator format; |
| + for (format = device_capabilities.begin(); |
| + format != device_capabilities.end(); |
| + ++format) { |
| + EXPECT_EQ(format->width, 320); |
| + EXPECT_EQ(format->height, 240); |
| + EXPECT_EQ(format->frame_rate, 30); |
| + DVLOG(1) << " Device name: " << devices.front().device.name << ", format (" |
| + << format->width << "x" << format->height << ")@" |
| + << format->frame_rate << "fps"; |
| + } |
| + |
| + EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| + StopClient(client_id); |
| + vcm_->Close(video_session_id); |
| + message_loop_->RunUntilIdle(); |
| + vcm_->Unregister(); |
| +} |
| + |
| +// Open and start one of the enumerated devices, then close the device. The |
| +// capability list after starting the device is reduced, and after stopping it |
| +// should become longer again. |
| +TEST_F(VideoCaptureManagerTest, StartDeviceAndStopAndCheckCapabilities) { |
| + StreamDeviceInfoArray devices; |
| + |
| + InSequence s; |
| + EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| + .Times(1) |
| + .WillOnce(SaveArg<1>(&devices)); |
| + vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| + message_loop_->RunUntilIdle(); |
| + |
| + EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| + int video_session_id = vcm_->Open(devices.front()); |
| + VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| + message_loop_->RunUntilIdle(); |
| + |
| + vcm_->EnumerateDeviceCapabilities(devices.front()); |
| + message_loop_->RunUntilIdle(); |
| + |
| + EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| + StopClient(client_id); |
| + vcm_->Close(video_session_id); |
| + |
| + media::VideoCaptureCapabilities device_capabilities; |
| + EXPECT_CALL(*listener_, DeviceCapabilitiesEnumerated(_, _)) |
| + .Times(1).WillOnce(SaveArg<1>(&device_capabilities)); |
| + // After StopClient(), the device's list of capabilities should be back to |
| + // normal, meaning all the capabilities supported by the device. For fake |
| + // device, this is 2. |
| + vcm_->EnumerateDeviceCapabilities(devices.front()); |
| + message_loop_->RunUntilIdle(); |
| + EXPECT_EQ(device_capabilities.size(), 2u); |
| + |
| + message_loop_->RunUntilIdle(); |
| + vcm_->Unregister(); |
| +} |
| + |
| // Open the same device twice. |
| TEST_F(VideoCaptureManagerTest, OpenTwice) { |
| StreamDeviceInfoArray devices; |