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 <stddef.h> | 5 #include <stddef.h> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 const char* kBarResponseBody = "Palm hearts are pretty delicious, also."; | 59 const char* kBarResponseBody = "Palm hearts are pretty delicious, also."; |
60 | 60 |
61 void GenerateBody(string* body, int length) { | 61 void GenerateBody(string* body, int length) { |
62 body->clear(); | 62 body->clear(); |
63 body->reserve(length); | 63 body->reserve(length); |
64 for (int i = 0; i < length; ++i) { | 64 for (int i = 0; i < length; ++i) { |
65 body->append(1, static_cast<char>(32 + i % (126 - 32))); | 65 body->append(1, static_cast<char>(32 + i % (126 - 32))); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 // Run all tests with the cross products of all versions | 69 // Run all tests with the cross products of all versions. |
70 // and all values of FLAGS_pad_quic_handshake_packets. | |
71 struct TestParams { | 70 struct TestParams { |
72 TestParams(const QuicVersionVector& client_supported_versions, | 71 TestParams(const QuicVersionVector& client_supported_versions, |
73 const QuicVersionVector& server_supported_versions, | 72 const QuicVersionVector& server_supported_versions, |
74 QuicVersion negotiated_version, | 73 QuicVersion negotiated_version, |
75 bool use_padding, | |
76 bool use_pacing) | 74 bool use_pacing) |
77 : client_supported_versions(client_supported_versions), | 75 : client_supported_versions(client_supported_versions), |
78 server_supported_versions(server_supported_versions), | 76 server_supported_versions(server_supported_versions), |
79 negotiated_version(negotiated_version), | 77 negotiated_version(negotiated_version), |
80 use_padding(use_padding), | |
81 use_pacing(use_pacing) { | 78 use_pacing(use_pacing) { |
82 } | 79 } |
83 | 80 |
84 friend ostream& operator<<(ostream& os, const TestParams& p) { | 81 friend ostream& operator<<(ostream& os, const TestParams& p) { |
85 os << "{ server_supported_versions: " | 82 os << "{ server_supported_versions: " |
86 << QuicVersionVectorToString(p.server_supported_versions); | 83 << QuicVersionVectorToString(p.server_supported_versions); |
87 os << " client_supported_versions: " | 84 os << " client_supported_versions: " |
88 << QuicVersionVectorToString(p.client_supported_versions); | 85 << QuicVersionVectorToString(p.client_supported_versions); |
89 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); | 86 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); |
90 os << " use_padding: " << p.use_padding; | |
91 os << " use_pacing: " << p.use_pacing << " }"; | 87 os << " use_pacing: " << p.use_pacing << " }"; |
92 return os; | 88 return os; |
93 } | 89 } |
94 | 90 |
95 QuicVersionVector client_supported_versions; | 91 QuicVersionVector client_supported_versions; |
96 QuicVersionVector server_supported_versions; | 92 QuicVersionVector server_supported_versions; |
97 QuicVersion negotiated_version; | 93 QuicVersion negotiated_version; |
98 bool use_padding; | |
99 bool use_pacing; | 94 bool use_pacing; |
100 }; | 95 }; |
101 | 96 |
102 // Constructs various test permutations. | 97 // Constructs various test permutations. |
103 vector<TestParams> GetTestParams() { | 98 vector<TestParams> GetTestParams() { |
104 vector<TestParams> params; | 99 vector<TestParams> params; |
105 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | 100 QuicVersionVector all_supported_versions = QuicSupportedVersions(); |
106 | 101 |
107 for (int use_pacing = 0; use_pacing < 2; ++use_pacing) { | 102 for (int use_pacing = 0; use_pacing < 2; ++use_pacing) { |
108 for (int use_padding = 0; use_padding < 2; ++use_padding) { | 103 // Add an entry for server and client supporting all versions. |
109 // Add an entry for server and client supporting all versions. | 104 params.push_back(TestParams(all_supported_versions, |
| 105 all_supported_versions, |
| 106 all_supported_versions[0], |
| 107 use_pacing != 0)); |
| 108 |
| 109 // Test client supporting 1 version and server supporting all versions. |
| 110 // Simulate an old client and exercise version downgrade in the server. |
| 111 // No protocol negotiation should occur. Skip the i = 0 case because it |
| 112 // is essentially the same as the default case. |
| 113 for (size_t i = 1; i < all_supported_versions.size(); ++i) { |
| 114 QuicVersionVector client_supported_versions; |
| 115 client_supported_versions.push_back(all_supported_versions[i]); |
| 116 params.push_back(TestParams(client_supported_versions, |
| 117 all_supported_versions, |
| 118 client_supported_versions[0], |
| 119 use_pacing != 0)); |
| 120 } |
| 121 |
| 122 // Test client supporting all versions and server supporting 1 version. |
| 123 // Simulate an old server and exercise version downgrade in the client. |
| 124 // Protocol negotiation should occur. Skip the i = 0 case because it is |
| 125 // essentially the same as the default case. |
| 126 for (size_t i = 1; i < all_supported_versions.size(); ++i) { |
| 127 QuicVersionVector server_supported_versions; |
| 128 server_supported_versions.push_back(all_supported_versions[i]); |
110 params.push_back(TestParams(all_supported_versions, | 129 params.push_back(TestParams(all_supported_versions, |
111 all_supported_versions, | 130 server_supported_versions, |
112 all_supported_versions[0], | 131 server_supported_versions[0], |
113 use_padding != 0, use_pacing != 0)); | 132 use_pacing != 0)); |
114 | |
115 // Test client supporting 1 version and server supporting all versions. | |
116 // Simulate an old client and exercise version downgrade in the server. | |
117 // No protocol negotiation should occur. Skip the i = 0 case because it | |
118 // is essentially the same as the default case. | |
119 for (size_t i = 1; i < all_supported_versions.size(); ++i) { | |
120 QuicVersionVector client_supported_versions; | |
121 client_supported_versions.push_back(all_supported_versions[i]); | |
122 params.push_back(TestParams(client_supported_versions, | |
123 all_supported_versions, | |
124 client_supported_versions[0], | |
125 use_pacing != 0, use_padding != 0)); | |
126 } | |
127 | |
128 // Test client supporting all versions and server supporting 1 version. | |
129 // Simulate an old server and exercise version downgrade in the client. | |
130 // Protocol negotiation should occur. Skip the i = 0 case because it is | |
131 // essentially the same as the default case. | |
132 for (size_t i = 1; i < all_supported_versions.size(); ++i) { | |
133 QuicVersionVector server_supported_versions; | |
134 server_supported_versions.push_back(all_supported_versions[i]); | |
135 params.push_back(TestParams(all_supported_versions, | |
136 server_supported_versions, | |
137 server_supported_versions[0], | |
138 use_pacing != 0, use_padding != 0)); | |
139 } | |
140 } | 133 } |
141 } | 134 } |
142 return params; | 135 return params; |
143 } | 136 } |
144 | 137 |
145 class EndToEndTest : public ::testing::TestWithParam<TestParams> { | 138 class EndToEndTest : public ::testing::TestWithParam<TestParams> { |
146 protected: | 139 protected: |
147 EndToEndTest() | 140 EndToEndTest() |
148 : server_hostname_("example.com"), | 141 : server_hostname_("example.com"), |
149 server_started_(false), | 142 server_started_(false), |
150 strike_register_no_startup_period_(false) { | 143 strike_register_no_startup_period_(false) { |
151 net::IPAddressNumber ip; | 144 net::IPAddressNumber ip; |
152 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); | 145 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); |
153 server_address_ = IPEndPoint(ip, 0); | 146 server_address_ = IPEndPoint(ip, 0); |
154 | 147 |
155 client_supported_versions_ = GetParam().client_supported_versions; | 148 client_supported_versions_ = GetParam().client_supported_versions; |
156 server_supported_versions_ = GetParam().server_supported_versions; | 149 server_supported_versions_ = GetParam().server_supported_versions; |
157 negotiated_version_ = GetParam().negotiated_version; | 150 negotiated_version_ = GetParam().negotiated_version; |
158 FLAGS_limit_rto_increase_for_tests = true; | 151 FLAGS_limit_rto_increase_for_tests = true; |
159 FLAGS_pad_quic_handshake_packets = GetParam().use_padding; | |
160 FLAGS_enable_quic_pacing = GetParam().use_pacing; | 152 FLAGS_enable_quic_pacing = GetParam().use_pacing; |
161 LOG(INFO) << "Using Configuration: " << GetParam(); | 153 LOG(INFO) << "Using Configuration: " << GetParam(); |
162 | 154 |
163 client_config_.SetDefaults(); | 155 client_config_.SetDefaults(); |
164 server_config_.SetDefaults(); | 156 server_config_.SetDefaults(); |
165 server_config_.set_initial_round_trip_time_us(kMaxInitialRoundTripTimeUs, | 157 server_config_.set_initial_round_trip_time_us(kMaxInitialRoundTripTimeUs, |
166 0); | 158 0); |
167 | 159 |
168 QuicInMemoryCachePeer::ResetForTests(); | 160 QuicInMemoryCachePeer::ResetForTests(); |
169 AddToCache("GET", "https://www.google.com/foo", | 161 AddToCache("GET", "https://www.google.com/foo", |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 string body; | 548 string body; |
557 GenerateBody(&body, 1024 * 1024); | 549 GenerateBody(&body, 1024 * 1024); |
558 | 550 |
559 HTTPMessage request(HttpConstants::HTTP_1_1, | 551 HTTPMessage request(HttpConstants::HTTP_1_1, |
560 HttpConstants::POST, "/foo"); | 552 HttpConstants::POST, "/foo"); |
561 request.AddBody(body, true); | 553 request.AddBody(body, true); |
562 | 554 |
563 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 555 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
564 } | 556 } |
565 | 557 |
566 // Enable once FLAGS_quic_allow_oversized_packets_for_test is added. | |
567 TEST_P(EndToEndTest, DISABLED_PacketTooLarge) { | |
568 //FLAGS_quic_allow_oversized_packets_for_test = true; | |
569 ASSERT_TRUE(Initialize()); | |
570 | |
571 // Wait for the handshake to be confirmed so that the negotiated | |
572 // max packet size does not overwrite our increased packet size. | |
573 client_->client()->WaitForCryptoHandshakeConfirmed(); | |
574 | |
575 // If we use packet padding, then the CHLO is padded to such a large | |
576 // size that it is rejected by the server before the handshake can complete | |
577 // which results in a test timeout. | |
578 if (FLAGS_pad_quic_handshake_packets) { | |
579 return; | |
580 } | |
581 | |
582 string body; | |
583 GenerateBody(&body, kMaxPacketSize); | |
584 | |
585 HTTPMessage request(HttpConstants::HTTP_1_1, | |
586 HttpConstants::POST, "/foo"); | |
587 request.AddBody(body, true); | |
588 client_->options()->max_packet_length = 20480; | |
589 | |
590 EXPECT_EQ("", client_->SendCustomSynchronousRequest(request)); | |
591 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | |
592 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, client_->connection_error()); | |
593 } | |
594 | |
595 TEST_P(EndToEndTest, InvalidStream) { | 558 TEST_P(EndToEndTest, InvalidStream) { |
596 ASSERT_TRUE(Initialize()); | 559 ASSERT_TRUE(Initialize()); |
597 client_->client()->WaitForCryptoHandshakeConfirmed(); | 560 client_->client()->WaitForCryptoHandshakeConfirmed(); |
598 | 561 |
599 string body; | 562 string body; |
600 GenerateBody(&body, kMaxPacketSize); | 563 GenerateBody(&body, kMaxPacketSize); |
601 | 564 |
602 HTTPMessage request(HttpConstants::HTTP_1_1, | 565 HTTPMessage request(HttpConstants::HTTP_1_1, |
603 HttpConstants::POST, "/foo"); | 566 HttpConstants::POST, "/foo"); |
604 request.AddBody(body, true); | 567 request.AddBody(body, true); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 client_->SendSynchronousRequest("/bar"); | 810 client_->SendSynchronousRequest("/bar"); |
848 | 811 |
849 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 812 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
850 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 813 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
851 } | 814 } |
852 | 815 |
853 } // namespace | 816 } // namespace |
854 } // namespace test | 817 } // namespace test |
855 } // namespace tools | 818 } // namespace tools |
856 } // namespace net | 819 } // namespace net |
OLD | NEW |