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

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

Issue 112963005: Update uses of UTF conversions in courgette/, device/, extensions/, google_apis/, gpu/, ipc/, media… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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') | net/base/keygen_handler_win.cc » ('j') | 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) 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "net/base/escape.h" 8 #include "net/base/escape.h"
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 {L"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS, 243 {L"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS,
244 L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, 244 L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"},
245 {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"}, 245 {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"},
246 {L"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS, 246 {L"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS,
247 L"Hello%20\x13\x10\x02"}, 247 L"Hello%20\x13\x10\x02"},
248 {L"Hello\x9824\x9827", UnescapeRule::CONTROL_CHARS, 248 {L"Hello\x9824\x9827", UnescapeRule::CONTROL_CHARS,
249 L"Hello\x9824\x9827"}, 249 L"Hello\x9824\x9827"},
250 }; 250 };
251 251
252 for (size_t i = 0; i < arraysize(unescape_cases); i++) { 252 for (size_t i = 0; i < arraysize(unescape_cases); i++) {
253 base::string16 str(WideToUTF16(unescape_cases[i].input)); 253 base::string16 str(base::WideToUTF16(unescape_cases[i].input));
254 EXPECT_EQ(WideToUTF16(unescape_cases[i].output), 254 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].output),
255 UnescapeURLComponent(str, unescape_cases[i].rules)); 255 UnescapeURLComponent(str, unescape_cases[i].rules));
256 } 256 }
257 257
258 // Test the NULL character unescaping (which wouldn't work above since those 258 // Test the NULL character unescaping (which wouldn't work above since those
259 // are just char pointers). 259 // are just char pointers).
260 base::string16 input(WideToUTF16(L"Null")); 260 base::string16 input(base::WideToUTF16(L"Null"));
261 input.push_back(0); // Also have a NULL in the input. 261 input.push_back(0); // Also have a NULL in the input.
262 input.append(WideToUTF16(L"%00%39Test")); 262 input.append(base::WideToUTF16(L"%00%39Test"));
263 263
264 // When we're unescaping NULLs 264 // When we're unescaping NULLs
265 base::string16 expected(WideToUTF16(L"Null")); 265 base::string16 expected(base::WideToUTF16(L"Null"));
266 expected.push_back(0); 266 expected.push_back(0);
267 expected.push_back(0); 267 expected.push_back(0);
268 expected.append(ASCIIToUTF16("9Test")); 268 expected.append(base::ASCIIToUTF16("9Test"));
269 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::CONTROL_CHARS)); 269 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::CONTROL_CHARS));
270 270
271 // When we're not unescaping NULLs. 271 // When we're not unescaping NULLs.
272 expected = WideToUTF16(L"Null"); 272 expected = base::WideToUTF16(L"Null");
273 expected.push_back(0); 273 expected.push_back(0);
274 expected.append(WideToUTF16(L"%009Test")); 274 expected.append(base::WideToUTF16(L"%009Test"));
275 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL)); 275 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL));
276 } 276 }
277 277
278 TEST(EscapeTest, UnescapeAndDecodeUTF8URLComponent) { 278 TEST(EscapeTest, UnescapeAndDecodeUTF8URLComponent) {
279 const UnescapeAndDecodeCase unescape_cases[] = { 279 const UnescapeAndDecodeCase unescape_cases[] = {
280 { "%", 280 { "%",
281 "%", 281 "%",
282 "%", 282 "%",
283 L"%"}, 283 L"%"},
284 { "+", 284 { "+",
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 UnescapeRule::NORMAL); 324 UnescapeRule::NORMAL);
325 EXPECT_EQ(std::string(unescape_cases[i].url_unescaped), unescaped); 325 EXPECT_EQ(std::string(unescape_cases[i].url_unescaped), unescaped);
326 326
327 unescaped = UnescapeURLComponent(unescape_cases[i].input, 327 unescaped = UnescapeURLComponent(unescape_cases[i].input,
328 UnescapeRule::REPLACE_PLUS_WITH_SPACE); 328 UnescapeRule::REPLACE_PLUS_WITH_SPACE);
329 EXPECT_EQ(std::string(unescape_cases[i].query_unescaped), unescaped); 329 EXPECT_EQ(std::string(unescape_cases[i].query_unescaped), unescaped);
330 330
331 // TODO: Need to test unescape_spaces and unescape_percent. 331 // TODO: Need to test unescape_spaces and unescape_percent.
332 base::string16 decoded = UnescapeAndDecodeUTF8URLComponent( 332 base::string16 decoded = UnescapeAndDecodeUTF8URLComponent(
333 unescape_cases[i].input, UnescapeRule::NORMAL, NULL); 333 unescape_cases[i].input, UnescapeRule::NORMAL, NULL);
334 EXPECT_EQ(WideToUTF16(unescape_cases[i].decoded), decoded); 334 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].decoded), decoded);
335 } 335 }
336 } 336 }
337 337
338 TEST(EscapeTest, AdjustOffset) { 338 TEST(EscapeTest, AdjustOffset) {
339 const AdjustOffsetCase adjust_cases[] = { 339 const AdjustOffsetCase adjust_cases[] = {
340 {"", 0, 0}, 340 {"", 0, 0},
341 {"", 1, std::string::npos}, 341 {"", 1, std::string::npos},
342 {"test", 0, 0}, 342 {"test", 0, 0},
343 {"test", 2, 2}, 343 {"test", 2, 2},
344 {"test", 4, 4}, 344 {"test", 4, 4},
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 { "&lt;&gt;&amp;&quot;&#39;", "<>&\"'" }, 380 { "&lt;&gt;&amp;&quot;&#39;", "<>&\"'" },
381 { "& lt; &amp ; &; '", "& lt; &amp ; &; '" }, 381 { "& lt; &amp ; &; '", "& lt; &amp ; &; '" },
382 { "&amp;", "&" }, 382 { "&amp;", "&" },
383 { "&quot;", "\"" }, 383 { "&quot;", "\"" },
384 { "&#39;", "'" }, 384 { "&#39;", "'" },
385 { "&lt;", "<" }, 385 { "&lt;", "<" },
386 { "&gt;", ">" }, 386 { "&gt;", ">" },
387 { "&amp; &", "& &" }, 387 { "&amp; &", "& &" },
388 }; 388 };
389 for (size_t i = 0; i < arraysize(tests); ++i) { 389 for (size_t i = 0; i < arraysize(tests); ++i) {
390 base::string16 result = UnescapeForHTML(ASCIIToUTF16(tests[i].input)); 390 base::string16 result = UnescapeForHTML(base::ASCIIToUTF16(tests[i].input));
391 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_output), result); 391 EXPECT_EQ(base::ASCIIToUTF16(tests[i].expected_output), result);
392 } 392 }
393 } 393 }
394 394
395 TEST(EscapeTest, AdjustEncodingOffset) { 395 TEST(EscapeTest, AdjustEncodingOffset) {
396 // Imagine we have strings as shown in the following cases where the 396 // Imagine we have strings as shown in the following cases where the
397 // %XX's represent encoded characters 397 // %XX's represent encoded characters
398 398
399 // 1: abc%ECdef ==> abcXdef 399 // 1: abc%ECdef ==> abcXdef
400 std::vector<size_t> offsets; 400 std::vector<size_t> offsets;
401 for (size_t t = 0; t < 9; ++t) 401 for (size_t t = 0; t < 9; ++t)
(...skipping 21 matching lines...) Expand all
423 internal::AdjustEncodingOffset(adjustments)); 423 internal::AdjustEncodingOffset(adjustments));
424 size_t expected_2[] = {0, kNpos, kNpos, 1, 2, 3, 4, kNpos, kNpos, 5, kNpos, 424 size_t expected_2[] = {0, kNpos, kNpos, 1, 2, 3, 4, kNpos, kNpos, 5, kNpos,
425 kNpos, 6, 7, 8, 9, kNpos, kNpos}; 425 kNpos, 6, 7, 8, 9, kNpos, kNpos};
426 EXPECT_EQ(offsets.size(), arraysize(expected_2)); 426 EXPECT_EQ(offsets.size(), arraysize(expected_2));
427 for (size_t i = 0; i < arraysize(expected_2); ++i) 427 for (size_t i = 0; i < arraysize(expected_2); ++i)
428 EXPECT_EQ(expected_2[i], offsets[i]); 428 EXPECT_EQ(expected_2[i], offsets[i]);
429 } 429 }
430 430
431 } // namespace 431 } // namespace
432 } // namespace net 432 } // namespace net
OLDNEW
« no previous file with comments | « net/base/escape.cc ('k') | net/base/keygen_handler_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698