OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/loader/upload_data_stream_builder.h" | 5 #include "content/browser/loader/upload_data_stream_builder.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/macros.h" |
12 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
13 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
14 #include "base/time/time.h" | 17 #include "base/time/time.h" |
15 #include "content/common/resource_request_body.h" | 18 #include "content/common/resource_request_body.h" |
16 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
18 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
19 #include "net/base/upload_bytes_element_reader.h" | 22 #include "net/base/upload_bytes_element_reader.h" |
20 #include "net/base/upload_data_stream.h" | 23 #include "net/base/upload_data_stream.h" |
21 #include "net/base/upload_file_element_reader.h" | 24 #include "net/base/upload_file_element_reader.h" |
(...skipping 12 matching lines...) Expand all Loading... |
34 | 37 |
35 TEST(UploadDataStreamBuilderTest, CreateUploadDataStream) { | 38 TEST(UploadDataStreamBuilderTest, CreateUploadDataStream) { |
36 base::MessageLoop message_loop; | 39 base::MessageLoop message_loop; |
37 { | 40 { |
38 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; | 41 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; |
39 | 42 |
40 const std::string kBlob = "blobuuid"; | 43 const std::string kBlob = "blobuuid"; |
41 const std::string kBlobData = "blobdata"; | 44 const std::string kBlobData = "blobdata"; |
42 const char kData[] = "123"; | 45 const char kData[] = "123"; |
43 const base::FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc"); | 46 const base::FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc"); |
44 const uint64 kFileOffset = 10U; | 47 const uint64_t kFileOffset = 10U; |
45 const uint64 kFileLength = 100U; | 48 const uint64_t kFileLength = 100U; |
46 const base::Time kFileTime = base::Time::FromDoubleT(999); | 49 const base::Time kFileTime = base::Time::FromDoubleT(999); |
47 const int64 kIdentifier = 12345; | 50 const int64_t kIdentifier = 12345; |
48 | 51 |
49 BlobStorageContext context; | 52 BlobStorageContext context; |
50 BlobDataBuilder builder(kBlob); | 53 BlobDataBuilder builder(kBlob); |
51 builder.AppendData(kBlobData); | 54 builder.AppendData(kBlobData); |
52 scoped_ptr<BlobDataHandle> handle = context.AddFinishedBlob(&builder); | 55 scoped_ptr<BlobDataHandle> handle = context.AddFinishedBlob(&builder); |
53 | 56 |
54 request_body->AppendBytes(kData, arraysize(kData) - 1); | 57 request_body->AppendBytes(kData, arraysize(kData) - 1); |
55 request_body->AppendFileRange(base::FilePath(kFilePath), kFileOffset, | 58 request_body->AppendFileRange(base::FilePath(kFilePath), kFileOffset, |
56 kFileLength, kFileTime); | 59 kFileLength, kFileTime); |
57 request_body->AppendBlob(kBlob); | 60 request_body->AppendBlob(kBlob); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 154 } |
152 | 155 |
153 TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) { | 156 TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) { |
154 base::MessageLoopForIO message_loop; | 157 base::MessageLoopForIO message_loop; |
155 { | 158 { |
156 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; | 159 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; |
157 | 160 |
158 const std::string kBlob = "blobuuid"; | 161 const std::string kBlob = "blobuuid"; |
159 const std::string kBlobData = "blobdata"; | 162 const std::string kBlobData = "blobdata"; |
160 const int kBlobDataLength = 8; | 163 const int kBlobDataLength = 8; |
161 const int64 kIdentifier = 12345; | 164 const int64_t kIdentifier = 12345; |
162 | 165 |
163 BlobStorageContext blob_storage_context; | 166 BlobStorageContext blob_storage_context; |
164 BlobDataBuilder builder(kBlob); | 167 BlobDataBuilder builder(kBlob); |
165 builder.AppendData(kBlobData); | 168 builder.AppendData(kBlobData); |
166 scoped_ptr<BlobDataHandle> handle = | 169 scoped_ptr<BlobDataHandle> handle = |
167 blob_storage_context.AddFinishedBlob(&builder); | 170 blob_storage_context.AddFinishedBlob(&builder); |
168 request_body->AppendBlob(kBlob); | 171 request_body->AppendBlob(kBlob); |
169 request_body->set_identifier(kIdentifier); | 172 request_body->set_identifier(kIdentifier); |
170 | 173 |
171 scoped_ptr<net::UploadDataStream> upload(UploadDataStreamBuilder::Build( | 174 scoped_ptr<net::UploadDataStream> upload(UploadDataStreamBuilder::Build( |
(...skipping 22 matching lines...) Expand all Loading... |
194 result = | 197 result = |
195 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); | 198 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); |
196 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result)); | 199 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result)); |
197 EXPECT_EQ(0, | 200 EXPECT_EQ(0, |
198 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); | 201 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); |
199 } | 202 } |
200 // Clean up for ASAN. | 203 // Clean up for ASAN. |
201 base::RunLoop().RunUntilIdle(); | 204 base::RunLoop().RunUntilIdle(); |
202 } | 205 } |
203 } // namespace content | 206 } // namespace content |
OLD | NEW |