| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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/fakesslidentity.h" | 13 #include "webrtc/base/fakesslidentity.h" |
| 14 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/network.h" | 15 #include "webrtc/base/network.h" |
| 16 #include "webrtc/p2p/base/faketransportcontroller.h" | 16 #include "webrtc/p2p/base/faketransportcontroller.h" |
| 17 | 17 |
| 18 using cricket::JsepTransport; | 18 using cricket::JsepTransport; |
| 19 using cricket::TransportChannel; | 19 using cricket::TransportChannel; |
| 20 using cricket::FakeDtlsTransport; | 20 using cricket::FakeTransportChannel; |
| 21 using cricket::FakeIceTransport; | |
| 22 using cricket::IceRole; | 21 using cricket::IceRole; |
| 23 using cricket::TransportDescription; | 22 using cricket::TransportDescription; |
| 24 using rtc::SocketAddress; | 23 using rtc::SocketAddress; |
| 25 | 24 |
| 26 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 25 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
| 27 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 26 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
| 28 | 27 |
| 29 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; | 28 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; |
| 30 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; | 29 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; |
| 31 | 30 |
| 32 class JsepTransportTest : public testing::Test, public sigslot::has_slots<> { | 31 class JsepTransportTest : public testing::Test, public sigslot::has_slots<> { |
| 33 public: | 32 public: |
| 34 JsepTransportTest() | 33 JsepTransportTest() |
| 35 : transport_(new JsepTransport("test content name", nullptr)) {} | 34 : transport_(new JsepTransport("test content name", nullptr)) {} |
| 36 bool SetupChannel() { | 35 bool SetupChannel() { |
| 37 fake_ice_channel_.reset(new FakeIceTransport(transport_->mid(), 1)); | 36 fake_ice_channel_.reset(new FakeTransportChannel(transport_->mid(), 1)); |
| 38 fake_dtls_transport_.reset(new FakeDtlsTransport(fake_ice_channel_.get())); | 37 fake_dtls_channel_.reset(new FakeTransportChannel(transport_->mid(), 1)); |
| 39 return transport_->AddChannel(fake_dtls_transport_.get(), 1); | 38 return transport_->AddChannel(fake_dtls_channel_.get(), 1); |
| 40 } | 39 } |
| 41 void DestroyChannel() { transport_->RemoveChannel(1); } | 40 void DestroyChannel() { transport_->RemoveChannel(1); } |
| 42 | 41 |
| 43 protected: | 42 protected: |
| 44 std::unique_ptr<FakeDtlsTransport> fake_dtls_transport_; | 43 std::unique_ptr<FakeTransportChannel> fake_dtls_channel_; |
| 45 std::unique_ptr<FakeIceTransport> fake_ice_channel_; | 44 std::unique_ptr<FakeTransportChannel> fake_ice_channel_; |
| 46 std::unique_ptr<JsepTransport> transport_; | 45 std::unique_ptr<JsepTransport> transport_; |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 // This test verifies channels are created with proper ICE | 48 // This test verifies channels are created with proper ICE |
| 50 // ufrag/password after a transport description is applied. | 49 // ufrag/password after a transport description is applied. |
| 51 TEST_F(JsepTransportTest, TestChannelIceParameters) { | 50 TEST_F(JsepTransportTest, TestChannelIceParameters) { |
| 52 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); | 51 cricket::TransportDescription local_desc(kIceUfrag1, kIcePwd1); |
| 53 ASSERT_TRUE(transport_->SetLocalTransportDescription( | 52 ASSERT_TRUE(transport_->SetLocalTransportDescription( |
| 54 local_desc, cricket::CA_OFFER, NULL)); | 53 local_desc, cricket::CA_OFFER, NULL)); |
| 55 EXPECT_TRUE(SetupChannel()); | 54 EXPECT_TRUE(SetupChannel()); |
| 56 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_transport_->remote_ice_mode()); | 55 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_channel_->remote_ice_mode()); |
| 57 EXPECT_EQ(kIceUfrag1, fake_dtls_transport_->ice_ufrag()); | 56 EXPECT_EQ(kIceUfrag1, fake_dtls_channel_->ice_ufrag()); |
| 58 EXPECT_EQ(kIcePwd1, fake_dtls_transport_->ice_pwd()); | 57 EXPECT_EQ(kIcePwd1, fake_dtls_channel_->ice_pwd()); |
| 59 | 58 |
| 60 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); | 59 cricket::TransportDescription remote_desc(kIceUfrag1, kIcePwd1); |
| 61 ASSERT_TRUE(transport_->SetRemoteTransportDescription( | 60 ASSERT_TRUE(transport_->SetRemoteTransportDescription( |
| 62 remote_desc, cricket::CA_ANSWER, NULL)); | 61 remote_desc, cricket::CA_ANSWER, NULL)); |
| 63 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_transport_->remote_ice_mode()); | 62 EXPECT_EQ(cricket::ICEMODE_FULL, fake_dtls_channel_->remote_ice_mode()); |
| 64 EXPECT_EQ(kIceUfrag1, fake_dtls_transport_->remote_ice_ufrag()); | 63 EXPECT_EQ(kIceUfrag1, fake_dtls_channel_->remote_ice_ufrag()); |
| 65 EXPECT_EQ(kIcePwd1, fake_dtls_transport_->remote_ice_pwd()); | 64 EXPECT_EQ(kIcePwd1, fake_dtls_channel_->remote_ice_pwd()); |
| 66 } | 65 } |
| 67 | 66 |
| 68 // Verifies that IceCredentialsChanged returns true when either ufrag or pwd | 67 // Verifies that IceCredentialsChanged returns true when either ufrag or pwd |
| 69 // changed, and false in other cases. | 68 // changed, and false in other cases. |
| 70 TEST_F(JsepTransportTest, TestIceCredentialsChanged) { | 69 TEST_F(JsepTransportTest, TestIceCredentialsChanged) { |
| 71 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p2")); | 70 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p2")); |
| 72 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p1")); | 71 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u2", "p1")); |
| 73 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p2")); | 72 EXPECT_TRUE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p2")); |
| 74 EXPECT_FALSE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p1")); | 73 EXPECT_FALSE(cricket::IceCredentialsChanged("u1", "p1", "u1", "p1")); |
| 75 } | 74 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 ice_restart_local_desc, cricket::CA_OFFER, nullptr)); | 105 ice_restart_local_desc, cricket::CA_OFFER, nullptr)); |
| 107 ASSERT_TRUE(transport_->SetRemoteTransportDescription( | 106 ASSERT_TRUE(transport_->SetRemoteTransportDescription( |
| 108 ice_restart_remote_desc, cricket::CA_ANSWER, nullptr)); | 107 ice_restart_remote_desc, cricket::CA_ANSWER, nullptr)); |
| 109 EXPECT_FALSE(transport_->NeedsIceRestart()); | 108 EXPECT_FALSE(transport_->NeedsIceRestart()); |
| 110 } | 109 } |
| 111 | 110 |
| 112 TEST_F(JsepTransportTest, TestGetStats) { | 111 TEST_F(JsepTransportTest, TestGetStats) { |
| 113 EXPECT_TRUE(SetupChannel()); | 112 EXPECT_TRUE(SetupChannel()); |
| 114 cricket::TransportStats stats; | 113 cricket::TransportStats stats; |
| 115 EXPECT_TRUE(transport_->GetStats(&stats)); | 114 EXPECT_TRUE(transport_->GetStats(&stats)); |
| 116 // Note that this tests the behavior of a FakeIceTransport. | 115 // Note that this tests the behavior of a FakeTransportChannel. |
| 117 ASSERT_EQ(1U, stats.channel_stats.size()); | 116 ASSERT_EQ(1U, stats.channel_stats.size()); |
| 118 EXPECT_EQ(1, stats.channel_stats[0].component); | 117 EXPECT_EQ(1, stats.channel_stats[0].component); |
| 119 // Set local transport description for FakeTransport before connecting. | 118 // Set local transport description for FakeTransport before connecting. |
| 120 TransportDescription faketransport_desc( | 119 TransportDescription faketransport_desc( |
| 121 std::vector<std::string>(), | 120 std::vector<std::string>(), |
| 122 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), | 121 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), |
| 123 rtc::CreateRandomString(cricket::ICE_PWD_LENGTH), cricket::ICEMODE_FULL, | 122 rtc::CreateRandomString(cricket::ICE_PWD_LENGTH), cricket::ICEMODE_FULL, |
| 124 cricket::CONNECTIONROLE_NONE, nullptr); | 123 cricket::CONNECTIONROLE_NONE, nullptr); |
| 125 transport_->SetLocalTransportDescription(faketransport_desc, | 124 transport_->SetLocalTransportDescription(faketransport_desc, |
| 126 cricket::CA_OFFER, nullptr); | 125 cricket::CA_OFFER, nullptr); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 remote_desc.connection_role = param.remote_role; | 298 remote_desc.connection_role = param.remote_role; |
| 300 | 299 |
| 301 ASSERT_TRUE(transport_->SetRemoteTransportDescription( | 300 ASSERT_TRUE(transport_->SetRemoteTransportDescription( |
| 302 remote_desc, param.remote_action, nullptr)); | 301 remote_desc, param.remote_action, nullptr)); |
| 303 ASSERT_TRUE(transport_->SetLocalTransportDescription( | 302 ASSERT_TRUE(transport_->SetLocalTransportDescription( |
| 304 local_desc, param.local_action, nullptr)); | 303 local_desc, param.local_action, nullptr)); |
| 305 EXPECT_FALSE( | 304 EXPECT_FALSE( |
| 306 transport_->NegotiateRole(param.local_action, &ssl_role, &error_desc)); | 305 transport_->NegotiateRole(param.local_action, &ssl_role, &error_desc)); |
| 307 } | 306 } |
| 308 } | 307 } |
| OLD | NEW |