OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "net/base/capturing_net_log.h" | 10 #include "net/base/capturing_net_log.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // Returns the header from the last packet written. | 57 // Returns the header from the last packet written. |
58 const QuicPacketHeader& header() { return header_; } | 58 const QuicPacketHeader& header() { return header_; } |
59 | 59 |
60 private: | 60 private: |
61 QuicPacketHeader header_; | 61 QuicPacketHeader header_; |
62 }; | 62 }; |
63 | 63 |
64 class QuicClientSessionTest : public ::testing::Test { | 64 class QuicClientSessionTest : public ::testing::Test { |
65 protected: | 65 protected: |
66 QuicClientSessionTest() | 66 QuicClientSessionTest() |
67 : guid_(1), | 67 : writer_(new TestPacketWriter()), |
68 writer_(new TestPacketWriter()), | 68 connection_(new PacketSavingConnection(false)), |
69 connection_(new PacketSavingConnection(guid_, IPEndPoint(), false)), | |
70 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, | 69 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, |
71 kServerHostname, DefaultQuicConfig(), &crypto_config_, | 70 kServerHostname, DefaultQuicConfig(), &crypto_config_, |
72 &net_log_) { | 71 &net_log_) { |
73 session_.config()->SetDefaults(); | 72 session_.config()->SetDefaults(); |
74 crypto_config_.SetDefaults(); | 73 crypto_config_.SetDefaults(); |
75 } | 74 } |
76 | 75 |
77 virtual void TearDown() OVERRIDE { | 76 virtual void TearDown() OVERRIDE { |
78 session_.CloseSessionOnError(ERR_ABORTED); | 77 session_.CloseSessionOnError(ERR_ABORTED); |
79 } | 78 } |
80 | 79 |
81 scoped_ptr<DatagramClientSocket> GetSocket() { | 80 scoped_ptr<DatagramClientSocket> GetSocket() { |
82 socket_factory_.AddSocketDataProvider(&socket_data_); | 81 socket_factory_.AddSocketDataProvider(&socket_data_); |
83 return socket_factory_.CreateDatagramClientSocket( | 82 return socket_factory_.CreateDatagramClientSocket( |
84 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), | 83 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), |
85 &net_log_, NetLog::Source()); | 84 &net_log_, NetLog::Source()); |
86 } | 85 } |
87 | 86 |
88 void CompleteCryptoHandshake() { | 87 void CompleteCryptoHandshake() { |
89 ASSERT_EQ(ERR_IO_PENDING, | 88 ASSERT_EQ(ERR_IO_PENDING, |
90 session_.CryptoConnect(false, callback_.callback())); | 89 session_.CryptoConnect(false, callback_.callback())); |
91 CryptoTestUtils::HandshakeWithFakeServer( | 90 CryptoTestUtils::HandshakeWithFakeServer( |
92 connection_, session_.GetCryptoStream()); | 91 connection_, session_.GetCryptoStream()); |
93 ASSERT_EQ(OK, callback_.WaitForResult()); | 92 ASSERT_EQ(OK, callback_.WaitForResult()); |
94 } | 93 } |
95 | 94 |
96 QuicGuid guid_; | |
97 scoped_ptr<QuicDefaultPacketWriter> writer_; | 95 scoped_ptr<QuicDefaultPacketWriter> writer_; |
98 PacketSavingConnection* connection_; | 96 PacketSavingConnection* connection_; |
99 CapturingNetLog net_log_; | 97 CapturingNetLog net_log_; |
100 MockClientSocketFactory socket_factory_; | 98 MockClientSocketFactory socket_factory_; |
101 StaticSocketDataProvider socket_data_; | 99 StaticSocketDataProvider socket_data_; |
102 QuicClientSession session_; | 100 QuicClientSession session_; |
103 MockClock clock_; | 101 MockClock clock_; |
104 MockRandom random_; | 102 MockRandom random_; |
105 QuicConnectionVisitorInterface* visitor_; | 103 QuicConnectionVisitorInterface* visitor_; |
106 TestCompletionCallback callback_; | 104 TestCompletionCallback callback_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 154 |
157 // After receiving a GoAway, I should no longer be able to create outgoing | 155 // After receiving a GoAway, I should no longer be able to create outgoing |
158 // streams. | 156 // streams. |
159 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); | 157 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); |
160 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); | 158 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); |
161 } | 159 } |
162 | 160 |
163 } // namespace | 161 } // namespace |
164 } // namespace test | 162 } // namespace test |
165 } // namespace net | 163 } // namespace net |
OLD | NEW |