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

Side by Side Diff: webkit/glue/resource_request_body_unittest.cc

Issue 15984016: Call scoped_refptr<T>::get() rather than relying on implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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
« no previous file with comments | « webkit/common/blob/scoped_file.cc ('k') | webkit/plugins/ppapi/host_globals.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/glue/resource_request_body.h" 5 #include "webkit/glue/resource_request_body.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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const base::Time kFileTime = base::Time::FromDoubleT(999); 65 const base::Time kFileTime = base::Time::FromDoubleT(999);
66 const int64 kIdentifier = 12345; 66 const int64 kIdentifier = 12345;
67 67
68 request_body->AppendBytes(kData, arraysize(kData) - 1); 68 request_body->AppendBytes(kData, arraysize(kData) - 1);
69 request_body->AppendFileRange(base::FilePath(kFilePath), 69 request_body->AppendFileRange(base::FilePath(kFilePath),
70 kFileOffset, kFileLength, kFileTime); 70 kFileOffset, kFileLength, kFileTime);
71 request_body->set_identifier(kIdentifier); 71 request_body->set_identifier(kIdentifier);
72 72
73 scoped_ptr<net::UploadDataStream> upload( 73 scoped_ptr<net::UploadDataStream> upload(
74 request_body->ResolveElementsAndCreateUploadDataStream( 74 request_body->ResolveElementsAndCreateUploadDataStream(
75 NULL, NULL, base::MessageLoopProxy::current())); 75 NULL, NULL, base::MessageLoopProxy::current().get()));
76 76
77 EXPECT_EQ(kIdentifier, upload->identifier()); 77 EXPECT_EQ(kIdentifier, upload->identifier());
78 ASSERT_EQ(request_body->elements()->size(), upload->element_readers().size()); 78 ASSERT_EQ(request_body->elements()->size(), upload->element_readers().size());
79 79
80 const net::UploadBytesElementReader* r1 = 80 const net::UploadBytesElementReader* r1 =
81 upload->element_readers()[0]->AsBytesReader(); 81 upload->element_readers()[0]->AsBytesReader();
82 ASSERT_TRUE(r1); 82 ASSERT_TRUE(r1);
83 EXPECT_EQ(kData, std::string(r1->bytes(), r1->length())); 83 EXPECT_EQ(kData, std::string(r1->bytes(), r1->length()));
84 84
85 const net::UploadFileElementReader* r2 = 85 const net::UploadFileElementReader* r2 =
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Test no blob reference. 137 // Test no blob reference.
138 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); 138 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody());
139 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 139 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
140 request_body->AppendFileRange(upload_element2.path(), 140 request_body->AppendFileRange(upload_element2.path(),
141 upload_element2.offset(), 141 upload_element2.offset(),
142 upload_element2.length(), 142 upload_element2.length(),
143 upload_element2.expected_modification_time()); 143 upload_element2.expected_modification_time());
144 144
145 scoped_ptr<net::UploadDataStream> upload( 145 scoped_ptr<net::UploadDataStream> upload(
146 request_body->ResolveElementsAndCreateUploadDataStream( 146 request_body->ResolveElementsAndCreateUploadDataStream(
147 &blob_storage_controller, NULL, base::MessageLoopProxy::current())); 147 &blob_storage_controller,
148 NULL,
149 base::MessageLoopProxy::current().get()));
148 150
149 ASSERT_EQ(2U, upload->element_readers().size()); 151 ASSERT_EQ(2U, upload->element_readers().size());
150 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1)); 152 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1));
151 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2)); 153 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2));
152 154
153 // 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.
154 request_body = new ResourceRequestBody(); 156 request_body = new ResourceRequestBody();
155 request_body->AppendBlob(blob_url0); 157 request_body->AppendBlob(blob_url0);
156 158
157 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream( 159 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream(
158 &blob_storage_controller, NULL, base::MessageLoopProxy::current())); 160 &blob_storage_controller, NULL, base::MessageLoopProxy::current().get()));
159 ASSERT_EQ(0U, upload->element_readers().size()); 161 ASSERT_EQ(0U, upload->element_readers().size());
160 162
161 // Test having only one blob reference. 163 // Test having only one blob reference.
162 request_body = new ResourceRequestBody(); 164 request_body = new ResourceRequestBody();
163 request_body->AppendBlob(blob_url1); 165 request_body->AppendBlob(blob_url1);
164 166
165 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream( 167 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream(
166 &blob_storage_controller, NULL, base::MessageLoopProxy::current())); 168 &blob_storage_controller, NULL, base::MessageLoopProxy::current().get()));
167 ASSERT_EQ(2U, upload->element_readers().size()); 169 ASSERT_EQ(2U, upload->element_readers().size());
168 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1)); 170 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1));
169 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2)); 171 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2));
170 172
171 // Test having one blob reference at the beginning. 173 // Test having one blob reference at the beginning.
172 request_body = new ResourceRequestBody(); 174 request_body = new ResourceRequestBody();
173 request_body->AppendBlob(blob_url1); 175 request_body->AppendBlob(blob_url1);
174 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 176 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
175 request_body->AppendFileRange(upload_element2.path(), 177 request_body->AppendFileRange(upload_element2.path(),
176 upload_element2.offset(), 178 upload_element2.offset(),
177 upload_element2.length(), 179 upload_element2.length(),
178 upload_element2.expected_modification_time()); 180 upload_element2.expected_modification_time());
179 181
180 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream( 182 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream(
181 &blob_storage_controller, NULL, base::MessageLoopProxy::current())); 183 &blob_storage_controller, NULL, base::MessageLoopProxy::current().get()));
182 ASSERT_EQ(4U, upload->element_readers().size()); 184 ASSERT_EQ(4U, upload->element_readers().size());
183 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1)); 185 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1));
184 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2)); 186 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2));
185 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1)); 187 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1));
186 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2)); 188 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2));
187 189
188 // Test having one blob reference at the end. 190 // Test having one blob reference at the end.
189 request_body = new ResourceRequestBody(); 191 request_body = new ResourceRequestBody();
190 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 192 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
191 request_body->AppendFileRange(upload_element2.path(), 193 request_body->AppendFileRange(upload_element2.path(),
192 upload_element2.offset(), 194 upload_element2.offset(),
193 upload_element2.length(), 195 upload_element2.length(),
194 upload_element2.expected_modification_time()); 196 upload_element2.expected_modification_time());
195 request_body->AppendBlob(blob_url1); 197 request_body->AppendBlob(blob_url1);
196 198
197 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream( 199 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream(
198 &blob_storage_controller, NULL, base::MessageLoopProxy::current())); 200 &blob_storage_controller, NULL, base::MessageLoopProxy::current().get()));
199 ASSERT_EQ(4U, upload->element_readers().size()); 201 ASSERT_EQ(4U, upload->element_readers().size());
200 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1)); 202 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1));
201 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2)); 203 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], upload_element2));
202 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element1)); 204 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element1));
203 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element2)); 205 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element2));
204 206
205 // Test having one blob reference in the middle. 207 // Test having one blob reference in the middle.
206 request_body = new ResourceRequestBody(); 208 request_body = new ResourceRequestBody();
207 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 209 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
208 request_body->AppendBlob(blob_url1); 210 request_body->AppendBlob(blob_url1);
209 request_body->AppendFileRange(upload_element2.path(), 211 request_body->AppendFileRange(upload_element2.path(),
210 upload_element2.offset(), 212 upload_element2.offset(),
211 upload_element2.length(), 213 upload_element2.length(),
212 upload_element2.expected_modification_time()); 214 upload_element2.expected_modification_time());
213 215
214 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream( 216 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream(
215 &blob_storage_controller, NULL, base::MessageLoopProxy::current())); 217 &blob_storage_controller, NULL, base::MessageLoopProxy::current().get()));
216 ASSERT_EQ(4U, upload->element_readers().size()); 218 ASSERT_EQ(4U, upload->element_readers().size());
217 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1)); 219 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], upload_element1));
218 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element1)); 220 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element1));
219 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element2)); 221 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], blob_element2));
220 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2)); 222 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], upload_element2));
221 223
222 // Test having multiple blob references. 224 // Test having multiple blob references.
223 request_body = new ResourceRequestBody(); 225 request_body = new ResourceRequestBody();
224 request_body->AppendBlob(blob_url1); 226 request_body->AppendBlob(blob_url1);
225 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length()); 227 request_body->AppendBytes(upload_element1.bytes(), upload_element1.length());
226 request_body->AppendBlob(blob_url2); 228 request_body->AppendBlob(blob_url2);
227 request_body->AppendBlob(blob_url3); 229 request_body->AppendBlob(blob_url3);
228 request_body->AppendFileRange(upload_element2.path(), 230 request_body->AppendFileRange(upload_element2.path(),
229 upload_element2.offset(), 231 upload_element2.offset(),
230 upload_element2.length(), 232 upload_element2.length(),
231 upload_element2.expected_modification_time()); 233 upload_element2.expected_modification_time());
232 234
233 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream( 235 upload.reset(request_body->ResolveElementsAndCreateUploadDataStream(
234 &blob_storage_controller, NULL, base::MessageLoopProxy::current())); 236 &blob_storage_controller, NULL, base::MessageLoopProxy::current().get()));
235 ASSERT_EQ(8U, upload->element_readers().size()); 237 ASSERT_EQ(8U, upload->element_readers().size());
236 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1)); 238 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[0], blob_element1));
237 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2)); 239 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[1], blob_element2));
238 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1)); 240 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[2], upload_element1));
239 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element1)); 241 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[3], blob_element1));
240 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[4], blob_element2)); 242 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[4], blob_element2));
241 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[5], blob_element1)); 243 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[5], blob_element1));
242 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[6], blob_element2)); 244 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[6], blob_element2));
243 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[7], upload_element2)); 245 EXPECT_TRUE(AreElementsEqual(*upload->element_readers()[7], upload_element2));
244 } 246 }
245 247
246 } // namespace webkit_glue 248 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/common/blob/scoped_file.cc ('k') | webkit/plugins/ppapi/host_globals.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698