Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: net/tools/quic/quic_client_session_test.cc

Issue 1977153002: Rename various MockConnectionFoo classes to MockQuicConnectionFoo. No behavior change. This is cons… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@121576119
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/quic_dispatcher_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/tools/quic/quic_client_session.h" 5 #include "net/tools/quic/quic_client_session.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "net/base/ip_endpoint.h" 10 #include "net/base/ip_endpoint.h"
11 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 11 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
12 #include "net/quic/quic_flags.h" 12 #include "net/quic/quic_flags.h"
13 #include "net/quic/spdy_utils.h" 13 #include "net/quic/spdy_utils.h"
14 #include "net/quic/test_tools/crypto_test_utils.h" 14 #include "net/quic/test_tools/crypto_test_utils.h"
15 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h" 15 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h"
16 #include "net/quic/test_tools/quic_connection_peer.h" 16 #include "net/quic/test_tools/quic_connection_peer.h"
17 #include "net/quic/test_tools/quic_packet_creator_peer.h" 17 #include "net/quic/test_tools/quic_packet_creator_peer.h"
18 #include "net/quic/test_tools/quic_spdy_session_peer.h" 18 #include "net/quic/test_tools/quic_spdy_session_peer.h"
19 #include "net/quic/test_tools/quic_test_utils.h" 19 #include "net/quic/test_tools/quic_test_utils.h"
20 #include "net/tools/quic/quic_spdy_client_stream.h" 20 #include "net/tools/quic/quic_spdy_client_stream.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 using base::StringPrintf; 23 using base::StringPrintf;
24 using google::protobuf::implicit_cast;
24 using net::test::ConstructEncryptedPacket; 25 using net::test::ConstructEncryptedPacket;
25 using net::test::ConstructMisFramedEncryptedPacket; 26 using net::test::ConstructMisFramedEncryptedPacket;
26 using net::test::CryptoTestUtils; 27 using net::test::CryptoTestUtils;
27 using net::test::DefaultQuicConfig; 28 using net::test::DefaultQuicConfig;
28 using net::test::MockConnection; 29 using net::test::MockQuicConnection;
29 using net::test::MockConnectionHelper; 30 using net::test::MockQuicConnectionHelper;
30 using net::test::MockQuicSpdyClientStream; 31 using net::test::MockQuicSpdyClientStream;
31 using net::test::PacketSavingConnection; 32 using net::test::PacketSavingConnection;
32 using net::test::QuicConnectionPeer; 33 using net::test::QuicConnectionPeer;
33 using net::test::QuicPacketCreatorPeer; 34 using net::test::QuicPacketCreatorPeer;
34 using net::test::QuicSpdySessionPeer; 35 using net::test::QuicSpdySessionPeer;
35 using net::test::SupportedVersions; 36 using net::test::SupportedVersions;
36 using net::test::TestPeerIPAddress; 37 using net::test::TestPeerIPAddress;
37 using net::test::ValueRestore; 38 using net::test::ValueRestore;
38 using net::test::kClientDataStreamId1; 39 using net::test::kClientDataStreamId1;
39 using net::test::kServerDataStreamId1; 40 using net::test::kServerDataStreamId1;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void CompleteCryptoHandshake() { 114 void CompleteCryptoHandshake() {
114 session_->CryptoConnect(); 115 session_->CryptoConnect();
115 QuicCryptoClientStream* stream = 116 QuicCryptoClientStream* stream =
116 static_cast<QuicCryptoClientStream*>(session_->GetCryptoStream()); 117 static_cast<QuicCryptoClientStream*>(session_->GetCryptoStream());
117 CryptoTestUtils::FakeServerOptions options; 118 CryptoTestUtils::FakeServerOptions options;
118 CryptoTestUtils::HandshakeWithFakeServer(&helper_, &alarm_factory_, 119 CryptoTestUtils::HandshakeWithFakeServer(&helper_, &alarm_factory_,
119 connection_, stream, options); 120 connection_, stream, options);
120 } 121 }
121 122
122 QuicCryptoClientConfig crypto_config_; 123 QuicCryptoClientConfig crypto_config_;
123 MockConnectionHelper helper_; 124 MockQuicConnectionHelper helper_;
124 MockAlarmFactory alarm_factory_; 125 MockAlarmFactory alarm_factory_;
125 PacketSavingConnection* connection_; 126 PacketSavingConnection* connection_;
126 std::unique_ptr<TestQuicClientSession> session_; 127 std::unique_ptr<TestQuicClientSession> session_;
127 QuicClientPushPromiseIndex push_promise_index_; 128 QuicClientPushPromiseIndex push_promise_index_;
128 SpdyHeaderBlock push_promise_; 129 SpdyHeaderBlock push_promise_;
129 string promise_url_; 130 string promise_url_;
130 QuicStreamId promised_stream_id_; 131 QuicStreamId promised_stream_id_;
131 QuicStreamId associated_stream_id_; 132 QuicStreamId associated_stream_id_;
132 }; 133 };
133 134
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 static bool CheckForDecryptionError(QuicFramer* framer) { 239 static bool CheckForDecryptionError(QuicFramer* framer) {
239 return framer->error() == QUIC_DECRYPTION_FAILURE; 240 return framer->error() == QUIC_DECRYPTION_FAILURE;
240 } 241 }
241 242
242 // Regression test for b/17206611. 243 // Regression test for b/17206611.
243 TEST_P(QuicClientSessionTest, InvalidPacketReceived) { 244 TEST_P(QuicClientSessionTest, InvalidPacketReceived) {
244 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); 245 IPEndPoint server_address(TestPeerIPAddress(), kTestPort);
245 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); 246 IPEndPoint client_address(TestPeerIPAddress(), kTestPort);
246 247
247 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) 248 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _))
248 .WillRepeatedly(Invoke(static_cast<MockConnection*>(connection_), 249 .WillRepeatedly(Invoke(implicit_cast<MockQuicConnection*>(connection_),
249 &MockConnection::ReallyProcessUdpPacket)); 250 &MockQuicConnection::ReallyProcessUdpPacket));
250 EXPECT_CALL(*connection_, OnCanWrite()).Times(AnyNumber()); 251 EXPECT_CALL(*connection_, OnCanWrite()).Times(AnyNumber());
251 EXPECT_CALL(*connection_, OnError(_)).Times(1); 252 EXPECT_CALL(*connection_, OnError(_)).Times(1);
252 253
253 // Verify that empty packets don't close the connection. 254 // Verify that empty packets don't close the connection.
254 QuicReceivedPacket zero_length_packet(nullptr, 0, QuicTime::Zero(), false); 255 QuicReceivedPacket zero_length_packet(nullptr, 0, QuicTime::Zero(), false);
255 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); 256 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
256 session_->ProcessUdpPacket(client_address, server_address, 257 session_->ProcessUdpPacket(client_address, server_address,
257 zero_length_packet); 258 zero_length_packet);
258 259
259 // Verifiy that small, invalid packets don't close the connection. 260 // Verifiy that small, invalid packets don't close the connection.
(...skipping 17 matching lines...) Expand all
277 EXPECT_CALL(*connection_, OnError(Truly(CheckForDecryptionError))).Times(1); 278 EXPECT_CALL(*connection_, OnError(Truly(CheckForDecryptionError))).Times(1);
278 session_->ProcessUdpPacket(client_address, server_address, *received); 279 session_->ProcessUdpPacket(client_address, server_address, *received);
279 } 280 }
280 281
281 // A packet with invalid framing should cause a connection to be closed. 282 // A packet with invalid framing should cause a connection to be closed.
282 TEST_P(QuicClientSessionTest, InvalidFramedPacketReceived) { 283 TEST_P(QuicClientSessionTest, InvalidFramedPacketReceived) {
283 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); 284 IPEndPoint server_address(TestPeerIPAddress(), kTestPort);
284 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); 285 IPEndPoint client_address(TestPeerIPAddress(), kTestPort);
285 286
286 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) 287 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _))
287 .WillRepeatedly(Invoke(static_cast<MockConnection*>(connection_), 288 .WillRepeatedly(Invoke(implicit_cast<MockQuicConnection*>(connection_),
288 &MockConnection::ReallyProcessUdpPacket)); 289 &MockQuicConnection::ReallyProcessUdpPacket));
289 EXPECT_CALL(*connection_, OnError(_)).Times(1); 290 EXPECT_CALL(*connection_, OnError(_)).Times(1);
290 291
291 // Verify that a decryptable packet with bad frames does close the connection. 292 // Verify that a decryptable packet with bad frames does close the connection.
292 QuicConnectionId connection_id = session_->connection()->connection_id(); 293 QuicConnectionId connection_id = session_->connection()->connection_id();
293 std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( 294 std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket(
294 connection_id, false, false, false, kDefaultPathId, 100, "data", 295 connection_id, false, false, false, kDefaultPathId, 100, "data",
295 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, nullptr, 296 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, nullptr,
296 Perspective::IS_SERVER)); 297 Perspective::IS_SERVER));
297 std::unique_ptr<QuicReceivedPacket> received( 298 std::unique_ptr<QuicReceivedPacket> received(
298 ConstructReceivedPacket(*packet, QuicTime::Zero())); 299 ConstructReceivedPacket(*packet, QuicTime::Zero()));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 QuicClientPromisedInfo* promised = 510 QuicClientPromisedInfo* promised =
510 session_->GetPromisedById(promised_stream_id_); 511 session_->GetPromisedById(promised_stream_id_);
511 EXPECT_NE(promised, nullptr); 512 EXPECT_NE(promised, nullptr);
512 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); 513 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr);
513 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); 514 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr);
514 } 515 }
515 516
516 } // namespace 517 } // namespace
517 } // namespace test 518 } // namespace test
518 } // namespace net 519 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/quic_dispatcher_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698