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

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: Soothe cranky Windows compiler. 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
« net/base/net_util_icu.cc ('K') | « net/base/net_util_icu.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 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 {"HTTP URL with path",
1146 "http://www.google.com/test.html",
1147 "",
1148 false,
1149 L"http://www.google.com"},
1150 {"HTTPS URL with path",
1151 "https://www.google.com/test.html",
1152 "",
1153 false,
1154 L"https://www.google.com"},
1155 {"Unusual secure scheme (wss)",
1156 "wss://www.google.com/",
1157 "",
1158 false,
1159 L"wss://www.google.com"},
1160 {"Unusual non-secure scheme (gopher)",
1161 "gopher://www.google.com/",
1162 "",
1163 false,
1164 L"gopher://www.google.com"},
1165 {"Unlisted scheme (chrome)",
1166 "chrome://version",
1167 "",
1168 false,
1169 L"chrome://version"},
1170 {"HTTP IP address",
1171 "http://173.194.65.103",
1172 "",
1173 false,
1174 L"http://173.194.65.103"},
1175 {"HTTPS IP address",
1176 "https://173.194.65.103",
1177 "",
1178 false,
1179 L"https://173.194.65.103"},
1180 {"HTTPS IP address, non-default port",
1181 "https://173.194.65.103:8443",
1182 "",
1183 false,
1184 L"https://173.194.65.103:8443"},
1185 {"HTTPS IP address, omit scheme",
1186 "https://173.194.65.103",
1187 "",
1188 true,
1189 L"173.194.65.103"},
1190 {"HTTP filesystem: URL with path",
1191 "filesystem:http://www.google.com/test.html",
1192 "",
1193 false,
1194 L"filesystem:http://www.google.com"},
asanka 2015/05/11 23:39:44 Nit: filesystem URIs are of the form filesystem:<o
palmer 2015/05/12 22:20:53 Done.
1195 {"HTTP filesystem: URL with path, omit scheme",
1196 "filesystem:http://www.google.com/test.html",
1197 "",
1198 true,
1199 L"filesystem:www.google.com"},
1200 };
asanka 2015/05/11 23:39:44 Do you want to test how the code behaves with inva
palmer 2015/05/12 22:20:53 I added some, but I am not sure if it really helps
1201 for (size_t i = 0; i < arraysize(tests); ++i) {
1202 base::string16 formatted = FormatOriginForDisplay(
1203 GURL(tests[i].input), tests[i].languages, tests[i].omit_scheme);
1204 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description;
1205 }
1206 }
1207
1084 } // namespace net 1208 } // namespace net
OLDNEW
« net/base/net_util_icu.cc ('K') | « net/base/net_util_icu.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698