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 "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 6565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6576 SessionDependencies session_deps; | 6576 SessionDependencies session_deps; |
6577 scoped_ptr<HttpTransaction> trans( | 6577 scoped_ptr<HttpTransaction> trans( |
6578 new HttpNetworkTransaction(CreateSession(&session_deps))); | 6578 new HttpNetworkTransaction(CreateSession(&session_deps))); |
6579 | 6579 |
6580 FilePath temp_file_path; | 6580 FilePath temp_file_path; |
6581 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); | 6581 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); |
6582 const uint64 kFakeSize = 100000; // file is actually blank | 6582 const uint64 kFakeSize = 100000; // file is actually blank |
6583 UploadFileElementReader::ScopedOverridingContentLengthForTests | 6583 UploadFileElementReader::ScopedOverridingContentLengthForTests |
6584 overriding_content_length(kFakeSize); | 6584 overriding_content_length(kFakeSize); |
6585 | 6585 |
6586 std::vector<UploadElement> elements; | 6586 request.upload_data->AppendFileRange( |
6587 UploadElement element; | 6587 temp_file_path, 0, kuint64max, base::Time()); |
6588 element.SetToFilePath(temp_file_path); | |
6589 elements.push_back(element); | |
6590 request.upload_data->SetElements(elements); | |
6591 | 6588 |
6592 MockRead data_reads[] = { | 6589 MockRead data_reads[] = { |
6593 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 6590 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
6594 MockRead("hello world"), | 6591 MockRead("hello world"), |
6595 MockRead(SYNCHRONOUS, OK), | 6592 MockRead(SYNCHRONOUS, OK), |
6596 }; | 6593 }; |
6597 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | 6594 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
6598 session_deps.socket_factory.AddSocketDataProvider(&data); | 6595 session_deps.socket_factory.AddSocketDataProvider(&data); |
6599 | 6596 |
6600 TestCompletionCallback callback; | 6597 TestCompletionCallback callback; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6632 scoped_ptr<HttpTransaction> trans( | 6629 scoped_ptr<HttpTransaction> trans( |
6633 new HttpNetworkTransaction(CreateSession(&session_deps))); | 6630 new HttpNetworkTransaction(CreateSession(&session_deps))); |
6634 | 6631 |
6635 FilePath temp_file; | 6632 FilePath temp_file; |
6636 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); | 6633 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); |
6637 std::string temp_file_content("Unreadable file."); | 6634 std::string temp_file_content("Unreadable file."); |
6638 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_content.c_str(), | 6635 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_content.c_str(), |
6639 temp_file_content.length())); | 6636 temp_file_content.length())); |
6640 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); | 6637 ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); |
6641 | 6638 |
6642 std::vector<UploadElement> elements; | 6639 request.upload_data->AppendFileRange(temp_file, 0, kuint64max, base::Time()); |
6643 UploadElement element; | |
6644 element.SetToFilePath(temp_file); | |
6645 elements.push_back(element); | |
6646 request.upload_data->SetElements(elements); | |
6647 | 6640 |
6648 MockRead data_reads[] = { | 6641 MockRead data_reads[] = { |
6649 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 6642 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
6650 MockRead(SYNCHRONOUS, OK), | 6643 MockRead(SYNCHRONOUS, OK), |
6651 }; | 6644 }; |
6652 MockWrite data_writes[] = { | 6645 MockWrite data_writes[] = { |
6653 MockWrite("POST /upload HTTP/1.1\r\n" | 6646 MockWrite("POST /upload HTTP/1.1\r\n" |
6654 "Host: www.google.com\r\n" | 6647 "Host: www.google.com\r\n" |
6655 "Connection: keep-alive\r\n" | 6648 "Connection: keep-alive\r\n" |
6656 "Content-Length: 0\r\n\r\n"), | 6649 "Content-Length: 0\r\n\r\n"), |
(...skipping 30 matching lines...) Expand all Loading... |
6687 scoped_ptr<HttpTransaction> trans( | 6680 scoped_ptr<HttpTransaction> trans( |
6688 new HttpNetworkTransaction(CreateSession(&session_deps))); | 6681 new HttpNetworkTransaction(CreateSession(&session_deps))); |
6689 | 6682 |
6690 FilePath temp_file; | 6683 FilePath temp_file; |
6691 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); | 6684 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); |
6692 std::string temp_file_contents("Unreadable file."); | 6685 std::string temp_file_contents("Unreadable file."); |
6693 std::string unreadable_contents(temp_file_contents.length(), '\0'); | 6686 std::string unreadable_contents(temp_file_contents.length(), '\0'); |
6694 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), | 6687 ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), |
6695 temp_file_contents.length())); | 6688 temp_file_contents.length())); |
6696 | 6689 |
6697 std::vector<UploadElement> elements; | 6690 request.upload_data->AppendFileRange(temp_file, 0, kuint64max, base::Time()); |
6698 UploadElement element; | |
6699 element.SetToFilePath(temp_file); | |
6700 elements.push_back(element); | |
6701 request.upload_data->SetElements(elements); | |
6702 | 6691 |
6703 MockRead data_reads[] = { | 6692 MockRead data_reads[] = { |
6704 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | 6693 MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
6705 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | 6694 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
6706 MockRead("Content-Length: 0\r\n\r\n"), // No response body. | 6695 MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
6707 | 6696 |
6708 MockRead("HTTP/1.1 200 OK\r\n"), | 6697 MockRead("HTTP/1.1 200 OK\r\n"), |
6709 MockRead("Content-Length: 0\r\n\r\n"), | 6698 MockRead("Content-Length: 0\r\n\r\n"), |
6710 MockRead(SYNCHRONOUS, OK), | 6699 MockRead(SYNCHRONOUS, OK), |
6711 }; | 6700 }; |
(...skipping 3543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10255 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | 10244 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
10256 MessageLoop::current()->RunAllPending(); | 10245 MessageLoop::current()->RunAllPending(); |
10257 data2->RunFor(3); | 10246 data2->RunFor(3); |
10258 | 10247 |
10259 ASSERT_TRUE(callback2.have_result()); | 10248 ASSERT_TRUE(callback2.have_result()); |
10260 EXPECT_EQ(OK, callback2.WaitForResult()); | 10249 EXPECT_EQ(OK, callback2.WaitForResult()); |
10261 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | 10250 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
10262 } | 10251 } |
10263 | 10252 |
10264 } // namespace net | 10253 } // namespace net |
OLD | NEW |