| 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 "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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 168 } |
| 169 devices_ = std::move(devices); | 169 devices_ = std::move(devices); |
| 170 quit_closure.Run(); | 170 quit_closure.Run(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 protected: | 173 protected: |
| 174 void SetUp() override { | 174 void SetUp() override { |
| 175 listener_.reset(new MockMediaStreamProviderListener()); | 175 listener_.reset(new MockMediaStreamProviderListener()); |
| 176 vcm_ = new VideoCaptureManager( | 176 vcm_ = new VideoCaptureManager( |
| 177 std::unique_ptr<media::VideoCaptureDeviceFactory>( | 177 std::unique_ptr<media::VideoCaptureDeviceFactory>( |
| 178 new WrappedDeviceFactory())); | 178 new WrappedDeviceFactory()), |
| 179 base::ThreadTaskRunnerHandle::Get()); |
| 179 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( | 180 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( |
| 180 vcm_->video_capture_device_factory()); | 181 vcm_->video_capture_device_factory()); |
| 181 const int32_t kNumberOfFakeDevices = 2; | 182 const int32_t kNumberOfFakeDevices = 2; |
| 182 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); | 183 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); |
| 183 vcm_->Register(listener_.get(), base::ThreadTaskRunnerHandle::Get()); | 184 vcm_->RegisterListener(listener_.get()); |
| 184 frame_observer_.reset(new MockFrameObserver()); | 185 frame_observer_.reset(new MockFrameObserver()); |
| 185 | 186 |
| 186 base::RunLoop run_loop; | 187 base::RunLoop run_loop; |
| 187 vcm_->EnumerateDevices( | 188 vcm_->EnumerateDevices( |
| 188 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 189 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
| 189 base::Unretained(this), run_loop.QuitClosure())); | 190 base::Unretained(this), run_loop.QuitClosure())); |
| 190 run_loop.Run(); | 191 run_loop.Run(); |
| 191 ASSERT_GE(devices_.size(), 2u); | 192 ASSERT_GE(devices_.size(), 2u); |
| 192 } | 193 } |
| 193 | 194 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 284 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 284 | 285 |
| 285 int video_session_id = vcm_->Open(devices_.front()); | 286 int video_session_id = vcm_->Open(devices_.front()); |
| 286 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 287 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 287 | 288 |
| 288 StopClient(client_id); | 289 StopClient(client_id); |
| 289 vcm_->Close(video_session_id); | 290 vcm_->Close(video_session_id); |
| 290 | 291 |
| 291 // Wait to check callbacks before removing the listener. | 292 // Wait to check callbacks before removing the listener. |
| 292 base::RunLoop().RunUntilIdle(); | 293 base::RunLoop().RunUntilIdle(); |
| 293 vcm_->Unregister(); | 294 vcm_->UnregisterListener(); |
| 294 } | 295 } |
| 295 | 296 |
| 296 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { | 297 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { |
| 297 InSequence s; | 298 InSequence s; |
| 298 for (int i = 1 ; i < 3 ; ++i) { | 299 for (int i = 1 ; i < 3 ; ++i) { |
| 299 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i)); | 300 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i)); |
| 300 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i)); | 301 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i)); |
| 301 int video_session_id = vcm_->Open(devices_.front()); | 302 int video_session_id = vcm_->Open(devices_.front()); |
| 302 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 303 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 303 | 304 |
| 304 StopClient(client_id); | 305 StopClient(client_id); |
| 305 vcm_->Close(video_session_id); | 306 vcm_->Close(video_session_id); |
| 306 } | 307 } |
| 307 | 308 |
| 308 // Wait to check callbacks before removing the listener. | 309 // Wait to check callbacks before removing the listener. |
| 309 base::RunLoop().RunUntilIdle(); | 310 base::RunLoop().RunUntilIdle(); |
| 310 vcm_->Unregister(); | 311 vcm_->UnregisterListener(); |
| 311 } | 312 } |
| 312 | 313 |
| 313 // Try to open, start, and abort a device. | 314 // Try to open, start, and abort a device. |
| 314 TEST_F(VideoCaptureManagerTest, CreateAndAbort) { | 315 TEST_F(VideoCaptureManagerTest, CreateAndAbort) { |
| 315 InSequence s; | 316 InSequence s; |
| 316 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 317 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 317 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 318 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 318 | 319 |
| 319 int video_session_id = vcm_->Open(devices_.front()); | 320 int video_session_id = vcm_->Open(devices_.front()); |
| 320 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 321 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 321 | 322 |
| 322 // Wait for device opened. | 323 // Wait for device opened. |
| 323 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
| 324 | 325 |
| 325 vcm_->StopCaptureForClient(controllers_[client_id], client_id, | 326 vcm_->StopCaptureForClient(controllers_[client_id], client_id, |
| 326 frame_observer_.get(), true); | 327 frame_observer_.get(), true); |
| 327 | 328 |
| 328 // Wait to check callbacks before removing the listener. | 329 // Wait to check callbacks before removing the listener. |
| 329 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
| 330 vcm_->Unregister(); | 331 vcm_->UnregisterListener(); |
| 331 } | 332 } |
| 332 | 333 |
| 333 // Open the same device twice. | 334 // Open the same device twice. |
| 334 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 335 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
| 335 InSequence s; | 336 InSequence s; |
| 336 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 337 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 337 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 338 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 338 | 339 |
| 339 int video_session_id_first = vcm_->Open(devices_.front()); | 340 int video_session_id_first = vcm_->Open(devices_.front()); |
| 340 | 341 |
| 341 // This should trigger an error callback with error code | 342 // This should trigger an error callback with error code |
| 342 // 'kDeviceAlreadyInUse'. | 343 // 'kDeviceAlreadyInUse'. |
| 343 int video_session_id_second = vcm_->Open(devices_.front()); | 344 int video_session_id_second = vcm_->Open(devices_.front()); |
| 344 EXPECT_NE(video_session_id_first, video_session_id_second); | 345 EXPECT_NE(video_session_id_first, video_session_id_second); |
| 345 | 346 |
| 346 vcm_->Close(video_session_id_first); | 347 vcm_->Close(video_session_id_first); |
| 347 vcm_->Close(video_session_id_second); | 348 vcm_->Close(video_session_id_second); |
| 348 | 349 |
| 349 // Wait to check callbacks before removing the listener. | 350 // Wait to check callbacks before removing the listener. |
| 350 base::RunLoop().RunUntilIdle(); | 351 base::RunLoop().RunUntilIdle(); |
| 351 vcm_->Unregister(); | 352 vcm_->UnregisterListener(); |
| 352 } | 353 } |
| 353 | 354 |
| 354 // Connect and disconnect devices. | 355 // Connect and disconnect devices. |
| 355 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { | 356 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
| 356 int number_of_devices_keep = | 357 int number_of_devices_keep = |
| 357 video_capture_device_factory_->number_of_devices(); | 358 video_capture_device_factory_->number_of_devices(); |
| 358 | 359 |
| 359 // Simulate we remove 1 fake device. | 360 // Simulate we remove 1 fake device. |
| 360 video_capture_device_factory_->set_number_of_devices(1); | 361 video_capture_device_factory_->set_number_of_devices(1); |
| 361 base::RunLoop run_loop; | 362 base::RunLoop run_loop; |
| 362 vcm_->EnumerateDevices( | 363 vcm_->EnumerateDevices( |
| 363 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 364 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
| 364 base::Unretained(this), run_loop.QuitClosure())); | 365 base::Unretained(this), run_loop.QuitClosure())); |
| 365 run_loop.Run(); | 366 run_loop.Run(); |
| 366 ASSERT_EQ(devices_.size(), 1u); | 367 ASSERT_EQ(devices_.size(), 1u); |
| 367 | 368 |
| 368 // Simulate we add 2 fake devices. | 369 // Simulate we add 2 fake devices. |
| 369 video_capture_device_factory_->set_number_of_devices(3); | 370 video_capture_device_factory_->set_number_of_devices(3); |
| 370 base::RunLoop run_loop2; | 371 base::RunLoop run_loop2; |
| 371 vcm_->EnumerateDevices( | 372 vcm_->EnumerateDevices( |
| 372 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 373 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
| 373 base::Unretained(this), run_loop2.QuitClosure())); | 374 base::Unretained(this), run_loop2.QuitClosure())); |
| 374 run_loop2.Run(); | 375 run_loop2.Run(); |
| 375 ASSERT_EQ(devices_.size(), 3u); | 376 ASSERT_EQ(devices_.size(), 3u); |
| 376 | 377 |
| 377 vcm_->Unregister(); | 378 vcm_->UnregisterListener(); |
| 378 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); | 379 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); |
| 379 } | 380 } |
| 380 | 381 |
| 381 // Enumerate devices and open the first, then check the list of supported | 382 // Enumerate devices and open the first, then check the list of supported |
| 382 // formats. Then start the opened device. The capability list should stay the | 383 // formats. Then start the opened device. The capability list should stay the |
| 383 // same. Finally stop the device and check that the capabilities stay unchanged. | 384 // same. Finally stop the device and check that the capabilities stay unchanged. |
| 384 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { | 385 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
| 385 // Before enumerating the devices, requesting formats should return false. | 386 // Before enumerating the devices, requesting formats should return false. |
| 386 int video_session_id = 0; | 387 int video_session_id = 0; |
| 387 media::VideoCaptureFormats supported_formats; | 388 media::VideoCaptureFormats supported_formats; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 ASSERT_GE(supported_formats.size(), 2u); | 429 ASSERT_GE(supported_formats.size(), 2u); |
| 429 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 430 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 430 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 431 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 431 EXPECT_GT(supported_formats[0].frame_rate, 1); | 432 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 432 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 433 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 433 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 434 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 434 EXPECT_GT(supported_formats[1].frame_rate, 1); | 435 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 435 | 436 |
| 436 vcm_->Close(video_session_id); | 437 vcm_->Close(video_session_id); |
| 437 base::RunLoop().RunUntilIdle(); | 438 base::RunLoop().RunUntilIdle(); |
| 438 vcm_->Unregister(); | 439 vcm_->UnregisterListener(); |
| 439 } | 440 } |
| 440 | 441 |
| 441 // Enumerate devices, then check the list of supported formats. Then open and | 442 // Enumerate devices, then check the list of supported formats. Then open and |
| 442 // start the first device. The capability list should stay the same. Finally | 443 // start the first device. The capability list should stay the same. Finally |
| 443 // stop the device and check that the capabilities stay unchanged. | 444 // stop the device and check that the capabilities stay unchanged. |
| 444 TEST_F(VideoCaptureManagerTest, | 445 TEST_F(VideoCaptureManagerTest, |
| 445 ManipulateDeviceAndCheckCapabilitiesWithDeviceId) { | 446 ManipulateDeviceAndCheckCapabilitiesWithDeviceId) { |
| 446 // Requesting formats should work even before enumerating/opening devices. | 447 // Requesting formats should work even before enumerating/opening devices. |
| 447 std::string device_id = devices_.front().device.id; | 448 std::string device_id = devices_.front().device.id; |
| 448 media::VideoCaptureFormats supported_formats; | 449 media::VideoCaptureFormats supported_formats; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 ASSERT_GE(supported_formats.size(), 2u); | 493 ASSERT_GE(supported_formats.size(), 2u); |
| 493 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 494 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 494 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 495 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 495 EXPECT_GT(supported_formats[0].frame_rate, 1); | 496 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 496 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 497 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 497 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 498 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 498 EXPECT_GT(supported_formats[1].frame_rate, 1); | 499 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 499 | 500 |
| 500 vcm_->Close(video_session_id); | 501 vcm_->Close(video_session_id); |
| 501 base::RunLoop().RunUntilIdle(); | 502 base::RunLoop().RunUntilIdle(); |
| 502 vcm_->Unregister(); | 503 vcm_->UnregisterListener(); |
| 503 } | 504 } |
| 504 | 505 |
| 505 // Enumerate devices and open the first, then check the formats currently in | 506 // Enumerate devices and open the first, then check the formats currently in |
| 506 // use, which should be an empty vector. Then start the opened device. The | 507 // use, which should be an empty vector. Then start the opened device. The |
| 507 // format(s) in use should be just one format (the one used when configuring- | 508 // format(s) in use should be just one format (the one used when configuring- |
| 508 // starting the device). Finally stop the device and check that the formats in | 509 // starting the device). Finally stop the device and check that the formats in |
| 509 // use is an empty vector. | 510 // use is an empty vector. |
| 510 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { | 511 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { |
| 511 InSequence s; | 512 InSequence s; |
| 512 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 513 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 534 | 535 |
| 535 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 536 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 536 StopClient(client_id); | 537 StopClient(client_id); |
| 537 base::RunLoop().RunUntilIdle(); | 538 base::RunLoop().RunUntilIdle(); |
| 538 // After StopClient(), the device's formats in use should be empty again. | 539 // After StopClient(), the device's formats in use should be empty again. |
| 539 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); | 540 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); |
| 540 EXPECT_TRUE(formats_in_use.empty()); | 541 EXPECT_TRUE(formats_in_use.empty()); |
| 541 | 542 |
| 542 vcm_->Close(video_session_id); | 543 vcm_->Close(video_session_id); |
| 543 base::RunLoop().RunUntilIdle(); | 544 base::RunLoop().RunUntilIdle(); |
| 544 vcm_->Unregister(); | 545 vcm_->UnregisterListener(); |
| 545 } | 546 } |
| 546 | 547 |
| 547 // Enumerate devices and open the first, then check the formats currently in | 548 // Enumerate devices and open the first, then check the formats currently in |
| 548 // use, which should be an empty vector. Then start the opened device. The | 549 // use, which should be an empty vector. Then start the opened device. The |
| 549 // format(s) in use should be just one format (the one used when configuring- | 550 // format(s) in use should be just one format (the one used when configuring- |
| 550 // starting the device). Finally stop the device and check that the formats in | 551 // starting the device). Finally stop the device and check that the formats in |
| 551 // use is an empty vector. | 552 // use is an empty vector. |
| 552 TEST_F(VideoCaptureManagerTest, | 553 TEST_F(VideoCaptureManagerTest, |
| 553 StartDeviceAndGetDeviceFormatInUseWithDeviceId) { | 554 StartDeviceAndGetDeviceFormatInUseWithDeviceId) { |
| 554 std::string device_id = devices_.front().device.id; | 555 std::string device_id = devices_.front().device.id; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 581 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 582 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 582 StopClient(client_id); | 583 StopClient(client_id); |
| 583 base::RunLoop().RunUntilIdle(); | 584 base::RunLoop().RunUntilIdle(); |
| 584 // After StopClient(), the device's formats in use should be empty again. | 585 // After StopClient(), the device's formats in use should be empty again. |
| 585 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, | 586 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, |
| 586 &formats_in_use)); | 587 &formats_in_use)); |
| 587 EXPECT_TRUE(formats_in_use.empty()); | 588 EXPECT_TRUE(formats_in_use.empty()); |
| 588 | 589 |
| 589 vcm_->Close(video_session_id); | 590 vcm_->Close(video_session_id); |
| 590 base::RunLoop().RunUntilIdle(); | 591 base::RunLoop().RunUntilIdle(); |
| 591 vcm_->Unregister(); | 592 vcm_->UnregisterListener(); |
| 592 } | 593 } |
| 593 | 594 |
| 594 // Open two different devices. | 595 // Open two different devices. |
| 595 TEST_F(VideoCaptureManagerTest, OpenTwo) { | 596 TEST_F(VideoCaptureManagerTest, OpenTwo) { |
| 596 InSequence s; | 597 InSequence s; |
| 597 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 598 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 598 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 599 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 599 | 600 |
| 600 StreamDeviceInfoArray::iterator it = devices_.begin(); | 601 StreamDeviceInfoArray::iterator it = devices_.begin(); |
| 601 | 602 |
| 602 int video_session_id_first = vcm_->Open(*it); | 603 int video_session_id_first = vcm_->Open(*it); |
| 603 ++it; | 604 ++it; |
| 604 int video_session_id_second = vcm_->Open(*it); | 605 int video_session_id_second = vcm_->Open(*it); |
| 605 | 606 |
| 606 vcm_->Close(video_session_id_first); | 607 vcm_->Close(video_session_id_first); |
| 607 vcm_->Close(video_session_id_second); | 608 vcm_->Close(video_session_id_second); |
| 608 | 609 |
| 609 // Wait to check callbacks before removing the listener. | 610 // Wait to check callbacks before removing the listener. |
| 610 base::RunLoop().RunUntilIdle(); | 611 base::RunLoop().RunUntilIdle(); |
| 611 vcm_->Unregister(); | 612 vcm_->UnregisterListener(); |
| 612 } | 613 } |
| 613 | 614 |
| 614 // Try open a non-existing device. | 615 // Try open a non-existing device. |
| 615 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { | 616 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { |
| 616 InSequence s; | 617 InSequence s; |
| 617 EXPECT_CALL(*frame_observer_, OnError(_)); | 618 EXPECT_CALL(*frame_observer_, OnError(_)); |
| 618 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 619 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 619 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 620 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 620 | 621 |
| 621 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; | 622 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 622 std::string device_name("device_doesnt_exist"); | 623 std::string device_name("device_doesnt_exist"); |
| 623 std::string device_id("id_doesnt_exist"); | 624 std::string device_id("id_doesnt_exist"); |
| 624 StreamDeviceInfo dummy_device(stream_type, device_name, device_id); | 625 StreamDeviceInfo dummy_device(stream_type, device_name, device_id); |
| 625 | 626 |
| 626 // This should fail with an error to the controller. | 627 // This should fail with an error to the controller. |
| 627 int session_id = vcm_->Open(dummy_device); | 628 int session_id = vcm_->Open(dummy_device); |
| 628 VideoCaptureControllerID client_id = StartClient(session_id, true); | 629 VideoCaptureControllerID client_id = StartClient(session_id, true); |
| 629 base::RunLoop().RunUntilIdle(); | 630 base::RunLoop().RunUntilIdle(); |
| 630 | 631 |
| 631 StopClient(client_id); | 632 StopClient(client_id); |
| 632 vcm_->Close(session_id); | 633 vcm_->Close(session_id); |
| 633 base::RunLoop().RunUntilIdle(); | 634 base::RunLoop().RunUntilIdle(); |
| 634 | 635 |
| 635 vcm_->Unregister(); | 636 vcm_->UnregisterListener(); |
| 636 } | 637 } |
| 637 | 638 |
| 638 // Start a device without calling Open, using a non-magic ID. | 639 // Start a device without calling Open, using a non-magic ID. |
| 639 TEST_F(VideoCaptureManagerTest, StartInvalidSession) { | 640 TEST_F(VideoCaptureManagerTest, StartInvalidSession) { |
| 640 StartClient(22, false); | 641 StartClient(22, false); |
| 641 | 642 |
| 642 // Wait to check callbacks before removing the listener. | 643 // Wait to check callbacks before removing the listener. |
| 643 base::RunLoop().RunUntilIdle(); | 644 base::RunLoop().RunUntilIdle(); |
| 644 vcm_->Unregister(); | 645 vcm_->UnregisterListener(); |
| 645 } | 646 } |
| 646 | 647 |
| 647 // Open and start a device, close it before calling Stop. | 648 // Open and start a device, close it before calling Stop. |
| 648 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { | 649 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { |
| 649 InSequence s; | 650 InSequence s; |
| 650 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 651 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 651 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 652 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 652 | 653 |
| 653 int video_session_id = vcm_->Open(devices_.front()); | 654 int video_session_id = vcm_->Open(devices_.front()); |
| 654 | 655 |
| 655 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 656 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 656 | 657 |
| 657 // Close will stop the running device, an assert will be triggered in | 658 // Close will stop the running device, an assert will be triggered in |
| 658 // VideoCaptureManager destructor otherwise. | 659 // VideoCaptureManager destructor otherwise. |
| 659 vcm_->Close(video_session_id); | 660 vcm_->Close(video_session_id); |
| 660 StopClient(client_id); | 661 StopClient(client_id); |
| 661 | 662 |
| 662 // Wait to check callbacks before removing the listener | 663 // Wait to check callbacks before removing the listener |
| 663 base::RunLoop().RunUntilIdle(); | 664 base::RunLoop().RunUntilIdle(); |
| 664 vcm_->Unregister(); | 665 vcm_->UnregisterListener(); |
| 665 } | 666 } |
| 666 | 667 |
| 667 // Try to open, start, pause and resume a device. Confirm the device is | 668 // Try to open, start, pause and resume a device. Confirm the device is |
| 668 // paused/resumed at the correct times in both single-client and multiple-client | 669 // paused/resumed at the correct times in both single-client and multiple-client |
| 669 // scenarios. | 670 // scenarios. |
| 670 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { | 671 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { |
| 671 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 672 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 672 | 673 |
| 673 const int video_session_id = vcm_->Open(devices_.front()); | 674 const int video_session_id = vcm_->Open(devices_.front()); |
| 674 const VideoCaptureControllerID client_id = | 675 const VideoCaptureControllerID client_id = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 693 ResumeClient(video_session_id, client_id); | 694 ResumeClient(video_session_id, client_id); |
| 694 | 695 |
| 695 StopClient(client_id); | 696 StopClient(client_id); |
| 696 StopClient(client_id2); | 697 StopClient(client_id2); |
| 697 | 698 |
| 698 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 699 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 699 vcm_->Close(video_session_id); | 700 vcm_->Close(video_session_id); |
| 700 | 701 |
| 701 // Wait to check callbacks before removing the listener. | 702 // Wait to check callbacks before removing the listener. |
| 702 base::RunLoop().RunUntilIdle(); | 703 base::RunLoop().RunUntilIdle(); |
| 703 vcm_->Unregister(); | 704 vcm_->UnregisterListener(); |
| 704 } | 705 } |
| 705 | 706 |
| 706 #if defined(OS_ANDROID) | 707 #if defined(OS_ANDROID) |
| 707 // Try to open, start, pause and resume a device. | 708 // Try to open, start, pause and resume a device. |
| 708 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) { | 709 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) { |
| 709 InSequence s; | 710 InSequence s; |
| 710 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 711 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 711 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 712 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 712 | 713 |
| 713 int video_session_id = vcm_->Open(devices_.front()); | 714 int video_session_id = vcm_->Open(devices_.front()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 724 ApplicationStateChange( | 725 ApplicationStateChange( |
| 725 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 726 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 726 ApplicationStateChange( | 727 ApplicationStateChange( |
| 727 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 728 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 728 | 729 |
| 729 StopClient(client_id); | 730 StopClient(client_id); |
| 730 vcm_->Close(video_session_id); | 731 vcm_->Close(video_session_id); |
| 731 | 732 |
| 732 // Wait to check callbacks before removing the listener. | 733 // Wait to check callbacks before removing the listener. |
| 733 base::RunLoop().RunUntilIdle(); | 734 base::RunLoop().RunUntilIdle(); |
| 734 vcm_->Unregister(); | 735 vcm_->UnregisterListener(); |
| 735 } | 736 } |
| 736 #endif | 737 #endif |
| 737 | 738 |
| 738 // TODO(mcasas): Add a test to check consolidation of the supported formats | 739 // TODO(mcasas): Add a test to check consolidation of the supported formats |
| 739 // provided by the device when http://crbug.com/323913 is closed. | 740 // provided by the device when http://crbug.com/323913 is closed. |
| 740 | 741 |
| 741 } // namespace content | 742 } // namespace content |
| OLD | NEW |