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

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

Issue 1133943002: Create net::FormatOriginForDisplay helper function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Crucial punctuation in comment. Created 5 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
OLDNEW
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 struct UrlTestData { 357 struct UrlTestData {
358 const char* const description; 358 const char* const description;
359 const char* const input; 359 const char* const input;
360 const char* const languages; 360 const char* const languages;
361 FormatUrlTypes format_types; 361 FormatUrlTypes format_types;
362 UnescapeRule::Type escape_rules; 362 UnescapeRule::Type escape_rules;
363 const wchar_t* output; // Use |wchar_t| to handle Unicode constants easily. 363 const wchar_t* output; // Use |wchar_t| to handle Unicode constants easily.
364 size_t prefix_len; 364 size_t prefix_len;
365 }; 365 };
366 366
367 struct OriginTestData {
368 const char* description;
369 const char* input;
370 const char* languages;
371 const bool omit_scheme;
372 const wchar_t* output;
373 };
374
367 // A helper for IDN*{Fast,Slow}. 375 // A helper for IDN*{Fast,Slow}.
368 // Append "::<language list>" to |expected| and |actual| to make it 376 // Append "::<language list>" to |expected| and |actual| to make it
369 // easy to tell which sub-case fails without debugging. 377 // easy to tell which sub-case fails without debugging.
370 void AppendLanguagesToOutputs(const char* languages, 378 void AppendLanguagesToOutputs(const char* languages,
371 base::string16* expected, 379 base::string16* expected,
372 base::string16* actual) { 380 base::string16* actual) {
373 base::string16 to_append = ASCIIToUTF16("::") + ASCIIToUTF16(languages); 381 base::string16 to_append = ASCIIToUTF16("::") + ASCIIToUTF16(languages);
374 expected->append(to_append); 382 expected->append(to_append);
375 actual->append(to_append); 383 actual->append(to_append);
376 } 384 }
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets); 1082 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets);
1075 1083
1076 const size_t omit_all_offsets[] = { 1084 const size_t omit_all_offsets[] = {
1077 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 1085 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
1078 0, 1, 2, 3, 4, 5, 6, 7 1086 0, 1, 2, 3, 4, 5, 6, 7
1079 }; 1087 };
1080 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, 1088 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll,
1081 UnescapeRule::NORMAL, omit_all_offsets); 1089 UnescapeRule::NORMAL, omit_all_offsets);
1082 } 1090 }
1083 1091
1092 TEST(NetUtilTest, FormatOriginForDisplay) {
1093 const OriginTestData tests[] = {
1094 {"Empty URL", "", "", false, L""},
1095 {"HTTP URL, no omit scheme",
1096 "http://www.google.com/",
1097 "",
1098 false,
1099 L"http://www.google.com"},
1100 {"HTTP URL, omit scheme",
1101 "http://www.google.com/",
1102 "",
1103 true,
1104 L"www.google.com"},
1105 {"HTTPS URL, no omit scheme",
1106 "https://www.google.com/",
1107 "",
1108 false,
1109 L"https://www.google.com"},
1110 {"HTTPS URL, omit scheme",
1111 "https://www.google.com/",
1112 "",
1113 true,
1114 L"www.google.com"},
1115 {"Standard HTTP port",
1116 "http://www.google.com:80/",
1117 "",
1118 false,
1119 L"http://www.google.com"},
1120 {"Standard HTTPS port",
1121 "https://www.google.com:443/",
1122 "",
1123 false,
1124 L"https://www.google.com"},
1125 {"Non-standard HTTP port",
1126 "http://www.google.com:9000/",
1127 "",
1128 false,
1129 L"http://www.google.com:9000"},
1130 {"Non-standard HTTPS port",
1131 "https://www.google.com:9000/",
1132 "",
1133 false,
1134 L"https://www.google.com:9000"},
1135 {"File URI, omit scheme",
1136 "file:///usr/example/file.html",
1137 "",
1138 true,
1139 L"/usr/example/file.html"},
1140 {"File URI, no omit scheme",
1141 "file:///usr/example/file.html",
1142 "",
1143 false,
1144 L"file:///usr/example/file.html"},
1145 {"File URI with hostname, omit scheme",
1146 "file://localhost/usr/example/file.html",
1147 "",
1148 true,
1149 L"/usr/example/file.html"},
1150 {"File URI with hostname, no omit scheme",
1151 "file://localhost/usr/example/file.html",
1152 "",
1153 false,
1154 L"file:///usr/example/file.html"},
1155 {"HTTP URL with path",
1156 "http://www.google.com/test.html",
1157 "",
1158 false,
1159 L"http://www.google.com"},
1160 {"HTTPS URL with path",
1161 "https://www.google.com/test.html",
1162 "",
1163 false,
1164 L"https://www.google.com"},
1165 {"Unusual secure scheme (wss)",
1166 "wss://www.google.com/",
1167 "",
1168 false,
1169 L"wss://www.google.com"},
1170 {"Unusual non-secure scheme (gopher)",
1171 "gopher://www.google.com/",
1172 "",
1173 false,
1174 L"gopher://www.google.com"},
1175 {"Unlisted scheme (chrome)",
1176 "chrome://version",
1177 "",
1178 false,
1179 L"chrome://version"},
1180 {"HTTP IP address",
1181 "http://173.194.65.103",
1182 "",
1183 false,
1184 L"http://173.194.65.103"},
1185 {"HTTPS IP address",
1186 "https://173.194.65.103",
1187 "",
1188 false,
1189 L"https://173.194.65.103"},
1190 {"HTTPS IP address, non-default port",
1191 "https://173.194.65.103:8443",
1192 "",
1193 false,
1194 L"https://173.194.65.103:8443"},
1195 {"HTTPS IP address, omit scheme",
1196 "https://173.194.65.103",
1197 "",
1198 true,
1199 L"173.194.65.103"},
1200 {"HTTP filesystem: URL with path",
1201 "filesystem:http://www.google.com/temporary/test.html",
1202 "",
1203 false,
1204 L"filesystem:http://www.google.com"},
1205 {"HTTP filesystem: URL with path, omit scheme",
1206 "filesystem:http://www.google.com/persistent/test.html",
1207 "",
1208 true,
1209 L"filesystem:www.google.com"},
1210 {"File filesystem: URL with path",
1211 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy",
1212 "",
1213 false,
1214 L"filesystem:file:///temporary/stuff/test.html"},
1215 {"File filesystem: URL with path, omit scheme",
1216 "filesystem:file://cyber.com/persistent/stuff/test.html?y=z#abc",
1217 "",
1218 true,
1219 L"filesystem:/persistent/stuff/test.html"},
1220 {"Invalid scheme 1",
1221 "twelve://www.cyber.org/wow.php",
1222 "",
1223 false,
1224 L"twelve://www.cyber.org/wow.php"},
1225 {"Invalid scheme 2",
1226 "://www.cyber.org/wow.php",
1227 "",
1228 false,
1229 L"://www.cyber.org/wow.php"},
1230 {"Invalid host 1",
1231 "https://www.cyber../wow.php",
1232 "",
1233 false,
1234 L"https://www.cyber.."},
1235 {"Invalid host 2",
1236 "https://www...cyber/wow.php",
1237 "",
1238 false,
1239 L"https://www...cyber"},
1240 {"Invalid port 1",
1241 "https://173.194.65.103:000",
1242 "",
1243 false,
1244 L"https://173.194.65.103"},
1245 {"Invalid port 2",
1246 "https://173.194.65.103:gruffle",
1247 "",
1248 false,
1249 L"https://173.194.65.103:gruffle"},
1250 {"Invalid port 3",
1251 "https://173.194.65.103:/hello.aspx",
1252 "",
1253 false,
1254 L"https://173.194.65.103"},
1255 };
1256 for (size_t i = 0; i < arraysize(tests); ++i) {
1257 base::string16 formatted = FormatOriginForDisplay(
1258 GURL(tests[i].input), tests[i].languages, tests[i].omit_scheme);
1259 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description;
1260 }
1261 }
1262
1084 } // namespace net 1263 } // namespace net
OLDNEW
« net/base/net_util_icu.cc ('K') | « net/base/net_util_icu.cc ('k') | url/gurl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698