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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 message_loop_->RunUntilIdle(); | 160 message_loop_->RunUntilIdle(); |
161 vcm_->Unregister(); | 161 vcm_->Unregister(); |
162 } | 162 } |
163 | 163 |
164 // Open the same device twice. | 164 // Open the same device twice. |
165 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 165 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
166 StreamDeviceInfoArray devices; | 166 StreamDeviceInfoArray devices; |
167 | 167 |
168 InSequence s; | 168 InSequence s; |
169 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 169 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
170 .Times(1).WillOnce(SaveArg<1>(&devices)); | 170 .Times(1) |
| 171 .WillOnce(SaveArg<1>(&devices)); |
171 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 172 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
172 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 173 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
173 | 174 |
174 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 175 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
175 | 176 |
176 // Wait to get device callback. | 177 // Wait to get device callback. |
177 message_loop_->RunUntilIdle(); | 178 message_loop_->RunUntilIdle(); |
178 | 179 |
179 int video_session_id_first = vcm_->Open(devices.front()); | 180 int video_session_id_first = vcm_->Open(devices.front()); |
180 | 181 |
181 // This should trigger an error callback with error code | 182 // This should trigger an error callback with error code |
182 // 'kDeviceAlreadyInUse'. | 183 // 'kDeviceAlreadyInUse'. |
183 int video_session_id_second = vcm_->Open(devices.front()); | 184 int video_session_id_second = vcm_->Open(devices.front()); |
184 EXPECT_NE(video_session_id_first, video_session_id_second); | 185 EXPECT_NE(video_session_id_first, video_session_id_second); |
185 | 186 |
186 vcm_->Close(video_session_id_first); | 187 vcm_->Close(video_session_id_first); |
187 vcm_->Close(video_session_id_second); | 188 vcm_->Close(video_session_id_second); |
188 | 189 |
189 // Wait to check callbacks before removing the listener. | 190 // Wait to check callbacks before removing the listener. |
190 message_loop_->RunUntilIdle(); | 191 message_loop_->RunUntilIdle(); |
191 vcm_->Unregister(); | 192 vcm_->Unregister(); |
192 } | 193 } |
193 | 194 |
| 195 // Enumerate devices and open the first, then check the capabilities. Then start |
| 196 // the opened device. The capability list should be reduced to just one format, |
| 197 // and this should be the one used when configuring-starting the device. Finally |
| 198 // stop the device and check that the capabilities have been restored. |
| 199 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
| 200 StreamDeviceInfoArray devices; |
| 201 |
| 202 InSequence s; |
| 203 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 204 .Times(1) |
| 205 .WillOnce(SaveArg<1>(&devices)); |
| 206 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 207 message_loop_->RunUntilIdle(); |
| 208 |
| 209 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| 210 int video_session_id = vcm_->Open(devices.front()); |
| 211 message_loop_->RunUntilIdle(); |
| 212 |
| 213 // When the device has been opened, we should see all the devices' |
| 214 // capabilities. |
| 215 media::VideoCaptureCapabilities device_capabilities; |
| 216 vcm_->GetDeviceCapabilities(video_session_id, &device_capabilities); |
| 217 ASSERT_GT(device_capabilities.size(), 1u); |
| 218 EXPECT_GT(device_capabilities[0].width, 1); |
| 219 EXPECT_GT(device_capabilities[0].height, 1); |
| 220 EXPECT_GT(device_capabilities[0].frame_rate, 1); |
| 221 EXPECT_GT(device_capabilities[1].width, 1); |
| 222 EXPECT_GT(device_capabilities[1].height, 1); |
| 223 EXPECT_GT(device_capabilities[1].frame_rate, 1); |
| 224 |
| 225 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 226 message_loop_->RunUntilIdle(); |
| 227 // After StartClient(), the device's capabilities should be reduced to one. |
| 228 vcm_->GetDeviceCapabilities(video_session_id, &device_capabilities); |
| 229 ASSERT_EQ(device_capabilities.size(), 1u); |
| 230 EXPECT_GT(device_capabilities[0].width, 1); |
| 231 EXPECT_GT(device_capabilities[0].height, 1); |
| 232 EXPECT_GT(device_capabilities[0].frame_rate, 1); |
| 233 |
| 234 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| 235 StopClient(client_id); |
| 236 message_loop_->RunUntilIdle(); |
| 237 // After StopClient(), the device's list of capabilities should be restored |
| 238 // to the original one. |
| 239 vcm_->GetDeviceCapabilities(video_session_id, &device_capabilities); |
| 240 ASSERT_GT(device_capabilities.size(), 1u); |
| 241 EXPECT_GT(device_capabilities[0].width, 1); |
| 242 EXPECT_GT(device_capabilities[0].height, 1); |
| 243 EXPECT_GT(device_capabilities[0].frame_rate, 1); |
| 244 EXPECT_GT(device_capabilities[1].width, 1); |
| 245 EXPECT_GT(device_capabilities[1].height, 1); |
| 246 EXPECT_GT(device_capabilities[1].frame_rate, 1); |
| 247 |
| 248 vcm_->Close(video_session_id); |
| 249 message_loop_->RunUntilIdle(); |
| 250 vcm_->Unregister(); |
| 251 } |
| 252 |
194 // Open two different devices. | 253 // Open two different devices. |
195 TEST_F(VideoCaptureManagerTest, OpenTwo) { | 254 TEST_F(VideoCaptureManagerTest, OpenTwo) { |
196 StreamDeviceInfoArray devices; | 255 StreamDeviceInfoArray devices; |
197 | 256 |
198 InSequence s; | 257 InSequence s; |
199 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 258 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
200 .Times(1).WillOnce(SaveArg<1>(&devices)); | 259 .Times(1).WillOnce(SaveArg<1>(&devices)); |
201 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 260 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
202 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 261 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
203 | 262 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // VideoCaptureManager destructor otherwise. | 344 // VideoCaptureManager destructor otherwise. |
286 vcm_->Close(video_session_id); | 345 vcm_->Close(video_session_id); |
287 StopClient(client_id); | 346 StopClient(client_id); |
288 | 347 |
289 // Wait to check callbacks before removing the listener | 348 // Wait to check callbacks before removing the listener |
290 message_loop_->RunUntilIdle(); | 349 message_loop_->RunUntilIdle(); |
291 vcm_->Unregister(); | 350 vcm_->Unregister(); |
292 } | 351 } |
293 | 352 |
294 } // namespace content | 353 } // namespace content |
OLD | NEW |