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

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

Issue 2595723003: url_formatter: Update comments for clarity. (Closed)
Patch Set: Rebase. Created 3 years, 10 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 | « components/url_formatter/url_formatter.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 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>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 19
20 namespace url_formatter { 20 namespace url_formatter {
21 21
22 namespace { 22 namespace {
23 23
24 using base::WideToUTF16; 24 using base::WideToUTF16;
25 using base::ASCIIToUTF16; 25 using base::ASCIIToUTF16;
26 26
27 const size_t kNpos = base::string16::npos; 27 const size_t kNpos = base::string16::npos;
28 28
29 struct IDNTestCase { 29 struct IDNTestCase {
30 // The IDNA/Punycode version of the domain (plain ASCII).
30 const char* const input; 31 const char* const input;
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
34 // equivalent (see |unicode_allowed|).
31 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
37 // (true) or in its Punycode form (false).
32 const bool unicode_allowed; 38 const bool unicode_allowed;
33 }; 39 };
34 40
41 // These cases can be generated with the following simple Python function:
42 // import codecs
43 // def make_case(case_name, unicode_domain, unicode_allowed=True):
44 // idna_input = codecs.encode(unicode_domain, 'idna').decode('ascii')
45 // unicode_output = 'L' + (ascii(unicode_domain)
46 // .replace("'", '"')
47 // .replace('\\u', '\\x'))
48 // print(' // %s' % case_name)
49 // print(' {"%s", %s, %s},' %
50 // (idna_input, unicode_output, repr(unicode_allowed).lower()))
Peter Kasting 2017/02/06 21:54:14 You said this didn't warrant a separate tool, but
51
35 const IDNTestCase idn_cases[] = { 52 const IDNTestCase idn_cases[] = {
36 // No IDN 53 // No IDN
37 {"www.google.com", L"www.google.com", true}, 54 {"www.google.com", L"www.google.com", true},
38 {"www.google.com.", L"www.google.com.", true}, 55 {"www.google.com.", L"www.google.com.", true},
39 {".", L".", true}, 56 {".", L".", true},
40 {"", L"", true}, 57 {"", L"", true},
41 // IDN 58 // IDN
42 // Hanzi (Traditional Chinese) 59 // Hanzi (Traditional Chinese)
43 {"xn--1lq90ic7f1rc.cn", L"\x5317\x4eac\x5927\x5b78.cn", true}, 60 {"xn--1lq90ic7f1rc.cn", L"\x5317\x4eac\x5927\x5b78.cn", true},
44 // Hanzi ('video' in Simplified Chinese 61 // Hanzi ('video' in Simplified Chinese
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 938 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
922 0, 1, 2, 3, 4, 5, 6, 7 939 0, 1, 2, 3, 4, 5, 6, 7
923 }; 940 };
924 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll, 941 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll,
925 net::UnescapeRule::NORMAL, omit_all_offsets); 942 net::UnescapeRule::NORMAL, omit_all_offsets);
926 } 943 }
927 944
928 } // namespace 945 } // namespace
929 946
930 } // namespace url_formatter 947 } // namespace url_formatter
OLDNEW
« no previous file with comments | « components/url_formatter/url_formatter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698