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

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

Issue 2350693002: Remove device enumeration, caching and monitoring from MediaStreamManager. (Closed)
Patch Set: latest hta@ comments Created 4 years, 3 months 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
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.cc ('k') | content/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/renderer_host/media/video_capture_manager.h" 7 #include "content/browser/renderer_host/media/video_capture_manager.h"
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 23 matching lines...) Expand all
34 namespace content { 34 namespace content {
35 35
36 // Listener class used to track progress of VideoCaptureManager test. 36 // Listener class used to track progress of VideoCaptureManager test.
37 class MockMediaStreamProviderListener : public MediaStreamProviderListener { 37 class MockMediaStreamProviderListener : public MediaStreamProviderListener {
38 public: 38 public:
39 MockMediaStreamProviderListener() {} 39 MockMediaStreamProviderListener() {}
40 ~MockMediaStreamProviderListener() {} 40 ~MockMediaStreamProviderListener() {}
41 41
42 MOCK_METHOD2(Opened, void(MediaStreamType, int)); 42 MOCK_METHOD2(Opened, void(MediaStreamType, int));
43 MOCK_METHOD2(Closed, void(MediaStreamType, int)); 43 MOCK_METHOD2(Closed, void(MediaStreamType, int));
44 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType,
45 const StreamDeviceInfoArray&));
46 MOCK_METHOD2(Aborted, void(MediaStreamType, int)); 44 MOCK_METHOD2(Aborted, void(MediaStreamType, int));
47 }; // class MockMediaStreamProviderListener 45 }; // class MockMediaStreamProviderListener
48 46
49 // Needed as an input argument to StartCaptureForClient(). 47 // Needed as an input argument to StartCaptureForClient().
50 class MockFrameObserver : public VideoCaptureControllerEventHandler { 48 class MockFrameObserver : public VideoCaptureControllerEventHandler {
51 public: 49 public:
52 MOCK_METHOD1(OnError, void(VideoCaptureControllerID id)); 50 MOCK_METHOD1(OnError, void(VideoCaptureControllerID id));
53 51
54 void OnBufferCreated(VideoCaptureControllerID id, 52 void OnBufferCreated(VideoCaptureControllerID id,
55 base::SharedMemoryHandle handle, 53 base::SharedMemoryHandle handle,
(...skipping 10 matching lines...) Expand all
66 64
67 void OnGotControllerCallback(VideoCaptureControllerID) {} 65 void OnGotControllerCallback(VideoCaptureControllerID) {}
68 }; 66 };
69 67
70 // Test class 68 // Test class
71 class VideoCaptureManagerTest : public testing::Test { 69 class VideoCaptureManagerTest : public testing::Test {
72 public: 70 public:
73 VideoCaptureManagerTest() : next_client_id_(1) {} 71 VideoCaptureManagerTest() : next_client_id_(1) {}
74 ~VideoCaptureManagerTest() override {} 72 ~VideoCaptureManagerTest() override {}
75 73
74 void HandleEnumerationResult(
75 const base::Closure& quit_closure,
76 const media::VideoCaptureDeviceDescriptors& descriptors) {
77 StreamDeviceInfoArray devices;
78 for (const auto& descriptor : descriptors) {
79 devices.emplace_back(MEDIA_DEVICE_VIDEO_CAPTURE,
80 descriptor.GetNameAndModel(), descriptor.device_id);
81 }
82 devices_ = std::move(devices);
83 quit_closure.Run();
84 }
85
76 protected: 86 protected:
77 void SetUp() override { 87 void SetUp() override {
78 listener_.reset(new MockMediaStreamProviderListener()); 88 listener_.reset(new MockMediaStreamProviderListener());
79 message_loop_.reset(new base::MessageLoopForIO); 89 message_loop_.reset(new base::MessageLoopForIO);
80 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, 90 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI,
81 message_loop_.get())); 91 message_loop_.get()));
82 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 92 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
83 message_loop_.get())); 93 message_loop_.get()));
84 vcm_ = new VideoCaptureManager( 94 vcm_ = new VideoCaptureManager(
85 std::unique_ptr<media::VideoCaptureDeviceFactory>( 95 std::unique_ptr<media::VideoCaptureDeviceFactory>(
86 new media::FakeVideoCaptureDeviceFactory())); 96 new media::FakeVideoCaptureDeviceFactory()));
87 video_capture_device_factory_ = 97 video_capture_device_factory_ =
88 static_cast<media::FakeVideoCaptureDeviceFactory*>( 98 static_cast<media::FakeVideoCaptureDeviceFactory*>(
89 vcm_->video_capture_device_factory()); 99 vcm_->video_capture_device_factory());
90 const int32_t kNumberOfFakeDevices = 2; 100 const int32_t kNumberOfFakeDevices = 2;
91 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); 101 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices);
92 vcm_->Register(listener_.get(), message_loop_->task_runner().get()); 102 vcm_->Register(listener_.get(), message_loop_->task_runner().get());
93 frame_observer_.reset(new MockFrameObserver()); 103 frame_observer_.reset(new MockFrameObserver());
104
105 base::RunLoop run_loop;
106 vcm_->EnumerateDevices(
107 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult,
108 base::Unretained(this), run_loop.QuitClosure()));
109 run_loop.Run();
110 ASSERT_GE(devices_.size(), 2u);
94 } 111 }
95 112
96 void TearDown() override {} 113 void TearDown() override {}
97 114
98 void OnGotControllerCallback( 115 void OnGotControllerCallback(
99 VideoCaptureControllerID id, 116 VideoCaptureControllerID id,
100 base::Closure quit_closure, 117 base::Closure quit_closure,
101 bool expect_success, 118 bool expect_success,
102 const base::WeakPtr<VideoCaptureController>& controller) { 119 const base::WeakPtr<VideoCaptureController>& controller) {
103 if (expect_success) { 120 if (expect_success) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 184
168 int next_client_id_; 185 int next_client_id_;
169 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; 186 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_;
170 scoped_refptr<VideoCaptureManager> vcm_; 187 scoped_refptr<VideoCaptureManager> vcm_;
171 std::unique_ptr<MockMediaStreamProviderListener> listener_; 188 std::unique_ptr<MockMediaStreamProviderListener> listener_;
172 std::unique_ptr<base::MessageLoop> message_loop_; 189 std::unique_ptr<base::MessageLoop> message_loop_;
173 std::unique_ptr<BrowserThreadImpl> ui_thread_; 190 std::unique_ptr<BrowserThreadImpl> ui_thread_;
174 std::unique_ptr<BrowserThreadImpl> io_thread_; 191 std::unique_ptr<BrowserThreadImpl> io_thread_;
175 std::unique_ptr<MockFrameObserver> frame_observer_; 192 std::unique_ptr<MockFrameObserver> frame_observer_;
176 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; 193 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_;
194 StreamDeviceInfoArray devices_;
177 195
178 private: 196 private:
179 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); 197 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest);
180 }; 198 };
181 199
182 // Test cases 200 // Test cases
183 201
184 // Try to open, start, stop and close a device. 202 // Try to open, start, stop and close a device.
185 TEST_F(VideoCaptureManagerTest, CreateAndClose) { 203 TEST_F(VideoCaptureManagerTest, CreateAndClose) {
186 StreamDeviceInfoArray devices;
187
188 InSequence s; 204 InSequence s;
189 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
190 .WillOnce(SaveArg<1>(&devices));
191 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 205 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
192 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 206 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
193 207
194 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 208 int video_session_id = vcm_->Open(devices_.front());
195
196 // Wait to get device callback.
197 base::RunLoop().RunUntilIdle();
198
199 int video_session_id = vcm_->Open(devices.front());
200 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 209 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
201 210
202 StopClient(client_id); 211 StopClient(client_id);
203 vcm_->Close(video_session_id); 212 vcm_->Close(video_session_id);
204 213
205 // Wait to check callbacks before removing the listener. 214 // Wait to check callbacks before removing the listener.
206 base::RunLoop().RunUntilIdle(); 215 base::RunLoop().RunUntilIdle();
207 vcm_->Unregister(); 216 vcm_->Unregister();
208 } 217 }
209 218
210 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { 219 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) {
211 StreamDeviceInfoArray devices;
212
213 InSequence s; 220 InSequence s;
214 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
215 .WillOnce(SaveArg<1>(&devices));
216
217 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
218
219 // Wait to get device callback.
220 base::RunLoop().RunUntilIdle();
221
222 for (int i = 1 ; i < 3 ; ++i) { 221 for (int i = 1 ; i < 3 ; ++i) {
223 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i)); 222 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i));
224 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i)); 223 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i));
225 int video_session_id = vcm_->Open(devices.front()); 224 int video_session_id = vcm_->Open(devices_.front());
226 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 225 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
227 226
228 StopClient(client_id); 227 StopClient(client_id);
229 vcm_->Close(video_session_id); 228 vcm_->Close(video_session_id);
230 } 229 }
231 230
232 // Wait to check callbacks before removing the listener. 231 // Wait to check callbacks before removing the listener.
233 base::RunLoop().RunUntilIdle(); 232 base::RunLoop().RunUntilIdle();
234 vcm_->Unregister(); 233 vcm_->Unregister();
235 } 234 }
236 235
237 // Try to open, start, and abort a device. 236 // Try to open, start, and abort a device.
238 TEST_F(VideoCaptureManagerTest, CreateAndAbort) { 237 TEST_F(VideoCaptureManagerTest, CreateAndAbort) {
239 StreamDeviceInfoArray devices;
240
241 InSequence s; 238 InSequence s;
242 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
243 .WillOnce(SaveArg<1>(&devices));
244 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 239 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
245 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 240 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _));
246 241
247 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 242 int video_session_id = vcm_->Open(devices_.front());
248
249 // Wait to get device callback.
250 base::RunLoop().RunUntilIdle();
251
252 int video_session_id = vcm_->Open(devices.front());
253 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 243 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
254 244
255 // Wait for device opened. 245 // Wait for device opened.
256 base::RunLoop().RunUntilIdle(); 246 base::RunLoop().RunUntilIdle();
257 247
258 vcm_->StopCaptureForClient(controllers_[client_id], client_id, 248 vcm_->StopCaptureForClient(controllers_[client_id], client_id,
259 frame_observer_.get(), true); 249 frame_observer_.get(), true);
260 250
261 // Wait to check callbacks before removing the listener. 251 // Wait to check callbacks before removing the listener.
262 base::RunLoop().RunUntilIdle(); 252 base::RunLoop().RunUntilIdle();
263 vcm_->Unregister(); 253 vcm_->Unregister();
264 } 254 }
265 255
266 // Open the same device twice. 256 // Open the same device twice.
267 TEST_F(VideoCaptureManagerTest, OpenTwice) { 257 TEST_F(VideoCaptureManagerTest, OpenTwice) {
268 StreamDeviceInfoArray devices;
269
270 InSequence s; 258 InSequence s;
271 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
272 .WillOnce(SaveArg<1>(&devices));
273 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 259 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
274 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 260 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
275 261
276 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 262 int video_session_id_first = vcm_->Open(devices_.front());
277
278 // Wait to get device callback.
279 base::RunLoop().RunUntilIdle();
280
281 int video_session_id_first = vcm_->Open(devices.front());
282 263
283 // This should trigger an error callback with error code 264 // This should trigger an error callback with error code
284 // 'kDeviceAlreadyInUse'. 265 // 'kDeviceAlreadyInUse'.
285 int video_session_id_second = vcm_->Open(devices.front()); 266 int video_session_id_second = vcm_->Open(devices_.front());
286 EXPECT_NE(video_session_id_first, video_session_id_second); 267 EXPECT_NE(video_session_id_first, video_session_id_second);
287 268
288 vcm_->Close(video_session_id_first); 269 vcm_->Close(video_session_id_first);
289 vcm_->Close(video_session_id_second); 270 vcm_->Close(video_session_id_second);
290 271
291 // Wait to check callbacks before removing the listener. 272 // Wait to check callbacks before removing the listener.
292 base::RunLoop().RunUntilIdle(); 273 base::RunLoop().RunUntilIdle();
293 vcm_->Unregister(); 274 vcm_->Unregister();
294 } 275 }
295 276
296 // Connect and disconnect devices. 277 // Connect and disconnect devices.
297 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { 278 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) {
298 StreamDeviceInfoArray devices;
299 int number_of_devices_keep = 279 int number_of_devices_keep =
300 video_capture_device_factory_->number_of_devices(); 280 video_capture_device_factory_->number_of_devices();
301 281
302 InSequence s;
303 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
304 .WillOnce(SaveArg<1>(&devices));
305 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
306 base::RunLoop().RunUntilIdle();
307 ASSERT_EQ(devices.size(), 2u);
308
309 // Simulate we remove 1 fake device. 282 // Simulate we remove 1 fake device.
310 video_capture_device_factory_->set_number_of_devices(1); 283 video_capture_device_factory_->set_number_of_devices(1);
311 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 284 base::RunLoop run_loop;
312 .WillOnce(SaveArg<1>(&devices)); 285 vcm_->EnumerateDevices(
313 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 286 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult,
314 base::RunLoop().RunUntilIdle(); 287 base::Unretained(this), run_loop.QuitClosure()));
315 ASSERT_EQ(devices.size(), 1u); 288 run_loop.Run();
289 ASSERT_EQ(devices_.size(), 1u);
316 290
317 // Simulate we add 2 fake devices. 291 // Simulate we add 2 fake devices.
318 video_capture_device_factory_->set_number_of_devices(3); 292 video_capture_device_factory_->set_number_of_devices(3);
319 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 293 base::RunLoop run_loop2;
320 .WillOnce(SaveArg<1>(&devices)); 294 vcm_->EnumerateDevices(
321 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 295 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult,
322 base::RunLoop().RunUntilIdle(); 296 base::Unretained(this), run_loop2.QuitClosure()));
323 ASSERT_EQ(devices.size(), 3u); 297 run_loop2.Run();
298 ASSERT_EQ(devices_.size(), 3u);
324 299
325 vcm_->Unregister(); 300 vcm_->Unregister();
326 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); 301 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep);
327 } 302 }
328 303
329 // Enumerate devices and open the first, then check the list of supported 304 // Enumerate devices and open the first, then check the list of supported
330 // formats. Then start the opened device. The capability list should stay the 305 // formats. Then start the opened device. The capability list should stay the
331 // same. Finally stop the device and check that the capabilities stay unchanged. 306 // same. Finally stop the device and check that the capabilities stay unchanged.
332 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { 307 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
333 StreamDeviceInfoArray devices;
334
335 // Before enumerating the devices, requesting formats should return false. 308 // Before enumerating the devices, requesting formats should return false.
336 int video_session_id = 0; 309 int video_session_id = 0;
337 media::VideoCaptureFormats supported_formats; 310 media::VideoCaptureFormats supported_formats;
338 supported_formats.clear(); 311 supported_formats.clear();
339 EXPECT_FALSE( 312 EXPECT_FALSE(
340 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); 313 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats));
341 314
342 InSequence s; 315 InSequence s;
343 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
344 .WillOnce(SaveArg<1>(&devices));
345 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
346 base::RunLoop().RunUntilIdle();
347 ASSERT_GE(devices.size(), 2u);
348
349 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 316 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
350 video_session_id = vcm_->Open(devices.front()); 317 video_session_id = vcm_->Open(devices_.front());
351 base::RunLoop().RunUntilIdle(); 318 base::RunLoop().RunUntilIdle();
352 319
353 // Right after opening the device, we should see all its formats. 320 // Right after opening the device, we should see all its formats.
354 supported_formats.clear(); 321 supported_formats.clear();
355 EXPECT_TRUE( 322 EXPECT_TRUE(
356 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); 323 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats));
357 ASSERT_GT(supported_formats.size(), 1u); 324 ASSERT_GT(supported_formats.size(), 1u);
358 EXPECT_GT(supported_formats[0].frame_size.width(), 1); 325 EXPECT_GT(supported_formats[0].frame_size.width(), 1);
359 EXPECT_GT(supported_formats[0].frame_size.height(), 1); 326 EXPECT_GT(supported_formats[0].frame_size.height(), 1);
360 EXPECT_GT(supported_formats[0].frame_rate, 1); 327 EXPECT_GT(supported_formats[0].frame_rate, 1);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 base::RunLoop().RunUntilIdle(); 360 base::RunLoop().RunUntilIdle();
394 vcm_->Unregister(); 361 vcm_->Unregister();
395 } 362 }
396 363
397 // Enumerate devices and open the first, then check the formats currently in 364 // Enumerate devices and open the first, then check the formats currently in
398 // use, which should be an empty vector. Then start the opened device. The 365 // use, which should be an empty vector. Then start the opened device. The
399 // format(s) in use should be just one format (the one used when configuring- 366 // format(s) in use should be just one format (the one used when configuring-
400 // starting the device). Finally stop the device and check that the formats in 367 // starting the device). Finally stop the device and check that the formats in
401 // use is an empty vector. 368 // use is an empty vector.
402 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { 369 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) {
403 StreamDeviceInfoArray devices;
404
405 InSequence s; 370 InSequence s;
406 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
407 .WillOnce(SaveArg<1>(&devices));
408 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
409 base::RunLoop().RunUntilIdle();
410 ASSERT_GE(devices.size(), 2u);
411
412 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 371 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
413 int video_session_id = vcm_->Open(devices.front()); 372 int video_session_id = vcm_->Open(devices_.front());
414 base::RunLoop().RunUntilIdle(); 373 base::RunLoop().RunUntilIdle();
415 374
416 // Right after opening the device, we should see no format in use. 375 // Right after opening the device, we should see no format in use.
417 media::VideoCaptureFormats formats_in_use; 376 media::VideoCaptureFormats formats_in_use;
418 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); 377 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use));
419 EXPECT_TRUE(formats_in_use.empty()); 378 EXPECT_TRUE(formats_in_use.empty());
420 379
421 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 380 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
422 base::RunLoop().RunUntilIdle(); 381 base::RunLoop().RunUntilIdle();
423 // After StartClient(), |formats_in_use| should contain one valid format. 382 // After StartClient(), |formats_in_use| should contain one valid format.
(...skipping 15 matching lines...) Expand all
439 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); 398 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use));
440 EXPECT_TRUE(formats_in_use.empty()); 399 EXPECT_TRUE(formats_in_use.empty());
441 400
442 vcm_->Close(video_session_id); 401 vcm_->Close(video_session_id);
443 base::RunLoop().RunUntilIdle(); 402 base::RunLoop().RunUntilIdle();
444 vcm_->Unregister(); 403 vcm_->Unregister();
445 } 404 }
446 405
447 // Open two different devices. 406 // Open two different devices.
448 TEST_F(VideoCaptureManagerTest, OpenTwo) { 407 TEST_F(VideoCaptureManagerTest, OpenTwo) {
449 StreamDeviceInfoArray devices;
450
451 InSequence s; 408 InSequence s;
452 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
453 .WillOnce(SaveArg<1>(&devices));
454 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 409 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
455 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 410 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
456 411
457 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 412 StreamDeviceInfoArray::iterator it = devices_.begin();
458
459 // Wait to get device callback.
460 base::RunLoop().RunUntilIdle();
461
462 StreamDeviceInfoArray::iterator it = devices.begin();
463 413
464 int video_session_id_first = vcm_->Open(*it); 414 int video_session_id_first = vcm_->Open(*it);
465 ++it; 415 ++it;
466 int video_session_id_second = vcm_->Open(*it); 416 int video_session_id_second = vcm_->Open(*it);
467 417
468 vcm_->Close(video_session_id_first); 418 vcm_->Close(video_session_id_first);
469 vcm_->Close(video_session_id_second); 419 vcm_->Close(video_session_id_second);
470 420
471 // Wait to check callbacks before removing the listener. 421 // Wait to check callbacks before removing the listener.
472 base::RunLoop().RunUntilIdle(); 422 base::RunLoop().RunUntilIdle();
473 vcm_->Unregister(); 423 vcm_->Unregister();
474 } 424 }
475 425
476 // Try open a non-existing device. 426 // Try open a non-existing device.
477 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { 427 TEST_F(VideoCaptureManagerTest, OpenNotExisting) {
478 StreamDeviceInfoArray devices;
479
480 InSequence s; 428 InSequence s;
481 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
482 .WillOnce(SaveArg<1>(&devices));
483 EXPECT_CALL(*frame_observer_, OnError(_)); 429 EXPECT_CALL(*frame_observer_, OnError(_));
484 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 430 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
485 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 431 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
486 432
487 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
488
489 // Wait to get device callback.
490 base::RunLoop().RunUntilIdle();
491
492 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; 433 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE;
493 std::string device_name("device_doesnt_exist"); 434 std::string device_name("device_doesnt_exist");
494 std::string device_id("id_doesnt_exist"); 435 std::string device_id("id_doesnt_exist");
495 StreamDeviceInfo dummy_device(stream_type, device_name, device_id); 436 StreamDeviceInfo dummy_device(stream_type, device_name, device_id);
496 437
497 // This should fail with an error to the controller. 438 // This should fail with an error to the controller.
498 int session_id = vcm_->Open(dummy_device); 439 int session_id = vcm_->Open(dummy_device);
499 VideoCaptureControllerID client_id = StartClient(session_id, true); 440 VideoCaptureControllerID client_id = StartClient(session_id, true);
500 base::RunLoop().RunUntilIdle(); 441 base::RunLoop().RunUntilIdle();
501 442
502 StopClient(client_id); 443 StopClient(client_id);
503 vcm_->Close(session_id); 444 vcm_->Close(session_id);
504 base::RunLoop().RunUntilIdle(); 445 base::RunLoop().RunUntilIdle();
505 446
506 vcm_->Unregister(); 447 vcm_->Unregister();
507 } 448 }
508 449
509 // Start a device without calling Open, using a non-magic ID. 450 // Start a device without calling Open, using a non-magic ID.
510 TEST_F(VideoCaptureManagerTest, StartInvalidSession) { 451 TEST_F(VideoCaptureManagerTest, StartInvalidSession) {
511 StartClient(22, false); 452 StartClient(22, false);
512 453
513 // Wait to check callbacks before removing the listener. 454 // Wait to check callbacks before removing the listener.
514 base::RunLoop().RunUntilIdle(); 455 base::RunLoop().RunUntilIdle();
515 vcm_->Unregister(); 456 vcm_->Unregister();
516 } 457 }
517 458
518 // Open and start a device, close it before calling Stop. 459 // Open and start a device, close it before calling Stop.
519 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { 460 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) {
520 StreamDeviceInfoArray devices;
521 base::RunLoop run_loop;
522
523 InSequence s; 461 InSequence s;
524 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
525 .WillOnce(
526 DoAll(SaveArg<1>(&devices),
527 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)));
528 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 462 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
529 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 463 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
530 464
531 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 465 int video_session_id = vcm_->Open(devices_.front());
532
533 // Wait to get device callback.
534 run_loop.Run();
535 ASSERT_FALSE(devices.empty());
536 int video_session_id = vcm_->Open(devices.front());
537 466
538 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 467 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
539 468
540 // Close will stop the running device, an assert will be triggered in 469 // Close will stop the running device, an assert will be triggered in
541 // VideoCaptureManager destructor otherwise. 470 // VideoCaptureManager destructor otherwise.
542 vcm_->Close(video_session_id); 471 vcm_->Close(video_session_id);
543 StopClient(client_id); 472 StopClient(client_id);
544 473
545 // Wait to check callbacks before removing the listener 474 // Wait to check callbacks before removing the listener
546 base::RunLoop().RunUntilIdle(); 475 base::RunLoop().RunUntilIdle();
547 vcm_->Unregister(); 476 vcm_->Unregister();
548 } 477 }
549 478
550 // Try to open, start, pause and resume a device. 479 // Try to open, start, pause and resume a device.
551 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { 480 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) {
552 StreamDeviceInfoArray devices;
553
554 InSequence s; 481 InSequence s;
555 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
556 .WillOnce(SaveArg<1>(&devices));
557 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 482 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
558 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 483 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
559 484
560 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 485 int video_session_id = vcm_->Open(devices_.front());
561
562 // Wait to get device callback.
563 base::RunLoop().RunUntilIdle();
564
565 int video_session_id = vcm_->Open(devices.front());
566 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 486 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
567 487
568 // Resume client a second time should cause no problem. 488 // Resume client a second time should cause no problem.
569 PauseClient(client_id); 489 PauseClient(client_id);
570 ResumeClient(video_session_id, client_id); 490 ResumeClient(video_session_id, client_id);
571 ResumeClient(video_session_id, client_id); 491 ResumeClient(video_session_id, client_id);
572 492
573 StopClient(client_id); 493 StopClient(client_id);
574 vcm_->Close(video_session_id); 494 vcm_->Close(video_session_id);
575 495
576 // Wait to check callbacks before removing the listener. 496 // Wait to check callbacks before removing the listener.
577 base::RunLoop().RunUntilIdle(); 497 base::RunLoop().RunUntilIdle();
578 vcm_->Unregister(); 498 vcm_->Unregister();
579 } 499 }
580 500
581 #if defined(OS_ANDROID) 501 #if defined(OS_ANDROID)
582 // Try to open, start, pause and resume a device. 502 // Try to open, start, pause and resume a device.
583 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) { 503 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) {
584 StreamDeviceInfoArray devices;
585
586 InSequence s; 504 InSequence s;
587 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
588 .WillOnce(SaveArg<1>(&devices));
589 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 505 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
590 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); 506 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _));
591 507
592 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 508 int video_session_id = vcm_->Open(devices_.front());
593
594 // Wait to get device callback.
595 base::RunLoop().RunUntilIdle();
596
597 int video_session_id = vcm_->Open(devices.front());
598 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 509 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
599 510
600 // Release/ResumeDevices according to ApplicationStatus. Should cause no 511 // Release/ResumeDevices according to ApplicationStatus. Should cause no
601 // problem in any order. Check https://crbug.com/615557 for more details. 512 // problem in any order. Check https://crbug.com/615557 for more details.
602 ApplicationStateChange( 513 ApplicationStateChange(
603 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); 514 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
604 ApplicationStateChange( 515 ApplicationStateChange(
605 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); 516 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES);
606 ApplicationStateChange( 517 ApplicationStateChange(
607 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); 518 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES);
608 ApplicationStateChange( 519 ApplicationStateChange(
609 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); 520 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
610 ApplicationStateChange( 521 ApplicationStateChange(
611 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); 522 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
612 523
613 StopClient(client_id); 524 StopClient(client_id);
614 vcm_->Close(video_session_id); 525 vcm_->Close(video_session_id);
615 526
616 // Wait to check callbacks before removing the listener. 527 // Wait to check callbacks before removing the listener.
617 base::RunLoop().RunUntilIdle(); 528 base::RunLoop().RunUntilIdle();
618 vcm_->Unregister(); 529 vcm_->Unregister();
619 } 530 }
620 #endif 531 #endif
621 532
622 // TODO(mcasas): Add a test to check consolidation of the supported formats 533 // TODO(mcasas): Add a test to check consolidation of the supported formats
623 // provided by the device when http://crbug.com/323913 is closed. 534 // provided by the device when http://crbug.com/323913 is closed.
624 535
625 } // namespace content 536 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.cc ('k') | content/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698