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

Side by Side Diff: net/base/net_util_unittest.cc

Issue 9296005: Delete net::GetHeaderParamValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Delete net::GetHeaderParamValue Created 8 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 EXPECT_EQ(result, tests[i].expected); 741 EXPECT_EQ(result, tests[i].expected);
742 } 742 }
743 743
744 // Test again with empty headers. 744 // Test again with empty headers.
745 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 745 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
746 std::string result = GetSpecificHeader(std::string(), tests[i].header_name); 746 std::string result = GetSpecificHeader(std::string(), tests[i].header_name);
747 EXPECT_EQ(result, std::string()); 747 EXPECT_EQ(result, std::string());
748 } 748 }
749 } 749 }
750 750
751 TEST(NetUtilTest, GetHeaderParamValue) {
752 const HeaderParamCase tests[] = {
753 {"Content-type", "charset", "utf-8"},
754 {"content-disposition", "filename", "download.pdf"},
755 {"Content-Type", "badparam", ""},
756 {"X-Malformed", "arg", "test\""},
757 {"X-Malformed2", "arg", ""},
758 {"X-Test", "arg1", "val1"},
759 {"X-Test", "arg2", "val2"},
760 {"Bad-Header", "badparam", ""},
761 {"Bad-Header", "", ""},
762 {"", "badparam", ""},
763 {"", "", ""},
764 };
765 // TODO(mpcomplete): add tests for other formats of headers.
766
767 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
768 std::string header_value =
769 GetSpecificHeader(google_headers, tests[i].header_name);
770 std::string result =
771 GetHeaderParamValue(header_value, tests[i].param_name,
772 QuoteRule::REMOVE_OUTER_QUOTES);
773 EXPECT_EQ(result, tests[i].expected);
774 }
775
776 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
777 std::string header_value =
778 GetSpecificHeader(std::string(), tests[i].header_name);
779 std::string result =
780 GetHeaderParamValue(header_value, tests[i].param_name,
781 QuoteRule::REMOVE_OUTER_QUOTES);
782 EXPECT_EQ(result, std::string());
783 }
784 }
785
786 TEST(NetUtilTest, GetHeaderParamValueQuotes) {
787 struct {
788 const char* header;
789 const char* expected_with_quotes;
790 const char* expected_without_quotes;
791 } tests[] = {
792 {"filename=foo", "foo", "foo"},
793 {"filename=\"foo\"", "\"foo\"", "foo"},
794 {"filename=foo\"", "foo\"", "foo\""},
795 {"filename=fo\"o", "fo\"o", "fo\"o"},
796 };
797
798 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
799 std::string actual_with_quotes =
800 GetHeaderParamValue(tests[i].header, "filename",
801 QuoteRule::KEEP_OUTER_QUOTES);
802 std::string actual_without_quotes =
803 GetHeaderParamValue(tests[i].header, "filename",
804 QuoteRule::REMOVE_OUTER_QUOTES);
805 EXPECT_EQ(tests[i].expected_with_quotes, actual_with_quotes)
806 << "Failed while processing: " << tests[i].header;
807 EXPECT_EQ(tests[i].expected_without_quotes, actual_without_quotes)
808 << "Failed while processing: " << tests[i].header;
809 }
810 }
811
812 TEST(NetUtilTest, IDNToUnicodeFast) { 751 TEST(NetUtilTest, IDNToUnicodeFast) {
813 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) { 752 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) {
814 for (size_t j = 0; j < arraysize(kLanguages); j++) { 753 for (size_t j = 0; j < arraysize(kLanguages); j++) {
815 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow 754 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow
816 if (j == 3 || j == 17 || j == 18) 755 if (j == 3 || j == 17 || j == 18)
817 continue; 756 continue;
818 string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); 757 string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j]));
819 string16 expected(idn_cases[i].unicode_allowed[j] ? 758 string16 expected(idn_cases[i].unicode_allowed[j] ?
820 WideToUTF16(idn_cases[i].unicode_output) : 759 WideToUTF16(idn_cases[i].unicode_output) :
821 ASCIIToUTF16(idn_cases[i].input)); 760 ASCIIToUTF16(idn_cases[i].input));
(...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after
3265 if (it->address[i] != 0) { 3204 if (it->address[i] != 0) {
3266 all_zeroes = false; 3205 all_zeroes = false;
3267 break; 3206 break;
3268 } 3207 }
3269 } 3208 }
3270 EXPECT_FALSE(all_zeroes); 3209 EXPECT_FALSE(all_zeroes);
3271 } 3210 }
3272 } 3211 }
3273 3212
3274 } // namespace net 3213 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698