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..4836d525ca41155d739288636f8339d09c63b43e 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. |
+ { |
+ scoped_ptr<UploadDataStream> stream(new UploadDataStream(upload_data_)); |
willchan no longer on Chromium
2012/05/21 18:17:35
Any special reason to use a scoped_ptr here?
satorux1
2012/05/21 19:37:00
Done.
|
+ ASSERT_EQ(OK, stream->Init()); |
+ EXPECT_EQ(kTestData, ReadFromUploadDataStream(stream.get())); |
+ } |
+ |
+ // Reuse |upload_data_| for another UploadDataStream, and confirm that the |
+ // file is read properly. |
+ { |
+ scoped_ptr<UploadDataStream> stream(new UploadDataStream(upload_data_)); |
willchan no longer on Chromium
2012/05/21 18:17:35
Ditto
satorux1
2012/05/21 19:37:00
Done.
|
+ ASSERT_EQ(OK, stream->Init()); |
+ EXPECT_EQ(kTestData, ReadFromUploadDataStream(stream.get())); |
+ } |
+ |
+ file_util::Delete(temp_file_path, false); |
+} |
+ |
} // namespace net |