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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 *(*upload->GetElementReaders())[5], blob_element1)); | 303 *(*upload->GetElementReaders())[5], blob_element1)); |
304 EXPECT_TRUE(AreElementsEqual( | 304 EXPECT_TRUE(AreElementsEqual( |
305 *(*upload->GetElementReaders())[6], blob_element2)); | 305 *(*upload->GetElementReaders())[6], blob_element2)); |
306 EXPECT_TRUE(AreElementsEqual( | 306 EXPECT_TRUE(AreElementsEqual( |
307 *(*upload->GetElementReaders())[7], upload_element2)); | 307 *(*upload->GetElementReaders())[7], upload_element2)); |
308 } | 308 } |
309 // Clean up for ASAN. | 309 // Clean up for ASAN. |
310 base::RunLoop().RunUntilIdle(); | 310 base::RunLoop().RunUntilIdle(); |
311 } | 311 } |
312 | 312 |
313 TEST(UploadDataStreamBuilderTest, CreateUploadDataStreamWithEmptyBlob) { | |
314 base::MessageLoop message_loop; | |
315 { | |
316 // Setup blob data for testing. | |
317 base::Time time1, time2; | |
318 base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &time1); | |
319 base::Time::FromString("Mon, 14 Nov 1994, 11:30:49 GMT", &time2); | |
320 | |
321 BlobStorageContext blob_storage_context; | |
322 | |
323 const std::string blob_id0("id-0"); | |
324 scoped_ptr<BlobDataBuilder> blob_data_builder( | |
325 new BlobDataBuilder(blob_id0)); | |
326 scoped_ptr<BlobDataHandle> handle1 = | |
327 blob_storage_context.AddFinishedBlob(blob_data_builder.get()); | |
328 | |
329 const std::string blob_id1("id-1"); | |
330 const std::string kBlobData = ""; | |
331 blob_data_builder.reset(new BlobDataBuilder(blob_id1)); | |
332 blob_data_builder->AppendData(kBlobData); | |
333 blob_data_builder->AppendFile( | |
334 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); | |
michaeln
2015/03/06 22:31:38
This isn't an empty blob?
cmumford
2015/03/09 20:05:48
Acknowledged.
| |
335 scoped_ptr<BlobDataHandle> handle2 = | |
336 blob_storage_context.AddFinishedBlob(blob_data_builder.get()); | |
337 | |
338 ResourceRequestBody::Element blob_element1, blob_element2; | |
339 blob_element1.SetToBytes(kBlobData.c_str(), kBlobData.size()); | |
340 blob_element2.SetToFilePathRange( | |
341 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); | |
mmenke
2015/03/06 20:54:40
The CL description indicates it supports empty fil
cmumford
2015/03/09 20:05:48
Acknowledged.
| |
342 | |
343 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); | |
344 scoped_ptr<net::UploadDataStream> upload(UploadDataStreamBuilder::Build( | |
345 request_body.get(), &blob_storage_context, NULL, | |
346 base::MessageLoopProxy::current().get())); | |
347 | |
348 request_body = new ResourceRequestBody(); | |
349 request_body->AppendBlob(blob_id1); | |
350 request_body->AppendBlob(blob_id1); | |
351 request_body->AppendBlob(blob_id1); | |
352 | |
353 upload = UploadDataStreamBuilder::Build( | |
354 request_body.get(), &blob_storage_context, NULL, | |
355 base::MessageLoopProxy::current().get()); | |
356 ASSERT_TRUE(upload->GetElementReaders()); | |
357 const auto& readers = *upload->GetElementReaders(); | |
358 ASSERT_EQ(6U, readers.size()); | |
359 EXPECT_TRUE(AreElementsEqual(*readers[0], blob_element1)); | |
michaeln
2015/03/06 22:31:38
Not sure about this test? It's making sure that bl
cmumford
2015/03/09 20:05:48
Yes, I see your point. I've modified the test to u
| |
360 EXPECT_TRUE(AreElementsEqual(*readers[1], blob_element2)); | |
361 EXPECT_TRUE(AreElementsEqual(*readers[2], blob_element1)); | |
362 EXPECT_TRUE(AreElementsEqual(*readers[3], blob_element2)); | |
363 EXPECT_TRUE(AreElementsEqual(*readers[4], blob_element1)); | |
364 EXPECT_TRUE(AreElementsEqual(*readers[5], blob_element2)); | |
365 } | |
366 // Clean up for ASAN. | |
367 base::RunLoop().RunUntilIdle(); | |
368 } | |
313 } // namespace content | 369 } // namespace content |
OLD | NEW |