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

Unified Diff: net/base/upload_data_stream_unittest.cc

Issue 10408042: net: Fix a regression that broke file uploading with http authentication (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 7 months 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
« net/base/upload_data.cc ('K') | « net/base/upload_data.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/upload_data_stream_unittest.cc
diff --git a/net/base/upload_data_stream_unittest.cc b/net/base/upload_data_stream_unittest.cc
index 078f2007bbece58a34bff7c790a2ed4a2ae0fd68..2715e73d18d04e1bb03a53159a183fdca0d818c0 100644
--- a/net/base/upload_data_stream_unittest.cc
+++ b/net/base/upload_data_stream_unittest.cc
@@ -27,6 +27,17 @@ const char kTestData[] = "0123456789";
const size_t kTestDataSize = arraysize(kTestData) - 1;
const size_t kTestBufferSize = 1 << 14; // 16KB.
+// Reads data from the upload data stream, and returns the data as string.
+std::string ReadFromUploadDataStream(UploadDataStream* stream) {
+ std::string data_read;
+ scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize);
+ while (!stream->IsEOF()) {
+ const int bytes_read = stream->Read(buf, kTestBufferSize);
+ data_read.append(buf->data(), bytes_read);
+ }
+ return data_read;
+}
+
} // namespace
class UploadDataStreamTest : public PlatformTest {
@@ -144,4 +155,36 @@ TEST_F(UploadDataStreamTest, FileChanged) {
file_util::Delete(temp_file_path, false);
}
+TEST_F(UploadDataStreamTest, UploadDataReused) {
+ FilePath temp_file_path;
+ ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
+ ASSERT_EQ(static_cast<int>(kTestDataSize),
+ file_util::WriteFile(temp_file_path, kTestData, kTestDataSize));
+
+ // Prepare |upload_data_| that contains a file.
+ std::vector<UploadData::Element> elements;
+ UploadData::Element element;
+ element.SetToFilePath(temp_file_path);
+ elements.push_back(element);
+ upload_data_->SetElements(elements);
+ EXPECT_EQ(kTestDataSize, upload_data_->GetContentLengthSync());
+
+ // Confirm that the file is read properly.
+ {
+ UploadDataStream stream(upload_data_);
+ ASSERT_EQ(OK, stream.Init());
+ EXPECT_EQ(kTestData, ReadFromUploadDataStream(&stream));
+ }
+
+ // Reuse |upload_data_| for another UploadDataStream, and confirm that the
+ // file is read properly.
+ {
+ UploadDataStream stream(upload_data_);
+ ASSERT_EQ(OK, stream.Init());
+ EXPECT_EQ(kTestData, ReadFromUploadDataStream(&stream));
+ }
+
+ file_util::Delete(temp_file_path, false);
+}
+
} // namespace net
« net/base/upload_data.cc ('K') | « net/base/upload_data.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698