OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/child/multipart_response_delegate.h" | 5 #include "content/child/multipart_response_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"); | 483 string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"); |
484 delegate.OnReceivedData(data.c_str(), | 484 delegate.OnReceivedData(data.c_str(), |
485 static_cast<int>(data.length()), | 485 static_cast<int>(data.length()), |
486 static_cast<int>(data.length())); | 486 static_cast<int>(data.length())); |
487 EXPECT_EQ(2, client.received_response_); | 487 EXPECT_EQ(2, client.received_response_); |
488 EXPECT_EQ(1, client.received_data_); | 488 EXPECT_EQ(1, client.received_data_); |
489 EXPECT_EQ(string("foofoo"), client.data_); | 489 EXPECT_EQ(string("foofoo"), client.data_); |
490 EXPECT_EQ(static_cast<int>(data.length()), client.total_encoded_data_length_); | 490 EXPECT_EQ(static_cast<int>(data.length()), client.total_encoded_data_length_); |
491 } | 491 } |
492 | 492 |
493 TEST(MultipartResponseTest, MultipartByteRangeParsingTest) { | |
494 // Test multipart/byteranges based boundary parsing. | |
495 WebURLResponse response1; | |
496 response1.initialize(); | |
497 response1.setMIMEType("multipart/x-mixed-replace"); | |
498 response1.setHTTPHeaderField("Content-Length", "200"); | |
499 response1.setHTTPHeaderField("Content-type", | |
500 "multipart/byteranges; boundary=--bound--"); | |
501 | |
502 std::string multipart_boundary; | |
503 bool result = MultipartResponseDelegate::ReadMultipartBoundary( | |
504 response1, &multipart_boundary); | |
505 EXPECT_EQ(result, true); | |
506 EXPECT_EQ(string("--bound--"), | |
507 multipart_boundary); | |
508 | |
509 WebURLResponse response2; | |
510 response2.initialize(); | |
511 response2.setMIMEType("image/png"); | |
512 | |
513 response2.setHTTPHeaderField("Content-Length", "300"); | |
514 response2.setHTTPHeaderField("Last-Modified", | |
515 "Mon, 04 Apr 2005 20:36:01 GMT"); | |
516 response2.setHTTPHeaderField("Date", "Thu, 11 Sep 2008 18:21:42 GMT"); | |
517 | |
518 multipart_boundary.clear(); | |
519 result = MultipartResponseDelegate::ReadMultipartBoundary( | |
520 response2, &multipart_boundary); | |
521 EXPECT_EQ(result, false); | |
522 | |
523 WebURLResponse response3; | |
524 response3.initialize(); | |
525 response3.setMIMEType("multipart/byteranges"); | |
526 | |
527 response3.setHTTPHeaderField("Content-Length", "300"); | |
528 response3.setHTTPHeaderField("Last-Modified", | |
529 "Mon, 04 Apr 2005 20:36:01 GMT"); | |
530 response3.setHTTPHeaderField("Date", "Thu, 11 Sep 2008 18:21:42 GMT"); | |
531 response3.setHTTPHeaderField("Content-type", "multipart/byteranges"); | |
532 | |
533 multipart_boundary.clear(); | |
534 result = MultipartResponseDelegate::ReadMultipartBoundary( | |
535 response3, &multipart_boundary); | |
536 EXPECT_EQ(result, false); | |
537 EXPECT_EQ(multipart_boundary.length(), 0U); | |
538 | |
539 WebURLResponse response4; | |
540 response4.initialize(); | |
541 response4.setMIMEType("multipart/byteranges"); | |
542 response4.setHTTPHeaderField("Content-Length", "200"); | |
543 response4.setHTTPHeaderField("Content-type", | |
544 "multipart/byteranges; boundary=--bound--; charSet=utf8"); | |
545 | |
546 multipart_boundary.clear(); | |
547 | |
548 result = MultipartResponseDelegate::ReadMultipartBoundary( | |
549 response4, &multipart_boundary); | |
550 EXPECT_EQ(result, true); | |
551 EXPECT_EQ(string("--bound--"), multipart_boundary); | |
552 | |
553 WebURLResponse response5; | |
554 response5.initialize(); | |
555 response5.setMIMEType("multipart/byteranges"); | |
556 response5.setHTTPHeaderField("Content-Length", "200"); | |
557 response5.setHTTPHeaderField("Content-type", | |
558 "multipart/byteranges; boundary=\"--bound--\"; charSet=utf8"); | |
559 | |
560 multipart_boundary.clear(); | |
561 | |
562 result = MultipartResponseDelegate::ReadMultipartBoundary( | |
563 response5, &multipart_boundary); | |
564 EXPECT_EQ(result, true); | |
565 EXPECT_EQ(string("--bound--"), multipart_boundary); | |
566 } | |
567 | |
568 TEST(MultipartResponseTest, MultipartContentRangesTest) { | 493 TEST(MultipartResponseTest, MultipartContentRangesTest) { |
569 WebURLResponse response1; | 494 WebURLResponse response1; |
570 response1.initialize(); | 495 response1.initialize(); |
571 response1.setMIMEType("application/pdf"); | 496 response1.setMIMEType("application/pdf"); |
572 response1.setHTTPHeaderField("Content-Length", "200"); // Ignored! | 497 response1.setHTTPHeaderField("Content-Length", "200"); // Ignored! |
573 // Use intentionally >32bit values to check they are handled correctly. | 498 // Use intentionally >32bit values to check they are handled correctly. |
574 response1.setHTTPHeaderField("Content-Range", | 499 response1.setHTTPHeaderField("Content-Range", |
575 "bytes 5000000000-5000000050/6000000000"); | 500 "bytes 5000000000-5000000050/6000000000"); |
576 | 501 |
577 int64_t content_range_lower_bound = 0; | 502 int64_t content_range_lower_bound = 0; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 EXPECT_EQ(2, client.received_response_); | 596 EXPECT_EQ(2, client.received_response_); |
672 EXPECT_EQ(string("response data2"), client.data_); | 597 EXPECT_EQ(string("response data2"), client.data_); |
673 EXPECT_EQ(static_cast<int>(data.length()) + static_cast<int>(data2.length()), | 598 EXPECT_EQ(static_cast<int>(data.length()) + static_cast<int>(data2.length()), |
674 client.total_encoded_data_length_); | 599 client.total_encoded_data_length_); |
675 EXPECT_TRUE(client.response_.isMultipartPayload()); | 600 EXPECT_TRUE(client.response_.isMultipartPayload()); |
676 } | 601 } |
677 | 602 |
678 } // namespace | 603 } // namespace |
679 | 604 |
680 } // namespace content | 605 } // namespace content |
OLD | NEW |