OLD | NEW |
---|---|
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, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
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 | 29 |
30 #include "talk/app/webrtc/fakeportallocatorfactory.h" | |
31 #include "talk/app/webrtc/mediastreaminterface.h" | 30 #include "talk/app/webrtc/mediastreaminterface.h" |
32 #include "talk/app/webrtc/peerconnectionfactory.h" | 31 #include "talk/app/webrtc/peerconnectionfactory.h" |
33 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" | 32 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
34 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" | 33 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
35 #include "talk/app/webrtc/videosourceinterface.h" | 34 #include "talk/app/webrtc/videosourceinterface.h" |
36 #include "talk/media/base/fakevideocapturer.h" | 35 #include "talk/media/base/fakevideocapturer.h" |
37 #include "talk/media/webrtc/webrtccommon.h" | 36 #include "talk/media/webrtc/webrtccommon.h" |
38 #include "talk/media/webrtc/webrtcvoe.h" | 37 #include "talk/media/webrtc/webrtcvoe.h" |
39 #include "webrtc/base/gunit.h" | 38 #include "webrtc/base/gunit.h" |
40 #include "webrtc/base/scoped_ptr.h" | 39 #include "webrtc/base/scoped_ptr.h" |
41 #include "webrtc/base/thread.h" | 40 #include "webrtc/base/thread.h" |
41 #include "webrtc/p2p/client/fakeportallocator.h" | |
42 | 42 |
43 using webrtc::DataChannelInterface; | 43 using webrtc::DataChannelInterface; |
44 using webrtc::DtlsIdentityStoreInterface; | 44 using webrtc::DtlsIdentityStoreInterface; |
45 using webrtc::FakeVideoTrackRenderer; | 45 using webrtc::FakeVideoTrackRenderer; |
46 using webrtc::MediaStreamInterface; | 46 using webrtc::MediaStreamInterface; |
47 using webrtc::PeerConnectionFactoryInterface; | 47 using webrtc::PeerConnectionFactoryInterface; |
48 using webrtc::PeerConnectionInterface; | 48 using webrtc::PeerConnectionInterface; |
49 using webrtc::PeerConnectionObserver; | 49 using webrtc::PeerConnectionObserver; |
50 using webrtc::PortAllocatorFactoryInterface; | |
51 using webrtc::VideoSourceInterface; | 50 using webrtc::VideoSourceInterface; |
52 using webrtc::VideoTrackInterface; | 51 using webrtc::VideoTrackInterface; |
53 | 52 |
54 namespace { | 53 namespace { |
55 | 54 |
56 typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration> | |
57 StunConfigurations; | |
58 typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration> | |
59 TurnConfigurations; | |
60 | |
61 static const char kStunIceServer[] = "stun:stun.l.google.com:19302"; | 55 static const char kStunIceServer[] = "stun:stun.l.google.com:19302"; |
62 static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234"; | 56 static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234"; |
63 static const char kTurnIceServerWithTransport[] = | 57 static const char kTurnIceServerWithTransport[] = |
64 "turn:test@hello.com?transport=tcp"; | 58 "turn:test@hello.com?transport=tcp"; |
65 static const char kSecureTurnIceServer[] = | 59 static const char kSecureTurnIceServer[] = |
66 "turns:test@hello.com?transport=tcp"; | 60 "turns:test@hello.com?transport=tcp"; |
67 static const char kSecureTurnIceServerWithoutTransportParam[] = | 61 static const char kSecureTurnIceServerWithoutTransportParam[] = |
68 "turns:test_no_transport@hello.com:443"; | 62 "turns:test_no_transport@hello.com:443"; |
69 static const char kSecureTurnIceServerWithoutTransportAndPortParam[] = | 63 static const char kSecureTurnIceServerWithoutTransportAndPortParam[] = |
70 "turns:test_no_transport@hello.com"; | 64 "turns:test_no_transport@hello.com"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 | 97 |
104 class PeerConnectionFactoryTest : public testing::Test { | 98 class PeerConnectionFactoryTest : public testing::Test { |
105 void SetUp() { | 99 void SetUp() { |
106 factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(), | 100 factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(), |
107 rtc::Thread::Current(), | 101 rtc::Thread::Current(), |
108 NULL, | 102 NULL, |
109 NULL, | 103 NULL, |
110 NULL); | 104 NULL); |
111 | 105 |
112 ASSERT_TRUE(factory_.get() != NULL); | 106 ASSERT_TRUE(factory_.get() != NULL); |
113 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create(); | 107 port_allocator_.reset( |
108 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | |
109 raw_port_allocator_ = port_allocator_.get(); | |
pthatcher1
2015/12/15 07:58:44
Why not just have a getter of port_allocator() tha
Taylor Brandstetter
2015/12/15 21:31:54
I tried this route, but at the point where I was w
| |
114 } | 110 } |
115 | 111 |
116 protected: | 112 protected: |
117 void VerifyStunConfigurations(StunConfigurations stun_config) { | 113 void VerifyStunServers(cricket::ServerAddresses stun_servers) { |
118 webrtc::FakePortAllocatorFactory* allocator = | 114 EXPECT_EQ(stun_servers, raw_port_allocator_->stun_servers()); |
119 static_cast<webrtc::FakePortAllocatorFactory*>( | |
120 allocator_factory_.get()); | |
121 ASSERT_TRUE(allocator != NULL); | |
122 EXPECT_EQ(stun_config.size(), allocator->stun_configs().size()); | |
123 for (size_t i = 0; i < stun_config.size(); ++i) { | |
124 EXPECT_EQ(stun_config[i].server.ToString(), | |
125 allocator->stun_configs()[i].server.ToString()); | |
126 } | |
127 } | 115 } |
128 | 116 |
129 void VerifyTurnConfigurations(TurnConfigurations turn_config) { | 117 void VerifyTurnServers(std::vector<cricket::RelayServerConfig> turn_servers) { |
130 webrtc::FakePortAllocatorFactory* allocator = | 118 EXPECT_EQ(turn_servers.size(), raw_port_allocator_->turn_servers().size()); |
131 static_cast<webrtc::FakePortAllocatorFactory*>( | 119 for (size_t i = 0; i < turn_servers.size(); ++i) { |
132 allocator_factory_.get()); | 120 ASSERT_EQ(1u, turn_servers[i].ports.size()); |
133 ASSERT_TRUE(allocator != NULL); | 121 EXPECT_EQ(1u, raw_port_allocator_->turn_servers()[i].ports.size()); |
134 EXPECT_EQ(turn_config.size(), allocator->turn_configs().size()); | 122 EXPECT_EQ( |
135 for (size_t i = 0; i < turn_config.size(); ++i) { | 123 turn_servers[i].ports[0].address.ToString(), |
136 EXPECT_EQ(turn_config[i].server.ToString(), | 124 raw_port_allocator_->turn_servers()[i].ports[0].address.ToString()); |
137 allocator->turn_configs()[i].server.ToString()); | 125 EXPECT_EQ(turn_servers[i].ports[0].proto, |
138 EXPECT_EQ(turn_config[i].username, allocator->turn_configs()[i].username); | 126 raw_port_allocator_->turn_servers()[i].ports[0].proto); |
139 EXPECT_EQ(turn_config[i].password, allocator->turn_configs()[i].password); | 127 EXPECT_EQ(turn_servers[i].credentials.username, |
140 EXPECT_EQ(turn_config[i].transport_type, | 128 raw_port_allocator_->turn_servers()[i].credentials.username); |
141 allocator->turn_configs()[i].transport_type); | 129 EXPECT_EQ(turn_servers[i].credentials.password, |
130 raw_port_allocator_->turn_servers()[i].credentials.password); | |
142 } | 131 } |
143 } | 132 } |
144 | 133 |
145 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; | 134 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; |
146 NullPeerConnectionObserver observer_; | 135 NullPeerConnectionObserver observer_; |
147 rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_; | 136 rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator_; |
137 // Since the PC owns the port allocator after it's been initialized, | |
138 // this should only be used when known to be safe. | |
139 cricket::FakePortAllocator* raw_port_allocator_; | |
148 }; | 140 }; |
149 | 141 |
150 // Verify creation of PeerConnection using internal ADM, video factory and | 142 // Verify creation of PeerConnection using internal ADM, video factory and |
151 // internal libjingle threads. | 143 // internal libjingle threads. |
152 TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) { | 144 TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) { |
153 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 145 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
154 webrtc::CreatePeerConnectionFactory()); | 146 webrtc::CreatePeerConnectionFactory()); |
155 | 147 |
156 NullPeerConnectionObserver observer; | 148 NullPeerConnectionObserver observer; |
157 webrtc::PeerConnectionInterface::IceServers servers; | 149 webrtc::PeerConnectionInterface::RTCConfiguration config; |
158 | 150 |
159 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( | 151 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
160 new FakeDtlsIdentityStore()); | 152 new FakeDtlsIdentityStore()); |
161 rtc::scoped_refptr<PeerConnectionInterface> pc( | 153 rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection( |
162 factory->CreatePeerConnection( | 154 config, nullptr, nullptr, std::move(dtls_identity_store), &observer)); |
163 servers, nullptr, nullptr, dtls_identity_store.Pass(), &observer)); | |
164 | 155 |
165 EXPECT_TRUE(pc.get() != nullptr); | 156 EXPECT_TRUE(pc.get() != nullptr); |
166 } | 157 } |
167 | 158 |
168 // This test verifies creation of PeerConnection with valid STUN and TURN | 159 // This test verifies creation of PeerConnection with valid STUN and TURN |
169 // configuration. Also verifies the URL's parsed correctly as expected. | 160 // configuration. Also verifies the URL's parsed correctly as expected. |
170 TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { | 161 TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { |
171 PeerConnectionInterface::RTCConfiguration config; | 162 PeerConnectionInterface::RTCConfiguration config; |
172 webrtc::PeerConnectionInterface::IceServer ice_server; | 163 webrtc::PeerConnectionInterface::IceServer ice_server; |
173 ice_server.uri = kStunIceServer; | 164 ice_server.uri = kStunIceServer; |
174 config.servers.push_back(ice_server); | 165 config.servers.push_back(ice_server); |
175 ice_server.uri = kTurnIceServer; | 166 ice_server.uri = kTurnIceServer; |
176 ice_server.password = kTurnPassword; | 167 ice_server.password = kTurnPassword; |
177 config.servers.push_back(ice_server); | 168 config.servers.push_back(ice_server); |
178 ice_server.uri = kTurnIceServerWithTransport; | 169 ice_server.uri = kTurnIceServerWithTransport; |
179 ice_server.password = kTurnPassword; | 170 ice_server.password = kTurnPassword; |
180 config.servers.push_back(ice_server); | 171 config.servers.push_back(ice_server); |
181 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( | 172 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
182 new FakeDtlsIdentityStore()); | 173 new FakeDtlsIdentityStore()); |
183 rtc::scoped_refptr<PeerConnectionInterface> pc( | 174 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
184 factory_->CreatePeerConnection(config, nullptr, | 175 config, nullptr, std::move(port_allocator_), |
185 allocator_factory_.get(), | 176 std::move(dtls_identity_store), &observer_)); |
186 dtls_identity_store.Pass(), | 177 ASSERT_TRUE(pc.get() != NULL); |
187 &observer_)); | 178 cricket::ServerAddresses stun_servers; |
188 EXPECT_TRUE(pc.get() != NULL); | 179 rtc::SocketAddress stun1("stun.l.google.com", 19302); |
189 StunConfigurations stun_configs; | 180 stun_servers.insert(stun1); |
190 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( | 181 VerifyStunServers(stun_servers); |
191 "stun.l.google.com", 19302); | 182 std::vector<cricket::RelayServerConfig> turn_servers; |
192 stun_configs.push_back(stun1); | 183 cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
193 VerifyStunConfigurations(stun_configs); | 184 kTurnPassword, cricket::PROTO_UDP, false); |
194 TurnConfigurations turn_configs; | 185 turn_servers.push_back(turn1); |
195 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( | 186 cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
196 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); | 187 kTurnPassword, cricket::PROTO_TCP, false); |
197 turn_configs.push_back(turn1); | 188 turn_servers.push_back(turn2); |
198 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( | 189 VerifyTurnServers(turn_servers); |
199 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); | |
200 turn_configs.push_back(turn2); | |
201 VerifyTurnConfigurations(turn_configs); | |
202 } | 190 } |
203 | 191 |
204 // This test verifies creation of PeerConnection with valid STUN and TURN | 192 // This test verifies creation of PeerConnection with valid STUN and TURN |
205 // configuration. Also verifies the list of URL's parsed correctly as expected. | 193 // configuration. Also verifies the list of URL's parsed correctly as expected. |
206 TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) { | 194 TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) { |
207 PeerConnectionInterface::RTCConfiguration config; | 195 PeerConnectionInterface::RTCConfiguration config; |
208 webrtc::PeerConnectionInterface::IceServer ice_server; | 196 webrtc::PeerConnectionInterface::IceServer ice_server; |
209 ice_server.urls.push_back(kStunIceServer); | 197 ice_server.urls.push_back(kStunIceServer); |
210 ice_server.urls.push_back(kTurnIceServer); | 198 ice_server.urls.push_back(kTurnIceServer); |
211 ice_server.urls.push_back(kTurnIceServerWithTransport); | 199 ice_server.urls.push_back(kTurnIceServerWithTransport); |
212 ice_server.password = kTurnPassword; | 200 ice_server.password = kTurnPassword; |
213 config.servers.push_back(ice_server); | 201 config.servers.push_back(ice_server); |
214 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( | 202 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
215 new FakeDtlsIdentityStore()); | 203 new FakeDtlsIdentityStore()); |
216 rtc::scoped_refptr<PeerConnectionInterface> pc( | 204 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
217 factory_->CreatePeerConnection(config, nullptr, | 205 config, nullptr, std::move(port_allocator_), |
218 allocator_factory_.get(), | 206 std::move(dtls_identity_store), &observer_)); |
219 dtls_identity_store.Pass(), | 207 ASSERT_TRUE(pc.get() != NULL); |
220 &observer_)); | 208 cricket::ServerAddresses stun_servers; |
221 EXPECT_TRUE(pc.get() != NULL); | 209 rtc::SocketAddress stun1("stun.l.google.com", 19302); |
222 StunConfigurations stun_configs; | 210 stun_servers.insert(stun1); |
223 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( | 211 VerifyStunServers(stun_servers); |
224 "stun.l.google.com", 19302); | 212 std::vector<cricket::RelayServerConfig> turn_servers; |
225 stun_configs.push_back(stun1); | 213 cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
226 VerifyStunConfigurations(stun_configs); | 214 kTurnPassword, cricket::PROTO_UDP, false); |
227 TurnConfigurations turn_configs; | 215 turn_servers.push_back(turn1); |
228 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( | 216 cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
229 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); | 217 kTurnPassword, cricket::PROTO_TCP, false); |
230 turn_configs.push_back(turn1); | 218 turn_servers.push_back(turn2); |
231 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( | 219 VerifyTurnServers(turn_servers); |
232 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); | |
233 turn_configs.push_back(turn2); | |
234 VerifyTurnConfigurations(turn_configs); | |
235 } | |
236 | |
237 // This test verifies creation of PeerConnection with valid STUN and TURN | |
238 // configuration. Also verifies the URL's parsed correctly as expected. | |
239 // This version doesn't use RTCConfiguration. | |
240 // TODO(mallinath) - Remove this method after clients start using RTCConfig. | |
241 TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) { | |
242 webrtc::PeerConnectionInterface::IceServers ice_servers; | |
243 webrtc::PeerConnectionInterface::IceServer ice_server; | |
244 ice_server.uri = kStunIceServer; | |
245 ice_servers.push_back(ice_server); | |
246 ice_server.uri = kTurnIceServer; | |
247 ice_server.password = kTurnPassword; | |
248 ice_servers.push_back(ice_server); | |
249 ice_server.uri = kTurnIceServerWithTransport; | |
250 ice_server.password = kTurnPassword; | |
251 ice_servers.push_back(ice_server); | |
252 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( | |
253 new FakeDtlsIdentityStore()); | |
254 rtc::scoped_refptr<PeerConnectionInterface> pc( | |
255 factory_->CreatePeerConnection(ice_servers, nullptr, | |
256 allocator_factory_.get(), | |
257 dtls_identity_store.Pass(), | |
258 &observer_)); | |
259 EXPECT_TRUE(pc.get() != NULL); | |
260 StunConfigurations stun_configs; | |
261 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( | |
262 "stun.l.google.com", 19302); | |
263 stun_configs.push_back(stun1); | |
264 VerifyStunConfigurations(stun_configs); | |
265 TurnConfigurations turn_configs; | |
266 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( | |
267 "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); | |
268 turn_configs.push_back(turn1); | |
269 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( | |
270 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); | |
271 turn_configs.push_back(turn2); | |
272 VerifyTurnConfigurations(turn_configs); | |
273 } | 220 } |
274 | 221 |
275 TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { | 222 TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
276 PeerConnectionInterface::RTCConfiguration config; | 223 PeerConnectionInterface::RTCConfiguration config; |
277 webrtc::PeerConnectionInterface::IceServer ice_server; | 224 webrtc::PeerConnectionInterface::IceServer ice_server; |
278 ice_server.uri = kStunIceServer; | 225 ice_server.uri = kStunIceServer; |
279 config.servers.push_back(ice_server); | 226 config.servers.push_back(ice_server); |
280 ice_server.uri = kTurnIceServerWithNoUsernameInUri; | 227 ice_server.uri = kTurnIceServerWithNoUsernameInUri; |
281 ice_server.username = kTurnUsername; | 228 ice_server.username = kTurnUsername; |
282 ice_server.password = kTurnPassword; | 229 ice_server.password = kTurnPassword; |
283 config.servers.push_back(ice_server); | 230 config.servers.push_back(ice_server); |
284 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( | 231 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
285 new FakeDtlsIdentityStore()); | 232 new FakeDtlsIdentityStore()); |
286 rtc::scoped_refptr<PeerConnectionInterface> pc( | 233 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
287 factory_->CreatePeerConnection(config, nullptr, | 234 config, nullptr, std::move(port_allocator_), |
288 allocator_factory_.get(), | 235 std::move(dtls_identity_store), &observer_)); |
289 dtls_identity_store.Pass(), | 236 ASSERT_TRUE(pc.get() != NULL); |
290 &observer_)); | 237 std::vector<cricket::RelayServerConfig> turn_servers; |
291 EXPECT_TRUE(pc.get() != NULL); | 238 cricket::RelayServerConfig turn("test.com", 1234, kTurnUsername, |
292 TurnConfigurations turn_configs; | 239 kTurnPassword, cricket::PROTO_UDP, false); |
293 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( | 240 turn_servers.push_back(turn); |
294 "test.com", 1234, kTurnUsername, kTurnPassword, "udp", false); | 241 VerifyTurnServers(turn_servers); |
295 turn_configs.push_back(turn); | |
296 VerifyTurnConfigurations(turn_configs); | |
297 } | 242 } |
298 | 243 |
299 // This test verifies the PeerConnection created properly with TURN url which | 244 // This test verifies the PeerConnection created properly with TURN url which |
300 // has transport parameter in it. | 245 // has transport parameter in it. |
301 TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { | 246 TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { |
302 PeerConnectionInterface::RTCConfiguration config; | 247 PeerConnectionInterface::RTCConfiguration config; |
303 webrtc::PeerConnectionInterface::IceServer ice_server; | 248 webrtc::PeerConnectionInterface::IceServer ice_server; |
304 ice_server.uri = kTurnIceServerWithTransport; | 249 ice_server.uri = kTurnIceServerWithTransport; |
305 ice_server.password = kTurnPassword; | 250 ice_server.password = kTurnPassword; |
306 config.servers.push_back(ice_server); | 251 config.servers.push_back(ice_server); |
307 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( | 252 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
308 new FakeDtlsIdentityStore()); | 253 new FakeDtlsIdentityStore()); |
309 rtc::scoped_refptr<PeerConnectionInterface> pc( | 254 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
310 factory_->CreatePeerConnection(config, nullptr, | 255 config, nullptr, std::move(port_allocator_), |
311 allocator_factory_.get(), | 256 std::move(dtls_identity_store), &observer_)); |
312 dtls_identity_store.Pass(), | 257 ASSERT_TRUE(pc.get() != NULL); |
313 &observer_)); | 258 std::vector<cricket::RelayServerConfig> turn_servers; |
314 EXPECT_TRUE(pc.get() != NULL); | 259 cricket::RelayServerConfig turn("hello.com", kDefaultStunPort, "test", |
315 TurnConfigurations turn_configs; | 260 kTurnPassword, cricket::PROTO_TCP, false); |
316 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( | 261 turn_servers.push_back(turn); |
317 "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); | 262 VerifyTurnServers(turn_servers); |
318 turn_configs.push_back(turn); | |
319 VerifyTurnConfigurations(turn_configs); | |
320 } | 263 } |
321 | 264 |
322 TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { | 265 TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
323 PeerConnectionInterface::RTCConfiguration config; | 266 PeerConnectionInterface::RTCConfiguration config; |
324 webrtc::PeerConnectionInterface::IceServer ice_server; | 267 webrtc::PeerConnectionInterface::IceServer ice_server; |
325 ice_server.uri = kSecureTurnIceServer; | 268 ice_server.uri = kSecureTurnIceServer; |
326 ice_server.password = kTurnPassword; | 269 ice_server.password = kTurnPassword; |
327 config.servers.push_back(ice_server); | 270 config.servers.push_back(ice_server); |
328 ice_server.uri = kSecureTurnIceServerWithoutTransportParam; | 271 ice_server.uri = kSecureTurnIceServerWithoutTransportParam; |
329 ice_server.password = kTurnPassword; | 272 ice_server.password = kTurnPassword; |
330 config.servers.push_back(ice_server); | 273 config.servers.push_back(ice_server); |
331 ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam; | 274 ice_server.uri = kSecureTurnIceServerWithoutTransportAndPortParam; |
332 ice_server.password = kTurnPassword; | 275 ice_server.password = kTurnPassword; |
333 config.servers.push_back(ice_server); | 276 config.servers.push_back(ice_server); |
334 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( | 277 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
335 new FakeDtlsIdentityStore()); | 278 new FakeDtlsIdentityStore()); |
336 rtc::scoped_refptr<PeerConnectionInterface> pc( | 279 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
337 factory_->CreatePeerConnection(config, nullptr, | 280 config, nullptr, std::move(port_allocator_), |
338 allocator_factory_.get(), | 281 std::move(dtls_identity_store), &observer_)); |
339 dtls_identity_store.Pass(), | 282 ASSERT_TRUE(pc.get() != NULL); |
340 &observer_)); | 283 std::vector<cricket::RelayServerConfig> turn_servers; |
341 EXPECT_TRUE(pc.get() != NULL); | 284 cricket::RelayServerConfig turn1("hello.com", kDefaultStunTlsPort, "test", |
342 TurnConfigurations turn_configs; | 285 kTurnPassword, cricket::PROTO_TCP, true); |
343 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( | 286 turn_servers.push_back(turn1); |
344 "hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true); | |
345 turn_configs.push_back(turn1); | |
346 // TURNS with transport param should be default to tcp. | 287 // TURNS with transport param should be default to tcp. |
347 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( | 288 cricket::RelayServerConfig turn2("hello.com", 443, "test_no_transport", |
348 "hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true); | 289 kTurnPassword, cricket::PROTO_TCP, true); |
349 turn_configs.push_back(turn2); | 290 turn_servers.push_back(turn2); |
350 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3( | 291 cricket::RelayServerConfig turn3("hello.com", kDefaultStunTlsPort, |
351 "hello.com", kDefaultStunTlsPort, "test_no_transport", | 292 "test_no_transport", kTurnPassword, |
352 kTurnPassword, "tcp", true); | 293 cricket::PROTO_TCP, true); |
353 turn_configs.push_back(turn3); | 294 turn_servers.push_back(turn3); |
354 VerifyTurnConfigurations(turn_configs); | 295 VerifyTurnServers(turn_servers); |
355 } | 296 } |
356 | 297 |
357 TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { | 298 TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
358 PeerConnectionInterface::RTCConfiguration config; | 299 PeerConnectionInterface::RTCConfiguration config; |
359 webrtc::PeerConnectionInterface::IceServer ice_server; | 300 webrtc::PeerConnectionInterface::IceServer ice_server; |
360 ice_server.uri = kStunIceServerWithIPv4Address; | 301 ice_server.uri = kStunIceServerWithIPv4Address; |
361 config.servers.push_back(ice_server); | 302 config.servers.push_back(ice_server); |
362 ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort; | 303 ice_server.uri = kStunIceServerWithIPv4AddressWithoutPort; |
363 config.servers.push_back(ice_server); | 304 config.servers.push_back(ice_server); |
364 ice_server.uri = kStunIceServerWithIPv6Address; | 305 ice_server.uri = kStunIceServerWithIPv6Address; |
365 config.servers.push_back(ice_server); | 306 config.servers.push_back(ice_server); |
366 ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort; | 307 ice_server.uri = kStunIceServerWithIPv6AddressWithoutPort; |
367 config.servers.push_back(ice_server); | 308 config.servers.push_back(ice_server); |
368 ice_server.uri = kTurnIceServerWithIPv6Address; | 309 ice_server.uri = kTurnIceServerWithIPv6Address; |
369 ice_server.password = kTurnPassword; | 310 ice_server.password = kTurnPassword; |
370 config.servers.push_back(ice_server); | 311 config.servers.push_back(ice_server); |
371 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( | 312 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
372 new FakeDtlsIdentityStore()); | 313 new FakeDtlsIdentityStore()); |
373 rtc::scoped_refptr<PeerConnectionInterface> pc( | 314 rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
374 factory_->CreatePeerConnection(config, nullptr, | 315 config, nullptr, std::move(port_allocator_), |
375 allocator_factory_.get(), | 316 std::move(dtls_identity_store), &observer_)); |
376 dtls_identity_store.Pass(), | 317 ASSERT_TRUE(pc.get() != NULL); |
377 &observer_)); | 318 cricket::ServerAddresses stun_servers; |
378 EXPECT_TRUE(pc.get() != NULL); | 319 rtc::SocketAddress stun1("1.2.3.4", 1234); |
379 StunConfigurations stun_configs; | 320 stun_servers.insert(stun1); |
380 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( | 321 rtc::SocketAddress stun2("1.2.3.4", 3478); |
381 "1.2.3.4", 1234); | 322 stun_servers.insert(stun2); // Default port |
382 stun_configs.push_back(stun1); | 323 rtc::SocketAddress stun3("2401:fa00:4::", 1234); |
383 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2( | 324 stun_servers.insert(stun3); |
384 "1.2.3.4", 3478); | 325 rtc::SocketAddress stun4("2401:fa00:4::", 3478); |
385 stun_configs.push_back(stun2); // Default port | 326 stun_servers.insert(stun4); // Default port |
386 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3( | 327 VerifyStunServers(stun_servers); |
387 "2401:fa00:4::", 1234); | |
388 stun_configs.push_back(stun3); | |
389 webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4( | |
390 "2401:fa00:4::", 3478); | |
391 stun_configs.push_back(stun4); // Default port | |
392 VerifyStunConfigurations(stun_configs); | |
393 | 328 |
394 TurnConfigurations turn_configs; | 329 std::vector<cricket::RelayServerConfig> turn_servers; |
395 webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( | 330 cricket::RelayServerConfig turn1("2401:fa00:4::", 1234, "test", kTurnPassword, |
396 "2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false); | 331 cricket::PROTO_UDP, false); |
397 turn_configs.push_back(turn1); | 332 turn_servers.push_back(turn1); |
398 VerifyTurnConfigurations(turn_configs); | 333 VerifyTurnServers(turn_servers); |
399 } | 334 } |
400 | 335 |
401 // This test verifies the captured stream is rendered locally using a | 336 // This test verifies the captured stream is rendered locally using a |
402 // local video track. | 337 // local video track. |
403 TEST_F(PeerConnectionFactoryTest, LocalRendering) { | 338 TEST_F(PeerConnectionFactoryTest, LocalRendering) { |
404 cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer(); | 339 cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer(); |
405 // The source take ownership of |capturer|. | 340 // The source take ownership of |capturer|. |
406 rtc::scoped_refptr<VideoSourceInterface> source( | 341 rtc::scoped_refptr<VideoSourceInterface> source( |
407 factory_->CreateVideoSource(capturer, NULL)); | 342 factory_->CreateVideoSource(capturer, NULL)); |
408 ASSERT_TRUE(source.get() != NULL); | 343 ASSERT_TRUE(source.get() != NULL); |
409 rtc::scoped_refptr<VideoTrackInterface> track( | 344 rtc::scoped_refptr<VideoTrackInterface> track( |
410 factory_->CreateVideoTrack("testlabel", source)); | 345 factory_->CreateVideoTrack("testlabel", source)); |
411 ASSERT_TRUE(track.get() != NULL); | 346 ASSERT_TRUE(track.get() != NULL); |
412 FakeVideoTrackRenderer local_renderer(track); | 347 FakeVideoTrackRenderer local_renderer(track); |
413 | 348 |
414 EXPECT_EQ(0, local_renderer.num_rendered_frames()); | 349 EXPECT_EQ(0, local_renderer.num_rendered_frames()); |
415 EXPECT_TRUE(capturer->CaptureFrame()); | 350 EXPECT_TRUE(capturer->CaptureFrame()); |
416 EXPECT_EQ(1, local_renderer.num_rendered_frames()); | 351 EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
417 | 352 |
418 track->set_enabled(false); | 353 track->set_enabled(false); |
419 EXPECT_TRUE(capturer->CaptureFrame()); | 354 EXPECT_TRUE(capturer->CaptureFrame()); |
420 EXPECT_EQ(1, local_renderer.num_rendered_frames()); | 355 EXPECT_EQ(1, local_renderer.num_rendered_frames()); |
421 | 356 |
422 track->set_enabled(true); | 357 track->set_enabled(true); |
423 EXPECT_TRUE(capturer->CaptureFrame()); | 358 EXPECT_TRUE(capturer->CaptureFrame()); |
424 EXPECT_EQ(2, local_renderer.num_rendered_frames()); | 359 EXPECT_EQ(2, local_renderer.num_rendered_frames()); |
425 } | 360 } |
426 | 361 |
OLD | NEW |