| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); | 625 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); |
| 626 } | 626 } |
| 627 | 627 |
| 628 TEST(HttpUtilTest, GenerateAcceptCharsetHeader) { | 628 TEST(HttpUtilTest, GenerateAcceptCharsetHeader) { |
| 629 EXPECT_EQ(std::string("utf-8,*;q=0.5"), | 629 EXPECT_EQ(std::string("utf-8,*;q=0.5"), |
| 630 HttpUtil::GenerateAcceptCharsetHeader("utf-8")); | 630 HttpUtil::GenerateAcceptCharsetHeader("utf-8")); |
| 631 EXPECT_EQ(std::string("EUC-JP,utf-8;q=0.7,*;q=0.3"), | 631 EXPECT_EQ(std::string("EUC-JP,utf-8;q=0.7,*;q=0.3"), |
| 632 HttpUtil::GenerateAcceptCharsetHeader("EUC-JP")); | 632 HttpUtil::GenerateAcceptCharsetHeader("EUC-JP")); |
| 633 } | 633 } |
| 634 | 634 |
| 635 // HttpResponseHeadersTest.GetMimeType also tests ParseContentType. |
| 636 TEST(HttpUtilTest, ParseContentType) { |
| 637 const struct { |
| 638 const char* content_type; |
| 639 const char* expected_mime_type; |
| 640 const char* expected_charset; |
| 641 const bool expected_had_charset; |
| 642 const char* expected_boundary; |
| 643 } tests[] = { |
| 644 { "text/html; charset=utf-8", |
| 645 "text/html", |
| 646 "utf-8", |
| 647 true, |
| 648 "" |
| 649 }, |
| 650 { "text/html; charset =utf-8", |
| 651 "text/html", |
| 652 "utf-8", |
| 653 true, |
| 654 "" |
| 655 }, |
| 656 { "text/html; charset= utf-8", |
| 657 "text/html", |
| 658 "utf-8", |
| 659 true, |
| 660 "" |
| 661 }, |
| 662 { "text/html; charset=utf-8 ", |
| 663 "text/html", |
| 664 "utf-8", |
| 665 true, |
| 666 "" |
| 667 }, |
| 668 { "text/html; boundary=\"WebKit-ada-df-dsf-adsfadsfs\"", |
| 669 "text/html", |
| 670 "", |
| 671 false, |
| 672 "\"WebKit-ada-df-dsf-adsfadsfs\"" |
| 673 }, |
| 674 { "text/html; boundary =\"WebKit-ada-df-dsf-adsfadsfs\"", |
| 675 "text/html", |
| 676 "", |
| 677 false, |
| 678 "\"WebKit-ada-df-dsf-adsfadsfs\"" |
| 679 }, |
| 680 { "text/html; boundary= \"WebKit-ada-df-dsf-adsfadsfs\"", |
| 681 "text/html", |
| 682 "", |
| 683 false, |
| 684 "\"WebKit-ada-df-dsf-adsfadsfs\"" |
| 685 }, |
| 686 { "text/html; boundary= \"WebKit-ada-df-dsf-adsfadsfs\" ", |
| 687 "text/html", |
| 688 "", |
| 689 false, |
| 690 "\"WebKit-ada-df-dsf-adsfadsfs\"" |
| 691 }, |
| 692 { "text/html; boundary=\"WebKit-ada-df-dsf-adsfadsfs \"", |
| 693 "text/html", |
| 694 "", |
| 695 false, |
| 696 "\"WebKit-ada-df-dsf-adsfadsfs \"" |
| 697 }, |
| 698 { "text/html; boundary=WebKit-ada-df-dsf-adsfadsfs", |
| 699 "text/html", |
| 700 "", |
| 701 false, |
| 702 "WebKit-ada-df-dsf-adsfadsfs" |
| 703 }, |
| 704 // TODO(abarth): Add more interesting test cases. |
| 705 }; |
| 706 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 707 std::string mime_type; |
| 708 std::string charset; |
| 709 bool had_charset = false; |
| 710 std::string boundary; |
| 711 net::HttpUtil::ParseContentType(tests[i].content_type, &mime_type, |
| 712 &charset, &had_charset, &boundary); |
| 713 EXPECT_EQ(tests[i].expected_mime_type, mime_type) << "i=" << i; |
| 714 EXPECT_EQ(tests[i].expected_charset, charset) << "i=" << i; |
| 715 EXPECT_EQ(tests[i].expected_had_charset, had_charset) << "i=" << i; |
| 716 EXPECT_EQ(tests[i].expected_boundary, boundary) << "i=" << i; |
| 717 } |
| 718 } |
| 719 |
| 635 TEST(HttpUtilTest, ParseRanges) { | 720 TEST(HttpUtilTest, ParseRanges) { |
| 636 const struct { | 721 const struct { |
| 637 const char* headers; | 722 const char* headers; |
| 638 bool expected_return_value; | 723 bool expected_return_value; |
| 639 size_t expected_ranges_size; | 724 size_t expected_ranges_size; |
| 640 const struct { | 725 const struct { |
| 641 int64 expected_first_byte_position; | 726 int64 expected_first_byte_position; |
| 642 int64 expected_last_byte_position; | 727 int64 expected_last_byte_position; |
| 643 int64 expected_suffix_length; | 728 int64 expected_suffix_length; |
| 644 } expected_ranges[10]; | 729 } expected_ranges[10]; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { | 1042 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { |
| 958 std::string data = "name='value"; | 1043 std::string data = "name='value"; |
| 959 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 1044 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
| 960 EXPECT_TRUE(parser.valid()); | 1045 EXPECT_TRUE(parser.valid()); |
| 961 | 1046 |
| 962 ASSERT_NO_FATAL_FAILURE( | 1047 ASSERT_NO_FATAL_FAILURE( |
| 963 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 1048 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
| 964 ASSERT_NO_FATAL_FAILURE( | 1049 ASSERT_NO_FATAL_FAILURE( |
| 965 CheckNextNameValuePair(&parser, false, true, "", "")); | 1050 CheckNextNameValuePair(&parser, false, true, "", "")); |
| 966 } | 1051 } |
| OLD | NEW |