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

Side by Side Diff: webkit/blob/blob_storage_controller_unittest.cc

Issue 3282003: Support handling blob URL and resolve blob references in upload data.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/time.h" 6 #include "base/time.h"
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "net/base/upload_data.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/blob/blob_data.h" 11 #include "webkit/blob/blob_data.h"
11 #include "webkit/blob/blob_storage_controller.h" 12 #include "webkit/blob/blob_storage_controller.h"
12 13
14 using net::UploadData;
15
13 namespace webkit_blob { 16 namespace webkit_blob {
14 17
15 TEST(BlobStorageControllerTest, RegisterBlobUrl) { 18 TEST(BlobStorageControllerTest, RegisterBlobUrl) {
16 // Setup a set of blob data for testing. 19 // Setup a set of blob data for testing.
17 base::Time time1, time2; 20 base::Time time1, time2;
18 base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", &time1); 21 base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", &time1);
19 base::Time::FromString(L"Mon, 14 Nov 1994, 11:30:49 GMT", &time2); 22 base::Time::FromString(L"Mon, 14 Nov 1994, 11:30:49 GMT", &time2);
20 23
21 scoped_refptr<BlobData> blob_data1 = new BlobData(); 24 scoped_refptr<BlobData> blob_data1 = new BlobData();
22 blob_data1->AppendData("Data1"); 25 blob_data1->AppendData("Data1");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 EXPECT_TRUE(*blob_data_found == *canonicalized_blob_data2); 64 EXPECT_TRUE(*blob_data_found == *canonicalized_blob_data2);
62 65
63 // Test registering a blob URL referring to existent blob URL. 66 // Test registering a blob URL referring to existent blob URL.
64 GURL blob_url3("blob://url_3"); 67 GURL blob_url3("blob://url_3");
65 blob_storage_controller->RegisterBlobUrlFrom(blob_url3, blob_url1); 68 blob_storage_controller->RegisterBlobUrlFrom(blob_url3, blob_url1);
66 69
67 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url3); 70 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url3);
68 ASSERT_TRUE(blob_data_found != NULL); 71 ASSERT_TRUE(blob_data_found != NULL);
69 EXPECT_TRUE(*blob_data_found == *blob_data1); 72 EXPECT_TRUE(*blob_data_found == *blob_data1);
70 73
71 // Test registering a blob URL referring to non-existent blob URL.
72 GURL nonexistent_blob_url("blob://url_none");
73 GURL blob_url4("blob://url_4");
74 blob_storage_controller->RegisterBlobUrlFrom(blob_url4, nonexistent_blob_url);
75
76 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url4);
77 EXPECT_FALSE(blob_data_found != NULL);
78
79 // Test unregistering a blob URL. 74 // Test unregistering a blob URL.
80 blob_storage_controller->UnregisterBlobUrl(blob_url3); 75 blob_storage_controller->UnregisterBlobUrl(blob_url3);
81 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url3); 76 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url3);
82 EXPECT_FALSE(blob_data_found != NULL); 77 EXPECT_TRUE(!blob_data_found);
78 }
79
80 TEST(BlobStorageControllerTest, ResolveBlobReferencesInUploadData) {
81 // Setup blob data for testing.
82 base::Time time1, time2;
83 base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", &time1);
84 base::Time::FromString(L"Mon, 14 Nov 1994, 11:30:49 GMT", &time2);
85
86 scoped_ptr<BlobStorageController> blob_storage_controller(
87 new BlobStorageController());
88
89 scoped_refptr<BlobData> blob_data = new BlobData();
90
91 GURL blob_url0("blob://url_0");
92 blob_storage_controller->RegisterBlobUrl(blob_url0, blob_data);
93
94 blob_data->AppendData("BlobData");
95 blob_data->AppendFile(
96 FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1);
97
98 GURL blob_url1("blob://url_1");
99 blob_storage_controller->RegisterBlobUrl(blob_url1, blob_data);
100
101 GURL blob_url2("blob://url_2");
102 blob_storage_controller->RegisterBlobUrlFrom(blob_url2, blob_url1);
103
104 GURL blob_url3("blob://url_3");
105 blob_storage_controller->RegisterBlobUrlFrom(blob_url3, blob_url2);
106
107 // Setup upload data elements for comparison.
108 UploadData::Element blob_element1, blob_element2;
109 blob_element1.SetToBytes(
110 blob_data->items().at(0).data().c_str() +
111 static_cast<int>(blob_data->items().at(0).offset()),
112 static_cast<int>(blob_data->items().at(0).length()));
113 blob_element2.SetToFilePathRange(
114 blob_data->items().at(1).file_path(),
115 blob_data->items().at(1).offset(),
116 blob_data->items().at(1).length(),
117 blob_data->items().at(1).expected_modification_time());
118
119 UploadData::Element upload_element1, upload_element2;
120 upload_element1.SetToBytes("Hello", 5);
121 upload_element2.SetToFilePathRange(
122 FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2);
123
124 // Test no blob reference.
125 scoped_refptr<UploadData> upload_data = new UploadData();
126 upload_data->AppendBytes(
127 &upload_element1.bytes().at(0),
128 upload_element1.bytes().size());
129 upload_data->AppendFileRange(
130 upload_element2.file_path(),
131 upload_element2.file_range_offset(),
132 upload_element2.file_range_length(),
133 upload_element2.expected_file_modification_time());
134
135 blob_storage_controller->ResolveBlobReferencesInUploadData(upload_data.get());
136 ASSERT_EQ(upload_data->elements()->size(), 2U);
137 EXPECT_TRUE(upload_data->elements()->at(0) == upload_element1);
138 EXPECT_TRUE(upload_data->elements()->at(1) == upload_element2);
139
140 // Test having only one blob reference that refers to empty blob data.
141 upload_data = new UploadData();
142 upload_data->AppendBlob(blob_url0);
143
144 blob_storage_controller->ResolveBlobReferencesInUploadData(upload_data.get());
145 ASSERT_EQ(upload_data->elements()->size(), 0U);
146
147 // Test having only one blob reference.
148 upload_data = new UploadData();
149 upload_data->AppendBlob(blob_url1);
150
151 blob_storage_controller->ResolveBlobReferencesInUploadData(upload_data.get());
152 ASSERT_EQ(upload_data->elements()->size(), 2U);
153 EXPECT_TRUE(upload_data->elements()->at(0) == blob_element1);
154 EXPECT_TRUE(upload_data->elements()->at(1) == blob_element2);
155
156 // Test having one blob reference at the beginning.
157 upload_data = new UploadData();
158 upload_data->AppendBlob(blob_url1);
159 upload_data->AppendBytes(
160 &upload_element1.bytes().at(0),
161 upload_element1.bytes().size());
162 upload_data->AppendFileRange(
163 upload_element2.file_path(),
164 upload_element2.file_range_offset(),
165 upload_element2.file_range_length(),
166 upload_element2.expected_file_modification_time());
167
168 blob_storage_controller->ResolveBlobReferencesInUploadData(upload_data.get());
169 ASSERT_EQ(upload_data->elements()->size(), 4U);
170 EXPECT_TRUE(upload_data->elements()->at(0) == blob_element1);
171 EXPECT_TRUE(upload_data->elements()->at(1) == blob_element2);
172 EXPECT_TRUE(upload_data->elements()->at(2) == upload_element1);
173 EXPECT_TRUE(upload_data->elements()->at(3) == upload_element2);
174
175 // Test having one blob reference at the end.
176 upload_data = new UploadData();
177 upload_data->AppendBytes(
178 &upload_element1.bytes().at(0),
179 upload_element1.bytes().size());
180 upload_data->AppendFileRange(
181 upload_element2.file_path(),
182 upload_element2.file_range_offset(),
183 upload_element2.file_range_length(),
184 upload_element2.expected_file_modification_time());
185 upload_data->AppendBlob(blob_url1);
186
187 blob_storage_controller->ResolveBlobReferencesInUploadData(upload_data.get());
188 ASSERT_EQ(upload_data->elements()->size(), 4U);
189 EXPECT_TRUE(upload_data->elements()->at(0) == upload_element1);
190 EXPECT_TRUE(upload_data->elements()->at(1) == upload_element2);
191 EXPECT_TRUE(upload_data->elements()->at(2) == blob_element1);
192 EXPECT_TRUE(upload_data->elements()->at(3) == blob_element2);
193
194 // Test having one blob reference in the middle.
195 upload_data = new UploadData();
196 upload_data->AppendBytes(
197 &upload_element1.bytes().at(0),
198 upload_element1.bytes().size());
199 upload_data->AppendBlob(blob_url1);
200 upload_data->AppendFileRange(
201 upload_element2.file_path(),
202 upload_element2.file_range_offset(),
203 upload_element2.file_range_length(),
204 upload_element2.expected_file_modification_time());
205
206 blob_storage_controller->ResolveBlobReferencesInUploadData(upload_data.get());
207 ASSERT_EQ(upload_data->elements()->size(), 4U);
208 EXPECT_TRUE(upload_data->elements()->at(0) == upload_element1);
209 EXPECT_TRUE(upload_data->elements()->at(1) == blob_element1);
210 EXPECT_TRUE(upload_data->elements()->at(2) == blob_element2);
211 EXPECT_TRUE(upload_data->elements()->at(3) == upload_element2);
212
213 // Test having multiple blob references.
214 upload_data = new UploadData();
215 upload_data->AppendBlob(blob_url1);
216 upload_data->AppendBytes(
217 &upload_element1.bytes().at(0),
218 upload_element1.bytes().size());
219 upload_data->AppendBlob(blob_url2);
220 upload_data->AppendBlob(blob_url3);
221 upload_data->AppendFileRange(
222 upload_element2.file_path(),
223 upload_element2.file_range_offset(),
224 upload_element2.file_range_length(),
225 upload_element2.expected_file_modification_time());
226
227 blob_storage_controller->ResolveBlobReferencesInUploadData(upload_data.get());
228 ASSERT_EQ(upload_data->elements()->size(), 8U);
229 EXPECT_TRUE(upload_data->elements()->at(0) == blob_element1);
230 EXPECT_TRUE(upload_data->elements()->at(1) == blob_element2);
231 EXPECT_TRUE(upload_data->elements()->at(2) == upload_element1);
232 EXPECT_TRUE(upload_data->elements()->at(3) == blob_element1);
233 EXPECT_TRUE(upload_data->elements()->at(4) == blob_element2);
234 EXPECT_TRUE(upload_data->elements()->at(5) == blob_element1);
235 EXPECT_TRUE(upload_data->elements()->at(6) == blob_element2);
236 EXPECT_TRUE(upload_data->elements()->at(7) == upload_element2);
83 } 237 }
84 238
85 } // namespace webkit_blob 239 } // namespace webkit_blob
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698