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

Side by Side Diff: webrtc/pc/peerconnectioninterface_unittest.cc

Issue 2991693002: Adding support for Unified Plan offer/answer negotiation. (Closed)
Patch Set: Fix the chromium win-clang bulid by replacing int with Optional<size_t>. Created 3 years, 4 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 | « webrtc/pc/peerconnection.cc ('k') | webrtc/pc/webrtcsession_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 const std::string& GetFirstAudioStreamCname( 1177 const std::string& GetFirstAudioStreamCname(
1178 const SessionDescriptionInterface* desc) { 1178 const SessionDescriptionInterface* desc) {
1179 const cricket::ContentInfo* audio_content = 1179 const cricket::ContentInfo* audio_content =
1180 cricket::GetFirstAudioContent(desc->description()); 1180 cricket::GetFirstAudioContent(desc->description());
1181 const cricket::AudioContentDescription* audio_desc = 1181 const cricket::AudioContentDescription* audio_desc =
1182 static_cast<const cricket::AudioContentDescription*>( 1182 static_cast<const cricket::AudioContentDescription*>(
1183 audio_content->description); 1183 audio_content->description);
1184 return audio_desc->streams()[0].cname; 1184 return audio_desc->streams()[0].cname;
1185 } 1185 }
1186 1186
1187 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1188 const RTCOfferAnswerOptions& offer_answer_options) {
1189 RTC_DCHECK(pc_);
1190 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1191 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1192 pc_->CreateOffer(observer, offer_answer_options);
1193 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1194 return observer->MoveDescription();
1195 }
1196
1197 void CreateOfferWithOptionsAsRemoteDescription(
1198 std::unique_ptr<SessionDescriptionInterface>* desc,
1199 const RTCOfferAnswerOptions& offer_answer_options) {
1200 *desc = CreateOfferWithOptions(offer_answer_options);
1201 ASSERT_TRUE(desc != nullptr);
1202 std::string sdp;
1203 EXPECT_TRUE((*desc)->ToString(&sdp));
1204 SessionDescriptionInterface* remote_offer =
1205 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1206 sdp, NULL);
1207 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
1208 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1209 }
1210
1211 void CreateOfferWithOptionsAsLocalDescription(
1212 std::unique_ptr<SessionDescriptionInterface>* desc,
1213 const RTCOfferAnswerOptions& offer_answer_options) {
1214 *desc = CreateOfferWithOptions(offer_answer_options);
1215 ASSERT_TRUE(desc != nullptr);
1216 std::string sdp;
1217 EXPECT_TRUE((*desc)->ToString(&sdp));
1218 SessionDescriptionInterface* new_offer = webrtc::CreateSessionDescription(
1219 SessionDescriptionInterface::kOffer, sdp, NULL);
1220
1221 EXPECT_TRUE(DoSetLocalDescription(new_offer));
1222 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1223 }
1224
1225 bool HasCNCodecs(const cricket::ContentInfo* content) {
1226 const cricket::ContentDescription* description = content->description;
1227 RTC_DCHECK(description);
1228 const cricket::AudioContentDescription* audio_content_desc =
1229 static_cast<const cricket::AudioContentDescription*>(description);
1230 RTC_DCHECK(audio_content_desc);
1231 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1232 if (audio_content_desc->codecs()[i].name == "CN")
1233 return true;
1234 }
1235 return false;
1236 }
1237
1187 std::unique_ptr<rtc::VirtualSocketServer> vss_; 1238 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1188 rtc::AutoSocketServerThread main_; 1239 rtc::AutoSocketServerThread main_;
1189 cricket::FakePortAllocator* port_allocator_ = nullptr; 1240 cricket::FakePortAllocator* port_allocator_ = nullptr;
1190 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr; 1241 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
1191 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; 1242 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1192 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; 1243 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1193 rtc::scoped_refptr<PeerConnectionInterface> pc_; 1244 rtc::scoped_refptr<PeerConnectionInterface> pc_;
1194 MockPeerConnectionObserver observer_; 1245 MockPeerConnectionObserver observer_;
1195 rtc::scoped_refptr<StreamCollection> reference_collection_; 1246 rtc::scoped_refptr<StreamCollection> reference_collection_;
1196 }; 1247 };
(...skipping 2290 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 // Call's BitrateConfig, which comes from the SDP or a default value. This test 3538 // Call's BitrateConfig, which comes from the SDP or a default value. This test
3488 // checks that a call to SetBitrate with a current bitrate that will be clamped 3539 // checks that a call to SetBitrate with a current bitrate that will be clamped
3489 // succeeds. 3540 // succeeds.
3490 TEST_F(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) { 3541 TEST_F(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
3491 CreatePeerConnection(); 3542 CreatePeerConnection();
3492 PeerConnectionInterface::BitrateParameters bitrate; 3543 PeerConnectionInterface::BitrateParameters bitrate;
3493 bitrate.current_bitrate_bps = rtc::Optional<int>(1); 3544 bitrate.current_bitrate_bps = rtc::Optional<int>(1);
3494 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); 3545 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3495 } 3546 }
3496 3547
3548 // The following tests verify that the offer can be created correctly.
3549 TEST_F(PeerConnectionInterfaceTest,
3550 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3551 RTCOfferAnswerOptions rtc_options;
3552
3553 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3554 // than kMaxOfferToReceiveMedia should be treated as invalid.
3555 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3556 CreatePeerConnection();
3557 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3558
3559 rtc_options.offer_to_receive_audio =
3560 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3561 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3562 }
3563
3564 TEST_F(PeerConnectionInterfaceTest,
3565 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3566 RTCOfferAnswerOptions rtc_options;
3567
3568 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3569 // than kMaxOfferToReceiveMedia should be treated as invalid.
3570 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3571 CreatePeerConnection();
3572 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3573
3574 rtc_options.offer_to_receive_video =
3575 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3576 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3577 }
3578
3579 // Test that the audio and video content will be added to an offer if both
3580 // |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
3581 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
3582 RTCOfferAnswerOptions rtc_options;
3583 rtc_options.offer_to_receive_audio = 1;
3584 rtc_options.offer_to_receive_video = 1;
3585
3586 std::unique_ptr<SessionDescriptionInterface> offer;
3587 CreatePeerConnection();
3588 offer = CreateOfferWithOptions(rtc_options);
3589 ASSERT_TRUE(offer);
3590 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3591 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3592 }
3593
3594 // Test that only audio content will be added to the offer if only
3595 // |offer_to_receive_audio| options is 1.
3596 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
3597 RTCOfferAnswerOptions rtc_options;
3598 rtc_options.offer_to_receive_audio = 1;
3599 rtc_options.offer_to_receive_video = 0;
3600
3601 std::unique_ptr<SessionDescriptionInterface> offer;
3602 CreatePeerConnection();
3603 offer = CreateOfferWithOptions(rtc_options);
3604 ASSERT_TRUE(offer);
3605 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3606 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3607 }
3608
3609 // Test that only video content will be added if only |offer_to_receive_video|
3610 // options is 1.
3611 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
3612 RTCOfferAnswerOptions rtc_options;
3613 rtc_options.offer_to_receive_audio = 0;
3614 rtc_options.offer_to_receive_video = 1;
3615
3616 std::unique_ptr<SessionDescriptionInterface> offer;
3617 CreatePeerConnection();
3618 offer = CreateOfferWithOptions(rtc_options);
3619 ASSERT_TRUE(offer);
3620 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3621 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3622 }
3623
3624 // Test that if |voice_activity_detection| is false, no CN codec is added to the
3625 // offer.
3626 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithVADOptions) {
3627 RTCOfferAnswerOptions rtc_options;
3628 rtc_options.offer_to_receive_audio = 1;
3629 rtc_options.offer_to_receive_video = 0;
3630
3631 std::unique_ptr<SessionDescriptionInterface> offer;
3632 CreatePeerConnection();
3633 offer = CreateOfferWithOptions(rtc_options);
3634 ASSERT_TRUE(offer);
3635 const cricket::ContentInfo* audio_content =
3636 offer->description()->GetContentByName(cricket::CN_AUDIO);
3637 ASSERT_TRUE(audio_content);
3638 // |voice_activity_detection| is true by default.
3639 EXPECT_TRUE(HasCNCodecs(audio_content));
3640
3641 rtc_options.voice_activity_detection = false;
3642 CreatePeerConnection();
3643 offer = CreateOfferWithOptions(rtc_options);
3644 ASSERT_TRUE(offer);
3645 audio_content = offer->description()->GetContentByName(cricket::CN_AUDIO);
3646 ASSERT_TRUE(audio_content);
3647 EXPECT_FALSE(HasCNCodecs(audio_content));
3648 }
3649
3650 // Test that no media content will be added to the offer if using default
3651 // RTCOfferAnswerOptions.
3652 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
3653 RTCOfferAnswerOptions rtc_options;
3654
3655 std::unique_ptr<SessionDescriptionInterface> offer;
3656 CreatePeerConnection();
3657 offer = CreateOfferWithOptions(rtc_options);
3658 ASSERT_TRUE(offer);
3659 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3660 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3661 }
3662
3663 // Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3664 // ufrag/pwd will be the same in the new offer.
3665 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3666 RTCOfferAnswerOptions rtc_options;
3667 rtc_options.ice_restart = false;
3668 rtc_options.offer_to_receive_audio = 1;
3669
3670 std::unique_ptr<SessionDescriptionInterface> offer;
3671 CreatePeerConnection();
3672 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
3673 auto ufrag1 = offer->description()
3674 ->GetTransportInfoByName(cricket::CN_AUDIO)
3675 ->description.ice_ufrag;
3676 auto pwd1 = offer->description()
3677 ->GetTransportInfoByName(cricket::CN_AUDIO)
3678 ->description.ice_pwd;
3679
3680 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3681 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
3682 auto ufrag2 = offer->description()
3683 ->GetTransportInfoByName(cricket::CN_AUDIO)
3684 ->description.ice_ufrag;
3685 auto pwd2 = offer->description()
3686 ->GetTransportInfoByName(cricket::CN_AUDIO)
3687 ->description.ice_pwd;
3688
3689 // |ice_restart| is true, the ufrag/pwd should change.
3690 rtc_options.ice_restart = true;
3691 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
3692 auto ufrag3 = offer->description()
3693 ->GetTransportInfoByName(cricket::CN_AUDIO)
3694 ->description.ice_ufrag;
3695 auto pwd3 = offer->description()
3696 ->GetTransportInfoByName(cricket::CN_AUDIO)
3697 ->description.ice_pwd;
3698
3699 EXPECT_EQ(ufrag1, ufrag2);
3700 EXPECT_EQ(pwd1, pwd2);
3701 EXPECT_NE(ufrag2, ufrag3);
3702 EXPECT_NE(pwd2, pwd3);
3703 }
3704
3705 // Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3706 // offer; if it is false, there won't be any bundle group in the offer.
3707 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
3708 RTCOfferAnswerOptions rtc_options;
3709 rtc_options.offer_to_receive_audio = 1;
3710 rtc_options.offer_to_receive_video = 1;
3711
3712 std::unique_ptr<SessionDescriptionInterface> offer;
3713 CreatePeerConnection();
3714
3715 rtc_options.use_rtp_mux = true;
3716 offer = CreateOfferWithOptions(rtc_options);
3717 ASSERT_TRUE(offer);
3718 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3719 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3720 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3721
3722 rtc_options.use_rtp_mux = false;
3723 offer = CreateOfferWithOptions(rtc_options);
3724 ASSERT_TRUE(offer);
3725 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3726 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3727 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3728 }
3729
3730 // If SetMandatoryReceiveAudio(false) and SetMandatoryReceiveVideo(false) are
3731 // called for the answer constraints, but an audio and a video section were
3732 // offered, there will still be an audio and a video section in the answer.
3733 TEST_F(PeerConnectionInterfaceTest,
3734 RejectAudioAndVideoInAnswerWithConstraints) {
3735 // Offer both audio and video.
3736 RTCOfferAnswerOptions rtc_offer_options;
3737 rtc_offer_options.offer_to_receive_audio = 1;
3738 rtc_offer_options.offer_to_receive_video = 1;
3739
3740 CreatePeerConnection();
3741 std::unique_ptr<SessionDescriptionInterface> offer;
3742 CreateOfferWithOptionsAsRemoteDescription(&offer, rtc_offer_options);
3743 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3744 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3745
3746 // Since an offer has been created with both audio and video,
3747 // Answers will contain the media types that exist in the offer regardless of
3748 // the value of |answer_options.has_audio| and |answer_options.has_video|.
3749 FakeConstraints answer_c;
3750 // Reject both audio and video.
3751 answer_c.SetMandatoryReceiveAudio(false);
3752 answer_c.SetMandatoryReceiveVideo(false);
3753
3754 std::unique_ptr<SessionDescriptionInterface> answer;
3755 ASSERT_TRUE(DoCreateAnswer(&answer, &answer_c));
3756 const cricket::ContentInfo* audio_content =
3757 GetFirstAudioContent(answer->description());
3758 const cricket::ContentInfo* video_content =
3759 GetFirstVideoContent(answer->description());
3760 ASSERT_NE(nullptr, audio_content);
3761 ASSERT_NE(nullptr, video_content);
3762 EXPECT_TRUE(audio_content->rejected);
3763 EXPECT_TRUE(video_content->rejected);
3764 }
3765
3497 class PeerConnectionMediaConfigTest : public testing::Test { 3766 class PeerConnectionMediaConfigTest : public testing::Test {
3498 protected: 3767 protected:
3499 void SetUp() override { 3768 void SetUp() override {
3500 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); 3769 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
3501 pcf_->Initialize(); 3770 pcf_->Initialize();
3502 } 3771 }
3503 const cricket::MediaConfig TestCreatePeerConnection( 3772 const cricket::MediaConfig TestCreatePeerConnection(
3504 const PeerConnectionInterface::RTCConfiguration& config, 3773 const PeerConnectionInterface::RTCConfiguration& config,
3505 const MediaConstraintsInterface *constraints) { 3774 const MediaConstraintsInterface* constraints) {
3506
3507 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection( 3775 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
3508 config, constraints, nullptr, nullptr, &observer_)); 3776 config, constraints, nullptr, nullptr, &observer_));
3509 EXPECT_TRUE(pc.get()); 3777 EXPECT_TRUE(pc.get());
3510 return pc->GetConfiguration().media_config; 3778 return pc->GetConfiguration().media_config;
3511 } 3779 }
3512 3780
3513 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; 3781 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
3514 MockPeerConnectionObserver observer_; 3782 MockPeerConnectionObserver observer_;
3515 }; 3783 };
3516 3784
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3578 3846
3579 constraints.AddOptional( 3847 constraints.AddOptional(
3580 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, 3848 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3581 true); 3849 true);
3582 const cricket::MediaConfig media_config = 3850 const cricket::MediaConfig media_config =
3583 TestCreatePeerConnection(config, &constraints); 3851 TestCreatePeerConnection(config, &constraints);
3584 3852
3585 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate); 3853 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
3586 } 3854 }
3587 3855
3588 // The following tests verify that session options are created correctly.
3589 // TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
3590 // "verify options are converted correctly", should be "pass options into
3591 // CreateOffer and verify the correct offer is produced."
3592
3593 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
3594 RTCOfferAnswerOptions rtc_options;
3595 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3596
3597 cricket::MediaSessionOptions options;
3598 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
3599
3600 rtc_options.offer_to_receive_audio =
3601 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3602 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
3603 }
3604
3605 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
3606 RTCOfferAnswerOptions rtc_options;
3607 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3608
3609 cricket::MediaSessionOptions options;
3610 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
3611
3612 rtc_options.offer_to_receive_video =
3613 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3614 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
3615 }
3616
3617 // Test that a MediaSessionOptions is created for an offer if
3618 // OfferToReceiveAudio and OfferToReceiveVideo options are set.
3619 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
3620 RTCOfferAnswerOptions rtc_options;
3621 rtc_options.offer_to_receive_audio = 1;
3622 rtc_options.offer_to_receive_video = 1;
3623
3624 cricket::MediaSessionOptions options;
3625 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
3626 EXPECT_TRUE(options.has_audio());
3627 EXPECT_TRUE(options.has_video());
3628 EXPECT_TRUE(options.bundle_enabled);
3629 }
3630
3631 // Test that a correct MediaSessionOptions is created for an offer if
3632 // OfferToReceiveAudio is set.
3633 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
3634 RTCOfferAnswerOptions rtc_options;
3635 rtc_options.offer_to_receive_audio = 1;
3636
3637 cricket::MediaSessionOptions options;
3638 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
3639 EXPECT_TRUE(options.has_audio());
3640 EXPECT_FALSE(options.has_video());
3641 EXPECT_TRUE(options.bundle_enabled);
3642 }
3643
3644 // Test that a correct MediaSessionOptions is created for an offer if
3645 // the default OfferOptions are used.
3646 TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
3647 RTCOfferAnswerOptions rtc_options;
3648
3649 cricket::MediaSessionOptions options;
3650 options.transport_options["audio"] = cricket::TransportOptions();
3651 options.transport_options["video"] = cricket::TransportOptions();
3652 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
3653 EXPECT_TRUE(options.has_audio());
3654 EXPECT_FALSE(options.has_video());
3655 EXPECT_TRUE(options.bundle_enabled);
3656 EXPECT_TRUE(options.vad_enabled);
3657 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3658 EXPECT_FALSE(options.transport_options["video"].ice_restart);
3659 }
3660
3661 // Test that a correct MediaSessionOptions is created for an offer if
3662 // OfferToReceiveVideo is set.
3663 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
3664 RTCOfferAnswerOptions rtc_options;
3665 rtc_options.offer_to_receive_audio = 0;
3666 rtc_options.offer_to_receive_video = 1;
3667
3668 cricket::MediaSessionOptions options;
3669 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
3670 EXPECT_FALSE(options.has_audio());
3671 EXPECT_TRUE(options.has_video());
3672 EXPECT_TRUE(options.bundle_enabled);
3673 }
3674
3675 // Test that a correct MediaSessionOptions is created for an offer if
3676 // UseRtpMux is set to false.
3677 TEST(CreateSessionOptionsTest,
3678 GetMediaSessionOptionsForOfferWithBundleDisabled) {
3679 RTCOfferAnswerOptions rtc_options;
3680 rtc_options.offer_to_receive_audio = 1;
3681 rtc_options.offer_to_receive_video = 1;
3682 rtc_options.use_rtp_mux = false;
3683
3684 cricket::MediaSessionOptions options;
3685 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
3686 EXPECT_TRUE(options.has_audio());
3687 EXPECT_TRUE(options.has_video());
3688 EXPECT_FALSE(options.bundle_enabled);
3689 }
3690
3691 // Test that a correct MediaSessionOptions is created to restart ice if
3692 // IceRestart is set. It also tests that subsequent MediaSessionOptions don't
3693 // have |audio_transport_options.ice_restart| etc. set.
3694 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
3695 RTCOfferAnswerOptions rtc_options;
3696 rtc_options.ice_restart = true;
3697
3698 cricket::MediaSessionOptions options;
3699 options.transport_options["audio"] = cricket::TransportOptions();
3700 options.transport_options["video"] = cricket::TransportOptions();
3701 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
3702 EXPECT_TRUE(options.transport_options["audio"].ice_restart);
3703 EXPECT_TRUE(options.transport_options["video"].ice_restart);
3704
3705 rtc_options = RTCOfferAnswerOptions();
3706 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
3707 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3708 EXPECT_FALSE(options.transport_options["video"].ice_restart);
3709 }
3710
3711 // Test that the MediaConstraints in an answer don't affect if audio and video
3712 // is offered in an offer but that if kOfferToReceiveAudio or
3713 // kOfferToReceiveVideo constraints are true in an offer, the media type will be
3714 // included in subsequent answers.
3715 TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
3716 FakeConstraints answer_c;
3717 answer_c.SetMandatoryReceiveAudio(true);
3718 answer_c.SetMandatoryReceiveVideo(true);
3719
3720 cricket::MediaSessionOptions answer_options;
3721 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
3722 EXPECT_TRUE(answer_options.has_audio());
3723 EXPECT_TRUE(answer_options.has_video());
3724
3725 RTCOfferAnswerOptions rtc_offer_options;
3726
3727 cricket::MediaSessionOptions offer_options;
3728 EXPECT_TRUE(
3729 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options));
3730 EXPECT_TRUE(offer_options.has_audio());
3731 EXPECT_TRUE(offer_options.has_video());
3732
3733 RTCOfferAnswerOptions updated_rtc_offer_options;
3734 updated_rtc_offer_options.offer_to_receive_audio = 1;
3735 updated_rtc_offer_options.offer_to_receive_video = 1;
3736
3737 cricket::MediaSessionOptions updated_offer_options;
3738 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false,
3739 &updated_offer_options));
3740 EXPECT_TRUE(updated_offer_options.has_audio());
3741 EXPECT_TRUE(updated_offer_options.has_video());
3742
3743 // Since an offer has been created with both audio and video, subsequent
3744 // offers and answers should contain both audio and video.
3745 // Answers will only contain the media types that exist in the offer
3746 // regardless of the value of |updated_answer_options.has_audio| and
3747 // |updated_answer_options.has_video|.
3748 FakeConstraints updated_answer_c;
3749 answer_c.SetMandatoryReceiveAudio(false);
3750 answer_c.SetMandatoryReceiveVideo(false);
3751
3752 cricket::MediaSessionOptions updated_answer_options;
3753 EXPECT_TRUE(
3754 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
3755 EXPECT_TRUE(updated_answer_options.has_audio());
3756 EXPECT_TRUE(updated_answer_options.has_video());
3757 }
3758
3759 // Tests a few random fields being different. 3856 // Tests a few random fields being different.
3760 TEST(RTCConfigurationTest, ComparisonOperators) { 3857 TEST(RTCConfigurationTest, ComparisonOperators) {
3761 PeerConnectionInterface::RTCConfiguration a; 3858 PeerConnectionInterface::RTCConfiguration a;
3762 PeerConnectionInterface::RTCConfiguration b; 3859 PeerConnectionInterface::RTCConfiguration b;
3763 EXPECT_EQ(a, b); 3860 EXPECT_EQ(a, b);
3764 3861
3765 PeerConnectionInterface::RTCConfiguration c; 3862 PeerConnectionInterface::RTCConfiguration c;
3766 c.servers.push_back(PeerConnectionInterface::IceServer()); 3863 c.servers.push_back(PeerConnectionInterface::IceServer());
3767 EXPECT_NE(a, c); 3864 EXPECT_NE(a, c);
3768 3865
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3813 observer_.renegotiation_needed_ = false; 3910 observer_.renegotiation_needed_ = false;
3814 3911
3815 stream->RemoveTrack(audio_track); 3912 stream->RemoveTrack(audio_track);
3816 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); 3913 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3817 observer_.renegotiation_needed_ = false; 3914 observer_.renegotiation_needed_ = false;
3818 3915
3819 stream->RemoveTrack(video_track); 3916 stream->RemoveTrack(video_track);
3820 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); 3917 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3821 observer_.renegotiation_needed_ = false; 3918 observer_.renegotiation_needed_ = false;
3822 } 3919 }
OLDNEW
« no previous file with comments | « webrtc/pc/peerconnection.cc ('k') | webrtc/pc/webrtcsession_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698