OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/base/upload_data.h" | 18 #include "net/base/upload_data.h" |
| 19 #include "net/base/upload_file_element_reader.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
21 | 22 |
22 namespace net { | 23 namespace net { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 const char kTestData[] = "0123456789"; | 27 const char kTestData[] = "0123456789"; |
27 const size_t kTestDataSize = arraysize(kTestData) - 1; | 28 const size_t kTestDataSize = arraysize(kTestData) - 1; |
28 const size_t kTestBufferSize = 1 << 14; // 16KB. | 29 const size_t kTestBufferSize = 1 << 14; // 16KB. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 file_util::Delete(temp_file_path, false); | 110 file_util::Delete(temp_file_path, false); |
110 } | 111 } |
111 | 112 |
112 TEST_F(UploadDataStreamTest, FileSmallerThanLength) { | 113 TEST_F(UploadDataStreamTest, FileSmallerThanLength) { |
113 FilePath temp_file_path; | 114 FilePath temp_file_path; |
114 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); | 115 ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); |
115 ASSERT_EQ(static_cast<int>(kTestDataSize), | 116 ASSERT_EQ(static_cast<int>(kTestDataSize), |
116 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 117 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
117 const uint64 kFakeSize = kTestDataSize*2; | 118 const uint64 kFakeSize = kTestDataSize*2; |
118 | 119 |
| 120 UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 121 overriding_content_length(kFakeSize); |
| 122 |
119 std::vector<UploadElement> elements; | 123 std::vector<UploadElement> elements; |
120 UploadElement element; | 124 UploadElement element; |
121 element.SetToFilePath(temp_file_path); | 125 element.SetToFilePath(temp_file_path); |
122 element.SetContentLength(kFakeSize); | |
123 elements.push_back(element); | 126 elements.push_back(element); |
124 upload_data_->SetElements(elements); | 127 upload_data_->SetElements(elements); |
125 | 128 |
126 scoped_ptr<UploadDataStream> stream(new UploadDataStream(upload_data_)); | 129 scoped_ptr<UploadDataStream> stream(new UploadDataStream(upload_data_)); |
127 ASSERT_EQ(OK, stream->Init()); | 130 ASSERT_EQ(OK, stream->Init()); |
128 EXPECT_FALSE(stream->IsInMemory()); | 131 EXPECT_FALSE(stream->IsInMemory()); |
129 ASSERT_TRUE(stream.get()); | 132 ASSERT_TRUE(stream.get()); |
130 EXPECT_EQ(kFakeSize, stream->size()); | 133 EXPECT_EQ(kFakeSize, stream->size()); |
131 EXPECT_EQ(0U, stream->position()); | 134 EXPECT_EQ(0U, stream->position()); |
132 EXPECT_FALSE(stream->IsEOF()); | 135 EXPECT_FALSE(stream->IsEOF()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 UploadDataStream stream(upload_data_); | 270 UploadDataStream stream(upload_data_); |
268 ASSERT_EQ(OK, stream.Init()); | 271 ASSERT_EQ(OK, stream.Init()); |
269 EXPECT_EQ(kTestDataSize, stream.size()); | 272 EXPECT_EQ(kTestDataSize, stream.size()); |
270 EXPECT_EQ(kTestData, ReadFromUploadDataStream(&stream)); | 273 EXPECT_EQ(kTestData, ReadFromUploadDataStream(&stream)); |
271 } | 274 } |
272 | 275 |
273 file_util::Delete(temp_file_path, false); | 276 file_util::Delete(temp_file_path, false); |
274 } | 277 } |
275 | 278 |
276 } // namespace net | 279 } // namespace net |
OLD | NEW |