| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/common/resource_request_body.h" | 15 #include "content/common/resource_request_body.h" |
| 16 #include "net/base/upload_bytes_element_reader.h" | 16 #include "net/base/upload_bytes_element_reader.h" |
| 17 #include "net/base/upload_data_stream.h" | 17 #include "net/base/upload_data_stream.h" |
| 18 #include "net/base/upload_file_element_reader.h" | 18 #include "net/base/upload_file_element_reader.h" |
| 19 #include "storage/browser/blob/blob_data_builder.h" |
| 19 #include "storage/browser/blob/blob_storage_context.h" | 20 #include "storage/browser/blob/blob_storage_context.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 using storage::BlobData; | 24 using storage::BlobDataBuilder; |
| 24 using storage::BlobDataHandle; | 25 using storage::BlobDataHandle; |
| 25 using storage::BlobStorageContext; | 26 using storage::BlobStorageContext; |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 bool AreElementsEqual(const net::UploadElementReader& reader, | 31 bool AreElementsEqual(const net::UploadElementReader& reader, |
| 31 const ResourceRequestBody::Element& element) { | 32 const ResourceRequestBody::Element& element) { |
| 32 switch(element.type()) { | 33 switch(element.type()) { |
| 33 case ResourceRequestBody::Element::TYPE_BYTES: { | 34 case ResourceRequestBody::Element::TYPE_BYTES: { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 base::MessageLoop message_loop; | 99 base::MessageLoop message_loop; |
| 99 { | 100 { |
| 100 // Setup blob data for testing. | 101 // Setup blob data for testing. |
| 101 base::Time time1, time2; | 102 base::Time time1, time2; |
| 102 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); |
| 103 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); |
| 104 | 105 |
| 105 BlobStorageContext blob_storage_context; | 106 BlobStorageContext blob_storage_context; |
| 106 | 107 |
| 107 const std::string blob_id0("id-0"); | 108 const std::string blob_id0("id-0"); |
| 108 scoped_refptr<BlobData> blob_data(new BlobData(blob_id0)); | 109 scoped_ptr<BlobDataBuilder> blob_data_builder( |
| 110 new BlobDataBuilder(blob_id0)); |
| 109 scoped_ptr<BlobDataHandle> handle1 = | 111 scoped_ptr<BlobDataHandle> handle1 = |
| 110 blob_storage_context.AddFinishedBlob(blob_data.get()); | 112 blob_storage_context.AddFinishedBlob(*blob_data_builder.get()); |
| 111 | 113 |
| 112 const std::string blob_id1("id-1"); | 114 const std::string blob_id1("id-1"); |
| 113 blob_data = new BlobData(blob_id1); | 115 blob_data_builder.reset(new BlobDataBuilder(blob_id1)); |
| 114 blob_data->AppendData("BlobData"); | 116 blob_data_builder->AppendData("BlobData"); |
| 115 blob_data->AppendFile( | 117 blob_data_builder->AppendFile( |
| 116 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); | 118 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); |
| 117 scoped_ptr<BlobDataHandle> handle2 = | 119 scoped_ptr<BlobDataHandle> handle2 = |
| 118 blob_storage_context.AddFinishedBlob(blob_data.get()); | 120 blob_storage_context.AddFinishedBlob(*blob_data_builder.get()); |
| 119 | 121 |
| 120 // Setup upload data elements for comparison. | 122 // Setup upload data elements for comparison. |
| 123 auto blob_data = blob_data_builder->BuildSnapshot(); |
| 121 ResourceRequestBody::Element blob_element1, blob_element2; | 124 ResourceRequestBody::Element blob_element1, blob_element2; |
| 122 blob_element1.SetToBytes( | 125 blob_element1.SetToBytes( |
| 123 blob_data->items().at(0).bytes() + | 126 blob_data->items().at(0)->bytes() + |
| 124 static_cast<int>(blob_data->items().at(0).offset()), | 127 static_cast<int>(blob_data->items().at(0)->offset()), |
| 125 static_cast<int>(blob_data->items().at(0).length())); | 128 static_cast<int>(blob_data->items().at(0)->length())); |
| 126 blob_element2.SetToFilePathRange( | 129 blob_element2.SetToFilePathRange( |
| 127 blob_data->items().at(1).path(), | 130 blob_data->items().at(1)->path(), blob_data->items().at(1)->offset(), |
| 128 blob_data->items().at(1).offset(), | 131 blob_data->items().at(1)->length(), |
| 129 blob_data->items().at(1).length(), | 132 blob_data->items().at(1)->expected_modification_time()); |
| 130 blob_data->items().at(1).expected_modification_time()); | |
| 131 | 133 |
| 132 ResourceRequestBody::Element upload_element1, upload_element2; | 134 ResourceRequestBody::Element upload_element1, upload_element2; |
| 133 upload_element1.SetToBytes("Hello", 5); | 135 upload_element1.SetToBytes("Hello", 5); |
| 134 upload_element2.SetToFilePathRange( | 136 upload_element2.SetToFilePathRange( |
| 135 base::FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2); | 137 base::FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2); |
| 136 | 138 |
| 137 // Test no blob reference. | 139 // Test no blob reference. |
| 138 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); | 140 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); |
| 139 request_body->AppendBytes( | 141 request_body->AppendBytes( |
| 140 upload_element1.bytes(), | 142 upload_element1.bytes(), |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 EXPECT_TRUE(AreElementsEqual( | 309 EXPECT_TRUE(AreElementsEqual( |
| 308 *(*upload->GetElementReaders())[6], blob_element2)); | 310 *(*upload->GetElementReaders())[6], blob_element2)); |
| 309 EXPECT_TRUE(AreElementsEqual( | 311 EXPECT_TRUE(AreElementsEqual( |
| 310 *(*upload->GetElementReaders())[7], upload_element2)); | 312 *(*upload->GetElementReaders())[7], upload_element2)); |
| 311 } | 313 } |
| 312 // Clean up for ASAN. | 314 // Clean up for ASAN. |
| 313 base::RunLoop().RunUntilIdle(); | 315 base::RunLoop().RunUntilIdle(); |
| 314 } | 316 } |
| 315 | 317 |
| 316 } // namespace content | 318 } // namespace content |
| OLD | NEW |