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

Side by Side Diff: talk/app/webrtc/peerconnectioninterface_unittest.cc

Issue 1520963002: Removing webrtc::PortAllocatorFactoryInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing patch conflicts Created 5 years 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 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 11 matching lines...) Expand all
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include <string> 28 #include <string>
29 #include <utility> 29 #include <utility>
30 30
31 #include "talk/app/webrtc/audiotrack.h" 31 #include "talk/app/webrtc/audiotrack.h"
32 #include "talk/app/webrtc/fakeportallocatorfactory.h"
33 #include "talk/app/webrtc/jsepsessiondescription.h" 32 #include "talk/app/webrtc/jsepsessiondescription.h"
34 #include "talk/app/webrtc/mediastream.h" 33 #include "talk/app/webrtc/mediastream.h"
35 #include "talk/app/webrtc/mediastreaminterface.h" 34 #include "talk/app/webrtc/mediastreaminterface.h"
36 #include "talk/app/webrtc/peerconnection.h" 35 #include "talk/app/webrtc/peerconnection.h"
37 #include "talk/app/webrtc/peerconnectioninterface.h" 36 #include "talk/app/webrtc/peerconnectioninterface.h"
38 #include "talk/app/webrtc/rtpreceiverinterface.h" 37 #include "talk/app/webrtc/rtpreceiverinterface.h"
39 #include "talk/app/webrtc/rtpsenderinterface.h" 38 #include "talk/app/webrtc/rtpsenderinterface.h"
40 #include "talk/app/webrtc/streamcollection.h" 39 #include "talk/app/webrtc/streamcollection.h"
41 #include "talk/app/webrtc/test/fakeconstraints.h" 40 #include "talk/app/webrtc/test/fakeconstraints.h"
42 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" 41 #include "talk/app/webrtc/test/fakedtlsidentitystore.h"
43 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" 42 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h"
44 #include "talk/app/webrtc/test/testsdpstrings.h" 43 #include "talk/app/webrtc/test/testsdpstrings.h"
45 #include "talk/app/webrtc/videosource.h" 44 #include "talk/app/webrtc/videosource.h"
46 #include "talk/app/webrtc/videotrack.h" 45 #include "talk/app/webrtc/videotrack.h"
47 #include "talk/media/base/fakevideocapturer.h" 46 #include "talk/media/base/fakevideocapturer.h"
48 #include "talk/media/sctp/sctpdataengine.h" 47 #include "talk/media/sctp/sctpdataengine.h"
49 #include "talk/session/media/mediasession.h" 48 #include "talk/session/media/mediasession.h"
50 #include "webrtc/base/gunit.h" 49 #include "webrtc/base/gunit.h"
51 #include "webrtc/base/scoped_ptr.h" 50 #include "webrtc/base/scoped_ptr.h"
52 #include "webrtc/base/ssladapter.h" 51 #include "webrtc/base/ssladapter.h"
53 #include "webrtc/base/sslstreamadapter.h" 52 #include "webrtc/base/sslstreamadapter.h"
54 #include "webrtc/base/stringutils.h" 53 #include "webrtc/base/stringutils.h"
55 #include "webrtc/base/thread.h" 54 #include "webrtc/base/thread.h"
55 #include "webrtc/p2p/client/fakeportallocator.h"
56 56
57 static const char kStreamLabel1[] = "local_stream_1"; 57 static const char kStreamLabel1[] = "local_stream_1";
58 static const char kStreamLabel2[] = "local_stream_2"; 58 static const char kStreamLabel2[] = "local_stream_2";
59 static const char kStreamLabel3[] = "local_stream_3"; 59 static const char kStreamLabel3[] = "local_stream_3";
60 static const int kDefaultStunPort = 3478; 60 static const int kDefaultStunPort = 3478;
61 static const char kStunAddressOnly[] = "stun:address"; 61 static const char kStunAddressOnly[] = "stun:address";
62 static const char kStunInvalidPort[] = "stun:address:-1"; 62 static const char kStunInvalidPort[] = "stun:address:-1";
63 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; 63 static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
64 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; 64 static const char kStunAddressPortAndMore2[] = "stun:address:port more";
65 static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; 65 static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 252 }
253 253
254 using rtc::scoped_ptr; 254 using rtc::scoped_ptr;
255 using rtc::scoped_refptr; 255 using rtc::scoped_refptr;
256 using webrtc::AudioSourceInterface; 256 using webrtc::AudioSourceInterface;
257 using webrtc::AudioTrack; 257 using webrtc::AudioTrack;
258 using webrtc::AudioTrackInterface; 258 using webrtc::AudioTrackInterface;
259 using webrtc::DataBuffer; 259 using webrtc::DataBuffer;
260 using webrtc::DataChannelInterface; 260 using webrtc::DataChannelInterface;
261 using webrtc::FakeConstraints; 261 using webrtc::FakeConstraints;
262 using webrtc::FakePortAllocatorFactory;
263 using webrtc::IceCandidateInterface; 262 using webrtc::IceCandidateInterface;
264 using webrtc::MediaConstraintsInterface; 263 using webrtc::MediaConstraintsInterface;
265 using webrtc::MediaStream; 264 using webrtc::MediaStream;
266 using webrtc::MediaStreamInterface; 265 using webrtc::MediaStreamInterface;
267 using webrtc::MediaStreamTrackInterface; 266 using webrtc::MediaStreamTrackInterface;
268 using webrtc::MockCreateSessionDescriptionObserver; 267 using webrtc::MockCreateSessionDescriptionObserver;
269 using webrtc::MockDataChannelObserver; 268 using webrtc::MockDataChannelObserver;
270 using webrtc::MockSetSessionDescriptionObserver; 269 using webrtc::MockSetSessionDescriptionObserver;
271 using webrtc::MockStatsObserver; 270 using webrtc::MockStatsObserver;
272 using webrtc::PeerConnectionInterface; 271 using webrtc::PeerConnectionInterface;
273 using webrtc::PeerConnectionObserver; 272 using webrtc::PeerConnectionObserver;
274 using webrtc::PortAllocatorFactoryInterface;
275 using webrtc::RtpReceiverInterface; 273 using webrtc::RtpReceiverInterface;
276 using webrtc::RtpSenderInterface; 274 using webrtc::RtpSenderInterface;
277 using webrtc::SdpParseError; 275 using webrtc::SdpParseError;
278 using webrtc::SessionDescriptionInterface; 276 using webrtc::SessionDescriptionInterface;
279 using webrtc::StreamCollection; 277 using webrtc::StreamCollection;
280 using webrtc::StreamCollectionInterface; 278 using webrtc::StreamCollectionInterface;
281 using webrtc::VideoSourceInterface; 279 using webrtc::VideoSourceInterface;
282 using webrtc::VideoTrack; 280 using webrtc::VideoTrack;
283 using webrtc::VideoTrackInterface; 281 using webrtc::VideoTrackInterface;
284 282
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 CreatePeerConnection("", "", NULL); 525 CreatePeerConnection("", "", NULL);
528 } 526 }
529 527
530 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { 528 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
531 CreatePeerConnection("", "", constraints); 529 CreatePeerConnection("", "", constraints);
532 } 530 }
533 531
534 void CreatePeerConnection(const std::string& uri, 532 void CreatePeerConnection(const std::string& uri,
535 const std::string& password, 533 const std::string& password,
536 webrtc::MediaConstraintsInterface* constraints) { 534 webrtc::MediaConstraintsInterface* constraints) {
535 PeerConnectionInterface::RTCConfiguration config;
537 PeerConnectionInterface::IceServer server; 536 PeerConnectionInterface::IceServer server;
538 PeerConnectionInterface::IceServers servers;
539 if (!uri.empty()) { 537 if (!uri.empty()) {
540 server.uri = uri; 538 server.uri = uri;
541 server.password = password; 539 server.password = password;
542 servers.push_back(server); 540 config.servers.push_back(server);
543 } 541 }
544 542
545 port_allocator_factory_ = FakePortAllocatorFactory::Create(); 543 rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator(
544 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
545 port_allocator_ = port_allocator.get();
546 546
547 // DTLS does not work in a loopback call, so is disabled for most of the 547 // DTLS does not work in a loopback call, so is disabled for most of the
548 // tests in this file. We only create a FakeIdentityService if the test 548 // tests in this file. We only create a FakeIdentityService if the test
549 // explicitly sets the constraint. 549 // explicitly sets the constraint.
550 FakeConstraints default_constraints; 550 FakeConstraints default_constraints;
551 if (!constraints) { 551 if (!constraints) {
552 constraints = &default_constraints; 552 constraints = &default_constraints;
553 553
554 default_constraints.AddMandatory( 554 default_constraints.AddMandatory(
555 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); 555 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
556 } 556 }
557 557
558 scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store; 558 scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store;
559 bool dtls; 559 bool dtls;
560 if (FindConstraint(constraints, 560 if (FindConstraint(constraints,
561 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, 561 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
562 &dtls, 562 &dtls,
563 nullptr) && dtls) { 563 nullptr) && dtls) {
564 dtls_identity_store.reset(new FakeDtlsIdentityStore()); 564 dtls_identity_store.reset(new FakeDtlsIdentityStore());
565 } 565 }
566 pc_ = pc_factory_->CreatePeerConnection( 566 pc_ = pc_factory_->CreatePeerConnection(
567 servers, constraints, port_allocator_factory_.get(), 567 config, constraints, std::move(port_allocator),
568 std::move(dtls_identity_store), &observer_); 568 std::move(dtls_identity_store), &observer_);
569 ASSERT_TRUE(pc_.get() != NULL); 569 ASSERT_TRUE(pc_.get() != NULL);
570 observer_.SetPeerConnectionInterface(pc_.get()); 570 observer_.SetPeerConnectionInterface(pc_.get());
571 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); 571 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
572 } 572 }
573 573
574 void CreatePeerConnectionExpectFail(const std::string& uri) { 574 void CreatePeerConnectionExpectFail(const std::string& uri) {
575 PeerConnectionInterface::RTCConfiguration config;
575 PeerConnectionInterface::IceServer server; 576 PeerConnectionInterface::IceServer server;
576 PeerConnectionInterface::IceServers servers;
577 server.uri = uri; 577 server.uri = uri;
578 servers.push_back(server); 578 config.servers.push_back(server);
579 579
580 scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store;
581 port_allocator_factory_ = FakePortAllocatorFactory::Create();
582 scoped_refptr<PeerConnectionInterface> pc; 580 scoped_refptr<PeerConnectionInterface> pc;
583 pc = pc_factory_->CreatePeerConnection( 581 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
584 servers, nullptr, port_allocator_factory_.get(), 582 &observer_);
585 std::move(dtls_identity_store), &observer_); 583 EXPECT_EQ(nullptr, pc);
586 ASSERT_EQ(nullptr, pc);
587 } 584 }
588 585
589 void CreatePeerConnectionWithDifferentConfigurations() { 586 void CreatePeerConnectionWithDifferentConfigurations() {
590 CreatePeerConnection(kStunAddressOnly, "", NULL); 587 CreatePeerConnection(kStunAddressOnly, "", NULL);
591 EXPECT_EQ(1u, port_allocator_factory_->stun_configs().size()); 588 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
592 EXPECT_EQ(0u, port_allocator_factory_->turn_configs().size()); 589 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
593 EXPECT_EQ("address", 590 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
594 port_allocator_factory_->stun_configs()[0].server.hostname());
595 EXPECT_EQ(kDefaultStunPort, 591 EXPECT_EQ(kDefaultStunPort,
596 port_allocator_factory_->stun_configs()[0].server.port()); 592 port_allocator_->stun_servers().begin()->port());
597 593
598 CreatePeerConnectionExpectFail(kStunInvalidPort); 594 CreatePeerConnectionExpectFail(kStunInvalidPort);
599 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); 595 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
600 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); 596 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
601 597
602 CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL); 598 CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL);
603 EXPECT_EQ(0u, port_allocator_factory_->stun_configs().size()); 599 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
604 EXPECT_EQ(1u, port_allocator_factory_->turn_configs().size()); 600 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
605 EXPECT_EQ(kTurnUsername, 601 EXPECT_EQ(kTurnUsername,
606 port_allocator_factory_->turn_configs()[0].username); 602 port_allocator_->turn_servers()[0].credentials.username);
607 EXPECT_EQ(kTurnPassword, 603 EXPECT_EQ(kTurnPassword,
608 port_allocator_factory_->turn_configs()[0].password); 604 port_allocator_->turn_servers()[0].credentials.password);
609 EXPECT_EQ(kTurnHostname, 605 EXPECT_EQ(kTurnHostname,
610 port_allocator_factory_->turn_configs()[0].server.hostname()); 606 port_allocator_->turn_servers()[0].ports[0].address.hostname());
611 } 607 }
612 608
613 void ReleasePeerConnection() { 609 void ReleasePeerConnection() {
614 pc_ = NULL; 610 pc_ = NULL;
615 observer_.SetPeerConnectionInterface(NULL); 611 observer_.SetPeerConnectionInterface(NULL);
616 } 612 }
617 613
618 void AddVideoStream(const std::string& label) { 614 void AddVideoStream(const std::string& label) {
619 // Create a local stream. 615 // Create a local stream.
620 scoped_refptr<MediaStreamInterface> stream( 616 scoped_refptr<MediaStreamInterface> stream(
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 ASSERT_TRUE(stream->AddTrack(audio_track)); 915 ASSERT_TRUE(stream->AddTrack(audio_track));
920 } 916 }
921 917
922 void AddVideoTrack(const std::string& track_id, 918 void AddVideoTrack(const std::string& track_id,
923 MediaStreamInterface* stream) { 919 MediaStreamInterface* stream) {
924 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( 920 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
925 webrtc::VideoTrack::Create(track_id, nullptr)); 921 webrtc::VideoTrack::Create(track_id, nullptr));
926 ASSERT_TRUE(stream->AddTrack(video_track)); 922 ASSERT_TRUE(stream->AddTrack(video_track));
927 } 923 }
928 924
929 scoped_refptr<FakePortAllocatorFactory> port_allocator_factory_; 925 cricket::FakePortAllocator* port_allocator_ = nullptr;
930 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; 926 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
931 scoped_refptr<PeerConnectionInterface> pc_; 927 scoped_refptr<PeerConnectionInterface> pc_;
932 MockPeerConnectionObserver observer_; 928 MockPeerConnectionObserver observer_;
933 rtc::scoped_refptr<StreamCollection> reference_collection_; 929 rtc::scoped_refptr<StreamCollection> reference_collection_;
934 }; 930 };
935 931
936 TEST_F(PeerConnectionInterfaceTest, 932 TEST_F(PeerConnectionInterfaceTest,
937 CreatePeerConnectionWithDifferentConfigurations) { 933 CreatePeerConnectionWithDifferentConfigurations) {
938 CreatePeerConnectionWithDifferentConfigurations(); 934 CreatePeerConnectionWithDifferentConfigurations();
939 } 935 }
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 // PortAllocator. 1702 // PortAllocator.
1707 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { 1703 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
1708 CreatePeerConnection(); 1704 CreatePeerConnection();
1709 1705
1710 PeerConnectionInterface::RTCConfiguration config; 1706 PeerConnectionInterface::RTCConfiguration config;
1711 PeerConnectionInterface::IceServer server; 1707 PeerConnectionInterface::IceServer server;
1712 server.uri = "stun:test_hostname"; 1708 server.uri = "stun:test_hostname";
1713 config.servers.push_back(server); 1709 config.servers.push_back(server);
1714 EXPECT_TRUE(pc_->SetConfiguration(config)); 1710 EXPECT_TRUE(pc_->SetConfiguration(config));
1715 1711
1716 cricket::FakePortAllocator* allocator = 1712 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
1717 port_allocator_factory_->last_created_allocator(); 1713 EXPECT_EQ("test_hostname",
1718 EXPECT_EQ(1u, allocator->stun_servers().size()); 1714 port_allocator_->stun_servers().begin()->hostname());
1719 EXPECT_EQ("test_hostname", allocator->stun_servers().begin()->hostname());
1720 } 1715 }
1721 1716
1722 // Test that PeerConnection::Close changes the states to closed and all remote 1717 // Test that PeerConnection::Close changes the states to closed and all remote
1723 // tracks change state to ended. 1718 // tracks change state to ended.
1724 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { 1719 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
1725 // Initialize a PeerConnection and negotiate local and remote session 1720 // Initialize a PeerConnection and negotiate local and remote session
1726 // description. 1721 // description.
1727 InitiateCall(); 1722 InitiateCall();
1728 ASSERT_EQ(1u, pc_->local_streams()->count()); 1723 ASSERT_EQ(1u, pc_->local_streams()->count());
1729 ASSERT_EQ(1u, pc_->remote_streams()->count()); 1724 ASSERT_EQ(1u, pc_->remote_streams()->count());
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 FakeConstraints updated_answer_c; 2386 FakeConstraints updated_answer_c;
2392 answer_c.SetMandatoryReceiveAudio(false); 2387 answer_c.SetMandatoryReceiveAudio(false);
2393 answer_c.SetMandatoryReceiveVideo(false); 2388 answer_c.SetMandatoryReceiveVideo(false);
2394 2389
2395 cricket::MediaSessionOptions updated_answer_options; 2390 cricket::MediaSessionOptions updated_answer_options;
2396 EXPECT_TRUE( 2391 EXPECT_TRUE(
2397 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); 2392 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
2398 EXPECT_TRUE(updated_answer_options.has_audio()); 2393 EXPECT_TRUE(updated_answer_options.has_audio());
2399 EXPECT_TRUE(updated_answer_options.has_video()); 2394 EXPECT_TRUE(updated_answer_options.has_video());
2400 } 2395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698