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

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

Issue 6322001: Remove wstring from TemplateURL and friends.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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/base/escape.cc ('k') | no next file » | 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) 2009 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 <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
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(value.output, EscapeQueryParamValueUTF8(value.input, true)); 69 EXPECT_EQ(WideToUTF16Hack(value.output),
70 EscapeQueryParamValueUTF8(WideToUTF16Hack(value.input), true));
70 } 71 }
71 72
72 const EscapeCase escape_cases_no_plus[] = { 73 const EscapeCase escape_cases_no_plus[] = {
73 {L"foo", L"foo"}, 74 {L"foo", L"foo"},
74 {L"foo bar", L"foo%20bar"}, 75 {L"foo bar", L"foo%20bar"},
75 {L"foo++", L"foo%2B%2B"} 76 {L"foo++", L"foo%2B%2B"}
76 }; 77 };
77 for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) { 78 for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) {
78 EscapeCase value = escape_cases_no_plus[i]; 79 EscapeCase value = escape_cases_no_plus[i];
79 EXPECT_EQ(value.output, EscapeQueryParamValueUTF8(value.input, false)); 80 EXPECT_EQ(WideToUTF16Hack(value.output),
81 EscapeQueryParamValueUTF8(WideToUTF16Hack(value.input), false));
80 } 82 }
81 83
82 // Test all the values in we're supposed to be escaping. 84 // Test all the values in we're supposed to be escaping.
83 const std::string no_escape( 85 const std::string no_escape(
84 "abcdefghijklmnopqrstuvwxyz" 86 "abcdefghijklmnopqrstuvwxyz"
85 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 87 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
86 "0123456789" 88 "0123456789"
87 "!'()*-._~"); 89 "!'()*-._~");
88 for (int i = 0; i < 256; ++i) { 90 for (int i = 0; i < 256; ++i) {
89 std::string in; 91 std::string in;
(...skipping 17 matching lines...) Expand all
107 // Check to see if EscapeQueryParamValueUTF8 is the same as 109 // Check to see if EscapeQueryParamValueUTF8 is the same as
108 // EscapeQueryParamValue(..., kCodepageUTF8,) 110 // EscapeQueryParamValue(..., kCodepageUTF8,)
109 string16 test_str; 111 string16 test_str;
110 test_str.reserve(5000); 112 test_str.reserve(5000);
111 for (int i = 1; i < 5000; ++i) { 113 for (int i = 1; i < 5000; ++i) {
112 test_str.push_back(i); 114 test_str.push_back(i);
113 } 115 }
114 string16 wide; 116 string16 wide;
115 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, true, 117 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, true,
116 &wide)); 118 &wide));
117 EXPECT_EQ(UTF16ToWideHack(wide), 119 EXPECT_EQ(wide, EscapeQueryParamValueUTF8(test_str, true));
118 EscapeQueryParamValueUTF8(UTF16ToWideHack(test_str), true));
119 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, false, 120 EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, false,
120 &wide)); 121 &wide));
121 EXPECT_EQ(UTF16ToWideHack(wide), 122 EXPECT_EQ(wide, EscapeQueryParamValueUTF8(test_str, false));
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
389 { "&#39;", "'" }, 389 { "&#39;", "'" },
390 { "&lt;", "<" }, 390 { "&lt;", "<" },
391 { "&gt;", ">" }, 391 { "&gt;", ">" },
392 { "&amp; &", "& &" }, 392 { "&amp; &", "& &" },
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 }
OLDNEW
« no previous file with comments | « net/base/escape.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698