Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit test for VideoCaptureManager. | 5 // Unit test for VideoCaptureManager. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 public: | 33 public: |
| 34 MockMediaStreamProviderListener() {} | 34 MockMediaStreamProviderListener() {} |
| 35 ~MockMediaStreamProviderListener() {} | 35 ~MockMediaStreamProviderListener() {} |
| 36 | 36 |
| 37 MOCK_METHOD2(Opened, void(MediaStreamType, int)); | 37 MOCK_METHOD2(Opened, void(MediaStreamType, int)); |
| 38 MOCK_METHOD2(Closed, void(MediaStreamType, int)); | 38 MOCK_METHOD2(Closed, void(MediaStreamType, int)); |
| 39 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType, | 39 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType, |
| 40 const StreamDeviceInfoArray&)); | 40 const StreamDeviceInfoArray&)); |
| 41 MOCK_METHOD3(Error, void(MediaStreamType, int, | 41 MOCK_METHOD3(Error, void(MediaStreamType, int, |
| 42 MediaStreamProviderError)); | 42 MediaStreamProviderError)); |
| 43 MOCK_METHOD2( | |
| 44 DeviceCapabilitiesEnumerated, | |
| 45 void(const StreamDeviceInfo&, const media::VideoCaptureCapabilities&)); | |
| 43 }; // class MockMediaStreamProviderListener | 46 }; // class MockMediaStreamProviderListener |
| 44 | 47 |
| 45 // Needed as an input argument to StartCaptureForClient(). | 48 // Needed as an input argument to StartCaptureForClient(). |
| 46 class MockFrameObserver : public VideoCaptureControllerEventHandler { | 49 class MockFrameObserver : public VideoCaptureControllerEventHandler { |
| 47 public: | 50 public: |
| 48 MOCK_METHOD1(OnError, void(const VideoCaptureControllerID& id)); | 51 MOCK_METHOD1(OnError, void(const VideoCaptureControllerID& id)); |
| 49 | 52 |
| 50 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | 53 virtual void OnBufferCreated(const VideoCaptureControllerID& id, |
| 51 base::SharedMemoryHandle handle, | 54 base::SharedMemoryHandle handle, |
| 52 int length, int buffer_id) OVERRIDE {} | 55 int length, int buffer_id) OVERRIDE {} |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 157 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 155 | 158 |
| 156 StopClient(client_id); | 159 StopClient(client_id); |
| 157 vcm_->Close(video_session_id); | 160 vcm_->Close(video_session_id); |
| 158 | 161 |
| 159 // Wait to check callbacks before removing the listener. | 162 // Wait to check callbacks before removing the listener. |
| 160 message_loop_->RunUntilIdle(); | 163 message_loop_->RunUntilIdle(); |
| 161 vcm_->Unregister(); | 164 vcm_->Unregister(); |
| 162 } | 165 } |
| 163 | 166 |
| 167 // Try to enumerate all devices, then check their capture capabilities. | |
| 168 TEST_F(VideoCaptureManagerTest, EnumerateDevicesAndCheckCapabilities) { | |
|
perkj_chrome
2013/10/29 12:13:36
You don't need to be able to enumerate all devices
| |
| 169 StreamDeviceInfoArray devices; | |
| 170 | |
| 171 InSequence s; | |
| 172 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 173 .Times(1).WillOnce(SaveArg<1>(&devices)); | |
| 174 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 175 message_loop_->RunUntilIdle(); | |
| 176 | |
| 177 media::VideoCaptureCapabilities device_capabilities; | |
| 178 StreamDeviceInfoArray::iterator device_it; | |
| 179 for (device_it = devices.begin(); device_it != devices.end(); ++device_it) { | |
| 180 device_capabilities.clear(); | |
| 181 EXPECT_CALL(*listener_, DeviceCapabilitiesEnumerated(_, _)) | |
| 182 .Times(1).WillOnce(SaveArg<1>(&device_capabilities)); | |
| 183 | |
| 184 // Enumerate the device capabilities for a single device identified by its | |
| 185 // unique name. Result is left in DeviceCapabilitiesEnumerated() parameter. | |
| 186 // For fake device, there are two capabilities. | |
| 187 vcm_->EnumerateDeviceCapabilities(*device_it); | |
| 188 message_loop_->RunUntilIdle(); | |
| 189 EXPECT_EQ(device_capabilities.size(), 2u); | |
| 190 | |
| 191 media::VideoCaptureCapabilities::const_iterator format; | |
| 192 for (format = device_capabilities.begin(); | |
| 193 format != device_capabilities.end(); | |
| 194 ++format) { | |
| 195 EXPECT_GE(format->width, 1); | |
| 196 EXPECT_GE(format->height, 1); | |
| 197 EXPECT_GE(format->frame_rate, 1); | |
| 198 DVLOG(1) << " Device name: " << device_it->device.name << ", format (" | |
| 199 << format->width << "x" << format->height << ")@" | |
| 200 << format->frame_rate << "fps"; | |
| 201 } | |
| 202 } | |
| 203 } | |
| 204 | |
| 205 // Open and start one of the enumerated devices. The capability list should be | |
| 206 // reduced to just one format, and this should be the one used when | |
| 207 // configuring-starting the device. | |
| 208 TEST_F(VideoCaptureManagerTest, StartDeviceAndCheckCapabilities) { | |
| 209 StreamDeviceInfoArray devices; | |
| 210 | |
| 211 InSequence s; | |
| 212 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 213 .Times(1) | |
| 214 .WillOnce(SaveArg<1>(&devices)); | |
| 215 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 216 message_loop_->RunUntilIdle(); | |
| 217 | |
| 218 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); | |
| 219 int video_session_id = vcm_->Open(devices.front()); | |
| 220 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | |
| 221 message_loop_->RunUntilIdle(); | |
| 222 | |
| 223 media::VideoCaptureCapabilities device_capabilities; | |
| 224 EXPECT_CALL(*listener_, DeviceCapabilitiesEnumerated(_, _)) | |
| 225 .Times(1).WillOnce(SaveArg<1>(&device_capabilities)); | |
| 226 // After StartClient(), the device's list of capabilities should be reduced | |
| 227 // to just one, coinciding with the one configured inside that method. | |
| 228 vcm_->EnumerateDeviceCapabilities(devices.front()); | |
| 229 message_loop_->RunUntilIdle(); | |
| 230 EXPECT_EQ(device_capabilities.size(), 1u); | |
| 231 | |
| 232 media::VideoCaptureCapabilities::const_iterator format; | |
| 233 for (format = device_capabilities.begin(); | |
| 234 format != device_capabilities.end(); | |
| 235 ++format) { | |
| 236 EXPECT_EQ(format->width, 320); | |
| 237 EXPECT_EQ(format->height, 240); | |
| 238 EXPECT_EQ(format->frame_rate, 30); | |
| 239 DVLOG(1) << " Device name: " << devices.front().device.name << ", format (" | |
| 240 << format->width << "x" << format->height << ")@" | |
| 241 << format->frame_rate << "fps"; | |
| 242 } | |
| 243 | |
| 244 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); | |
| 245 StopClient(client_id); | |
| 246 vcm_->Close(video_session_id); | |
| 247 message_loop_->RunUntilIdle(); | |
| 248 vcm_->Unregister(); | |
| 249 } | |
| 250 | |
| 251 // Open and start one of the enumerated devices, then close the device. The | |
| 252 // capability list after starting the device is reduced, and after stopping it | |
| 253 // should become longer again. | |
| 254 TEST_F(VideoCaptureManagerTest, StartDeviceAndStopAndCheckCapabilities) { | |
| 255 StreamDeviceInfoArray devices; | |
| 256 | |
| 257 InSequence s; | |
| 258 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 259 .Times(1) | |
| 260 .WillOnce(SaveArg<1>(&devices)); | |
| 261 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 262 message_loop_->RunUntilIdle(); | |
| 263 | |
| 264 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); | |
| 265 int video_session_id = vcm_->Open(devices.front()); | |
| 266 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | |
| 267 message_loop_->RunUntilIdle(); | |
| 268 | |
| 269 vcm_->EnumerateDeviceCapabilities(devices.front()); | |
| 270 message_loop_->RunUntilIdle(); | |
| 271 | |
| 272 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); | |
| 273 StopClient(client_id); | |
| 274 vcm_->Close(video_session_id); | |
| 275 | |
| 276 media::VideoCaptureCapabilities device_capabilities; | |
| 277 EXPECT_CALL(*listener_, DeviceCapabilitiesEnumerated(_, _)) | |
| 278 .Times(1).WillOnce(SaveArg<1>(&device_capabilities)); | |
| 279 // After StopClient(), the device's list of capabilities should be back to | |
| 280 // normal, meaning all the capabilities supported by the device. For fake | |
| 281 // device, this is 2. | |
| 282 vcm_->EnumerateDeviceCapabilities(devices.front()); | |
| 283 message_loop_->RunUntilIdle(); | |
| 284 EXPECT_EQ(device_capabilities.size(), 2u); | |
| 285 | |
| 286 message_loop_->RunUntilIdle(); | |
| 287 vcm_->Unregister(); | |
| 288 } | |
| 289 | |
| 164 // Open the same device twice. | 290 // Open the same device twice. |
| 165 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 291 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
| 166 StreamDeviceInfoArray devices; | 292 StreamDeviceInfoArray devices; |
| 167 | 293 |
| 168 InSequence s; | 294 InSequence s; |
| 169 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 295 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 170 .Times(1).WillOnce(SaveArg<1>(&devices)); | 296 .Times(1).WillOnce(SaveArg<1>(&devices)); |
| 171 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 297 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 172 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 298 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 173 | 299 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 // VideoCaptureManager destructor otherwise. | 411 // VideoCaptureManager destructor otherwise. |
| 286 vcm_->Close(video_session_id); | 412 vcm_->Close(video_session_id); |
| 287 StopClient(client_id); | 413 StopClient(client_id); |
| 288 | 414 |
| 289 // Wait to check callbacks before removing the listener | 415 // Wait to check callbacks before removing the listener |
| 290 message_loop_->RunUntilIdle(); | 416 message_loop_->RunUntilIdle(); |
| 291 vcm_->Unregister(); | 417 vcm_->Unregister(); |
| 292 } | 418 } |
| 293 | 419 |
| 294 } // namespace content | 420 } // namespace content |
| OLD | NEW |