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 3317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3328 ASSERT_EQ(1, d.response_started_count()) | 3328 ASSERT_EQ(1, d.response_started_count()) |
3329 << "request failed: " << r->status().status() | 3329 << "request failed: " << r->status().status() |
3330 << ", os error: " << r->status().error(); | 3330 << ", os error: " << r->status().error(); |
3331 | 3331 |
3332 EXPECT_FALSE(d.received_data_before_response()); | 3332 EXPECT_FALSE(d.received_data_before_response()); |
3333 EXPECT_EQ(uploadBytes, d.data_received()); | 3333 EXPECT_EQ(uploadBytes, d.data_received()); |
3334 } | 3334 } |
3335 delete[] uploadBytes; | 3335 delete[] uploadBytes; |
3336 } | 3336 } |
3337 | 3337 |
3338 void AddChunksToUpload(URLRequest* r) { | |
3339 r->AppendChunkToUpload("a", 1, false); | |
3340 r->AppendChunkToUpload("bcd", 3, false); | |
3341 r->AppendChunkToUpload("this is a longer chunk than before.", 35, false); | |
3342 r->AppendChunkToUpload("\r\n\r\n", 4, false); | |
3343 r->AppendChunkToUpload("0", 1, false); | |
3344 r->AppendChunkToUpload("2323", 4, true); | |
3345 } | |
3346 | |
3347 void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) { | |
3348 // This should match the chunks sent by AddChunksToUpload(). | |
3349 const std::string expected_data = | |
3350 "abcdthis is a longer chunk than before.\r\n\r\n02323"; | |
3351 | |
3352 ASSERT_EQ(1, d->response_started_count()) | |
3353 << "request failed: " << r->status().status() | |
3354 << ", os error: " << r->status().error(); | |
3355 | |
3356 EXPECT_FALSE(d->received_data_before_response()); | |
3357 | |
3358 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); | |
3359 EXPECT_EQ(expected_data, d->data_received()); | |
3360 } | |
3361 | |
3362 bool DoManyCookiesRequest(int num_cookies) { | 3338 bool DoManyCookiesRequest(int num_cookies) { |
3363 TestDelegate d; | 3339 TestDelegate d; |
3364 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 3340 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
3365 test_server_.GetURL("/set-many-cookies?" + | 3341 test_server_.GetURL("/set-many-cookies?" + |
3366 base::IntToString(num_cookies)), | 3342 base::IntToString(num_cookies)), |
3367 DEFAULT_PRIORITY, &d)); | 3343 DEFAULT_PRIORITY, &d)); |
3368 | 3344 |
3369 r->Start(); | 3345 r->Start(); |
3370 EXPECT_TRUE(r->is_pending()); | 3346 EXPECT_TRUE(r->is_pending()); |
3371 | 3347 |
(...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5753 base::RunLoop().Run(); | 5729 base::RunLoop().Run(); |
5754 | 5730 |
5755 EXPECT_TRUE(d.request_failed()); | 5731 EXPECT_TRUE(d.request_failed()); |
5756 EXPECT_FALSE(d.received_data_before_response()); | 5732 EXPECT_FALSE(d.received_data_before_response()); |
5757 EXPECT_EQ(0, d.bytes_received()); | 5733 EXPECT_EQ(0, d.bytes_received()); |
5758 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 5734 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
5759 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); | 5735 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); |
5760 } | 5736 } |
5761 } | 5737 } |
5762 | 5738 |
| 5739 namespace { |
| 5740 |
| 5741 // Adds a standard set of data to an upload for chunked upload integration |
| 5742 // tests. |
| 5743 void AddDataToUpload(ChunkedUploadDataStream::Writer* writer) { |
| 5744 writer->AppendData("a", 1, false); |
| 5745 writer->AppendData("bcd", 3, false); |
| 5746 writer->AppendData("this is a longer chunk than before.", 35, false); |
| 5747 writer->AppendData("\r\n\r\n", 4, false); |
| 5748 writer->AppendData("0", 1, false); |
| 5749 writer->AppendData("2323", 4, true); |
| 5750 } |
| 5751 |
| 5752 // Checks that the upload data added in AddChunksToUpload() was echoed back from |
| 5753 // the server. |
| 5754 void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) { |
| 5755 // This should match the chunks sent by AddChunksToUpload(). |
| 5756 const std::string expected_data = |
| 5757 "abcdthis is a longer chunk than before.\r\n\r\n02323"; |
| 5758 |
| 5759 ASSERT_EQ(1, d->response_started_count()) |
| 5760 << "request failed: " << r->status().status() |
| 5761 << ", os error: " << r->status().error(); |
| 5762 |
| 5763 EXPECT_FALSE(d->received_data_before_response()); |
| 5764 |
| 5765 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); |
| 5766 EXPECT_EQ(expected_data, d->data_received()); |
| 5767 } |
| 5768 |
| 5769 } // namespace |
| 5770 |
5763 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 5771 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
5764 ASSERT_TRUE(http_test_server()->Start()); | 5772 ASSERT_TRUE(http_test_server()->Start()); |
5765 | 5773 |
5766 TestDelegate d; | 5774 TestDelegate d; |
5767 { | 5775 { |
5768 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5776 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
5769 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5777 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
5770 r->EnableChunkedUpload(); | 5778 scoped_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5779 new ChunkedUploadDataStream(0)); |
| 5780 scoped_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5781 upload_data_stream->CreateWriter(); |
| 5782 r->set_upload(std::move(upload_data_stream)); |
5771 r->set_method("POST"); | 5783 r->set_method("POST"); |
5772 AddChunksToUpload(r.get()); | 5784 AddDataToUpload(writer.get()); |
5773 r->Start(); | 5785 r->Start(); |
5774 EXPECT_TRUE(r->is_pending()); | 5786 EXPECT_TRUE(r->is_pending()); |
5775 | 5787 |
5776 base::RunLoop().Run(); | 5788 base::RunLoop().Run(); |
5777 | 5789 |
5778 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5790 VerifyReceivedDataMatchesChunks(r.get(), &d); |
5779 } | 5791 } |
5780 } | 5792 } |
5781 | 5793 |
5782 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { | 5794 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { |
5783 ASSERT_TRUE(http_test_server()->Start()); | 5795 ASSERT_TRUE(http_test_server()->Start()); |
5784 | 5796 |
5785 TestDelegate d; | 5797 TestDelegate d; |
5786 { | 5798 { |
5787 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5799 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
5788 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5800 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
5789 r->EnableChunkedUpload(); | 5801 scoped_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5802 new ChunkedUploadDataStream(0)); |
| 5803 scoped_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5804 upload_data_stream->CreateWriter(); |
| 5805 r->set_upload(make_scoped_ptr(upload_data_stream.release())); |
5790 r->set_method("POST"); | 5806 r->set_method("POST"); |
5791 r->Start(); | 5807 r->Start(); |
5792 EXPECT_TRUE(r->is_pending()); | 5808 EXPECT_TRUE(r->is_pending()); |
5793 AddChunksToUpload(r.get()); | 5809 AddDataToUpload(writer.get()); |
5794 base::RunLoop().Run(); | 5810 base::RunLoop().Run(); |
5795 | 5811 |
5796 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5812 VerifyReceivedDataMatchesChunks(r.get(), &d); |
5797 } | 5813 } |
5798 } | 5814 } |
5799 | 5815 |
5800 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 5816 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
5801 ASSERT_TRUE(http_test_server()->Start()); | 5817 ASSERT_TRUE(http_test_server()->Start()); |
5802 | 5818 |
5803 TestDelegate d; | 5819 TestDelegate d; |
5804 { | 5820 { |
5805 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5821 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
5806 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5822 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
5807 r->EnableChunkedUpload(); | 5823 scoped_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5824 new ChunkedUploadDataStream(0)); |
| 5825 scoped_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5826 upload_data_stream->CreateWriter(); |
| 5827 r->set_upload(std::move(upload_data_stream)); |
5808 r->set_method("POST"); | 5828 r->set_method("POST"); |
5809 r->Start(); | 5829 r->Start(); |
5810 EXPECT_TRUE(r->is_pending()); | 5830 EXPECT_TRUE(r->is_pending()); |
5811 | 5831 |
5812 base::RunLoop().RunUntilIdle(); | 5832 base::RunLoop().RunUntilIdle(); |
5813 AddChunksToUpload(r.get()); | 5833 AddDataToUpload(writer.get()); |
5814 base::RunLoop().Run(); | 5834 base::RunLoop().Run(); |
5815 | 5835 |
5816 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5836 VerifyReceivedDataMatchesChunks(r.get(), &d); |
5817 } | 5837 } |
5818 } | 5838 } |
5819 | 5839 |
5820 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 5840 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
5821 ASSERT_TRUE(http_test_server()->Start()); | 5841 ASSERT_TRUE(http_test_server()->Start()); |
5822 | 5842 |
5823 TestDelegate d; | 5843 TestDelegate d; |
(...skipping 4222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10046 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10066 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
10047 | 10067 |
10048 req->Start(); | 10068 req->Start(); |
10049 req->Cancel(); | 10069 req->Cancel(); |
10050 base::RunLoop().RunUntilIdle(); | 10070 base::RunLoop().RunUntilIdle(); |
10051 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 10071 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
10052 EXPECT_EQ(0, d.received_redirect_count()); | 10072 EXPECT_EQ(0, d.received_redirect_count()); |
10053 } | 10073 } |
10054 | 10074 |
10055 } // namespace net | 10075 } // namespace net |
OLD | NEW |