QUICHE team | 2bfc754 | 2019-02-26 14:36:06 -0500 | [diff] [blame] | 1 | // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/quartc/quartc_endpoint.h" |
| 6 | |
| 7 | #include "testing/gmock/include/gmock/gmock.h" |
| 8 | #include "testing/gtest/include/gtest/gtest.h" |
| 9 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 10 | #include "net/third_party/quiche/src/quic/quartc/simulated_packet_transport.h" |
| 11 | #include "net/third_party/quiche/src/quic/test_tools/simulator/simulator.h" |
| 12 | |
| 13 | namespace quic { |
| 14 | namespace { |
| 15 | |
| 16 | static QuicByteCount kDefaultMaxPacketSize = 1200; |
| 17 | |
| 18 | class FakeEndpointDelegate : public QuartcEndpoint::Delegate { |
| 19 | public: |
| 20 | void OnSessionCreated(QuartcSession* session) override { |
| 21 | last_session_ = session; |
| 22 | } |
| 23 | |
| 24 | void OnConnectError(QuicErrorCode /*error*/, |
| 25 | const QuicString& /*error_details*/) override {} |
| 26 | |
| 27 | QuartcSession* last_session() { return last_session_; } |
| 28 | |
| 29 | private: |
| 30 | QuartcSession* last_session_ = nullptr; |
| 31 | }; |
| 32 | |
| 33 | class QuartcEndpointTest : public QuicTest { |
| 34 | protected: |
| 35 | QuartcEndpointTest() |
| 36 | : transport_(&simulator_, |
| 37 | "client_transport", |
| 38 | "server_transport", |
| 39 | 10 * kDefaultMaxPacketSize) {} |
| 40 | |
| 41 | simulator::Simulator simulator_; |
| 42 | simulator::SimulatedQuartcPacketTransport transport_; |
| 43 | FakeEndpointDelegate delegate_; |
| 44 | }; |
| 45 | |
| 46 | // After calling Connect, the client endpoint must wait for an async callback. |
| 47 | // The callback occurs after a finite amount of time and produces a session. |
| 48 | TEST_F(QuartcEndpointTest, ClientCreatesSessionAsynchronously) { |
| 49 | QuartcClientEndpoint endpoint_(simulator_.GetAlarmFactory(), |
| 50 | simulator_.GetClock(), &delegate_, |
| 51 | /*serialized_server_config=*/""); |
| 52 | QuartcSessionConfig config; |
| 53 | config.packet_transport = &transport_; |
| 54 | config.max_packet_size = kDefaultMaxPacketSize; |
| 55 | endpoint_.Connect(config); |
| 56 | |
| 57 | EXPECT_EQ(delegate_.last_session(), nullptr); |
| 58 | |
| 59 | EXPECT_TRUE(simulator_.RunUntil( |
| 60 | [this] { return delegate_.last_session() != nullptr; })); |
| 61 | } |
| 62 | |
| 63 | } // namespace |
| 64 | } // namespace quic |