Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: net/spdy/spdy_network_transaction_unittest.cc

Issue 39203004: [Net] Fix error handling on wrong file in UploadData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1822 MockWrite writes[] = {
1823 CreateMockWrite(*req),
1824 };
1825 MockRead reads[] = {
1826 CreateMockRead(*resp),
1827 };
1828
1829 DelayedSocketData data(2, reads, arraysize(reads), writes, arraysize(writes));
1830 NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(),
1831 DEFAULT_PRIORITY,
1832 BoundNetLog(), GetParam(), NULL);
1833 helper.RunPreTestSetup();
1834 helper.AddData(&data);
1835 helper.RunDefaultTest();
1836
1837 base::RunLoop().RunUntilIdle();
1838 helper.VerifyDataNotConsumed();
1839 EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv);
1840 }
1841
1788 // Test that a complex POST works. 1842 // Test that a complex POST works.
1789 TEST_P(SpdyNetworkTransactionTest, ComplexPost) { 1843 TEST_P(SpdyNetworkTransactionTest, ComplexPost) {
1790 scoped_ptr<SpdyFrame> req( 1844 scoped_ptr<SpdyFrame> req(
1791 spdy_util_.ConstructSpdyPost( 1845 spdy_util_.ConstructSpdyPost(
1792 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); 1846 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0));
1793 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1847 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1794 MockWrite writes[] = { 1848 MockWrite writes[] = {
1795 CreateMockWrite(*req), 1849 CreateMockWrite(*req),
1796 CreateMockWrite(*body), // POST upload frame 1850 CreateMockWrite(*body), // POST upload frame
1797 }; 1851 };
(...skipping 4612 matching lines...) Expand 10 before | Expand all | Expand 10 after
6410 // since we're send-stalled. 6464 // since we're send-stalled.
6411 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); 6465 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control());
6412 6466
6413 // Read in WINDOW_UPDATE or SETTINGS frame. 6467 // Read in WINDOW_UPDATE or SETTINGS frame.
6414 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); 6468 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7);
6415 rv = callback.WaitForResult(); 6469 rv = callback.WaitForResult();
6416 helper.VerifyDataConsumed(); 6470 helper.VerifyDataConsumed();
6417 } 6471 }
6418 6472
6419 } // namespace net 6473 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698