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

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

Powered by Google App Engine
This is Rietveld 408576698