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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "webrtc/p2p/quic/quictransportchannel.h" | 23 #include "webrtc/p2p/quic/quictransportchannel.h" |
24 #include "webrtc/p2p/quic/reliablequicstream.h" | 24 #include "webrtc/p2p/quic/reliablequicstream.h" |
25 | 25 |
26 using webrtc::DataBuffer; | 26 using webrtc::DataBuffer; |
27 using webrtc::DataChannelInit; | 27 using webrtc::DataChannelInit; |
28 using webrtc::DataChannelInterface; | 28 using webrtc::DataChannelInterface; |
29 using webrtc::DataChannelObserver; | 29 using webrtc::DataChannelObserver; |
30 using webrtc::QuicDataChannel; | 30 using webrtc::QuicDataChannel; |
31 using webrtc::QuicDataTransport; | 31 using webrtc::QuicDataTransport; |
32 using cricket::FakeTransportChannel; | 32 using cricket::FakeTransportChannel; |
33 using cricket::FakeTransportController; | |
34 using cricket::QuicTransportChannel; | 33 using cricket::QuicTransportChannel; |
35 using cricket::ReliableQuicStream; | 34 using cricket::ReliableQuicStream; |
36 | 35 |
37 namespace { | 36 namespace { |
38 | 37 |
39 // Timeout for asynchronous operations. | 38 // Timeout for asynchronous operations. |
40 static const int kTimeoutMs = 1000; // milliseconds | 39 static const int kTimeoutMs = 1000; // milliseconds |
41 static const char kTransportName[] = "data"; | |
42 | 40 |
43 // FakeObserver receives messages from the data channel. | 41 // FakeObserver receives messages from the data channel. |
44 class FakeObserver : public DataChannelObserver { | 42 class FakeObserver : public DataChannelObserver { |
45 public: | 43 public: |
46 FakeObserver() {} | 44 FakeObserver() {} |
47 | 45 |
48 void OnStateChange() override {} | 46 void OnStateChange() override {} |
49 | 47 |
50 void OnBufferedAmountChange(uint64_t previous_amount) override {} | 48 void OnBufferedAmountChange(uint64_t previous_amount) override {} |
51 | 49 |
52 void OnMessage(const webrtc::DataBuffer& buffer) override { | 50 void OnMessage(const webrtc::DataBuffer& buffer) override { |
53 messages_.push_back(std::string(buffer.data.data<char>(), buffer.size())); | 51 messages_.push_back(std::string(buffer.data.data<char>(), buffer.size())); |
54 } | 52 } |
55 | 53 |
56 const std::vector<std::string>& messages() const { return messages_; } | 54 const std::vector<std::string>& messages() const { return messages_; } |
57 | 55 |
58 size_t messages_received() const { return messages_.size(); } | 56 size_t messages_received() const { return messages_.size(); } |
59 | 57 |
60 private: | 58 private: |
61 std::vector<std::string> messages_; | 59 std::vector<std::string> messages_; |
62 }; | 60 }; |
63 | 61 |
64 // A peer who uses a QUIC transport channel and fake ICE transport channel to | 62 // A peer who uses a QUIC transport channel and fake ICE transport channel to |
65 // send or receive data. | 63 // send or receive data. |
66 class QuicDataTransportPeer { | 64 class QuicDataTransportPeer { |
67 public: | 65 public: |
68 QuicDataTransportPeer() | 66 QuicDataTransportPeer() |
69 : fake_transport_controller_(new FakeTransportController()), | 67 : quic_data_transport_(rtc::Thread::Current(), |
70 quic_data_transport_(rtc::Thread::Current(), | |
71 rtc::Thread::Current(), | 68 rtc::Thread::Current(), |
72 rtc::Thread::Current(), | 69 rtc::Thread::Current()), |
73 fake_transport_controller_.get()) { | 70 ice_transport_channel_(new FakeTransportChannel("data", 0)), |
74 fake_transport_controller_->use_quic(); | 71 quic_transport_channel_(ice_transport_channel_) { |
75 quic_data_transport_.set_content_name("data"); | |
76 quic_data_transport_.SetTransport(kTransportName); | |
77 ice_transport_channel_ = static_cast<FakeTransportChannel*>( | |
78 quic_data_transport_.quic_transport_channel()->ice_transport_channel()); | |
79 ice_transport_channel_->SetAsync(true); | 72 ice_transport_channel_->SetAsync(true); |
80 } | 73 } |
81 | 74 |
82 void GenerateCertificateAndFingerprint() { | 75 void GenerateCertificateAndFingerprint() { |
83 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = | 76 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = |
84 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( | 77 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
85 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); | 78 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); |
86 quic_data_transport_.quic_transport_channel()->SetLocalCertificate( | 79 quic_transport_channel_.SetLocalCertificate(local_cert); |
87 local_cert); | |
88 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); | 80 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); |
89 } | 81 } |
90 | 82 |
91 // Connects |ice_transport_channel_| to that of the other peer. | 83 // Connects |ice_transport_channel_| to that of the other peer. |
92 void Connect(QuicDataTransportPeer* other_peer) { | 84 void Connect(QuicDataTransportPeer* other_peer) { |
93 ice_transport_channel_->SetDestination(other_peer->ice_transport_channel_); | 85 ice_transport_channel_->SetDestination(other_peer->ice_transport_channel_); |
94 } | 86 } |
95 | 87 |
96 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() { | 88 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() { |
97 return local_fingerprint_; | 89 return local_fingerprint_; |
98 } | 90 } |
99 | 91 |
100 QuicTransportChannel* quic_transport_channel() { | 92 QuicTransportChannel* quic_transport_channel() { |
101 return quic_data_transport_.quic_transport_channel(); | 93 return &quic_transport_channel_; |
102 } | 94 } |
103 | 95 |
104 // Write a messge directly to the ReliableQuicStream. | 96 // Write a messge directly to the ReliableQuicStream. |
105 void WriteMessage(int data_channel_id, | 97 void WriteMessage(int data_channel_id, |
106 uint64_t message_id, | 98 uint64_t message_id, |
107 const std::string& message) { | 99 const std::string& message) { |
108 ReliableQuicStream* stream = | 100 ReliableQuicStream* stream = quic_transport_channel_.CreateQuicStream(); |
109 quic_data_transport_.quic_transport_channel()->CreateQuicStream(); | |
110 rtc::CopyOnWriteBuffer payload; | 101 rtc::CopyOnWriteBuffer payload; |
111 webrtc::WriteQuicDataChannelMessageHeader(data_channel_id, message_id, | 102 webrtc::WriteQuicDataChannelMessageHeader(data_channel_id, message_id, |
112 &payload); | 103 &payload); |
113 stream->Write(payload.data<char>(), payload.size(), false); | 104 stream->Write(payload.data<char>(), payload.size(), false); |
114 stream->Write(message.data(), message.size(), true); | 105 stream->Write(message.data(), message.size(), true); |
115 } | 106 } |
116 | 107 |
117 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( | 108 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
118 const DataChannelInit* config) { | 109 const DataChannelInit* config) { |
119 return quic_data_transport_.CreateDataChannel("testing", config); | 110 return quic_data_transport_.CreateDataChannel("testing", config); |
120 } | 111 } |
121 | 112 |
122 QuicDataTransport* quic_data_transport() { return &quic_data_transport_; } | 113 QuicDataTransport* quic_data_transport() { return &quic_data_transport_; } |
123 | 114 |
124 private: | 115 private: |
125 // Creates a fingerprint from a certificate. | 116 // Creates a fingerprint from a certificate. |
126 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { | 117 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { |
127 std::string digest_algorithm; | 118 std::string digest_algorithm; |
128 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm); | 119 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm); |
129 std::unique_ptr<rtc::SSLFingerprint> fingerprint( | 120 std::unique_ptr<rtc::SSLFingerprint> fingerprint( |
130 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity())); | 121 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity())); |
131 return fingerprint.release(); | 122 return fingerprint.release(); |
132 } | 123 } |
133 | 124 |
134 std::unique_ptr<FakeTransportController> fake_transport_controller_; | |
135 QuicDataTransport quic_data_transport_; | 125 QuicDataTransport quic_data_transport_; |
136 FakeTransportChannel* ice_transport_channel_; | 126 FakeTransportChannel* ice_transport_channel_; |
| 127 QuicTransportChannel quic_transport_channel_; |
137 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_; | 128 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_; |
138 }; | 129 }; |
139 | 130 |
140 class QuicDataTransportTest : public testing::Test { | 131 class QuicDataTransportTest : public testing::Test { |
141 public: | 132 public: |
142 QuicDataTransportTest() {} | 133 QuicDataTransportTest() {} |
143 | 134 |
144 void ConnectTransportChannels() { | 135 void ConnectTransportChannels() { |
145 SetCryptoParameters(); | 136 SetCryptoParameters(); |
146 peer1_.Connect(&peer2_); | 137 peer1_.Connect(&peer2_); |
147 ASSERT_TRUE_WAIT(peer1_.quic_transport_channel()->writable() && | 138 ASSERT_TRUE_WAIT(peer1_.quic_transport_channel()->writable() && |
148 peer2_.quic_transport_channel()->writable(), | 139 peer2_.quic_transport_channel()->writable(), |
149 kTimeoutMs); | 140 kTimeoutMs); |
150 } | 141 } |
151 | 142 |
| 143 void SetTransportChannels() { |
| 144 ASSERT_TRUE(peer1_.quic_data_transport()->SetTransportChannel( |
| 145 peer1_.quic_transport_channel())); |
| 146 ASSERT_TRUE(peer2_.quic_data_transport()->SetTransportChannel( |
| 147 peer2_.quic_transport_channel())); |
| 148 } |
| 149 |
152 // Sets crypto parameters required for the QUIC handshake. | 150 // Sets crypto parameters required for the QUIC handshake. |
153 void SetCryptoParameters() { | 151 void SetCryptoParameters() { |
154 peer1_.GenerateCertificateAndFingerprint(); | 152 peer1_.GenerateCertificateAndFingerprint(); |
155 peer2_.GenerateCertificateAndFingerprint(); | 153 peer2_.GenerateCertificateAndFingerprint(); |
156 | 154 |
157 peer1_.quic_transport_channel()->SetSslRole(rtc::SSL_CLIENT); | 155 peer1_.quic_transport_channel()->SetSslRole(rtc::SSL_CLIENT); |
158 peer2_.quic_transport_channel()->SetSslRole(rtc::SSL_SERVER); | 156 peer2_.quic_transport_channel()->SetSslRole(rtc::SSL_SERVER); |
159 | 157 |
160 std::unique_ptr<rtc::SSLFingerprint>& peer1_fingerprint = | 158 std::unique_ptr<rtc::SSLFingerprint>& peer1_fingerprint = |
161 peer1_.local_fingerprint(); | 159 peer1_.local_fingerprint(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // Tests that the QuicDataTransport does not allow creating multiple | 200 // Tests that the QuicDataTransport does not allow creating multiple |
203 // QuicDataChannels with the same id. | 201 // QuicDataChannels with the same id. |
204 TEST_F(QuicDataTransportTest, CannotCreateDataChannelsWithSameId) { | 202 TEST_F(QuicDataTransportTest, CannotCreateDataChannelsWithSameId) { |
205 webrtc::DataChannelInit config; | 203 webrtc::DataChannelInit config; |
206 config.id = 2; | 204 config.id = 2; |
207 EXPECT_NE(nullptr, peer2_.CreateDataChannel(&config)); | 205 EXPECT_NE(nullptr, peer2_.CreateDataChannel(&config)); |
208 EXPECT_EQ(nullptr, peer2_.CreateDataChannel(&config)); | 206 EXPECT_EQ(nullptr, peer2_.CreateDataChannel(&config)); |
209 } | 207 } |
210 | 208 |
211 // Tests that any data channels created by the QuicDataTransport are in state | 209 // Tests that any data channels created by the QuicDataTransport are in state |
212 // kConnecting before the QuicTransportChannel is set, then transition to state | 210 // kConnecting before the QuicTransportChannel is set, then transiton to state |
213 // kOpen when the transport channel becomes writable. | 211 // kOpen when the transport channel becomes writable. |
214 TEST_F(QuicDataTransportTest, DataChannelsOpenWhenTransportChannelWritable) { | 212 TEST_F(QuicDataTransportTest, DataChannelsOpenWhenTransportChannelWritable) { |
215 webrtc::DataChannelInit config1; | 213 webrtc::DataChannelInit config1; |
216 config1.id = 7; | 214 config1.id = 7; |
217 rtc::scoped_refptr<DataChannelInterface> data_channel1 = | 215 rtc::scoped_refptr<DataChannelInterface> data_channel1 = |
218 peer2_.CreateDataChannel(&config1); | 216 peer2_.CreateDataChannel(&config1); |
219 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel1->state()); | 217 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel1->state()); |
| 218 SetTransportChannels(); |
220 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel1->state()); | 219 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel1->state()); |
221 webrtc::DataChannelInit config2; | 220 webrtc::DataChannelInit config2; |
222 config2.id = 14; | 221 config2.id = 14; |
223 rtc::scoped_refptr<DataChannelInterface> data_channel2 = | 222 rtc::scoped_refptr<DataChannelInterface> data_channel2 = |
224 peer2_.CreateDataChannel(&config2); | 223 peer2_.CreateDataChannel(&config2); |
225 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel2->state()); | 224 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel2->state()); |
226 // Existing data channels should open once the transport channel is writable. | 225 // Existing data channels should open once the transport channel is writable. |
227 ConnectTransportChannels(); | 226 ConnectTransportChannels(); |
228 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, data_channel1->state(), | 227 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, data_channel1->state(), |
229 kTimeoutMs); | 228 kTimeoutMs); |
230 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, data_channel2->state(), | 229 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, data_channel2->state(), |
231 kTimeoutMs); | 230 kTimeoutMs); |
232 // Any data channels created afterwards should start in state kOpen. | 231 // Any data channels created afterwards should start in state kOpen. |
233 webrtc::DataChannelInit config3; | 232 webrtc::DataChannelInit config3; |
234 config3.id = 21; | 233 config3.id = 21; |
235 rtc::scoped_refptr<DataChannelInterface> data_channel3 = | 234 rtc::scoped_refptr<DataChannelInterface> data_channel3 = |
236 peer2_.CreateDataChannel(&config3); | 235 peer2_.CreateDataChannel(&config3); |
237 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, data_channel3->state()); | 236 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, data_channel3->state()); |
238 } | 237 } |
239 | 238 |
240 // Tests that the QuicTransport dispatches messages for one QuicDataChannel. | 239 // Tests that the QuicTransport dispatches messages for one QuicDataChannel. |
241 TEST_F(QuicDataTransportTest, ReceiveMessagesForSingleDataChannel) { | 240 TEST_F(QuicDataTransportTest, ReceiveMessagesForSingleDataChannel) { |
242 ConnectTransportChannels(); | 241 ConnectTransportChannels(); |
| 242 SetTransportChannels(); |
243 | 243 |
244 int data_channel_id = 1337; | 244 int data_channel_id = 1337; |
245 webrtc::DataChannelInit config; | 245 webrtc::DataChannelInit config; |
246 config.id = data_channel_id; | 246 config.id = data_channel_id; |
247 rtc::scoped_refptr<DataChannelInterface> peer2_data_channel = | 247 rtc::scoped_refptr<DataChannelInterface> peer2_data_channel = |
248 peer2_.CreateDataChannel(&config); | 248 peer2_.CreateDataChannel(&config); |
249 FakeObserver observer; | 249 FakeObserver observer; |
250 peer2_data_channel->RegisterObserver(&observer); | 250 peer2_data_channel->RegisterObserver(&observer); |
251 | 251 |
252 uint64_t message1_id = 26u; | 252 uint64_t message1_id = 26u; |
253 peer1_.WriteMessage(data_channel_id, message1_id, "Testing"); | 253 peer1_.WriteMessage(data_channel_id, message1_id, "Testing"); |
254 ASSERT_EQ_WAIT(1, observer.messages_received(), kTimeoutMs); | 254 ASSERT_EQ_WAIT(1, observer.messages_received(), kTimeoutMs); |
255 EXPECT_EQ("Testing", observer.messages()[0]); | 255 EXPECT_EQ("Testing", observer.messages()[0]); |
256 | 256 |
257 uint64_t message2_id = 402u; | 257 uint64_t message2_id = 402u; |
258 peer1_.WriteMessage(data_channel_id, message2_id, "Hello, World!"); | 258 peer1_.WriteMessage(data_channel_id, message2_id, "Hello, World!"); |
259 ASSERT_EQ_WAIT(2, observer.messages_received(), kTimeoutMs); | 259 ASSERT_EQ_WAIT(2, observer.messages_received(), kTimeoutMs); |
260 EXPECT_EQ("Hello, World!", observer.messages()[1]); | 260 EXPECT_EQ("Hello, World!", observer.messages()[1]); |
261 | 261 |
262 uint64_t message3_id = 100260415u; | 262 uint64_t message3_id = 100260415u; |
263 peer1_.WriteMessage(data_channel_id, message3_id, "Third message"); | 263 peer1_.WriteMessage(data_channel_id, message3_id, "Third message"); |
264 ASSERT_EQ_WAIT(3, observer.messages_received(), kTimeoutMs); | 264 ASSERT_EQ_WAIT(3, observer.messages_received(), kTimeoutMs); |
265 EXPECT_EQ("Third message", observer.messages()[2]); | 265 EXPECT_EQ("Third message", observer.messages()[2]); |
266 } | 266 } |
267 | 267 |
268 // Tests that the QuicTransport dispatches messages to the correct data channel | 268 // Tests that the QuicTransport dispatches messages to the correct data channel |
269 // when multiple are in use. | 269 // when multiple are in use. |
270 TEST_F(QuicDataTransportTest, ReceiveMessagesForMultipleDataChannels) { | 270 TEST_F(QuicDataTransportTest, ReceiveMessagesForMultipleDataChannels) { |
271 ConnectTransportChannels(); | 271 ConnectTransportChannels(); |
| 272 SetTransportChannels(); |
272 | 273 |
273 std::vector<rtc::scoped_refptr<DataChannelInterface>> data_channels; | 274 std::vector<rtc::scoped_refptr<DataChannelInterface>> data_channels; |
274 for (int data_channel_id = 0; data_channel_id < 5; ++data_channel_id) { | 275 for (int data_channel_id = 0; data_channel_id < 5; ++data_channel_id) { |
275 webrtc::DataChannelInit config; | 276 webrtc::DataChannelInit config; |
276 config.id = data_channel_id; | 277 config.id = data_channel_id; |
277 data_channels.push_back(peer2_.CreateDataChannel(&config)); | 278 data_channels.push_back(peer2_.CreateDataChannel(&config)); |
278 } | 279 } |
279 | 280 |
280 for (int data_channel_id = 0; data_channel_id < 5; ++data_channel_id) { | 281 for (int data_channel_id = 0; data_channel_id < 5; ++data_channel_id) { |
281 uint64_t message1_id = 48023u; | 282 uint64_t message1_id = 48023u; |
282 FakeObserver observer; | 283 FakeObserver observer; |
283 DataChannelInterface* peer2_data_channel = | 284 DataChannelInterface* peer2_data_channel = |
284 data_channels[data_channel_id].get(); | 285 data_channels[data_channel_id].get(); |
285 peer2_data_channel->RegisterObserver(&observer); | 286 peer2_data_channel->RegisterObserver(&observer); |
286 peer1_.WriteMessage(data_channel_id, message1_id, "Testing"); | 287 peer1_.WriteMessage(data_channel_id, message1_id, "Testing"); |
287 ASSERT_EQ_WAIT(1, observer.messages_received(), kTimeoutMs); | 288 ASSERT_EQ_WAIT(1, observer.messages_received(), kTimeoutMs); |
288 EXPECT_EQ("Testing", observer.messages()[0]); | 289 EXPECT_EQ("Testing", observer.messages()[0]); |
289 | 290 |
290 uint64_t message2_id = 1372643095u; | 291 uint64_t message2_id = 1372643095u; |
291 peer1_.WriteMessage(data_channel_id, message2_id, "Hello, World!"); | 292 peer1_.WriteMessage(data_channel_id, message2_id, "Hello, World!"); |
292 ASSERT_EQ_WAIT(2, observer.messages_received(), kTimeoutMs); | 293 ASSERT_EQ_WAIT(2, observer.messages_received(), kTimeoutMs); |
293 EXPECT_EQ("Hello, World!", observer.messages()[1]); | 294 EXPECT_EQ("Hello, World!", observer.messages()[1]); |
294 } | 295 } |
295 } | 296 } |
296 | 297 |
297 // Tests end-to-end that both peers can use multiple QuicDataChannels to | 298 // Tests end-to-end that both peers can use multiple QuicDataChannels to |
298 // send/receive messages using a QuicDataTransport. | 299 // send/receive messages using a QuicDataTransport. |
299 TEST_F(QuicDataTransportTest, EndToEndSendReceiveMessages) { | 300 TEST_F(QuicDataTransportTest, EndToEndSendReceiveMessages) { |
300 ConnectTransportChannels(); | 301 ConnectTransportChannels(); |
| 302 SetTransportChannels(); |
301 | 303 |
302 std::vector<rtc::scoped_refptr<DataChannelInterface>> peer1_data_channels; | 304 std::vector<rtc::scoped_refptr<DataChannelInterface>> peer1_data_channels; |
303 std::vector<rtc::scoped_refptr<DataChannelInterface>> peer2_data_channels; | 305 std::vector<rtc::scoped_refptr<DataChannelInterface>> peer2_data_channels; |
304 | 306 |
305 for (int data_channel_id = 0; data_channel_id < 5; ++data_channel_id) { | 307 for (int data_channel_id = 0; data_channel_id < 5; ++data_channel_id) { |
306 webrtc::DataChannelInit config; | 308 webrtc::DataChannelInit config; |
307 config.id = data_channel_id; | 309 config.id = data_channel_id; |
308 peer1_data_channels.push_back(peer1_.CreateDataChannel(&config)); | 310 peer1_data_channels.push_back(peer1_.CreateDataChannel(&config)); |
309 peer2_data_channels.push_back(peer2_.CreateDataChannel(&config)); | 311 peer2_data_channels.push_back(peer2_.CreateDataChannel(&config)); |
310 } | 312 } |
(...skipping 19 matching lines...) Expand all Loading... |
330 peer2_data_channel->Send(webrtc::DataBuffer("Peer 2 message 1")); | 332 peer2_data_channel->Send(webrtc::DataBuffer("Peer 2 message 1")); |
331 ASSERT_EQ_WAIT(1, observer1.messages_received(), kTimeoutMs); | 333 ASSERT_EQ_WAIT(1, observer1.messages_received(), kTimeoutMs); |
332 EXPECT_EQ("Peer 2 message 1", observer1.messages()[0]); | 334 EXPECT_EQ("Peer 2 message 1", observer1.messages()[0]); |
333 | 335 |
334 peer2_data_channel->Send(webrtc::DataBuffer("Peer 2 message 2")); | 336 peer2_data_channel->Send(webrtc::DataBuffer("Peer 2 message 2")); |
335 ASSERT_EQ_WAIT(2, observer1.messages_received(), kTimeoutMs); | 337 ASSERT_EQ_WAIT(2, observer1.messages_received(), kTimeoutMs); |
336 EXPECT_EQ("Peer 2 message 2", observer1.messages()[1]); | 338 EXPECT_EQ("Peer 2 message 2", observer1.messages()[1]); |
337 } | 339 } |
338 } | 340 } |
339 | 341 |
340 // Tests that SetTransport returns false when setting a transport that is not | 342 // Tests that SetTransportChannel returns false when setting a NULL transport |
341 // equivalent to the one already set. | 343 // channel or a transport channel that is not equivalent to the one already set. |
342 TEST_F(QuicDataTransportTest, SetTransportReturnValue) { | 344 TEST_F(QuicDataTransportTest, SetTransportChannelReturnValue) { |
343 QuicDataTransport* quic_data_transport = peer1_.quic_data_transport(); | 345 QuicDataTransport* quic_data_transport = peer1_.quic_data_transport(); |
344 // Ignore the same transport name. | 346 EXPECT_FALSE(quic_data_transport->SetTransportChannel(nullptr)); |
345 EXPECT_TRUE(quic_data_transport->SetTransport(kTransportName)); | 347 QuicTransportChannel* transport_channel = peer1_.quic_transport_channel(); |
346 // Return false when setting a different transport name. | 348 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); |
347 EXPECT_FALSE(quic_data_transport->SetTransport("another transport name")); | 349 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); |
| 350 QuicTransportChannel* other_transport_channel = |
| 351 peer2_.quic_transport_channel(); |
| 352 EXPECT_FALSE( |
| 353 quic_data_transport->SetTransportChannel(other_transport_channel)); |
348 } | 354 } |
349 | 355 |
350 } // namespace | 356 } // namespace |
OLD | NEW |