| OLD | NEW |
| 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 "config.h" | 7 #include "config.h" |
| 8 | 8 |
| 9 #pragma warning(push, 0) | 9 #pragma warning(push, 0) |
| 10 #include "KURL.h" | 10 #include "KURL.h" |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"); | 366 string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"); |
| 367 delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); | 367 delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); |
| 368 EXPECT_EQ(2, | 368 EXPECT_EQ(2, |
| 369 client.received_response_); | 369 client.received_response_); |
| 370 EXPECT_EQ(1, | 370 EXPECT_EQ(1, |
| 371 client.received_data_); | 371 client.received_data_); |
| 372 EXPECT_EQ(string("foofoo"), | 372 EXPECT_EQ(string("foofoo"), |
| 373 client.data_); | 373 client.data_); |
| 374 } | 374 } |
| 375 | 375 |
| 376 TEST(MultipartResponseTest, MultipartByteRangeParsingTest) { |
| 377 // Test multipart/byteranges based boundary parsing. |
| 378 ResourceResponse response1(KURL(), "multipart/byteranges", 0, "en-US", |
| 379 String()); |
| 380 response1.setHTTPHeaderField(String("Content-Length"), String("200")); |
| 381 response1.setHTTPHeaderField( |
| 382 String("Content-type"), |
| 383 String("multipart/byteranges; boundary=--bound--")); |
| 384 |
| 385 std::string multipart_boundary; |
| 386 bool result = MultipartResponseDelegate::ReadMultipartBoundary( |
| 387 response1, &multipart_boundary); |
| 388 EXPECT_EQ(result, true); |
| 389 EXPECT_EQ(string("--bound--"), |
| 390 multipart_boundary); |
| 391 |
| 392 ResourceResponse response2(KURL(), "image/png", 0, "en-US", |
| 393 String()); |
| 394 |
| 395 response2.setHTTPHeaderField(String("Content-Length"), String("300")); |
| 396 response2.setHTTPHeaderField( |
| 397 String("Last-Modified"), |
| 398 String("Mon, 04 Apr 2005 20:36:01 GMT")); |
| 399 response2.setHTTPHeaderField( |
| 400 String("Date"), |
| 401 String("Thu, 11 Sep 2008 18:21:42 GMT")); |
| 402 |
| 403 multipart_boundary.clear(); |
| 404 result = MultipartResponseDelegate::ReadMultipartBoundary( |
| 405 response2, &multipart_boundary); |
| 406 EXPECT_EQ(result, false); |
| 407 |
| 408 ResourceResponse response3(KURL(), "multipart/byteranges", 0, "en-US", |
| 409 String()); |
| 410 |
| 411 response3.setHTTPHeaderField(String("Content-Length"), String("300")); |
| 412 response3.setHTTPHeaderField( |
| 413 String("Last-Modified"), |
| 414 String("Mon, 04 Apr 2005 20:36:01 GMT")); |
| 415 response3.setHTTPHeaderField( |
| 416 String("Date"), |
| 417 String("Thu, 11 Sep 2008 18:21:42 GMT")); |
| 418 response3.setHTTPHeaderField( |
| 419 String("Content-type"), |
| 420 String("multipart/byteranges")); |
| 421 |
| 422 multipart_boundary.clear(); |
| 423 result = MultipartResponseDelegate::ReadMultipartBoundary( |
| 424 response3, &multipart_boundary); |
| 425 EXPECT_EQ(result, false); |
| 426 EXPECT_EQ(multipart_boundary.length(), 0); |
| 427 } |
| 428 |
| 429 TEST(MultipartResponseTest, MultipartContentRangesTest) { |
| 430 ResourceResponse response1(KURL(), "application/pdf", 0, "en-US", |
| 431 String()); |
| 432 response1.setHTTPHeaderField(String("Content-Length"), String("200")); |
| 433 response1.setHTTPHeaderField( |
| 434 String("Content-Range"), |
| 435 String("bytes 1000-1050/5000")); |
| 436 |
| 437 int content_range_lower_bound = 0; |
| 438 int content_range_upper_bound = 0; |
| 439 |
| 440 bool result = MultipartResponseDelegate::ReadContentRanges( |
| 441 response1, &content_range_lower_bound, |
| 442 &content_range_upper_bound); |
| 443 |
| 444 EXPECT_EQ(result, true); |
| 445 EXPECT_EQ(content_range_lower_bound, 1000); |
| 446 EXPECT_EQ(content_range_upper_bound, 1050); |
| 447 |
| 448 ResourceResponse response2(KURL(), "application/pdf", 0, "en-US", |
| 449 String()); |
| 450 response2.setHTTPHeaderField(String("Content-Length"), String("200")); |
| 451 response2.setHTTPHeaderField( |
| 452 String("Content-Range"), |
| 453 String("bytes 1000/1050")); |
| 454 |
| 455 content_range_lower_bound = 0; |
| 456 content_range_upper_bound = 0; |
| 457 |
| 458 result = MultipartResponseDelegate::ReadContentRanges( |
| 459 response2, &content_range_lower_bound, |
| 460 &content_range_upper_bound); |
| 461 |
| 462 EXPECT_EQ(result, false); |
| 463 } |
| 464 |
| 376 } // namespace | 465 } // namespace |
| 377 | 466 |
| OLD | NEW |