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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/test/test_file_util.h" | |
15 #include "net/base/auth.h" | 16 #include "net/base/auth.h" |
16 #include "net/base/net_log_unittest.h" | 17 #include "net/base/net_log_unittest.h" |
17 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
18 #include "net/base/upload_bytes_element_reader.h" | 19 #include "net/base/upload_bytes_element_reader.h" |
19 #include "net/base/upload_data_stream.h" | 20 #include "net/base/upload_data_stream.h" |
20 #include "net/base/upload_file_element_reader.h" | 21 #include "net/base/upload_file_element_reader.h" |
21 #include "net/http/http_network_session_peer.h" | 22 #include "net/http/http_network_session_peer.h" |
22 #include "net/http/http_network_transaction.h" | 23 #include "net/http/http_network_transaction.h" |
23 #include "net/http/http_server_properties.h" | 24 #include "net/http/http_server_properties.h" |
24 #include "net/http/http_transaction_unittest.h" | 25 #include "net/http/http_transaction_unittest.h" |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 new UploadDataStream(element_readers.Pass(), 0)); | 453 new UploadDataStream(element_readers.Pass(), 0)); |
453 | 454 |
454 google_post_request_.method = "POST"; | 455 google_post_request_.method = "POST"; |
455 google_post_request_.url = GURL(kDefaultURL); | 456 google_post_request_.url = GURL(kDefaultURL); |
456 google_post_request_.upload_data_stream = upload_data_stream_.get(); | 457 google_post_request_.upload_data_stream = upload_data_stream_.get(); |
457 google_post_request_initialized_ = true; | 458 google_post_request_initialized_ = true; |
458 } | 459 } |
459 return google_post_request_; | 460 return google_post_request_; |
460 } | 461 } |
461 | 462 |
463 const HttpRequestInfo& CreateUnreadableFilePostRequest() { | |
464 if (google_post_request_initialized_) | |
465 return google_post_request_; | |
466 | |
467 base::FilePath file_path; | |
468 CHECK(file_util::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); | |
469 CHECK_EQ(static_cast<int>(kUploadDataSize), | |
470 file_util::WriteFile(file_path, kUploadData, kUploadDataSize)); | |
471 CHECK(file_util::MakeFileUnreadable(file_path)); | |
472 | |
473 ScopedVector<UploadElementReader> element_readers; | |
474 element_readers.push_back( | |
475 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | |
476 file_path, | |
477 0, | |
478 kUploadDataSize, | |
479 base::Time())); | |
480 upload_data_stream_.reset( | |
481 new UploadDataStream(element_readers.Pass(), 0)); | |
482 | |
483 google_post_request_.method = "POST"; | |
484 google_post_request_.url = GURL(kDefaultURL); | |
485 google_post_request_.upload_data_stream = upload_data_stream_.get(); | |
486 google_post_request_initialized_ = true; | |
487 return google_post_request_; | |
488 } | |
489 | |
462 const HttpRequestInfo& CreateComplexPostRequest() { | 490 const HttpRequestInfo& CreateComplexPostRequest() { |
463 if (!google_post_request_initialized_) { | 491 if (!google_post_request_initialized_) { |
464 const int kFileRangeOffset = 1; | 492 const int kFileRangeOffset = 1; |
465 const int kFileRangeLength = 3; | 493 const int kFileRangeLength = 3; |
466 CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize); | 494 CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize); |
467 | 495 |
468 base::FilePath file_path; | 496 base::FilePath file_path; |
469 CHECK(file_util::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); | 497 CHECK(file_util::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
470 CHECK_EQ(static_cast<int>(kUploadDataSize), | 498 CHECK_EQ(static_cast<int>(kUploadDataSize), |
471 file_util::WriteFile(file_path, kUploadData, kUploadDataSize)); | 499 file_util::WriteFile(file_path, kUploadData, kUploadDataSize)); |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1778 writes, arraysize(writes)); | 1806 writes, arraysize(writes)); |
1779 NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, | 1807 NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, |
1780 BoundNetLog(), GetParam(), NULL); | 1808 BoundNetLog(), GetParam(), NULL); |
1781 helper.RunToCompletion(&data); | 1809 helper.RunToCompletion(&data); |
1782 TransactionHelperResult out = helper.output(); | 1810 TransactionHelperResult out = helper.output(); |
1783 EXPECT_EQ(OK, out.rv); | 1811 EXPECT_EQ(OK, out.rv); |
1784 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1812 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
1785 EXPECT_EQ("hello!", out.response_data); | 1813 EXPECT_EQ("hello!", out.response_data); |
1786 } | 1814 } |
1787 | 1815 |
1816 // Test that a POST with a unreadable file fails. | |
1817 TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { | |
1818 scoped_ptr<SpdyFrame> req( | |
1819 spdy_util_.ConstructSpdyPost( | |
1820 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); | |
1821 MockWrite writes[] = { | |
1822 CreateMockWrite(*req), | |
mmenke
2013/11/07 20:29:00
I believe this can just be NULL, too? Since we ca
mmenke
2013/11/07 21:55:51
(To make it NULL, best to just get rid of writes c
tzik
2013/11/11 04:03:04
Done.
tzik
2013/11/11 04:03:04
Passing empty writes and using StaticSocketDataPro
| |
1823 }; | |
1824 MockRead reads[] = { | |
1825 MockRead(ASYNC, 0, 0) // EOF | |
1826 }; | |
1827 | |
1828 DelayedSocketData data(2, reads, arraysize(reads), writes, arraysize(writes)); | |
mmenke
2013/11/07 21:55:51
I believe this can just be a StaticSocketDataProvi
tzik
2013/11/11 05:33:52
Using it causes hang around line 213. (see reply a
| |
1829 NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), | |
1830 DEFAULT_PRIORITY, | |
1831 BoundNetLog(), GetParam(), NULL); | |
1832 helper.RunPreTestSetup(); | |
1833 helper.AddData(&data); | |
1834 helper.RunDefaultTest(); | |
1835 | |
1836 base::RunLoop().RunUntilIdle(); | |
1837 helper.VerifyDataNotConsumed(); | |
1838 EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); | |
1839 } | |
1840 | |
1788 // Test that a complex POST works. | 1841 // Test that a complex POST works. |
1789 TEST_P(SpdyNetworkTransactionTest, ComplexPost) { | 1842 TEST_P(SpdyNetworkTransactionTest, ComplexPost) { |
1790 scoped_ptr<SpdyFrame> req( | 1843 scoped_ptr<SpdyFrame> req( |
1791 spdy_util_.ConstructSpdyPost( | 1844 spdy_util_.ConstructSpdyPost( |
1792 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); | 1845 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
1793 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1846 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
1794 MockWrite writes[] = { | 1847 MockWrite writes[] = { |
1795 CreateMockWrite(*req), | 1848 CreateMockWrite(*req), |
1796 CreateMockWrite(*body), // POST upload frame | 1849 CreateMockWrite(*body), // POST upload frame |
1797 }; | 1850 }; |
(...skipping 4618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6416 // since we're send-stalled. | 6469 // since we're send-stalled. |
6417 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); | 6470 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
6418 | 6471 |
6419 // Read in WINDOW_UPDATE or SETTINGS frame. | 6472 // Read in WINDOW_UPDATE or SETTINGS frame. |
6420 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); | 6473 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); |
6421 rv = callback.WaitForResult(); | 6474 rv = callback.WaitForResult(); |
6422 helper.VerifyDataConsumed(); | 6475 helper.VerifyDataConsumed(); |
6423 } | 6476 } |
6424 | 6477 |
6425 } // namespace net | 6478 } // namespace net |
OLD | NEW |