OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/upload_data_stream.h" | 5 #include "net/base/upload_data_stream.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 ASSERT_TRUE(stream.get()); | 43 ASSERT_TRUE(stream.get()); |
44 EXPECT_TRUE(stream->eof()); | 44 EXPECT_TRUE(stream->eof()); |
45 } | 45 } |
46 | 46 |
47 TEST_F(UploadDataStreamTest, ConsumeAll) { | 47 TEST_F(UploadDataStreamTest, ConsumeAll) { |
48 upload_data_->AppendBytes(kTestData, kTestDataSize); | 48 upload_data_->AppendBytes(kTestData, kTestDataSize); |
49 scoped_ptr<UploadDataStream> stream( | 49 scoped_ptr<UploadDataStream> stream( |
50 UploadDataStream::Create(upload_data_, NULL)); | 50 UploadDataStream::Create(upload_data_, NULL)); |
51 ASSERT_TRUE(stream.get()); | 51 ASSERT_TRUE(stream.get()); |
52 while (!stream->eof()) { | 52 while (!stream->eof()) { |
53 stream->DidConsume(stream->buf_len()); | 53 stream->MarkConsumedAndFillBuffer(stream->buf_len()); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 TEST_F(UploadDataStreamTest, FileSmallerThanLength) { | 57 TEST_F(UploadDataStreamTest, FileSmallerThanLength) { |
58 FilePath temp_file_path; | 58 FilePath temp_file_path; |
59 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); | 59 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); |
60 ASSERT_EQ(kTestDataSize, file_util::WriteFile(temp_file_path, | 60 ASSERT_EQ(kTestDataSize, file_util::WriteFile(temp_file_path, |
61 kTestData, kTestDataSize)); | 61 kTestData, kTestDataSize)); |
62 const uint64 kFakeSize = kTestDataSize*2; | 62 const uint64 kFakeSize = kTestDataSize*2; |
63 | 63 |
64 std::vector<UploadData::Element> elements; | 64 std::vector<UploadData::Element> elements; |
65 UploadData::Element element; | 65 UploadData::Element element; |
66 element.SetToFilePath(temp_file_path); | 66 element.SetToFilePath(temp_file_path); |
67 element.SetContentLength(kFakeSize); | 67 element.SetContentLength(kFakeSize); |
68 elements.push_back(element); | 68 elements.push_back(element); |
69 upload_data_->SetElements(elements); | 69 upload_data_->SetElements(elements); |
70 EXPECT_EQ(kFakeSize, upload_data_->GetContentLength()); | 70 EXPECT_EQ(kFakeSize, upload_data_->GetContentLength()); |
71 | 71 |
72 scoped_ptr<UploadDataStream> stream( | 72 scoped_ptr<UploadDataStream> stream( |
73 UploadDataStream::Create(upload_data_, NULL)); | 73 UploadDataStream::Create(upload_data_, NULL)); |
74 ASSERT_TRUE(stream.get()); | 74 ASSERT_TRUE(stream.get()); |
75 EXPECT_FALSE(stream->eof()); | 75 EXPECT_FALSE(stream->eof()); |
76 uint64 read_counter = 0; | 76 uint64 read_counter = 0; |
77 while (!stream->eof()) { | 77 while (!stream->eof()) { |
78 read_counter += stream->buf_len(); | 78 read_counter += stream->buf_len(); |
79 stream->DidConsume(stream->buf_len()); | 79 stream->MarkConsumedAndFillBuffer(stream->buf_len()); |
80 } | 80 } |
81 // UpdateDataStream will pad out the file with 0 bytes so that the HTTP | 81 // UpdateDataStream will pad out the file with 0 bytes so that the HTTP |
82 // transaction doesn't hang. Therefore we expected the full size. | 82 // transaction doesn't hang. Therefore we expected the full size. |
83 EXPECT_EQ(read_counter, stream->size()); | 83 EXPECT_EQ(read_counter, stream->size()); |
84 | 84 |
85 file_util::Delete(temp_file_path, false); | 85 file_util::Delete(temp_file_path, false); |
86 } | 86 } |
87 | 87 |
88 void UploadDataStreamTest::FileChangedHelper(const FilePath& file_path, | 88 void UploadDataStreamTest::FileChangedHelper(const FilePath& file_path, |
89 const base::Time& time, | 89 const base::Time& time, |
(...skipping 27 matching lines...) Expand all Loading... |
117 | 117 |
118 // Test file changed. | 118 // Test file changed. |
119 FileChangedHelper(temp_file_path, | 119 FileChangedHelper(temp_file_path, |
120 file_info.last_modified - base::TimeDelta::FromSeconds(1), | 120 file_info.last_modified - base::TimeDelta::FromSeconds(1), |
121 true); | 121 true); |
122 | 122 |
123 file_util::Delete(temp_file_path, false); | 123 file_util::Delete(temp_file_path, false); |
124 } | 124 } |
125 | 125 |
126 } // namespace net | 126 } // namespace net |
OLD | NEW |