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

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

Issue 2738353003: Rewrite PeerConnection integration tests using better testing practices. (Closed)
Patch Set: Add the missing tests for CreateOffer/CreateAnswer with constraints. Created 3 years, 9 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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 config.servers.push_back(server); 725 config.servers.push_back(server);
726 CreatePeerConnection(config, nullptr); 726 CreatePeerConnection(config, nullptr);
727 } 727 }
728 728
729 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config, 729 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config,
730 webrtc::MediaConstraintsInterface* constraints) { 730 webrtc::MediaConstraintsInterface* constraints) {
731 std::unique_ptr<cricket::FakePortAllocator> port_allocator( 731 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
732 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); 732 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
733 port_allocator_ = port_allocator.get(); 733 port_allocator_ = port_allocator.get();
734 734
735 // Create certificate generator unless DTLS constraint is explicitly set to
736 // false.
735 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator; 737 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
736 bool dtls; 738 bool dtls;
737 if (FindConstraint(constraints, 739 if (FindConstraint(constraints,
738 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, 740 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
739 &dtls, 741 &dtls,
740 nullptr) && dtls) { 742 nullptr) && dtls) {
741 fake_certificate_generator_ = new FakeRTCCertificateGenerator(); 743 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
742 cert_generator.reset(fake_certificate_generator_); 744 cert_generator.reset(fake_certificate_generator_);
743 } 745 }
744 pc_ = pc_factory_->CreatePeerConnection( 746 pc_ = pc_factory_->CreatePeerConnection(
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 stream->RemoveTrack(stream->GetVideoTracks()[0]); 1644 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1643 1645
1644 std::unique_ptr<SessionDescriptionInterface> offer; 1646 std::unique_ptr<SessionDescriptionInterface> offer;
1645 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); 1647 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1646 1648
1647 const cricket::MediaContentDescription* video_desc = 1649 const cricket::MediaContentDescription* video_desc =
1648 cricket::GetFirstVideoContentDescription(offer->description()); 1650 cricket::GetFirstVideoContentDescription(offer->description());
1649 EXPECT_TRUE(video_desc == nullptr); 1651 EXPECT_TRUE(video_desc == nullptr);
1650 } 1652 }
1651 1653
1654 // Verify that CreateDtmfSender only succeeds if called with a valid local
1655 // track. Other aspects of DtmfSenders are tested in
1656 // peerconnection_integrationtest.cc.
1657 TEST_F(PeerConnectionInterfaceTest, CreateDtmfSenderWithInvalidParams) {
1658 CreatePeerConnection();
1659 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1660 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(nullptr));
1661 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
1662 pc_factory_->CreateAudioTrack("dummy_track", nullptr));
1663 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(non_localtrack));
1664 }
1665
1652 // Test creating a sender with a stream ID, and ensure the ID is populated 1666 // Test creating a sender with a stream ID, and ensure the ID is populated
1653 // in the offer. 1667 // in the offer.
1654 TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) { 1668 TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
1655 CreatePeerConnectionWithoutDtls(); 1669 CreatePeerConnectionWithoutDtls();
1656 pc_->CreateSender("video", kStreamLabel1); 1670 pc_->CreateSender("video", kStreamLabel1);
1657 1671
1658 std::unique_ptr<SessionDescriptionInterface> offer; 1672 std::unique_ptr<SessionDescriptionInterface> offer;
1659 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); 1673 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1660 1674
1661 const cricket::MediaContentDescription* video_desc = 1675 const cricket::MediaContentDescription* video_desc =
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after
3106 CreatePeerConnection(); 3120 CreatePeerConnection();
3107 // The RtcEventLog will be reset when the PeerConnection is closed. 3121 // The RtcEventLog will be reset when the PeerConnection is closed.
3108 pc_->Close(); 3122 pc_->Close();
3109 3123
3110 rtc::PlatformFile file = 0; 3124 rtc::PlatformFile file = 0;
3111 int64_t max_size_bytes = 1024; 3125 int64_t max_size_bytes = 1024;
3112 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes)); 3126 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3113 pc_->StopRtcEventLog(); 3127 pc_->StopRtcEventLog();
3114 } 3128 }
3115 3129
3130 // Test that ICE renomination isn't offered if it's not enabled in the PC's
3131 // RTCConfiguration.
3132 TEST_F(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
3133 PeerConnectionInterface::RTCConfiguration config;
3134 config.enable_ice_renomination = false;
3135 CreatePeerConnection(config, nullptr);
3136 AddVoiceStream("foo");
3137
3138 std::unique_ptr<SessionDescriptionInterface> offer;
3139 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3140 cricket::SessionDescription* desc = offer->description();
3141 EXPECT_EQ(1u, desc->transport_infos().size());
3142 EXPECT_FALSE(
3143 desc->transport_infos()[0].description.GetIceParameters().renomination);
3144 }
3145
3146 // Test that the ICE renomination option is present in generated offers/answers
3147 // if it's enabled in the PC's RTCConfiguration.
3148 TEST_F(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
3149 PeerConnectionInterface::RTCConfiguration config;
3150 config.enable_ice_renomination = true;
3151 CreatePeerConnection(config, nullptr);
3152 AddVoiceStream("foo");
3153
3154 std::unique_ptr<SessionDescriptionInterface> offer;
3155 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3156 cricket::SessionDescription* desc = offer->description();
3157 EXPECT_EQ(1u, desc->transport_infos().size());
3158 EXPECT_TRUE(
3159 desc->transport_infos()[0].description.GetIceParameters().renomination);
3160
3161 // Set the offer as a remote description, then create an answer and ensure it
3162 // has the renomination flag too.
3163 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3164 std::unique_ptr<SessionDescriptionInterface> answer;
3165 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3166 desc = answer->description();
3167 EXPECT_EQ(1u, desc->transport_infos().size());
3168 EXPECT_TRUE(
3169 desc->transport_infos()[0].description.GetIceParameters().renomination);
3170 }
3171
3172 // Test that if CreateOffer is called with the deprecated "offer to receive
3173 // audio/video" constraints, they're processed and result in an offer with
3174 // audio/video sections just as if RTCOfferAnswerOptions had been used.
3175 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
3176 CreatePeerConnection();
3177
3178 FakeConstraints constraints;
3179 constraints.SetMandatoryReceiveAudio(true);
3180 constraints.SetMandatoryReceiveVideo(true);
3181 std::unique_ptr<SessionDescriptionInterface> offer;
3182 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3183
3184 cricket::SessionDescription* desc = offer->description();
3185 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3186 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3187 ASSERT_NE(nullptr, audio);
3188 ASSERT_NE(nullptr, video);
3189 EXPECT_FALSE(audio->rejected);
3190 EXPECT_FALSE(video->rejected);
3191 }
3192
3193 // Test that if CreateAnswer is called with the deprecated "offer to receive
3194 // audio/video" constraints, they're processed and can be used to reject an
3195 // offered m= section just as can be done with RTCOfferAnswerOptions;
3196 TEST_F(PeerConnectionInterfaceTest, CreateAnswerWithOfferToReceiveConstraints) {
3197 CreatePeerConnection();
3198
3199 // First, create an offer with audio/video and apply it as a remote
3200 // description.
3201 FakeConstraints constraints;
3202 constraints.SetMandatoryReceiveAudio(true);
3203 constraints.SetMandatoryReceiveVideo(true);
3204 std::unique_ptr<SessionDescriptionInterface> offer;
3205 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3206 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3207
3208 // Now create answer that rejects audio/video.
3209 constraints.SetMandatoryReceiveAudio(false);
3210 constraints.SetMandatoryReceiveVideo(false);
3211 std::unique_ptr<SessionDescriptionInterface> answer;
3212 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3213
3214 cricket::SessionDescription* desc = answer->description();
3215 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3216 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3217 ASSERT_NE(nullptr, audio);
3218 ASSERT_NE(nullptr, video);
3219 EXPECT_TRUE(audio->rejected);
3220 EXPECT_TRUE(video->rejected);
3221 }
3222
3116 class PeerConnectionMediaConfigTest : public testing::Test { 3223 class PeerConnectionMediaConfigTest : public testing::Test {
3117 protected: 3224 protected:
3118 void SetUp() override { 3225 void SetUp() override {
3119 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); 3226 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
3120 pcf_->Initialize(); 3227 pcf_->Initialize();
3121 } 3228 }
3122 const cricket::MediaConfig& TestCreatePeerConnection( 3229 const cricket::MediaConfig& TestCreatePeerConnection(
3123 const PeerConnectionInterface::RTCConfiguration& config, 3230 const PeerConnectionInterface::RTCConfiguration& config,
3124 const MediaConstraintsInterface *constraints) { 3231 const MediaConstraintsInterface *constraints) {
3125 pcf_->create_media_controller_called_ = false; 3232 pcf_->create_media_controller_called_ = false;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
3400 EXPECT_NE(a, f); 3507 EXPECT_NE(a, f);
3401 3508
3402 PeerConnectionInterface::RTCConfiguration g; 3509 PeerConnectionInterface::RTCConfiguration g;
3403 g.disable_ipv6 = true; 3510 g.disable_ipv6 = true;
3404 EXPECT_NE(a, g); 3511 EXPECT_NE(a, g);
3405 3512
3406 PeerConnectionInterface::RTCConfiguration h( 3513 PeerConnectionInterface::RTCConfiguration h(
3407 PeerConnectionInterface::RTCConfigurationType::kAggressive); 3514 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3408 EXPECT_NE(a, h); 3515 EXPECT_NE(a, h);
3409 } 3516 }
OLDNEW
« webrtc/pc/iceserverparsing_unittest.cc ('K') | « webrtc/pc/peerconnection_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698