| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <memory> | 5 #include <memory> |
| 6 #include <ostream> | 6 #include <ostream> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void InitializePostRequest(size_t length) { | 212 void InitializePostRequest(size_t length) { |
| 213 GenerateBody(length); | 213 GenerateBody(length); |
| 214 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 214 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 215 element_readers.push_back(base::MakeUnique<UploadBytesElementReader>( | 215 element_readers.push_back(base::MakeUnique<UploadBytesElementReader>( |
| 216 request_body_.data(), request_body_.length())); | 216 request_body_.data(), request_body_.length())); |
| 217 upload_data_stream_.reset( | 217 upload_data_stream_.reset( |
| 218 new ElementsUploadDataStream(std::move(element_readers), 0)); | 218 new ElementsUploadDataStream(std::move(element_readers), 0)); |
| 219 request_.method = "POST"; | 219 request_.method = "POST"; |
| 220 request_.url = GURL("https://test.example.com/"); | 220 request_.url = GURL("https://test.example.com/"); |
| 221 request_.upload_data_stream = upload_data_stream_.get(); | 221 request_.upload_data_stream = upload_data_stream_.get(); |
| 222 ASSERT_THAT( | 222 ASSERT_THAT(request_.upload_data_stream->Init(CompletionCallback(), |
| 223 request_.upload_data_stream->Init(CompletionCallback(), BoundNetLog()), | 223 NetLogWithSource()), |
| 224 IsOk()); | 224 IsOk()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Checks that |consumer| completed and received |status_line| and |body|. | 227 // Checks that |consumer| completed and received |status_line| and |body|. |
| 228 void CheckResponse(const TestTransactionConsumer& consumer, | 228 void CheckResponse(const TestTransactionConsumer& consumer, |
| 229 const std::string& status_line, | 229 const std::string& status_line, |
| 230 const std::string& body) { | 230 const std::string& body) { |
| 231 ASSERT_TRUE(consumer.is_done()); | 231 ASSERT_TRUE(consumer.is_done()); |
| 232 ASSERT_THAT(consumer.error(), IsOk()); | 232 ASSERT_THAT(consumer.error(), IsOk()); |
| 233 EXPECT_EQ(status_line, consumer.response_info()->headers->GetStatusLine()); | 233 EXPECT_EQ(status_line, consumer.response_info()->headers->GetStatusLine()); |
| 234 EXPECT_EQ(body, consumer.content()); | 234 EXPECT_EQ(body, consumer.content()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 263 QuicEndToEndTest, | 263 QuicEndToEndTest, |
| 264 ::testing::ValuesIn(GetTestParams())); | 264 ::testing::ValuesIn(GetTestParams())); |
| 265 | 265 |
| 266 TEST_P(QuicEndToEndTest, LargeGetWithNoPacketLoss) { | 266 TEST_P(QuicEndToEndTest, LargeGetWithNoPacketLoss) { |
| 267 std::string response(10 * 1024, 'x'); | 267 std::string response(10 * 1024, 'x'); |
| 268 | 268 |
| 269 AddToCache(request_.url.PathForRequest(), 200, "OK", response); | 269 AddToCache(request_.url.PathForRequest(), 200, "OK", response); |
| 270 | 270 |
| 271 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 271 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
| 272 transaction_factory_.get()); | 272 transaction_factory_.get()); |
| 273 consumer.Start(&request_, BoundNetLog()); | 273 consumer.Start(&request_, NetLogWithSource()); |
| 274 | 274 |
| 275 // Will terminate when the last consumer completes. | 275 // Will terminate when the last consumer completes. |
| 276 base::RunLoop().Run(); | 276 base::RunLoop().Run(); |
| 277 | 277 |
| 278 CheckResponse(consumer, "HTTP/1.1 200", response); | 278 CheckResponse(consumer, "HTTP/1.1 200", response); |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST_P(QuicEndToEndTest, TokenBinding) { | 281 TEST_P(QuicEndToEndTest, TokenBinding) { |
| 282 // Enable token binding and re-initialize the TestTransactionFactory. | 282 // Enable token binding and re-initialize the TestTransactionFactory. |
| 283 params_.enable_token_binding = true; | 283 params_.enable_token_binding = true; |
| 284 transaction_factory_.reset(new TestTransactionFactory(params_)); | 284 transaction_factory_.reset(new TestTransactionFactory(params_)); |
| 285 | 285 |
| 286 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); | 286 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
| 287 | 287 |
| 288 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 288 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
| 289 transaction_factory_.get()); | 289 transaction_factory_.get()); |
| 290 consumer.Start(&request_, BoundNetLog()); | 290 consumer.Start(&request_, NetLogWithSource()); |
| 291 | 291 |
| 292 // Will terminate when the last consumer completes. | 292 // Will terminate when the last consumer completes. |
| 293 base::RunLoop().Run(); | 293 base::RunLoop().Run(); |
| 294 | 294 |
| 295 CheckResponse(consumer, "HTTP/1.1 200", kResponseBody); | 295 CheckResponse(consumer, "HTTP/1.1 200", kResponseBody); |
| 296 HttpRequestHeaders headers; | 296 HttpRequestHeaders headers; |
| 297 ASSERT_TRUE(consumer.transaction()->GetFullRequestHeaders(&headers)); | 297 ASSERT_TRUE(consumer.transaction()->GetFullRequestHeaders(&headers)); |
| 298 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 298 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 299 } | 299 } |
| 300 | 300 |
| 301 // crbug.com/559173 | 301 // crbug.com/559173 |
| 302 #if defined(THREAD_SANITIZER) | 302 #if defined(THREAD_SANITIZER) |
| 303 TEST_P(QuicEndToEndTest, DISABLED_LargePostWithNoPacketLoss) { | 303 TEST_P(QuicEndToEndTest, DISABLED_LargePostWithNoPacketLoss) { |
| 304 #else | 304 #else |
| 305 TEST_P(QuicEndToEndTest, LargePostWithNoPacketLoss) { | 305 TEST_P(QuicEndToEndTest, LargePostWithNoPacketLoss) { |
| 306 #endif | 306 #endif |
| 307 InitializePostRequest(1024 * 1024); | 307 InitializePostRequest(1024 * 1024); |
| 308 | 308 |
| 309 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); | 309 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
| 310 | 310 |
| 311 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 311 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
| 312 transaction_factory_.get()); | 312 transaction_factory_.get()); |
| 313 consumer.Start(&request_, BoundNetLog()); | 313 consumer.Start(&request_, NetLogWithSource()); |
| 314 | 314 |
| 315 // Will terminate when the last consumer completes. | 315 // Will terminate when the last consumer completes. |
| 316 base::RunLoop().Run(); | 316 base::RunLoop().Run(); |
| 317 | 317 |
| 318 CheckResponse(consumer, "HTTP/1.1 200", kResponseBody); | 318 CheckResponse(consumer, "HTTP/1.1 200", kResponseBody); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // crbug.com/559173 | 321 // crbug.com/559173 |
| 322 #if defined(THREAD_SANITIZER) | 322 #if defined(THREAD_SANITIZER) |
| 323 TEST_P(QuicEndToEndTest, DISABLED_LargePostWithPacketLoss) { | 323 TEST_P(QuicEndToEndTest, DISABLED_LargePostWithPacketLoss) { |
| 324 #else | 324 #else |
| 325 TEST_P(QuicEndToEndTest, LargePostWithPacketLoss) { | 325 TEST_P(QuicEndToEndTest, LargePostWithPacketLoss) { |
| 326 #endif | 326 #endif |
| 327 // FLAGS_fake_packet_loss_percentage = 30; | 327 // FLAGS_fake_packet_loss_percentage = 30; |
| 328 InitializePostRequest(1024 * 1024); | 328 InitializePostRequest(1024 * 1024); |
| 329 | 329 |
| 330 const char kResponseBody[] = "some really big response body"; | 330 const char kResponseBody[] = "some really big response body"; |
| 331 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); | 331 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
| 332 | 332 |
| 333 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 333 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
| 334 transaction_factory_.get()); | 334 transaction_factory_.get()); |
| 335 consumer.Start(&request_, BoundNetLog()); | 335 consumer.Start(&request_, NetLogWithSource()); |
| 336 | 336 |
| 337 // Will terminate when the last consumer completes. | 337 // Will terminate when the last consumer completes. |
| 338 base::RunLoop().Run(); | 338 base::RunLoop().Run(); |
| 339 | 339 |
| 340 CheckResponse(consumer, "HTTP/1.1 200", kResponseBody); | 340 CheckResponse(consumer, "HTTP/1.1 200", kResponseBody); |
| 341 } | 341 } |
| 342 | 342 |
| 343 // crbug.com/536845 | 343 // crbug.com/536845 |
| 344 #if defined(THREAD_SANITIZER) | 344 #if defined(THREAD_SANITIZER) |
| 345 TEST_P(QuicEndToEndTest, DISABLED_UberTest) { | 345 TEST_P(QuicEndToEndTest, DISABLED_UberTest) { |
| 346 #else | 346 #else |
| 347 TEST_P(QuicEndToEndTest, UberTest) { | 347 TEST_P(QuicEndToEndTest, UberTest) { |
| 348 #endif | 348 #endif |
| 349 // FLAGS_fake_packet_loss_percentage = 30; | 349 // FLAGS_fake_packet_loss_percentage = 30; |
| 350 | 350 |
| 351 const char kResponseBody[] = "some really big response body"; | 351 const char kResponseBody[] = "some really big response body"; |
| 352 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); | 352 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
| 353 | 353 |
| 354 std::vector<TestTransactionConsumer*> consumers; | 354 std::vector<TestTransactionConsumer*> consumers; |
| 355 size_t num_requests = 100; | 355 size_t num_requests = 100; |
| 356 for (size_t i = 0; i < num_requests; ++i) { | 356 for (size_t i = 0; i < num_requests; ++i) { |
| 357 TestTransactionConsumer* consumer = new TestTransactionConsumer( | 357 TestTransactionConsumer* consumer = new TestTransactionConsumer( |
| 358 DEFAULT_PRIORITY, transaction_factory_.get()); | 358 DEFAULT_PRIORITY, transaction_factory_.get()); |
| 359 consumers.push_back(consumer); | 359 consumers.push_back(consumer); |
| 360 consumer->Start(&request_, BoundNetLog()); | 360 consumer->Start(&request_, NetLogWithSource()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 // Will terminate when the last consumer completes. | 363 // Will terminate when the last consumer completes. |
| 364 base::RunLoop().Run(); | 364 base::RunLoop().Run(); |
| 365 | 365 |
| 366 for (size_t i = 0; i < num_requests; ++i) { | 366 for (size_t i = 0; i < num_requests; ++i) { |
| 367 CheckResponse(*consumers[i], "HTTP/1.1 200", kResponseBody); | 367 CheckResponse(*consumers[i], "HTTP/1.1 200", kResponseBody); |
| 368 } | 368 } |
| 369 base::STLDeleteElements(&consumers); | 369 base::STLDeleteElements(&consumers); |
| 370 } | 370 } |
| 371 | 371 |
| 372 } // namespace test | 372 } // namespace test |
| 373 } // namespace net | 373 } // namespace net |
| OLD | NEW |