OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 struct UrlTestData { | 356 struct UrlTestData { |
357 const char* description; | 357 const char* description; |
358 const char* input; | 358 const char* input; |
359 const char* languages; | 359 const char* languages; |
360 FormatUrlTypes format_types; | 360 FormatUrlTypes format_types; |
361 UnescapeRule::Type escape_rules; | 361 UnescapeRule::Type escape_rules; |
362 const wchar_t* output; // Use |wchar_t| to handle Unicode constants easily. | 362 const wchar_t* output; // Use |wchar_t| to handle Unicode constants easily. |
363 size_t prefix_len; | 363 size_t prefix_len; |
364 }; | 364 }; |
365 | 365 |
| 366 struct OriginTestData { |
| 367 const char* description; |
| 368 const char* input; |
| 369 const char* languages; |
| 370 const bool always_show_scheme; |
| 371 const wchar_t* output; |
| 372 }; |
| 373 |
366 // A helper for IDN*{Fast,Slow}. | 374 // A helper for IDN*{Fast,Slow}. |
367 // Append "::<language list>" to |expected| and |actual| to make it | 375 // Append "::<language list>" to |expected| and |actual| to make it |
368 // easy to tell which sub-case fails without debugging. | 376 // easy to tell which sub-case fails without debugging. |
369 void AppendLanguagesToOutputs(const char* languages, | 377 void AppendLanguagesToOutputs(const char* languages, |
370 base::string16* expected, | 378 base::string16* expected, |
371 base::string16* actual) { | 379 base::string16* actual) { |
372 base::string16 to_append = ASCIIToUTF16("::") + ASCIIToUTF16(languages); | 380 base::string16 to_append = ASCIIToUTF16("::") + ASCIIToUTF16(languages); |
373 expected->append(to_append); | 381 expected->append(to_append); |
374 actual->append(to_append); | 382 actual->append(to_append); |
375 } | 383 } |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets); | 1069 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets); |
1062 | 1070 |
1063 const size_t omit_all_offsets[] = { | 1071 const size_t omit_all_offsets[] = { |
1064 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, | 1072 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, |
1065 0, 1, 2, 3, 4, 5, 6, 7 | 1073 0, 1, 2, 3, 4, 5, 6, 7 |
1066 }; | 1074 }; |
1067 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, | 1075 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, |
1068 UnescapeRule::NORMAL, omit_all_offsets); | 1076 UnescapeRule::NORMAL, omit_all_offsets); |
1069 } | 1077 } |
1070 | 1078 |
| 1079 TEST(NetUtilTest, FormatOriginForDisplay) { |
| 1080 const OriginTestData tests[] = { |
| 1081 {"Empty URL", "", "", false, L""}, |
| 1082 {"HTTP URL, forcing bool", |
| 1083 "http://www.google.com/", "", true, L"http://www.google.com"}, |
| 1084 {"HTTP URL, no forcing bool", |
| 1085 "http://www.google.com/", "", false, L"http://www.google.com"}, |
| 1086 {"HTTPS URL, forcing bool", |
| 1087 "https://www.google.com/", "", true, L"https://www.google.com"}, |
| 1088 {"HTTPS URL, no forcing bool", |
| 1089 "https://www.google.com/", "", false, L"www.google.com"}, |
| 1090 {"Standard HTTP port", |
| 1091 "http://www.google.com:80/", "", false, L"http://www.google.com"}, |
| 1092 {"Standard HTTPS port", |
| 1093 "https://www.google.com:443/", "", false, L"www.google.com"}, |
| 1094 {"Non-standard HTTP port", |
| 1095 "http://www.google.com:9000/", "", false, L"http://www.google.com:9000"}, |
| 1096 {"Non-standard HTTPS port", |
| 1097 "https://www.google.com:9000/", "", false, L"www.google.com:9000"}, |
| 1098 {"File URI, forcing bool", |
| 1099 "file://usr/example/file.html", "", true, L"file://usr/example/file.html"}, |
| 1100 {"File URI, no forcing bool", |
| 1101 "file://usr/example/file.html", "", true, L"file://usr/example/file.html"}, |
| 1102 {"HTTP URL with path", |
| 1103 "http://www.google.com/test.html", "", false, L"http://www.google.com"}, |
| 1104 {"HTTPS URL with path", |
| 1105 "https://www.google.com/test.html", "", false, L"www.google.com"}, |
| 1106 {"Unusual secure scheme (wss)", |
| 1107 "wss://www.google.com/", "", false, L"www.google.com"}, |
| 1108 {"Unusual non-secure scheme (gopher)", |
| 1109 "gopher://www.google.com/", "", false, L"gopher://www.google.com"}, |
| 1110 {"Unlisted scheme (chrome)", |
| 1111 "chrome://version", "", false, L"chrome://version"}, |
| 1112 {"HTTP IP address", |
| 1113 "http://173.194.65.103", "", false, L"http://173.194.65.103"}, |
| 1114 {"HTTPS IP address, no forcing bool", |
| 1115 "https://173.194.65.103", "", false, L"173.194.65.103"}, |
| 1116 {"HTTPS IP address, forcing bool", |
| 1117 "https://173.194.65.103", "", true, L"https://173.194.65.103"}, |
| 1118 }; |
| 1119 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 1120 base::string16 formatted = FormatOriginForDisplay( |
| 1121 GURL(tests[i].input), tests[i].languages, tests[i].always_show_scheme); |
| 1122 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; |
| 1123 } |
| 1124 } |
| 1125 |
1071 } // namespace net | 1126 } // namespace net |
OLD | NEW |