Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager_unittest.cc

Issue 91343002: Added supported formats caching to VideoCaptureManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased FakeVCD. Reconnected VCManager unittest for all platforms. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "content/browser/browser_thread_impl.h" 14 #include "content/browser/browser_thread_impl.h"
15 #include "content/browser/renderer_host/media/media_stream_provider.h" 15 #include "content/browser/renderer_host/media/media_stream_provider.h"
16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
17 #include "content/browser/renderer_host/media/video_capture_manager.h" 17 #include "content/browser/renderer_host/media/video_capture_manager.h"
18 #include "content/common/media/media_stream_options.h" 18 #include "content/common/media/media_stream_options.h"
19 #include "media/video/capture/fake_video_capture_device.h"
19 #include "media/video/capture/video_capture_device.h" 20 #include "media/video/capture/video_capture_device.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 using ::testing::_; 24 using ::testing::_;
24 using ::testing::AnyNumber; 25 using ::testing::AnyNumber;
25 using ::testing::InSequence; 26 using ::testing::InSequence;
26 using ::testing::Return; 27 using ::testing::Return;
27 using ::testing::SaveArg; 28 using ::testing::SaveArg;
28 29
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 message_loop_->RunUntilIdle(); 166 message_loop_->RunUntilIdle();
166 vcm_->Unregister(); 167 vcm_->Unregister();
167 } 168 }
168 169
169 // Open the same device twice. 170 // Open the same device twice.
170 TEST_F(VideoCaptureManagerTest, OpenTwice) { 171 TEST_F(VideoCaptureManagerTest, OpenTwice) {
171 StreamDeviceInfoArray devices; 172 StreamDeviceInfoArray devices;
172 173
173 InSequence s; 174 InSequence s;
174 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 175 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
175 .Times(1).WillOnce(SaveArg<1>(&devices)); 176 .Times(1)
scherkus (not reviewing) 2013/12/03 22:04:48 nit: Times(1) is implied when using EXPECT_CALL()
mcasas 2013/12/04 15:23:32 Thanks, see http://crbug.com/325740.
177 .WillOnce(SaveArg<1>(&devices));
176 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 178 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
177 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 179 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
178 180
179 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 181 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
180 182
181 // Wait to get device callback. 183 // Wait to get device callback.
182 message_loop_->RunUntilIdle(); 184 message_loop_->RunUntilIdle();
183 185
184 int video_session_id_first = vcm_->Open(devices.front()); 186 int video_session_id_first = vcm_->Open(devices.front());
185 187
186 // This should trigger an error callback with error code 188 // This should trigger an error callback with error code
187 // 'kDeviceAlreadyInUse'. 189 // 'kDeviceAlreadyInUse'.
188 int video_session_id_second = vcm_->Open(devices.front()); 190 int video_session_id_second = vcm_->Open(devices.front());
189 EXPECT_NE(video_session_id_first, video_session_id_second); 191 EXPECT_NE(video_session_id_first, video_session_id_second);
190 192
191 vcm_->Close(video_session_id_first); 193 vcm_->Close(video_session_id_first);
192 vcm_->Close(video_session_id_second); 194 vcm_->Close(video_session_id_second);
193 195
194 // Wait to check callbacks before removing the listener. 196 // Wait to check callbacks before removing the listener.
195 message_loop_->RunUntilIdle(); 197 message_loop_->RunUntilIdle();
196 vcm_->Unregister(); 198 vcm_->Unregister();
197 } 199 }
198 200
201 // Connect and disconnect devices.
202 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) {
203 StreamDeviceInfoArray devices;
204 int number_of_devices_keep =
205 media::FakeVideoCaptureDevice::NumberOfFakeDevices();
206
207 InSequence s;
208 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
209 .Times(1)
210 .WillOnce(SaveArg<1>(&devices));
211 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
212 message_loop_->RunUntilIdle();
213 ASSERT_EQ(devices.size(), 2u);
214
215 // Simulate we remove 1 fake device.
216 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1);
217 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
218 .Times(1)
219 .WillOnce(SaveArg<1>(&devices));
220 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
221 message_loop_->RunUntilIdle();
222 ASSERT_EQ(devices.size(), 1u);
223
224 // Simulate we add 2 fake devices.
225 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3);
226 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
227 .Times(1)
228 .WillOnce(SaveArg<1>(&devices));
229 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
230 message_loop_->RunUntilIdle();
231 ASSERT_EQ(devices.size(), 3u);
232
233 vcm_->Unregister();
234 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep);
235 }
236
237 // Enumerate devices and open the first, then check the list of supported
238 // formats. Then start the opened device. The capability list should be reduced
239 // to just one format, and this should be the one used when configuring-starting
240 // the device. Finally stop the device and check that the capabilities have been
241 // restored.
242 //
243 // Underlying FakeVCD hits a SIGSEGV at the end of this test in Mac Valgrind
244 // bot, see http://crbug.com/319955. Possibly associated to FakeVCD races,
245 // check this test after http://crbug.com/323893.
246 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
247 StreamDeviceInfoArray devices;
248
249 InSequence s;
250 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
251 .Times(1)
252 .WillOnce(SaveArg<1>(&devices));
253 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
254 message_loop_->RunUntilIdle();
255
256 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
257 int video_session_id = vcm_->Open(devices.front());
258 message_loop_->RunUntilIdle();
259
260 // When the device has been opened, we should see all the devices'
261 // supported formats.
262 media::VideoCaptureFormats supported_formats;
263 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
264 ASSERT_EQ(devices.size(), 2u);
265 ASSERT_GT(supported_formats.size(), 1u);
266 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
267 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
268 EXPECT_GT(supported_formats[0].frame_rate, 1);
269 EXPECT_GT(supported_formats[1].frame_size.width(), 1);
270 EXPECT_GT(supported_formats[1].frame_size.height(), 1);
271 EXPECT_GT(supported_formats[1].frame_rate, 1);
272
273 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
274 message_loop_->RunUntilIdle();
275 // After StartClient(), device's supported formats should be reduced to one.
276 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
277 ASSERT_EQ(supported_formats.size(), 1u);
278 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
279 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
280 EXPECT_GT(supported_formats[0].frame_rate, 1);
281
282 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
283 StopClient(client_id);
284 // After StopClient(), the device's list of supported formats should be
285 // restored to the original one.
286 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
287 ASSERT_GT(supported_formats.size(), 1u);
288 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
289 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
290 EXPECT_GT(supported_formats[0].frame_rate, 1);
291 EXPECT_GT(supported_formats[1].frame_size.width(), 1);
292 EXPECT_GT(supported_formats[1].frame_size.height(), 1);
293 EXPECT_GT(supported_formats[1].frame_rate, 1);
294
295 vcm_->Close(video_session_id);
296 message_loop_->RunUntilIdle();
297 vcm_->Unregister();
298 }
299
199 // Open two different devices. 300 // Open two different devices.
200 TEST_F(VideoCaptureManagerTest, OpenTwo) { 301 TEST_F(VideoCaptureManagerTest, OpenTwo) {
201 StreamDeviceInfoArray devices; 302 StreamDeviceInfoArray devices;
202 303
203 InSequence s; 304 InSequence s;
204 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 305 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
205 .Times(1).WillOnce(SaveArg<1>(&devices)); 306 .Times(1).WillOnce(SaveArg<1>(&devices));
206 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 307 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
207 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 308 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
208 309
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // VideoCaptureManager destructor otherwise. 391 // VideoCaptureManager destructor otherwise.
291 vcm_->Close(video_session_id); 392 vcm_->Close(video_session_id);
292 StopClient(client_id); 393 StopClient(client_id);
293 394
294 // Wait to check callbacks before removing the listener 395 // Wait to check callbacks before removing the listener
295 message_loop_->RunUntilIdle(); 396 message_loop_->RunUntilIdle();
296 vcm_->Unregister(); 397 vcm_->Unregister();
297 } 398 }
298 399
299 } // namespace content 400 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698