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

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

Issue 2690943011: Use the same draft version in SDP data channel answers as used in the offer. (Closed)
Patch Set: No actual changes from Patch Set 1 (learning the tools). Created 3 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
« webrtc/pc/webrtcsdp.cc ('K') | « webrtc/pc/webrtcsdp.cc ('k') | no next file » | 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 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2011 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 using webrtc::JsepIceCandidate; 58 using webrtc::JsepIceCandidate;
59 using webrtc::JsepSessionDescription; 59 using webrtc::JsepSessionDescription;
60 using webrtc::RtpExtension; 60 using webrtc::RtpExtension;
61 using webrtc::SdpParseError; 61 using webrtc::SdpParseError;
62 using webrtc::SessionDescriptionInterface; 62 using webrtc::SessionDescriptionInterface;
63 63
64 typedef std::vector<AudioCodec> AudioCodecs; 64 typedef std::vector<AudioCodec> AudioCodecs;
65 typedef std::vector<Candidate> Candidates; 65 typedef std::vector<Candidate> Candidates;
66 66
67 static const uint32_t kDefaultSctpPort = 5000; 67 static const uint32_t kDefaultSctpPort = 5000;
68 static const char kDefaultSctpPortStr[] = "5000";
69 static const uint16_t kUnusualSctpPort = 9556;
70 static const char kUnusualSctpPortStr[] = "9556";
68 static const char kSessionTime[] = "t=0 0\r\n"; 71 static const char kSessionTime[] = "t=0 0\r\n";
69 static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 72 static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
70 static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n"; 73 static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
71 static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; 74 static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
72 static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n"; 75 static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
73 static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; 76 static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
74 static const uint32_t kCandidateGeneration = 2; 77 static const uint32_t kCandidateGeneration = 2;
75 static const char kCandidateFoundation1[] = "a0+B/1"; 78 static const char kCandidateFoundation1[] = "a0+B/1";
76 static const char kCandidateFoundation2[] = "a0+B/2"; 79 static const char kCandidateFoundation2[] = "a0+B/2";
77 static const char kCandidateFoundation3[] = "a0+B/3"; 80 static const char kCandidateFoundation3[] = "a0+B/3";
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 ASSERT_EQ(cd1->rtp_header_extensions().size(), 1206 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1204 cd2->rtp_header_extensions().size()); 1207 cd2->rtp_header_extensions().size());
1205 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) { 1208 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1206 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); 1209 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1207 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); 1210 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
1208 EXPECT_EQ(ext1.uri, ext2.uri); 1211 EXPECT_EQ(ext1.uri, ext2.uri);
1209 EXPECT_EQ(ext1.id, ext2.id); 1212 EXPECT_EQ(ext1.id, ext2.id);
1210 } 1213 }
1211 } 1214 }
1212 1215
1216 void CompareDataContentDescription(const DataContentDescription* dcd1,
1217 const DataContentDescription* dcd2) {
1218 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1219 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1220 }
1213 1221
1214 void CompareSessionDescription(const SessionDescription& desc1, 1222 void CompareSessionDescription(const SessionDescription& desc1,
1215 const SessionDescription& desc2) { 1223 const SessionDescription& desc2) {
1216 // Compare content descriptions. 1224 // Compare content descriptions.
1217 if (desc1.contents().size() != desc2.contents().size()) { 1225 if (desc1.contents().size() != desc2.contents().size()) {
1218 ADD_FAILURE(); 1226 ADD_FAILURE();
1219 return; 1227 return;
1220 } 1228 }
1221 for (size_t i = 0 ; i < desc1.contents().size(); ++i) { 1229 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1222 const cricket::ContentInfo& c1 = desc1.contents().at(i); 1230 const cricket::ContentInfo& c1 = desc1.contents().at(i);
(...skipping 21 matching lines...) Expand all
1244 static_cast<const VideoContentDescription*>(c2.description); 1252 static_cast<const VideoContentDescription*>(c2.description);
1245 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2); 1253 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1246 } 1254 }
1247 1255
1248 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2)); 1256 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1249 if (IsDataContent(&c1)) { 1257 if (IsDataContent(&c1)) {
1250 const DataContentDescription* dcd1 = 1258 const DataContentDescription* dcd1 =
1251 static_cast<const DataContentDescription*>(c1.description); 1259 static_cast<const DataContentDescription*>(c1.description);
1252 const DataContentDescription* dcd2 = 1260 const DataContentDescription* dcd2 =
1253 static_cast<const DataContentDescription*>(c2.description); 1261 static_cast<const DataContentDescription*>(c2.description);
1254 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2); 1262 CompareDataContentDescription(dcd1, dcd2);
1255 } 1263 }
1256 } 1264 }
1257 1265
1258 // group 1266 // group
1259 const cricket::ContentGroups groups1 = desc1.groups(); 1267 const cricket::ContentGroups groups1 = desc1.groups();
1260 const cricket::ContentGroups groups2 = desc2.groups(); 1268 const cricket::ContentGroups groups2 = desc2.groups();
1261 EXPECT_EQ(groups1.size(), groups1.size()); 1269 EXPECT_EQ(groups1.size(), groups1.size());
1262 if (groups1.size() != groups2.size()) { 1270 if (groups1.size() != groups2.size()) {
1263 ADD_FAILURE(); 1271 ADD_FAILURE();
1264 return; 1272 return;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 JsepSessionDescription jdesc_no_candidates(kDummyString); 1487 JsepSessionDescription jdesc_no_candidates(kDummyString);
1480 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, 1488 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1481 kSessionVersion)) { 1489 kSessionVersion)) {
1482 return false; 1490 return false;
1483 } 1491 }
1484 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); 1492 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
1485 EXPECT_EQ(new_sdp, message); 1493 EXPECT_EQ(new_sdp, message);
1486 return true; 1494 return true;
1487 } 1495 }
1488 1496
1489 void AddSctpDataChannel() { 1497 void AddSctpDataChannel(bool use_sctpmap) {
1490 std::unique_ptr<DataContentDescription> data(new DataContentDescription()); 1498 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
1491 data_desc_ = data.get(); 1499 data_desc_ = data.get();
1500 data_desc_->set_use_sctpmap(use_sctpmap);
1492 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); 1501 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
1493 DataCodec codec(cricket::kGoogleSctpDataCodecPlType, 1502 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
1494 cricket::kGoogleSctpDataCodecName); 1503 cricket::kGoogleSctpDataCodecName);
1495 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort); 1504 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1496 data_desc_->AddCodec(codec); 1505 data_desc_->AddCodec(codec);
1497 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release()); 1506 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
1498 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( 1507 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1499 kDataContentName, TransportDescription(kUfragData, kPwdData)))); 1508 kDataContentName, TransportDescription(kUfragData, kPwdData))));
1500 } 1509 }
1501 1510
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 2060
2052 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2061 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2053 std::string message = webrtc::SdpSerialize(jsep_desc, false); 2062 std::string message = webrtc::SdpSerialize(jsep_desc, false);
2054 2063
2055 std::string expected_sdp = kSdpString; 2064 std::string expected_sdp = kSdpString;
2056 expected_sdp.append(kSdpRtpDataChannelString); 2065 expected_sdp.append(kSdpRtpDataChannelString);
2057 EXPECT_EQ(expected_sdp, message); 2066 EXPECT_EQ(expected_sdp, message);
2058 } 2067 }
2059 2068
2060 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) { 2069 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
2061 AddSctpDataChannel(); 2070 AddSctpDataChannel(true);
2062 JsepSessionDescription jsep_desc(kDummyString); 2071 JsepSessionDescription jsep_desc(kDummyString);
2063 2072
2064 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2073 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2065 std::string message = webrtc::SdpSerialize(jsep_desc, false); 2074 std::string message = webrtc::SdpSerialize(jsep_desc, false);
2066 2075
2067 std::string expected_sdp = kSdpString; 2076 std::string expected_sdp = kSdpString;
2068 expected_sdp.append(kSdpSctpDataChannelString); 2077 expected_sdp.append(kSdpSctpDataChannelString);
2069 EXPECT_EQ(message, expected_sdp); 2078 EXPECT_EQ(message, expected_sdp);
2070 } 2079 }
2071 2080
2072 TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) { 2081 TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
2073 AddSctpDataChannel(); 2082 AddSctpDataChannel(true);
2074 JsepSessionDescription jsep_desc(kDummyString); 2083 JsepSessionDescription jsep_desc(kDummyString);
2075 2084
2076 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2085 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2077 DataContentDescription* dcdesc = static_cast<DataContentDescription*>( 2086 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2078 jsep_desc.description()->GetContentDescriptionByName(kDataContentName)); 2087 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
2079 2088
2080 const int kNewPort = 1234; 2089 const int kNewPort = 1234;
2081 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType, 2090 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
2082 cricket::kGoogleSctpDataCodecName); 2091 cricket::kGoogleSctpDataCodecName);
2083 codec.SetParam(cricket::kCodecParamPort, kNewPort); 2092 codec.SetParam(cricket::kCodecParamPort, kNewPort);
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 sdp_with_data.append(kSdpRtpDataChannelString); 2572 sdp_with_data.append(kSdpRtpDataChannelString);
2564 JsepSessionDescription jdesc_output(kDummyString); 2573 JsepSessionDescription jdesc_output(kDummyString);
2565 2574
2566 // Deserialize 2575 // Deserialize
2567 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2576 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2568 // Verify 2577 // Verify
2569 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2578 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2570 } 2579 }
2571 2580
2572 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { 2581 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2573 AddSctpDataChannel(); 2582 AddSctpDataChannel(true);
2574 JsepSessionDescription jdesc(kDummyString); 2583 JsepSessionDescription jdesc(kDummyString);
2575 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2584 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2576 2585
2577 std::string sdp_with_data = kSdpString; 2586 std::string sdp_with_data = kSdpString;
2578 sdp_with_data.append(kSdpSctpDataChannelString); 2587 sdp_with_data.append(kSdpSctpDataChannelString);
2579 JsepSessionDescription jdesc_output(kDummyString); 2588 JsepSessionDescription jdesc_output(kDummyString);
2580 2589
2581 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString). 2590 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2582 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2591 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2583 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2592 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2584 2593
2585 // Verify with UDP/DTLS/SCTP. 2594 // Verify with UDP/DTLS/SCTP.
2586 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), 2595 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2587 strlen(kDtlsSctp), kUdpDtlsSctp); 2596 strlen(kDtlsSctp), kUdpDtlsSctp);
2588 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2597 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2589 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2598 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2590 2599
2591 // Verify with TCP/DTLS/SCTP. 2600 // Verify with TCP/DTLS/SCTP.
2592 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), 2601 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2593 strlen(kUdpDtlsSctp), kTcpDtlsSctp); 2602 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2594 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2603 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2595 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2604 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2596 } 2605 }
2597 2606
2598 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { 2607 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2599 AddSctpDataChannel(); 2608 AddSctpDataChannel(false);
2600 JsepSessionDescription jdesc(kDummyString); 2609 JsepSessionDescription jdesc(kDummyString);
2601 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2610 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2602 2611
2603 std::string sdp_with_data = kSdpString; 2612 std::string sdp_with_data = kSdpString;
2604 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); 2613 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2605 JsepSessionDescription jdesc_output(kDummyString); 2614 JsepSessionDescription jdesc_output(kDummyString);
2606 2615
2607 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort). 2616 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
2608 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2617 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2609 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2618 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2610 2619
2611 // Verify with UDP/DTLS/SCTP. 2620 // Verify with UDP/DTLS/SCTP.
2612 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), 2621 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2613 strlen(kDtlsSctp), kUdpDtlsSctp); 2622 strlen(kDtlsSctp), kUdpDtlsSctp);
2614 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2623 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2615 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2624 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2616 2625
2617 // Verify with TCP/DTLS/SCTP. 2626 // Verify with TCP/DTLS/SCTP.
2618 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), 2627 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2619 strlen(kUdpDtlsSctp), kTcpDtlsSctp); 2628 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2620 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2629 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2621 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2630 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2622 } 2631 }
2623 2632
2624 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { 2633 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2625 AddSctpDataChannel(); 2634 AddSctpDataChannel(false);
2626 JsepSessionDescription jdesc(kDummyString); 2635 JsepSessionDescription jdesc(kDummyString);
2627 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2636 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2628 2637
2629 std::string sdp_with_data = kSdpString; 2638 std::string sdp_with_data = kSdpString;
2630 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); 2639 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2631 JsepSessionDescription jdesc_output(kDummyString); 2640 JsepSessionDescription jdesc_output(kDummyString);
2632 2641
2633 // Verify with DTLS/SCTP. 2642 // Verify with DTLS/SCTP.
2634 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2643 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2635 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2644 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2636 2645
2637 // Verify with UDP/DTLS/SCTP. 2646 // Verify with UDP/DTLS/SCTP.
2638 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), 2647 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2639 strlen(kDtlsSctp), kUdpDtlsSctp); 2648 strlen(kDtlsSctp), kUdpDtlsSctp);
2640 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2649 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2641 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2650 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2642 2651
2643 // Verify with TCP/DTLS/SCTP. 2652 // Verify with TCP/DTLS/SCTP.
2644 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), 2653 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2645 strlen(kUdpDtlsSctp), kTcpDtlsSctp); 2654 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2646 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2655 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2647 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2656 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2648 } 2657 }
2649 2658
2650 // Test to check the behaviour if sctp-port is specified 2659 // Test to check the behaviour if sctp-port is specified
2651 // on the m= line and in a=sctp-port. 2660 // on the m= line and in a=sctp-port.
2652 TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { 2661 TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2653 AddSctpDataChannel(); 2662 AddSctpDataChannel(true);
2654 JsepSessionDescription jdesc(kDummyString); 2663 JsepSessionDescription jdesc(kDummyString);
2655 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2664 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2656 2665
2657 std::string sdp_with_data = kSdpString; 2666 std::string sdp_with_data = kSdpString;
2658 // Append m= attributes 2667 // Append m= attributes
2659 sdp_with_data.append(kSdpSctpDataChannelString); 2668 sdp_with_data.append(kSdpSctpDataChannelString);
2660 // Append a=sctp-port attribute 2669 // Append a=sctp-port attribute
2661 sdp_with_data.append("a=sctp-port 5000\r\n"); 2670 sdp_with_data.append("a=sctp-port 5000\r\n");
2662 JsepSessionDescription jdesc_output(kDummyString); 2671 JsepSessionDescription jdesc_output(kDummyString);
2663 2672
2664 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2673 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2665 } 2674 }
2666 2675
2667 // For crbug/344475. 2676 // For crbug/344475.
2668 TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { 2677 TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2669 std::string sdp_with_data = kSdpString; 2678 std::string sdp_with_data = kSdpString;
2670 sdp_with_data.append(kSdpSctpDataChannelString); 2679 sdp_with_data.append(kSdpSctpDataChannelString);
2671 // Remove the "\n" at the end. 2680 // Remove the "\n" at the end.
2672 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); 2681 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2673 JsepSessionDescription jdesc_output(kDummyString); 2682 JsepSessionDescription jdesc_output(kDummyString);
2674 2683
2675 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2684 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2676 // No crash is a pass. 2685 // No crash is a pass.
2677 } 2686 }
2678 2687
2679 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) { 2688 void MutateJsepSctpPort(JsepSessionDescription& jdesc,
2680 AddSctpDataChannel(); 2689 const SessionDescription& desc) {
2681 const uint16_t kUnusualSctpPort = 9556;
2682 char default_portstr[16];
2683 char unusual_portstr[16];
2684 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
2685 kDefaultSctpPort);
2686 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
2687 kUnusualSctpPort);
2688
2689 // First setup the expected JsepSessionDescription.
2690 JsepSessionDescription jdesc(kDummyString);
2691 // take our pre-built session description and change the SCTP port. 2690 // take our pre-built session description and change the SCTP port.
2692 cricket::SessionDescription* mutant = desc_.Copy(); 2691 cricket::SessionDescription* mutant = desc.Copy();
2693 DataContentDescription* dcdesc = static_cast<DataContentDescription*>( 2692 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2694 mutant->GetContentDescriptionByName(kDataContentName)); 2693 mutant->GetContentDescriptionByName(kDataContentName));
2695 std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); 2694 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
2696 EXPECT_EQ(1U, codecs.size()); 2695 EXPECT_EQ(1U, codecs.size());
2697 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id); 2696 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
2698 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); 2697 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
2699 dcdesc->set_codecs(codecs); 2698 dcdesc->set_codecs(codecs);
2700 2699
2701 // note: mutant's owned by jdesc now. 2700 // note: mutant's owned by jdesc now.
2702 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion)); 2701 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2703 mutant = NULL; 2702 mutant = NULL;
2703 }
2704
2705 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2706 AddSctpDataChannel(true);
Taylor Brandstetter 2017/02/17 02:10:57 nit: In situations where you may wonder "what does
Zach Stein 2017/02/17 21:29:17 Done.
2707
2708 // First setup the expected JsepSessionDescription.
2709 JsepSessionDescription jdesc(kDummyString);
2710 MutateJsepSctpPort(jdesc, desc_);
2704 2711
2705 // Then get the deserialized JsepSessionDescription. 2712 // Then get the deserialized JsepSessionDescription.
2706 std::string sdp_with_data = kSdpString; 2713 std::string sdp_with_data = kSdpString;
2707 sdp_with_data.append(kSdpSctpDataChannelString); 2714 sdp_with_data.append(kSdpSctpDataChannelString);
2708 rtc::replace_substrs(default_portstr, strlen(default_portstr), 2715 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2709 unusual_portstr, strlen(unusual_portstr), 2716 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2710 &sdp_with_data); 2717 &sdp_with_data);
2711 JsepSessionDescription jdesc_output(kDummyString); 2718 JsepSessionDescription jdesc_output(kDummyString);
2712 2719
2713 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2720 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2714 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2721 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2722 }
2723
2724 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewUnusualPort) {
Taylor Brandstetter 2017/02/17 02:10:56 nit: "AndNew" doesn't quite make it clear what's b
Zach Stein 2017/02/17 21:29:17 Done.
2725 AddSctpDataChannel(false);
2726
2727 JsepSessionDescription jdesc(kDummyString);
2728 MutateJsepSctpPort(jdesc, desc_);
2715 2729
2716 // We need to test the deserialized JsepSessionDescription from 2730 // We need to test the deserialized JsepSessionDescription from
2717 // kSdpSctpDataChannelStringWithSctpPort for 2731 // kSdpSctpDataChannelStringWithSctpPort for
2718 // draft-ietf-mmusic-sctp-sdp-07 2732 // draft-ietf-mmusic-sctp-sdp-07
2719 // a=sctp-port 2733 // a=sctp-port
2720 sdp_with_data = kSdpString; 2734 std::string sdp_with_data = kSdpString;
2721 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); 2735 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2722 rtc::replace_substrs(default_portstr, strlen(default_portstr), 2736 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2723 unusual_portstr, strlen(unusual_portstr), 2737 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2724 &sdp_with_data); 2738 &sdp_with_data);
2739 JsepSessionDescription jdesc_output(kDummyString);
2725 2740
2726 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); 2741 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2727 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); 2742 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2728 } 2743 }
2729 2744
2730 TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) { 2745 TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
2731 // We want to test that deserializing data content limits bandwidth 2746 // We want to test that deserializing data content limits bandwidth
2732 // settings (it should never be greater than the default). 2747 // settings (it should never be greater than the default).
2733 // This should prevent someone from using unlimited data bandwidth through 2748 // This should prevent someone from using unlimited data bandwidth through
2734 // JS and "breaking the Internet". 2749 // JS and "breaking the Internet".
2735 // See: https://code.google.com/p/chromium/issues/detail?id=280726 2750 // See: https://code.google.com/p/chromium/issues/detail?id=280726
2736 std::string sdp_with_bandwidth = kSdpString; 2751 std::string sdp_with_bandwidth = kSdpString;
2737 sdp_with_bandwidth.append(kSdpRtpDataChannelString); 2752 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2738 InjectAfter("a=mid:data_content_name\r\n", 2753 InjectAfter("a=mid:data_content_name\r\n",
2739 "b=AS:100\r\n", 2754 "b=AS:100\r\n",
2740 &sdp_with_bandwidth); 2755 &sdp_with_bandwidth);
2741 JsepSessionDescription jdesc_with_bandwidth(kDummyString); 2756 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2742 2757
2743 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); 2758 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2744 } 2759 }
2745 2760
2746 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { 2761 TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2747 AddSctpDataChannel(); 2762 AddSctpDataChannel(true);
2748 JsepSessionDescription jdesc(kDummyString); 2763 JsepSessionDescription jdesc(kDummyString);
2749 DataContentDescription* dcd = static_cast<DataContentDescription*>( 2764 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2750 GetFirstDataContent(&desc_)->description); 2765 GetFirstDataContent(&desc_)->description);
2751 dcd->set_bandwidth(100 * 1000); 2766 dcd->set_bandwidth(100 * 1000);
2752 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); 2767 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2753 2768
2754 std::string sdp_with_bandwidth = kSdpString; 2769 std::string sdp_with_bandwidth = kSdpString;
2755 sdp_with_bandwidth.append(kSdpSctpDataChannelString); 2770 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2756 InjectAfter("a=mid:data_content_name\r\n", 2771 InjectAfter("a=mid:data_content_name\r\n",
2757 "b=AS:100\r\n", 2772 "b=AS:100\r\n",
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
3417 JsepSessionDescription jdesc_output(kDummyString); 3432 JsepSessionDescription jdesc_output(kDummyString);
3418 EXPECT_TRUE( 3433 EXPECT_TRUE(
3419 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output)); 3434 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3420 const IceCandidateCollection* candidates = jdesc_output.candidates(0); 3435 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3421 ASSERT_NE(nullptr, candidates); 3436 ASSERT_NE(nullptr, candidates);
3422 ASSERT_EQ(1, candidates->count()); 3437 ASSERT_EQ(1, candidates->count());
3423 cricket::Candidate c = candidates->at(0)->candidate(); 3438 cricket::Candidate c = candidates->at(0)->candidate();
3424 EXPECT_EQ("ufrag_voice", c.username()); 3439 EXPECT_EQ("ufrag_voice", c.username());
3425 EXPECT_EQ("pwd_voice", c.password()); 3440 EXPECT_EQ("pwd_voice", c.password());
3426 } 3441 }
OLDNEW
« webrtc/pc/webrtcsdp.cc ('K') | « webrtc/pc/webrtcsdp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698