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

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

Issue 18346006: Update OS X to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 5 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 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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const uint64 kFileOffset = 10U; 64 const uint64 kFileOffset = 10U;
65 const uint64 kFileLength = 100U; 65 const uint64 kFileLength = 100U;
66 const base::Time kFileTime = base::Time::FromDoubleT(999); 66 const base::Time kFileTime = base::Time::FromDoubleT(999);
67 const int64 kIdentifier = 12345; 67 const int64 kIdentifier = 12345;
68 68
69 request_body->AppendBytes(kData, arraysize(kData) - 1); 69 request_body->AppendBytes(kData, arraysize(kData) - 1);
70 request_body->AppendFileRange(base::FilePath(kFilePath), 70 request_body->AppendFileRange(base::FilePath(kFilePath),
71 kFileOffset, kFileLength, kFileTime); 71 kFileOffset, kFileLength, kFileTime);
72 request_body->set_identifier(kIdentifier); 72 request_body->set_identifier(kIdentifier);
73 73
74 scoped_ptr<net::UploadDataStream> upload( 74 scoped_ptr<net::UploadDataStream> upload(UploadDataStreamBuilder::Build(
75 UploadDataStreamBuilder::Build( 75 request_body.get(), NULL, NULL, base::MessageLoopProxy::current().get()));
76 request_body, NULL, NULL, base::MessageLoopProxy::current().get()));
77 76
78 EXPECT_EQ(kIdentifier, upload->identifier()); 77 EXPECT_EQ(kIdentifier, upload->identifier());
79 ASSERT_EQ(request_body->elements()->size(), upload->element_readers().size()); 78 ASSERT_EQ(request_body->elements()->size(), upload->element_readers().size());
80 79
81 const net::UploadBytesElementReader* r1 = 80 const net::UploadBytesElementReader* r1 =
82 upload->element_readers()[0]->AsBytesReader(); 81 upload->element_readers()[0]->AsBytesReader();
83 ASSERT_TRUE(r1); 82 ASSERT_TRUE(r1);
84 EXPECT_EQ(kData, std::string(r1->bytes(), r1->length())); 83 EXPECT_EQ(kData, std::string(r1->bytes(), r1->length()));
85 84
86 const net::UploadFileElementReader* r2 = 85 const net::UploadFileElementReader* r2 =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 136
138 // Test no blob reference. 137 // Test no blob reference.
139 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); 138 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody());
140 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 139 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
141 request_body->AppendFileRange(upload_element2.path(), 140 request_body->AppendFileRange(upload_element2.path(),
142 upload_element2.offset(), 141 upload_element2.offset(),
143 upload_element2.length(), 142 upload_element2.length(),
144 upload_element2.expected_modification_time()); 143 upload_element2.expected_modification_time());
145 144
146 scoped_ptr<net::UploadDataStream> upload( 145 scoped_ptr<net::UploadDataStream> upload(
147 UploadDataStreamBuilder::Build( 146 UploadDataStreamBuilder::Build(request_body.get(),
148 request_body, 147 &blob_storage_controller,
149 &blob_storage_controller, 148 NULL,
150 NULL, 149 base::MessageLoopProxy::current().get()));
151 base::MessageLoopProxy::current().get()));
152 150
153 ASSERT_EQ(2U, upload->element_readers().size()); 151 ASSERT_EQ(2U, upload->element_readers().size());
154 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1)); 152 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1));
155 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2)); 153 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2));
156 154
157 // Test having only one blob reference that refers to empty blob data. 155 // Test having only one blob reference that refers to empty blob data.
158 request_body = new ResourceRequestBody(); 156 request_body = new ResourceRequestBody();
159 request_body->AppendBlob(blob_url0); 157 request_body->AppendBlob(blob_url0);
160 158
161 upload = UploadDataStreamBuilder::Build( 159 upload =
162 request_body, 160 UploadDataStreamBuilder::Build(request_body.get(),
163 &blob_storage_controller, 161 &blob_storage_controller,
164 NULL, 162 NULL,
165 base::MessageLoopProxy::current().get()); 163 base::MessageLoopProxy::current().get());
166 ASSERT_EQ(0U, upload->element_readers().size()); 164 ASSERT_EQ(0U, upload->element_readers().size());
167 165
168 // Test having only one blob reference. 166 // Test having only one blob reference.
169 request_body = new ResourceRequestBody(); 167 request_body = new ResourceRequestBody();
170 request_body->AppendBlob(blob_url1); 168 request_body->AppendBlob(blob_url1);
171 169
172 upload = UploadDataStreamBuilder::Build( 170 upload =
173 request_body, 171 UploadDataStreamBuilder::Build(request_body.get(),
174 &blob_storage_controller, 172 &blob_storage_controller,
175 NULL, 173 NULL,
176 base::MessageLoopProxy::current().get()); 174 base::MessageLoopProxy::current().get());
177 ASSERT_EQ(2U, upload->element_readers().size()); 175 ASSERT_EQ(2U, upload->element_readers().size());
178 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1)); 176 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1));
179 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2)); 177 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2));
180 178
181 // Test having one blob reference at the beginning. 179 // Test having one blob reference at the beginning.
182 request_body = new ResourceRequestBody(); 180 request_body = new ResourceRequestBody();
183 request_body->AppendBlob(blob_url1); 181 request_body->AppendBlob(blob_url1);
184 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 182 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
185 request_body->AppendFileRange(upload_element2.path(), 183 request_body->AppendFileRange(upload_element2.path(),
186 upload_element2.offset(), 184 upload_element2.offset(),
187 upload_element2.length(), 185 upload_element2.length(),
188 upload_element2.expected_modification_time()); 186 upload_element2.expected_modification_time());
189 187
190 upload = UploadDataStreamBuilder::Build( 188 upload =
191 request_body, 189 UploadDataStreamBuilder::Build(request_body.get(),
192 &blob_storage_controller, 190 &blob_storage_controller,
193 NULL, 191 NULL,
194 base::MessageLoopProxy::current().get()); 192 base::MessageLoopProxy::current().get());
195 ASSERT_EQ(4U, upload->element_readers().size()); 193 ASSERT_EQ(4U, upload->element_readers().size());
196 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1)); 194 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1));
197 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2)); 195 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2));
198 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1)); 196 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1));
199 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2)); 197 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2));
200 198
201 // Test having one blob reference at the end. 199 // Test having one blob reference at the end.
202 request_body = new ResourceRequestBody(); 200 request_body = new ResourceRequestBody();
203 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 201 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
204 request_body->AppendFileRange(upload_element2.path(), 202 request_body->AppendFileRange(upload_element2.path(),
205 upload_element2.offset(), 203 upload_element2.offset(),
206 upload_element2.length(), 204 upload_element2.length(),
207 upload_element2.expected_modification_time()); 205 upload_element2.expected_modification_time());
208 request_body->AppendBlob(blob_url1); 206 request_body->AppendBlob(blob_url1);
209 207
210 upload = UploadDataStreamBuilder::Build( 208 upload =
211 request_body, 209 UploadDataStreamBuilder::Build(request_body.get(),
212 &blob_storage_controller, 210 &blob_storage_controller,
213 NULL, 211 NULL,
214 base::MessageLoopProxy::current().get()); 212 base::MessageLoopProxy::current().get());
215 ASSERT_EQ(4U, upload->element_readers().size()); 213 ASSERT_EQ(4U, upload->element_readers().size());
216 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1)); 214 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1));
217 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2)); 215 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2));
218 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element1)); 216 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element1));
219 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element2)); 217 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element2));
220 218
221 // Test having one blob reference in the middle. 219 // Test having one blob reference in the middle.
222 request_body = new ResourceRequestBody(); 220 request_body = new ResourceRequestBody();
223 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 221 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
224 request_body->AppendBlob(blob_url1); 222 request_body->AppendBlob(blob_url1);
225 request_body->AppendFileRange(upload_element2.path(), 223 request_body->AppendFileRange(upload_element2.path(),
226 upload_element2.offset(), 224 upload_element2.offset(),
227 upload_element2.length(), 225 upload_element2.length(),
228 upload_element2.expected_modification_time()); 226 upload_element2.expected_modification_time());
229 227
230 upload = UploadDataStreamBuilder::Build( 228 upload =
231 request_body, 229 UploadDataStreamBuilder::Build(request_body.get(),
232 &blob_storage_controller, 230 &blob_storage_controller,
233 NULL, 231 NULL,
234 base::MessageLoopProxy::current().get()); 232 base::MessageLoopProxy::current().get());
235 ASSERT_EQ(4U, upload->element_readers().size()); 233 ASSERT_EQ(4U, upload->element_readers().size());
236 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1)); 234 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1));
237 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element1)); 235 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element1));
238 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element2)); 236 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element2));
239 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2)); 237 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2));
240 238
241 // Test having multiple blob references. 239 // Test having multiple blob references.
242 request_body = new ResourceRequestBody(); 240 request_body = new ResourceRequestBody();
243 request_body->AppendBlob(blob_url1); 241 request_body->AppendBlob(blob_url1);
244 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 242 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
245 request_body->AppendBlob(blob_url2); 243 request_body->AppendBlob(blob_url2);
246 request_body->AppendBlob(blob_url3); 244 request_body->AppendBlob(blob_url3);
247 request_body->AppendFileRange(upload_element2.path(), 245 request_body->AppendFileRange(upload_element2.path(),
248 upload_element2.offset(), 246 upload_element2.offset(),
249 upload_element2.length(), 247 upload_element2.length(),
250 upload_element2.expected_modification_time()); 248 upload_element2.expected_modification_time());
251 249
252 upload = UploadDataStreamBuilder::Build( 250 upload =
253 request_body, 251 UploadDataStreamBuilder::Build(request_body.get(),
254 &blob_storage_controller, 252 &blob_storage_controller,
255 NULL, 253 NULL,
256 base::MessageLoopProxy::current().get()); 254 base::MessageLoopProxy::current().get());
257 ASSERT_EQ(8U, upload->element_readers().size()); 255 ASSERT_EQ(8U, upload->element_readers().size());
258 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1)); 256 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1));
259 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2)); 257 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2));
260 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1)); 258 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1));
261 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element1)); 259 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element1));
262 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[4], blob_element2)); 260 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[4], blob_element2));
263 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[5], blob_element1)); 261 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[5], blob_element1));
264 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[6], blob_element2)); 262 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[6], blob_element2));
265 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[7], upload_element2)); 263 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[7], upload_element2));
266 } 264 }
267 265
268 } // namespace content 266 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698