OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 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 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
14 #include "webrtc/base/thread.h" | 14 #include "webrtc/base/thread.h" |
15 #include "webrtc/p2p/base/fakeportallocator.h" | 15 #include "webrtc/p2p/base/fakeportallocator.h" |
16 #include "webrtc/p2p/base/portallocator.h" | 16 #include "webrtc/p2p/base/portallocator.h" |
17 | 17 |
| 18 static const char kSessionId[] = "session id"; |
18 static const char kContentName[] = "test content"; | 19 static const char kContentName[] = "test content"; |
19 // Based on ICE_UFRAG_LENGTH | 20 // Based on ICE_UFRAG_LENGTH |
20 static const char kIceUfrag[] = "TESTICEUFRAG0000"; | 21 static const char kIceUfrag[] = "TESTICEUFRAG0000"; |
21 // Based on ICE_PWD_LENGTH | 22 // Based on ICE_PWD_LENGTH |
22 static const char kIcePwd[] = "TESTICEPWD00000000000000"; | 23 static const char kIcePwd[] = "TESTICEPWD00000000000000"; |
23 static const char kTurnUsername[] = "test"; | 24 static const char kTurnUsername[] = "test"; |
24 static const char kTurnPassword[] = "test"; | 25 static const char kTurnPassword[] = "test"; |
25 | 26 |
26 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { | 27 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { |
27 public: | 28 public: |
28 PortAllocatorTest() { | 29 PortAllocatorTest() { |
29 allocator_.reset( | 30 allocator_.reset( |
30 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | 31 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
31 } | 32 } |
32 | 33 |
33 protected: | 34 protected: |
34 void SetConfigurationWithPoolSize(int candidate_pool_size) { | 35 void SetConfigurationWithPoolSize(int candidate_pool_size) { |
35 allocator_->SetConfiguration(cricket::ServerAddresses(), | 36 allocator_->SetConfiguration(cricket::ServerAddresses(), |
36 std::vector<cricket::RelayServerConfig>(), | 37 std::vector<cricket::RelayServerConfig>(), |
37 candidate_pool_size); | 38 candidate_pool_size); |
38 } | 39 } |
39 | 40 |
| 41 std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession( |
| 42 const std::string& sid, |
| 43 const std::string& content_name, |
| 44 int component, |
| 45 const std::string& ice_ufrag, |
| 46 const std::string& ice_pwd) { |
| 47 return std::unique_ptr<cricket::FakePortAllocatorSession>( |
| 48 static_cast<cricket::FakePortAllocatorSession*>( |
| 49 allocator_ |
| 50 ->CreateSession(sid, content_name, component, ice_ufrag, |
| 51 ice_pwd) |
| 52 .release())); |
| 53 } |
| 54 |
40 const cricket::FakePortAllocatorSession* GetPooledSession() const { | 55 const cricket::FakePortAllocatorSession* GetPooledSession() const { |
41 return static_cast<const cricket::FakePortAllocatorSession*>( | 56 return static_cast<const cricket::FakePortAllocatorSession*>( |
42 allocator_->GetPooledSession()); | 57 allocator_->GetPooledSession()); |
43 } | 58 } |
44 | 59 |
45 std::unique_ptr<cricket::FakePortAllocatorSession> TakePooledSession() { | 60 std::unique_ptr<cricket::FakePortAllocatorSession> TakePooledSession() { |
46 return std::unique_ptr<cricket::FakePortAllocatorSession>( | 61 return std::unique_ptr<cricket::FakePortAllocatorSession>( |
47 static_cast<cricket::FakePortAllocatorSession*>( | 62 static_cast<cricket::FakePortAllocatorSession*>( |
48 allocator_->TakePooledSession(kContentName, 0, kIceUfrag, kIcePwd) | 63 allocator_->TakePooledSession(kContentName, 0, kIceUfrag, kIcePwd) |
49 .release())); | 64 .release())); |
(...skipping 19 matching lines...) Expand all Loading... |
69 cricket::PROTO_UDP, false}; | 84 cricket::PROTO_UDP, false}; |
70 }; | 85 }; |
71 | 86 |
72 TEST_F(PortAllocatorTest, TestDefaults) { | 87 TEST_F(PortAllocatorTest, TestDefaults) { |
73 EXPECT_EQ(0UL, allocator_->stun_servers().size()); | 88 EXPECT_EQ(0UL, allocator_->stun_servers().size()); |
74 EXPECT_EQ(0UL, allocator_->turn_servers().size()); | 89 EXPECT_EQ(0UL, allocator_->turn_servers().size()); |
75 EXPECT_EQ(0, allocator_->candidate_pool_size()); | 90 EXPECT_EQ(0, allocator_->candidate_pool_size()); |
76 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); | 91 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); |
77 } | 92 } |
78 | 93 |
| 94 // Call CreateSession and verify that the parameters passed in and the |
| 95 // candidate filter are applied as expected. |
| 96 TEST_F(PortAllocatorTest, CreateSession) { |
| 97 allocator_->set_candidate_filter(cricket::CF_RELAY); |
| 98 auto session = CreateSession(kSessionId, kContentName, 1, kIceUfrag, kIcePwd); |
| 99 ASSERT_NE(nullptr, session); |
| 100 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
| 101 EXPECT_EQ(kContentName, session->content_name()); |
| 102 EXPECT_EQ(1, session->component()); |
| 103 EXPECT_EQ(kIceUfrag, session->ice_ufrag()); |
| 104 EXPECT_EQ(kIcePwd, session->ice_pwd()); |
| 105 } |
| 106 |
79 TEST_F(PortAllocatorTest, SetConfigurationUpdatesIceServers) { | 107 TEST_F(PortAllocatorTest, SetConfigurationUpdatesIceServers) { |
80 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; | 108 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; |
81 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; | 109 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; |
82 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 0); | 110 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 0); |
83 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); | 111 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); |
84 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); | 112 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); |
85 | 113 |
86 // Update with a different set of servers. | 114 // Update with a different set of servers. |
87 cricket::ServerAddresses stun_servers_2 = {stun_server_2}; | 115 cricket::ServerAddresses stun_servers_2 = {stun_server_2}; |
88 std::vector<cricket::RelayServerConfig> turn_servers_2 = {turn_server_2}; | 116 std::vector<cricket::RelayServerConfig> turn_servers_2 = {turn_server_2}; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 std::unique_ptr<cricket::FakePortAllocatorSession> session( | 224 std::unique_ptr<cricket::FakePortAllocatorSession> session( |
197 static_cast<cricket::FakePortAllocatorSession*>( | 225 static_cast<cricket::FakePortAllocatorSession*>( |
198 allocator_->TakePooledSession(kContentName, 1, kIceUfrag, kIcePwd) | 226 allocator_->TakePooledSession(kContentName, 1, kIceUfrag, kIcePwd) |
199 .release())); | 227 .release())); |
200 EXPECT_EQ(1, session->transport_info_update_count()); | 228 EXPECT_EQ(1, session->transport_info_update_count()); |
201 EXPECT_EQ(kContentName, session->content_name()); | 229 EXPECT_EQ(kContentName, session->content_name()); |
202 EXPECT_EQ(1, session->component()); | 230 EXPECT_EQ(1, session->component()); |
203 EXPECT_EQ(kIceUfrag, session->ice_ufrag()); | 231 EXPECT_EQ(kIceUfrag, session->ice_ufrag()); |
204 EXPECT_EQ(kIcePwd, session->ice_pwd()); | 232 EXPECT_EQ(kIcePwd, session->ice_pwd()); |
205 } | 233 } |
| 234 |
| 235 // According to JSEP, candidate filtering should be done when the pooled |
| 236 // candidates are surfaced to the application. This means when a pooled |
| 237 // session is taken. So a pooled session should gather candidates |
| 238 // unfiltered until it's returned by TakePooledSession. |
| 239 TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { |
| 240 allocator_->set_candidate_filter(cricket::CF_RELAY); |
| 241 SetConfigurationWithPoolSize(1); |
| 242 auto peeked_session = GetPooledSession(); |
| 243 ASSERT_NE(nullptr, peeked_session); |
| 244 EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); |
| 245 auto session = TakePooledSession(); |
| 246 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
| 247 } |
OLD | NEW |