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