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

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: Mad formatting corrected in certain files. 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 EXPECT_NE(video_session_id_first, video_session_id_second); 190 EXPECT_NE(video_session_id_first, video_session_id_second);
190 191
191 vcm_->Close(video_session_id_first); 192 vcm_->Close(video_session_id_first);
192 vcm_->Close(video_session_id_second); 193 vcm_->Close(video_session_id_second);
193 194
194 // Wait to check callbacks before removing the listener. 195 // Wait to check callbacks before removing the listener.
195 message_loop_->RunUntilIdle(); 196 message_loop_->RunUntilIdle();
196 vcm_->Unregister(); 197 vcm_->Unregister();
197 } 198 }
198 199
200 // Connect and disconnect devices.
201 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) {
202 StreamDeviceInfoArray devices;
203 int number_of_devices_keep =
204 media::FakeVideoCaptureDevice::NumberOfFakeDevices();
205
206 InSequence s;
207 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
208 .Times(1).WillOnce(SaveArg<1>(&devices));
209 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
210 message_loop_->RunUntilIdle();
211 ASSERT_EQ(devices.size(), 2u);
212
213 // Simulate we remove 1 fake device.
214 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1);
215 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
216 .Times(1).WillOnce(SaveArg<1>(&devices));
217 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
218 message_loop_->RunUntilIdle();
219 ASSERT_EQ(devices.size(), 1u);
220
221 // Simulate we add 2 fake devices.
222 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3);
223 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
224 .Times(1).WillOnce(SaveArg<1>(&devices));
225 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
226 message_loop_->RunUntilIdle();
227 ASSERT_EQ(devices.size(), 3u);
228
229 vcm_->Unregister();
230 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep);
231 }
232
233 // Enumerate devices and open the first, then check the list of supported
234 // formats. Then start the opened device. The capability list should be reduced
235 // to just one format, and this should be the one used when configuring-starting
236 // the device. Finally stop the device and check that the capabilities have been
237 // restored.
238 //
239 // Underlying FakeVCD hits a SIGSEGV at the end of this test in Mac Valgrind
240 // bot, see http://crbug.com/319955. Possibly associated to FakeVCD races,
241 // check this test after http://crbug.com/323893.
perkj_chrome 2013/12/10 12:27:14 looks like this is fixed. Remove the comments and
mcasas 2013/12/12 10:38:05 Done.
242 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
243 StreamDeviceInfoArray devices;
244
245 InSequence s;
246 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
247 .Times(1).WillOnce(SaveArg<1>(&devices));
248 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
249 message_loop_->RunUntilIdle();
250
251 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
252 int video_session_id = vcm_->Open(devices.front());
253 message_loop_->RunUntilIdle();
254
255 // When the device has been opened, we should see all the devices'
256 // supported formats.
257 media::VideoCaptureFormats supported_formats;
258 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
259 ASSERT_EQ(devices.size(), 2u);
260 ASSERT_GT(supported_formats.size(), 1u);
261 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
262 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
263 EXPECT_GT(supported_formats[0].frame_rate, 1);
264 EXPECT_GT(supported_formats[1].frame_size.width(), 1);
265 EXPECT_GT(supported_formats[1].frame_size.height(), 1);
266 EXPECT_GT(supported_formats[1].frame_rate, 1);
267
268 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
269 message_loop_->RunUntilIdle();
270 // After StartClient(), device's supported formats should be reduced to one.
271 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
272 ASSERT_EQ(supported_formats.size(), 1u);
perkj_chrome 2013/12/10 12:27:14 nit: This can be EXPECT_EQ
mcasas 2013/12/12 10:38:05 I prefer the test to fail and not continue if the
273 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
274 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
275 EXPECT_GT(supported_formats[0].frame_rate, 1);
276
277 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
278 StopClient(client_id);
279 // After StopClient(), the device's list of supported formats should be
280 // restored to the original one.
281 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
282 ASSERT_GT(supported_formats.size(), 1u);
283 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
284 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
285 EXPECT_GT(supported_formats[0].frame_rate, 1);
286 EXPECT_GT(supported_formats[1].frame_size.width(), 1);
287 EXPECT_GT(supported_formats[1].frame_size.height(), 1);
288 EXPECT_GT(supported_formats[1].frame_rate, 1);
289
290 vcm_->Close(video_session_id);
291 message_loop_->RunUntilIdle();
292 vcm_->Unregister();
293 }
294
199 // Open two different devices. 295 // Open two different devices.
200 TEST_F(VideoCaptureManagerTest, OpenTwo) { 296 TEST_F(VideoCaptureManagerTest, OpenTwo) {
201 StreamDeviceInfoArray devices; 297 StreamDeviceInfoArray devices;
202 298
203 InSequence s; 299 InSequence s;
204 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 300 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
205 .Times(1).WillOnce(SaveArg<1>(&devices)); 301 .Times(1).WillOnce(SaveArg<1>(&devices));
206 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 302 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
207 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 303 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
208 304
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // VideoCaptureManager destructor otherwise. 386 // VideoCaptureManager destructor otherwise.
291 vcm_->Close(video_session_id); 387 vcm_->Close(video_session_id);
292 StopClient(client_id); 388 StopClient(client_id);
293 389
294 // Wait to check callbacks before removing the listener 390 // Wait to check callbacks before removing the listener
295 message_loop_->RunUntilIdle(); 391 message_loop_->RunUntilIdle();
296 vcm_->Unregister(); 392 vcm_->Unregister();
297 } 393 }
298 394
299 } // namespace content 395 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698