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

Side by Side Diff: net/quic/quic_chromium_client_session_test.cc

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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/p2p/quic_p2p_session_test.cc ('k') | net/quic/quic_chromium_client_stream_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/quic/quic_chromium_client_session.h" 5 #include "net/quic/quic_chromium_client_session.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 19 matching lines...) Expand all
30 #include "net/quic/test_tools/crypto_test_utils.h" 30 #include "net/quic/test_tools/crypto_test_utils.h"
31 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" 31 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
32 #include "net/quic/test_tools/quic_chromium_client_session_peer.h" 32 #include "net/quic/test_tools/quic_chromium_client_session_peer.h"
33 #include "net/quic/test_tools/quic_spdy_session_peer.h" 33 #include "net/quic/test_tools/quic_spdy_session_peer.h"
34 #include "net/quic/test_tools/quic_test_packet_maker.h" 34 #include "net/quic/test_tools/quic_test_packet_maker.h"
35 #include "net/quic/test_tools/quic_test_utils.h" 35 #include "net/quic/test_tools/quic_test_utils.h"
36 #include "net/quic/test_tools/simple_quic_framer.h" 36 #include "net/quic/test_tools/simple_quic_framer.h"
37 #include "net/socket/socket_test_util.h" 37 #include "net/socket/socket_test_util.h"
38 #include "net/spdy/spdy_test_utils.h" 38 #include "net/spdy/spdy_test_utils.h"
39 #include "net/test/cert_test_util.h" 39 #include "net/test/cert_test_util.h"
40 #include "net/test/gtest_util.h"
40 #include "net/test/test_data_directory.h" 41 #include "net/test/test_data_directory.h"
41 #include "net/udp/datagram_client_socket.h" 42 #include "net/udp/datagram_client_socket.h"
43 #include "testing/gmock/include/gmock/gmock.h"
42 44
43 using testing::_; 45 using testing::_;
44 46
45 namespace net { 47 namespace net {
46 namespace test { 48 namespace test {
47 namespace { 49 namespace {
48 50
49 const IPEndPoint kIpEndPoint = IPEndPoint(IPAddress::IPv4AllZeros(), 0); 51 const IPEndPoint kIpEndPoint = IPEndPoint(IPAddress::IPv4AllZeros(), 0);
50 const char kServerHostname[] = "test.example.com"; 52 const char kServerHostname[] = "test.example.com";
51 const uint16_t kServerPort = 443; 53 const uint16_t kServerPort = 443;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 verify_details_.cert_verify_result.is_issued_by_known_root = true; 110 verify_details_.cert_verify_result.is_issued_by_known_root = true;
109 session_->Initialize(); 111 session_->Initialize();
110 session_->StartReading(); 112 session_->StartReading();
111 } 113 }
112 114
113 void TearDown() override { 115 void TearDown() override {
114 session_->CloseSessionOnError(ERR_ABORTED, QUIC_INTERNAL_ERROR); 116 session_->CloseSessionOnError(ERR_ABORTED, QUIC_INTERNAL_ERROR);
115 } 117 }
116 118
117 void CompleteCryptoHandshake() { 119 void CompleteCryptoHandshake() {
118 ASSERT_EQ(OK, session_->CryptoConnect(false, callback_.callback())); 120 ASSERT_THAT(session_->CryptoConnect(false, callback_.callback()), IsOk());
119 } 121 }
120 122
121 QuicPacketWriter* CreateQuicPacketWriter(DatagramClientSocket* socket, 123 QuicPacketWriter* CreateQuicPacketWriter(DatagramClientSocket* socket,
122 QuicConnection* connection) const { 124 QuicConnection* connection) const {
123 std::unique_ptr<QuicChromiumPacketWriter> writer( 125 std::unique_ptr<QuicChromiumPacketWriter> writer(
124 new QuicChromiumPacketWriter(socket)); 126 new QuicChromiumPacketWriter(socket));
125 writer->SetConnection(connection); 127 writer->SetConnection(connection);
126 return writer.release(); 128 return writer.release();
127 } 129 }
128 130
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ASSERT_EQ(ERR_IO_PENDING, 220 ASSERT_EQ(ERR_IO_PENDING,
219 stream_request.StartRequest(session_->GetWeakPtr(), &stream, 221 stream_request.StartRequest(session_->GetWeakPtr(), &stream,
220 callback.callback())); 222 callback.callback()));
221 223
222 // Close a stream and ensure I can now open a new one. 224 // Close a stream and ensure I can now open a new one.
223 QuicStreamId stream_id = streams[0]->id(); 225 QuicStreamId stream_id = streams[0]->id();
224 session_->CloseStream(stream_id); 226 session_->CloseStream(stream_id);
225 QuicRstStreamFrame rst1(stream_id, QUIC_STREAM_NO_ERROR, 0); 227 QuicRstStreamFrame rst1(stream_id, QUIC_STREAM_NO_ERROR, 0);
226 session_->OnRstStream(rst1); 228 session_->OnRstStream(rst1);
227 ASSERT_TRUE(callback.have_result()); 229 ASSERT_TRUE(callback.have_result());
228 EXPECT_EQ(OK, callback.WaitForResult()); 230 EXPECT_THAT(callback.WaitForResult(), IsOk());
229 EXPECT_TRUE(stream != nullptr); 231 EXPECT_TRUE(stream != nullptr);
230 } 232 }
231 233
232 TEST_P(QuicChromiumClientSessionTest, GoAwayReceived) { 234 TEST_P(QuicChromiumClientSessionTest, GoAwayReceived) {
233 Initialize(); 235 Initialize();
234 CompleteCryptoHandshake(); 236 CompleteCryptoHandshake();
235 237
236 // After receiving a GoAway, I should no longer be able to create outgoing 238 // After receiving a GoAway, I should no longer be able to create outgoing
237 // streams. 239 // streams.
238 session_->connection()->OnGoAwayFrame( 240 session_->connection()->OnGoAwayFrame(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 ack_and_data_out->length(), 3)}; 359 ack_and_data_out->length(), 3)};
358 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 360 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
359 arraysize(writes)); 361 arraysize(writes));
360 socket_factory_.AddSocketDataProvider(&socket_data); 362 socket_factory_.AddSocketDataProvider(&socket_data);
361 363
362 // Create connected socket. 364 // Create connected socket.
363 std::unique_ptr<DatagramClientSocket> new_socket = 365 std::unique_ptr<DatagramClientSocket> new_socket =
364 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND, 366 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND,
365 base::Bind(&base::RandInt), 367 base::Bind(&base::RandInt),
366 &net_log_, NetLog::Source()); 368 &net_log_, NetLog::Source());
367 EXPECT_EQ(OK, new_socket->Connect(kIpEndPoint)); 369 EXPECT_THAT(new_socket->Connect(kIpEndPoint), IsOk());
368 370
369 // Create reader and writer. 371 // Create reader and writer.
370 std::unique_ptr<QuicChromiumPacketReader> new_reader( 372 std::unique_ptr<QuicChromiumPacketReader> new_reader(
371 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(), 373 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
372 kQuicYieldAfterPacketsRead, 374 kQuicYieldAfterPacketsRead,
373 QuicTime::Delta::FromMilliseconds( 375 QuicTime::Delta::FromMilliseconds(
374 kQuicYieldAfterDurationMilliseconds), 376 kQuicYieldAfterDurationMilliseconds),
375 bound_net_log_.bound())); 377 bound_net_log_.bound()));
376 std::unique_ptr<QuicPacketWriter> new_writer( 378 std::unique_ptr<QuicPacketWriter> new_writer(
377 CreateQuicPacketWriter(new_socket.get(), session_->connection())); 379 CreateQuicPacketWriter(new_socket.get(), session_->connection()));
(...skipping 27 matching lines...) Expand all
405 MockWrite(SYNCHRONOUS, ping_out->data(), ping_out->length(), i + 2)}; 407 MockWrite(SYNCHRONOUS, ping_out->data(), ping_out->length(), i + 2)};
406 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 408 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
407 arraysize(writes)); 409 arraysize(writes));
408 socket_factory_.AddSocketDataProvider(&socket_data); 410 socket_factory_.AddSocketDataProvider(&socket_data);
409 411
410 // Create connected socket. 412 // Create connected socket.
411 std::unique_ptr<DatagramClientSocket> new_socket = 413 std::unique_ptr<DatagramClientSocket> new_socket =
412 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND, 414 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND,
413 base::Bind(&base::RandInt), 415 base::Bind(&base::RandInt),
414 &net_log_, NetLog::Source()); 416 &net_log_, NetLog::Source());
415 EXPECT_EQ(OK, new_socket->Connect(kIpEndPoint)); 417 EXPECT_THAT(new_socket->Connect(kIpEndPoint), IsOk());
416 418
417 // Create reader and writer. 419 // Create reader and writer.
418 std::unique_ptr<QuicChromiumPacketReader> new_reader( 420 std::unique_ptr<QuicChromiumPacketReader> new_reader(
419 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(), 421 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
420 kQuicYieldAfterPacketsRead, 422 kQuicYieldAfterPacketsRead,
421 QuicTime::Delta::FromMilliseconds( 423 QuicTime::Delta::FromMilliseconds(
422 kQuicYieldAfterDurationMilliseconds), 424 kQuicYieldAfterDurationMilliseconds),
423 bound_net_log_.bound())); 425 bound_net_log_.bound()));
424 std::unique_ptr<QuicPacketWriter> new_writer( 426 std::unique_ptr<QuicPacketWriter> new_writer(
425 CreateQuicPacketWriter(new_socket.get(), session_->connection())); 427 CreateQuicPacketWriter(new_socket.get(), session_->connection()));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 MockRead(ASYNC, ERR_NETWORK_CHANGED, 5)}; 467 MockRead(ASYNC, ERR_NETWORK_CHANGED, 5)};
466 SequencedSocketData new_socket_data(new_reads, arraysize(new_reads), writes, 468 SequencedSocketData new_socket_data(new_reads, arraysize(new_reads), writes,
467 arraysize(writes)); 469 arraysize(writes));
468 socket_factory_.AddSocketDataProvider(&new_socket_data); 470 socket_factory_.AddSocketDataProvider(&new_socket_data);
469 471
470 // Create connected socket. 472 // Create connected socket.
471 std::unique_ptr<DatagramClientSocket> new_socket = 473 std::unique_ptr<DatagramClientSocket> new_socket =
472 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND, 474 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND,
473 base::Bind(&base::RandInt), 475 base::Bind(&base::RandInt),
474 &net_log_, NetLog::Source()); 476 &net_log_, NetLog::Source());
475 EXPECT_EQ(OK, new_socket->Connect(kIpEndPoint)); 477 EXPECT_THAT(new_socket->Connect(kIpEndPoint), IsOk());
476 478
477 // Create reader and writer. 479 // Create reader and writer.
478 std::unique_ptr<QuicChromiumPacketReader> new_reader( 480 std::unique_ptr<QuicChromiumPacketReader> new_reader(
479 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(), 481 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
480 kQuicYieldAfterPacketsRead, 482 kQuicYieldAfterPacketsRead,
481 QuicTime::Delta::FromMilliseconds( 483 QuicTime::Delta::FromMilliseconds(
482 kQuicYieldAfterDurationMilliseconds), 484 kQuicYieldAfterDurationMilliseconds),
483 bound_net_log_.bound())); 485 bound_net_log_.bound()));
484 std::unique_ptr<QuicPacketWriter> new_writer( 486 std::unique_ptr<QuicPacketWriter> new_writer(
485 CreateQuicPacketWriter(new_socket.get(), session_->connection())); 487 CreateQuicPacketWriter(new_socket.get(), session_->connection()));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 MockWrite(SYNCHRONOUS, ERR_FAILED, 2)}; 520 MockWrite(SYNCHRONOUS, ERR_FAILED, 2)};
519 SequencedSocketData socket_data(reads, arraysize(reads), writes, 521 SequencedSocketData socket_data(reads, arraysize(reads), writes,
520 arraysize(writes)); 522 arraysize(writes));
521 socket_factory_.AddSocketDataProvider(&socket_data); 523 socket_factory_.AddSocketDataProvider(&socket_data);
522 524
523 // Create connected socket. 525 // Create connected socket.
524 std::unique_ptr<DatagramClientSocket> new_socket = 526 std::unique_ptr<DatagramClientSocket> new_socket =
525 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND, 527 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND,
526 base::Bind(&base::RandInt), 528 base::Bind(&base::RandInt),
527 &net_log_, NetLog::Source()); 529 &net_log_, NetLog::Source());
528 EXPECT_EQ(OK, new_socket->Connect(kIpEndPoint)); 530 EXPECT_THAT(new_socket->Connect(kIpEndPoint), IsOk());
529 531
530 // Create reader and writer. 532 // Create reader and writer.
531 std::unique_ptr<QuicChromiumPacketReader> new_reader( 533 std::unique_ptr<QuicChromiumPacketReader> new_reader(
532 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(), 534 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
533 kQuicYieldAfterPacketsRead, 535 kQuicYieldAfterPacketsRead,
534 QuicTime::Delta::FromMilliseconds( 536 QuicTime::Delta::FromMilliseconds(
535 kQuicYieldAfterDurationMilliseconds), 537 kQuicYieldAfterDurationMilliseconds),
536 bound_net_log_.bound())); 538 bound_net_log_.bound()));
537 std::unique_ptr<QuicPacketWriter> new_writer( 539 std::unique_ptr<QuicPacketWriter> new_writer(
538 CreateQuicPacketWriter(new_socket.get(), session_->connection())); 540 CreateQuicPacketWriter(new_socket.get(), session_->connection()));
539 541
540 // Migrate session. 542 // Migrate session.
541 EXPECT_TRUE(session_->MigrateToSocket( 543 EXPECT_TRUE(session_->MigrateToSocket(
542 std::move(new_socket), std::move(new_reader), std::move(new_writer))); 544 std::move(new_socket), std::move(new_reader), std::move(new_writer)));
543 545
544 // Write error on new socket causes session close. 546 // Write error on new socket causes session close.
545 EXPECT_TRUE(session_->connection()->connected()); 547 EXPECT_TRUE(session_->connection()->connected());
546 session_->connection()->SendPing(); 548 session_->connection()->SendPing();
547 EXPECT_FALSE(session_->connection()->connected()); 549 EXPECT_FALSE(session_->connection()->connected());
548 550
549 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 551 EXPECT_TRUE(socket_data.AllReadDataConsumed());
550 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 552 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
551 } 553 }
552 554
553 } // namespace 555 } // namespace
554 } // namespace test 556 } // namespace test
555 } // namespace net 557 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/p2p/quic_p2p_session_test.cc ('k') | net/quic/quic_chromium_client_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698