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

Side by Side Diff: webrtc/pc/webrtcsession_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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 "a=fmtp:96 apt=0\r\n"; 136 "a=fmtp:96 apt=0\r\n";
137 137
138 static const char kStream1[] = "stream1"; 138 static const char kStream1[] = "stream1";
139 static const char kVideoTrack1[] = "video1"; 139 static const char kVideoTrack1[] = "video1";
140 static const char kAudioTrack1[] = "audio1"; 140 static const char kAudioTrack1[] = "audio1";
141 141
142 static const char kStream2[] = "stream2"; 142 static const char kStream2[] = "stream2";
143 static const char kVideoTrack2[] = "video2"; 143 static const char kVideoTrack2[] = "video2";
144 static const char kAudioTrack2[] = "audio2"; 144 static const char kAudioTrack2[] = "audio2";
145 145
146 static constexpr bool kStopped = true;
147
146 enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE }; 148 enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
147 149
148 class MockIceObserver : public webrtc::IceObserver { 150 class MockIceObserver : public webrtc::IceObserver {
149 public: 151 public:
150 MockIceObserver() 152 MockIceObserver()
151 : oncandidatesready_(false), 153 : oncandidatesready_(false),
152 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), 154 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
153 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { 155 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
154 } 156 }
155 157
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { 393 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
392 cricket::ServerAddresses stun_servers; 394 cricket::ServerAddresses stun_servers;
393 stun_servers.insert(stun_socket_addr_); 395 stun_servers.insert(stun_socket_addr_);
394 allocator_.reset(new cricket::BasicPortAllocator( 396 allocator_.reset(new cricket::BasicPortAllocator(
395 &network_manager_, 397 &network_manager_,
396 stun_servers, 398 stun_servers,
397 SocketAddress(), SocketAddress(), SocketAddress())); 399 SocketAddress(), SocketAddress(), SocketAddress()));
398 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | 400 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
399 cricket::PORTALLOCATOR_DISABLE_RELAY); 401 cricket::PORTALLOCATOR_DISABLE_RELAY);
400 EXPECT_TRUE(channel_manager_->Init()); 402 EXPECT_TRUE(channel_manager_->Init());
401 desc_factory_->set_add_legacy_streams(false);
402 allocator_->set_step_delay(cricket::kMinimumStepDelay); 403 allocator_->set_step_delay(cricket::kMinimumStepDelay);
403 } 404 }
404 405
405 void AddInterface(const SocketAddress& addr) { 406 void AddInterface(const SocketAddress& addr) {
406 network_manager_.AddInterface(addr); 407 network_manager_.AddInterface(addr);
407 } 408 }
408 void RemoveInterface(const SocketAddress& addr) { 409 void RemoveInterface(const SocketAddress& addr) {
409 network_manager_.RemoveInterface(addr); 410 network_manager_.RemoveInterface(addr);
410 } 411 }
411 412
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 send_video_ = false; 543 send_video_ = false;
543 } 544 }
544 545
545 void SendVideoOnlyStream2() { 546 void SendVideoOnlyStream2() {
546 send_stream_1_ = false; 547 send_stream_1_ = false;
547 send_stream_2_ = true; 548 send_stream_2_ = true;
548 send_audio_ = false; 549 send_audio_ = false;
549 send_video_ = true; 550 send_video_ = true;
550 } 551 }
551 552
552 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) { 553 // Helper function used to add a specific media section to the
553 if (send_stream_1_ && send_audio_) { 554 // |session_options|.
554 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1, 555 void AddMediaSection(cricket::MediaType type,
555 kStream1); 556 const std::string& mid,
557 cricket::MediaContentDirection direction,
558 bool stopped,
559 cricket::MediaSessionOptions* opts) {
560 opts->media_description_options.push_back(cricket::MediaDescriptionOptions(
561 type, mid,
562 cricket::RtpTransceiverDirection::FromMediaContentDirection(direction),
563 stopped));
564 }
565
566 // Add the media sections to the options from |offered_media_sections_| when
567 // creating an answer or a new offer.
568 // This duplicates a lot of logic from PeerConnection but this can be fix when
569 // PeerConnection and WebRtcSession are merged.
570 void AddExistingMediaSectionsAndSendersToOptions(
571 cricket::MediaSessionOptions* session_options,
572 bool send_audio,
573 bool recv_audio,
574 bool send_video,
575 bool recv_video) {
576 int num_sim_layer = 1;
577 for (auto media_description_options : offered_media_sections_) {
Taylor Brandstetter 2017/08/05 00:39:09 It would be ideal if instead of using extra state
Zhi Huang 2017/08/09 00:54:51 There are some test cases would create answer befo
578 if (media_description_options.type == cricket::MEDIA_TYPE_AUDIO) {
579 bool stopped = !send_audio && !recv_audio;
580 auto media_desc_options = cricket::MediaDescriptionOptions(
581 cricket::MEDIA_TYPE_AUDIO, media_description_options.mid,
582 cricket::RtpTransceiverDirection(send_audio, recv_audio), stopped);
583 if (send_stream_1_ && send_audio_) {
584 media_desc_options.AddAudioSender(kAudioTrack1, kStream1);
585 }
586 if (send_stream_2_ && send_audio_) {
587 media_desc_options.AddAudioSender(kAudioTrack2, kStream2);
588 }
589 session_options->media_description_options.push_back(
590 media_desc_options);
591 } else if (media_description_options.type == cricket::MEDIA_TYPE_VIDEO) {
592 bool stopped = !send_video && !recv_video;
593 auto media_desc_options = cricket::MediaDescriptionOptions(
594 cricket::MEDIA_TYPE_VIDEO, media_description_options.mid,
595 cricket::RtpTransceiverDirection(send_video, recv_video), stopped);
596 if (send_stream_1_ && send_video_) {
597 media_desc_options.AddVideoSender(kVideoTrack1, kStream1,
598 num_sim_layer);
599 }
600 if (send_stream_2_ && send_video_) {
601 media_desc_options.AddVideoSender(kVideoTrack2, kStream2,
602 num_sim_layer);
603 }
604 session_options->media_description_options.push_back(
605 media_desc_options);
606 } else if (media_description_options.type == cricket::MEDIA_TYPE_DATA) {
607 session_options->media_description_options.push_back(
608 cricket::MediaDescriptionOptions(
609 cricket::MEDIA_TYPE_DATA, media_description_options.mid,
610 // Direction for data sections is meaningless, but legacy
611 // endpoints might expect sendrecv.
612 cricket::RtpTransceiverDirection(true, true), false));
613 } else {
614 RTC_NOTREACHED();
615 }
556 } 616 }
557 if (send_stream_1_ && send_video_) { 617 }
558 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1, 618
559 kStream1); 619 // Add the existing media sections first and then add new media sections if
620 // needed.
621 void AddMediaSectionsAndSendersToOptions(
622 cricket::MediaSessionOptions* session_options,
623 bool recv_audio,
624 bool recv_video) {
625 AddExistingMediaSectionsAndSendersToOptions(
626 session_options, send_audio_, recv_audio, send_video_, recv_video);
627
628 if (!session_options->has_audio() && (send_audio_ || recv_audio)) {
629 cricket::MediaDescriptionOptions media_desc_options =
630 cricket::MediaDescriptionOptions(
631 cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
632 cricket::RtpTransceiverDirection(send_audio_, recv_audio),
633 !kStopped);
634 if (send_stream_1_ && send_audio_) {
635 media_desc_options.AddAudioSender(kAudioTrack1, kStream1);
636 }
637 if (send_stream_2_ && send_audio_) {
638 media_desc_options.AddAudioSender(kAudioTrack2, kStream2);
639 }
640 session_options->media_description_options.push_back(media_desc_options);
641 offered_media_sections_.push_back(media_desc_options);
560 } 642 }
561 if (send_stream_2_ && send_audio_) { 643
562 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2, 644 if (!session_options->has_video() && (send_video_ || recv_video)) {
563 kStream2); 645 cricket::MediaDescriptionOptions media_desc_options =
646 cricket::MediaDescriptionOptions(
647 cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
648 cricket::RtpTransceiverDirection(send_video_, recv_video),
649 !kStopped);
650 int num_sim_layer = 1;
651 if (send_stream_1_ && send_video_) {
652 media_desc_options.AddVideoSender(kVideoTrack1, kStream1,
653 num_sim_layer);
654 }
655 if (send_stream_2_ && send_video_) {
656 media_desc_options.AddVideoSender(kVideoTrack2, kStream2,
657 num_sim_layer);
658 }
659 session_options->media_description_options.push_back(media_desc_options);
660 offered_media_sections_.push_back(media_desc_options);
564 } 661 }
565 if (send_stream_2_ && send_video_) { 662
566 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2, 663 if (!session_options->has_data() &&
567 kStream2); 664 (data_channel_ ||
568 } 665 session_options->data_channel_type != cricket::DCT_NONE)) {
569 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) { 666 cricket::MediaDescriptionOptions media_desc_options =
570 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, 667 cricket::MediaDescriptionOptions(
571 data_channel_->label(), 668 cricket::MEDIA_TYPE_DATA, cricket::CN_DATA,
572 data_channel_->label()); 669 cricket::RtpTransceiverDirection(true, true), !kStopped);
670 if (session_options->data_channel_type == cricket::DCT_RTP) {
671 media_desc_options.AddRtpDataChannel(data_channel_->label(),
672 data_channel_->label());
673 }
674 session_options->media_description_options.push_back(media_desc_options);
675 offered_media_sections_.push_back(media_desc_options);
573 } 676 }
574 } 677 }
575 678
576 void GetOptionsForOffer( 679 void GetOptionsForOffer(
577 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, 680 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
578 cricket::MediaSessionOptions* session_options) { 681 cricket::MediaSessionOptions* session_options) {
579 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options)); 682 ExtractSharedMediaSessionOptions(rtc_options, session_options);
580 683
581 AddStreamsToOptions(session_options); 684 // |recv_X| is true by default if |offer_to_receive_X| is undefined.
582 if (rtc_options.offer_to_receive_audio == 685 bool recv_audio = rtc_options.offer_to_receive_audio != 0;
583 RTCOfferAnswerOptions::kUndefined) { 686 bool recv_video = rtc_options.offer_to_receive_video != 0;
584 session_options->recv_audio = 687
585 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO); 688 AddMediaSectionsAndSendersToOptions(session_options, recv_audio,
586 } 689 recv_video);
587 if (rtc_options.offer_to_receive_video ==
588 RTCOfferAnswerOptions::kUndefined) {
589 session_options->recv_video =
590 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
591 }
592 session_options->bundle_enabled = 690 session_options->bundle_enabled =
593 session_options->bundle_enabled && 691 session_options->bundle_enabled &&
594 (session_options->has_audio() || session_options->has_video() || 692 (session_options->has_audio() || session_options->has_video() ||
595 session_options->has_data()); 693 session_options->has_data());
596 694
597 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
598 session_options->data_channel_type = cricket::DCT_SCTP;
599 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
600 session_options->data_channel_type = cricket::DCT_QUIC;
601 }
602
603 session_options->crypto_options = crypto_options_; 695 session_options->crypto_options = crypto_options_;
604 } 696 }
605 697
606 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { 698 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
607 // ParseConstraintsForAnswer is used to set some defaults. 699 // |recv_X| is true if callee wants to receive or the caller wants to send.
608 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); 700 bool recv_audio = recv_audio_ || send_audio_;
701 bool recv_video = recv_video_ || send_video_;
702 bool send_audio = false;
703 bool send_video = false;
609 704
610 AddStreamsToOptions(session_options); 705 AddExistingMediaSectionsAndSendersToOptions(
706 session_options, send_audio, recv_audio, send_video, recv_video);
707
611 session_options->bundle_enabled = 708 session_options->bundle_enabled =
612 session_options->bundle_enabled && 709 session_options->bundle_enabled &&
613 (session_options->has_audio() || session_options->has_video() || 710 (session_options->has_audio() || session_options->has_video() ||
614 session_options->has_data()); 711 session_options->has_data());
615 712
616 if (session_->data_channel_type() != cricket::DCT_RTP) { 713 if (session_->data_channel_type() != cricket::DCT_RTP) {
617 session_options->data_channel_type = session_->data_channel_type(); 714 session_options->data_channel_type = session_->data_channel_type();
618 } 715 }
619 716
620 session_options->crypto_options = crypto_options_; 717 session_options->crypto_options = crypto_options_;
621 } 718 }
622 719
720 void GetOptionsForAudioOnlyRemoteOffer(
721 cricket::MediaSessionOptions* session_options) {
722 recv_audio_ = true;
723 recv_video_ = false;
724 GetOptionsForRemoteOffer(session_options);
725 }
726
727 void GetOptionsForRemoteOffer(cricket::MediaSessionOptions* session_options) {
Taylor Brandstetter 2017/08/05 00:39:10 This method is what still confuses me; it uses a l
Zhi Huang 2017/08/09 00:54:51 I modified these tests a bit to make it easier to
728 AddMediaSectionsAndSendersToOptions(session_options, recv_audio_,
729 recv_video_);
730 session_options->bundle_enabled =
731 (session_options->has_audio() || session_options->has_video() ||
732 session_options->has_data());
733
734 if (session_->data_channel_type() != cricket::DCT_RTP) {
735 session_options->data_channel_type = session_->data_channel_type();
736 }
737
738 session_options->crypto_options = crypto_options_;
739 }
740
623 // Creates a local offer and applies it. Starts ICE. 741 // Creates a local offer and applies it. Starts ICE.
624 // Call SendAudioVideoStreamX() before this function 742 // Call SendAudioVideoStreamX() before this function
625 // to decide which streams to create. 743 // to decide which streams to create.
626 void InitiateCall() { 744 void InitiateCall() {
627 SessionDescriptionInterface* offer = CreateOffer(); 745 SessionDescriptionInterface* offer = CreateOffer();
628 SetLocalDescriptionWithoutError(offer); 746 SetLocalDescriptionWithoutError(offer);
629 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != 747 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
630 observer_.ice_gathering_state_, 748 observer_.ice_gathering_state_,
631 kIceCandidatesTimeout); 749 kIceCandidatesTimeout);
632 } 750 }
633 751
634 SessionDescriptionInterface* CreateOffer() { 752 SessionDescriptionInterface* CreateOffer() {
635 PeerConnectionInterface::RTCOfferAnswerOptions options; 753 PeerConnectionInterface::RTCOfferAnswerOptions options;
636 options.offer_to_receive_audio = 754 options.offer_to_receive_audio =
637 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; 755 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
638
639 return CreateOffer(options); 756 return CreateOffer(options);
640 } 757 }
641 758
642 SessionDescriptionInterface* CreateOffer( 759 SessionDescriptionInterface* CreateOffer(
643 const PeerConnectionInterface::RTCOfferAnswerOptions options) { 760 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
644 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> 761 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
645 observer = new WebRtcSessionCreateSDPObserverForTest(); 762 observer = new WebRtcSessionCreateSDPObserverForTest();
646 cricket::MediaSessionOptions session_options; 763 cricket::MediaSessionOptions session_options;
647 GetOptionsForOffer(options, &session_options); 764 GetOptionsForOffer(options, &session_options);
648 session_->CreateOffer(observer, options, session_options); 765 session_->CreateOffer(observer, options, session_options);
649 EXPECT_TRUE_WAIT( 766 EXPECT_TRUE_WAIT(
650 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, 767 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
651 2000); 768 2000);
652 return observer->ReleaseDescription(); 769 return observer->ReleaseDescription();
653 } 770 }
654 771
655 SessionDescriptionInterface* CreateAnswer( 772 SessionDescriptionInterface* CreateAnswer(
656 const cricket::MediaSessionOptions& options) { 773 const cricket::MediaSessionOptions& options) {
657 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer 774 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
658 = new WebRtcSessionCreateSDPObserverForTest(); 775 = new WebRtcSessionCreateSDPObserverForTest();
659 cricket::MediaSessionOptions session_options = options; 776 cricket::MediaSessionOptions session_options = options;
660 GetOptionsForAnswer(&session_options); 777 GetOptionsForAnswer(&session_options);
661 // Overwrite recv_audio and recv_video with passed-in values.
662 session_options.recv_video = options.recv_video;
663 session_options.recv_audio = options.recv_audio;
664 session_->CreateAnswer(observer, session_options); 778 session_->CreateAnswer(observer, session_options);
665 EXPECT_TRUE_WAIT( 779 EXPECT_TRUE_WAIT(
666 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, 780 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
667 2000); 781 2000);
668 return observer->ReleaseDescription(); 782 return observer->ReleaseDescription();
669 } 783 }
670 784
671 SessionDescriptionInterface* CreateAnswer() { 785 SessionDescriptionInterface* CreateAnswer() {
672 cricket::MediaSessionOptions options; 786 cricket::MediaSessionOptions options;
673 options.recv_video = true; 787 options.bundle_enabled = true;
674 options.recv_audio = true;
675 return CreateAnswer(options); 788 return CreateAnswer(options);
676 } 789 }
677 790
678 bool ChannelsExist() const { 791 bool ChannelsExist() const {
679 return (session_->voice_channel() != NULL && 792 return (session_->voice_channel() != NULL &&
680 session_->video_channel() != NULL); 793 session_->video_channel() != NULL);
681 } 794 }
682 795
683 void VerifyCryptoParams(const cricket::SessionDescription* sdp, 796 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
684 bool gcm_enabled = false) { 797 bool gcm_enabled = false) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 ASSERT_TRUE(audio != NULL); 895 ASSERT_TRUE(audio != NULL);
783 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL); 896 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
784 const TransportInfo* video = sdp->GetTransportInfoByName("video"); 897 const TransportInfo* video = sdp->GetTransportInfoByName("video");
785 ASSERT_TRUE(video != NULL); 898 ASSERT_TRUE(video != NULL);
786 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL); 899 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
787 } 900 }
788 901
789 void VerifyAnswerFromNonCryptoOffer() { 902 void VerifyAnswerFromNonCryptoOffer() {
790 // Create an SDP without Crypto. 903 // Create an SDP without Crypto.
791 cricket::MediaSessionOptions options; 904 cricket::MediaSessionOptions options;
792 options.recv_video = true; 905 GetOptionsForRemoteOffer(&options);
793 JsepSessionDescription* offer( 906 JsepSessionDescription* offer(
794 CreateRemoteOffer(options, cricket::SEC_DISABLED)); 907 CreateRemoteOffer(options, cricket::SEC_DISABLED));
795 ASSERT_TRUE(offer != NULL); 908 ASSERT_TRUE(offer != NULL);
796 VerifyNoCryptoParams(offer->description(), false); 909 VerifyNoCryptoParams(offer->description(), false);
797 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, 910 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
798 offer); 911 offer);
799 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(); 912 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
800 // Answer should be NULL as no crypto params in offer. 913 // Answer should be NULL as no crypto params in offer.
801 ASSERT_TRUE(answer == NULL); 914 ASSERT_TRUE(answer == NULL);
802 } 915 }
803 916
804 void VerifyAnswerFromCryptoOffer() { 917 void VerifyAnswerFromCryptoOffer() {
805 cricket::MediaSessionOptions options; 918 cricket::MediaSessionOptions options;
806 options.recv_video = true; 919 GetOptionsForRemoteOffer(&options);
807 options.bundle_enabled = true; 920 options.bundle_enabled = true;
808 std::unique_ptr<JsepSessionDescription> offer( 921 std::unique_ptr<JsepSessionDescription> offer(
809 CreateRemoteOffer(options, cricket::SEC_REQUIRED)); 922 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
810 ASSERT_TRUE(offer.get() != NULL); 923 ASSERT_TRUE(offer.get() != NULL);
811 VerifyCryptoParams(offer->description()); 924 VerifyCryptoParams(offer->description());
812 SetRemoteDescriptionWithoutError(offer.release()); 925 SetRemoteDescriptionWithoutError(offer.release());
813 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); 926 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
814 ASSERT_TRUE(answer.get() != NULL); 927 ASSERT_TRUE(answer.get() != NULL);
815 VerifyCryptoParams(answer->description()); 928 VerifyCryptoParams(answer->description());
816 } 929 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 SessionDescriptionInterface* desc) { 1061 SessionDescriptionInterface* desc) {
949 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, 1062 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
950 expected_error, desc); 1063 expected_error, desc);
951 } 1064 }
952 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error, 1065 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
953 SessionDescriptionInterface* desc) { 1066 SessionDescriptionInterface* desc) {
954 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer, 1067 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
955 expected_error, desc); 1068 expected_error, desc);
956 } 1069 }
957 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { 1070 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
958 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL)); 1071 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
Zhi Huang 2017/08/09 00:54:51 I would change this to ASSERT so that the test wou
959 } 1072 }
960 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, 1073 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
961 WebRtcSession::State expected_state) { 1074 WebRtcSession::State expected_state) {
962 SetRemoteDescriptionWithoutError(desc); 1075 SetRemoteDescriptionWithoutError(desc);
963 EXPECT_EQ(expected_state, session_->state()); 1076 EXPECT_EQ(expected_state, session_->state());
964 } 1077 }
965 void SetRemoteDescriptionExpectError(const std::string& action, 1078 void SetRemoteDescriptionExpectError(const std::string& action,
966 const std::string& expected_error, 1079 const std::string& expected_error,
967 SessionDescriptionInterface* desc) { 1080 SessionDescriptionInterface* desc) {
968 std::string error; 1081 std::string error;
(...skipping 16 matching lines...) Expand all
985 void SetRemoteDescriptionAnswerExpectError( 1098 void SetRemoteDescriptionAnswerExpectError(
986 const std::string& expected_error, SessionDescriptionInterface* desc) { 1099 const std::string& expected_error, SessionDescriptionInterface* desc) {
987 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer, 1100 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
988 expected_error, desc); 1101 expected_error, desc);
989 } 1102 }
990 1103
991 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer, 1104 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
992 SessionDescriptionInterface** nocrypto_answer) { 1105 SessionDescriptionInterface** nocrypto_answer) {
993 // Create a SDP without Crypto. 1106 // Create a SDP without Crypto.
994 cricket::MediaSessionOptions options; 1107 cricket::MediaSessionOptions options;
995 options.recv_video = true; 1108 GetOptionsForRemoteOffer(&options);
996 options.bundle_enabled = true; 1109 options.bundle_enabled = true;
997 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); 1110 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
998 ASSERT_TRUE(*offer != NULL); 1111 ASSERT_TRUE(*offer != NULL);
999 VerifyCryptoParams((*offer)->description()); 1112 VerifyCryptoParams((*offer)->description());
1000 1113
1001 *nocrypto_answer = CreateRemoteAnswer(*offer, options, 1114 cricket::MediaSessionOptions answer_options;
1002 cricket::SEC_DISABLED); 1115 GetOptionsForAnswer(&answer_options);
Taylor Brandstetter 2017/08/05 00:39:10 I also don't see how GetOptionsForAnswer works for
Zhi Huang 2017/08/09 00:54:51 I added another helper method for remote answer op
1116 *nocrypto_answer =
1117 CreateRemoteAnswer(*offer, answer_options, cricket::SEC_DISABLED);
1003 EXPECT_TRUE(*nocrypto_answer != NULL); 1118 EXPECT_TRUE(*nocrypto_answer != NULL);
1004 } 1119 }
1005 1120
1006 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer, 1121 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1007 SessionDescriptionInterface** nodtls_answer) { 1122 SessionDescriptionInterface** nodtls_answer) {
1008 cricket::MediaSessionOptions options; 1123 cricket::MediaSessionOptions options;
1009 options.recv_video = true; 1124 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
1125 cricket::MD_RECVONLY, !kStopped, &options);
1126 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
1127 cricket::MD_RECVONLY, !kStopped, &options);
1010 options.bundle_enabled = true; 1128 options.bundle_enabled = true;
1011 1129
1012 std::unique_ptr<SessionDescriptionInterface> temp_offer( 1130 std::unique_ptr<SessionDescriptionInterface> temp_offer(
1013 CreateRemoteOffer(options, cricket::SEC_ENABLED)); 1131 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1014 1132
1015 *nodtls_answer = 1133 *nodtls_answer =
1016 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); 1134 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1017 EXPECT_TRUE(*nodtls_answer != NULL); 1135 EXPECT_TRUE(*nodtls_answer != NULL);
1018 VerifyFingerprintStatus((*nodtls_answer)->description(), false); 1136 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1019 VerifyCryptoParams((*nodtls_answer)->description()); 1137 VerifyCryptoParams((*nodtls_answer)->description());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 cricket::MediaSessionOptions options, 1179 cricket::MediaSessionOptions options,
1062 const SessionDescriptionInterface* current_desc) { 1180 const SessionDescriptionInterface* current_desc) {
1063 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, 1181 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1064 kSessionVersion, current_desc); 1182 kSessionVersion, current_desc);
1065 } 1183 }
1066 1184
1067 JsepSessionDescription* CreateRemoteOfferWithSctpPort( 1185 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1068 const char* sctp_stream_name, int new_port, 1186 const char* sctp_stream_name, int new_port,
1069 cricket::MediaSessionOptions options) { 1187 cricket::MediaSessionOptions options) {
1070 options.data_channel_type = cricket::DCT_SCTP; 1188 options.data_channel_type = cricket::DCT_SCTP;
1071 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel", 1189 GetOptionsForRemoteOffer(&options);
1072 sctp_stream_name);
1073 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); 1190 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1074 } 1191 }
1075 1192
1076 // Takes ownership of offer_basis (and deletes it). 1193 // Takes ownership of offer_basis (and deletes it).
1077 JsepSessionDescription* ChangeSDPSctpPort( 1194 JsepSessionDescription* ChangeSDPSctpPort(
1078 int new_port, webrtc::SessionDescriptionInterface *offer_basis) { 1195 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1079 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new 1196 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1080 // SessionDescription from the mutated string. 1197 // SessionDescription from the mutated string.
1081 const char* default_port_str = "5000"; 1198 const char* default_port_str = "5000";
1082 char new_port_str[16]; 1199 char new_port_str[16];
1083 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port); 1200 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
1084 std::string offer_str; 1201 std::string offer_str;
1085 offer_basis->ToString(&offer_str); 1202 offer_basis->ToString(&offer_str);
1086 rtc::replace_substrs(default_port_str, strlen(default_port_str), 1203 rtc::replace_substrs(default_port_str, strlen(default_port_str),
1087 new_port_str, strlen(new_port_str), 1204 new_port_str, strlen(new_port_str),
1088 &offer_str); 1205 &offer_str);
1089 JsepSessionDescription* offer = new JsepSessionDescription( 1206 JsepSessionDescription* offer = new JsepSessionDescription(
1090 offer_basis->type()); 1207 offer_basis->type());
1091 delete offer_basis; 1208 delete offer_basis;
1092 offer->Initialize(offer_str, NULL); 1209 offer->Initialize(offer_str, NULL);
1093 return offer; 1210 return offer;
1094 } 1211 }
1095 1212
1096 // Create a remote offer. Call SendAudioVideoStreamX() 1213 // Create a remote offer. Call SendAudioVideoStreamX()
1097 // before this function to decide which streams to create. 1214 // before this function to decide which streams to create.
1098 JsepSessionDescription* CreateRemoteOffer() { 1215 JsepSessionDescription* CreateRemoteOffer() {
1099 cricket::MediaSessionOptions options; 1216 cricket::MediaSessionOptions options;
1100 GetOptionsForAnswer(&options); 1217 GetOptionsForRemoteOffer(&options);
1101 return CreateRemoteOffer(options, session_->remote_description()); 1218 return CreateRemoteOffer(options, session_->remote_description());
1102 } 1219 }
1103 1220
1104 JsepSessionDescription* CreateRemoteAnswer( 1221 JsepSessionDescription* CreateRemoteAnswer(
1105 const SessionDescriptionInterface* offer, 1222 const SessionDescriptionInterface* offer,
1106 cricket::MediaSessionOptions options, 1223 cricket::MediaSessionOptions options,
1107 cricket::SecurePolicy policy) { 1224 cricket::SecurePolicy policy) {
1108 desc_factory_->set_secure(policy); 1225 desc_factory_->set_secure(policy);
1109 const std::string session_id = 1226 const std::string session_id =
1110 rtc::ToString(rtc::CreateRandomId64()); 1227 rtc::ToString(rtc::CreateRandomId64());
(...skipping 14 matching lines...) Expand all
1125 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); 1242 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1126 } 1243 }
1127 1244
1128 // Creates an answer session description. 1245 // Creates an answer session description.
1129 // Call SendAudioVideoStreamX() before this function 1246 // Call SendAudioVideoStreamX() before this function
1130 // to decide which streams to create. 1247 // to decide which streams to create.
1131 JsepSessionDescription* CreateRemoteAnswer( 1248 JsepSessionDescription* CreateRemoteAnswer(
1132 const SessionDescriptionInterface* offer) { 1249 const SessionDescriptionInterface* offer) {
1133 cricket::MediaSessionOptions options; 1250 cricket::MediaSessionOptions options;
1134 GetOptionsForAnswer(&options); 1251 GetOptionsForAnswer(&options);
1252 options.bundle_enabled = true;
1135 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); 1253 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1136 } 1254 }
1137 1255
1138 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { 1256 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
1139 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); 1257 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1140 Init(); 1258 Init();
1141 SendAudioVideoStream1(); 1259 SendAudioVideoStream1();
1142 1260
1143 PeerConnectionInterface::RTCOfferAnswerOptions options; 1261 PeerConnectionInterface::RTCOfferAnswerOptions options;
1144 options.use_rtp_mux = bundle; 1262 options.use_rtp_mux = bundle;
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 InitWithDtlsIdentityGenFail(); 1566 InitWithDtlsIdentityGenFail();
1449 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type); 1567 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1450 } 1568 }
1451 1569
1452 void VerifyMultipleAsyncCreateDescriptionAfterInit( 1570 void VerifyMultipleAsyncCreateDescriptionAfterInit(
1453 bool success, CreateSessionDescriptionRequest::Type type) { 1571 bool success, CreateSessionDescriptionRequest::Type type) {
1454 RTC_CHECK(session_); 1572 RTC_CHECK(session_);
1455 SetFactoryDtlsSrtp(); 1573 SetFactoryDtlsSrtp();
1456 if (type == CreateSessionDescriptionRequest::kAnswer) { 1574 if (type == CreateSessionDescriptionRequest::kAnswer) {
1457 cricket::MediaSessionOptions options; 1575 cricket::MediaSessionOptions options;
1576 GetOptionsForRemoteOffer(&options);
1458 std::unique_ptr<JsepSessionDescription> offer( 1577 std::unique_ptr<JsepSessionDescription> offer(
1459 CreateRemoteOffer(options, cricket::SEC_DISABLED)); 1578 CreateRemoteOffer(options, cricket::SEC_DISABLED));
1460 ASSERT_TRUE(offer.get() != NULL); 1579 ASSERT_TRUE(offer.get() != NULL);
1461 SetRemoteDescriptionWithoutError(offer.release()); 1580 SetRemoteDescriptionWithoutError(offer.release());
1462 } 1581 }
1463 1582
1464 PeerConnectionInterface::RTCOfferAnswerOptions options; 1583 PeerConnectionInterface::RTCOfferAnswerOptions options;
1465 cricket::MediaSessionOptions session_options; 1584 cricket::MediaSessionOptions offer_session_options;
1585 cricket::MediaSessionOptions answer_session_options;
1586 GetOptionsForOffer(options, &offer_session_options);
1587 GetOptionsForAnswer(&answer_session_options);
1466 const int kNumber = 3; 1588 const int kNumber = 3;
1467 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> 1589 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
1468 observers[kNumber]; 1590 observers[kNumber];
1469 for (int i = 0; i < kNumber; ++i) { 1591 for (int i = 0; i < kNumber; ++i) {
1470 observers[i] = new WebRtcSessionCreateSDPObserverForTest(); 1592 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1471 if (type == CreateSessionDescriptionRequest::kOffer) { 1593 if (type == CreateSessionDescriptionRequest::kOffer) {
1472 session_->CreateOffer(observers[i], options, session_options); 1594 session_->CreateOffer(observers[i], options, offer_session_options);
1473 } else { 1595 } else {
1474 session_->CreateAnswer(observers[i], session_options); 1596 session_->CreateAnswer(observers[i], answer_session_options);
1475 } 1597 }
1476 } 1598 }
1477 1599
1478 WebRtcSessionCreateSDPObserverForTest::State expected_state = 1600 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1479 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded : 1601 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1480 WebRtcSessionCreateSDPObserverForTest::kFailed; 1602 WebRtcSessionCreateSDPObserverForTest::kFailed;
1481 1603
1482 for (int i = 0; i < kNumber; ++i) { 1604 for (int i = 0; i < kNumber; ++i) {
1483 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000); 1605 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1484 if (success) { 1606 if (success) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 std::unique_ptr<WebRtcSessionForTest> session_; 1646 std::unique_ptr<WebRtcSessionForTest> session_;
1525 MockIceObserver observer_; 1647 MockIceObserver observer_;
1526 cricket::FakeVideoMediaChannel* video_channel_; 1648 cricket::FakeVideoMediaChannel* video_channel_;
1527 cricket::FakeVoiceMediaChannel* voice_channel_; 1649 cricket::FakeVoiceMediaChannel* voice_channel_;
1528 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; 1650 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
1529 // The following flags affect options created for CreateOffer/CreateAnswer. 1651 // The following flags affect options created for CreateOffer/CreateAnswer.
1530 bool send_stream_1_ = false; 1652 bool send_stream_1_ = false;
1531 bool send_stream_2_ = false; 1653 bool send_stream_2_ = false;
1532 bool send_audio_ = false; 1654 bool send_audio_ = false;
1533 bool send_video_ = false; 1655 bool send_video_ = false;
1656 bool recv_audio_ = true;
1657 bool recv_video_ = true;
1658 std::vector<cricket::MediaDescriptionOptions> offered_media_sections_;
1534 rtc::scoped_refptr<DataChannel> data_channel_; 1659 rtc::scoped_refptr<DataChannel> data_channel_;
1535 // Last values received from data channel creation signal. 1660 // Last values received from data channel creation signal.
1536 std::string last_data_channel_label_; 1661 std::string last_data_channel_label_;
1537 InternalDataChannelInit last_data_channel_config_; 1662 InternalDataChannelInit last_data_channel_config_;
1538 rtc::CryptoOptions crypto_options_; 1663 rtc::CryptoOptions crypto_options_;
1539 }; 1664 };
1540 1665
1541 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { 1666 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1542 InitWithDtls(GetParam()); 1667 InitWithDtls(GetParam());
1543 // SDES is disabled when DTLS is on. 1668 // SDES is disabled when DTLS is on.
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 // answer without SDES or DTLS --> success 1888 // answer without SDES or DTLS --> success
1764 // TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local 1889 // TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1765 // answer without SDES or DTLS --> success 1890 // answer without SDES or DTLS --> success
1766 // 1891 //
1767 1892
1768 // Test that we return a failure when applying a remote/local offer that doesn't 1893 // Test that we return a failure when applying a remote/local offer that doesn't
1769 // have cryptos enabled when DTLS is off. 1894 // have cryptos enabled when DTLS is off.
1770 TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) { 1895 TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
1771 Init(); 1896 Init();
1772 cricket::MediaSessionOptions options; 1897 cricket::MediaSessionOptions options;
1773 options.recv_video = true; 1898 GetOptionsForRemoteOffer(&options);
1774 JsepSessionDescription* offer = CreateRemoteOffer( 1899 JsepSessionDescription* offer = CreateRemoteOffer(
1775 options, cricket::SEC_DISABLED); 1900 options, cricket::SEC_DISABLED);
1776 ASSERT_TRUE(offer != NULL); 1901 ASSERT_TRUE(offer != NULL);
1777 VerifyNoCryptoParams(offer->description(), false); 1902 VerifyNoCryptoParams(offer->description(), false);
1778 // SetRemoteDescription and SetLocalDescription will take the ownership of 1903 // SetRemoteDescription and SetLocalDescription will take the ownership of
1779 // the offer. 1904 // the offer.
1780 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); 1905 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
1781 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); 1906 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1782 ASSERT_TRUE(offer != NULL); 1907 ASSERT_TRUE(offer != NULL);
1783 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); 1908 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
(...skipping 25 matching lines...) Expand all
1809 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer); 1934 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
1810 } 1935 }
1811 1936
1812 // Test that we accept an offer with a DTLS fingerprint when DTLS is on 1937 // Test that we accept an offer with a DTLS fingerprint when DTLS is on
1813 // and that we return an answer with a DTLS fingerprint. 1938 // and that we return an answer with a DTLS fingerprint.
1814 TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) { 1939 TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
1815 SendAudioVideoStream1(); 1940 SendAudioVideoStream1();
1816 InitWithDtls(GetParam()); 1941 InitWithDtls(GetParam());
1817 SetFactoryDtlsSrtp(); 1942 SetFactoryDtlsSrtp();
1818 cricket::MediaSessionOptions options; 1943 cricket::MediaSessionOptions options;
1819 options.recv_video = true; 1944 GetOptionsForRemoteOffer(&options);
1820 JsepSessionDescription* offer = 1945 JsepSessionDescription* offer =
1821 CreateRemoteOffer(options, cricket::SEC_DISABLED); 1946 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1822 ASSERT_TRUE(offer != NULL); 1947 ASSERT_TRUE(offer != NULL);
1823 VerifyFingerprintStatus(offer->description(), true); 1948 VerifyFingerprintStatus(offer->description(), true);
1824 VerifyNoCryptoParams(offer->description(), true); 1949 VerifyNoCryptoParams(offer->description(), true);
1825 1950
1826 // SetRemoteDescription will take the ownership of the offer. 1951 // SetRemoteDescription will take the ownership of the offer.
1827 SetRemoteDescriptionWithoutError(offer); 1952 SetRemoteDescriptionWithoutError(offer);
1828 1953
1829 // Verify that we get a crypto fingerprint in the answer. 1954 // Verify that we get a crypto fingerprint in the answer.
(...skipping 18 matching lines...) Expand all
1848 SessionDescriptionInterface* offer = CreateOffer(); 1973 SessionDescriptionInterface* offer = CreateOffer();
1849 ASSERT_TRUE(offer != NULL); 1974 ASSERT_TRUE(offer != NULL);
1850 VerifyFingerprintStatus(offer->description(), true); 1975 VerifyFingerprintStatus(offer->description(), true);
1851 // Check that we don't have an a=crypto line in the offer. 1976 // Check that we don't have an a=crypto line in the offer.
1852 VerifyNoCryptoParams(offer->description(), true); 1977 VerifyNoCryptoParams(offer->description(), true);
1853 1978
1854 // Now set the local description, which should work, even without a=crypto. 1979 // Now set the local description, which should work, even without a=crypto.
1855 SetLocalDescriptionWithoutError(offer); 1980 SetLocalDescriptionWithoutError(offer);
1856 1981
1857 cricket::MediaSessionOptions options; 1982 cricket::MediaSessionOptions options;
1858 options.recv_video = true; 1983 GetOptionsForAnswer(&options);
1859 JsepSessionDescription* answer = 1984 JsepSessionDescription* answer =
1860 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); 1985 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1861 ASSERT_TRUE(answer != NULL); 1986 ASSERT_TRUE(answer != NULL);
1862 VerifyFingerprintStatus(answer->description(), true); 1987 VerifyFingerprintStatus(answer->description(), true);
1863 VerifyNoCryptoParams(answer->description(), true); 1988 VerifyNoCryptoParams(answer->description(), true);
1864 1989
1865 // SetRemoteDescription will take the ownership of the answer. 1990 // SetRemoteDescription will take the ownership of the answer.
1866 SetRemoteDescriptionWithoutError(answer); 1991 SetRemoteDescriptionWithoutError(answer);
1867 } 1992 }
1868 1993
1869 // Test that if we support DTLS and the other side didn't offer a fingerprint, 1994 // Test that if we support DTLS and the other side didn't offer a fingerprint,
1870 // we will fail to set the remote description. 1995 // we will fail to set the remote description.
1871 TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) { 1996 TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
1872 InitWithDtls(GetParam()); 1997 InitWithDtls(GetParam());
1873 cricket::MediaSessionOptions options; 1998 cricket::MediaSessionOptions options;
1874 options.recv_video = true; 1999 GetOptionsForRemoteOffer(&options);
1875 options.bundle_enabled = true; 2000 options.bundle_enabled = true;
1876 JsepSessionDescription* offer = CreateRemoteOffer( 2001 JsepSessionDescription* offer = CreateRemoteOffer(
1877 options, cricket::SEC_REQUIRED); 2002 options, cricket::SEC_REQUIRED);
1878 ASSERT_TRUE(offer != NULL); 2003 ASSERT_TRUE(offer != NULL);
1879 VerifyFingerprintStatus(offer->description(), false); 2004 VerifyFingerprintStatus(offer->description(), false);
1880 VerifyCryptoParams(offer->description()); 2005 VerifyCryptoParams(offer->description());
1881 2006
1882 // SetRemoteDescription will take the ownership of the offer. 2007 // SetRemoteDescription will take the ownership of the offer.
1883 SetRemoteDescriptionOfferExpectError( 2008 SetRemoteDescriptionOfferExpectError(
1884 kSdpWithoutDtlsFingerprint, offer); 2009 kSdpWithoutDtlsFingerprint, offer);
(...skipping 17 matching lines...) Expand all
1902 SetRemoteDescriptionWithoutError(offer); 2027 SetRemoteDescriptionWithoutError(offer);
1903 SetLocalDescriptionAnswerExpectError( 2028 SetLocalDescriptionAnswerExpectError(
1904 kSdpWithoutDtlsFingerprint, answer); 2029 kSdpWithoutDtlsFingerprint, answer);
1905 } 2030 }
1906 2031
1907 // Test that we return a failure when applying a remote answer that doesn't have 2032 // Test that we return a failure when applying a remote answer that doesn't have
1908 // a DTLS fingerprint when DTLS is required. 2033 // a DTLS fingerprint when DTLS is required.
1909 TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) { 2034 TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
1910 InitWithDtls(GetParam()); 2035 InitWithDtls(GetParam());
1911 SessionDescriptionInterface* offer = CreateOffer(); 2036 SessionDescriptionInterface* offer = CreateOffer();
1912 cricket::MediaSessionOptions options; 2037 cricket::MediaSessionOptions offer_options;
1913 options.recv_video = true; 2038 GetOptionsForRemoteOffer(&offer_options);
2039
1914 std::unique_ptr<SessionDescriptionInterface> temp_offer( 2040 std::unique_ptr<SessionDescriptionInterface> temp_offer(
1915 CreateRemoteOffer(options, cricket::SEC_ENABLED)); 2041 CreateRemoteOffer(offer_options, cricket::SEC_ENABLED));
1916 JsepSessionDescription* answer = 2042
1917 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); 2043 cricket::MediaSessionOptions answer_options;
2044 GetOptionsForAnswer(&answer_options);
2045 JsepSessionDescription* answer = CreateRemoteAnswer(
2046 temp_offer.get(), answer_options, cricket::SEC_ENABLED);
1918 2047
1919 // SetRemoteDescription and SetLocalDescription will take the ownership of 2048 // SetRemoteDescription and SetLocalDescription will take the ownership of
1920 // the offer and answer. 2049 // the offer and answer.
1921 SetLocalDescriptionWithoutError(offer); 2050 SetLocalDescriptionWithoutError(offer);
1922 SetRemoteDescriptionAnswerExpectError( 2051 SetRemoteDescriptionAnswerExpectError(
1923 kSdpWithoutDtlsFingerprint, answer); 2052 kSdpWithoutDtlsFingerprint, answer);
1924 } 2053 }
1925 2054
1926 // Test that we create a local offer without SDES or DTLS and accept a remote 2055 // Test that we create a local offer without SDES or DTLS and accept a remote
1927 // answer without SDES or DTLS when encryption is disabled. 2056 // answer without SDES or DTLS when encryption is disabled.
1928 TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) { 2057 TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1929 SendAudioVideoStream1(); 2058 SendAudioVideoStream1();
1930 options_.disable_encryption = true; 2059 options_.disable_encryption = true;
1931 InitWithDtls(GetParam()); 2060 InitWithDtls(GetParam());
1932 2061
1933 // Verify that we get a crypto fingerprint in the answer. 2062 // Verify that we get a crypto fingerprint in the answer.
1934 SessionDescriptionInterface* offer = CreateOffer(); 2063 SessionDescriptionInterface* offer = CreateOffer();
1935 ASSERT_TRUE(offer != NULL); 2064 ASSERT_TRUE(offer != NULL);
1936 VerifyFingerprintStatus(offer->description(), false); 2065 VerifyFingerprintStatus(offer->description(), false);
1937 // Check that we don't have an a=crypto line in the offer. 2066 // Check that we don't have an a=crypto line in the offer.
1938 VerifyNoCryptoParams(offer->description(), false); 2067 VerifyNoCryptoParams(offer->description(), false);
1939 2068
1940 // Now set the local description, which should work, even without a=crypto. 2069 // Now set the local description, which should work, even without a=crypto.
1941 SetLocalDescriptionWithoutError(offer); 2070 SetLocalDescriptionWithoutError(offer);
1942 2071
1943 cricket::MediaSessionOptions options; 2072 cricket::MediaSessionOptions options;
1944 options.recv_video = true; 2073 GetOptionsForAnswer(&options);
1945 JsepSessionDescription* answer = 2074 JsepSessionDescription* answer =
1946 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); 2075 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1947 ASSERT_TRUE(answer != NULL); 2076 ASSERT_TRUE(answer != NULL);
1948 VerifyFingerprintStatus(answer->description(), false); 2077 VerifyFingerprintStatus(answer->description(), false);
1949 VerifyNoCryptoParams(answer->description(), false); 2078 VerifyNoCryptoParams(answer->description(), false);
1950 2079
1951 // SetRemoteDescription will take the ownership of the answer. 2080 // SetRemoteDescription will take the ownership of the answer.
1952 SetRemoteDescriptionWithoutError(answer); 2081 SetRemoteDescriptionWithoutError(answer);
1953 } 2082 }
1954 2083
1955 // Test that we create a local answer without SDES or DTLS and accept a remote 2084 // Test that we create a local answer without SDES or DTLS and accept a remote
1956 // offer without SDES or DTLS when encryption is disabled. 2085 // offer without SDES or DTLS when encryption is disabled.
1957 TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) { 2086 TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1958 options_.disable_encryption = true; 2087 options_.disable_encryption = true;
1959 InitWithDtls(GetParam()); 2088 InitWithDtls(GetParam());
1960 2089
1961 cricket::MediaSessionOptions options; 2090 cricket::MediaSessionOptions options;
1962 options.recv_video = true; 2091 GetOptionsForRemoteOffer(&options);
1963 JsepSessionDescription* offer = 2092 JsepSessionDescription* offer =
1964 CreateRemoteOffer(options, cricket::SEC_DISABLED); 2093 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1965 ASSERT_TRUE(offer != NULL); 2094 ASSERT_TRUE(offer != NULL);
1966 VerifyFingerprintStatus(offer->description(), false); 2095 VerifyFingerprintStatus(offer->description(), false);
1967 VerifyNoCryptoParams(offer->description(), false); 2096 VerifyNoCryptoParams(offer->description(), false);
1968 2097
1969 // SetRemoteDescription will take the ownership of the offer. 2098 // SetRemoteDescription will take the ownership of the offer.
1970 SetRemoteDescriptionWithoutError(offer); 2099 SetRemoteDescriptionWithoutError(offer);
1971 2100
1972 // Verify that we get a crypto fingerprint in the answer. 2101 // Verify that we get a crypto fingerprint in the answer.
(...skipping 12 matching lines...) Expand all
1985 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525 2114 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1986 TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) { 2115 TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1987 SendAudioVideoStream1(); 2116 SendAudioVideoStream1();
1988 InitWithDtls(GetParam()); 2117 InitWithDtls(GetParam());
1989 SetFactoryDtlsSrtp(); 2118 SetFactoryDtlsSrtp();
1990 2119
1991 SessionDescriptionInterface* offer = CreateOffer(); 2120 SessionDescriptionInterface* offer = CreateOffer();
1992 SetLocalDescriptionWithoutError(offer); 2121 SetLocalDescriptionWithoutError(offer);
1993 2122
1994 cricket::MediaSessionOptions options; 2123 cricket::MediaSessionOptions options;
1995 options.recv_video = true; 2124 GetOptionsForAnswer(&options);
1996 2125
1997 // First, negotiate different SSL roles. 2126 // First, negotiate different SSL roles.
1998 SessionDescriptionInterface* answer = 2127 SessionDescriptionInterface* answer =
1999 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); 2128 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2000 TransportInfo* audio_transport_info = 2129 TransportInfo* audio_transport_info =
2001 answer->description()->GetTransportInfoByName("audio"); 2130 answer->description()->GetTransportInfoByName("audio");
2002 audio_transport_info->description.connection_role = 2131 audio_transport_info->description.connection_role =
2003 cricket::CONNECTIONROLE_ACTIVE; 2132 cricket::CONNECTIONROLE_ACTIVE;
2004 TransportInfo* video_transport_info = 2133 TransportInfo* video_transport_info =
2005 answer->description()->GetTransportInfoByName("video"); 2134 answer->description()->GetTransportInfoByName("video");
2006 video_transport_info->description.connection_role = 2135 video_transport_info->description.connection_role =
2007 cricket::CONNECTIONROLE_PASSIVE; 2136 cricket::CONNECTIONROLE_PASSIVE;
2008 SetRemoteDescriptionWithoutError(answer); 2137 SetRemoteDescriptionWithoutError(answer);
2009 2138
2010 // Now create an offer in the reverse direction, and ensure the initial 2139 // Now create an offer in the reverse direction, and ensure the initial
2011 // offerer responds with an answer with correct SSL roles. 2140 // offerer responds with an answer with correct SSL roles.
2012 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, 2141 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2013 kSessionVersion, 2142 kSessionVersion,
2014 session_->remote_description()); 2143 session_->remote_description());
2015 SetRemoteDescriptionWithoutError(offer); 2144 SetRemoteDescriptionWithoutError(offer);
2016 2145
2017 answer = CreateAnswer(); 2146 cricket::MediaSessionOptions answer_options;
2147 answer_options.bundle_enabled = true;
2148 answer = CreateAnswer(answer_options);
2018 audio_transport_info = answer->description()->GetTransportInfoByName("audio"); 2149 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2019 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, 2150 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2020 audio_transport_info->description.connection_role); 2151 audio_transport_info->description.connection_role);
2021 video_transport_info = answer->description()->GetTransportInfoByName("video"); 2152 video_transport_info = answer->description()->GetTransportInfoByName("video");
2022 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, 2153 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2023 video_transport_info->description.connection_role); 2154 video_transport_info->description.connection_role);
2024 SetLocalDescriptionWithoutError(answer); 2155 SetLocalDescriptionWithoutError(answer);
2025 2156
2026 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of 2157 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2027 // audio is transferred over to video in the answer that completes the BUNDLE 2158 // audio is transferred over to video in the answer that completes the BUNDLE
2028 // negotiation. 2159 // negotiation.
2029 options.bundle_enabled = true; 2160 options.bundle_enabled = true;
2030 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, 2161 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2031 kSessionVersion, 2162 kSessionVersion,
2032 session_->remote_description()); 2163 session_->remote_description());
2033 SetRemoteDescriptionWithoutError(offer); 2164 SetRemoteDescriptionWithoutError(offer);
2034 answer = CreateAnswer(); 2165 answer = CreateAnswer(answer_options);
2035 audio_transport_info = answer->description()->GetTransportInfoByName("audio"); 2166 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2036 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, 2167 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2037 audio_transport_info->description.connection_role); 2168 audio_transport_info->description.connection_role);
2038 video_transport_info = answer->description()->GetTransportInfoByName("video"); 2169 video_transport_info = answer->description()->GetTransportInfoByName("video");
2039 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, 2170 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2040 video_transport_info->description.connection_role); 2171 video_transport_info->description.connection_role);
2041 SetLocalDescriptionWithoutError(answer); 2172 SetLocalDescriptionWithoutError(answer);
2042 } 2173 }
2043 2174
2044 TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) { 2175 TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 // is called. 2516 // is called.
2386 EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); 2517 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2387 EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); 2518 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2388 CreateAndSetRemoteOfferAndLocalAnswer(); 2519 CreateAndSetRemoteOfferAndLocalAnswer();
2389 // Wait until at least one local candidate has been collected. 2520 // Wait until at least one local candidate has been collected.
2390 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(), 2521 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2391 kIceCandidatesTimeout); 2522 kIceCandidatesTimeout);
2392 2523
2393 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer()); 2524 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2394 2525
2526 ASSERT_TRUE(local_offer);
2395 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL); 2527 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2396 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count()); 2528 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2397 2529
2398 SessionDescriptionInterface* remote_offer(CreateRemoteOffer()); 2530 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2399 SetRemoteDescriptionWithoutError(remote_offer); 2531 SetRemoteDescriptionWithoutError(remote_offer);
2400 SessionDescriptionInterface* answer = CreateAnswer(); 2532 SessionDescriptionInterface* answer = CreateAnswer();
2401 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL); 2533 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2402 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count()); 2534 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2403 SetLocalDescriptionWithoutError(answer); 2535 SetLocalDescriptionWithoutError(answer);
2404 } 2536 }
2405 2537
2406 // Verifies TransportProxy and media channels are created with content names 2538 // Verifies TransportProxy and media channels are created with content names
2407 // present in the SessionDescription. 2539 // present in the SessionDescription.
2408 TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { 2540 TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
2409 Init(); 2541 Init();
2410 SendAudioVideoStream1(); 2542 SendAudioVideoStream1();
2411 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); 2543 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2412 2544
2413 // CreateOffer creates session description with the content names "audio" and 2545 // CreateOffer creates session description with the content names "audio" and
2414 // "video". Goal is to modify these content names and verify transport 2546 // "video". Goal is to modify these content names and verify transport
2415 // channels 2547 // channels
2416 // in the WebRtcSession, as channels are created with the content names 2548 // in the WebRtcSession, as channels are created with the content names
2417 // present in SDP. 2549 // present in SDP.
2418 std::string sdp; 2550 std::string sdp;
2419 EXPECT_TRUE(offer->ToString(&sdp)); 2551 EXPECT_TRUE(offer->ToString(&sdp));
2420 const std::string kAudioMid = "a=mid:audio";
2421 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2422 const std::string kVideoMid = "a=mid:video";
2423 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2424
2425 // Replacing |audio| with |audio_content_name|.
2426 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
2427 kAudioMidReplaceStr.c_str(),
2428 kAudioMidReplaceStr.length(),
2429 &sdp);
2430 // Replacing |video| with |video_content_name|.
2431 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
2432 kVideoMidReplaceStr.c_str(),
2433 kVideoMidReplaceStr.length(),
2434 &sdp);
2435 2552
2436 SessionDescriptionInterface* modified_offer = 2553 SessionDescriptionInterface* modified_offer =
2437 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); 2554 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2438 2555
2439 SetRemoteDescriptionWithoutError(modified_offer); 2556 SetRemoteDescriptionWithoutError(modified_offer);
2440 2557
2441 SessionDescriptionInterface* answer = CreateAnswer(); 2558 cricket::MediaSessionOptions answer_options;
2559 answer_options.bundle_enabled = false;
2560 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
2442 SetLocalDescriptionWithoutError(answer); 2561 SetLocalDescriptionWithoutError(answer);
2443 2562
2444 rtc::PacketTransportInternal* voice_transport_channel = 2563 rtc::PacketTransportInternal* voice_transport_channel =
2445 session_->voice_rtp_transport_channel(); 2564 session_->voice_rtp_transport_channel();
2446 EXPECT_TRUE(voice_transport_channel != NULL); 2565 EXPECT_TRUE(voice_transport_channel != NULL);
2447 EXPECT_EQ(voice_transport_channel->debug_name(), 2566 EXPECT_EQ(voice_transport_channel->debug_name(),
2448 "audio_content_name " + 2567 "audio " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2449 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2450 rtc::PacketTransportInternal* video_transport_channel = 2568 rtc::PacketTransportInternal* video_transport_channel =
2451 session_->video_rtp_transport_channel(); 2569 session_->video_rtp_transport_channel();
2452 ASSERT_TRUE(video_transport_channel != NULL); 2570 ASSERT_TRUE(video_transport_channel != NULL);
2453 EXPECT_EQ(video_transport_channel->debug_name(), 2571 EXPECT_EQ(video_transport_channel->debug_name(),
2454 "video_content_name " + 2572 "video " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2455 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2456 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); 2573 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2457 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); 2574 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2458 } 2575 }
2459 2576
2460 // Test that an offer contains the correct media content descriptions based on 2577 // Test that an offer contains the correct media content descriptions based on
2461 // the send streams when no constraints have been set. 2578 // the send streams when no constraints have been set.
2462 TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { 2579 TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
2463 Init(); 2580 Init();
2464 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); 2581 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2465 2582
2466 ASSERT_TRUE(offer != NULL); 2583 ASSERT_TRUE(offer != NULL);
2467 const cricket::ContentInfo* content = 2584 const cricket::ContentInfo* content =
2468 cricket::GetFirstAudioContent(offer->description()); 2585 cricket::GetFirstAudioContent(offer->description());
2469 EXPECT_TRUE(content != NULL); 2586 ASSERT_TRUE(content != NULL);
2587 EXPECT_EQ(
2588 cricket::MD_RECVONLY,
2589 static_cast<const cricket::AudioContentDescription*>(content->description)
2590 ->direction());
2470 content = cricket::GetFirstVideoContent(offer->description()); 2591 content = cricket::GetFirstVideoContent(offer->description());
2471 EXPECT_TRUE(content == NULL); 2592 ASSERT_TRUE(content != NULL);
2593 EXPECT_EQ(
2594 cricket::MD_RECVONLY,
2595 static_cast<const cricket::VideoContentDescription*>(content->description)
2596 ->direction());
2472 } 2597 }
2473 2598
2474 // Test that an offer contains the correct media content descriptions based on 2599 // Test that an offer contains the correct media content descriptions based on
2475 // the send streams when no constraints have been set. 2600 // the send streams when no constraints have been set.
2476 TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { 2601 TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
2477 Init(); 2602 Init();
2478 // Test Audio only offer. 2603 // Test Audio only offer.
2479 SendAudioOnlyStream2(); 2604 SendAudioOnlyStream2();
2480 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); 2605 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2481 2606
2482 const cricket::ContentInfo* content = 2607 const cricket::ContentInfo* content =
2483 cricket::GetFirstAudioContent(offer->description()); 2608 cricket::GetFirstAudioContent(offer->description());
2484 EXPECT_TRUE(content != NULL); 2609 ASSERT_TRUE(content != NULL);
2610 EXPECT_EQ(
2611 cricket::MD_SENDRECV,
2612 static_cast<const cricket::AudioContentDescription*>(content->description)
2613 ->direction());
2485 content = cricket::GetFirstVideoContent(offer->description()); 2614 content = cricket::GetFirstVideoContent(offer->description());
2486 EXPECT_TRUE(content == NULL); 2615 ASSERT_TRUE(content != NULL);
2616 EXPECT_EQ(
2617 cricket::MD_RECVONLY,
2618 static_cast<const cricket::VideoContentDescription*>(content->description)
2619 ->direction());
2487 2620
2488 // Test Audio / Video offer. 2621 // Test Audio / Video offer.
2489 SendAudioVideoStream1(); 2622 SendAudioVideoStream1();
2490 offer.reset(CreateOffer()); 2623 offer.reset(CreateOffer());
2491 content = cricket::GetFirstAudioContent(offer->description()); 2624 content = cricket::GetFirstAudioContent(offer->description());
2492 EXPECT_TRUE(content != NULL); 2625 ASSERT_TRUE(content != NULL);
2626 EXPECT_EQ(
2627 cricket::MD_SENDRECV,
2628 static_cast<const cricket::AudioContentDescription*>(content->description)
2629 ->direction());
2630
2493 content = cricket::GetFirstVideoContent(offer->description()); 2631 content = cricket::GetFirstVideoContent(offer->description());
2494 EXPECT_TRUE(content != NULL); 2632 ASSERT_TRUE(content != NULL);
2633 EXPECT_EQ(
2634 cricket::MD_SENDRECV,
2635 static_cast<const cricket::VideoContentDescription*>(content->description)
2636 ->direction());
2495 } 2637 }
2496 2638
2497 // Test that an offer contains no media content descriptions if 2639 // Test that an offer contains no media content descriptions if
2498 // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. 2640 // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2499 TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { 2641 TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
2500 Init(); 2642 Init();
2501 PeerConnectionInterface::RTCOfferAnswerOptions options; 2643 PeerConnectionInterface::RTCOfferAnswerOptions options;
2502 options.offer_to_receive_audio = 0; 2644 options.offer_to_receive_audio = 0;
2503 options.offer_to_receive_video = 0; 2645 options.offer_to_receive_video = 0;
2504 2646
2505 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); 2647 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
2506 2648
2507 ASSERT_TRUE(offer != NULL); 2649 ASSERT_TRUE(offer != NULL);
2508 const cricket::ContentInfo* content = 2650 const cricket::ContentInfo* content =
2509 cricket::GetFirstAudioContent(offer->description()); 2651 cricket::GetFirstAudioContent(offer->description());
2510 EXPECT_TRUE(content == NULL); 2652 EXPECT_TRUE(content == NULL);
2511 content = cricket::GetFirstVideoContent(offer->description()); 2653 content = cricket::GetFirstVideoContent(offer->description());
2512 EXPECT_TRUE(content == NULL); 2654 EXPECT_TRUE(content == NULL);
2513 } 2655 }
2514 2656
2515 // Test that an offer contains only audio media content descriptions if 2657 // Test that an offer contains only audio media content descriptions if
2516 // kOfferToReceiveAudio constraints are set to true. 2658 // kOfferToReceiveAudio constraints are set to true.
2517 TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { 2659 TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
2518 Init(); 2660 Init();
2519 PeerConnectionInterface::RTCOfferAnswerOptions options; 2661 PeerConnectionInterface::RTCOfferAnswerOptions options;
2520 options.offer_to_receive_audio = 2662 options.offer_to_receive_audio =
2521 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; 2663 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2664 options.offer_to_receive_video = 0;
2522 2665
2523 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); 2666 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
2524 2667
2525 const cricket::ContentInfo* content = 2668 const cricket::ContentInfo* content =
2526 cricket::GetFirstAudioContent(offer->description()); 2669 cricket::GetFirstAudioContent(offer->description());
2527 EXPECT_TRUE(content != NULL); 2670 EXPECT_TRUE(content != NULL);
2528 content = cricket::GetFirstVideoContent(offer->description()); 2671 content = cricket::GetFirstVideoContent(offer->description());
2529 EXPECT_TRUE(content == NULL); 2672 EXPECT_TRUE(content == NULL);
2530 } 2673 }
2531 2674
(...skipping 14 matching lines...) Expand all
2546 cricket::GetFirstAudioContent(offer->description()); 2689 cricket::GetFirstAudioContent(offer->description());
2547 EXPECT_TRUE(content != NULL); 2690 EXPECT_TRUE(content != NULL);
2548 2691
2549 content = cricket::GetFirstVideoContent(offer->description()); 2692 content = cricket::GetFirstVideoContent(offer->description());
2550 EXPECT_TRUE(content != NULL); 2693 EXPECT_TRUE(content != NULL);
2551 2694
2552 // Sets constraints to false and verifies that audio/video contents are 2695 // Sets constraints to false and verifies that audio/video contents are
2553 // removed. 2696 // removed.
2554 options.offer_to_receive_audio = 0; 2697 options.offer_to_receive_audio = 0;
2555 options.offer_to_receive_video = 0; 2698 options.offer_to_receive_video = 0;
2699 // Remove the media sections added in previous offer.
2700 offered_media_sections_.clear();
2556 offer.reset(CreateOffer(options)); 2701 offer.reset(CreateOffer(options));
2557 2702
2558 content = cricket::GetFirstAudioContent(offer->description()); 2703 content = cricket::GetFirstAudioContent(offer->description());
2559 EXPECT_TRUE(content == NULL); 2704 EXPECT_TRUE(content == NULL);
2560 content = cricket::GetFirstVideoContent(offer->description()); 2705 content = cricket::GetFirstVideoContent(offer->description());
2561 EXPECT_TRUE(content == NULL); 2706 EXPECT_TRUE(content == NULL);
2562 } 2707 }
2563 2708
2564 // Test that an answer can not be created if the last remote description is not 2709 // Test that an answer can not be created if the last remote description is not
2565 // an offer. 2710 // an offer.
(...skipping 23 matching lines...) Expand all
2589 ASSERT_TRUE(content != NULL); 2734 ASSERT_TRUE(content != NULL);
2590 EXPECT_FALSE(content->rejected); 2735 EXPECT_FALSE(content->rejected);
2591 } 2736 }
2592 2737
2593 // Test that an answer contains the correct media content descriptions when no 2738 // Test that an answer contains the correct media content descriptions when no
2594 // constraints have been set and the offer only contain audio. 2739 // constraints have been set and the offer only contain audio.
2595 TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { 2740 TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
2596 Init(); 2741 Init();
2597 // Create a remote offer with audio only. 2742 // Create a remote offer with audio only.
2598 cricket::MediaSessionOptions options; 2743 cricket::MediaSessionOptions options;
2744 GetOptionsForAudioOnlyRemoteOffer(&options);
2599 2745
2600 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); 2746 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
2601 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); 2747 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2602 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); 2748 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2603 2749
2604 SetRemoteDescriptionWithoutError(offer.release()); 2750 SetRemoteDescriptionWithoutError(offer.release());
2605 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); 2751 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2606 const cricket::ContentInfo* content = 2752 const cricket::ContentInfo* content =
2607 cricket::GetFirstAudioContent(answer->description()); 2753 cricket::GetFirstAudioContent(answer->description());
2608 ASSERT_TRUE(content != NULL); 2754 ASSERT_TRUE(content != NULL);
(...skipping 24 matching lines...) Expand all
2633 2779
2634 // Test that an answer contains the correct media content descriptions when 2780 // Test that an answer contains the correct media content descriptions when
2635 // constraints have been set but no stream is sent. 2781 // constraints have been set but no stream is sent.
2636 TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { 2782 TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
2637 Init(); 2783 Init();
2638 // Create a remote offer with audio and video content. 2784 // Create a remote offer with audio and video content.
2639 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); 2785 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
2640 SetRemoteDescriptionWithoutError(offer.release()); 2786 SetRemoteDescriptionWithoutError(offer.release());
2641 2787
2642 cricket::MediaSessionOptions session_options; 2788 cricket::MediaSessionOptions session_options;
2643 session_options.recv_audio = false; 2789 recv_audio_ = false;
2644 session_options.recv_video = false; 2790 recv_video_ = false;
2645 std::unique_ptr<SessionDescriptionInterface> answer( 2791 std::unique_ptr<SessionDescriptionInterface> answer(
2646 CreateAnswer(session_options)); 2792 CreateAnswer(session_options));
2647 2793
2648 const cricket::ContentInfo* content = 2794 const cricket::ContentInfo* content =
2649 cricket::GetFirstAudioContent(answer->description()); 2795 cricket::GetFirstAudioContent(answer->description());
2650 ASSERT_TRUE(content != NULL); 2796 ASSERT_TRUE(content != NULL);
2651 EXPECT_TRUE(content->rejected); 2797 EXPECT_TRUE(content->rejected);
2652 2798
2653 content = cricket::GetFirstVideoContent(answer->description()); 2799 content = cricket::GetFirstVideoContent(answer->description());
2654 ASSERT_TRUE(content != NULL); 2800 ASSERT_TRUE(content != NULL);
2655 EXPECT_TRUE(content->rejected); 2801 EXPECT_TRUE(content->rejected);
2656 } 2802 }
2657 2803
2658 // Test that an answer contains the correct media content descriptions when 2804 // Test that an answer contains the correct media content descriptions when
2659 // constraints have been set and streams are sent. 2805 // constraints have been set and streams are sent.
2660 TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { 2806 TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
2661 Init(); 2807 Init();
2662 // Create a remote offer with audio and video content. 2808 // Create a remote offer with audio and video content.
2663 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); 2809 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
2664 SetRemoteDescriptionWithoutError(offer.release()); 2810 SetRemoteDescriptionWithoutError(offer.release());
2665 2811
2666 cricket::MediaSessionOptions options; 2812 cricket::MediaSessionOptions options;
2667 options.recv_audio = false;
2668 options.recv_video = false;
2669
2670 // Test with a stream with tracks. 2813 // Test with a stream with tracks.
2671 SendAudioVideoStream1(); 2814 SendAudioVideoStream1();
2672 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); 2815 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
2673 2816
2674 // TODO(perkj): Should the direction be set to SEND_ONLY? 2817 // TODO(perkj): Should the direction be set to SEND_ONLY?
2675 const cricket::ContentInfo* content = 2818 const cricket::ContentInfo* content =
2676 cricket::GetFirstAudioContent(answer->description()); 2819 cricket::GetFirstAudioContent(answer->description());
2677 ASSERT_TRUE(content != NULL); 2820 ASSERT_TRUE(content != NULL);
2678 EXPECT_FALSE(content->rejected); 2821 EXPECT_FALSE(content->rejected);
2679 2822
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 // later updates with video. 2862 // later updates with video.
2720 TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { 2863 TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
2721 Init(); 2864 Init();
2722 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); 2865 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2723 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); 2866 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2724 2867
2725 SendAudioVideoStream1(); 2868 SendAudioVideoStream1();
2726 SessionDescriptionInterface* offer = CreateOffer(); 2869 SessionDescriptionInterface* offer = CreateOffer();
2727 2870
2728 cricket::MediaSessionOptions options; 2871 cricket::MediaSessionOptions options;
2872 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
2873 cricket::MD_RECVONLY, !kStopped, &options);
2874 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
2875 cricket::MD_INACTIVE, kStopped, &options);
2729 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); 2876 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2730 2877
2731 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer 2878 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2732 // and answer; 2879 // and answer;
2733 SetLocalDescriptionWithoutError(offer); 2880 SetLocalDescriptionWithoutError(offer);
2734 SetRemoteDescriptionWithoutError(answer); 2881 SetRemoteDescriptionWithoutError(answer);
2735 2882
2736 video_channel_ = media_engine_->GetVideoChannel(0); 2883 video_channel_ = media_engine_->GetVideoChannel(0);
2737 voice_channel_ = media_engine_->GetVoiceChannel(0); 2884 voice_channel_ = media_engine_->GetVoiceChannel(0);
2738 2885
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2775 // This test verifies the call setup when remote answer with video only and 2922 // This test verifies the call setup when remote answer with video only and
2776 // later updates with audio. 2923 // later updates with audio.
2777 TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { 2924 TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
2778 Init(); 2925 Init();
2779 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); 2926 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2780 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); 2927 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2781 SendAudioVideoStream1(); 2928 SendAudioVideoStream1();
2782 SessionDescriptionInterface* offer = CreateOffer(); 2929 SessionDescriptionInterface* offer = CreateOffer();
2783 2930
2784 cricket::MediaSessionOptions options; 2931 cricket::MediaSessionOptions options;
2785 options.recv_audio = false; 2932 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
2786 options.recv_video = true; 2933 cricket::MD_INACTIVE, kStopped, &options);
2787 SessionDescriptionInterface* answer = CreateRemoteAnswer( 2934 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
2788 offer, options, cricket::SEC_ENABLED); 2935 cricket::MD_RECVONLY, !kStopped, &options);
2936
2937 SessionDescriptionInterface* answer =
2938 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
2789 2939
2790 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer 2940 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2791 // and answer. 2941 // and answer.
2792 SetLocalDescriptionWithoutError(offer); 2942 SetLocalDescriptionWithoutError(offer);
2793 SetRemoteDescriptionWithoutError(answer); 2943 SetRemoteDescriptionWithoutError(answer);
2794 2944
2795 video_channel_ = media_engine_->GetVideoChannel(0); 2945 video_channel_ = media_engine_->GetVideoChannel(0);
2796 voice_channel_ = media_engine_->GetVoiceChannel(0); 2946 voice_channel_ = media_engine_->GetVoiceChannel(0);
2797 2947
2798 ASSERT_TRUE(voice_channel_ == NULL); 2948 ASSERT_TRUE(voice_channel_ == NULL);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
3018 } 3168 }
3019 3169
3020 // Test that candidates sent to the "video" transport do not get pushed down to 3170 // Test that candidates sent to the "video" transport do not get pushed down to
3021 // the "audio" transport channel when bundling. 3171 // the "audio" transport channel when bundling.
3022 TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { 3172 TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3023 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); 3173 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3024 3174
3025 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); 3175 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3026 SendAudioVideoStream1(); 3176 SendAudioVideoStream1();
3027 3177
3028 PeerConnectionInterface::RTCOfferAnswerOptions options; 3178 cricket::MediaSessionOptions offer_options;
3029 options.use_rtp_mux = true; 3179 GetOptionsForRemoteOffer(&offer_options);
3180 offer_options.bundle_enabled = true;
3030 3181
3031 SessionDescriptionInterface* offer = CreateRemoteOffer(); 3182 SessionDescriptionInterface* offer = CreateRemoteOffer(offer_options);
3032 SetRemoteDescriptionWithoutError(offer); 3183 SetRemoteDescriptionWithoutError(offer);
3033 3184
3034 SessionDescriptionInterface* answer = CreateAnswer(); 3185 cricket::MediaSessionOptions answer_options;
3186 answer_options.bundle_enabled = true;
3187 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
3035 SetLocalDescriptionWithoutError(answer); 3188 SetLocalDescriptionWithoutError(answer);
3036 3189
3037 EXPECT_EQ(session_->voice_rtp_transport_channel(), 3190 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3038 session_->video_rtp_transport_channel()); 3191 session_->video_rtp_transport_channel());
3039 3192
3040 cricket::BaseChannel* voice_channel = session_->voice_channel(); 3193 cricket::BaseChannel* voice_channel = session_->voice_channel();
3041 ASSERT_TRUE(voice_channel != NULL); 3194 ASSERT_TRUE(voice_channel != NULL);
3042 3195
3043 // Checks if one of the transport channels contains a connection using a given 3196 // Checks if one of the transport channels contains a connection using a given
3044 // port. 3197 // port.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3189 3342
3190 PeerConnectionInterface::RTCOfferAnswerOptions options; 3343 PeerConnectionInterface::RTCOfferAnswerOptions options;
3191 options.use_rtp_mux = true; 3344 options.use_rtp_mux = true;
3192 3345
3193 SessionDescriptionInterface* offer = CreateOffer(options); 3346 SessionDescriptionInterface* offer = CreateOffer(options);
3194 SetLocalDescriptionWithoutError(offer); 3347 SetLocalDescriptionWithoutError(offer);
3195 3348
3196 EXPECT_EQ(session_->voice_rtp_transport_channel(), 3349 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3197 session_->video_rtp_transport_channel()); 3350 session_->video_rtp_transport_channel());
3198 3351
3199 SendAudioVideoStream2(); 3352 SendVideoOnlyStream2();
3200 cricket::MediaSessionOptions recv_options; 3353 cricket::MediaSessionOptions recv_options;
3201 recv_options.recv_audio = false; 3354 recv_audio_ = false;
3202 recv_options.recv_video = true; 3355 GetOptionsForAnswer(&recv_options);
3203 SessionDescriptionInterface* answer = 3356 SessionDescriptionInterface* answer =
3204 CreateRemoteAnswer(session_->local_description(), recv_options); 3357 CreateRemoteAnswer(session_->local_description(), recv_options);
3205 SetRemoteDescriptionWithoutError(answer); 3358 SetRemoteDescriptionWithoutError(answer);
3206 3359
3207 EXPECT_TRUE(nullptr == session_->voice_channel()); 3360 EXPECT_TRUE(nullptr == session_->voice_channel());
3208 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel()); 3361 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
3209 3362
3210 session_->Close(); 3363 session_->Close();
3211 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel()); 3364 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3212 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel()); 3365 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3279 // Expect an error when applying the remote description 3432 // Expect an error when applying the remote description
3280 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer, 3433 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3281 kCreateChannelFailed, modified_offer); 3434 kCreateChannelFailed, modified_offer);
3282 } 3435 }
3283 3436
3284 // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE. 3437 // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
3285 TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) { 3438 TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3286 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); 3439 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
3287 SendAudioVideoStream1(); 3440 SendAudioVideoStream1();
3288 3441
3289 PeerConnectionInterface::RTCOfferAnswerOptions options; 3442 PeerConnectionInterface::RTCOfferAnswerOptions rtc_options;
3290 options.use_rtp_mux = true; 3443 rtc_options.use_rtp_mux = true;
3291 3444
3292 SessionDescriptionInterface* offer = CreateOffer(options); 3445 SessionDescriptionInterface* offer = CreateOffer(rtc_options);
3293 SetLocalDescriptionWithoutError(offer); 3446 SetLocalDescriptionWithoutError(offer);
3294 3447
3295 EXPECT_NE(session_->voice_rtp_transport_channel(), 3448 EXPECT_NE(session_->voice_rtp_transport_channel(),
3296 session_->video_rtp_transport_channel()); 3449 session_->video_rtp_transport_channel());
3297 3450
3298 SendAudioVideoStream2(); 3451 SendAudioVideoStream2();
3299 SessionDescriptionInterface* answer = 3452 SessionDescriptionInterface* answer =
3300 CreateRemoteAnswer(session_->local_description()); 3453 CreateRemoteAnswer(session_->local_description());
3301 SetRemoteDescriptionWithoutError(answer); 3454 SetRemoteDescriptionWithoutError(answer);
3302 3455
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
3638 SetLocalDescriptionWithoutError(jsep_offer_str); 3791 SetLocalDescriptionWithoutError(jsep_offer_str);
3639 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing()); 3792 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3640 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing()); 3793 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
3641 } 3794 }
3642 3795
3643 // This test verifies that an answer contains new ufrag and password if an offer 3796 // This test verifies that an answer contains new ufrag and password if an offer
3644 // with new ufrag and password is received. 3797 // with new ufrag and password is received.
3645 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { 3798 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
3646 Init(); 3799 Init();
3647 cricket::MediaSessionOptions options; 3800 cricket::MediaSessionOptions options;
3648 options.recv_video = true; 3801 GetOptionsForRemoteOffer(&options);
3649 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); 3802 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3650 SetRemoteDescriptionWithoutError(offer.release()); 3803 SetRemoteDescriptionWithoutError(offer.release());
3651 3804
3652 SendAudioVideoStream1(); 3805 SendAudioVideoStream1();
3653 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); 3806 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
3654 SetLocalDescriptionWithoutError(answer.release()); 3807 SetLocalDescriptionWithoutError(answer.release());
3655 3808
3656 // Receive an offer with new ufrag and password. 3809 // Receive an offer with new ufrag and password.
3657 for (const cricket::ContentInfo& content : 3810 for (size_t i = 0; i < options.media_description_options.size(); ++i) {
3658 session_->local_description()->description()->contents()) { 3811 options.media_description_options[i].transport_options.ice_restart = true;
3659 options.transport_options[content.name].ice_restart = true;
3660 } 3812 }
3813
3661 std::unique_ptr<JsepSessionDescription> updated_offer1( 3814 std::unique_ptr<JsepSessionDescription> updated_offer1(
3662 CreateRemoteOffer(options, session_->remote_description())); 3815 CreateRemoteOffer(options, session_->remote_description()));
3663 SetRemoteDescriptionWithoutError(updated_offer1.release()); 3816 SetRemoteDescriptionWithoutError(updated_offer1.release());
3664 3817
3665 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer()); 3818 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
3666 3819
3667 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(), 3820 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3668 session_->local_description()->description())); 3821 session_->local_description()->description()));
3669 3822
3670 // Even a second answer (created before the description is set) should have 3823 // Even a second answer (created before the description is set) should have
3671 // a new ufrag/password. 3824 // a new ufrag/password.
3672 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); 3825 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
3673 3826
3674 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(), 3827 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3675 session_->local_description()->description())); 3828 session_->local_description()->description()));
3676 3829
3677 SetLocalDescriptionWithoutError(updated_answer2.release()); 3830 SetLocalDescriptionWithoutError(updated_answer2.release());
3678 } 3831 }
3679 3832
3680 // This test verifies that an answer contains new ufrag and password if an offer 3833 // This test verifies that an answer contains new ufrag and password if an offer
3681 // that changes either the ufrag or password (but not both) is received. 3834 // that changes either the ufrag or password (but not both) is received.
3682 // RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or 3835 // RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3683 // a=ice-pwd attributes compared to the previous SDP from the peer, it 3836 // a=ice-pwd attributes compared to the previous SDP from the peer, it
3684 // indicates that ICE is restarting for this media stream." 3837 // indicates that ICE is restarting for this media stream."
3685 TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) { 3838 TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3686 Init(); 3839 Init();
3687 cricket::MediaSessionOptions options; 3840 cricket::MediaSessionOptions options;
3688 options.recv_audio = true; 3841 GetOptionsForRemoteOffer(&options);
3689 options.recv_video = true;
3690 // Create an offer with audio and video. 3842 // Create an offer with audio and video.
3691 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); 3843 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3692 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345"); 3844 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3693 SetRemoteDescriptionWithoutError(offer.release()); 3845 SetRemoteDescriptionWithoutError(offer.release());
3694 3846
3695 SendAudioVideoStream1(); 3847 SendAudioVideoStream1();
3696 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); 3848 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
3697 SetLocalDescriptionWithoutError(answer.release()); 3849 SetLocalDescriptionWithoutError(answer.release());
3698 3850
3699 // Receive an offer with a new ufrag but stale password. 3851 // Receive an offer with a new ufrag but stale password.
(...skipping 19 matching lines...) Expand all
3719 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(), 3871 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3720 session_->local_description()->description())); 3872 session_->local_description()->description()));
3721 SetLocalDescriptionWithoutError(updated_answer2.release()); 3873 SetLocalDescriptionWithoutError(updated_answer2.release());
3722 } 3874 }
3723 3875
3724 // This test verifies that an answer contains old ufrag and password if an offer 3876 // This test verifies that an answer contains old ufrag and password if an offer
3725 // with old ufrag and password is received. 3877 // with old ufrag and password is received.
3726 TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { 3878 TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
3727 Init(); 3879 Init();
3728 cricket::MediaSessionOptions options; 3880 cricket::MediaSessionOptions options;
3729 options.recv_video = true; 3881 GetOptionsForRemoteOffer(&options);
3730 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); 3882 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3731 SetRemoteDescriptionWithoutError(offer.release()); 3883 SetRemoteDescriptionWithoutError(offer.release());
3732 3884
3733 SendAudioVideoStream1(); 3885 SendAudioVideoStream1();
3734 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); 3886 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
3735 SetLocalDescriptionWithoutError(answer.release()); 3887 SetLocalDescriptionWithoutError(answer.release());
3736 3888
3737 // Receive an offer without changed ufrag or password. 3889 // Receive an offer without changed ufrag or password.
3738 std::unique_ptr<JsepSessionDescription> updated_offer2( 3890 std::unique_ptr<JsepSessionDescription> updated_offer2(
3739 CreateRemoteOffer(options, session_->remote_description())); 3891 CreateRemoteOffer(options, session_->remote_description()));
3740 SetRemoteDescriptionWithoutError(updated_offer2.release()); 3892 SetRemoteDescriptionWithoutError(updated_offer2.release());
3741 3893
3742 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); 3894 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
3743 3895
3744 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(), 3896 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3745 session_->local_description()->description())); 3897 session_->local_description()->description()));
3746 3898
3747 SetLocalDescriptionWithoutError(updated_answer2.release()); 3899 SetLocalDescriptionWithoutError(updated_answer2.release());
3748 } 3900 }
3749 3901
3750 // This test verifies that if an offer does an ICE restart on some, but not all 3902 // This test verifies that if an offer does an ICE restart on some, but not all
3751 // media sections, the answer will change the ufrag/password in the correct 3903 // media sections, the answer will change the ufrag/password in the correct
3752 // media sections. 3904 // media sections.
3753 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) { 3905 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3754 Init(); 3906 Init();
3755 cricket::MediaSessionOptions options; 3907 cricket::MediaSessionOptions options;
3756 options.recv_video = true; 3908 GetOptionsForRemoteOffer(&options);
3757 options.recv_audio = true;
3758 options.bundle_enabled = false; 3909 options.bundle_enabled = false;
3759 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); 3910 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3760 3911
3761 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa", 3912 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3762 "aaaaaaaaaaaaaaaaaaaaaa"); 3913 "aaaaaaaaaaaaaaaaaaaaaa");
3763 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb", 3914 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3764 "bbbbbbbbbbbbbbbbbbbbbb"); 3915 "bbbbbbbbbbbbbbbbbbbbbb");
3765 SetRemoteDescriptionWithoutError(offer.release()); 3916 SetRemoteDescriptionWithoutError(offer.release());
3766 3917
3767 SendAudioVideoStream1(); 3918 SendAudioVideoStream1();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 CreateDataChannel(); 4030 CreateDataChannel();
3880 InitiateCall(); 4031 InitiateCall();
3881 ASSERT_TRUE(session_->sctp_content_name()); 4032 ASSERT_TRUE(session_->sctp_content_name());
3882 ASSERT_TRUE(session_->sctp_transport_name()); 4033 ASSERT_TRUE(session_->sctp_transport_name());
3883 EXPECT_EQ("data", *session_->sctp_content_name()); 4034 EXPECT_EQ("data", *session_->sctp_content_name());
3884 EXPECT_EQ("data", *session_->sctp_transport_name()); 4035 EXPECT_EQ("data", *session_->sctp_transport_name());
3885 4036
3886 // Create answer that finishes BUNDLE negotiation, which means everything 4037 // Create answer that finishes BUNDLE negotiation, which means everything
3887 // should be bundled on the first transport (audio). 4038 // should be bundled on the first transport (audio).
3888 cricket::MediaSessionOptions answer_options; 4039 cricket::MediaSessionOptions answer_options;
3889 answer_options.recv_video = true;
3890 answer_options.bundle_enabled = true; 4040 answer_options.bundle_enabled = true;
3891 answer_options.data_channel_type = cricket::DCT_SCTP; 4041 answer_options.data_channel_type = cricket::DCT_SCTP;
4042 GetOptionsForAnswer(&answer_options);
3892 SetRemoteDescriptionWithoutError(CreateRemoteAnswer( 4043 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3893 session_->local_description(), answer_options, cricket::SEC_DISABLED)); 4044 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3894 ASSERT_TRUE(session_->sctp_content_name()); 4045 ASSERT_TRUE(session_->sctp_content_name());
3895 ASSERT_TRUE(session_->sctp_transport_name()); 4046 ASSERT_TRUE(session_->sctp_transport_name());
3896 EXPECT_EQ("data", *session_->sctp_content_name()); 4047 EXPECT_EQ("data", *session_->sctp_content_name());
3897 EXPECT_EQ("audio", *session_->sctp_transport_name()); 4048 EXPECT_EQ("audio", *session_->sctp_transport_name());
3898 } 4049 }
3899 4050
3900 TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { 4051 TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
3901 InitWithDtls(GetParam()); 4052 InitWithDtls(GetParam());
3902 4053
3903 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); 4054 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
3904 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); 4055 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
3905 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); 4056 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3906 } 4057 }
3907 4058
3908 TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { 4059 TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
3909 SetFactoryDtlsSrtp(); 4060 SetFactoryDtlsSrtp();
3910 InitWithDtls(GetParam()); 4061 InitWithDtls(GetParam());
3911 4062
3912 // Create remote offer with SCTP. 4063 // Create remote offer with SCTP.
3913 cricket::MediaSessionOptions options; 4064 cricket::MediaSessionOptions options;
3914 options.data_channel_type = cricket::DCT_SCTP; 4065 options.data_channel_type = cricket::DCT_SCTP;
4066 GetOptionsForRemoteOffer(&options);
3915 JsepSessionDescription* offer = 4067 JsepSessionDescription* offer =
3916 CreateRemoteOffer(options, cricket::SEC_DISABLED); 4068 CreateRemoteOffer(options, cricket::SEC_DISABLED);
3917 SetRemoteDescriptionWithoutError(offer); 4069 SetRemoteDescriptionWithoutError(offer);
3918 4070
3919 // Verifies the answer contains SCTP. 4071 // Verifies the answer contains SCTP.
3920 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); 4072 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
3921 EXPECT_TRUE(answer != NULL); 4073 EXPECT_TRUE(answer != NULL);
3922 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); 4074 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3923 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); 4075 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
3924 } 4076 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 } 4200 }
4049 4201
4050 // Verifies that CreateAnswer succeeds when CreateOffer is called before async 4202 // Verifies that CreateAnswer succeeds when CreateOffer is called before async
4051 // identity generation is finished (even if a certificate is provided this is 4203 // identity generation is finished (even if a certificate is provided this is
4052 // an async op). 4204 // an async op).
4053 TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) { 4205 TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
4054 InitWithDtls(GetParam()); 4206 InitWithDtls(GetParam());
4055 SetFactoryDtlsSrtp(); 4207 SetFactoryDtlsSrtp();
4056 4208
4057 cricket::MediaSessionOptions options; 4209 cricket::MediaSessionOptions options;
4058 options.recv_video = true; 4210 GetOptionsForRemoteOffer(&options);
4059 std::unique_ptr<JsepSessionDescription> offer( 4211 std::unique_ptr<JsepSessionDescription> offer(
4060 CreateRemoteOffer(options, cricket::SEC_DISABLED)); 4212 CreateRemoteOffer(options, cricket::SEC_DISABLED));
4061 ASSERT_TRUE(offer.get() != NULL); 4213 ASSERT_TRUE(offer.get() != NULL);
4062 SetRemoteDescriptionWithoutError(offer.release()); 4214 SetRemoteDescriptionWithoutError(offer.release());
4063 4215
4064 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); 4216 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
4065 EXPECT_TRUE(answer != NULL); 4217 EXPECT_TRUE(answer != NULL);
4066 VerifyNoCryptoParams(answer->description(), true); 4218 VerifyNoCryptoParams(answer->description(), true);
4067 VerifyFingerprintStatus(answer->description(), true); 4219 VerifyFingerprintStatus(answer->description(), true);
4068 } 4220 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4122 CreateSessionDescriptionRequest::kAnswer); 4274 CreateSessionDescriptionRequest::kAnswer);
4123 } 4275 }
4124 4276
4125 // Verifies that setRemoteDescription fails when DTLS is disabled and the remote 4277 // Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4126 // offer has no SDES crypto but only DTLS fingerprint. 4278 // offer has no SDES crypto but only DTLS fingerprint.
4127 TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) { 4279 TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4128 // Init without DTLS. 4280 // Init without DTLS.
4129 Init(); 4281 Init();
4130 // Create a remote offer with secured transport disabled. 4282 // Create a remote offer with secured transport disabled.
4131 cricket::MediaSessionOptions options; 4283 cricket::MediaSessionOptions options;
4284 GetOptionsForRemoteOffer(&options);
4132 JsepSessionDescription* offer(CreateRemoteOffer( 4285 JsepSessionDescription* offer(CreateRemoteOffer(
4133 options, cricket::SEC_DISABLED)); 4286 options, cricket::SEC_DISABLED));
4134 // Adds a DTLS fingerprint to the remote offer. 4287 // Adds a DTLS fingerprint to the remote offer.
4135 cricket::SessionDescription* sdp = offer->description(); 4288 cricket::SessionDescription* sdp = offer->description();
4136 TransportInfo* audio = sdp->GetTransportInfoByName("audio"); 4289 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4137 ASSERT_TRUE(audio != NULL); 4290 ASSERT_TRUE(audio != NULL);
4138 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL); 4291 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4139 audio->description.identity_fingerprint.reset( 4292 audio->description.identity_fingerprint.reset(
4140 rtc::SSLFingerprint::CreateFromRfc4572( 4293 rtc::SSLFingerprint::CreateFromRfc4572(
4141 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint)); 4294 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
(...skipping 23 matching lines...) Expand all
4165 SetFactoryDtlsSrtp(); 4318 SetFactoryDtlsSrtp();
4166 4319
4167 SendAudioOnlyStream2(); 4320 SendAudioOnlyStream2();
4168 SessionDescriptionInterface* offer = CreateOffer(); 4321 SessionDescriptionInterface* offer = CreateOffer();
4169 SetLocalDescriptionWithoutError(offer); 4322 SetLocalDescriptionWithoutError(offer);
4170 4323
4171 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); 4324 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4172 SetRemoteDescriptionWithoutError(answer); 4325 SetRemoteDescriptionWithoutError(answer);
4173 4326
4174 cricket::MediaSessionOptions options; 4327 cricket::MediaSessionOptions options;
4175 options.recv_video = true; 4328 GetOptionsForRemoteOffer(&options);
4176 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); 4329 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4177 4330
4178 cricket::Candidate candidate1; 4331 cricket::Candidate candidate1;
4179 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); 4332 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
4180 candidate1.set_component(1); 4333 candidate1.set_component(1);
4181 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, 4334 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4182 candidate1); 4335 candidate1);
4183 EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); 4336 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4184 SetRemoteDescriptionWithoutError(offer); 4337 SetRemoteDescriptionWithoutError(offer);
4185 4338
4186 answer = CreateAnswer(); 4339 answer = CreateAnswer();
4187 SetLocalDescriptionWithoutError(answer); 4340 SetLocalDescriptionWithoutError(answer);
4188 } 4341 }
4189 4342
4190 // Tests that we can renegotiate new media content with ICE candidates separated 4343 // Tests that we can renegotiate new media content with ICE candidates separated
4191 // from the remote SDP. 4344 // from the remote SDP.
4192 TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) { 4345 TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
4193 InitWithDtls(GetParam()); 4346 InitWithDtls(GetParam());
4194 SetFactoryDtlsSrtp(); 4347 SetFactoryDtlsSrtp();
4195 4348
4196 SendAudioOnlyStream2(); 4349 SendAudioOnlyStream2();
4197 SessionDescriptionInterface* offer = CreateOffer(); 4350 SessionDescriptionInterface* offer = CreateOffer();
4198 SetLocalDescriptionWithoutError(offer); 4351 SetLocalDescriptionWithoutError(offer);
4199 4352
4200 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); 4353 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4201 SetRemoteDescriptionWithoutError(answer); 4354 SetRemoteDescriptionWithoutError(answer);
4202 4355
4203 cricket::MediaSessionOptions options; 4356 cricket::MediaSessionOptions options;
4204 options.recv_video = true; 4357 GetOptionsForRemoteOffer(&options);
4205 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); 4358 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4206 SetRemoteDescriptionWithoutError(offer); 4359 SetRemoteDescriptionWithoutError(offer);
4207 4360
4208 cricket::Candidate candidate1; 4361 cricket::Candidate candidate1;
4209 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); 4362 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
4210 candidate1.set_component(1); 4363 candidate1.set_component(1);
4211 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, 4364 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4212 candidate1); 4365 candidate1);
4213 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate)); 4366 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4214 4367
4215 answer = CreateAnswer(); 4368 answer = CreateAnswer();
4216 SetLocalDescriptionWithoutError(answer); 4369 SetLocalDescriptionWithoutError(answer);
4217 } 4370 }
4218 4371
4219 #ifdef HAVE_QUIC 4372 #ifdef HAVE_QUIC
4220 TEST_P(WebRtcSessionTest, TestNegotiateQuic) { 4373 TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4221 configuration_.enable_quic = true; 4374 configuration_.enable_quic = true;
4222 InitWithDtls(GetParam()); 4375 InitWithDtls(GetParam());
4223 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC); 4376 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4224 SessionDescriptionInterface* offer = CreateOffer(); 4377 SessionDescriptionInterface* offer = CreateOffer();
4225 ASSERT_TRUE(offer); 4378 ASSERT_TRUE(offer);
4226 ASSERT_TRUE(offer->description()); 4379 ASSERT_TRUE(offer->description());
4227 SetLocalDescriptionWithoutError(offer); 4380 SetLocalDescriptionWithoutError(offer);
4228 cricket::MediaSessionOptions options; 4381 cricket::MediaSessionOptions options;
4229 options.recv_audio = true; 4382 GetOptionsForAnswer(&options);
4230 options.recv_video = true;
4231 SessionDescriptionInterface* answer = 4383 SessionDescriptionInterface* answer =
4232 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); 4384 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4233 ASSERT_TRUE(answer); 4385 ASSERT_TRUE(answer);
4234 ASSERT_TRUE(answer->description()); 4386 ASSERT_TRUE(answer->description());
4235 SetRemoteDescriptionWithoutError(answer); 4387 SetRemoteDescriptionWithoutError(answer);
4236 } 4388 }
4237 #endif // HAVE_QUIC 4389 #endif // HAVE_QUIC
4238 4390
4239 // Tests that RTX codec is removed from the answer when it isn't supported 4391 // Tests that RTX codec is removed from the answer when it isn't supported
4240 // by local side. 4392 // by local side.
4241 TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) { 4393 TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4242 Init(); 4394 Init();
4243 SendAudioVideoStream1(); 4395 // Send video only to match the |kSdpWithRtx|.
4396 SendVideoOnlyStream2();
4244 std::string offer_sdp(kSdpWithRtx); 4397 std::string offer_sdp(kSdpWithRtx);
4245 4398
4246 SessionDescriptionInterface* offer = 4399 SessionDescriptionInterface* offer =
4247 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL); 4400 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4248 EXPECT_TRUE(offer->ToString(&offer_sdp)); 4401 EXPECT_TRUE(offer->ToString(&offer_sdp));
4249 4402
4250 // Offer SDP contains the RTX codec. 4403 // Offer SDP contains the RTX codec.
4251 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx")); 4404 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
4252 SetRemoteDescriptionWithoutError(offer); 4405 SetRemoteDescriptionWithoutError(offer);
4253 4406
4407 // |offered_media_sections_| is used when creating answer.
4408 offered_media_sections_.push_back(cricket::MediaDescriptionOptions(
4409 cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
4410 cricket::RtpTransceiverDirection(true, true), false));
4411 // Don't create media section for audio in the answer.
4254 SessionDescriptionInterface* answer = CreateAnswer(); 4412 SessionDescriptionInterface* answer = CreateAnswer();
4255 // Answer SDP does not contain the RTX codec. 4413 // Answer SDP does not contain the RTX codec.
4256 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx")); 4414 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
4257 SetLocalDescriptionWithoutError(answer); 4415 SetLocalDescriptionWithoutError(answer);
4258 } 4416 }
4259 4417
4260 // This verifies that the voice channel after bundle has both options from video 4418 // This verifies that the voice channel after bundle has both options from video
4261 // and voice channels. 4419 // and voice channels.
4262 TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) { 4420 TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4263 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); 4421 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4309 // and make sure we got success/failure callbacks for all of the requests. 4467 // and make sure we got success/failure callbacks for all of the requests.
4310 // Background: crbug.com/507307 4468 // Background: crbug.com/507307
4311 TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) { 4469 TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4312 Init(); 4470 Init();
4313 4471
4314 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100]; 4472 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4315 PeerConnectionInterface::RTCOfferAnswerOptions options; 4473 PeerConnectionInterface::RTCOfferAnswerOptions options;
4316 options.offer_to_receive_audio = 4474 options.offer_to_receive_audio =
4317 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; 4475 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
4318 cricket::MediaSessionOptions session_options; 4476 cricket::MediaSessionOptions session_options;
4319 session_options.recv_audio = true; 4477 GetOptionsForOffer(options, &session_options);
4320
4321 for (auto& o : observers) { 4478 for (auto& o : observers) {
4322 o = new WebRtcSessionCreateSDPObserverForTest(); 4479 o = new WebRtcSessionCreateSDPObserverForTest();
4323 session_->CreateOffer(o, options, session_options); 4480 session_->CreateOffer(o, options, session_options);
4324 } 4481 }
4325 4482
4326 session_.reset(); 4483 session_.reset();
4327 4484
4328 for (auto& o : observers) { 4485 for (auto& o : observers) {
4329 // We expect to have received a notification now even if the session was 4486 // We expect to have received a notification now even if the session was
4330 // terminated. The offer creation may or may not have succeeded, but we 4487 // terminated. The offer creation may or may not have succeeded, but we
4331 // must have received a notification which, so the only invalid state 4488 // must have received a notification which, so the only invalid state
4332 // is kInit. 4489 // is kInit.
4333 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); 4490 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4334 } 4491 }
4335 } 4492 }
4336 4493
4337 TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { 4494 TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4338 TestPacketOptions(); 4495 TestPacketOptions();
4339 } 4496 }
4340 4497
4341 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test 4498 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4342 // currently fails because upon disconnection and reconnection OnIceComplete is 4499 // currently fails because upon disconnection and reconnection OnIceComplete is
4343 // called more than once without returning to IceGatheringGathering. 4500 // called more than once without returning to IceGatheringGathering.
4344 4501
4345 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, 4502 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4346 WebRtcSessionTest, 4503 WebRtcSessionTest,
4347 testing::Values(ALREADY_GENERATED, 4504 testing::Values(ALREADY_GENERATED,
4348 DTLS_IDENTITY_STORE)); 4505 DTLS_IDENTITY_STORE));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698