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