| 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/base/fakeportallocator.h" | 42 #include "webrtc/p2p/client/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(PeerConnectionInterface::RTCConfiguration(), nullptr); | 535 CreatePeerConnection("", "", NULL); |
| 536 } | 536 } |
| 537 | 537 |
| 538 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { | 538 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { |
| 539 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), | 539 CreatePeerConnection("", "", constraints); |
| 540 constraints); | |
| 541 } | 540 } |
| 542 | 541 |
| 543 void CreatePeerConnectionWithIceTransportsType( | 542 void CreatePeerConnection(const std::string& uri, |
| 544 PeerConnectionInterface::IceTransportsType type) { | 543 const std::string& password, |
| 545 PeerConnectionInterface::RTCConfiguration config; | 544 webrtc::MediaConstraintsInterface* constraints) { |
| 546 config.type = type; | |
| 547 return CreatePeerConnection(config, nullptr); | |
| 548 } | |
| 549 | |
| 550 void CreatePeerConnectionWithIceServer(const std::string& uri, | |
| 551 const std::string& password) { | |
| 552 PeerConnectionInterface::RTCConfiguration config; | 545 PeerConnectionInterface::RTCConfiguration config; |
| 553 PeerConnectionInterface::IceServer server; | 546 PeerConnectionInterface::IceServer server; |
| 554 server.uri = uri; | 547 if (!uri.empty()) { |
| 555 server.password = password; | 548 server.uri = uri; |
| 556 config.servers.push_back(server); | 549 server.password = password; |
| 557 CreatePeerConnection(config, nullptr); | 550 config.servers.push_back(server); |
| 558 } | 551 } |
| 559 | 552 |
| 560 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config, | |
| 561 webrtc::MediaConstraintsInterface* constraints) { | |
| 562 std::unique_ptr<cricket::FakePortAllocator> port_allocator( | 553 std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
| 563 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | 554 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 564 port_allocator_ = port_allocator.get(); | 555 port_allocator_ = port_allocator.get(); |
| 565 | 556 |
| 566 // DTLS does not work in a loopback call, so is disabled for most of the | 557 // DTLS does not work in a loopback call, so is disabled for most of the |
| 567 // tests in this file. We only create a FakeIdentityService if the test | 558 // tests in this file. We only create a FakeIdentityService if the test |
| 568 // explicitly sets the constraint. | 559 // explicitly sets the constraint. |
| 569 FakeConstraints default_constraints; | 560 FakeConstraints default_constraints; |
| 570 if (!constraints) { | 561 if (!constraints) { |
| 571 constraints = &default_constraints; | 562 constraints = &default_constraints; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 596 server.uri = uri; | 587 server.uri = uri; |
| 597 config.servers.push_back(server); | 588 config.servers.push_back(server); |
| 598 | 589 |
| 599 scoped_refptr<PeerConnectionInterface> pc; | 590 scoped_refptr<PeerConnectionInterface> pc; |
| 600 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, | 591 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, |
| 601 &observer_); | 592 &observer_); |
| 602 EXPECT_EQ(nullptr, pc); | 593 EXPECT_EQ(nullptr, pc); |
| 603 } | 594 } |
| 604 | 595 |
| 605 void CreatePeerConnectionWithDifferentConfigurations() { | 596 void CreatePeerConnectionWithDifferentConfigurations() { |
| 606 CreatePeerConnectionWithIceServer(kStunAddressOnly, ""); | 597 CreatePeerConnection(kStunAddressOnly, "", NULL); |
| 607 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | 598 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 608 EXPECT_EQ(0u, port_allocator_->turn_servers().size()); | 599 EXPECT_EQ(0u, port_allocator_->turn_servers().size()); |
| 609 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); | 600 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); |
| 610 EXPECT_EQ(kDefaultStunPort, | 601 EXPECT_EQ(kDefaultStunPort, |
| 611 port_allocator_->stun_servers().begin()->port()); | 602 port_allocator_->stun_servers().begin()->port()); |
| 612 | 603 |
| 613 CreatePeerConnectionExpectFail(kStunInvalidPort); | 604 CreatePeerConnectionExpectFail(kStunInvalidPort); |
| 614 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); | 605 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); |
| 615 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); | 606 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); |
| 616 | 607 |
| 617 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword); | 608 CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL); |
| 618 EXPECT_EQ(0u, port_allocator_->stun_servers().size()); | 609 EXPECT_EQ(0u, port_allocator_->stun_servers().size()); |
| 619 EXPECT_EQ(1u, port_allocator_->turn_servers().size()); | 610 EXPECT_EQ(1u, port_allocator_->turn_servers().size()); |
| 620 EXPECT_EQ(kTurnUsername, | 611 EXPECT_EQ(kTurnUsername, |
| 621 port_allocator_->turn_servers()[0].credentials.username); | 612 port_allocator_->turn_servers()[0].credentials.username); |
| 622 EXPECT_EQ(kTurnPassword, | 613 EXPECT_EQ(kTurnPassword, |
| 623 port_allocator_->turn_servers()[0].credentials.password); | 614 port_allocator_->turn_servers()[0].credentials.password); |
| 624 EXPECT_EQ(kTurnHostname, | 615 EXPECT_EQ(kTurnHostname, |
| 625 port_allocator_->turn_servers()[0].ports[0].address.hostname()); | 616 port_allocator_->turn_servers()[0].ports[0].address.hostname()); |
| 626 } | 617 } |
| 627 | 618 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 CreateAnswerWithOneAudioStream(); | 988 CreateAnswerWithOneAudioStream(); |
| 998 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), | 989 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), |
| 999 GetFirstAudioStreamCname(answer2.get())); | 990 GetFirstAudioStreamCname(answer2.get())); |
| 1000 } | 991 } |
| 1001 | 992 |
| 1002 TEST_F(PeerConnectionInterfaceTest, | 993 TEST_F(PeerConnectionInterfaceTest, |
| 1003 CreatePeerConnectionWithDifferentConfigurations) { | 994 CreatePeerConnectionWithDifferentConfigurations) { |
| 1004 CreatePeerConnectionWithDifferentConfigurations(); | 995 CreatePeerConnectionWithDifferentConfigurations(); |
| 1005 } | 996 } |
| 1006 | 997 |
| 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 | |
| 1045 TEST_F(PeerConnectionInterfaceTest, AddStreams) { | 998 TEST_F(PeerConnectionInterfaceTest, AddStreams) { |
| 1046 CreatePeerConnection(); | 999 CreatePeerConnection(); |
| 1047 AddVideoStream(kStreamLabel1); | 1000 AddVideoStream(kStreamLabel1); |
| 1048 AddVoiceStream(kStreamLabel2); | 1001 AddVoiceStream(kStreamLabel2); |
| 1049 ASSERT_EQ(2u, pc_->local_streams()->count()); | 1002 ASSERT_EQ(2u, pc_->local_streams()->count()); |
| 1050 | 1003 |
| 1051 // Test we can add multiple local streams to one peerconnection. | 1004 // Test we can add multiple local streams to one peerconnection. |
| 1052 scoped_refptr<MediaStreamInterface> stream( | 1005 scoped_refptr<MediaStreamInterface> stream( |
| 1053 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); | 1006 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); |
| 1054 scoped_refptr<AudioTrackInterface> audio_track( | 1007 scoped_refptr<AudioTrackInterface> audio_track( |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 PeerConnectionInterface::IceServer server; | 1881 PeerConnectionInterface::IceServer server; |
| 1929 server.uri = "stun:test_hostname"; | 1882 server.uri = "stun:test_hostname"; |
| 1930 config.servers.push_back(server); | 1883 config.servers.push_back(server); |
| 1931 EXPECT_TRUE(pc_->SetConfiguration(config)); | 1884 EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 1932 | 1885 |
| 1933 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | 1886 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 1934 EXPECT_EQ("test_hostname", | 1887 EXPECT_EQ("test_hostname", |
| 1935 port_allocator_->stun_servers().begin()->hostname()); | 1888 port_allocator_->stun_servers().begin()->hostname()); |
| 1936 } | 1889 } |
| 1937 | 1890 |
| 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 | |
| 1967 // Test that PeerConnection::Close changes the states to closed and all remote | 1891 // Test that PeerConnection::Close changes the states to closed and all remote |
| 1968 // tracks change state to ended. | 1892 // tracks change state to ended. |
| 1969 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { | 1893 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |
| 1970 // Initialize a PeerConnection and negotiate local and remote session | 1894 // Initialize a PeerConnection and negotiate local and remote session |
| 1971 // description. | 1895 // description. |
| 1972 InitiateCall(); | 1896 InitiateCall(); |
| 1973 ASSERT_EQ(1u, pc_->local_streams()->count()); | 1897 ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 1974 ASSERT_EQ(1u, pc_->remote_streams()->count()); | 1898 ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1975 | 1899 |
| 1976 pc_->Close(); | 1900 pc_->Close(); |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2786 FakeConstraints updated_answer_c; | 2710 FakeConstraints updated_answer_c; |
| 2787 answer_c.SetMandatoryReceiveAudio(false); | 2711 answer_c.SetMandatoryReceiveAudio(false); |
| 2788 answer_c.SetMandatoryReceiveVideo(false); | 2712 answer_c.SetMandatoryReceiveVideo(false); |
| 2789 | 2713 |
| 2790 cricket::MediaSessionOptions updated_answer_options; | 2714 cricket::MediaSessionOptions updated_answer_options; |
| 2791 EXPECT_TRUE( | 2715 EXPECT_TRUE( |
| 2792 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2716 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
| 2793 EXPECT_TRUE(updated_answer_options.has_audio()); | 2717 EXPECT_TRUE(updated_answer_options.has_audio()); |
| 2794 EXPECT_TRUE(updated_answer_options.has_video()); | 2718 EXPECT_TRUE(updated_answer_options.has_video()); |
| 2795 } | 2719 } |
| OLD | NEW |