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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 client_config_.SetInitialStreamFlowControlWindowToSend( | 205 client_config_.SetInitialStreamFlowControlWindowToSend( |
206 2 * kInitialStreamFlowControlWindowForTest); | 206 2 * kInitialStreamFlowControlWindowForTest); |
207 client_config_.SetInitialSessionFlowControlWindowToSend( | 207 client_config_.SetInitialSessionFlowControlWindowToSend( |
208 2 * kInitialSessionFlowControlWindowForTest); | 208 2 * kInitialSessionFlowControlWindowForTest); |
209 server_config_.SetInitialStreamFlowControlWindowToSend( | 209 server_config_.SetInitialStreamFlowControlWindowToSend( |
210 3 * kInitialStreamFlowControlWindowForTest); | 210 3 * kInitialStreamFlowControlWindowForTest); |
211 server_config_.SetInitialSessionFlowControlWindowToSend( | 211 server_config_.SetInitialSessionFlowControlWindowToSend( |
212 3 * kInitialSessionFlowControlWindowForTest); | 212 3 * kInitialSessionFlowControlWindowForTest); |
213 | 213 |
214 QuicInMemoryCachePeer::ResetForTests(); | 214 QuicInMemoryCachePeer::ResetForTests(); |
215 AddToCache("GET", "https://www.google.com/foo", | 215 AddToCache("/foo", 200, "OK", kFooResponseBody); |
216 "HTTP/1.1", "200", "OK", kFooResponseBody); | 216 AddToCache("/bar", 200, "OK", kBarResponseBody); |
217 AddToCache("GET", "https://www.google.com/bar", | |
218 "HTTP/1.1", "200", "OK", kBarResponseBody); | |
219 } | 217 } |
220 | 218 |
221 ~EndToEndTest() override { | 219 ~EndToEndTest() override { |
222 // TODO(rtenneti): port RecycleUnusedPort if needed. | 220 // TODO(rtenneti): port RecycleUnusedPort if needed. |
223 // RecycleUnusedPort(server_address_.port()); | 221 // RecycleUnusedPort(server_address_.port()); |
224 QuicInMemoryCachePeer::ResetForTests(); | 222 QuicInMemoryCachePeer::ResetForTests(); |
225 } | 223 } |
226 | 224 |
227 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { | 225 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { |
228 QuicTestClient* client = new QuicTestClient( | 226 QuicTestClient* client = new QuicTestClient( |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 334 |
337 void StopServer() { | 335 void StopServer() { |
338 if (!server_started_) | 336 if (!server_started_) |
339 return; | 337 return; |
340 if (server_thread_.get()) { | 338 if (server_thread_.get()) { |
341 server_thread_->Quit(); | 339 server_thread_->Quit(); |
342 server_thread_->Join(); | 340 server_thread_->Join(); |
343 } | 341 } |
344 } | 342 } |
345 | 343 |
346 void AddToCache(StringPiece method, | 344 void AddToCache(StringPiece path, |
347 StringPiece path, | 345 int response_code, |
348 StringPiece version, | |
349 StringPiece response_code, | |
350 StringPiece response_detail, | 346 StringPiece response_detail, |
351 StringPiece body) { | 347 StringPiece body) { |
352 QuicInMemoryCache::GetInstance()->AddSimpleResponse( | 348 QuicInMemoryCache::GetInstance()->AddSimpleResponse( |
353 method, path, version, response_code, response_detail, body); | 349 "www.google.com", path, response_code, response_detail, body); |
354 } | 350 } |
355 | 351 |
356 void SetPacketLossPercentage(int32 loss) { | 352 void SetPacketLossPercentage(int32 loss) { |
357 // TODO(rtenneti): enable when we can do random packet loss tests in | 353 // TODO(rtenneti): enable when we can do random packet loss tests in |
358 // chrome's tree. | 354 // chrome's tree. |
359 if (loss != 0 && loss != 100) | 355 if (loss != 0 && loss != 100) |
360 return; | 356 return; |
361 client_writer_->set_fake_packet_loss_percentage(loss); | 357 client_writer_->set_fake_packet_loss_percentage(loss); |
362 server_writer_->set_fake_packet_loss_percentage(loss); | 358 server_writer_->set_fake_packet_loss_percentage(loss); |
363 } | 359 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 491 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
496 | 492 |
497 client2->SendData("eep", true); | 493 client2->SendData("eep", true); |
498 client2->WaitForResponse(); | 494 client2->WaitForResponse(); |
499 EXPECT_EQ(kFooResponseBody, client2->response_body()); | 495 EXPECT_EQ(kFooResponseBody, client2->response_body()); |
500 EXPECT_EQ(200u, client2->response_headers()->parsed_response_code()); | 496 EXPECT_EQ(200u, client2->response_headers()->parsed_response_code()); |
501 } | 497 } |
502 | 498 |
503 TEST_P(EndToEndTest, RequestOverMultiplePackets) { | 499 TEST_P(EndToEndTest, RequestOverMultiplePackets) { |
504 // Send a large enough request to guarantee fragmentation. | 500 // Send a large enough request to guarantee fragmentation. |
505 string huge_request = | 501 string huge_request = "/some/path?query=" + string(kMaxPacketSize, '.'); |
506 "https://www.google.com/some/path?query=" + string(kMaxPacketSize, '.'); | 502 AddToCache(huge_request, 200, "OK", kBarResponseBody); |
507 AddToCache("GET", huge_request, "HTTP/1.1", "200", "OK", kBarResponseBody); | |
508 | 503 |
509 ASSERT_TRUE(Initialize()); | 504 ASSERT_TRUE(Initialize()); |
510 | 505 |
511 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); | 506 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); |
512 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 507 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
513 } | 508 } |
514 | 509 |
515 TEST_P(EndToEndTest, MultiplePacketsRandomOrder) { | 510 TEST_P(EndToEndTest, MultiplePacketsRandomOrder) { |
516 // Send a large enough request to guarantee fragmentation. | 511 // Send a large enough request to guarantee fragmentation. |
517 string huge_request = | 512 string huge_request = "/some/path?query=" + string(kMaxPacketSize, '.'); |
518 "https://www.google.com/some/path?query=" + string(kMaxPacketSize, '.'); | 513 AddToCache(huge_request, 200, "OK", kBarResponseBody); |
519 AddToCache("GET", huge_request, "HTTP/1.1", "200", "OK", kBarResponseBody); | |
520 | 514 |
521 ASSERT_TRUE(Initialize()); | 515 ASSERT_TRUE(Initialize()); |
522 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 516 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
523 SetReorderPercentage(50); | 517 SetReorderPercentage(50); |
524 | 518 |
525 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); | 519 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); |
526 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 520 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
527 } | 521 } |
528 | 522 |
529 TEST_P(EndToEndTest, PostMissingBytes) { | 523 TEST_P(EndToEndTest, PostMissingBytes) { |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1055 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
1062 } | 1056 } |
1063 | 1057 |
1064 TEST_P(EndToEndTest, MaxStreamsUberTest) { | 1058 TEST_P(EndToEndTest, MaxStreamsUberTest) { |
1065 SetPacketLossPercentage(1); | 1059 SetPacketLossPercentage(1); |
1066 ASSERT_TRUE(Initialize()); | 1060 ASSERT_TRUE(Initialize()); |
1067 string large_body; | 1061 string large_body; |
1068 GenerateBody(&large_body, 10240); | 1062 GenerateBody(&large_body, 10240); |
1069 int max_streams = 100; | 1063 int max_streams = 100; |
1070 | 1064 |
1071 AddToCache("GET", "/large_response", "HTTP/1.1", "200", "OK", large_body);; | 1065 AddToCache("/large_response", 200, "OK", large_body);; |
1072 | 1066 |
1073 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1067 client_->client()->WaitForCryptoHandshakeConfirmed(); |
1074 SetPacketLossPercentage(10); | 1068 SetPacketLossPercentage(10); |
1075 | 1069 |
1076 for (int i = 0; i < max_streams; ++i) { | 1070 for (int i = 0; i < max_streams; ++i) { |
1077 EXPECT_LT(0, client_->SendRequest("/large_response")); | 1071 EXPECT_LT(0, client_->SendRequest("/large_response")); |
1078 } | 1072 } |
1079 | 1073 |
1080 // WaitForEvents waits 50ms and returns true if there are outstanding | 1074 // WaitForEvents waits 50ms and returns true if there are outstanding |
1081 // requests. | 1075 // requests. |
1082 while (client_->client()->WaitForEvents() == true) { | 1076 while (client_->client()->WaitForEvents() == true) { |
1083 } | 1077 } |
1084 } | 1078 } |
1085 | 1079 |
1086 TEST_P(EndToEndTest, StreamCancelErrorTest) { | 1080 TEST_P(EndToEndTest, StreamCancelErrorTest) { |
1087 ASSERT_TRUE(Initialize()); | 1081 ASSERT_TRUE(Initialize()); |
1088 string small_body; | 1082 string small_body; |
1089 GenerateBody(&small_body, 256); | 1083 GenerateBody(&small_body, 256); |
1090 | 1084 |
1091 AddToCache("GET", "/small_response", "HTTP/1.1", "200", "OK", small_body); | 1085 AddToCache("/small_response", 200, "OK", small_body); |
1092 | 1086 |
1093 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1087 client_->client()->WaitForCryptoHandshakeConfirmed(); |
1094 | 1088 |
1095 QuicSession* session = client_->client()->session(); | 1089 QuicSession* session = client_->client()->session(); |
1096 // Lose the request. | 1090 // Lose the request. |
1097 SetPacketLossPercentage(100); | 1091 SetPacketLossPercentage(100); |
1098 EXPECT_LT(0, client_->SendRequest("/small_response")); | 1092 EXPECT_LT(0, client_->SendRequest("/small_response")); |
1099 client_->client()->WaitForEvents(); | 1093 client_->client()->WaitForEvents(); |
1100 // Transmit the cancel, and ensure the connection is torn down properly. | 1094 // Transmit the cancel, and ensure the connection is torn down properly. |
1101 SetPacketLossPercentage(0); | 1095 SetPacketLossPercentage(0); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 // Waits for up to 50 ms. | 1393 // Waits for up to 50 ms. |
1400 client_->client()->WaitForEvents(); | 1394 client_->client()->WaitForEvents(); |
1401 } | 1395 } |
1402 server_thread_->Resume(); | 1396 server_thread_->Resume(); |
1403 } | 1397 } |
1404 | 1398 |
1405 } // namespace | 1399 } // namespace |
1406 } // namespace test | 1400 } // namespace test |
1407 } // namespace tools | 1401 } // namespace tools |
1408 } // namespace net | 1402 } // namespace net |
OLD | NEW |