Index: webrtc/pc/webrtcsdp_unittest.cc |
diff --git a/webrtc/pc/webrtcsdp_unittest.cc b/webrtc/pc/webrtcsdp_unittest.cc |
index f5cac8921f3a3fddadf0672f372ce9f2c4713d1d..816808b6cac63f2a7ba4cde364356edf90fce913 100644 |
--- a/webrtc/pc/webrtcsdp_unittest.cc |
+++ b/webrtc/pc/webrtcsdp_unittest.cc |
@@ -3504,3 +3504,81 @@ TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) { |
JsepSessionDescription jdesc_output(kDummyString); |
EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output)); |
} |
+ |
+// Tests that the connection data on both the session level and media level can |
+// be sucessfully parsed. |
+TEST_F(WebRtcSdpTest, ParseConnectionData) { |
+ JsepSessionDescription jsep_desc(kDummyString); |
+ |
+ // IPv4 addresses. |
+ std::string sdp = kSdpFullString; |
+ InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.1\r\n", &sdp); |
+ EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
+ ASSERT_TRUE(jsep_desc.description()->session_connection_addr()); |
+ // The port is expected to be the default value 0. |
+ EXPECT_EQ("192.168.0.1:0", |
+ jsep_desc.description()->session_connection_addr()->ToString()); |
+ const auto& content1 = jsep_desc.description()->contents()[0]; |
+ EXPECT_EQ("74.125.127.126:0", |
+ static_cast<cricket::MediaContentDescription*>(content1.description) |
+ ->media_connection_addr() |
+ ->ToString()); |
+ const auto& content2 = jsep_desc.description()->contents()[1]; |
+ EXPECT_EQ("74.125.224.39:0", |
+ static_cast<cricket::MediaContentDescription*>(content2.description) |
+ ->media_connection_addr() |
+ ->ToString()); |
+ |
+ // IPv6 addresses/ |
+ sdp = kSdpFullString; |
+ InjectAfter("s=-\r\n", "c=IN IP6 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", |
+ &sdp); |
+ EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
+ Replace("c=IN IP4 74.125.127.126\r\n", |
+ "c=IN IP6 2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n", &sdp); |
+ Replace("c=IN IP4 74.125.224.39\r\n", |
+ "c=IN IP6 2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n", &sdp); |
+ EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
+ ASSERT_TRUE(jsep_desc.description()->session_connection_addr()); |
+ EXPECT_EQ("[2001:db8:85a3::8a2e:370:7334]:0", |
+ jsep_desc.description()->session_connection_addr()->ToString()); |
+ const auto& content3 = jsep_desc.description()->contents()[0]; |
+ EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:0", |
+ static_cast<cricket::MediaContentDescription*>(content3.description) |
+ ->media_connection_addr() |
+ ->ToString()); |
+ const auto& content4 = jsep_desc.description()->contents()[1]; |
+ EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:0", |
+ static_cast<cricket::MediaContentDescription*>(content4.description) |
+ ->media_connection_addr() |
+ ->ToString()); |
+} |
+ |
+// Test that the invalid connection data cannot be parsed. |
Taylor Brandstetter
2017/03/10 22:41:18
I'd use the term "unsupported" rather than "invali
|
+TEST_F(WebRtcSdpTest, ParseInvalidConnectionData) { |
+ JsepSessionDescription jsep_desc(kDummyString); |
+ std::string sdp = kSdpFullString; |
+ EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
+ |
+ // Invalid session level IPv4 address. |
+ InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.1/127\r\n", &sdp); |
+ EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
+ |
+ // Invalid media level IPv4 address. |
+ sdp = kSdpFullString; |
+ Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp); |
+ EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
+ |
+ // Invalid session level IPv6 address. |
+ sdp = kSdpFullString; |
+ EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
+ InjectAfter("s=-\r\n", |
+ "c=IN IP6 2001:0db8:85a3:0000:0000:8a2e:0370:7334/3\r\n", &sdp); |
+ EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
+ |
+ // Invalid media level IPv6 address. |
+ sdp = kSdpFullString; |
+ Replace("c=IN IP4 74.125.224.39\r\n", |
+ "c=IN IP6 2001:0db8:85a3:0000:0000:8a2e:0370:7334/3\r\n", &sdp); |
+ EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
+} |