summaryrefslogtreecommitdiffstats
path: root/net/http/http_network_transaction_unittest.cc
diff options
context:
space:
mode:
authorvandebo@google.com <vandebo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 21:25:33 +0000
committervandebo@google.com <vandebo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 21:25:33 +0000
commit95d88ffe2faa5ccceb1c4619f4e316fb7ad4d70f (patch)
treedb13d8ae72b1e28783fa0571b08e31b4b65c8358 /net/http/http_network_transaction_unittest.cc
parent268b02fa13ca56e7b32f0b6a445ce5758a1dfc3c (diff)
downloadchromium_src-95d88ffe2faa5ccceb1c4619f4e316fb7ad4d70f.zip
chromium_src-95d88ffe2faa5ccceb1c4619f4e316fb7ad4d70f.tar.gz
chromium_src-95d88ffe2faa5ccceb1c4619f4e316fb7ad4d70f.tar.bz2
Add a notion of 'eof' to UploadDataStream, replacing the use of its size property for detecting when an upload is finished.
While this does prevent the crash described in the bug from occurring, this doesn't fully solve the problem as now the affected uploads don't complete. Fully resolving the issue will require implementing the chunked transfer encoding for requests. Patch from Vernon Tang <vt@foilhead.net>, original review: http://codereview.chromium.org/555194 BUG=33501 TEST=Create a file with a non-zero size and select that file in an HTML-based uploader. Before starting the upload, remove read permissions from that file. Check that the upload doesn't cause the browser to crash or hang. net_unittests: HttpNetworkTransactionTest.UploadFileSmallerThanLength, UploadDataStreamTest.* Review URL: http://codereview.chromium.org/578004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38129 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_network_transaction_unittest.cc')
-rw-r--r--net/http/http_network_transaction_unittest.cc58
1 files changed, 57 insertions, 1 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 9639457..4a71ab1 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -1,10 +1,13 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <math.h> // ceil
+#include <vector>
#include "base/compiler_specific.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
#include "net/base/completion_callback.h"
#include "net/base/mock_host_resolver.h"
#include "net/base/request_priority.h"
@@ -3966,4 +3969,57 @@ TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
EXPECT_EQ("", out.response_data);
}
+TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) {
+ SessionDependencies session_deps;
+ scoped_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(CreateSession(&session_deps)));
+
+ HttpRequestInfo request;
+ request.method = "POST";
+ request.url = GURL("http://www.google.com/upload");
+ request.upload_data = new UploadData;
+ request.load_flags = 0;
+
+ FilePath temp_file_path;
+ ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
+ const uint64 kFakeSize = 100000; // file is actually blank
+
+ std::vector<UploadData::Element> elements;
+ UploadData::Element element;
+ element.SetToFilePath(temp_file_path);
+ element.SetContentLength(kFakeSize);
+ elements.push_back(element);
+ request.upload_data->set_elements(elements);
+ EXPECT_EQ(kFakeSize, request.upload_data->GetContentLength());
+
+ MockRead data_reads[] = {
+ MockRead("HTTP/1.0 200 OK\r\n\r\n"),
+ MockRead("hello world"),
+ MockRead(false, OK),
+ };
+ StaticSocketDataProvider data(data_reads, NULL);
+ session_deps.socket_factory.AddSocketDataProvider(&data);
+
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&request, &callback, NULL);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ rv = callback.WaitForResult();
+ EXPECT_EQ(OK, rv);
+
+ const HttpResponseInfo* response = trans->GetResponseInfo();
+ EXPECT_TRUE(response != NULL);
+
+ EXPECT_TRUE(response->headers != NULL);
+ EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
+
+ std::string response_data;
+ rv = ReadTransaction(trans.get(), &response_data);
+ EXPECT_EQ(OK, rv);
+ EXPECT_EQ("hello world", response_data);
+
+ file_util::Delete(temp_file_path, false);
+}
+
} // namespace net