Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: webrtc/p2p/quic/quictransport_unittest.cc

Issue 1856943002: Allow TransportController to create a QuicTransportChannel (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix incorrect header order Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/p2p/quic/quictransport.h"
12
13 #include <string>
14 #include <vector>
15
16 #include "webrtc/base/gunit.h"
17 #include "webrtc/base/rtccertificate.h"
18 #include "webrtc/base/sslidentity.h"
19
20 using cricket::TransportChannelImpl;
21 using cricket::QuicTransport;
22 using cricket::Transport;
23 using cricket::TransportDescription;
24
25 static const char kIceUfrag1[] = "TESTICEUFRAG0001";
26 static const char kIcePwd1[] = "TESTICEPWD00000000000001";
27
28 static const char kIceUfrag2[] = "TESTICEUFRAG0002";
29 static const char kIcePwd2[] = "TESTICEPWD00000000000002";
30
31 static rtc::scoped_refptr<rtc::RTCCertificate> CreateCertificate(
32 std::string name) {
33 return rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
34 rtc::SSLIdentity::Generate(name, rtc::KT_DEFAULT)));
35 }
36
37 static rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) {
38 std::string digest_algorithm;
39 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm);
40 return rtc::SSLFingerprint::Create(digest_algorithm, cert->identity());
41 }
42
43 class QuicTransportTest : public testing::Test {
44 public:
45 QuicTransportTest() : transport_("testing", nullptr, nullptr) {}
46
47 protected:
48 QuicTransport transport_;
49 };
50
51 // Test that QuicTransport keeps the local certificate for later.
52 TEST_F(QuicTransportTest, SetLocalCertificate) {
53 TransportChannelImpl* channel = transport_.CreateChannel(1);
54 ASSERT_NE(nullptr, channel);
55 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate(
56 CreateCertificate("local"));
57 ASSERT_NE(nullptr, local_certificate);
58 transport_.SetLocalCertificate(local_certificate);
59 rtc::scoped_refptr<rtc::RTCCertificate> transport_local_certificate;
60 ASSERT_TRUE(transport_.GetLocalCertificate(&transport_local_certificate));
61 ASSERT_NE(nullptr, transport_local_certificate);
62 EXPECT_EQ(local_certificate, transport_local_certificate);
63 }
64
65 // Test setting the ICE role.
66 TEST_F(QuicTransportTest, SetIceRole) {
67 TransportChannelImpl* channel = transport_.CreateChannel(1);
68 ASSERT_NE(nullptr, channel);
69 transport_.SetIceRole(cricket::ICEROLE_CONTROLLING);
70 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_.ice_role());
71 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel->GetIceRole());
72 }
73
74 // Test setting the ICE tie breaker.
75 TEST_F(QuicTransportTest, SetIceTiebreaker) {
76 TransportChannelImpl* channel = transport_.CreateChannel(1);
77 ASSERT_NE(nullptr, channel);
78 transport_.SetIceTiebreaker(1u);
79 EXPECT_EQ(1u, transport_.IceTiebreaker());
80 }
81
82 // Test setting the local and remote descriptions.
83 TEST_F(QuicTransportTest, SetLocalAndRemoteTransportDescription) {
84 TransportChannelImpl* channel = transport_.CreateChannel(1);
85 ASSERT_NE(nullptr, channel);
86
87 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate(
88 CreateCertificate("local"));
89 ASSERT_NE(nullptr, local_certificate);
90 transport_.SetLocalCertificate(local_certificate);
91
92 rtc::scoped_ptr<rtc::SSLFingerprint> local_fingerprint(
93 CreateFingerprint(local_certificate.get()));
94 ASSERT_NE(nullptr, local_fingerprint);
95 TransportDescription local_desc(
96 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL,
97 cricket::CONNECTIONROLE_ACTPASS, local_fingerprint.get());
98 ASSERT_TRUE(transport_.SetLocalTransportDescription(
99 local_desc, cricket::CA_OFFER, nullptr));
100 // The certificate is applied to QuicTransportChannel when the local
101 // description is set.
102 rtc::scoped_refptr<rtc::RTCCertificate> channel_local_certificate =
103 channel->GetLocalCertificate();
104 ASSERT_NE(nullptr, channel_local_certificate);
105 EXPECT_EQ(local_certificate, channel_local_certificate);
106 rtc::scoped_ptr<rtc::SSLFingerprint> remote_fingerprint(
107 CreateFingerprint(CreateCertificate("remote").get()));
108 // NegotiateTransportDescription was not called yet. The SSL role should
109 // not be set and neither should the remote fingerprint.
110 rtc::scoped_ptr<rtc::SSLRole> role(new rtc::SSLRole());
111 EXPECT_FALSE(channel->GetSslRole(role.get()));
112 // Setting the remote description should set the SSL role.
113 ASSERT_NE(nullptr, remote_fingerprint);
114 TransportDescription remote_desc(
115 std::vector<std::string>(), kIceUfrag2, kIcePwd2, cricket::ICEMODE_FULL,
116 cricket::CONNECTIONROLE_PASSIVE, remote_fingerprint.get());
117 ASSERT_TRUE(transport_.SetRemoteTransportDescription(
118 remote_desc, cricket::CA_ANSWER, nullptr));
119 ASSERT_TRUE(channel->GetSslRole(role.get()));
120 // SSL role should be client because the remote description is an ANSWER.
121 EXPECT_EQ(*role, rtc::SSL_CLIENT);
122 }
123
124 // Test creation and destruction of channels.
125 TEST_F(QuicTransportTest, CreateAndDestroyChannels) {
126 TransportChannelImpl* channel1 = transport_.CreateChannel(1);
127 ASSERT_NE(nullptr, channel1);
128 EXPECT_TRUE(transport_.HasChannel(1));
129 EXPECT_EQ(channel1, transport_.GetChannel(1));
130 TransportChannelImpl* channel2 = transport_.CreateChannel(2);
131 ASSERT_NE(nullptr, channel2);
132 EXPECT_TRUE(transport_.HasChannel(2));
133 EXPECT_EQ(channel2, transport_.GetChannel(2));
134 transport_.DestroyChannel(1);
135 EXPECT_FALSE(transport_.HasChannel(1));
136 EXPECT_EQ(nullptr, transport_.GetChannel(1));
137 transport_.DestroyChannel(2);
138 EXPECT_FALSE(transport_.HasChannel(2));
139 EXPECT_EQ(nullptr, transport_.GetChannel(2));
140 }
OLDNEW
« webrtc/p2p/quic/quictransport.cc ('K') | « webrtc/p2p/quic/quictransport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698