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

Side by Side Diff: components/url_formatter/url_formatter_unittest.cc

Issue 2880983002: Added a Python script in tools/ to generate IDN test cases. (Closed)
Patch Set: Minor refactor. Created 3 years, 7 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
« no previous file with comments | « no previous file | tools/security/idn_test_case_generator.py » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/url_formatter/url_formatter.h" 5 #include "components/url_formatter/url_formatter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 20 matching lines...) Expand all
31 const char* const input; 31 const char* const input;
32 // The equivalent Unicode version of the domain. Even if we expect the domain 32 // The equivalent Unicode version of the domain. Even if we expect the domain
33 // to be displayed in Punycode, this should still contain the Unicode 33 // to be displayed in Punycode, this should still contain the Unicode
34 // equivalent (see |unicode_allowed|). 34 // equivalent (see |unicode_allowed|).
35 const wchar_t* unicode_output; 35 const wchar_t* unicode_output;
36 // Whether we expect the domain to be displayed decoded as a Unicode string 36 // Whether we expect the domain to be displayed decoded as a Unicode string
37 // (true) or in its Punycode form (false). 37 // (true) or in its Punycode form (false).
38 const bool unicode_allowed; 38 const bool unicode_allowed;
39 }; 39 };
40 40
41 // These cases can be generated with the script
42 // tools/security/idn_test_case_generator.py.
43 // See documentation there: you can either run it from the command line or call
44 // the make_case function directly from the Python shell (which may be easier
45 // for entering Unicode text).
46 //
47 // Q: Why not just do this conversion right here in the test, rather than having
48 // a Python script to generate it?
49 // A: Because then we would have to rely on complex logic (IDNA encoding) in the
50 // test itself; the same code we are trying to test. By using Python's IDN
51 // encoder to generate the test data, we independently verify that our
52 // algorithm is correct.
53
41 // TODO(jshin): Replace L"..." with "..." in UTF-8 when it's easier to read. 54 // TODO(jshin): Replace L"..." with "..." in UTF-8 when it's easier to read.
42 const IDNTestCase idn_cases[] = { 55 const IDNTestCase idn_cases[] = {
43 // No IDN 56 // No IDN
44 {"www.google.com", L"www.google.com", true}, 57 {"www.google.com", L"www.google.com", true},
45 {"www.google.com.", L"www.google.com.", true}, 58 {"www.google.com.", L"www.google.com.", true},
46 {".", L".", true}, 59 {".", L".", true},
47 {"", L"", true}, 60 {"", L"", true},
48 // IDN 61 // IDN
49 // Hanzi (Traditional Chinese) 62 // Hanzi (Traditional Chinese)
50 {"xn--1lq90ic7f1rc.cn", L"\x5317\x4eac\x5927\x5b78.cn", true}, 63 {"xn--1lq90ic7f1rc.cn", L"\x5317\x4eac\x5927\x5b78.cn", true},
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 1016 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
1004 0, 1, 2, 3, 4, 5, 6, 7 1017 0, 1, 2, 3, 4, 5, 6, 7
1005 }; 1018 };
1006 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll, 1019 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll,
1007 net::UnescapeRule::NORMAL, omit_all_offsets); 1020 net::UnescapeRule::NORMAL, omit_all_offsets);
1008 } 1021 }
1009 1022
1010 } // namespace 1023 } // namespace
1011 1024
1012 } // namespace url_formatter 1025 } // namespace url_formatter
OLDNEW
« no previous file with comments | « no previous file | tools/security/idn_test_case_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698