| OLD | NEW |
| 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 |
| 35 // TODO(jshin): Replace L"..." with "..." in UTF-8 when it's easier to read. | 41 // TODO(jshin): Replace L"..." with "..." in UTF-8 when it's easier to read. |
| 36 const IDNTestCase idn_cases[] = { | 42 const IDNTestCase idn_cases[] = { |
| 37 // No IDN | 43 // No IDN |
| 38 {"www.google.com", L"www.google.com", true}, | 44 {"www.google.com", L"www.google.com", true}, |
| 39 {"www.google.com.", L"www.google.com.", true}, | 45 {"www.google.com.", L"www.google.com.", true}, |
| 40 {".", L".", true}, | 46 {".", L".", true}, |
| 41 {"", L"", true}, | 47 {"", L"", true}, |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, | 1003 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, |
| 998 0, 1, 2, 3, 4, 5, 6, 7 | 1004 0, 1, 2, 3, 4, 5, 6, 7 |
| 999 }; | 1005 }; |
| 1000 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll, | 1006 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll, |
| 1001 net::UnescapeRule::NORMAL, omit_all_offsets); | 1007 net::UnescapeRule::NORMAL, omit_all_offsets); |
| 1002 } | 1008 } |
| 1003 | 1009 |
| 1004 } // namespace | 1010 } // namespace |
| 1005 | 1011 |
| 1006 } // namespace url_formatter | 1012 } // namespace url_formatter |
| OLD | NEW |