| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 3285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3296 ASSERT_EQ(1, d.response_started_count()) | 3296 ASSERT_EQ(1, d.response_started_count()) |
| 3297 << "request failed: " << r->status().status() | 3297 << "request failed: " << r->status().status() |
| 3298 << ", os error: " << r->status().error(); | 3298 << ", os error: " << r->status().error(); |
| 3299 | 3299 |
| 3300 EXPECT_FALSE(d.received_data_before_response()); | 3300 EXPECT_FALSE(d.received_data_before_response()); |
| 3301 EXPECT_EQ(uploadBytes, d.data_received()); | 3301 EXPECT_EQ(uploadBytes, d.data_received()); |
| 3302 } | 3302 } |
| 3303 delete[] uploadBytes; | 3303 delete[] uploadBytes; |
| 3304 } | 3304 } |
| 3305 | 3305 |
| 3306 void AddChunksToUpload(URLRequest* r) { | |
| 3307 r->AppendChunkToUpload("a", 1, false); | |
| 3308 r->AppendChunkToUpload("bcd", 3, false); | |
| 3309 r->AppendChunkToUpload("this is a longer chunk than before.", 35, false); | |
| 3310 r->AppendChunkToUpload("\r\n\r\n", 4, false); | |
| 3311 r->AppendChunkToUpload("0", 1, false); | |
| 3312 r->AppendChunkToUpload("2323", 4, true); | |
| 3313 } | |
| 3314 | |
| 3315 void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) { | |
| 3316 // This should match the chunks sent by AddChunksToUpload(). | |
| 3317 const std::string expected_data = | |
| 3318 "abcdthis is a longer chunk than before.\r\n\r\n02323"; | |
| 3319 | |
| 3320 ASSERT_EQ(1, d->response_started_count()) | |
| 3321 << "request failed: " << r->status().status() | |
| 3322 << ", os error: " << r->status().error(); | |
| 3323 | |
| 3324 EXPECT_FALSE(d->received_data_before_response()); | |
| 3325 | |
| 3326 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); | |
| 3327 EXPECT_EQ(expected_data, d->data_received()); | |
| 3328 } | |
| 3329 | |
| 3330 bool DoManyCookiesRequest(int num_cookies) { | 3306 bool DoManyCookiesRequest(int num_cookies) { |
| 3331 TestDelegate d; | 3307 TestDelegate d; |
| 3332 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 3308 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3333 test_server_.GetURL("/set-many-cookies?" + | 3309 test_server_.GetURL("/set-many-cookies?" + |
| 3334 base::IntToString(num_cookies)), | 3310 base::IntToString(num_cookies)), |
| 3335 DEFAULT_PRIORITY, &d)); | 3311 DEFAULT_PRIORITY, &d)); |
| 3336 | 3312 |
| 3337 r->Start(); | 3313 r->Start(); |
| 3338 EXPECT_TRUE(r->is_pending()); | 3314 EXPECT_TRUE(r->is_pending()); |
| 3339 | 3315 |
| (...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5721 base::RunLoop().Run(); | 5697 base::RunLoop().Run(); |
| 5722 | 5698 |
| 5723 EXPECT_TRUE(d.request_failed()); | 5699 EXPECT_TRUE(d.request_failed()); |
| 5724 EXPECT_FALSE(d.received_data_before_response()); | 5700 EXPECT_FALSE(d.received_data_before_response()); |
| 5725 EXPECT_EQ(0, d.bytes_received()); | 5701 EXPECT_EQ(0, d.bytes_received()); |
| 5726 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 5702 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 5727 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); | 5703 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); |
| 5728 } | 5704 } |
| 5729 } | 5705 } |
| 5730 | 5706 |
| 5707 namespace { |
| 5708 |
| 5709 // Add a standard set of data to an upload for chunked upload integration |
| 5710 // tests. |
| 5711 void AddDataToUpload(ChunkedUploadDataStream::Writer* writer) { |
| 5712 writer->AppendData("a", 1, false); |
| 5713 writer->AppendData("bcd", 3, false); |
| 5714 writer->AppendData("this is a longer chunk than before.", 35, false); |
| 5715 writer->AppendData("\r\n\r\n", 4, false); |
| 5716 writer->AppendData("0", 1, false); |
| 5717 writer->AppendData("2323", 4, true); |
| 5718 } |
| 5719 |
| 5720 // Check that the upload data added in AddChunksToUpload() was echoed back from |
| 5721 // the server. |
| 5722 void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) { |
| 5723 // This should match the chunks sent by AddChunksToUpload(). |
| 5724 const std::string expected_data = |
| 5725 "abcdthis is a longer chunk than before.\r\n\r\n02323"; |
| 5726 |
| 5727 ASSERT_EQ(1, d->response_started_count()) |
| 5728 << "request failed: " << r->status().status() |
| 5729 << ", os error: " << r->status().error(); |
| 5730 |
| 5731 EXPECT_FALSE(d->received_data_before_response()); |
| 5732 |
| 5733 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); |
| 5734 EXPECT_EQ(expected_data, d->data_received()); |
| 5735 } |
| 5736 |
| 5737 } // namespace |
| 5738 |
| 5731 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 5739 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 5732 ASSERT_TRUE(http_test_server()->Start()); | 5740 ASSERT_TRUE(http_test_server()->Start()); |
| 5733 | 5741 |
| 5734 TestDelegate d; | 5742 TestDelegate d; |
| 5735 { | 5743 { |
| 5736 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5744 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5737 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5745 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5738 r->EnableChunkedUpload(); | 5746 scoped_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5747 new ChunkedUploadDataStream(0)); |
| 5748 scoped_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5749 upload_data_stream->CreateWriter(); |
| 5750 r->set_upload(std::move(upload_data_stream)); |
| 5739 r->set_method("POST"); | 5751 r->set_method("POST"); |
| 5740 AddChunksToUpload(r.get()); | 5752 AddDataToUpload(writer.get()); |
| 5741 r->Start(); | 5753 r->Start(); |
| 5742 EXPECT_TRUE(r->is_pending()); | 5754 EXPECT_TRUE(r->is_pending()); |
| 5743 | 5755 |
| 5744 base::RunLoop().Run(); | 5756 base::RunLoop().Run(); |
| 5745 | 5757 |
| 5746 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5758 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5747 } | 5759 } |
| 5748 } | 5760 } |
| 5749 | 5761 |
| 5750 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { | 5762 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { |
| 5751 ASSERT_TRUE(http_test_server()->Start()); | 5763 ASSERT_TRUE(http_test_server()->Start()); |
| 5752 | 5764 |
| 5753 TestDelegate d; | 5765 TestDelegate d; |
| 5754 { | 5766 { |
| 5755 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5767 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5756 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5768 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5757 r->EnableChunkedUpload(); | 5769 scoped_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5770 new ChunkedUploadDataStream(0)); |
| 5771 scoped_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5772 upload_data_stream->CreateWriter(); |
| 5773 r->set_upload(make_scoped_ptr(upload_data_stream.release())); |
| 5758 r->set_method("POST"); | 5774 r->set_method("POST"); |
| 5759 r->Start(); | 5775 r->Start(); |
| 5760 EXPECT_TRUE(r->is_pending()); | 5776 EXPECT_TRUE(r->is_pending()); |
| 5761 AddChunksToUpload(r.get()); | 5777 AddDataToUpload(writer.get()); |
| 5762 base::RunLoop().Run(); | 5778 base::RunLoop().Run(); |
| 5763 | 5779 |
| 5764 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5780 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5765 } | 5781 } |
| 5766 } | 5782 } |
| 5767 | 5783 |
| 5768 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 5784 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
| 5769 ASSERT_TRUE(http_test_server()->Start()); | 5785 ASSERT_TRUE(http_test_server()->Start()); |
| 5770 | 5786 |
| 5771 TestDelegate d; | 5787 TestDelegate d; |
| 5772 { | 5788 { |
| 5773 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5789 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5774 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5790 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5775 r->EnableChunkedUpload(); | 5791 scoped_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5792 new ChunkedUploadDataStream(0)); |
| 5793 scoped_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5794 upload_data_stream->CreateWriter(); |
| 5795 r->set_upload(std::move(upload_data_stream)); |
| 5776 r->set_method("POST"); | 5796 r->set_method("POST"); |
| 5777 r->Start(); | 5797 r->Start(); |
| 5778 EXPECT_TRUE(r->is_pending()); | 5798 EXPECT_TRUE(r->is_pending()); |
| 5779 | 5799 |
| 5780 base::RunLoop().RunUntilIdle(); | 5800 base::RunLoop().RunUntilIdle(); |
| 5781 AddChunksToUpload(r.get()); | 5801 AddDataToUpload(writer.get()); |
| 5782 base::RunLoop().Run(); | 5802 base::RunLoop().Run(); |
| 5783 | 5803 |
| 5784 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5804 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5785 } | 5805 } |
| 5786 } | 5806 } |
| 5787 | 5807 |
| 5788 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 5808 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
| 5789 ASSERT_TRUE(http_test_server()->Start()); | 5809 ASSERT_TRUE(http_test_server()->Start()); |
| 5790 | 5810 |
| 5791 TestDelegate d; | 5811 TestDelegate d; |
| (...skipping 4223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10015 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10035 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 10016 | 10036 |
| 10017 req->Start(); | 10037 req->Start(); |
| 10018 req->Cancel(); | 10038 req->Cancel(); |
| 10019 base::RunLoop().RunUntilIdle(); | 10039 base::RunLoop().RunUntilIdle(); |
| 10020 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 10040 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 10021 EXPECT_EQ(0, d.received_redirect_count()); | 10041 EXPECT_EQ(0, d.received_redirect_count()); |
| 10022 } | 10042 } |
| 10023 | 10043 |
| 10024 } // namespace net | 10044 } // namespace net |
| OLD | NEW |