| 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 16 matching lines...) Expand all Loading... |
| 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: |
| 66 QuicDataTransportPeer() | 67 QuicDataTransportPeer() |
| 67 : quic_data_transport_(rtc::Thread::Current(), | 68 : quic_data_transport_(rtc::Thread::Current(), |
| 68 rtc::Thread::Current(), | 69 rtc::Thread::Current(), |
| 69 rtc::Thread::Current()), | 70 rtc::Thread::Current(), |
| 71 new FakeTransportController()), |
| 70 ice_transport_channel_(new FakeTransportChannel("data", 0)), | 72 ice_transport_channel_(new FakeTransportChannel("data", 0)), |
| 71 quic_transport_channel_(ice_transport_channel_) { | 73 quic_transport_channel_(ice_transport_channel_) { |
| 72 ice_transport_channel_->SetAsync(true); | 74 ice_transport_channel_->SetAsync(true); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void GenerateCertificateAndFingerprint() { | 77 void GenerateCertificateAndFingerprint() { |
| 76 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = | 78 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = |
| 77 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( | 79 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
| 78 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); | 80 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); |
| 79 quic_transport_channel_.SetLocalCertificate(local_cert); | 81 quic_transport_channel_.SetLocalCertificate(local_cert); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 ASSERT_EQ_WAIT(1, observer1.messages_received(), kTimeoutMs); | 335 ASSERT_EQ_WAIT(1, observer1.messages_received(), kTimeoutMs); |
| 334 EXPECT_EQ("Peer 2 message 1", observer1.messages()[0]); | 336 EXPECT_EQ("Peer 2 message 1", observer1.messages()[0]); |
| 335 | 337 |
| 336 peer2_data_channel->Send(webrtc::DataBuffer("Peer 2 message 2")); | 338 peer2_data_channel->Send(webrtc::DataBuffer("Peer 2 message 2")); |
| 337 ASSERT_EQ_WAIT(2, observer1.messages_received(), kTimeoutMs); | 339 ASSERT_EQ_WAIT(2, observer1.messages_received(), kTimeoutMs); |
| 338 EXPECT_EQ("Peer 2 message 2", observer1.messages()[1]); | 340 EXPECT_EQ("Peer 2 message 2", observer1.messages()[1]); |
| 339 } | 341 } |
| 340 } | 342 } |
| 341 | 343 |
| 342 // Tests that SetTransportChannel returns false when setting a NULL transport | 344 // 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. | 345 // channel. |
| 344 TEST_F(QuicDataTransportTest, SetTransportChannelReturnValue) { | 346 TEST_F(QuicDataTransportTest, SetTransportChannelReturnValue) { |
| 345 QuicDataTransport* quic_data_transport = peer1_.quic_data_transport(); | 347 QuicDataTransport* quic_data_transport = peer1_.quic_data_transport(); |
| 346 EXPECT_FALSE(quic_data_transport->SetTransportChannel(nullptr)); | 348 EXPECT_FALSE(quic_data_transport->SetTransportChannel(nullptr)); |
| 347 QuicTransportChannel* transport_channel = peer1_.quic_transport_channel(); | 349 QuicTransportChannel* transport_channel = peer1_.quic_transport_channel(); |
| 348 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); | 350 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); |
| 349 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); | 351 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); |
| 350 QuicTransportChannel* other_transport_channel = | 352 QuicTransportChannel* other_transport_channel = |
| 351 peer2_.quic_transport_channel(); | 353 peer2_.quic_transport_channel(); |
| 352 EXPECT_FALSE( | 354 EXPECT_TRUE( |
| 353 quic_data_transport->SetTransportChannel(other_transport_channel)); | 355 quic_data_transport->SetTransportChannel(other_transport_channel)); |
| 354 } | 356 } |
| 355 | 357 |
| 356 } // namespace | 358 } // namespace |
| OLD | NEW |