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 "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 7706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7717 kuint64max, | 7717 kuint64max, |
7718 base::Time())); | 7718 base::Time())); |
7719 UploadDataStream upload_data_stream(element_readers.Pass(), 0); | 7719 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
7720 | 7720 |
7721 HttpRequestInfo request; | 7721 HttpRequestInfo request; |
7722 request.method = "POST"; | 7722 request.method = "POST"; |
7723 request.url = GURL("http://www.google.com/upload"); | 7723 request.url = GURL("http://www.google.com/upload"); |
7724 request.upload_data_stream = &upload_data_stream; | 7724 request.upload_data_stream = &upload_data_stream; |
7725 request.load_flags = 0; | 7725 request.load_flags = 0; |
7726 | 7726 |
7727 // If we try to upload an unreadable file, the network stack should report | 7727 // If we try to upload an unreadable file, the transaction should fail. |
7728 // the file size as zero and upload zero bytes for that file. | |
7729 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 7728 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
7730 scoped_ptr<HttpTransaction> trans( | 7729 scoped_ptr<HttpTransaction> trans( |
7731 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); | 7730 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
7732 | 7731 |
7733 MockRead data_reads[] = { | 7732 MockRead data_reads[] = { |
7734 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 7733 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
7735 MockRead(SYNCHRONOUS, OK), | 7734 MockRead(SYNCHRONOUS, OK), |
7736 }; | 7735 }; |
7737 MockWrite data_writes[] = { | 7736 MockWrite data_writes[] = { |
7738 MockWrite("POST /upload HTTP/1.1\r\n" | 7737 MockWrite("POST /upload HTTP/1.1\r\n" |
7739 "Host: www.google.com\r\n" | 7738 "Host: www.google.com\r\n" |
7740 "Connection: keep-alive\r\n" | 7739 "Connection: keep-alive\r\n" |
7741 "Content-Length: 0\r\n\r\n"), | 7740 "Content-Length: 0\r\n\r\n"), |
mmenke
2013/10/29 15:29:31
Do we need all this stuff? I thought we ended up
tzik
2013/11/07 04:42:55
Done.
| |
7742 MockWrite(SYNCHRONOUS, OK), | 7741 MockWrite(SYNCHRONOUS, OK), |
7743 }; | 7742 }; |
7744 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | 7743 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
7745 arraysize(data_writes)); | 7744 arraysize(data_writes)); |
7746 session_deps_.socket_factory->AddSocketDataProvider(&data); | 7745 session_deps_.socket_factory->AddSocketDataProvider(&data); |
7747 | 7746 |
7748 TestCompletionCallback callback; | 7747 TestCompletionCallback callback; |
7749 | 7748 |
7750 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 7749 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
7751 EXPECT_EQ(ERR_IO_PENDING, rv); | 7750 EXPECT_EQ(ERR_IO_PENDING, rv); |
7752 | 7751 |
7753 rv = callback.WaitForResult(); | 7752 rv = callback.WaitForResult(); |
7754 EXPECT_EQ(OK, rv); | 7753 EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
7755 | 7754 |
7756 const HttpResponseInfo* response = trans->GetResponseInfo(); | 7755 const HttpResponseInfo* response = trans->GetResponseInfo(); |
7757 ASSERT_TRUE(response != NULL); | 7756 EXPECT_FALSE(response); |
7758 EXPECT_TRUE(response->headers.get() != NULL); | |
7759 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); | |
7760 | 7757 |
7761 base::DeleteFile(temp_file, false); | 7758 base::DeleteFile(temp_file, false); |
7762 } | 7759 } |
7763 | 7760 |
7764 TEST_P(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) { | 7761 TEST_P(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) { |
7765 base::FilePath temp_file; | 7762 base::FilePath temp_file; |
7766 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); | 7763 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); |
7767 std::string temp_file_contents("Unreadable file."); | 7764 std::string temp_file_contents("Unreadable file."); |
7768 std::string unreadable_contents(temp_file_contents.length(), '\0'); | 7765 std::string unreadable_contents(temp_file_contents.length(), '\0'); |
7769 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), | 7766 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7803 "Connection: keep-alive\r\n" | 7800 "Connection: keep-alive\r\n" |
7804 "Content-Length: 16\r\n\r\n"), | 7801 "Content-Length: 16\r\n\r\n"), |
7805 MockWrite(SYNCHRONOUS, temp_file_contents.c_str()), | 7802 MockWrite(SYNCHRONOUS, temp_file_contents.c_str()), |
7806 | 7803 |
7807 MockWrite("POST /upload HTTP/1.1\r\n" | 7804 MockWrite("POST /upload HTTP/1.1\r\n" |
7808 "Host: www.google.com\r\n" | 7805 "Host: www.google.com\r\n" |
7809 "Connection: keep-alive\r\n" | 7806 "Connection: keep-alive\r\n" |
7810 "Content-Length: 0\r\n" | 7807 "Content-Length: 0\r\n" |
7811 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 7808 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
7812 MockWrite(SYNCHRONOUS, unreadable_contents.c_str(), | 7809 MockWrite(SYNCHRONOUS, unreadable_contents.c_str(), |
7813 temp_file_contents.length()), | 7810 temp_file_contents.length()), |
mmenke
2013/10/29 15:29:31
Again, don't think we need the second block of dat
tzik
2013/11/07 04:42:55
Well, since the request should be aborted before s
| |
7814 MockWrite(SYNCHRONOUS, OK), | 7811 MockWrite(SYNCHRONOUS, OK), |
7815 }; | 7812 }; |
7816 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | 7813 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
7817 arraysize(data_writes)); | 7814 arraysize(data_writes)); |
7818 session_deps_.socket_factory->AddSocketDataProvider(&data); | 7815 session_deps_.socket_factory->AddSocketDataProvider(&data); |
7819 | 7816 |
7820 TestCompletionCallback callback1; | 7817 TestCompletionCallback callback1; |
7821 | 7818 |
7822 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 7819 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
7823 EXPECT_EQ(ERR_IO_PENDING, rv); | 7820 EXPECT_EQ(ERR_IO_PENDING, rv); |
(...skipping 10 matching lines...) Expand all Loading... | |
7834 // Now make the file unreadable and try again. | 7831 // Now make the file unreadable and try again. |
7835 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); | 7832 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); |
7836 | 7833 |
7837 TestCompletionCallback callback2; | 7834 TestCompletionCallback callback2; |
7838 | 7835 |
7839 rv = trans->RestartWithAuth( | 7836 rv = trans->RestartWithAuth( |
7840 AuthCredentials(kFoo, kBar), callback2.callback()); | 7837 AuthCredentials(kFoo, kBar), callback2.callback()); |
7841 EXPECT_EQ(ERR_IO_PENDING, rv); | 7838 EXPECT_EQ(ERR_IO_PENDING, rv); |
7842 | 7839 |
7843 rv = callback2.WaitForResult(); | 7840 rv = callback2.WaitForResult(); |
7844 EXPECT_EQ(OK, rv); | 7841 EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
7845 | 7842 |
7846 response = trans->GetResponseInfo(); | 7843 response = trans->GetResponseInfo(); |
7847 ASSERT_TRUE(response != NULL); | 7844 EXPECT_FALSE(response); |
7848 EXPECT_TRUE(response->headers.get() != NULL); | |
7849 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
7850 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
7851 | 7845 |
7852 base::DeleteFile(temp_file, false); | 7846 base::DeleteFile(temp_file, false); |
7853 } | 7847 } |
7854 | 7848 |
7855 TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { | 7849 TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
7856 class FakeUploadElementReader : public UploadElementReader { | 7850 class FakeUploadElementReader : public UploadElementReader { |
7857 public: | 7851 public: |
7858 FakeUploadElementReader() {} | 7852 FakeUploadElementReader() {} |
7859 virtual ~FakeUploadElementReader() {} | 7853 virtual ~FakeUploadElementReader() {} |
7860 | 7854 |
(...skipping 4441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12302 // established, to let the HTTP request start. | 12296 // established, to let the HTTP request start. |
12303 ASSERT_EQ(OK, http_callback.WaitForResult()); | 12297 ASSERT_EQ(OK, http_callback.WaitForResult()); |
12304 std::string response_data; | 12298 std::string response_data; |
12305 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); | 12299 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
12306 EXPECT_EQ("falafel", response_data); | 12300 EXPECT_EQ("falafel", response_data); |
12307 | 12301 |
12308 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); | 12302 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); |
12309 } | 12303 } |
12310 | 12304 |
12311 } // namespace net | 12305 } // namespace net |
OLD | NEW |