OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 #include "webrtc/api/test/testsdpstrings.h" | 32 #include "webrtc/api/test/testsdpstrings.h" |
33 #include "webrtc/api/videocapturertracksource.h" | 33 #include "webrtc/api/videocapturertracksource.h" |
34 #include "webrtc/api/videotrack.h" | 34 #include "webrtc/api/videotrack.h" |
35 #include "webrtc/base/gunit.h" | 35 #include "webrtc/base/gunit.h" |
36 #include "webrtc/base/ssladapter.h" | 36 #include "webrtc/base/ssladapter.h" |
37 #include "webrtc/base/sslstreamadapter.h" | 37 #include "webrtc/base/sslstreamadapter.h" |
38 #include "webrtc/base/stringutils.h" | 38 #include "webrtc/base/stringutils.h" |
39 #include "webrtc/base/thread.h" | 39 #include "webrtc/base/thread.h" |
40 #include "webrtc/media/base/fakevideocapturer.h" | 40 #include "webrtc/media/base/fakevideocapturer.h" |
41 #include "webrtc/media/sctp/sctpdataengine.h" | 41 #include "webrtc/media/sctp/sctpdataengine.h" |
42 #include "webrtc/p2p/client/fakeportallocator.h" | 42 #include "webrtc/p2p/base/fakeportallocator.h" |
43 #include "webrtc/pc/mediasession.h" | 43 #include "webrtc/pc/mediasession.h" |
44 | 44 |
45 static const char kStreamLabel1[] = "local_stream_1"; | 45 static const char kStreamLabel1[] = "local_stream_1"; |
46 static const char kStreamLabel2[] = "local_stream_2"; | 46 static const char kStreamLabel2[] = "local_stream_2"; |
47 static const char kStreamLabel3[] = "local_stream_3"; | 47 static const char kStreamLabel3[] = "local_stream_3"; |
48 static const int kDefaultStunPort = 3478; | 48 static const int kDefaultStunPort = 3478; |
49 static const char kStunAddressOnly[] = "stun:address"; | 49 static const char kStunAddressOnly[] = "stun:address"; |
50 static const char kStunInvalidPort[] = "stun:address:-1"; | 50 static const char kStunInvalidPort[] = "stun:address:-1"; |
51 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; | 51 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; |
52 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; | 52 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 525 } |
526 | 526 |
527 virtual void SetUp() { | 527 virtual void SetUp() { |
528 pc_factory_ = webrtc::CreatePeerConnectionFactory( | 528 pc_factory_ = webrtc::CreatePeerConnectionFactory( |
529 rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL, | 529 rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL, |
530 NULL); | 530 NULL); |
531 ASSERT_TRUE(pc_factory_.get() != NULL); | 531 ASSERT_TRUE(pc_factory_.get() != NULL); |
532 } | 532 } |
533 | 533 |
534 void CreatePeerConnection() { | 534 void CreatePeerConnection() { |
535 CreatePeerConnection("", "", NULL); | 535 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); |
536 } | 536 } |
537 | 537 |
538 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { | 538 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { |
539 CreatePeerConnection("", "", constraints); | 539 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), |
| 540 constraints); |
540 } | 541 } |
541 | 542 |
542 void CreatePeerConnection(const std::string& uri, | 543 void CreatePeerConnectionWithIceTransportsType( |
543 const std::string& password, | 544 PeerConnectionInterface::IceTransportsType type) { |
544 webrtc::MediaConstraintsInterface* constraints) { | 545 PeerConnectionInterface::RTCConfiguration config; |
| 546 config.type = type; |
| 547 return CreatePeerConnection(config, nullptr); |
| 548 } |
| 549 |
| 550 void CreatePeerConnectionWithIceServer(const std::string& uri, |
| 551 const std::string& password) { |
545 PeerConnectionInterface::RTCConfiguration config; | 552 PeerConnectionInterface::RTCConfiguration config; |
546 PeerConnectionInterface::IceServer server; | 553 PeerConnectionInterface::IceServer server; |
547 if (!uri.empty()) { | 554 server.uri = uri; |
548 server.uri = uri; | 555 server.password = password; |
549 server.password = password; | 556 config.servers.push_back(server); |
550 config.servers.push_back(server); | 557 CreatePeerConnection(config, nullptr); |
551 } | 558 } |
552 | 559 |
| 560 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config, |
| 561 webrtc::MediaConstraintsInterface* constraints) { |
553 std::unique_ptr<cricket::FakePortAllocator> port_allocator( | 562 std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
554 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | 563 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
555 port_allocator_ = port_allocator.get(); | 564 port_allocator_ = port_allocator.get(); |
556 | 565 |
557 // DTLS does not work in a loopback call, so is disabled for most of the | 566 // DTLS does not work in a loopback call, so is disabled for most of the |
558 // tests in this file. We only create a FakeIdentityService if the test | 567 // tests in this file. We only create a FakeIdentityService if the test |
559 // explicitly sets the constraint. | 568 // explicitly sets the constraint. |
560 FakeConstraints default_constraints; | 569 FakeConstraints default_constraints; |
561 if (!constraints) { | 570 if (!constraints) { |
562 constraints = &default_constraints; | 571 constraints = &default_constraints; |
(...skipping 24 matching lines...) Expand all Loading... |
587 server.uri = uri; | 596 server.uri = uri; |
588 config.servers.push_back(server); | 597 config.servers.push_back(server); |
589 | 598 |
590 scoped_refptr<PeerConnectionInterface> pc; | 599 scoped_refptr<PeerConnectionInterface> pc; |
591 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, | 600 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, |
592 &observer_); | 601 &observer_); |
593 EXPECT_EQ(nullptr, pc); | 602 EXPECT_EQ(nullptr, pc); |
594 } | 603 } |
595 | 604 |
596 void CreatePeerConnectionWithDifferentConfigurations() { | 605 void CreatePeerConnectionWithDifferentConfigurations() { |
597 CreatePeerConnection(kStunAddressOnly, "", NULL); | 606 CreatePeerConnectionWithIceServer(kStunAddressOnly, ""); |
598 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | 607 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
599 EXPECT_EQ(0u, port_allocator_->turn_servers().size()); | 608 EXPECT_EQ(0u, port_allocator_->turn_servers().size()); |
600 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); | 609 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); |
601 EXPECT_EQ(kDefaultStunPort, | 610 EXPECT_EQ(kDefaultStunPort, |
602 port_allocator_->stun_servers().begin()->port()); | 611 port_allocator_->stun_servers().begin()->port()); |
603 | 612 |
604 CreatePeerConnectionExpectFail(kStunInvalidPort); | 613 CreatePeerConnectionExpectFail(kStunInvalidPort); |
605 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); | 614 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); |
606 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); | 615 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); |
607 | 616 |
608 CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL); | 617 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword); |
609 EXPECT_EQ(0u, port_allocator_->stun_servers().size()); | 618 EXPECT_EQ(0u, port_allocator_->stun_servers().size()); |
610 EXPECT_EQ(1u, port_allocator_->turn_servers().size()); | 619 EXPECT_EQ(1u, port_allocator_->turn_servers().size()); |
611 EXPECT_EQ(kTurnUsername, | 620 EXPECT_EQ(kTurnUsername, |
612 port_allocator_->turn_servers()[0].credentials.username); | 621 port_allocator_->turn_servers()[0].credentials.username); |
613 EXPECT_EQ(kTurnPassword, | 622 EXPECT_EQ(kTurnPassword, |
614 port_allocator_->turn_servers()[0].credentials.password); | 623 port_allocator_->turn_servers()[0].credentials.password); |
615 EXPECT_EQ(kTurnHostname, | 624 EXPECT_EQ(kTurnHostname, |
616 port_allocator_->turn_servers()[0].ports[0].address.hostname()); | 625 port_allocator_->turn_servers()[0].ports[0].address.hostname()); |
617 } | 626 } |
618 | 627 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 CreateAnswerWithOneAudioStream(); | 997 CreateAnswerWithOneAudioStream(); |
989 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), | 998 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), |
990 GetFirstAudioStreamCname(answer2.get())); | 999 GetFirstAudioStreamCname(answer2.get())); |
991 } | 1000 } |
992 | 1001 |
993 TEST_F(PeerConnectionInterfaceTest, | 1002 TEST_F(PeerConnectionInterfaceTest, |
994 CreatePeerConnectionWithDifferentConfigurations) { | 1003 CreatePeerConnectionWithDifferentConfigurations) { |
995 CreatePeerConnectionWithDifferentConfigurations(); | 1004 CreatePeerConnectionWithDifferentConfigurations(); |
996 } | 1005 } |
997 | 1006 |
| 1007 TEST_F(PeerConnectionInterfaceTest, |
| 1008 CreatePeerConnectionWithDifferentIceTransportsTypes) { |
| 1009 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone); |
| 1010 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter()); |
| 1011 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay); |
| 1012 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
| 1013 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost); |
| 1014 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST, |
| 1015 port_allocator_->candidate_filter()); |
| 1016 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll); |
| 1017 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter()); |
| 1018 } |
| 1019 |
| 1020 // Test that when a PeerConnection is created with a nonzero candidate pool |
| 1021 // size, the pooled PortAllocatorSession is created with all the attributes |
| 1022 // in the RTCConfiguration. |
| 1023 TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { |
| 1024 PeerConnectionInterface::RTCConfiguration config; |
| 1025 PeerConnectionInterface::IceServer server; |
| 1026 server.uri = kStunAddressOnly; |
| 1027 config.servers.push_back(server); |
| 1028 config.type = PeerConnectionInterface::kRelay; |
| 1029 config.disable_ipv6 = true; |
| 1030 config.tcp_candidate_policy = |
| 1031 PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
| 1032 config.ice_candidate_pool_size = 1; |
| 1033 CreatePeerConnection(config, nullptr); |
| 1034 |
| 1035 const cricket::FakePortAllocatorSession* session = |
| 1036 static_cast<const cricket::FakePortAllocatorSession*>( |
| 1037 port_allocator_->GetPooledSession()); |
| 1038 ASSERT_NE(nullptr, session); |
| 1039 EXPECT_EQ(1UL, session->stun_servers().size()); |
| 1040 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 1041 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1042 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
| 1043 } |
| 1044 |
998 TEST_F(PeerConnectionInterfaceTest, AddStreams) { | 1045 TEST_F(PeerConnectionInterfaceTest, AddStreams) { |
999 CreatePeerConnection(); | 1046 CreatePeerConnection(); |
1000 AddVideoStream(kStreamLabel1); | 1047 AddVideoStream(kStreamLabel1); |
1001 AddVoiceStream(kStreamLabel2); | 1048 AddVoiceStream(kStreamLabel2); |
1002 ASSERT_EQ(2u, pc_->local_streams()->count()); | 1049 ASSERT_EQ(2u, pc_->local_streams()->count()); |
1003 | 1050 |
1004 // Test we can add multiple local streams to one peerconnection. | 1051 // Test we can add multiple local streams to one peerconnection. |
1005 scoped_refptr<MediaStreamInterface> stream( | 1052 scoped_refptr<MediaStreamInterface> stream( |
1006 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); | 1053 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); |
1007 scoped_refptr<AudioTrackInterface> audio_track( | 1054 scoped_refptr<AudioTrackInterface> audio_track( |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 PeerConnectionInterface::IceServer server; | 1928 PeerConnectionInterface::IceServer server; |
1882 server.uri = "stun:test_hostname"; | 1929 server.uri = "stun:test_hostname"; |
1883 config.servers.push_back(server); | 1930 config.servers.push_back(server); |
1884 EXPECT_TRUE(pc_->SetConfiguration(config)); | 1931 EXPECT_TRUE(pc_->SetConfiguration(config)); |
1885 | 1932 |
1886 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | 1933 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
1887 EXPECT_EQ("test_hostname", | 1934 EXPECT_EQ("test_hostname", |
1888 port_allocator_->stun_servers().begin()->hostname()); | 1935 port_allocator_->stun_servers().begin()->hostname()); |
1889 } | 1936 } |
1890 | 1937 |
| 1938 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) { |
| 1939 CreatePeerConnection(); |
| 1940 PeerConnectionInterface::RTCConfiguration config; |
| 1941 config.type = PeerConnectionInterface::kRelay; |
| 1942 EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 1943 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
| 1944 } |
| 1945 |
| 1946 // Test that when SetConfiguration changes both the pool size and other |
| 1947 // attributes, the pooled session is created with the updated attributes. |
| 1948 TEST_F(PeerConnectionInterfaceTest, |
| 1949 SetConfigurationCreatesPooledSessionCorrectly) { |
| 1950 CreatePeerConnection(); |
| 1951 PeerConnectionInterface::RTCConfiguration config; |
| 1952 config.ice_candidate_pool_size = 1; |
| 1953 PeerConnectionInterface::IceServer server; |
| 1954 server.uri = kStunAddressOnly; |
| 1955 config.servers.push_back(server); |
| 1956 config.type = PeerConnectionInterface::kRelay; |
| 1957 CreatePeerConnection(config, nullptr); |
| 1958 |
| 1959 const cricket::FakePortAllocatorSession* session = |
| 1960 static_cast<const cricket::FakePortAllocatorSession*>( |
| 1961 port_allocator_->GetPooledSession()); |
| 1962 ASSERT_NE(nullptr, session); |
| 1963 EXPECT_EQ(1UL, session->stun_servers().size()); |
| 1964 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
| 1965 } |
| 1966 |
1891 // Test that PeerConnection::Close changes the states to closed and all remote | 1967 // Test that PeerConnection::Close changes the states to closed and all remote |
1892 // tracks change state to ended. | 1968 // tracks change state to ended. |
1893 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { | 1969 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |
1894 // Initialize a PeerConnection and negotiate local and remote session | 1970 // Initialize a PeerConnection and negotiate local and remote session |
1895 // description. | 1971 // description. |
1896 InitiateCall(); | 1972 InitiateCall(); |
1897 ASSERT_EQ(1u, pc_->local_streams()->count()); | 1973 ASSERT_EQ(1u, pc_->local_streams()->count()); |
1898 ASSERT_EQ(1u, pc_->remote_streams()->count()); | 1974 ASSERT_EQ(1u, pc_->remote_streams()->count()); |
1899 | 1975 |
1900 pc_->Close(); | 1976 pc_->Close(); |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2710 FakeConstraints updated_answer_c; | 2786 FakeConstraints updated_answer_c; |
2711 answer_c.SetMandatoryReceiveAudio(false); | 2787 answer_c.SetMandatoryReceiveAudio(false); |
2712 answer_c.SetMandatoryReceiveVideo(false); | 2788 answer_c.SetMandatoryReceiveVideo(false); |
2713 | 2789 |
2714 cricket::MediaSessionOptions updated_answer_options; | 2790 cricket::MediaSessionOptions updated_answer_options; |
2715 EXPECT_TRUE( | 2791 EXPECT_TRUE( |
2716 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2792 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
2717 EXPECT_TRUE(updated_answer_options.has_audio()); | 2793 EXPECT_TRUE(updated_answer_options.has_audio()); |
2718 EXPECT_TRUE(updated_answer_options.has_video()); | 2794 EXPECT_TRUE(updated_answer_options.has_video()); |
2719 } | 2795 } |
OLD | NEW |