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

Side by Side Diff: net/http/http_util_unittest.cc

Issue 92006: Implement a parser that parses the "Range" HTTP header... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « net/http/http_util.cc ('k') | net/net.gyp » ('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-2009 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "net/http/http_util.h" 8 #include "net/http/http_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 using net::HttpUtil; 11 using net::HttpUtil;
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 "ja;q=0.2"), 506 "ja;q=0.2"),
507 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); 507 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja"));
508 } 508 }
509 509
510 TEST(HttpUtilTest, GenerateAcceptCharsetHeader) { 510 TEST(HttpUtilTest, GenerateAcceptCharsetHeader) {
511 EXPECT_EQ(std::string("utf-8,*;q=0.5"), 511 EXPECT_EQ(std::string("utf-8,*;q=0.5"),
512 HttpUtil::GenerateAcceptCharsetHeader("utf-8")); 512 HttpUtil::GenerateAcceptCharsetHeader("utf-8"));
513 EXPECT_EQ(std::string("EUC-JP,utf-8;q=0.7,*;q=0.3"), 513 EXPECT_EQ(std::string("EUC-JP,utf-8;q=0.7,*;q=0.3"),
514 HttpUtil::GenerateAcceptCharsetHeader("EUC-JP")); 514 HttpUtil::GenerateAcceptCharsetHeader("EUC-JP"));
515 } 515 }
516
517 TEST(HttpUtilTest, ParseRanges) {
518 const struct {
519 const char* headers;
520 bool expected_return_value;
521 size_t expected_ranges_size;
522 const struct {
523 int64 expected_first_byte_position;
524 int64 expected_last_byte_position;
525 int64 expected_suffix_length;
526 } expected_ranges[10];
527 } tests[] = {
528 { "Range: bytes=0-10",
529 true,
530 1,
531 { {0, 10, -1}, }
532 },
533 { "Range: bytes=10-0",
534 false,
535 0,
536 {}
537 },
538 { "Range: BytES=0-10",
539 true,
540 1,
541 { {0, 10, -1}, }
542 },
543 { "Range: megabytes=0-10",
544 false,
545 0,
546 {}
547 },
548 { "Range: bytes0-10",
549 false,
550 0,
551 {}
552 },
553 { "Range: bytes=0-0,0-10,10-20,100-200,100-,-200",
554 true,
555 6,
556 { {0, 0, -1},
557 {0, 10, -1},
558 {10, 20, -1},
559 {100, 200, -1},
560 {100, -1, -1},
561 {-1, -1, 200},
562 }
563 },
564 { "Range: bytes=0-10\r\n"
565 "Range: bytes=0-10,10-20,100-200,100-,-200",
566 true,
567 1,
568 { {0, 10, -1}
569 }
570 },
571 { "Range: bytes=",
572 false,
573 0,
574 {}
575 },
576 { "Range: bytes=-",
577 false,
578 0,
579 {}
580 },
581 { "Range: bytes=0-10-",
582 false,
583 0,
584 {}
585 },
586 { "Range: bytes=-0-10",
587 false,
588 0,
589 {}
590 },
591 { "Range: bytes =0-10\r\n",
592 true,
593 1,
594 { {0, 10, -1}
595 }
596 },
597 { "Range: bytes= 0-10 \r\n",
598 true,
599 1,
600 { {0, 10, -1}
601 }
602 },
603 { "Range: bytes = 0 - 10 \r\n",
604 true,
605 1,
606 { {0, 10, -1}
607 }
608 },
609 { "Range: bytes= 0-1 0\r\n",
610 false,
611 0,
612 {}
613 },
614 { "Range: bytes= 0- -10\r\n",
615 false,
616 0,
617 {}
618 },
619 { "Range: bytes= 0 - 1 , 10 -20, 100- 200 , 100-, -200 \r\n",
620 true,
621 5,
622 { {0, 1, -1},
623 {10, 20, -1},
624 {100, 200, -1},
625 {100, -1, -1},
626 {-1, -1, 200},
627 }
628 },
629 };
630
631 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
632 std::vector<net::HttpByteRange> ranges;
633 bool return_value = HttpUtil::ParseRanges(std::string(tests[i].headers),
634 &ranges);
635 EXPECT_EQ(tests[i].expected_return_value, return_value);
636 if (return_value) {
637 EXPECT_EQ(tests[i].expected_ranges_size, ranges.size());
638 for (size_t j = 0; j < ranges.size(); ++j) {
639 EXPECT_EQ(tests[i].expected_ranges[j].expected_first_byte_position,
640 ranges[j].first_byte_position());
641 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position,
642 ranges[j].last_byte_position());
643 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length,
644 ranges[j].suffix_length());
645 }
646 }
647 }
648 }
OLDNEW
« no previous file with comments | « net/http/http_util.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698