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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_network_transaction_unittest.cc
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index 780d1476be378b625414c9241b666c6a3a76b311..f58f64bd14d5382ee636fe1397a6424918935c39 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -12,6 +12,7 @@
#include "base/memory/scoped_vector.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
+#include "base/test/test_file_util.h"
#include "net/base/auth.h"
#include "net/base/net_log_unittest.h"
#include "net/base/request_priority.h"
@@ -459,6 +460,33 @@ class SpdyNetworkTransactionTest
return google_post_request_;
}
+ const HttpRequestInfo& CreateUnreadableFilePostRequest() {
+ if (google_post_request_initialized_)
+ return google_post_request_;
+
+ base::FilePath file_path;
+ CHECK(file_util::CreateTemporaryFileInDir(temp_dir_.path(), &file_path));
+ CHECK_EQ(static_cast<int>(kUploadDataSize),
+ file_util::WriteFile(file_path, kUploadData, kUploadDataSize));
+ CHECK(file_util::MakeFileUnreadable(file_path));
+
+ ScopedVector<UploadElementReader> element_readers;
+ element_readers.push_back(
+ new UploadFileElementReader(base::MessageLoopProxy::current().get(),
+ file_path,
+ 0,
+ kUploadDataSize,
+ base::Time()));
+ upload_data_stream_.reset(
+ new UploadDataStream(element_readers.Pass(), 0));
+
+ google_post_request_.method = "POST";
+ google_post_request_.url = GURL(kDefaultURL);
+ google_post_request_.upload_data_stream = upload_data_stream_.get();
+ google_post_request_initialized_ = true;
+ return google_post_request_;
+ }
+
const HttpRequestInfo& CreateComplexPostRequest() {
if (!google_post_request_initialized_) {
const int kFileRangeOffset = 1;
@@ -1785,6 +1813,28 @@ TEST_P(SpdyNetworkTransactionTest, FilePost) {
EXPECT_EQ("hello!", out.response_data);
}
+// Test that a POST with a unreadable file fails.
+TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) {
+ MockWrite writes[] = {
+ MockWrite(ASYNC, 0, 0) // EOF
+ };
+ MockRead reads[] = {
+ MockRead(ASYNC, 0, 0) // EOF
+ };
+
+ DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
+ NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(),
+ DEFAULT_PRIORITY,
+ BoundNetLog(), GetParam(), NULL);
+ helper.RunPreTestSetup();
+ helper.AddData(&data);
+ helper.RunDefaultTest();
+
+ base::RunLoop().RunUntilIdle();
+ helper.VerifyDataNotConsumed();
+ EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv);
+}
+
// Test that a complex POST works.
TEST_P(SpdyNetworkTransactionTest, ComplexPost) {
scoped_ptr<SpdyFrame> req(
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698