| OLD | NEW |
| 1 // Copyright (c) 2009 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" |
| 12 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 struct EscapeCase { | 18 struct EscapeCase { |
| 18 const wchar_t* input; | 19 const wchar_t* input; |
| 19 const wchar_t* output; | 20 const wchar_t* output; |
| 20 }; | 21 }; |
| 21 | 22 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 std::string in; | 89 std::string in; |
| 89 in.push_back(i); | 90 in.push_back(i); |
| 90 std::string out = EscapeQueryParamValue(in, true); | 91 std::string out = EscapeQueryParamValue(in, true); |
| 91 if (0 == i) { | 92 if (0 == i) { |
| 92 EXPECT_EQ(out, std::string("%00")); | 93 EXPECT_EQ(out, std::string("%00")); |
| 93 } else if (32 == i) { | 94 } else if (32 == i) { |
| 94 // Spaces are plus escaped like web forms. | 95 // Spaces are plus escaped like web forms. |
| 95 EXPECT_EQ(out, std::string("+")); | 96 EXPECT_EQ(out, std::string("+")); |
| 96 } else if (no_escape.find(in) == std::string::npos) { | 97 } else if (no_escape.find(in) == std::string::npos) { |
| 97 // Check %hex escaping | 98 // Check %hex escaping |
| 98 std::string expected = StringPrintf("%%%02X", i); | 99 std::string expected = base::StringPrintf("%%%02X", i); |
| 99 EXPECT_EQ(expected, out); | 100 EXPECT_EQ(expected, out); |
| 100 } else { | 101 } else { |
| 101 // No change for things in the no_escape list. | 102 // No change for things in the no_escape list. |
| 102 EXPECT_EQ(out, in); | 103 EXPECT_EQ(out, in); |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 // Check to see if EscapeQueryParamValueUTF8 is the same as | 107 // Check to see if EscapeQueryParamValueUTF8 is the same as |
| 107 // EscapeQueryParamValue(..., kCodepageUTF8,) | 108 // EscapeQueryParamValue(..., kCodepageUTF8,) |
| 108 string16 test_str; | 109 string16 test_str; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 { "'", "'" }, | 389 { "'", "'" }, |
| 389 { "<", "<" }, | 390 { "<", "<" }, |
| 390 { ">", ">" }, | 391 { ">", ">" }, |
| 391 { "& &", "& &" }, | 392 { "& &", "& &" }, |
| 392 }; | 393 }; |
| 393 for (size_t i = 0; i < arraysize(tests); ++i) { | 394 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 394 string16 result = UnescapeForHTML(ASCIIToUTF16(tests[i].input)); | 395 string16 result = UnescapeForHTML(ASCIIToUTF16(tests[i].input)); |
| 395 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_output), result); | 396 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_output), result); |
| 396 } | 397 } |
| 397 } | 398 } |
| OLD | NEW |