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

Side by Side Diff: webrtc/api/webrtcsession_unittest.cc

Issue 1671173002: Track pending ICE restarts independently for different media sections. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merging with master. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/api/webrtcsessiondescriptionfactory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 scoped_ptr<JsepSessionDescription> offer( 724 scoped_ptr<JsepSessionDescription> offer(
725 CreateRemoteOffer(options, cricket::SEC_REQUIRED)); 725 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
726 ASSERT_TRUE(offer.get() != NULL); 726 ASSERT_TRUE(offer.get() != NULL);
727 VerifyCryptoParams(offer->description()); 727 VerifyCryptoParams(offer->description());
728 SetRemoteDescriptionWithoutError(offer.release()); 728 SetRemoteDescriptionWithoutError(offer.release());
729 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); 729 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
730 ASSERT_TRUE(answer.get() != NULL); 730 ASSERT_TRUE(answer.get() != NULL);
731 VerifyCryptoParams(answer->description()); 731 VerifyCryptoParams(answer->description());
732 } 732 }
733 733
734 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1, 734 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
735 const cricket::SessionDescription* desc2, 735 const cricket::SessionDescription* desc2) {
736 bool expect_equal) {
737 if (desc1->contents().size() != desc2->contents().size()) { 736 if (desc1->contents().size() != desc2->contents().size()) {
738 EXPECT_FALSE(expect_equal); 737 return false;
739 return;
740 } 738 }
741 739
742 const cricket::ContentInfos& contents = desc1->contents(); 740 const cricket::ContentInfos& contents = desc1->contents();
743 cricket::ContentInfos::const_iterator it = contents.begin(); 741 cricket::ContentInfos::const_iterator it = contents.begin();
744 742
745 for (; it != contents.end(); ++it) { 743 for (; it != contents.end(); ++it) {
746 const cricket::TransportDescription* transport_desc1 = 744 const cricket::TransportDescription* transport_desc1 =
747 desc1->GetTransportDescriptionByName(it->name); 745 desc1->GetTransportDescriptionByName(it->name);
748 const cricket::TransportDescription* transport_desc2 = 746 const cricket::TransportDescription* transport_desc2 =
749 desc2->GetTransportDescriptionByName(it->name); 747 desc2->GetTransportDescriptionByName(it->name);
750 if (!transport_desc1 || !transport_desc2) { 748 if (!transport_desc1 || !transport_desc2) {
751 EXPECT_FALSE(expect_equal); 749 return false;
752 return;
753 } 750 }
754 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || 751 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
755 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { 752 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
756 EXPECT_FALSE(expect_equal); 753 return false;
757 return;
758 } 754 }
759 } 755 }
760 EXPECT_TRUE(expect_equal); 756 return true;
757 }
758
759 // Compares ufrag/password only for the specified |media_type|.
760 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
761 const cricket::SessionDescription* desc2,
762 cricket::MediaType media_type) {
763 if (desc1->contents().size() != desc2->contents().size()) {
764 return false;
765 }
766
767 const cricket::ContentInfo* cinfo =
768 cricket::GetFirstMediaContent(desc1->contents(), media_type);
769 const cricket::TransportDescription* transport_desc1 =
770 desc1->GetTransportDescriptionByName(cinfo->name);
771 const cricket::TransportDescription* transport_desc2 =
772 desc2->GetTransportDescriptionByName(cinfo->name);
773 if (!transport_desc1 || !transport_desc2) {
774 return false;
775 }
776 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
777 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
778 return false;
779 }
780 return true;
761 } 781 }
762 782
763 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, 783 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
764 std::string *sdp) { 784 std::string *sdp) {
765 const cricket::SessionDescription* desc = current_desc->description(); 785 const cricket::SessionDescription* desc = current_desc->description();
766 EXPECT_TRUE(current_desc->ToString(sdp)); 786 EXPECT_TRUE(current_desc->ToString(sdp));
767 787
768 const cricket::ContentInfos& contents = desc->contents(); 788 const cricket::ContentInfos& contents = desc->contents();
769 cricket::ContentInfos::const_iterator it = contents.begin(); 789 cricket::ContentInfos::const_iterator it = contents.begin();
770 // Replace ufrag and pwd lines with empty strings. 790 // Replace ufrag and pwd lines with empty strings.
771 for (; it != contents.end(); ++it) { 791 for (; it != contents.end(); ++it) {
772 const cricket::TransportDescription* transport_desc = 792 const cricket::TransportDescription* transport_desc =
773 desc->GetTransportDescriptionByName(it->name); 793 desc->GetTransportDescriptionByName(it->name);
774 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag 794 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
775 + "\r\n"; 795 + "\r\n";
776 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd 796 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
777 + "\r\n"; 797 + "\r\n";
778 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), 798 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
779 "", 0, 799 "", 0,
780 sdp); 800 sdp);
781 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), 801 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
782 "", 0, 802 "", 0,
783 sdp); 803 sdp);
784 } 804 }
785 } 805 }
786 806
787 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc, 807 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
788 const std::string& modified_ice_ufrag, 808 const std::string& ufrag,
789 const std::string& modified_ice_pwd, 809 const std::string& pwd) {
790 std::string* sdp) { 810 cricket::SessionDescription* desc = current_desc->description();
791 const cricket::SessionDescription* desc = current_desc->description(); 811 for (TransportInfo& transport_info : desc->transport_infos()) {
792 EXPECT_TRUE(current_desc->ToString(sdp)); 812 cricket::TransportDescription& transport_desc =
813 transport_info.description;
814 transport_desc.ice_ufrag = ufrag;
815 transport_desc.ice_pwd = pwd;
816 }
817 }
793 818
794 const cricket::ContentInfos& contents = desc->contents(); 819 // Sets ufrag/pwd for specified |media_type|.
795 cricket::ContentInfos::const_iterator it = contents.begin(); 820 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
796 // Replace ufrag and pwd lines with |modified_ice_ufrag| and 821 cricket::MediaType media_type,
797 // |modified_ice_pwd| strings. 822 const std::string& ufrag,
798 for (; it != contents.end(); ++it) { 823 const std::string& pwd) {
799 const cricket::TransportDescription* transport_desc = 824 cricket::SessionDescription* desc = current_desc->description();
800 desc->GetTransportDescriptionByName(it->name); 825 const cricket::ContentInfo* cinfo =
801 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag 826 cricket::GetFirstMediaContent(desc->contents(), media_type);
802 + "\r\n"; 827 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
803 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd 828 cricket::TransportDescription* transport_desc =
804 + "\r\n"; 829 &transport_info->description;
805 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n"; 830 transport_desc->ice_ufrag = ufrag;
806 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n"; 831 transport_desc->ice_pwd = pwd;
807 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
808 mod_ufrag.c_str(), mod_ufrag.length(),
809 sdp);
810 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
811 mod_pwd.c_str(), mod_pwd.length(),
812 sdp);
813 }
814 } 832 }
815 833
816 // Creates a remote offer and and applies it as a remote description, 834 // Creates a remote offer and and applies it as a remote description,
817 // creates a local answer and applies is as a local description. 835 // creates a local answer and applies is as a local description.
818 // Call SendAudioVideoStreamX() before this function 836 // Call SendAudioVideoStreamX() before this function
819 // to decide which local and remote streams to create. 837 // to decide which local and remote streams to create.
820 void CreateAndSetRemoteOfferAndLocalAnswer() { 838 void CreateAndSetRemoteOfferAndLocalAnswer() {
821 SessionDescriptionInterface* offer = CreateRemoteOffer(); 839 SessionDescriptionInterface* offer = CreateRemoteOffer();
822 SetRemoteDescriptionWithoutError(offer); 840 SetRemoteDescriptionWithoutError(offer);
823 SessionDescriptionInterface* answer = CreateAnswer(NULL); 841 SessionDescriptionInterface* answer = CreateAnswer(NULL);
(...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); 2786 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2769 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); 2787 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
2770 } 2788 }
2771 2789
2772 // This test verifies that setLocalDescription fails if local offer has 2790 // This test verifies that setLocalDescription fails if local offer has
2773 // too short ice ufrag and pwd strings. 2791 // too short ice ufrag and pwd strings.
2774 TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) { 2792 TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2775 Init(); 2793 Init();
2776 SendAudioVideoStream1(); 2794 SendAudioVideoStream1();
2777 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); 2795 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2778
2779 std::string sdp;
2780 // Modifying ice ufrag and pwd in local offer with strings smaller than the 2796 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2781 // recommended values of 4 and 22 bytes respectively. 2797 // recommended values of 4 and 22 bytes respectively.
2782 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp); 2798 SetIceUfragPwd(offer.get(), "ice", "icepwd");
2783 SessionDescriptionInterface* modified_offer =
2784 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2785 std::string error; 2799 std::string error;
2786 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error)); 2800 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
2787 2801
2788 // Test with string greater than 256. 2802 // Test with string greater than 256.
2789 sdp.clear(); 2803 offer.reset(CreateOffer());
2790 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd, 2804 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2791 &sdp); 2805 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
2792 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2793 NULL);
2794 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2795 } 2806 }
2796 2807
2797 // This test verifies that setRemoteDescription fails if remote offer has 2808 // This test verifies that setRemoteDescription fails if remote offer has
2798 // too short ice ufrag and pwd strings. 2809 // too short ice ufrag and pwd strings.
2799 TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) { 2810 TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2800 Init(); 2811 Init();
2801 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); 2812 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2802 std::string sdp;
2803 // Modifying ice ufrag and pwd in remote offer with strings smaller than the 2813 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2804 // recommended values of 4 and 22 bytes respectively. 2814 // recommended values of 4 and 22 bytes respectively.
2805 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp); 2815 SetIceUfragPwd(offer.get(), "ice", "icepwd");
2806 SessionDescriptionInterface* modified_offer =
2807 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2808 std::string error; 2816 std::string error;
2809 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error)); 2817 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
2810 2818
2811 sdp.clear(); 2819 offer.reset(CreateRemoteOffer());
2812 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd, 2820 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2813 &sdp); 2821 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
2814 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2815 NULL);
2816 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2817 } 2822 }
2818 2823
2819 // Test that if the remote offer indicates the peer requested ICE restart (via 2824 // Test that if the remote offer indicates the peer requested ICE restart (via
2820 // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa. 2825 // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2821 TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) { 2826 TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
2822 Init(); 2827 Init();
2823 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2824 2828
2825 // Create the first offer. 2829 // Create the first offer.
2826 std::string sdp; 2830 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2827 ModifyIceUfragPwdLines(offer.get(), "0123456789012345", 2831 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
2828 "abcdefghijklmnopqrstuvwx", &sdp);
2829 SessionDescriptionInterface* offer1 =
2830 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2831 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 2832 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2832 0, "", "", "relay", 0, ""); 2833 0, "", "", "relay", 0, "");
2833 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, 2834 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2834 candidate1); 2835 candidate1);
2835 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1)); 2836 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2836 SetRemoteDescriptionWithoutError(offer1); 2837 SetRemoteDescriptionWithoutError(offer.release());
2837 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); 2838 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2838 2839
2839 // The second offer has the same ufrag and pwd but different address. 2840 // The second offer has the same ufrag and pwd but different address.
2840 sdp.clear(); 2841 offer.reset(CreateRemoteOffer());
2841 ModifyIceUfragPwdLines(offer.get(), "0123456789012345", 2842 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
2842 "abcdefghijklmnopqrstuvwx", &sdp);
2843 SessionDescriptionInterface* offer2 =
2844 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2845 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); 2843 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2846 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, 2844 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2847 candidate1); 2845 candidate1);
2848 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2)); 2846 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2849 SetRemoteDescriptionWithoutError(offer2); 2847 SetRemoteDescriptionWithoutError(offer.release());
2850 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count()); 2848 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2851 2849
2852 // The third offer has a different ufrag and different address. 2850 // The third offer has a different ufrag and different address.
2853 sdp.clear(); 2851 offer.reset(CreateRemoteOffer());
2854 ModifyIceUfragPwdLines(offer.get(), "0123456789012333", 2852 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
2855 "abcdefghijklmnopqrstuvwx", &sdp);
2856 SessionDescriptionInterface* offer3 =
2857 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2858 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000)); 2853 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2859 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0, 2854 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2860 candidate1); 2855 candidate1);
2861 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3)); 2856 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2862 SetRemoteDescriptionWithoutError(offer3); 2857 SetRemoteDescriptionWithoutError(offer.release());
2863 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); 2858 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2864 2859
2865 // The fourth offer has no candidate but a different ufrag/pwd. 2860 // The fourth offer has no candidate but a different ufrag/pwd.
2866 sdp.clear(); 2861 offer.reset(CreateRemoteOffer());
2867 ModifyIceUfragPwdLines(offer.get(), "0123456789012444", 2862 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2868 "abcdefghijklmnopqrstuvyz", &sdp); 2863 SetRemoteDescriptionWithoutError(offer.release());
2869 SessionDescriptionInterface* offer4 =
2870 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2871 SetRemoteDescriptionWithoutError(offer4);
2872 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count()); 2864 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2873 } 2865 }
2874 2866
2875 // Test that if the remote answer indicates the peer requested ICE restart (via 2867 // Test that if the remote answer indicates the peer requested ICE restart (via
2876 // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa. 2868 // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2877 TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) { 2869 TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2878 Init(); 2870 Init();
2879 SessionDescriptionInterface* offer = CreateOffer(); 2871 SessionDescriptionInterface* offer = CreateOffer();
2880 SetLocalDescriptionWithoutError(offer); 2872 SetLocalDescriptionWithoutError(offer);
2881 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2882 2873
2883 // Create the first answer. 2874 // Create the first answer.
2884 std::string sdp; 2875 scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
2885 ModifyIceUfragPwdLines(answer.get(), "0123456789012345", 2876 answer->set_type(JsepSessionDescription::kPrAnswer);
2886 "abcdefghijklmnopqrstuvwx", &sdp); 2877 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
2887 SessionDescriptionInterface* answer1 =
2888 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2889 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 2878 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2890 0, "", "", "relay", 0, ""); 2879 0, "", "", "relay", 0, "");
2891 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, 2880 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2892 candidate1); 2881 candidate1);
2893 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1)); 2882 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2894 SetRemoteDescriptionWithoutError(answer1); 2883 SetRemoteDescriptionWithoutError(answer.release());
2895 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); 2884 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2896 2885
2897 // The second answer has the same ufrag and pwd but different address. 2886 // The second answer has the same ufrag and pwd but different address.
2898 sdp.clear(); 2887 answer.reset(CreateRemoteAnswer(offer));
2899 ModifyIceUfragPwdLines(answer.get(), "0123456789012345", 2888 answer->set_type(JsepSessionDescription::kPrAnswer);
2900 "abcdefghijklmnopqrstuvwx", &sdp); 2889 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
2901 SessionDescriptionInterface* answer2 =
2902 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2903 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); 2890 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2904 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, 2891 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2905 candidate1); 2892 candidate1);
2906 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2)); 2893 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2907 SetRemoteDescriptionWithoutError(answer2); 2894 SetRemoteDescriptionWithoutError(answer.release());
2908 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count()); 2895 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2909 2896
2910 // The third answer has a different ufrag and different address. 2897 // The third answer has a different ufrag and different address.
2911 sdp.clear(); 2898 answer.reset(CreateRemoteAnswer(offer));
2912 ModifyIceUfragPwdLines(answer.get(), "0123456789012333", 2899 answer->set_type(JsepSessionDescription::kPrAnswer);
2913 "abcdefghijklmnopqrstuvwx", &sdp); 2900 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
2914 SessionDescriptionInterface* answer3 =
2915 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2916 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000)); 2901 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2917 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0, 2902 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2918 candidate1); 2903 candidate1);
2919 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3)); 2904 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2920 SetRemoteDescriptionWithoutError(answer3); 2905 SetRemoteDescriptionWithoutError(answer.release());
2921 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); 2906 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2922 2907
2923 // The fourth answer has no candidate but a different ufrag/pwd. 2908 // The fourth answer has no candidate but a different ufrag/pwd.
2924 sdp.clear(); 2909 answer.reset(CreateRemoteAnswer(offer));
2925 ModifyIceUfragPwdLines(answer.get(), "0123456789012444", 2910 answer->set_type(JsepSessionDescription::kPrAnswer);
2926 "abcdefghijklmnopqrstuvyz", &sdp); 2911 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2927 SessionDescriptionInterface* offer4 = 2912 SetRemoteDescriptionWithoutError(answer.release());
2928 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2929 SetRemoteDescriptionWithoutError(offer4);
2930 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count()); 2913 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2931 } 2914 }
2932 2915
2933 // Test that candidates sent to the "video" transport do not get pushed down to 2916 // Test that candidates sent to the "video" transport do not get pushed down to
2934 // the "audio" transport channel when bundling. 2917 // the "audio" transport channel when bundling.
2935 TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { 2918 TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2936 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); 2919 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2937 2920
2938 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); 2921 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2939 SendAudioVideoStream1(); 2922 SendAudioVideoStream1();
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
3636 rtc::scoped_ptr<JsepSessionDescription> offer( 3619 rtc::scoped_ptr<JsepSessionDescription> offer(
3637 CreateRemoteOffer(options)); 3620 CreateRemoteOffer(options));
3638 SetRemoteDescriptionWithoutError(offer.release()); 3621 SetRemoteDescriptionWithoutError(offer.release());
3639 3622
3640 SendAudioVideoStream1(); 3623 SendAudioVideoStream1();
3641 rtc::scoped_ptr<SessionDescriptionInterface> answer( 3624 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3642 CreateAnswer(NULL)); 3625 CreateAnswer(NULL));
3643 SetLocalDescriptionWithoutError(answer.release()); 3626 SetLocalDescriptionWithoutError(answer.release());
3644 3627
3645 // Receive an offer with new ufrag and password. 3628 // Receive an offer with new ufrag and password.
3646 options.audio_transport_options.ice_restart = true; 3629 for (const cricket::ContentInfo& content :
3647 options.video_transport_options.ice_restart = true; 3630 session_->local_description()->description()->contents()) {
3648 options.data_transport_options.ice_restart = true; 3631 options.transport_options[content.name].ice_restart = true;
3632 }
3649 rtc::scoped_ptr<JsepSessionDescription> updated_offer1( 3633 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
3650 CreateRemoteOffer(options, session_->remote_description())); 3634 CreateRemoteOffer(options, session_->remote_description()));
3651 SetRemoteDescriptionWithoutError(updated_offer1.release()); 3635 SetRemoteDescriptionWithoutError(updated_offer1.release());
3652 3636
3653 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1( 3637 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
3654 CreateAnswer(NULL)); 3638 CreateAnswer(NULL));
3655 3639
3656 CompareIceUfragAndPassword(updated_answer1->description(), 3640 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3657 session_->local_description()->description(), 3641 session_->local_description()->description()));
3658 false);
3659 3642
3643 // Even a second answer (created before the description is set) should have
3644 // a new ufrag/password.
3645 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
3646 CreateAnswer(NULL));
3647
3648 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3649 session_->local_description()->description()));
3650
3651 SetLocalDescriptionWithoutError(updated_answer2.release());
3652 }
3653
3654 // This test verifies that an answer contains new ufrag and password if an offer
3655 // that changes either the ufrag or password (but not both) is received.
3656 // RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3657 // a=ice-pwd attributes compared to the previous SDP from the peer, it
3658 // indicates that ICE is restarting for this media stream."
3659 TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3660 Init();
3661 cricket::MediaSessionOptions options;
3662 options.recv_audio = true;
3663 options.recv_video = true;
3664 // Create an offer with audio and video.
3665 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3666 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3667 SetRemoteDescriptionWithoutError(offer.release());
3668
3669 SendAudioVideoStream1();
3670 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(nullptr));
3671 SetLocalDescriptionWithoutError(answer.release());
3672
3673 // Receive an offer with a new ufrag but stale password.
3674 rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer(
3675 CreateRemoteOffer(options, session_->remote_description()));
3676 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3677 "original_password12345");
3678 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3679
3680 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
3681 CreateAnswer(nullptr));
3682 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3683 session_->local_description()->description()));
3660 SetLocalDescriptionWithoutError(updated_answer1.release()); 3684 SetLocalDescriptionWithoutError(updated_answer1.release());
3685
3686 // Receive an offer with a new password but stale ufrag.
3687 rtc::scoped_ptr<JsepSessionDescription> password_changed_offer(
3688 CreateRemoteOffer(options, session_->remote_description()));
3689 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3690 "modified_password12345");
3691 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3692
3693 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
3694 CreateAnswer(nullptr));
3695 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3696 session_->local_description()->description()));
3697 SetLocalDescriptionWithoutError(updated_answer2.release());
3661 } 3698 }
3662 3699
3663 // This test verifies that an answer contains old ufrag and password if an offer 3700 // This test verifies that an answer contains old ufrag and password if an offer
3664 // with old ufrag and password is received. 3701 // with old ufrag and password is received.
3665 TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { 3702 TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
3666 Init(); 3703 Init();
3667 cricket::MediaSessionOptions options; 3704 cricket::MediaSessionOptions options;
3668 options.recv_video = true; 3705 options.recv_video = true;
3669 rtc::scoped_ptr<JsepSessionDescription> offer( 3706 rtc::scoped_ptr<JsepSessionDescription> offer(
3670 CreateRemoteOffer(options)); 3707 CreateRemoteOffer(options));
3671 SetRemoteDescriptionWithoutError(offer.release()); 3708 SetRemoteDescriptionWithoutError(offer.release());
3672 3709
3673 SendAudioVideoStream1(); 3710 SendAudioVideoStream1();
3674 rtc::scoped_ptr<SessionDescriptionInterface> answer( 3711 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3675 CreateAnswer(NULL)); 3712 CreateAnswer(NULL));
3676 SetLocalDescriptionWithoutError(answer.release()); 3713 SetLocalDescriptionWithoutError(answer.release());
3677 3714
3678 // Receive an offer without changed ufrag or password. 3715 // Receive an offer without changed ufrag or password.
3679 options.audio_transport_options.ice_restart = false;
3680 options.video_transport_options.ice_restart = false;
3681 options.data_transport_options.ice_restart = false;
3682 rtc::scoped_ptr<JsepSessionDescription> updated_offer2( 3716 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
3683 CreateRemoteOffer(options, session_->remote_description())); 3717 CreateRemoteOffer(options, session_->remote_description()));
3684 SetRemoteDescriptionWithoutError(updated_offer2.release()); 3718 SetRemoteDescriptionWithoutError(updated_offer2.release());
3685 3719
3686 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2( 3720 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
3687 CreateAnswer(NULL)); 3721 CreateAnswer(NULL));
3688 3722
3689 CompareIceUfragAndPassword(updated_answer2->description(), 3723 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3690 session_->local_description()->description(), 3724 session_->local_description()->description()));
3691 true);
3692 3725
3693 SetLocalDescriptionWithoutError(updated_answer2.release()); 3726 SetLocalDescriptionWithoutError(updated_answer2.release());
3694 } 3727 }
3695 3728
3729 // This test verifies that if an offer does an ICE restart on some, but not all
3730 // media sections, the answer will change the ufrag/password in the correct
3731 // media sections.
3732 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3733 Init();
3734 cricket::MediaSessionOptions options;
3735 options.recv_video = true;
3736 options.recv_audio = true;
3737 options.bundle_enabled = false;
3738 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3739
3740 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3741 "aaaaaaaaaaaaaaaaaaaaaa");
3742 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3743 "bbbbbbbbbbbbbbbbbbbbbb");
3744 SetRemoteDescriptionWithoutError(offer.release());
3745
3746 SendAudioVideoStream1();
3747 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(nullptr));
3748 SetLocalDescriptionWithoutError(answer.release());
3749
3750 // Receive an offer with new ufrag and password, but only for the video media
3751 // section.
3752 rtc::scoped_ptr<JsepSessionDescription> updated_offer(
3753 CreateRemoteOffer(options, session_->remote_description()));
3754 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3755 "cccccccccccccccccccccc");
3756 SetRemoteDescriptionWithoutError(updated_offer.release());
3757
3758 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(
3759 CreateAnswer(nullptr));
3760
3761 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3762 session_->local_description()->description(),
3763 cricket::MEDIA_TYPE_AUDIO));
3764
3765 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3766 session_->local_description()->description(),
3767 cricket::MEDIA_TYPE_VIDEO));
3768
3769 SetLocalDescriptionWithoutError(updated_answer.release());
3770 }
3771
3696 TEST_F(WebRtcSessionTest, TestSessionContentError) { 3772 TEST_F(WebRtcSessionTest, TestSessionContentError) {
3697 Init(); 3773 Init();
3698 SendAudioVideoStream1(); 3774 SendAudioVideoStream1();
3699 SessionDescriptionInterface* offer = CreateOffer(); 3775 SessionDescriptionInterface* offer = CreateOffer();
3700 const std::string session_id_orig = offer->session_id(); 3776 const std::string session_id_orig = offer->session_id();
3701 const std::string session_version_orig = offer->session_version(); 3777 const std::string session_version_orig = offer->session_version();
3702 SetLocalDescriptionWithoutError(offer); 3778 SetLocalDescriptionWithoutError(offer);
3703 3779
3704 video_channel_ = media_engine_->GetVideoChannel(0); 3780 video_channel_ = media_engine_->GetVideoChannel(0);
3705 video_channel_->set_fail_set_send_codecs(true); 3781 video_channel_->set_fail_set_send_codecs(true);
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
4255 } 4331 }
4256 4332
4257 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test 4333 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4258 // currently fails because upon disconnection and reconnection OnIceComplete is 4334 // currently fails because upon disconnection and reconnection OnIceComplete is
4259 // called more than once without returning to IceGatheringGathering. 4335 // called more than once without returning to IceGatheringGathering.
4260 4336
4261 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, 4337 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4262 WebRtcSessionTest, 4338 WebRtcSessionTest,
4263 testing::Values(ALREADY_GENERATED, 4339 testing::Values(ALREADY_GENERATED,
4264 DTLS_IDENTITY_STORE)); 4340 DTLS_IDENTITY_STORE));
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/api/webrtcsessiondescriptionfactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698