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

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

Issue 2738353003: Rewrite PeerConnection integration tests using better testing practices. (Closed)
Patch Set: Fixing issues caught by trybots. Created 3 years, 8 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/pc/peerconnection_unittest.cc ('k') | webrtc/pc/test/mockpeerconnectionobservers.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 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 MediaConstraintsInterface* constraints) { 845 MediaConstraintsInterface* constraints) {
844 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> 846 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
845 observer(new rtc::RefCountedObject< 847 observer(new rtc::RefCountedObject<
846 MockCreateSessionDescriptionObserver>()); 848 MockCreateSessionDescriptionObserver>());
847 if (offer) { 849 if (offer) {
848 pc_->CreateOffer(observer, constraints); 850 pc_->CreateOffer(observer, constraints);
849 } else { 851 } else {
850 pc_->CreateAnswer(observer, constraints); 852 pc_->CreateAnswer(observer, constraints);
851 } 853 }
852 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); 854 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
853 desc->reset(observer->release_desc()); 855 *desc = observer->MoveDescription();
854 return observer->result(); 856 return observer->result();
855 } 857 }
856 858
857 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc, 859 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
858 MediaConstraintsInterface* constraints) { 860 MediaConstraintsInterface* constraints) {
859 return DoCreateOfferAnswer(desc, true, constraints); 861 return DoCreateOfferAnswer(desc, true, constraints);
860 } 862 }
861 863
862 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, 864 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
863 MediaConstraintsInterface* constraints) { 865 MediaConstraintsInterface* constraints) {
(...skipping 778 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 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 CreatePeerConnection(); 3157 CreatePeerConnection();
3144 // The RtcEventLog will be reset when the PeerConnection is closed. 3158 // The RtcEventLog will be reset when the PeerConnection is closed.
3145 pc_->Close(); 3159 pc_->Close();
3146 3160
3147 rtc::PlatformFile file = 0; 3161 rtc::PlatformFile file = 0;
3148 int64_t max_size_bytes = 1024; 3162 int64_t max_size_bytes = 1024;
3149 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes)); 3163 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3150 pc_->StopRtcEventLog(); 3164 pc_->StopRtcEventLog();
3151 } 3165 }
3152 3166
3167 // Test that ICE renomination isn't offered if it's not enabled in the PC's
3168 // RTCConfiguration.
3169 TEST_F(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
3170 PeerConnectionInterface::RTCConfiguration config;
3171 config.enable_ice_renomination = false;
3172 CreatePeerConnection(config, nullptr);
3173 AddVoiceStream("foo");
3174
3175 std::unique_ptr<SessionDescriptionInterface> offer;
3176 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3177 cricket::SessionDescription* desc = offer->description();
3178 EXPECT_EQ(1u, desc->transport_infos().size());
3179 EXPECT_FALSE(
3180 desc->transport_infos()[0].description.GetIceParameters().renomination);
3181 }
3182
3183 // Test that the ICE renomination option is present in generated offers/answers
3184 // if it's enabled in the PC's RTCConfiguration.
3185 TEST_F(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
3186 PeerConnectionInterface::RTCConfiguration config;
3187 config.enable_ice_renomination = true;
3188 CreatePeerConnection(config, nullptr);
3189 AddVoiceStream("foo");
3190
3191 std::unique_ptr<SessionDescriptionInterface> offer;
3192 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3193 cricket::SessionDescription* desc = offer->description();
3194 EXPECT_EQ(1u, desc->transport_infos().size());
3195 EXPECT_TRUE(
3196 desc->transport_infos()[0].description.GetIceParameters().renomination);
3197
3198 // Set the offer as a remote description, then create an answer and ensure it
3199 // has the renomination flag too.
3200 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3201 std::unique_ptr<SessionDescriptionInterface> answer;
3202 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3203 desc = answer->description();
3204 EXPECT_EQ(1u, desc->transport_infos().size());
3205 EXPECT_TRUE(
3206 desc->transport_infos()[0].description.GetIceParameters().renomination);
3207 }
3208
3209 // Test that if CreateOffer is called with the deprecated "offer to receive
3210 // audio/video" constraints, they're processed and result in an offer with
3211 // audio/video sections just as if RTCOfferAnswerOptions had been used.
3212 TEST_F(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
3213 CreatePeerConnection();
3214
3215 FakeConstraints constraints;
3216 constraints.SetMandatoryReceiveAudio(true);
3217 constraints.SetMandatoryReceiveVideo(true);
3218 std::unique_ptr<SessionDescriptionInterface> offer;
3219 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3220
3221 cricket::SessionDescription* desc = offer->description();
3222 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3223 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3224 ASSERT_NE(nullptr, audio);
3225 ASSERT_NE(nullptr, video);
3226 EXPECT_FALSE(audio->rejected);
3227 EXPECT_FALSE(video->rejected);
3228 }
3229
3230 // Test that if CreateAnswer is called with the deprecated "offer to receive
3231 // audio/video" constraints, they're processed and can be used to reject an
3232 // offered m= section just as can be done with RTCOfferAnswerOptions;
3233 TEST_F(PeerConnectionInterfaceTest, CreateAnswerWithOfferToReceiveConstraints) {
3234 CreatePeerConnection();
3235
3236 // First, create an offer with audio/video and apply it as a remote
3237 // description.
3238 FakeConstraints constraints;
3239 constraints.SetMandatoryReceiveAudio(true);
3240 constraints.SetMandatoryReceiveVideo(true);
3241 std::unique_ptr<SessionDescriptionInterface> offer;
3242 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3243 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3244
3245 // Now create answer that rejects audio/video.
3246 constraints.SetMandatoryReceiveAudio(false);
3247 constraints.SetMandatoryReceiveVideo(false);
3248 std::unique_ptr<SessionDescriptionInterface> answer;
3249 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3250
3251 cricket::SessionDescription* desc = answer->description();
3252 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3253 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3254 ASSERT_NE(nullptr, audio);
3255 ASSERT_NE(nullptr, video);
3256 EXPECT_TRUE(audio->rejected);
3257 EXPECT_TRUE(video->rejected);
3258 }
3259
3260 #ifdef HAVE_SCTP
3261 #define MAYBE_DataChannelOnlyOfferWithMaxBundlePolicy \
3262 DataChannelOnlyOfferWithMaxBundlePolicy
3263 #else
3264 #define MAYBE_DataChannelOnlyOfferWithMaxBundlePolicy \
3265 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy
3266 #endif
3267
3268 // Test that negotiation can succeed with a data channel only, and with the max
3269 // bundle policy. Previously there was a bug that prevented this.
3270 TEST_F(PeerConnectionInterfaceTest,
3271 MAYBE_DataChannelOnlyOfferWithMaxBundlePolicy) {
3272 PeerConnectionInterface::RTCConfiguration config;
3273 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3274 CreatePeerConnection(config, nullptr);
3275
3276 // First, create an offer with only a data channel and apply it as a remote
3277 // description.
3278 pc_->CreateDataChannel("test", nullptr);
3279 std::unique_ptr<SessionDescriptionInterface> offer;
3280 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3281 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3282
3283 // Create and set answer as well.
3284 std::unique_ptr<SessionDescriptionInterface> answer;
3285 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3286 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
3287 }
3288
3153 class PeerConnectionMediaConfigTest : public testing::Test { 3289 class PeerConnectionMediaConfigTest : public testing::Test {
3154 protected: 3290 protected:
3155 void SetUp() override { 3291 void SetUp() override {
3156 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); 3292 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
3157 pcf_->Initialize(); 3293 pcf_->Initialize();
3158 } 3294 }
3159 const cricket::MediaConfig& TestCreatePeerConnection( 3295 const cricket::MediaConfig& TestCreatePeerConnection(
3160 const PeerConnectionInterface::RTCConfiguration& config, 3296 const PeerConnectionInterface::RTCConfiguration& config,
3161 const MediaConstraintsInterface *constraints) { 3297 const MediaConstraintsInterface *constraints) {
3162 pcf_->create_media_controller_called_ = false; 3298 pcf_->create_media_controller_called_ = false;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
3437 EXPECT_NE(a, f); 3573 EXPECT_NE(a, f);
3438 3574
3439 PeerConnectionInterface::RTCConfiguration g; 3575 PeerConnectionInterface::RTCConfiguration g;
3440 g.disable_ipv6 = true; 3576 g.disable_ipv6 = true;
3441 EXPECT_NE(a, g); 3577 EXPECT_NE(a, g);
3442 3578
3443 PeerConnectionInterface::RTCConfiguration h( 3579 PeerConnectionInterface::RTCConfiguration h(
3444 PeerConnectionInterface::RTCConfigurationType::kAggressive); 3580 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3445 EXPECT_NE(a, h); 3581 EXPECT_NE(a, h);
3446 } 3582 }
OLDNEW
« no previous file with comments | « webrtc/pc/peerconnection_unittest.cc ('k') | webrtc/pc/test/mockpeerconnectionobservers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698