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