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 7753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7764 | 7764 |
7765 response = trans->GetResponseInfo(); | 7765 response = trans->GetResponseInfo(); |
7766 ASSERT_TRUE(response != NULL); | 7766 ASSERT_TRUE(response != NULL); |
7767 EXPECT_TRUE(response->headers.get() != NULL); | 7767 EXPECT_TRUE(response->headers.get() != NULL); |
7768 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 7768 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
7769 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 7769 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
7770 | 7770 |
7771 base::DeleteFile(temp_file, false); | 7771 base::DeleteFile(temp_file, false); |
7772 } | 7772 } |
7773 | 7773 |
| 7774 TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 7775 class FakeUploadElementReader : public UploadElementReader { |
| 7776 public: |
| 7777 FakeUploadElementReader() {} |
| 7778 virtual ~FakeUploadElementReader() {} |
| 7779 |
| 7780 const CompletionCallback& callback() const { return callback_; } |
| 7781 |
| 7782 // UploadElementReader overrides: |
| 7783 virtual int Init(const CompletionCallback& callback) OVERRIDE { |
| 7784 callback_ = callback; |
| 7785 return ERR_IO_PENDING; |
| 7786 } |
| 7787 virtual uint64 GetContentLength() const OVERRIDE { return 0; } |
| 7788 virtual uint64 BytesRemaining() const OVERRIDE { return 0; } |
| 7789 virtual int Read(IOBuffer* buf, |
| 7790 int buf_length, |
| 7791 const CompletionCallback& callback) OVERRIDE { |
| 7792 return ERR_FAILED; |
| 7793 } |
| 7794 |
| 7795 private: |
| 7796 CompletionCallback callback_; |
| 7797 }; |
| 7798 |
| 7799 FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 7800 ScopedVector<UploadElementReader> element_readers; |
| 7801 element_readers.push_back(fake_reader); |
| 7802 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 7803 |
| 7804 HttpRequestInfo request; |
| 7805 request.method = "POST"; |
| 7806 request.url = GURL("http://www.google.com/upload"); |
| 7807 request.upload_data_stream = &upload_data_stream; |
| 7808 request.load_flags = 0; |
| 7809 |
| 7810 scoped_ptr<HttpTransaction> trans( |
| 7811 new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 7812 CreateSession(&session_deps_))); |
| 7813 |
| 7814 StaticSocketDataProvider data; |
| 7815 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7816 |
| 7817 TestCompletionCallback callback; |
| 7818 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7819 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7820 base::MessageLoop::current()->RunUntilIdle(); |
| 7821 |
| 7822 // Transaction is pending on request body initialization. |
| 7823 ASSERT_FALSE(fake_reader->callback().is_null()); |
| 7824 |
| 7825 // Return Init()'s result after the transaction gets destroyed. |
| 7826 trans.reset(); |
| 7827 fake_reader->callback().Run(OK); // Should not crash. |
| 7828 } |
| 7829 |
7774 // Tests that changes to Auth realms are treated like auth rejections. | 7830 // Tests that changes to Auth realms are treated like auth rejections. |
7775 TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { | 7831 TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
7776 | 7832 |
7777 HttpRequestInfo request; | 7833 HttpRequestInfo request; |
7778 request.method = "GET"; | 7834 request.method = "GET"; |
7779 request.url = GURL("http://www.google.com/"); | 7835 request.url = GURL("http://www.google.com/"); |
7780 request.load_flags = 0; | 7836 request.load_flags = 0; |
7781 | 7837 |
7782 // First transaction will request a resource and receive a Basic challenge | 7838 // First transaction will request a resource and receive a Basic challenge |
7783 // with realm="first_realm". | 7839 // with realm="first_realm". |
(...skipping 4382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12166 // established, to let the HTTP request start. | 12222 // established, to let the HTTP request start. |
12167 ASSERT_EQ(OK, http_callback.WaitForResult()); | 12223 ASSERT_EQ(OK, http_callback.WaitForResult()); |
12168 std::string response_data; | 12224 std::string response_data; |
12169 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); | 12225 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
12170 EXPECT_EQ("falafel", response_data); | 12226 EXPECT_EQ("falafel", response_data); |
12171 | 12227 |
12172 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); | 12228 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); |
12173 } | 12229 } |
12174 | 12230 |
12175 } // namespace net | 12231 } // namespace net |
OLD | NEW |