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

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: perkj@ nits 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 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
239 StreamDeviceInfoArray devices;
240
241 InSequence s;
242 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
243 .Times(1).WillOnce(SaveArg<1>(&devices));
244 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
245 message_loop_->RunUntilIdle();
246
247 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
248 int video_session_id = vcm_->Open(devices.front());
249 message_loop_->RunUntilIdle();
250
251 // When the device has been opened, we should see all the devices'
252 // supported formats.
253 media::VideoCaptureFormats supported_formats;
254 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
255 ASSERT_EQ(devices.size(), 2u);
256 ASSERT_GT(supported_formats.size(), 1u);
257 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
258 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
259 EXPECT_GT(supported_formats[0].frame_rate, 1);
260 EXPECT_GT(supported_formats[1].frame_size.width(), 1);
261 EXPECT_GT(supported_formats[1].frame_size.height(), 1);
262 EXPECT_GT(supported_formats[1].frame_rate, 1);
263
264 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
265 message_loop_->RunUntilIdle();
266 // After StartClient(), device's supported formats should be reduced to one.
267 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
268 ASSERT_EQ(supported_formats.size(), 1u);
269 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
270 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
271 EXPECT_GT(supported_formats[0].frame_rate, 1);
272
273 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
274 StopClient(client_id);
275 // After StopClient(), the device's list of supported formats should be
276 // restored to the original one.
277 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats);
278 ASSERT_GT(supported_formats.size(), 1u);
279 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
280 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
281 EXPECT_GT(supported_formats[0].frame_rate, 1);
282 EXPECT_GT(supported_formats[1].frame_size.width(), 1);
283 EXPECT_GT(supported_formats[1].frame_size.height(), 1);
284 EXPECT_GT(supported_formats[1].frame_rate, 1);
285
286 vcm_->Close(video_session_id);
287 message_loop_->RunUntilIdle();
288 vcm_->Unregister();
289 }
290
199 // Open two different devices. 291 // Open two different devices.
200 TEST_F(VideoCaptureManagerTest, OpenTwo) { 292 TEST_F(VideoCaptureManagerTest, OpenTwo) {
201 StreamDeviceInfoArray devices; 293 StreamDeviceInfoArray devices;
202 294
203 InSequence s; 295 InSequence s;
204 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 296 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
205 .Times(1).WillOnce(SaveArg<1>(&devices)); 297 .Times(1).WillOnce(SaveArg<1>(&devices));
206 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 298 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
207 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 299 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
208 300
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // VideoCaptureManager destructor otherwise. 382 // VideoCaptureManager destructor otherwise.
291 vcm_->Close(video_session_id); 383 vcm_->Close(video_session_id);
292 StopClient(client_id); 384 StopClient(client_id);
293 385
294 // Wait to check callbacks before removing the listener 386 // Wait to check callbacks before removing the listener
295 message_loop_->RunUntilIdle(); 387 message_loop_->RunUntilIdle();
296 vcm_->Unregister(); 388 vcm_->Unregister();
297 } 389 }
298 390
299 } // namespace content 391 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.cc ('k') | content/common/media/video_capture_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698