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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 base::Time time1, time2; | 102 base::Time time1, time2; |
103 base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &time1); | 103 base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &time1); |
104 base::Time::FromString("Mon, 14 Nov 1994, 11:30:49 GMT", &time2); | 104 base::Time::FromString("Mon, 14 Nov 1994, 11:30:49 GMT", &time2); |
105 | 105 |
106 BlobStorageContext blob_storage_context; | 106 BlobStorageContext blob_storage_context; |
107 | 107 |
108 const std::string blob_id0("id-0"); | 108 const std::string blob_id0("id-0"); |
109 scoped_ptr<BlobDataBuilder> blob_data_builder( | 109 scoped_ptr<BlobDataBuilder> blob_data_builder( |
110 new BlobDataBuilder(blob_id0)); | 110 new BlobDataBuilder(blob_id0)); |
111 scoped_ptr<BlobDataHandle> handle1 = | 111 scoped_ptr<BlobDataHandle> handle1 = |
112 blob_storage_context.AddFinishedBlob(*blob_data_builder.get()); | 112 blob_storage_context.AddFinishedBlob(blob_data_builder.get()); |
113 | 113 |
114 const std::string blob_id1("id-1"); | 114 const std::string blob_id1("id-1"); |
| 115 const std::string kBlobData = "BlobData"; |
115 blob_data_builder.reset(new BlobDataBuilder(blob_id1)); | 116 blob_data_builder.reset(new BlobDataBuilder(blob_id1)); |
116 blob_data_builder->AppendData("BlobData"); | 117 blob_data_builder->AppendData(kBlobData); |
117 blob_data_builder->AppendFile( | 118 blob_data_builder->AppendFile( |
118 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); | 119 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); |
119 scoped_ptr<BlobDataHandle> handle2 = | 120 scoped_ptr<BlobDataHandle> handle2 = |
120 blob_storage_context.AddFinishedBlob(*blob_data_builder.get()); | 121 blob_storage_context.AddFinishedBlob(blob_data_builder.get()); |
121 | 122 |
122 // Setup upload data elements for comparison. | 123 // Setup upload data elements for comparison. |
123 auto blob_data = blob_data_builder->BuildSnapshot(); | |
124 ResourceRequestBody::Element blob_element1, blob_element2; | 124 ResourceRequestBody::Element blob_element1, blob_element2; |
125 blob_element1.SetToBytes( | 125 blob_element1.SetToBytes(kBlobData.c_str(), kBlobData.size()); |
126 blob_data->items().at(0)->bytes() + | |
127 static_cast<int>(blob_data->items().at(0)->offset()), | |
128 static_cast<int>(blob_data->items().at(0)->length())); | |
129 blob_element2.SetToFilePathRange( | 126 blob_element2.SetToFilePathRange( |
130 blob_data->items().at(1)->path(), blob_data->items().at(1)->offset(), | 127 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); |
131 blob_data->items().at(1)->length(), | |
132 blob_data->items().at(1)->expected_modification_time()); | |
133 | 128 |
134 ResourceRequestBody::Element upload_element1, upload_element2; | 129 ResourceRequestBody::Element upload_element1, upload_element2; |
135 upload_element1.SetToBytes("Hello", 5); | 130 upload_element1.SetToBytes("Hello", 5); |
136 upload_element2.SetToFilePathRange( | 131 upload_element2.SetToFilePathRange( |
137 base::FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2); | 132 base::FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2); |
138 | 133 |
139 // Test no blob reference. | 134 // Test no blob reference. |
140 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); | 135 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); |
141 request_body->AppendBytes( | 136 request_body->AppendBytes( |
142 upload_element1.bytes(), | 137 upload_element1.bytes(), |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 EXPECT_TRUE(AreElementsEqual( | 304 EXPECT_TRUE(AreElementsEqual( |
310 *(*upload->GetElementReaders())[6], blob_element2)); | 305 *(*upload->GetElementReaders())[6], blob_element2)); |
311 EXPECT_TRUE(AreElementsEqual( | 306 EXPECT_TRUE(AreElementsEqual( |
312 *(*upload->GetElementReaders())[7], upload_element2)); | 307 *(*upload->GetElementReaders())[7], upload_element2)); |
313 } | 308 } |
314 // Clean up for ASAN. | 309 // Clean up for ASAN. |
315 base::RunLoop().RunUntilIdle(); | 310 base::RunLoop().RunUntilIdle(); |
316 } | 311 } |
317 | 312 |
318 } // namespace content | 313 } // namespace content |
OLD | NEW |