Index: webrtc/pc/mediasession_unittest.cc |
diff --git a/webrtc/pc/mediasession_unittest.cc b/webrtc/pc/mediasession_unittest.cc |
index 6ea7aeb8ab93f0b317e3b323acb88b9f39b15268..4d46dd7df7497289e6b29713084f76e11b0ec0a1 100644 |
--- a/webrtc/pc/mediasession_unittest.cc |
+++ b/webrtc/pc/mediasession_unittest.cc |
@@ -180,6 +180,11 @@ static const char kDataTrack1[] = "data_1"; |
static const char kDataTrack2[] = "data_2"; |
static const char kDataTrack3[] = "data_3"; |
+static const char* kMediaProtocols[] = {"RTP/AVP", "RTP/SAVP", "RTP/AVPF"}; |
Taylor Brandstetter
2016/04/12 21:50:05
What about RTP/SAVPF?
Zhi Huang
2016/04/12 23:00:20
I thought the RTP/SAVPF is the default protocol us
|
+static const char* kMediaProtocolsDtls[] = { |
+ "TCP/TLS/RTP/SAVPF", "TCP/TLS/RTP/SAVP", "UDP/TLS/RTP/SAVPF", |
+ "UDP/TLS/RTP/SAVP"}; |
+ |
static bool IsMediaContentOfType(const ContentInfo* content, |
MediaType media_type) { |
const MediaContentDescription* mdesc = |
@@ -2391,3 +2396,85 @@ TEST_F(MediaSessionDescriptionFactoryTest, |
EXPECT_EQ("video_modified", video_content->name); |
EXPECT_EQ("data_modified", data_content->name); |
} |
+ |
+class MediaProtocolTest : public ::testing::TestWithParam<const char*> { |
+ public: |
+ MediaProtocolTest() : f1_(&tdf1_), f2_(&tdf2_) { |
+ f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1)); |
+ f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); |
+ f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
+ f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2)); |
+ f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); |
+ f2_.set_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
+ f1_.set_secure(SEC_ENABLED); |
+ f2_.set_secure(SEC_ENABLED); |
+ tdf1_.set_certificate(rtc::RTCCertificate::Create( |
+ rtc::scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
+ tdf2_.set_certificate(rtc::RTCCertificate::Create( |
+ rtc::scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
+ tdf1_.set_secure(SEC_ENABLED); |
+ tdf2_.set_secure(SEC_ENABLED); |
+ } |
+ |
+ protected: |
+ MediaSessionDescriptionFactory f1_; |
+ MediaSessionDescriptionFactory f2_; |
+ TransportDescriptionFactory tdf1_; |
+ TransportDescriptionFactory tdf2_; |
+}; |
+ |
+TEST_P(MediaProtocolTest, TestAudioAcceptance) { |
+ std::unique_ptr<SessionDescription> offer( |
+ f1_.CreateOffer(MediaSessionOptions(), NULL)); |
+ ASSERT_TRUE(offer.get() != NULL); |
+ static_cast<MediaContentDescription*>(offer.get()->contents()[0].description) |
+ ->set_protocol(GetParam()); |
+ std::unique_ptr<SessionDescription> answer( |
+ f2_.CreateAnswer(offer.get(), MediaSessionOptions(), NULL)); |
+ const ContentInfo* ac = answer->GetContentByName("audio"); |
+ const ContentInfo* vc = answer->GetContentByName("video"); |
+ ASSERT_TRUE(ac != NULL); |
+ ASSERT_TRUE(vc == NULL); |
+ EXPECT_FALSE(ac->rejected); // the offer is accepted |
+} |
+ |
+TEST_P(MediaProtocolTest, TestVideoAcceptance) { |
Taylor Brandstetter
2016/04/12 21:50:05
I'd rename this to "TestAudioVideoAcceptance". And
|
+ MediaSessionOptions opts; |
+ opts.recv_video = true; |
+ std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
Taylor Brandstetter
2016/04/12 21:50:05
nit: replace "NULL" with C++11 "nullptr"
|
+ ASSERT_TRUE(offer.get() != NULL); |
+ static_cast<MediaContentDescription*>(offer.get()->contents()[0].description) |
+ ->set_protocol(GetParam()); |
+ std::unique_ptr<SessionDescription> answer( |
+ f2_.CreateAnswer(offer.get(), opts, NULL)); |
+ const ContentInfo* ac = answer->GetContentByName("audio"); |
+ const ContentInfo* vc = answer->GetContentByName("video"); |
+ ASSERT_TRUE(ac != NULL); |
+ ASSERT_TRUE(vc != NULL); |
+ EXPECT_FALSE(ac->rejected); // the offer is accepted |
+ EXPECT_FALSE(vc->rejected); |
Taylor Brandstetter
2016/04/12 21:50:05
One extra useful check would be that the protocol
|
+} |
+ |
+TEST_P(MediaProtocolTest, TestDataAcceptance) { |
Taylor Brandstetter
2016/04/12 21:50:05
I'd suggest leaving a TODO to remove this test whe
|
+ MediaSessionOptions opts; |
+ opts.data_channel_type = cricket::DCT_RTP; |
+ std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
+ ASSERT_TRUE(offer.get() != NULL); |
+ static_cast<MediaContentDescription*>(offer.get()->contents()[0].description) |
+ ->set_protocol(GetParam()); |
+ std::unique_ptr<SessionDescription> answer( |
+ f2_.CreateAnswer(offer.get(), opts, NULL)); |
+ const ContentInfo* ac = answer->GetContentByName("audio"); |
+ const ContentInfo* vc = answer->GetContentByName("data"); |
+ ASSERT_TRUE(ac != NULL); |
+ ASSERT_TRUE(vc != NULL); |
+ EXPECT_FALSE(ac->rejected); // the offer is accepted |
+ EXPECT_FALSE(vc->rejected); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P(MediaProtocolPatternTest, |
+ MediaProtocolTest, |
+ ::testing::ValuesIn(kMediaProtocols)); |
+INSTANTIATE_TEST_CASE_P(MediaProtocolDtlsPatternTest, |
+ MediaProtocolTest, |
+ ::testing::ValuesIn(kMediaProtocolsDtls)); |