| 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 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 base::RunLoop run_loop2; | 587 base::RunLoop run_loop2; |
| 588 host_->OnGenerateStream(kRenderId, kPageRequestId, controls, origin_, | 588 host_->OnGenerateStream(kRenderId, kPageRequestId, controls, origin_, |
| 589 run_loop1.QuitClosure()); | 589 run_loop1.QuitClosure()); |
| 590 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, controls, origin_, | 590 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, controls, origin_, |
| 591 run_loop2.QuitClosure()); | 591 run_loop2.QuitClosure()); |
| 592 | 592 |
| 593 run_loop1.Run(); | 593 run_loop1.Run(); |
| 594 run_loop2.Run(); | 594 run_loop2.Run(); |
| 595 } | 595 } |
| 596 | 596 |
| 597 // Test that we can generate streams where a mandatory sourceId is specified in | 597 // Test that we can generate streams where a sourceId is specified in |
| 598 // the request. | 598 // the request. |
| 599 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithMandatorySourceId) { | 599 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { |
| 600 ASSERT_GE(physical_audio_devices_.size(), 1u); | 600 ASSERT_GE(physical_audio_devices_.size(), 1u); |
| 601 ASSERT_GE(physical_video_devices_.size(), 1u); | 601 ASSERT_GE(physical_video_devices_.size(), 1u); |
| 602 | 602 |
| 603 media::AudioDeviceNames::const_iterator audio_it = | 603 media::AudioDeviceNames::const_iterator audio_it = |
| 604 physical_audio_devices_.begin(); | 604 physical_audio_devices_.begin(); |
| 605 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 605 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 606 std::string source_id = content::GetHMACForMediaDeviceID( | 606 std::string source_id = content::GetHMACForMediaDeviceID( |
| 607 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 607 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 608 origin_, | 608 origin_, |
| 609 audio_it->unique_id); | 609 audio_it->unique_id); |
| 610 ASSERT_FALSE(source_id.empty()); | 610 ASSERT_FALSE(source_id.empty()); |
| 611 StreamControls controls(true, true); | 611 StreamControls controls(true, true); |
| 612 controls.audio.device_ids.push_back(source_id); | 612 controls.audio.device_id = source_id; |
| 613 | 613 |
| 614 SetupFakeUI(true); | 614 SetupFakeUI(true); |
| 615 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 615 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 616 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); | 616 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); |
| 617 } | 617 } |
| 618 | 618 |
| 619 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 619 media::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 620 physical_video_devices_.begin(); | 620 physical_video_devices_.begin(); |
| 621 for (; video_it != physical_video_devices_.end(); ++video_it) { | 621 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 622 std::string source_id = content::GetHMACForMediaDeviceID( | 622 std::string source_id = content::GetHMACForMediaDeviceID( |
| 623 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, | 623 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, |
| 624 video_it->device_id); | 624 video_it->device_id); |
| 625 ASSERT_FALSE(source_id.empty()); | 625 ASSERT_FALSE(source_id.empty()); |
| 626 StreamControls controls(true, true); | 626 StreamControls controls(true, true); |
| 627 controls.video.device_ids.push_back(source_id); | 627 controls.video.device_id = source_id; |
| 628 | 628 |
| 629 SetupFakeUI(true); | 629 SetupFakeUI(true); |
| 630 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 630 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 631 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); | 631 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); |
| 632 } | 632 } |
| 633 } | 633 } |
| 634 | 634 |
| 635 // Test that we can generate streams where a optional sourceId is specified in | 635 // Test that generating a stream with an invalid video source id fail. |
| 636 // the request. | 636 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) { |
| 637 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithOptionalSourceId) { | |
| 638 ASSERT_GE(physical_audio_devices_.size(), 1u); | |
| 639 ASSERT_GE(physical_video_devices_.size(), 1u); | |
| 640 | |
| 641 media::AudioDeviceNames::const_iterator audio_it = | |
| 642 physical_audio_devices_.begin(); | |
| 643 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | |
| 644 std::string source_id = content::GetHMACForMediaDeviceID( | |
| 645 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | |
| 646 origin_, | |
| 647 audio_it->unique_id); | |
| 648 ASSERT_FALSE(source_id.empty()); | |
| 649 StreamControls controls(true, true); | |
| 650 controls.audio.device_ids.push_back(source_id); | |
| 651 | |
| 652 SetupFakeUI(true); | |
| 653 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | |
| 654 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); | |
| 655 } | |
| 656 | |
| 657 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | |
| 658 physical_video_devices_.begin(); | |
| 659 for (; video_it != physical_video_devices_.end(); ++video_it) { | |
| 660 std::string source_id = content::GetHMACForMediaDeviceID( | |
| 661 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, | |
| 662 video_it->device_id); | |
| 663 ASSERT_FALSE(source_id.empty()); | |
| 664 StreamControls controls(true, true); | |
| 665 controls.video.device_ids.push_back(source_id); | |
| 666 | |
| 667 SetupFakeUI(true); | |
| 668 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | |
| 669 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); | |
| 670 } | |
| 671 } | |
| 672 | |
| 673 // Test that generating a stream with an invalid mandatory video source id fail. | |
| 674 TEST_F(MediaStreamDispatcherHostTest, | |
| 675 GenerateStreamsWithInvalidMandatoryVideoSourceId) { | |
| 676 StreamControls controls(true, true); | 637 StreamControls controls(true, true); |
| 677 controls.video.device_ids.push_back("invalid source id"); | 638 controls.video.device_id = "invalid source id"; |
| 678 | 639 |
| 679 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, | 640 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, |
| 680 MEDIA_DEVICE_NO_HARDWARE); | 641 MEDIA_DEVICE_NO_HARDWARE); |
| 681 } | 642 } |
| 682 | 643 |
| 683 // Test that generating a stream with an invalid mandatory audio source id fail. | 644 // Test that generating a stream with an invalid audio source id fail. |
| 684 TEST_F(MediaStreamDispatcherHostTest, | 645 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) { |
| 685 GenerateStreamsWithInvalidMandatoryAudioSourceId) { | |
| 686 StreamControls controls(true, true); | 646 StreamControls controls(true, true); |
| 687 controls.audio.device_ids.push_back("invalid source id"); | 647 controls.audio.device_id = "invalid source id"; |
| 688 | 648 |
| 689 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, | 649 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, |
| 690 MEDIA_DEVICE_NO_HARDWARE); | 650 MEDIA_DEVICE_NO_HARDWARE); |
| 691 } | 651 } |
| 692 | 652 |
| 693 // Test that generating a stream with an invalid optional video source id | |
| 694 // succeed. | |
| 695 TEST_F(MediaStreamDispatcherHostTest, | |
| 696 GenerateStreamsWithInvalidOptionalVideoSourceId) { | |
| 697 StreamControls controls(true, true); | |
| 698 controls.video.alternate_device_ids.push_back("invalid source id"); | |
| 699 | |
| 700 SetupFakeUI(true); | |
| 701 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | |
| 702 } | |
| 703 | |
| 704 // Test that generating a stream with an invalid optional audio source id | |
| 705 // succeed. | |
| 706 TEST_F(MediaStreamDispatcherHostTest, | |
| 707 GenerateStreamsWithInvalidOptionalAudioSourceId) { | |
| 708 StreamControls controls(true, true); | |
| 709 controls.video.alternate_device_ids.push_back("invalid source id"); | |
| 710 | |
| 711 SetupFakeUI(true); | |
| 712 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | |
| 713 } | |
| 714 | |
| 715 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { | 653 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { |
| 716 physical_video_devices_.clear(); | 654 physical_video_devices_.clear(); |
| 717 video_capture_device_factory_->set_number_of_devices(0); | 655 video_capture_device_factory_->set_number_of_devices(0); |
| 718 video_capture_device_factory_->GetDeviceDescriptors(&physical_video_devices_); | 656 video_capture_device_factory_->GetDeviceDescriptors(&physical_video_devices_); |
| 719 StreamControls controls(true, true); | 657 StreamControls controls(true, true); |
| 720 | 658 |
| 721 SetupFakeUI(false); | 659 SetupFakeUI(false); |
| 722 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, | 660 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, |
| 723 MEDIA_DEVICE_NO_HARDWARE); | 661 MEDIA_DEVICE_NO_HARDWARE); |
| 724 } | 662 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 base::RunLoop run_loop; | 814 base::RunLoop run_loop; |
| 877 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 815 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
| 878 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 816 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 879 media_stream_manager_->media_devices_manager()->OnDevicesChanged( | 817 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
| 880 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 818 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
| 881 | 819 |
| 882 run_loop.Run(); | 820 run_loop.Run(); |
| 883 } | 821 } |
| 884 | 822 |
| 885 }; // namespace content | 823 }; // namespace content |
| OLD | NEW |