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

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

Issue 2538033003: Implement GetUserMedia device ID constraint processing in the renderer. (Closed)
Patch Set: fixes Created 4 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 #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
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 we can generate streams where a optional sourceId is specified in
hta - Chromium 2016/11/30 18:51:42 Is this sourceid still optional? Please update com
Guido Urdaneta 2016/12/01 10:28:53 Actually, this test was redundant in the original
636 // the request. 636 // the request.
637 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithOptionalSourceId) { 637 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithOptionalSourceId) {
638 ASSERT_GE(physical_audio_devices_.size(), 1u); 638 ASSERT_GE(physical_audio_devices_.size(), 1u);
639 ASSERT_GE(physical_video_devices_.size(), 1u); 639 ASSERT_GE(physical_video_devices_.size(), 1u);
640 640
641 media::AudioDeviceNames::const_iterator audio_it = 641 media::AudioDeviceNames::const_iterator audio_it =
642 physical_audio_devices_.begin(); 642 physical_audio_devices_.begin();
643 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 643 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
644 std::string source_id = content::GetHMACForMediaDeviceID( 644 std::string source_id = content::GetHMACForMediaDeviceID(
645 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 645 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
646 origin_, 646 origin_,
647 audio_it->unique_id); 647 audio_it->unique_id);
648 ASSERT_FALSE(source_id.empty()); 648 ASSERT_FALSE(source_id.empty());
649 StreamControls controls(true, true); 649 StreamControls controls(true, true);
650 controls.audio.device_ids.push_back(source_id); 650 controls.audio.device_id = source_id;
651 651
652 SetupFakeUI(true); 652 SetupFakeUI(true);
653 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 653 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
654 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); 654 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id);
655 } 655 }
656 656
657 media::VideoCaptureDeviceDescriptors::const_iterator video_it = 657 media::VideoCaptureDeviceDescriptors::const_iterator video_it =
658 physical_video_devices_.begin(); 658 physical_video_devices_.begin();
659 for (; video_it != physical_video_devices_.end(); ++video_it) { 659 for (; video_it != physical_video_devices_.end(); ++video_it) {
660 std::string source_id = content::GetHMACForMediaDeviceID( 660 std::string source_id = content::GetHMACForMediaDeviceID(
661 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, 661 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_,
662 video_it->device_id); 662 video_it->device_id);
663 ASSERT_FALSE(source_id.empty()); 663 ASSERT_FALSE(source_id.empty());
664 StreamControls controls(true, true); 664 StreamControls controls(true, true);
665 controls.video.device_ids.push_back(source_id); 665 controls.video.device_id = source_id;
666 666
667 SetupFakeUI(true); 667 SetupFakeUI(true);
668 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 668 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
669 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); 669 EXPECT_EQ(host_->video_devices_[0].device.id, source_id);
670 } 670 }
671 } 671 }
672 672
673 // Test that generating a stream with an invalid mandatory video source id fail. 673 // Test that generating a stream with an invalid video source id fail.
674 TEST_F(MediaStreamDispatcherHostTest, 674 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) {
675 GenerateStreamsWithInvalidMandatoryVideoSourceId) {
676 StreamControls controls(true, true); 675 StreamControls controls(true, true);
677 controls.video.device_ids.push_back("invalid source id"); 676 controls.video.device_id = "invalid source id";
678 677
679 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, 678 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls,
680 MEDIA_DEVICE_NO_HARDWARE); 679 MEDIA_DEVICE_NO_HARDWARE);
681 } 680 }
682 681
683 // Test that generating a stream with an invalid mandatory audio source id fail. 682 // Test that generating a stream with an invalid audio source id fail.
684 TEST_F(MediaStreamDispatcherHostTest, 683 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) {
685 GenerateStreamsWithInvalidMandatoryAudioSourceId) {
686 StreamControls controls(true, true); 684 StreamControls controls(true, true);
687 controls.audio.device_ids.push_back("invalid source id"); 685 controls.audio.device_id = "invalid source id";
688 686
689 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, 687 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls,
690 MEDIA_DEVICE_NO_HARDWARE); 688 MEDIA_DEVICE_NO_HARDWARE);
691 } 689 }
692 690
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) { 691 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) {
716 physical_video_devices_.clear(); 692 physical_video_devices_.clear();
717 video_capture_device_factory_->set_number_of_devices(0); 693 video_capture_device_factory_->set_number_of_devices(0);
718 video_capture_device_factory_->GetDeviceDescriptors(&physical_video_devices_); 694 video_capture_device_factory_->GetDeviceDescriptors(&physical_video_devices_);
719 StreamControls controls(true, true); 695 StreamControls controls(true, true);
720 696
721 SetupFakeUI(false); 697 SetupFakeUI(false);
722 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, 698 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls,
723 MEDIA_DEVICE_NO_HARDWARE); 699 MEDIA_DEVICE_NO_HARDWARE);
724 } 700 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 base::RunLoop run_loop; 852 base::RunLoop run_loop;
877 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) 853 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId))
878 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 854 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
879 media_stream_manager_->media_devices_manager()->OnDevicesChanged( 855 media_stream_manager_->media_devices_manager()->OnDevicesChanged(
880 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); 856 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
881 857
882 run_loop.Run(); 858 run_loop.Run();
883 } 859 }
884 860
885 }; // namespace content 861 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698