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

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

Issue 1893083002: Change scoped_ptr to std::unique_ptr in //net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-net-all: iwyu Created 4 years, 8 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/tools/net_watcher/net_watcher.cc ('k') | net/tools/quic/quic_client.h » ('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 <stddef.h> 5 #include <stddef.h>
6 #include <sys/epoll.h> 6 #include <sys/epoll.h>
7 7
8 #include <list> 8 #include <list>
9 #include <memory>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "net/base/ip_address.h" 18 #include "net/base/ip_address.h"
19 #include "net/base/ip_endpoint.h" 19 #include "net/base/ip_endpoint.h"
20 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 20 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
21 #include "net/quic/crypto/null_encrypter.h" 21 #include "net/quic/crypto/null_encrypter.h"
22 #include "net/quic/quic_client_session_base.h" 22 #include "net/quic/quic_client_session_base.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 500 }
501 501
502 // Must be called before Initialize to have effect. 502 // Must be called before Initialize to have effect.
503 void SetSpdyStreamFactory(QuicTestServer::StreamFactory* factory) { 503 void SetSpdyStreamFactory(QuicTestServer::StreamFactory* factory) {
504 stream_factory_ = factory; 504 stream_factory_ = factory;
505 } 505 }
506 506
507 bool initialized_; 507 bool initialized_;
508 IPEndPoint server_address_; 508 IPEndPoint server_address_;
509 string server_hostname_; 509 string server_hostname_;
510 scoped_ptr<ServerThread> server_thread_; 510 std::unique_ptr<ServerThread> server_thread_;
511 scoped_ptr<QuicTestClient> client_; 511 std::unique_ptr<QuicTestClient> client_;
512 PacketDroppingTestWriter* client_writer_; 512 PacketDroppingTestWriter* client_writer_;
513 PacketDroppingTestWriter* server_writer_; 513 PacketDroppingTestWriter* server_writer_;
514 bool server_started_; 514 bool server_started_;
515 QuicConfig client_config_; 515 QuicConfig client_config_;
516 QuicConfig server_config_; 516 QuicConfig server_config_;
517 QuicVersionVector client_supported_versions_; 517 QuicVersionVector client_supported_versions_;
518 QuicVersionVector server_supported_versions_; 518 QuicVersionVector server_supported_versions_;
519 QuicVersion negotiated_version_; 519 QuicVersion negotiated_version_;
520 bool strike_register_no_startup_period_; 520 bool strike_register_no_startup_period_;
521 size_t chlo_multiplier_; 521 size_t chlo_multiplier_;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 ASSERT_TRUE(Initialize()); 581 ASSERT_TRUE(Initialize());
582 582
583 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 583 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
584 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 584 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
585 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); 585 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar"));
586 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 586 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
587 } 587 }
588 588
589 TEST_P(EndToEndTest, MultipleClients) { 589 TEST_P(EndToEndTest, MultipleClients) {
590 ASSERT_TRUE(Initialize()); 590 ASSERT_TRUE(Initialize());
591 scoped_ptr<QuicTestClient> client2(CreateQuicClient(nullptr)); 591 std::unique_ptr<QuicTestClient> client2(CreateQuicClient(nullptr));
592 592
593 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); 593 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo");
594 request.AddHeader("content-length", "3"); 594 request.AddHeader("content-length", "3");
595 request.set_has_complete_message(false); 595 request.set_has_complete_message(false);
596 596
597 client_->SendMessage(request); 597 client_->SendMessage(request);
598 client2->SendMessage(request); 598 client2->SendMessage(request);
599 599
600 client_->SendData("bar", true); 600 client_->SendData("bar", true);
601 client_->WaitForResponse(); 601 client_->WaitForResponse();
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 // Send the public reset. 1731 // Send the public reset.
1732 QuicConnectionId incorrect_connection_id = 1732 QuicConnectionId incorrect_connection_id =
1733 client_->client()->session()->connection()->connection_id() + 1; 1733 client_->client()->session()->connection()->connection_id() + 1;
1734 QuicPublicResetPacket header; 1734 QuicPublicResetPacket header;
1735 header.public_header.connection_id = incorrect_connection_id; 1735 header.public_header.connection_id = incorrect_connection_id;
1736 header.public_header.reset_flag = true; 1736 header.public_header.reset_flag = true;
1737 header.public_header.version_flag = false; 1737 header.public_header.version_flag = false;
1738 header.rejected_packet_number = 10101; 1738 header.rejected_packet_number = 10101;
1739 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), 1739 QuicFramer framer(server_supported_versions_, QuicTime::Zero(),
1740 Perspective::IS_SERVER); 1740 Perspective::IS_SERVER);
1741 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); 1741 std::unique_ptr<QuicEncryptedPacket> packet(
1742 framer.BuildPublicResetPacket(header));
1742 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; 1743 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor;
1743 client_->client()->session()->connection()->set_debug_visitor(&visitor); 1744 client_->client()->session()->connection()->set_debug_visitor(&visitor);
1744 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) 1745 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id))
1745 .Times(1); 1746 .Times(1);
1746 // We must pause the server's thread in order to call WritePacket without 1747 // We must pause the server's thread in order to call WritePacket without
1747 // race conditions. 1748 // race conditions.
1748 server_thread_->Pause(); 1749 server_thread_->Pause();
1749 server_writer_->WritePacket( 1750 server_writer_->WritePacket(
1750 packet->data(), packet->length(), server_address_.address(), 1751 packet->data(), packet->length(), server_address_.address(),
1751 client_->client()->GetLatestClientAddress(), nullptr); 1752 client_->client()->GetLatestClientAddress(), nullptr);
(...skipping 14 matching lines...) Expand all
1766 // Send the public reset. 1767 // Send the public reset.
1767 QuicConnectionId incorrect_connection_id = 1768 QuicConnectionId incorrect_connection_id =
1768 client_->client()->session()->connection()->connection_id() + 1; 1769 client_->client()->session()->connection()->connection_id() + 1;
1769 QuicPublicResetPacket header; 1770 QuicPublicResetPacket header;
1770 header.public_header.connection_id = incorrect_connection_id; 1771 header.public_header.connection_id = incorrect_connection_id;
1771 header.public_header.reset_flag = true; 1772 header.public_header.reset_flag = true;
1772 header.public_header.version_flag = false; 1773 header.public_header.version_flag = false;
1773 header.rejected_packet_number = 10101; 1774 header.rejected_packet_number = 10101;
1774 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), 1775 QuicFramer framer(server_supported_versions_, QuicTime::Zero(),
1775 Perspective::IS_CLIENT); 1776 Perspective::IS_CLIENT);
1776 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); 1777 std::unique_ptr<QuicEncryptedPacket> packet(
1778 framer.BuildPublicResetPacket(header));
1777 client_writer_->WritePacket( 1779 client_writer_->WritePacket(
1778 packet->data(), packet->length(), 1780 packet->data(), packet->length(),
1779 client_->client()->GetLatestClientAddress().address(), server_address_, 1781 client_->client()->GetLatestClientAddress().address(), server_address_,
1780 nullptr); 1782 nullptr);
1781 1783
1782 // The connection should be unaffected. 1784 // The connection should be unaffected.
1783 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 1785 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
1784 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1786 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
1785 } 1787 }
1786 1788
1787 // Send a version negotiation packet from the server for a different 1789 // Send a version negotiation packet from the server for a different
1788 // connection ID. It should be ignored. 1790 // connection ID. It should be ignored.
1789 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { 1791 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) {
1790 ASSERT_TRUE(Initialize()); 1792 ASSERT_TRUE(Initialize());
1791 1793
1792 // Send the version negotiation packet. 1794 // Send the version negotiation packet.
1793 QuicConnectionId incorrect_connection_id = 1795 QuicConnectionId incorrect_connection_id =
1794 client_->client()->session()->connection()->connection_id() + 1; 1796 client_->client()->session()->connection()->connection_id() + 1;
1795 scoped_ptr<QuicEncryptedPacket> packet( 1797 std::unique_ptr<QuicEncryptedPacket> packet(
1796 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, 1798 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id,
1797 server_supported_versions_)); 1799 server_supported_versions_));
1798 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; 1800 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor;
1799 client_->client()->session()->connection()->set_debug_visitor(&visitor); 1801 client_->client()->session()->connection()->set_debug_visitor(&visitor);
1800 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) 1802 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id))
1801 .Times(1); 1803 .Times(1);
1802 // We must pause the server's thread in order to call WritePacket without 1804 // We must pause the server's thread in order to call WritePacket without
1803 // race conditions. 1805 // race conditions.
1804 server_thread_->Pause(); 1806 server_thread_->Pause();
1805 server_writer_->WritePacket( 1807 server_writer_->WritePacket(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 1890
1889 // Send a packet from the client with bad encrypted data. The server should not 1891 // Send a packet from the client with bad encrypted data. The server should not
1890 // tear down the connection. 1892 // tear down the connection.
1891 TEST_P(EndToEndTest, BadEncryptedData) { 1893 TEST_P(EndToEndTest, BadEncryptedData) {
1892 ASSERT_TRUE(Initialize()); 1894 ASSERT_TRUE(Initialize());
1893 1895
1894 // Start the connection. 1896 // Start the connection.
1895 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 1897 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
1896 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1898 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
1897 1899
1898 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( 1900 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
1899 client_->client()->session()->connection()->connection_id(), false, false, 1901 client_->client()->session()->connection()->connection_id(), false, false,
1900 false, kDefaultPathId, 1, "At least 20 characters.", 1902 false, kDefaultPathId, 1, "At least 20 characters.",
1901 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER)); 1903 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER));
1902 // Damage the encrypted data. 1904 // Damage the encrypted data.
1903 string damaged_packet(packet->data(), packet->length()); 1905 string damaged_packet(packet->data(), packet->length());
1904 damaged_packet[30] ^= 0x01; 1906 damaged_packet[30] ^= 0x01;
1905 DVLOG(1) << "Sending bad packet."; 1907 DVLOG(1) << "Sending bad packet.";
1906 client_writer_->WritePacket( 1908 client_writer_->WritePacket(
1907 damaged_packet.data(), damaged_packet.length(), 1909 damaged_packet.data(), damaged_packet.length(),
1908 client_->client()->GetLatestClientAddress().address(), server_address_, 1910 client_->client()->GetLatestClientAddress().address(), server_address_,
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
2608 client_->client()->WaitForCryptoHandshakeConfirmed(); 2610 client_->client()->WaitForCryptoHandshakeConfirmed();
2609 SetPacketLossPercentage(1); 2611 SetPacketLossPercentage(1);
2610 client_->SendRequest("/huge_response"); 2612 client_->SendRequest("/huge_response");
2611 client_->WaitForResponse(); 2613 client_->WaitForResponse();
2612 VerifyCleanConnection(false); 2614 VerifyCleanConnection(false);
2613 } 2615 }
2614 2616
2615 } // namespace 2617 } // namespace
2616 } // namespace test 2618 } // namespace test
2617 } // namespace net 2619 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/net_watcher/net_watcher.cc ('k') | net/tools/quic/quic_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698