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

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

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

Powered by Google App Engine
This is Rietveld 408576698