OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "net/base/escape.h" | 7 #include "net/base/escape.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 TEST(EscapeTest, EscapeTextForFormSubmission) { | 61 TEST(EscapeTest, EscapeTextForFormSubmission) { |
62 const EscapeCase escape_cases[] = { | 62 const EscapeCase escape_cases[] = { |
63 {L"foo", L"foo"}, | 63 {L"foo", L"foo"}, |
64 {L"foo bar", L"foo+bar"}, | 64 {L"foo bar", L"foo+bar"}, |
65 {L"foo++", L"foo%2B%2B"} | 65 {L"foo++", L"foo%2B%2B"} |
66 }; | 66 }; |
67 for (size_t i = 0; i < arraysize(escape_cases); ++i) { | 67 for (size_t i = 0; i < arraysize(escape_cases); ++i) { |
68 EscapeCase value = escape_cases[i]; | 68 EscapeCase value = escape_cases[i]; |
69 EXPECT_EQ(WideToUTF16Hack(value.output), | 69 EXPECT_EQ(value.output, EscapeQueryParamValueUTF8(value.input, true)); |
70 EscapeQueryParamValueUTF8(WideToUTF16Hack(value.input), true)); | |
71 } | 70 } |
72 | 71 |
73 const EscapeCase escape_cases_no_plus[] = { | 72 const EscapeCase escape_cases_no_plus[] = { |
74 {L"foo", L"foo"}, | 73 {L"foo", L"foo"}, |
75 {L"foo bar", L"foo%20bar"}, | 74 {L"foo bar", L"foo%20bar"}, |
76 {L"foo++", L"foo%2B%2B"} | 75 {L"foo++", L"foo%2B%2B"} |
77 }; | 76 }; |
78 for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) { | 77 for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) { |
79 EscapeCase value = escape_cases_no_plus[i]; | 78 EscapeCase value = escape_cases_no_plus[i]; |
80 EXPECT_EQ(WideToUTF16Hack(value.output), | 79 EXPECT_EQ(value.output, EscapeQueryParamValueUTF8(value.input, false)); |
81 EscapeQueryParamValueUTF8(WideToUTF16Hack(value.input), false)); | |
82 } | 80 } |
83 | 81 |
84 // Test all the values in we're supposed to be escaping. | 82 // Test all the values in we're supposed to be escaping. |
85 const std::string no_escape( | 83 const std::string no_escape( |
86 "abcdefghijklmnopqrstuvwxyz" | 84 "abcdefghijklmnopqrstuvwxyz" |
87 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 85 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
88 "0123456789" | 86 "0123456789" |
89 "!'()*-._~"); | 87 "!'()*-._~"); |
90 for (int i = 0; i < 256; ++i) { | 88 for (int i = 0; i < 256; ++i) { |
91 std::string in; | 89 std::string in; |
(...skipping 17 matching lines...) Expand all Loading... |
109 // Check to see if EscapeQueryParamValueUTF8 is the same as | 107 // Check to see if EscapeQueryParamValueUTF8 is the same as |
110 // EscapeQueryParamValue(..., kCodepageUTF8,) | 108 // EscapeQueryParamValue(..., kCodepageUTF8,) |
111 string16 test_str; | 109 string16 test_str; |
112 test_str.reserve(5000); | 110 test_str.reserve(5000); |
113 for (int i = 1; i < 5000; ++i) { | 111 for (int i = 1; i < 5000; ++i) { |
114 test_str.push_back(i); | 112 test_str.push_back(i); |
115 } | 113 } |
116 string16 wide; | 114 string16 wide; |
117 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, true, | 115 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, true, |
118 &wide)); | 116 &wide)); |
119 EXPECT_EQ(wide, EscapeQueryParamValueUTF8(test_str, true)); | 117 EXPECT_EQ(UTF16ToWideHack(wide), |
| 118 EscapeQueryParamValueUTF8(UTF16ToWideHack(test_str), true)); |
120 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, false, | 119 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, false, |
121 &wide)); | 120 &wide)); |
122 EXPECT_EQ(wide, EscapeQueryParamValueUTF8(test_str, false)); | 121 EXPECT_EQ(UTF16ToWideHack(wide), |
| 122 EscapeQueryParamValueUTF8(UTF16ToWideHack(test_str), false)); |
123 } | 123 } |
124 | 124 |
125 TEST(EscapeTest, EscapePath) { | 125 TEST(EscapeTest, EscapePath) { |
126 ASSERT_EQ( | 126 ASSERT_EQ( |
127 // Most of the character space we care about, un-escaped | 127 // Most of the character space we care about, un-escaped |
128 EscapePath( | 128 EscapePath( |
129 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" | 129 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" |
130 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 130 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
131 "[\\]^_`abcdefghijklmnopqrstuvwxyz" | 131 "[\\]^_`abcdefghijklmnopqrstuvwxyz" |
132 "{|}~\x7f\x80\xff"), | 132 "{|}~\x7f\x80\xff"), |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 { "'", "'" }, | 389 { "'", "'" }, |
390 { "<", "<" }, | 390 { "<", "<" }, |
391 { ">", ">" }, | 391 { ">", ">" }, |
392 { "& &", "& &" }, | 392 { "& &", "& &" }, |
393 }; | 393 }; |
394 for (size_t i = 0; i < arraysize(tests); ++i) { | 394 for (size_t i = 0; i < arraysize(tests); ++i) { |
395 string16 result = UnescapeForHTML(ASCIIToUTF16(tests[i].input)); | 395 string16 result = UnescapeForHTML(ASCIIToUTF16(tests[i].input)); |
396 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_output), result); | 396 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_output), result); |
397 } | 397 } |
398 } | 398 } |
OLD | NEW |