Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: content/browser/loader/upload_data_stream_builder_unittest.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Snapshots now created by the Handle, one more rename Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_storage_context.h" 19 #include "storage/browser/blob/blob_storage_context.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 using storage::BlobData; 23 using storage::BlobDataBuilder;
24 using storage::BlobDataHandle; 24 using storage::BlobDataHandle;
25 using storage::BlobStorageContext; 25 using storage::BlobStorageContext;
26 26
27 namespace content { 27 namespace content {
28 namespace { 28 namespace {
29 29
30 bool AreElementsEqual(const net::UploadElementReader& reader, 30 bool AreElementsEqual(const net::UploadElementReader& reader,
31 const ResourceRequestBody::Element& element) { 31 const ResourceRequestBody::Element& element) {
32 switch(element.type()) { 32 switch(element.type()) {
33 case ResourceRequestBody::Element::TYPE_BYTES: { 33 case ResourceRequestBody::Element::TYPE_BYTES: {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 base::MessageLoop message_loop; 98 base::MessageLoop message_loop;
99 { 99 {
100 // Setup blob data for testing. 100 // Setup blob data for testing.
101 base::Time time1, time2; 101 base::Time time1, time2;
102 base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &time1); 102 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); 103 base::Time::FromString("Mon, 14 Nov 1994, 11:30:49 GMT", &time2);
104 104
105 BlobStorageContext blob_storage_context; 105 BlobStorageContext blob_storage_context;
106 106
107 const std::string blob_id0("id-0"); 107 const std::string blob_id0("id-0");
108 scoped_refptr<BlobData> blob_data(new BlobData(blob_id0)); 108 scoped_ptr<BlobDataBuilder> blob_data_builder(
109 new BlobDataBuilder(blob_id0));
109 scoped_ptr<BlobDataHandle> handle1 = 110 scoped_ptr<BlobDataHandle> handle1 =
110 blob_storage_context.AddFinishedBlob(blob_data.get()); 111 blob_storage_context.AddFinishedBlob(*blob_data_builder.get());
111 112
112 const std::string blob_id1("id-1"); 113 const std::string blob_id1("id-1");
113 blob_data = new BlobData(blob_id1); 114 blob_data_builder.reset(new BlobDataBuilder(blob_id1));
114 blob_data->AppendData("BlobData"); 115 blob_data_builder->AppendData("BlobData");
115 blob_data->AppendFile( 116 blob_data_builder->AppendFile(
116 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); 117 base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1);
117 scoped_ptr<BlobDataHandle> handle2 = 118 scoped_ptr<BlobDataHandle> handle2 =
118 blob_storage_context.AddFinishedBlob(blob_data.get()); 119 blob_storage_context.AddFinishedBlob(*blob_data_builder.get());
119 120
120 // Setup upload data elements for comparison. 121 // Setup upload data elements for comparison.
122 auto blob_data = blob_data_builder->Build();
121 ResourceRequestBody::Element blob_element1, blob_element2; 123 ResourceRequestBody::Element blob_element1, blob_element2;
122 blob_element1.SetToBytes( 124 blob_element1.SetToBytes(
123 blob_data->items().at(0).bytes() + 125 blob_data->items().at(0)->bytes() +
124 static_cast<int>(blob_data->items().at(0).offset()), 126 static_cast<int>(blob_data->items().at(0)->offset()),
125 static_cast<int>(blob_data->items().at(0).length())); 127 static_cast<int>(blob_data->items().at(0)->length()));
126 blob_element2.SetToFilePathRange( 128 blob_element2.SetToFilePathRange(
127 blob_data->items().at(1).path(), 129 blob_data->items().at(1)->path(), blob_data->items().at(1)->offset(),
128 blob_data->items().at(1).offset(), 130 blob_data->items().at(1)->length(),
129 blob_data->items().at(1).length(), 131 blob_data->items().at(1)->expected_modification_time());
130 blob_data->items().at(1).expected_modification_time());
131 132
132 ResourceRequestBody::Element upload_element1, upload_element2; 133 ResourceRequestBody::Element upload_element1, upload_element2;
133 upload_element1.SetToBytes("Hello", 5); 134 upload_element1.SetToBytes("Hello", 5);
134 upload_element2.SetToFilePathRange( 135 upload_element2.SetToFilePathRange(
135 base::FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2); 136 base::FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2);
136 137
137 // Test no blob reference. 138 // Test no blob reference.
138 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); 139 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody());
139 request_body->AppendBytes( 140 request_body->AppendBytes(
140 upload_element1.bytes(), 141 upload_element1.bytes(),
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 EXPECT_TRUE(AreElementsEqual( 308 EXPECT_TRUE(AreElementsEqual(
308 *(*upload->GetElementReaders())[6], blob_element2)); 309 *(*upload->GetElementReaders())[6], blob_element2));
309 EXPECT_TRUE(AreElementsEqual( 310 EXPECT_TRUE(AreElementsEqual(
310 *(*upload->GetElementReaders())[7], upload_element2)); 311 *(*upload->GetElementReaders())[7], upload_element2));
311 } 312 }
312 // Clean up for ASAN. 313 // Clean up for ASAN.
313 base::RunLoop().RunUntilIdle(); 314 base::RunLoop().RunUntilIdle();
314 } 315 }
315 316
316 } // namespace content 317 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698