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

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

Issue 6771043: Enabled actual transfer size in chromium (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment added Created 9 years, 8 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/glue/multipart_response_delegate.cc ('k') | webkit/glue/resource_fetcher.h » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 virtual void didReceiveResponse(WebURLLoader* loader, 63 virtual void didReceiveResponse(WebURLLoader* loader,
64 const WebURLResponse& response) { 64 const WebURLResponse& response) {
65 ++received_response_; 65 ++received_response_;
66 response_ = response; 66 response_ = response;
67 data_.clear(); 67 data_.clear();
68 } 68 }
69 virtual void didReceiveData( 69 virtual void didReceiveData(
70 WebKit::WebURLLoader* loader, 70 WebKit::WebURLLoader* loader,
71 const char* data, 71 const char* data,
72 int data_length, 72 int data_length,
73 int length_received) { 73 int raw_data_length) {
74 ++received_data_; 74 ++received_data_;
75 data_.append(data, data_length); 75 data_.append(data, data_length);
76 total_raw_data_length_ += raw_data_length;
76 } 77 }
77 virtual void didFinishLoading(WebURLLoader*, double finishTime) {} 78 virtual void didFinishLoading(WebURLLoader*, double finishTime) {}
78 virtual void didFail(WebURLLoader*, const WebURLError&) {} 79 virtual void didFail(WebURLLoader*, const WebURLError&) {}
79 80
80 void Reset() { 81 void Reset() {
81 received_response_ = received_data_ = 0; 82 received_response_ = received_data_ = total_raw_data_length_ = 0;
82 data_.clear(); 83 data_.clear();
83 response_.reset(); 84 response_.reset();
84 } 85 }
85 86
86 string GetResponseHeader(const char* name) const { 87 string GetResponseHeader(const char* name) const {
87 return string(response_.httpHeaderField(WebString::fromUTF8(name)).utf8()); 88 return string(response_.httpHeaderField(WebString::fromUTF8(name)).utf8());
88 } 89 }
89 90
90 int received_response_, received_data_; 91 int received_response_, received_data_, total_raw_data_length_;
91 string data_; 92 string data_;
92 WebURLResponse response_; 93 WebURLResponse response_;
93 }; 94 };
94 95
95 // We can't put this in an anonymous function because it's a friend class for 96 // We can't put this in an anonymous function because it's a friend class for
96 // access to private members. 97 // access to private members.
97 TEST(MultipartResponseTest, Functions) { 98 TEST(MultipartResponseTest, Functions) {
98 // PushOverLine tests 99 // PushOverLine tests
99 100
100 WebURLResponse response; 101 WebURLResponse response;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 MockWebURLLoaderClient client; 210 MockWebURLLoaderClient client;
210 MultipartResponseDelegate delegate(&client, NULL, response, "bound"); 211 MultipartResponseDelegate delegate(&client, NULL, response, "bound");
211 212
212 // No start boundary 213 // No start boundary
213 string no_start_boundary( 214 string no_start_boundary(
214 "Content-type: text/plain\n\n" 215 "Content-type: text/plain\n\n"
215 "This is a sample response\n" 216 "This is a sample response\n"
216 "--bound--" 217 "--bound--"
217 "ignore junk after end token --bound\n\nTest2\n"); 218 "ignore junk after end token --bound\n\nTest2\n");
218 delegate.OnReceivedData(no_start_boundary.c_str(), 219 delegate.OnReceivedData(no_start_boundary.c_str(),
220 static_cast<int>(no_start_boundary.length()),
219 static_cast<int>(no_start_boundary.length())); 221 static_cast<int>(no_start_boundary.length()));
220 EXPECT_EQ(1, client.received_response_); 222 EXPECT_EQ(1, client.received_response_);
221 EXPECT_EQ(1, client.received_data_); 223 EXPECT_EQ(1, client.received_data_);
222 EXPECT_EQ(string("This is a sample response"), 224 EXPECT_EQ(string("This is a sample response"), client.data_);
223 client.data_); 225 EXPECT_EQ(static_cast<int>(no_start_boundary.length()),
226 client.total_raw_data_length_);
224 227
225 delegate.OnCompletedRequest(); 228 delegate.OnCompletedRequest();
226 EXPECT_EQ(1, client.received_response_); 229 EXPECT_EQ(1, client.received_response_);
227 EXPECT_EQ(1, client.received_data_); 230 EXPECT_EQ(1, client.received_data_);
228 231
229 // No end boundary 232 // No end boundary
230 client.Reset(); 233 client.Reset();
231 MultipartResponseDelegate delegate2(&client, NULL, response, "bound"); 234 MultipartResponseDelegate delegate2(&client, NULL, response, "bound");
232 string no_end_boundary( 235 string no_end_boundary(
233 "bound\nContent-type: text/plain\n\n" 236 "bound\nContent-type: text/plain\n\n"
234 "This is a sample response\n"); 237 "This is a sample response\n");
235 delegate2.OnReceivedData(no_end_boundary.c_str(), 238 delegate2.OnReceivedData(no_end_boundary.c_str(),
239 static_cast<int>(no_end_boundary.length()),
236 static_cast<int>(no_end_boundary.length())); 240 static_cast<int>(no_end_boundary.length()));
237 EXPECT_EQ(1, client.received_response_); 241 EXPECT_EQ(1, client.received_response_);
238 EXPECT_EQ(1, client.received_data_); 242 EXPECT_EQ(1, client.received_data_);
239 EXPECT_EQ("This is a sample response\n", client.data_); 243 EXPECT_EQ("This is a sample response\n", client.data_);
244 EXPECT_EQ(static_cast<int>(no_end_boundary.length()),
245 client.total_raw_data_length_);
240 246
241 delegate2.OnCompletedRequest(); 247 delegate2.OnCompletedRequest();
242 EXPECT_EQ(1, client.received_response_); 248 EXPECT_EQ(1, client.received_response_);
243 EXPECT_EQ(1, client.received_data_); 249 EXPECT_EQ(1, client.received_data_);
244 EXPECT_EQ(string("This is a sample response\n"), 250 EXPECT_EQ(string("This is a sample response\n"), client.data_);
245 client.data_); 251 EXPECT_EQ(static_cast<int>(no_end_boundary.length()),
252 client.total_raw_data_length_);
246 253
247 // Neither boundary 254 // Neither boundary
248 client.Reset(); 255 client.Reset();
249 MultipartResponseDelegate delegate3(&client, NULL, response, "bound"); 256 MultipartResponseDelegate delegate3(&client, NULL, response, "bound");
250 string no_boundaries( 257 string no_boundaries(
251 "Content-type: text/plain\n\n" 258 "Content-type: text/plain\n\n"
252 "This is a sample response\n"); 259 "This is a sample response\n");
253 delegate3.OnReceivedData(no_boundaries.c_str(), 260 delegate3.OnReceivedData(no_boundaries.c_str(),
261 static_cast<int>(no_boundaries.length()),
254 static_cast<int>(no_boundaries.length())); 262 static_cast<int>(no_boundaries.length()));
255 EXPECT_EQ(1, client.received_response_); 263 EXPECT_EQ(1, client.received_response_);
256 EXPECT_EQ(1, client.received_data_); 264 EXPECT_EQ(1, client.received_data_);
257 EXPECT_EQ("This is a sample response\n", client.data_); 265 EXPECT_EQ("This is a sample response\n", client.data_);
266 EXPECT_EQ(static_cast<int>(no_boundaries.length()),
267 client.total_raw_data_length_);
258 268
259 delegate3.OnCompletedRequest(); 269 delegate3.OnCompletedRequest();
260 EXPECT_EQ(1, client.received_response_); 270 EXPECT_EQ(1, client.received_response_);
261 EXPECT_EQ(1, client.received_data_); 271 EXPECT_EQ(1, client.received_data_);
262 EXPECT_EQ(string("This is a sample response\n"), 272 EXPECT_EQ(string("This is a sample response\n"), client.data_);
263 client.data_); 273 EXPECT_EQ(static_cast<int>(no_boundaries.length()),
274 client.total_raw_data_length_);
264 } 275 }
265 276
266 TEST(MultipartResponseTest, MalformedBoundary) { 277 TEST(MultipartResponseTest, MalformedBoundary) {
267 // Some servers send a boundary that is prefixed by "--". See bug 5786. 278 // Some servers send a boundary that is prefixed by "--". See bug 5786.
268 279
269 WebURLResponse response; 280 WebURLResponse response;
270 response.initialize(); 281 response.initialize();
271 response.setMIMEType("multipart/x-mixed-replace"); 282 response.setMIMEType("multipart/x-mixed-replace");
272 response.setHTTPHeaderField("Foo", "Bar"); 283 response.setHTTPHeaderField("Foo", "Bar");
273 response.setHTTPHeaderField("Content-type", "text/plain"); 284 response.setHTTPHeaderField("Content-type", "text/plain");
274 MockWebURLLoaderClient client; 285 MockWebURLLoaderClient client;
275 MultipartResponseDelegate delegate(&client, NULL, response, "--bound"); 286 MultipartResponseDelegate delegate(&client, NULL, response, "--bound");
276 287
277 string data( 288 string data(
278 "--bound\n" 289 "--bound\n"
279 "Content-type: text/plain\n\n" 290 "Content-type: text/plain\n\n"
280 "This is a sample response\n" 291 "This is a sample response\n"
281 "--bound--" 292 "--bound--"
282 "ignore junk after end token --bound\n\nTest2\n"); 293 "ignore junk after end token --bound\n\nTest2\n");
283 delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); 294 delegate.OnReceivedData(data.c_str(),
295 static_cast<int>(data.length()),
296 static_cast<int>(data.length()));
284 EXPECT_EQ(1, client.received_response_); 297 EXPECT_EQ(1, client.received_response_);
285 EXPECT_EQ(1, client.received_data_); 298 EXPECT_EQ(1, client.received_data_);
286 EXPECT_EQ(string("This is a sample response"), client.data_); 299 EXPECT_EQ(string("This is a sample response"), client.data_);
300 EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_);
287 301
288 delegate.OnCompletedRequest(); 302 delegate.OnCompletedRequest();
289 EXPECT_EQ(1, client.received_response_); 303 EXPECT_EQ(1, client.received_response_);
290 EXPECT_EQ(1, client.received_data_); 304 EXPECT_EQ(1, client.received_data_);
291 } 305 }
292 306
293 307
294 // Used in for tests that break the data in various places. 308 // Used in for tests that break the data in various places.
295 struct TestChunk { 309 struct TestChunk {
296 const int start_pos; // offset in data 310 const int start_pos; // offset in data
297 const int end_pos; // end offset in data 311 const int end_pos; // end offset in data
298 const int expected_responses; 312 const int expected_responses;
299 const int expected_received_data; 313 const int expected_received_data;
300 const char* expected_data; 314 const char* expected_data;
315 const int expected_raw_data_length;
301 }; 316 };
302 317
303 void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size, 318 void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size,
304 int responses, int received_data, 319 int responses, int received_data,
305 const char* completed_data) { 320 const char* completed_data,
321 int completed_raw_data_length) {
306 const string data( 322 const string data(
307 "--bound\n" // 0-7 323 "--bound\n" // 0-7
308 "Content-type: image/png\n\n" // 8-32 324 "Content-type: image/png\n\n" // 8-32
309 "datadatadatadatadata" // 33-52 325 "datadatadatadatadata" // 33-52
310 "--bound\n" // 53-60 326 "--bound\n" // 53-60
311 "Content-type: image/jpg\n\n" // 61-85 327 "Content-type: image/jpg\n\n" // 61-85
312 "foofoofoofoofoo" // 86-100 328 "foofoofoofoofoo" // 86-100
313 "--bound--"); // 101-109 329 "--bound--"); // 101-109
314 330
315 WebURLResponse response; 331 WebURLResponse response;
316 response.initialize(); 332 response.initialize();
317 response.setMIMEType("multipart/x-mixed-replace"); 333 response.setMIMEType("multipart/x-mixed-replace");
318 MockWebURLLoaderClient client; 334 MockWebURLLoaderClient client;
319 MultipartResponseDelegate delegate(&client, NULL, response, "bound"); 335 MultipartResponseDelegate delegate(&client, NULL, response, "bound");
320 336
321 for (int i = 0; i < chunks_size; ++i) { 337 for (int i = 0; i < chunks_size; ++i) {
322 ASSERT_TRUE(chunks[i].start_pos < chunks[i].end_pos); 338 ASSERT_TRUE(chunks[i].start_pos < chunks[i].end_pos);
323 string chunk = data.substr(chunks[i].start_pos, 339 string chunk = data.substr(chunks[i].start_pos,
324 chunks[i].end_pos - chunks[i].start_pos); 340 chunks[i].end_pos - chunks[i].start_pos);
325 delegate.OnReceivedData(chunk.c_str(), static_cast<int>(chunk.length())); 341 delegate.OnReceivedData(
326 EXPECT_EQ(chunks[i].expected_responses, 342 chunk.c_str(),
327 client.received_response_); 343 static_cast<int>(chunk.length()),
328 EXPECT_EQ(chunks[i].expected_received_data, 344 static_cast<int>(chunk.length()));
329 client.received_data_); 345 EXPECT_EQ(chunks[i].expected_responses, client.received_response_);
330 EXPECT_EQ(string(chunks[i].expected_data), 346 EXPECT_EQ(chunks[i].expected_received_data, client.received_data_);
331 client.data_); 347 EXPECT_EQ(string(chunks[i].expected_data), client.data_);
348 EXPECT_EQ(chunks[i].expected_raw_data_length,
349 client.total_raw_data_length_);
332 } 350 }
333 // Check final state 351 // Check final state
334 delegate.OnCompletedRequest(); 352 delegate.OnCompletedRequest();
335 EXPECT_EQ(responses, 353 EXPECT_EQ(responses, client.received_response_);
336 client.received_response_); 354 EXPECT_EQ(received_data, client.received_data_);
337 EXPECT_EQ(received_data, 355 string completed_data_string(completed_data);
338 client.received_data_); 356 EXPECT_EQ(completed_data_string, client.data_);
339 EXPECT_EQ(string(completed_data), 357 EXPECT_EQ(completed_raw_data_length, client.total_raw_data_length_);
340 client.data_);
341 } 358 }
342 359
343 TEST(MultipartResponseTest, BreakInBoundary) { 360 TEST(MultipartResponseTest, BreakInBoundary) {
344 // Break in the first boundary 361 // Break in the first boundary
345 const TestChunk bound1[] = { 362 const TestChunk bound1[] = {
346 { 0, 4, 0, 0, ""}, 363 { 0, 4, 0, 0, "", 0 },
347 { 4, 110, 2, 2, "foofoofoofoofoo" }, 364 { 4, 110, 2, 2, "foofoofoofoofoo", 110 },
348 }; 365 };
349 VariousChunkSizesTest(bound1, arraysize(bound1), 366 VariousChunkSizesTest(bound1, arraysize(bound1),
350 2, 2, "foofoofoofoofoo"); 367 2, 2, "foofoofoofoofoo", 110);
351 368
352 // Break in first and second 369 // Break in first and second
353 const TestChunk bound2[] = { 370 const TestChunk bound2[] = {
354 { 0, 4, 0, 0, ""}, 371 { 0, 4, 0, 0, "", 0 },
355 { 4, 55, 1, 1, "datadatadatadat" }, 372 { 4, 55, 1, 1, "datadatadatadat", 55 },
356 { 55, 65, 1, 2, "datadatadatadatadata" }, 373 { 55, 65, 1, 2, "datadatadatadatadata", 65 },
357 { 65, 110, 2, 3, "foofoofoofoofoo" }, 374 { 65, 110, 2, 3, "foofoofoofoofoo", 110 },
358 }; 375 };
359 VariousChunkSizesTest(bound2, arraysize(bound2), 376 VariousChunkSizesTest(bound2, arraysize(bound2),
360 2, 3, "foofoofoofoofoo"); 377 2, 3, "foofoofoofoofoo", 110);
361 378
362 // Break in second only 379 // Break in second only
363 const TestChunk bound3[] = { 380 const TestChunk bound3[] = {
364 { 0, 55, 1, 1, "datadatadatadat" }, 381 { 0, 55, 1, 1, "datadatadatadat", 55 },
365 { 55, 110, 2, 3, "foofoofoofoofoo" }, 382 { 55, 110, 2, 3, "foofoofoofoofoo", 110 },
366 }; 383 };
367 VariousChunkSizesTest(bound3, arraysize(bound3), 384 VariousChunkSizesTest(bound3, arraysize(bound3),
368 2, 3, "foofoofoofoofoo"); 385 2, 3, "foofoofoofoofoo", 110);
369 } 386 }
370 387
371 TEST(MultipartResponseTest, BreakInHeaders) { 388 TEST(MultipartResponseTest, BreakInHeaders) {
372 // Break in first header 389 // Break in first header
373 const TestChunk header1[] = { 390 const TestChunk header1[] = {
374 { 0, 10, 0, 0, "" }, 391 { 0, 10, 0, 0, "", 0 },
375 { 10, 35, 1, 0, "" }, 392 { 10, 35, 1, 0, "", 0 },
376 { 35, 110, 2, 2, "foofoofoofoofoo" }, 393 { 35, 110, 2, 2, "foofoofoofoofoo", 110 },
377 }; 394 };
378 VariousChunkSizesTest(header1, arraysize(header1), 395 VariousChunkSizesTest(header1, arraysize(header1),
379 2, 2, "foofoofoofoofoo"); 396 2, 2, "foofoofoofoofoo", 110);
380 397
381 // Break in both headers 398 // Break in both headers
382 const TestChunk header2[] = { 399 const TestChunk header2[] = {
383 { 0, 10, 0, 0, "" }, 400 { 0, 10, 0, 0, "", 0 },
384 { 10, 65, 1, 1, "datadatadatadatadata" }, 401 { 10, 65, 1, 1, "datadatadatadatadata", 65 },
385 { 65, 110, 2, 2, "foofoofoofoofoo" }, 402 { 65, 110, 2, 2, "foofoofoofoofoo", 110 },
386 }; 403 };
387 VariousChunkSizesTest(header2, arraysize(header2), 404 VariousChunkSizesTest(header2, arraysize(header2),
388 2, 2, "foofoofoofoofoo"); 405 2, 2, "foofoofoofoofoo", 110);
389 406
390 // Break at end of a header 407 // Break at end of a header
391 const TestChunk header3[] = { 408 const TestChunk header3[] = {
392 { 0, 33, 1, 0, "" }, 409 { 0, 33, 1, 0, "", 0 },
393 { 33, 65, 1, 1, "datadatadatadatadata" }, 410 { 33, 65, 1, 1, "datadatadatadatadata", 65 },
394 { 65, 110, 2, 2, "foofoofoofoofoo" }, 411 { 65, 110, 2, 2, "foofoofoofoofoo", 110 },
395 }; 412 };
396 VariousChunkSizesTest(header3, arraysize(header3), 413 VariousChunkSizesTest(header3, arraysize(header3),
397 2, 2, "foofoofoofoofoo"); 414 2, 2, "foofoofoofoofoo", 110);
398 } 415 }
399 416
400 TEST(MultipartResponseTest, BreakInData) { 417 TEST(MultipartResponseTest, BreakInData) {
401 // All data as one chunk 418 // All data as one chunk
402 const TestChunk data1[] = { 419 const TestChunk data1[] = {
403 { 0, 110, 2, 2, "foofoofoofoofoo" }, 420 { 0, 110, 2, 2, "foofoofoofoofoo", 110 },
404 }; 421 };
405 VariousChunkSizesTest(data1, arraysize(data1), 422 VariousChunkSizesTest(data1, arraysize(data1),
406 2, 2, "foofoofoofoofoo"); 423 2, 2, "foofoofoofoofoo", 110);
407 424
408 // breaks in data segment 425 // breaks in data segment
409 const TestChunk data2[] = { 426 const TestChunk data2[] = {
410 { 0, 35, 1, 0, "" }, 427 { 0, 35, 1, 0, "", 0 },
411 { 35, 65, 1, 1, "datadatadatadatadata" }, 428 { 35, 65, 1, 1, "datadatadatadatadata", 65 },
412 { 65, 90, 2, 1, "" }, 429 { 65, 90, 2, 1, "", 65 },
413 { 90, 110, 2, 2, "foofoofoofoofoo" }, 430 { 90, 110, 2, 2, "foofoofoofoofoo", 110 },
414 }; 431 };
415 VariousChunkSizesTest(data2, arraysize(data2), 432 VariousChunkSizesTest(data2, arraysize(data2),
416 2, 2, "foofoofoofoofoo"); 433 2, 2, "foofoofoofoofoo", 110);
417 434
418 // Incomplete send 435 // Incomplete send
419 const TestChunk data3[] = { 436 const TestChunk data3[] = {
420 { 0, 35, 1, 0, "" }, 437 { 0, 35, 1, 0, "", 0 },
421 { 35, 90, 2, 1, "" }, 438 { 35, 90, 2, 1, "", 90 },
422 }; 439 };
423 VariousChunkSizesTest(data3, arraysize(data3), 440 VariousChunkSizesTest(data3, arraysize(data3),
424 2, 2, "foof"); 441 2, 2, "foof", 90);
425 } 442 }
426 443
427 TEST(MultipartResponseTest, SmallChunk) { 444 TEST(MultipartResponseTest, SmallChunk) {
428 WebURLResponse response; 445 WebURLResponse response;
429 response.initialize(); 446 response.initialize();
430 response.setMIMEType("multipart/x-mixed-replace"); 447 response.setMIMEType("multipart/x-mixed-replace");
431 response.setHTTPHeaderField("Content-type", "text/plain"); 448 response.setHTTPHeaderField("Content-type", "text/plain");
432 MockWebURLLoaderClient client; 449 MockWebURLLoaderClient client;
433 MultipartResponseDelegate delegate(&client, NULL, response, "bound"); 450 MultipartResponseDelegate delegate(&client, NULL, response, "bound");
434 451
435 // Test chunks of size 1, 2, and 0. 452 // Test chunks of size 1, 2, and 0.
436 string data( 453 string data(
437 "--boundContent-type: text/plain\n\n" 454 "--boundContent-type: text/plain\n\n"
438 "\n--boundContent-type: text/plain\n\n" 455 "\n--boundContent-type: text/plain\n\n"
439 "\n\n--boundContent-type: text/plain\n\n" 456 "\n\n--boundContent-type: text/plain\n\n"
440 "--boundContent-type: text/plain\n\n" 457 "--boundContent-type: text/plain\n\n"
441 "end--bound--"); 458 "end--bound--");
442 delegate.OnReceivedData(data.c_str(), 459 delegate.OnReceivedData(data.c_str(),
460 static_cast<int>(data.length()),
443 static_cast<int>(data.length())); 461 static_cast<int>(data.length()));
444 EXPECT_EQ(4, client.received_response_); 462 EXPECT_EQ(4, client.received_response_);
445 EXPECT_EQ(2, client.received_data_); 463 EXPECT_EQ(2, client.received_data_);
446 EXPECT_EQ(string("end"), client.data_); 464 EXPECT_EQ(string("end"), client.data_);
465 EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_);
447 466
448 delegate.OnCompletedRequest(); 467 delegate.OnCompletedRequest();
449 EXPECT_EQ(4, client.received_response_); 468 EXPECT_EQ(4, client.received_response_);
450 EXPECT_EQ(2, client.received_data_); 469 EXPECT_EQ(2, client.received_data_);
451 } 470 }
452 471
453 TEST(MultipartResponseTest, MultipleBoundaries) { 472 TEST(MultipartResponseTest, MultipleBoundaries) {
454 // Test multiple boundaries back to back 473 // Test multiple boundaries back to back
455 WebURLResponse response; 474 WebURLResponse response;
456 response.initialize(); 475 response.initialize();
457 response.setMIMEType("multipart/x-mixed-replace"); 476 response.setMIMEType("multipart/x-mixed-replace");
458 MockWebURLLoaderClient client; 477 MockWebURLLoaderClient client;
459 MultipartResponseDelegate delegate(&client, NULL, response, "bound"); 478 MultipartResponseDelegate delegate(&client, NULL, response, "bound");
460 479
461 string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"); 480 string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--");
462 delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); 481 delegate.OnReceivedData(data.c_str(),
463 EXPECT_EQ(2, 482 static_cast<int>(data.length()),
464 client.received_response_); 483 static_cast<int>(data.length()));
465 EXPECT_EQ(1, 484 EXPECT_EQ(2, client.received_response_);
466 client.received_data_); 485 EXPECT_EQ(1, client.received_data_);
467 EXPECT_EQ(string("foofoo"), 486 EXPECT_EQ(string("foofoo"), client.data_);
468 client.data_); 487 EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_);
469 } 488 }
470 489
471 TEST(MultipartResponseTest, MultipartByteRangeParsingTest) { 490 TEST(MultipartResponseTest, MultipartByteRangeParsingTest) {
472 // Test multipart/byteranges based boundary parsing. 491 // Test multipart/byteranges based boundary parsing.
473 WebURLResponse response1; 492 WebURLResponse response1;
474 response1.initialize(); 493 response1.initialize();
475 response1.setMIMEType("multipart/x-mixed-replace"); 494 response1.setMIMEType("multipart/x-mixed-replace");
476 response1.setHTTPHeaderField("Content-Length", "200"); 495 response1.setHTTPHeaderField("Content-Length", "200");
477 response1.setHTTPHeaderField("Content-type", 496 response1.setHTTPHeaderField("Content-type",
478 "multipart/byteranges; boundary=--bound--"); 497 "multipart/byteranges; boundary=--bound--");
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 response.initialize(); 640 response.initialize();
622 response.setMIMEType("multipart/x-mixed-replace"); 641 response.setMIMEType("multipart/x-mixed-replace");
623 MockWebURLLoaderClient client; 642 MockWebURLLoaderClient client;
624 MultipartResponseDelegate delegate(&client, NULL, response, "bound"); 643 MultipartResponseDelegate delegate(&client, NULL, response, "bound");
625 644
626 string data( 645 string data(
627 "--bound\n" 646 "--bound\n"
628 "Content-type: text/plain\n\n" 647 "Content-type: text/plain\n\n"
629 "response data\n" 648 "response data\n"
630 "--bound\n"); 649 "--bound\n");
631 delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); 650 delegate.OnReceivedData(data.c_str(),
632 EXPECT_EQ(1, 651 static_cast<int>(data.length()),
633 client.received_response_); 652 static_cast<int>(data.length()));
634 EXPECT_EQ(string("response data"), 653 EXPECT_EQ(1, client.received_response_);
635 client.data_); 654 EXPECT_EQ(string("response data"), client.data_);
655 EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_);
636 EXPECT_FALSE(client.response_.isMultipartPayload()); 656 EXPECT_FALSE(client.response_.isMultipartPayload());
637 657
638 string data2( 658 string data2(
639 "Content-type: text/plain\n\n" 659 "Content-type: text/plain\n\n"
640 "response data2\n" 660 "response data2\n"
641 "--bound\n"); 661 "--bound\n");
642 delegate.OnReceivedData(data2.c_str(), static_cast<int>(data2.length())); 662 delegate.OnReceivedData(data2.c_str(),
643 EXPECT_EQ(2, 663 static_cast<int>(data2.length()),
644 client.received_response_); 664 static_cast<int>(data2.length()));
645 EXPECT_EQ(string("response data2"), 665 EXPECT_EQ(2, client.received_response_);
646 client.data_); 666 EXPECT_EQ(string("response data2"), client.data_);
667 EXPECT_EQ(static_cast<int>(data.length()) + static_cast<int>(data2.length()),
668 client.total_raw_data_length_);
647 EXPECT_TRUE(client.response_.isMultipartPayload()); 669 EXPECT_TRUE(client.response_.isMultipartPayload());
648 } 670 }
649 671
650 } // namespace 672 } // namespace
OLDNEW
« no previous file with comments | « webkit/glue/multipart_response_delegate.cc ('k') | webkit/glue/resource_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698