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

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

Issue 642403002: git cl format the first third of the net/base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 6 years, 1 month 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
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 using base::ASCIIToUTF16; 18 using base::ASCIIToUTF16;
19 using base::WideToUTF16; 19 using base::WideToUTF16;
20 20
21 namespace net { 21 namespace net {
22 22
23 namespace { 23 namespace {
24 24
25 static const size_t kNpos = base::string16::npos; 25 static const size_t kNpos = base::string16::npos;
26 26
27 const char* kLanguages[] = { 27 const char* kLanguages[] = {
28 "", "en", "zh-CN", "ja", "ko", 28 "", "en", "zh-CN", "ja", "ko", "he", "ar",
29 "he", "ar", "ru", "el", "fr", 29 "ru", "el", "fr", "de", "pt", "sv", "th",
30 "de", "pt", "sv", "th", "hi", 30 "hi", "de,en", "el,en", "zh-TW,en", "ko,ja", "he,ru,en", "zh,ru,en"};
31 "de,en", "el,en", "zh-TW,en", "ko,ja", "he,ru,en",
32 "zh,ru,en"
33 };
34 31
35 struct IDNTestCase { 32 struct IDNTestCase {
36 const char* input; 33 const char* input;
37 const wchar_t* unicode_output; 34 const wchar_t* unicode_output;
38 const bool unicode_allowed[arraysize(kLanguages)]; 35 const bool unicode_allowed[arraysize(kLanguages)];
39 }; 36 };
40 37
41 // TODO(jungshik) This is just a random sample of languages and is far 38 // TODO(jungshik) This is just a random sample of languages and is far
42 // from exhaustive. We may have to generate all the combinations 39 // from exhaustive. We may have to generate all the combinations
43 // of languages (powerset of a set of all the languages). 40 // of languages (powerset of a set of all the languages).
44 const IDNTestCase idn_cases[] = { 41 const IDNTestCase idn_cases[] = {
45 // No IDN 42 // No IDN
46 {"www.google.com", L"www.google.com", 43 {"www.google.com",
47 {true, true, true, true, true, 44 L"www.google.com",
48 true, true, true, true, true, 45 {true,
49 true, true, true, true, true, 46 true,
50 true, true, true, true, true, 47 true,
51 true}}, 48 true,
52 {"www.google.com.", L"www.google.com.", 49 true,
53 {true, true, true, true, true, 50 true,
54 true, true, true, true, true, 51 true,
55 true, true, true, true, true, 52 true,
56 true, true, true, true, true, 53 true,
57 true}}, 54 true,
58 {".", L".", 55 true,
59 {true, true, true, true, true, 56 true,
60 true, true, true, true, true, 57 true,
61 true, true, true, true, true, 58 true,
62 true, true, true, true, true, 59 true,
63 true}}, 60 true,
64 {"", L"", 61 true,
65 {true, true, true, true, true, 62 true,
66 true, true, true, true, true, 63 true,
67 true, true, true, true, true, 64 true,
68 true, true, true, true, true, 65 true}},
mmenke 2014/12/02 19:22:30 This is pretty hideous, though not sure it's worth
69 true}}, 66 {"www.google.com.",
70 // IDN 67 L"www.google.com.",
71 // Hanzi (Traditional Chinese) 68 {true,
72 {"xn--1lq90ic7f1rc.cn", L"\x5317\x4eac\x5927\x5b78.cn", 69 true,
73 {true, false, true, true, false, 70 true,
74 false, false, false, false, false, 71 true,
75 false, false, false, false, false, 72 true,
76 false, false, true, true, false, 73 true,
77 true}}, 74 true,
78 // Hanzi ('video' in Simplified Chinese : will pass only in zh-CN,zh) 75 true,
79 {"xn--cy2a840a.com", L"\x89c6\x9891.com", 76 true,
80 {true, false, true, false, false, 77 true,
81 false, false, false, false, false, 78 true,
82 false, false, false, false, false, 79 true,
83 false, false, false, false, false, 80 true,
84 true}}, 81 true,
85 // Hanzi + '123' 82 true,
86 {"www.xn--123-p18d.com", L"www.\x4e00" L"123.com", 83 true,
87 {true, false, true, true, false, 84 true,
88 false, false, false, false, false, 85 true,
89 false, false, false, false, false, 86 true,
90 false, false, true, true, false, 87 true,
91 true}}, 88 true}},
92 // Hanzi + Latin : U+56FD is simplified and is regarded 89 {".",
93 // as not supported in zh-TW. 90 L".",
94 {"www.xn--hello-9n1hm04c.com", L"www.hello\x4e2d\x56fd.com", 91 {true,
95 {false, false, true, true, false, 92 true,
96 false, false, false, false, false, 93 true,
97 false, false, false, false, false, 94 true,
98 false, false, false, true, false, 95 true,
99 true}}, 96 true,
100 // Kanji + Kana (Japanese) 97 true,
101 {"xn--l8jvb1ey91xtjb.jp", L"\x671d\x65e5\x3042\x3055\x3072.jp", 98 true,
102 {true, false, false, true, false, 99 true,
103 false, false, false, false, false, 100 true,
104 false, false, false, false, false, 101 true,
105 false, false, false, true, false, 102 true,
106 false}}, 103 true,
107 // Katakana including U+30FC 104 true,
108 {"xn--tckm4i2e.jp", L"\x30b3\x30de\x30fc\x30b9.jp", 105 true,
109 {true, false, false, true, false, 106 true,
110 false, false, false, false, false, 107 true,
111 false, false, false, false, false, 108 true,
112 false, false, false, true, false, 109 true,
113 }}, 110 true,
114 {"xn--3ck7a7g.jp", L"\u30ce\u30f3\u30bd.jp", 111 true}},
115 {true, false, false, true, false, 112 {"",
116 false, false, false, false, false, 113 L"",
117 false, false, false, false, false, 114 {true,
118 false, false, false, true, false, 115 true,
119 }}, 116 true,
120 // Katakana + Latin (Japanese) 117 true,
121 // TODO(jungshik): Change 'false' in the first element to 'true' 118 true,
122 // after upgrading to ICU 4.2.1 to use new uspoof_* APIs instead 119 true,
123 // of our IsIDNComponentInSingleScript(). 120 true,
124 {"xn--e-efusa1mzf.jp", L"e\x30b3\x30de\x30fc\x30b9.jp", 121 true,
125 {false, false, false, true, false, 122 true,
126 false, false, false, false, false, 123 true,
127 false, false, false, false, false, 124 true,
128 false, false, false, true, false, 125 true,
129 }}, 126 true,
130 {"xn--3bkxe.jp", L"\x30c8\x309a.jp", 127 true,
131 {false, false, false, true, false, 128 true,
132 false, false, false, false, false, 129 true,
133 false, false, false, false, false, 130 true,
134 false, false, false, true, false, 131 true,
135 }}, 132 true,
136 // Hangul (Korean) 133 true,
137 {"www.xn--or3b17p6jjc.kr", L"www.\xc804\xc790\xc815\xbd80.kr", 134 true}},
138 {true, false, false, false, true, 135 // IDN
139 false, false, false, false, false, 136 // Hanzi (Traditional Chinese)
140 false, false, false, false, false, 137 {"xn--1lq90ic7f1rc.cn",
141 false, false, false, true, false, 138 L"\x5317\x4eac\x5927\x5b78.cn",
142 false}}, 139 {true,
143 // b<u-umlaut>cher (German) 140 false,
144 {"xn--bcher-kva.de", L"b\x00fc" L"cher.de", 141 true,
145 {true, false, false, false, false, 142 true,
146 false, false, false, false, true, 143 false,
147 true, false, false, false, false, 144 false,
148 true, false, false, false, false, 145 false,
149 false}}, 146 false,
150 // a with diaeresis 147 false,
151 {"www.xn--frgbolaget-q5a.se", L"www.f\x00e4rgbolaget.se", 148 false,
152 {true, false, false, false, false, 149 false,
153 false, false, false, false, false, 150 false,
154 true, false, true, false, false, 151 false,
155 true, false, false, false, false, 152 false,
156 false}}, 153 false,
157 // c-cedilla (French) 154 false,
158 {"www.xn--alliancefranaise-npb.fr", L"www.alliancefran\x00e7" L"aise.fr", 155 false,
159 {true, false, false, false, false, 156 true,
160 false, false, false, false, true, 157 true,
161 false, true, false, false, false, 158 false,
162 false, false, false, false, false, 159 true}},
163 false}}, 160 // Hanzi ('video' in Simplified Chinese : will pass only in zh-CN,zh)
164 // caf'e with acute accent' (French) 161 {"xn--cy2a840a.com",
165 {"xn--caf-dma.fr", L"caf\x00e9.fr", 162 L"\x89c6\x9891.com",
166 {true, false, false, false, false, 163 {true,
167 false, false, false, false, true, 164 false,
168 false, true, true, false, false, 165 true,
169 false, false, false, false, false, 166 false,
170 false}}, 167 false,
171 // c-cedillla and a with tilde (Portuguese) 168 false,
172 {"xn--poema-9qae5a.com.br", L"p\x00e3oema\x00e7\x00e3.com.br", 169 false,
173 {true, false, false, false, false, 170 false,
174 false, false, false, false, false, 171 false,
175 false, true, false, false, false, 172 false,
176 false, false, false, false, false, 173 false,
177 false}}, 174 false,
178 // s with caron 175 false,
179 {"xn--achy-f6a.com", L"\x0161" L"achy.com", 176 false,
180 {true, false, false, false, false, 177 false,
181 false, false, false, false, false, 178 false,
182 false, false, false, false, false, 179 false,
183 false, false, false, false, false, 180 false,
184 false}}, 181 false,
185 // TODO(jungshik) : Add examples with Cyrillic letters 182 false,
186 // only used in some languages written in Cyrillic. 183 true}},
187 // Eutopia (Greek) 184 // Hanzi + '123'
188 {"xn--kxae4bafwg.gr", L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1.gr", 185 {"www.xn--123-p18d.com",
189 {true, false, false, false, false, 186 L"www.\x4e00"
190 false, false, false, true, false, 187 L"123.com",
191 false, false, false, false, false, 188 {true,
192 false, true, false, false, false, 189 false,
193 false}}, 190 true,
194 // Eutopia + 123 (Greek) 191 true,
195 {"xn---123-pldm0haj2bk.gr", 192 false,
196 L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1-123.gr", 193 false,
197 {true, false, false, false, false, 194 false,
198 false, false, false, true, false, 195 false,
199 false, false, false, false, false, 196 false,
200 false, true, false, false, false, 197 false,
201 false}}, 198 false,
202 // Cyrillic (Russian) 199 false,
203 {"xn--n1aeec9b.ru", L"\x0442\x043e\x0440\x0442\x044b.ru", 200 false,
204 {true, false, false, false, false, 201 false,
205 false, false, true, false, false, 202 false,
206 false, false, false, false, false, 203 false,
207 false, false, false, false, true, 204 false,
208 true}}, 205 true,
209 // Cyrillic + 123 (Russian) 206 true,
210 {"xn---123-45dmmc5f.ru", L"\x0442\x043e\x0440\x0442\x044b-123.ru", 207 false,
211 {true, false, false, false, false, 208 true}},
212 false, false, true, false, false, 209 // Hanzi + Latin : U+56FD is simplified and is regarded
213 false, false, false, false, false, 210 // as not supported in zh-TW.
214 false, false, false, false, true, 211 {"www.xn--hello-9n1hm04c.com",
215 true}}, 212 L"www.hello\x4e2d\x56fd.com",
216 // Arabic 213 {false,
217 {"xn--mgba1fmg.ar", L"\x0627\x0641\x0644\x0627\x0645.ar", 214 false,
218 {true, false, false, false, false, 215 true,
219 false, true, false, false, false, 216 true,
220 false, false, false, false, false, 217 false,
221 false, false, false, false, false, 218 false,
222 false}}, 219 false,
223 // Hebrew 220 false,
224 {"xn--4dbib.he", L"\x05d5\x05d0\x05d4.he", 221 false,
225 {true, false, false, false, false, 222 false,
226 true, false, false, false, false, 223 false,
227 false, false, false, false, false, 224 false,
228 false, false, false, false, true, 225 false,
229 false}}, 226 false,
230 // Thai 227 false,
231 {"xn--12c2cc4ag3b4ccu.th", 228 false,
232 L"\x0e2a\x0e32\x0e22\x0e01\x0e32\x0e23\x0e1a\x0e34\x0e19.th", 229 false,
233 {true, false, false, false, false, 230 false,
234 false, false, false, false, false, 231 true,
235 false, false, false, true, false, 232 false,
236 false, false, false, false, false, 233 true}},
237 false}}, 234 // Kanji + Kana (Japanese)
238 // Devangari (Hindi) 235 {"xn--l8jvb1ey91xtjb.jp",
239 {"www.xn--l1b6a9e1b7c.in", L"www.\x0905\x0915\x094b\x0932\x093e.in", 236 L"\x671d\x65e5\x3042\x3055\x3072.jp",
240 {true, false, false, false, false, 237 {true,
241 false, false, false, false, false, 238 false,
242 false, false, false, false, true, 239 false,
243 false, false, false, false, false, 240 true,
244 false}}, 241 false,
245 // Invalid IDN 242 false,
246 {"xn--hello?world.com", NULL, 243 false,
247 {false, false, false, false, false, 244 false,
248 false, false, false, false, false, 245 false,
249 false, false, false, false, false, 246 false,
250 false, false, false, false, false, 247 false,
251 false}}, 248 false,
252 // Unsafe IDNs 249 false,
253 // "payp<alpha>l.com" 250 false,
254 {"www.xn--paypl-g9d.com", L"payp\x03b1l.com", 251 false,
255 {false, false, false, false, false, 252 false,
256 false, false, false, false, false, 253 false,
257 false, false, false, false, false, 254 false,
258 false, false, false, false, false, 255 true,
259 false}}, 256 false,
260 // google.gr with Greek omicron and epsilon 257 false}},
261 {"xn--ggl-6xc1ca.gr", L"g\x03bf\x03bfgl\x03b5.gr", 258 // Katakana including U+30FC
262 {false, false, false, false, false, 259 {"xn--tckm4i2e.jp",
263 false, false, false, false, false, 260 L"\x30b3\x30de\x30fc\x30b9.jp",
264 false, false, false, false, false, 261 {
265 false, false, false, false, false, 262 true,
266 false}}, 263 false,
267 // google.ru with Cyrillic o 264 false,
268 {"xn--ggl-tdd6ba.ru", L"g\x043e\x043egl\x0435.ru", 265 true,
269 {false, false, false, false, false, 266 false,
270 false, false, false, false, false, 267 false,
271 false, false, false, false, false, 268 false,
272 false, false, false, false, false, 269 false,
273 false}}, 270 false,
274 // h<e with acute>llo<China in Han>.cn 271 false,
275 {"xn--hllo-bpa7979ih5m.cn", L"h\x00e9llo\x4e2d\x56fd.cn", 272 false,
276 {false, false, false, false, false, 273 false,
277 false, false, false, false, false, 274 false,
278 false, false, false, false, false, 275 false,
279 false, false, false, false, false, 276 false,
280 false}}, 277 false,
281 // <Greek rho><Cyrillic a><Cyrillic u>.ru 278 false,
282 {"xn--2xa6t2b.ru", L"\x03c1\x0430\x0443.ru", 279 false,
283 {false, false, false, false, false, 280 true,
284 false, false, false, false, false, 281 false,
285 false, false, false, false, false, 282 }},
286 false, false, false, false, false, 283 {"xn--3ck7a7g.jp",
287 false}}, 284 L"\u30ce\u30f3\u30bd.jp",
288 // One that's really long that will force a buffer realloc 285 {
289 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 286 true,
290 "aaaaaaa", 287 false,
291 L"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 288 false,
292 L"aaaaaaaa", 289 true,
293 {true, true, true, true, true, 290 false,
294 true, true, true, true, true, 291 false,
295 true, true, true, true, true, 292 false,
296 true, true, true, true, true, 293 false,
297 true}}, 294 false,
298 // Test cases for characters we blacklisted although allowed in IDN. 295 false,
299 // Embedded spaces will be turned to %20 in the display. 296 false,
300 // TODO(jungshik): We need to have more cases. This is a typical 297 false,
301 // data-driven trap. The following test cases need to be separated 298 false,
302 // and tested only for a couple of languages. 299 false,
303 {"xn--osd3820f24c.kr", L"\xac00\xb098\x115f.kr", 300 false,
304 {false, false, false, false, false, 301 false,
305 false, false, false, false, false, 302 false,
306 false, false, false, false, false, 303 false,
307 false, false, false, false, false, 304 true,
308 false}}, 305 false,
309 {"www.xn--google-ho0coa.com", L"www.\x2039google\x203a.com", 306 }},
310 {false, false, false, false, false, 307 // Katakana + Latin (Japanese)
311 false, false, false, false, false, 308 // TODO(jungshik): Change 'false' in the first element to 'true'
312 false, false, false, false, false, 309 // after upgrading to ICU 4.2.1 to use new uspoof_* APIs instead
313 false, false, false, false, false, 310 // of our IsIDNComponentInSingleScript().
314 }}, 311 {"xn--e-efusa1mzf.jp",
315 {"google.xn--comabc-k8d", L"google.com\x0338" L"abc", 312 L"e\x30b3\x30de\x30fc\x30b9.jp",
316 {false, false, false, false, false, 313 {
317 false, false, false, false, false, 314 false,
318 false, false, false, false, false, 315 false,
319 false, false, false, false, false, 316 false,
320 }}, 317 true,
321 {"google.xn--com-oh4ba.evil.jp", L"google.com\x309a\x309a.evil.jp", 318 false,
322 {false, false, false, false, false, 319 false,
323 false, false, false, false, false, 320 false,
324 false, false, false, false, false, 321 false,
325 false, false, false, false, false, 322 false,
326 }}, 323 false,
327 {"google.xn--comevil-v04f.jp", L"google.com\x30ce" L"evil.jp", 324 false,
328 {false, false, false, false, false, 325 false,
329 false, false, false, false, false, 326 false,
330 false, false, false, false, false, 327 false,
331 false, false, false, false, false, 328 false,
332 }}, 329 false,
330 false,
331 false,
332 true,
333 false,
334 }},
335 {"xn--3bkxe.jp",
336 L"\x30c8\x309a.jp",
337 {
338 false,
339 false,
340 false,
341 true,
342 false,
343 false,
344 false,
345 false,
346 false,
347 false,
348 false,
349 false,
350 false,
351 false,
352 false,
353 false,
354 false,
355 false,
356 true,
357 false,
358 }},
359 // Hangul (Korean)
360 {"www.xn--or3b17p6jjc.kr",
361 L"www.\xc804\xc790\xc815\xbd80.kr",
362 {true,
363 false,
364 false,
365 false,
366 true,
367 false,
368 false,
369 false,
370 false,
371 false,
372 false,
373 false,
374 false,
375 false,
376 false,
377 false,
378 false,
379 false,
380 true,
381 false,
382 false}},
383 // b<u-umlaut>cher (German)
384 {"xn--bcher-kva.de",
385 L"b\x00fc"
386 L"cher.de",
387 {true,
388 false,
389 false,
390 false,
391 false,
392 false,
393 false,
394 false,
395 false,
396 true,
397 true,
398 false,
399 false,
400 false,
401 false,
402 true,
403 false,
404 false,
405 false,
406 false,
407 false}},
408 // a with diaeresis
409 {"www.xn--frgbolaget-q5a.se",
410 L"www.f\x00e4rgbolaget.se",
411 {true,
412 false,
413 false,
414 false,
415 false,
416 false,
417 false,
418 false,
419 false,
420 false,
421 true,
422 false,
423 true,
424 false,
425 false,
426 true,
427 false,
428 false,
429 false,
430 false,
431 false}},
432 // c-cedilla (French)
433 {"www.xn--alliancefranaise-npb.fr",
434 L"www.alliancefran\x00e7"
435 L"aise.fr",
436 {true,
437 false,
438 false,
439 false,
440 false,
441 false,
442 false,
443 false,
444 false,
445 true,
446 false,
447 true,
448 false,
449 false,
450 false,
451 false,
452 false,
453 false,
454 false,
455 false,
456 false}},
457 // caf'e with acute accent' (French)
458 {"xn--caf-dma.fr",
459 L"caf\x00e9.fr",
460 {true,
461 false,
462 false,
463 false,
464 false,
465 false,
466 false,
467 false,
468 false,
469 true,
470 false,
471 true,
472 true,
473 false,
474 false,
475 false,
476 false,
477 false,
478 false,
479 false,
480 false}},
481 // c-cedillla and a with tilde (Portuguese)
482 {"xn--poema-9qae5a.com.br",
483 L"p\x00e3oema\x00e7\x00e3.com.br",
484 {true,
485 false,
486 false,
487 false,
488 false,
489 false,
490 false,
491 false,
492 false,
493 false,
494 false,
495 true,
496 false,
497 false,
498 false,
499 false,
500 false,
501 false,
502 false,
503 false,
504 false}},
505 // s with caron
506 {"xn--achy-f6a.com",
507 L"\x0161"
508 L"achy.com",
509 {true,
510 false,
511 false,
512 false,
513 false,
514 false,
515 false,
516 false,
517 false,
518 false,
519 false,
520 false,
521 false,
522 false,
523 false,
524 false,
525 false,
526 false,
527 false,
528 false,
529 false}},
530 // TODO(jungshik) : Add examples with Cyrillic letters
531 // only used in some languages written in Cyrillic.
532 // Eutopia (Greek)
533 {"xn--kxae4bafwg.gr",
534 L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1.gr",
535 {true,
536 false,
537 false,
538 false,
539 false,
540 false,
541 false,
542 false,
543 true,
544 false,
545 false,
546 false,
547 false,
548 false,
549 false,
550 false,
551 true,
552 false,
553 false,
554 false,
555 false}},
556 // Eutopia + 123 (Greek)
557 {"xn---123-pldm0haj2bk.gr",
558 L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1-123.gr",
559 {true,
560 false,
561 false,
562 false,
563 false,
564 false,
565 false,
566 false,
567 true,
568 false,
569 false,
570 false,
571 false,
572 false,
573 false,
574 false,
575 true,
576 false,
577 false,
578 false,
579 false}},
580 // Cyrillic (Russian)
581 {"xn--n1aeec9b.ru",
582 L"\x0442\x043e\x0440\x0442\x044b.ru",
583 {true,
584 false,
585 false,
586 false,
587 false,
588 false,
589 false,
590 true,
591 false,
592 false,
593 false,
594 false,
595 false,
596 false,
597 false,
598 false,
599 false,
600 false,
601 false,
602 true,
603 true}},
604 // Cyrillic + 123 (Russian)
605 {"xn---123-45dmmc5f.ru",
606 L"\x0442\x043e\x0440\x0442\x044b-123.ru",
607 {true,
608 false,
609 false,
610 false,
611 false,
612 false,
613 false,
614 true,
615 false,
616 false,
617 false,
618 false,
619 false,
620 false,
621 false,
622 false,
623 false,
624 false,
625 false,
626 true,
627 true}},
628 // Arabic
629 {"xn--mgba1fmg.ar",
630 L"\x0627\x0641\x0644\x0627\x0645.ar",
631 {true,
632 false,
633 false,
634 false,
635 false,
636 false,
637 true,
638 false,
639 false,
640 false,
641 false,
642 false,
643 false,
644 false,
645 false,
646 false,
647 false,
648 false,
649 false,
650 false,
651 false}},
652 // Hebrew
653 {"xn--4dbib.he",
654 L"\x05d5\x05d0\x05d4.he",
655 {true,
656 false,
657 false,
658 false,
659 false,
660 true,
661 false,
662 false,
663 false,
664 false,
665 false,
666 false,
667 false,
668 false,
669 false,
670 false,
671 false,
672 false,
673 false,
674 true,
675 false}},
676 // Thai
677 {"xn--12c2cc4ag3b4ccu.th",
678 L"\x0e2a\x0e32\x0e22\x0e01\x0e32\x0e23\x0e1a\x0e34\x0e19.th",
679 {true,
680 false,
681 false,
682 false,
683 false,
684 false,
685 false,
686 false,
687 false,
688 false,
689 false,
690 false,
691 false,
692 true,
693 false,
694 false,
695 false,
696 false,
697 false,
698 false,
699 false}},
700 // Devangari (Hindi)
701 {"www.xn--l1b6a9e1b7c.in",
702 L"www.\x0905\x0915\x094b\x0932\x093e.in",
703 {true,
704 false,
705 false,
706 false,
707 false,
708 false,
709 false,
710 false,
711 false,
712 false,
713 false,
714 false,
715 false,
716 false,
717 true,
718 false,
719 false,
720 false,
721 false,
722 false,
723 false}},
724 // Invalid IDN
725 {"xn--hello?world.com",
726 NULL,
727 {false,
728 false,
729 false,
730 false,
731 false,
732 false,
733 false,
734 false,
735 false,
736 false,
737 false,
738 false,
739 false,
740 false,
741 false,
742 false,
743 false,
744 false,
745 false,
746 false,
747 false}},
748 // Unsafe IDNs
749 // "payp<alpha>l.com"
750 {"www.xn--paypl-g9d.com",
751 L"payp\x03b1l.com",
752 {false,
753 false,
754 false,
755 false,
756 false,
757 false,
758 false,
759 false,
760 false,
761 false,
762 false,
763 false,
764 false,
765 false,
766 false,
767 false,
768 false,
769 false,
770 false,
771 false,
772 false}},
773 // google.gr with Greek omicron and epsilon
774 {"xn--ggl-6xc1ca.gr",
775 L"g\x03bf\x03bfgl\x03b5.gr",
776 {false,
777 false,
778 false,
779 false,
780 false,
781 false,
782 false,
783 false,
784 false,
785 false,
786 false,
787 false,
788 false,
789 false,
790 false,
791 false,
792 false,
793 false,
794 false,
795 false,
796 false}},
797 // google.ru with Cyrillic o
798 {"xn--ggl-tdd6ba.ru",
799 L"g\x043e\x043egl\x0435.ru",
800 {false,
801 false,
802 false,
803 false,
804 false,
805 false,
806 false,
807 false,
808 false,
809 false,
810 false,
811 false,
812 false,
813 false,
814 false,
815 false,
816 false,
817 false,
818 false,
819 false,
820 false}},
821 // h<e with acute>llo<China in Han>.cn
822 {"xn--hllo-bpa7979ih5m.cn",
823 L"h\x00e9llo\x4e2d\x56fd.cn",
824 {false,
825 false,
826 false,
827 false,
828 false,
829 false,
830 false,
831 false,
832 false,
833 false,
834 false,
835 false,
836 false,
837 false,
838 false,
839 false,
840 false,
841 false,
842 false,
843 false,
844 false}},
845 // <Greek rho><Cyrillic a><Cyrillic u>.ru
846 {"xn--2xa6t2b.ru",
847 L"\x03c1\x0430\x0443.ru",
848 {false,
849 false,
850 false,
851 false,
852 false,
853 false,
854 false,
855 false,
856 false,
857 false,
858 false,
859 false,
860 false,
861 false,
862 false,
863 false,
864 false,
865 false,
866 false,
867 false,
868 false}},
869 // One that's really long that will force a buffer realloc
870 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
871 "aaaaaaa",
872 L"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
873 L"aaaaaaaa",
874 {true,
875 true,
876 true,
877 true,
878 true,
879 true,
880 true,
881 true,
882 true,
883 true,
884 true,
885 true,
886 true,
887 true,
888 true,
889 true,
890 true,
891 true,
892 true,
893 true,
894 true}},
895 // Test cases for characters we blacklisted although allowed in IDN.
896 // Embedded spaces will be turned to %20 in the display.
897 // TODO(jungshik): We need to have more cases. This is a typical
898 // data-driven trap. The following test cases need to be separated
899 // and tested only for a couple of languages.
900 {"xn--osd3820f24c.kr",
901 L"\xac00\xb098\x115f.kr",
902 {false,
903 false,
904 false,
905 false,
906 false,
907 false,
908 false,
909 false,
910 false,
911 false,
912 false,
913 false,
914 false,
915 false,
916 false,
917 false,
918 false,
919 false,
920 false,
921 false,
922 false}},
923 {"www.xn--google-ho0coa.com",
924 L"www.\x2039google\x203a.com",
925 {
926 false,
927 false,
928 false,
929 false,
930 false,
931 false,
932 false,
933 false,
934 false,
935 false,
936 false,
937 false,
938 false,
939 false,
940 false,
941 false,
942 false,
943 false,
944 false,
945 false,
946 }},
947 {"google.xn--comabc-k8d",
948 L"google.com\x0338"
949 L"abc",
950 {
951 false,
952 false,
953 false,
954 false,
955 false,
956 false,
957 false,
958 false,
959 false,
960 false,
961 false,
962 false,
963 false,
964 false,
965 false,
966 false,
967 false,
968 false,
969 false,
970 false,
971 }},
972 {"google.xn--com-oh4ba.evil.jp",
973 L"google.com\x309a\x309a.evil.jp",
974 {
975 false,
976 false,
977 false,
978 false,
979 false,
980 false,
981 false,
982 false,
983 false,
984 false,
985 false,
986 false,
987 false,
988 false,
989 false,
990 false,
991 false,
992 false,
993 false,
994 false,
995 }},
996 {"google.xn--comevil-v04f.jp",
997 L"google.com\x30ce"
998 L"evil.jp",
999 {
1000 false,
1001 false,
1002 false,
1003 false,
1004 false,
1005 false,
1006 false,
1007 false,
1008 false,
1009 false,
1010 false,
1011 false,
1012 false,
1013 false,
1014 false,
1015 false,
1016 false,
1017 false,
1018 false,
1019 false,
1020 }},
333 #if 0 1021 #if 0
334 // These two cases are special. We need a separate test. 1022 // These two cases are special. We need a separate test.
335 // U+3000 and U+3002 are normalized to ASCII space and dot. 1023 // U+3000 and U+3002 are normalized to ASCII space and dot.
336 {"xn-- -kq6ay5z.cn", L"\x4e2d\x56fd\x3000.cn", 1024 {"xn-- -kq6ay5z.cn", L"\x4e2d\x56fd\x3000.cn",
337 {false, false, true, false, false, 1025 {false, false, true, false, false,
338 false, false, false, false, false, 1026 false, false, false, false, false,
339 false, false, false, false, false, 1027 false, false, false, false, false,
340 false, false, true, false, false, 1028 false, false, true, false, false,
341 true}}, 1029 true}},
342 {"xn--fiqs8s.cn", L"\x4e2d\x56fd\x3002" L"cn", 1030 {"xn--fiqs8s.cn", L"\x4e2d\x56fd\x3002" L"cn",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 actual->append(to_append); 1062 actual->append(to_append);
375 } 1063 }
376 1064
377 // A pair of helpers for the FormatUrlWithOffsets() test. 1065 // A pair of helpers for the FormatUrlWithOffsets() test.
378 void VerboseExpect(size_t expected, 1066 void VerboseExpect(size_t expected,
379 size_t actual, 1067 size_t actual,
380 const std::string& original_url, 1068 const std::string& original_url,
381 size_t position, 1069 size_t position,
382 const base::string16& formatted_url) { 1070 const base::string16& formatted_url) {
383 EXPECT_EQ(expected, actual) << "Original URL: " << original_url 1071 EXPECT_EQ(expected, actual) << "Original URL: " << original_url
384 << " (at char " << position << ")\nFormatted URL: " << formatted_url; 1072 << " (at char " << position
1073 << ")\nFormatted URL: " << formatted_url;
385 } 1074 }
386 1075
387 void CheckAdjustedOffsets(const std::string& url_string, 1076 void CheckAdjustedOffsets(const std::string& url_string,
388 const std::string& languages, 1077 const std::string& languages,
389 FormatUrlTypes format_types, 1078 FormatUrlTypes format_types,
390 UnescapeRule::Type unescape_rules, 1079 UnescapeRule::Type unescape_rules,
391 const size_t* output_offsets) { 1080 const size_t* output_offsets) {
392 GURL url(url_string); 1081 GURL url(url_string);
393 size_t url_length = url_string.length(); 1082 size_t url_length = url_string.length();
394 std::vector<size_t> offsets; 1083 std::vector<size_t> offsets;
395 for (size_t i = 0; i <= url_length + 1; ++i) 1084 for (size_t i = 0; i <= url_length + 1; ++i)
396 offsets.push_back(i); 1085 offsets.push_back(i);
397 offsets.push_back(500000); // Something larger than any input length. 1086 offsets.push_back(500000); // Something larger than any input length.
398 offsets.push_back(std::string::npos); 1087 offsets.push_back(std::string::npos);
399 base::string16 formatted_url = FormatUrlWithOffsets(url, languages, 1088 base::string16 formatted_url = FormatUrlWithOffsets(
400 format_types, unescape_rules, NULL, NULL, &offsets); 1089 url, languages, format_types, unescape_rules, NULL, NULL, &offsets);
401 for (size_t i = 0; i < url_length; ++i) 1090 for (size_t i = 0; i < url_length; ++i)
402 VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url); 1091 VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url);
403 VerboseExpect(formatted_url.length(), offsets[url_length], url_string, 1092 VerboseExpect(formatted_url.length(), offsets[url_length], url_string,
404 url_length, formatted_url); 1093 url_length, formatted_url);
405 VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string, 1094 VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string,
406 500000, formatted_url); 1095 500000, formatted_url);
407 VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string, 1096 VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string,
408 std::string::npos, formatted_url); 1097 std::string::npos, formatted_url);
409 } 1098 }
410 1099
411 } // anonymous namespace 1100 } // anonymous namespace
412 1101
413 TEST(NetUtilTest, IDNToUnicodeFast) { 1102 TEST(NetUtilTest, IDNToUnicodeFast) {
414 for (size_t i = 0; i < arraysize(idn_cases); i++) { 1103 for (size_t i = 0; i < arraysize(idn_cases); i++) {
415 for (size_t j = 0; j < arraysize(kLanguages); j++) { 1104 for (size_t j = 0; j < arraysize(kLanguages); j++) {
416 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow 1105 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow
417 if (j == 3 || j == 17 || j == 18) 1106 if (j == 3 || j == 17 || j == 18)
418 continue; 1107 continue;
419 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); 1108 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j]));
420 base::string16 expected(idn_cases[i].unicode_allowed[j] ? 1109 base::string16 expected(idn_cases[i].unicode_allowed[j]
421 WideToUTF16(idn_cases[i].unicode_output) : 1110 ? WideToUTF16(idn_cases[i].unicode_output)
422 ASCIIToUTF16(idn_cases[i].input)); 1111 : ASCIIToUTF16(idn_cases[i].input));
423 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); 1112 AppendLanguagesToOutputs(kLanguages[j], &expected, &output);
424 EXPECT_EQ(expected, output); 1113 EXPECT_EQ(expected, output);
425 } 1114 }
426 } 1115 }
427 } 1116 }
428 1117
429 TEST(NetUtilTest, IDNToUnicodeSlow) { 1118 TEST(NetUtilTest, IDNToUnicodeSlow) {
430 for (size_t i = 0; i < arraysize(idn_cases); i++) { 1119 for (size_t i = 0; i < arraysize(idn_cases); i++) {
431 for (size_t j = 0; j < arraysize(kLanguages); j++) { 1120 for (size_t j = 0; j < arraysize(kLanguages); j++) {
432 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast 1121 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast
433 if (!(j == 3 || j == 17 || j == 18)) 1122 if (!(j == 3 || j == 17 || j == 18))
434 continue; 1123 continue;
435 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); 1124 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j]));
436 base::string16 expected(idn_cases[i].unicode_allowed[j] ? 1125 base::string16 expected(idn_cases[i].unicode_allowed[j]
437 WideToUTF16(idn_cases[i].unicode_output) : 1126 ? WideToUTF16(idn_cases[i].unicode_output)
438 ASCIIToUTF16(idn_cases[i].input)); 1127 : ASCIIToUTF16(idn_cases[i].input));
439 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); 1128 AppendLanguagesToOutputs(kLanguages[j], &expected, &output);
440 EXPECT_EQ(expected, output); 1129 EXPECT_EQ(expected, output);
441 } 1130 }
442 } 1131 }
443 } 1132 }
444 1133
445 TEST(NetUtilTest, StripWWW) { 1134 TEST(NetUtilTest, StripWWW) {
446 EXPECT_EQ(base::string16(), StripWWW(base::string16())); 1135 EXPECT_EQ(base::string16(), StripWWW(base::string16()));
447 EXPECT_EQ(base::string16(), StripWWW(ASCIIToUTF16("www."))); 1136 EXPECT_EQ(base::string16(), StripWWW(ASCIIToUTF16("www.")));
448 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah"))); 1137 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah")));
(...skipping 10 matching lines...) Expand all
459 bool is_dir; 1148 bool is_dir;
460 int64 filesize; 1149 int64 filesize;
461 base::Time time; 1150 base::Time time;
462 const char* expected; 1151 const char* expected;
463 }; 1152 };
464 1153
465 } // namespace 1154 } // namespace
466 1155
467 TEST(NetUtilTest, GetDirectoryListingEntry) { 1156 TEST(NetUtilTest, GetDirectoryListingEntry) {
468 const GetDirectoryListingEntryCase test_cases[] = { 1157 const GetDirectoryListingEntryCase test_cases[] = {
469 {L"Foo", 1158 {L"Foo",
470 "", 1159 "",
471 false, 1160 false,
472 10000, 1161 10000,
473 base::Time(), 1162 base::Time(),
474 "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"}, 1163 "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"},
475 {L"quo\"tes", 1164 {L"quo\"tes",
476 "", 1165 "",
477 false, 1166 false,
478 10000, 1167 10000,
479 base::Time(), 1168 base::Time(),
480 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>" 1169 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 "
481 "\n"}, 1170 "kB\",\"\");</script>"
482 {L"quo\"tes", 1171 "\n"},
483 "quo\"tes", 1172 {L"quo\"tes",
484 false, 1173 "quo\"tes",
485 10000, 1174 false,
486 base::Time(), 1175 10000,
487 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>" 1176 base::Time(),
488 "\n"}, 1177 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 "
489 // U+D55C0 U+AE00. raw_bytes is empty (either a local file with 1178 "kB\",\"\");</script>"
490 // UTF-8/UTF-16 encoding or a remote file on an ftp server using UTF-8 1179 "\n"},
491 {L"\xD55C\xAE00.txt", 1180 // U+D55C0 U+AE00. raw_bytes is empty (either a local file with
492 "", 1181 // UTF-8/UTF-16 encoding or a remote file on an ftp server using UTF-8
493 false, 1182 {L"\xD55C\xAE00.txt",
494 10000, 1183 "",
495 base::Time(), 1184 false,
496 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\"," 1185 10000,
497 "\"%ED%95%9C%EA%B8%80.txt\",0,\"9.8 kB\",\"\");</script>\n"}, 1186 base::Time(),
498 // U+D55C0 U+AE00. raw_bytes is the corresponding EUC-KR sequence: 1187 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\","
499 // a local or remote file in EUC-KR. 1188 "\"%ED%95%9C%EA%B8%80.txt\",0,\"9.8 kB\",\"\");</script>\n"},
500 {L"\xD55C\xAE00.txt", 1189 // U+D55C0 U+AE00. raw_bytes is the corresponding EUC-KR sequence:
501 "\xC7\xD1\xB1\xDB.txt", 1190 // a local or remote file in EUC-KR.
502 false, 1191 {L"\xD55C\xAE00.txt",
503 10000, 1192 "\xC7\xD1\xB1\xDB.txt",
504 base::Time(), 1193 false,
505 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\",\"%C7%D1%B1%DB.txt\"" 1194 10000,
506 ",0,\"9.8 kB\",\"\");</script>\n"}, 1195 base::Time(),
1196 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\",\"%C7%D1%B1%DB.txt\""
1197 ",0,\"9.8 kB\",\"\");</script>\n"},
507 }; 1198 };
508 1199
509 for (size_t i = 0; i < arraysize(test_cases); ++i) { 1200 for (size_t i = 0; i < arraysize(test_cases); ++i) {
510 const std::string results = GetDirectoryListingEntry( 1201 const std::string results = GetDirectoryListingEntry(
511 WideToUTF16(test_cases[i].name), 1202 WideToUTF16(test_cases[i].name), test_cases[i].raw_bytes,
512 test_cases[i].raw_bytes, 1203 test_cases[i].is_dir, test_cases[i].filesize, test_cases[i].time);
513 test_cases[i].is_dir,
514 test_cases[i].filesize,
515 test_cases[i].time);
516 EXPECT_EQ(test_cases[i].expected, results); 1204 EXPECT_EQ(test_cases[i].expected, results);
517 } 1205 }
518 } 1206 }
519 1207
520 #endif 1208 #endif
521 1209
522 TEST(NetUtilTest, FormatUrl) { 1210 TEST(NetUtilTest, FormatUrl) {
523 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword; 1211 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword;
524 const UrlTestData tests[] = { 1212 const UrlTestData tests[] = {
525 {"Empty URL", "", "", default_format_type, UnescapeRule::NORMAL, L"", 0}, 1213 {"Empty URL", "", "", default_format_type, UnescapeRule::NORMAL, L"", 0},
526 1214
527 {"Simple URL", 1215 {"Simple URL",
528 "http://www.google.com/", "", default_format_type, UnescapeRule::NORMAL, 1216 "http://www.google.com/",
529 L"http://www.google.com/", 7}, 1217 "",
530 1218 default_format_type,
531 {"With a port number and a reference", 1219 UnescapeRule::NORMAL,
532 "http://www.google.com:8080/#\xE3\x82\xB0", "", default_format_type, 1220 L"http://www.google.com/",
533 UnescapeRule::NORMAL, 1221 7},
534 L"http://www.google.com:8080/#\x30B0", 7}, 1222
535 1223 {"With a port number and a reference",
536 // -------- IDN tests -------- 1224 "http://www.google.com:8080/#\xE3\x82\xB0",
537 {"Japanese IDN with ja", 1225 "",
538 "http://xn--l8jvb1ey91xtjb.jp", "ja", default_format_type, 1226 default_format_type,
539 UnescapeRule::NORMAL, L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7}, 1227 UnescapeRule::NORMAL,
540 1228 L"http://www.google.com:8080/#\x30B0",
541 {"Japanese IDN with en", 1229 7},
542 "http://xn--l8jvb1ey91xtjb.jp", "en", default_format_type, 1230
543 UnescapeRule::NORMAL, L"http://xn--l8jvb1ey91xtjb.jp/", 7}, 1231 // -------- IDN tests --------
544 1232 {"Japanese IDN with ja",
545 {"Japanese IDN without any languages", 1233 "http://xn--l8jvb1ey91xtjb.jp",
546 "http://xn--l8jvb1ey91xtjb.jp", "", default_format_type, 1234 "ja",
547 UnescapeRule::NORMAL, 1235 default_format_type,
548 // Single script is safe for empty languages. 1236 UnescapeRule::NORMAL,
549 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7}, 1237 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/",
550 1238 7},
551 {"mailto: with Japanese IDN", 1239
552 "mailto:foo@xn--l8jvb1ey91xtjb.jp", "ja", default_format_type, 1240 {"Japanese IDN with en",
553 UnescapeRule::NORMAL, 1241 "http://xn--l8jvb1ey91xtjb.jp",
554 // GURL doesn't assume an email address's domain part as a host name. 1242 "en",
555 L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7}, 1243 default_format_type,
556 1244 UnescapeRule::NORMAL,
557 {"file: with Japanese IDN", 1245 L"http://xn--l8jvb1ey91xtjb.jp/",
558 "file://xn--l8jvb1ey91xtjb.jp/config.sys", "ja", default_format_type, 1246 7},
559 UnescapeRule::NORMAL, 1247
560 L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7}, 1248 {"Japanese IDN without any languages",
561 1249 "http://xn--l8jvb1ey91xtjb.jp",
562 {"ftp: with Japanese IDN", 1250 "",
563 "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", "ja", default_format_type, 1251 default_format_type,
564 UnescapeRule::NORMAL, 1252 UnescapeRule::NORMAL,
565 L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6}, 1253 // Single script is safe for empty languages.
566 1254 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/",
567 // -------- omit_username_password flag tests -------- 1255 7},
568 {"With username and password, omit_username_password=false", 1256
569 "http://user:passwd@example.com/foo", "", 1257 {"mailto: with Japanese IDN",
570 kFormatUrlOmitNothing, UnescapeRule::NORMAL, 1258 "mailto:foo@xn--l8jvb1ey91xtjb.jp",
571 L"http://user:passwd@example.com/foo", 19}, 1259 "ja",
572 1260 default_format_type,
573 {"With username and password, omit_username_password=true", 1261 UnescapeRule::NORMAL,
574 "http://user:passwd@example.com/foo", "", default_format_type, 1262 // GURL doesn't assume an email address's domain part as a host name.
575 UnescapeRule::NORMAL, L"http://example.com/foo", 7}, 1263 L"mailto:foo@xn--l8jvb1ey91xtjb.jp",
576 1264 7},
577 {"With username and no password", 1265
578 "http://user@example.com/foo", "", default_format_type, 1266 {"file: with Japanese IDN",
579 UnescapeRule::NORMAL, L"http://example.com/foo", 7}, 1267 "file://xn--l8jvb1ey91xtjb.jp/config.sys",
580 1268 "ja",
581 {"Just '@' without username and password", 1269 default_format_type,
582 "http://@example.com/foo", "", default_format_type, UnescapeRule::NORMAL, 1270 UnescapeRule::NORMAL,
583 L"http://example.com/foo", 7}, 1271 L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys",
584 1272 7},
585 // GURL doesn't think local-part of an email address is username for URL. 1273
586 {"mailto:, omit_username_password=true", 1274 {"ftp: with Japanese IDN",
587 "mailto:foo@example.com", "", default_format_type, UnescapeRule::NORMAL, 1275 "ftp://xn--l8jvb1ey91xtjb.jp/config.sys",
588 L"mailto:foo@example.com", 7}, 1276 "ja",
589 1277 default_format_type,
590 // -------- unescape flag tests -------- 1278 UnescapeRule::NORMAL,
591 {"Do not unescape", 1279 L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys",
592 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" 1280 6},
593 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" 1281
594 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", "en", default_format_type, 1282 // -------- omit_username_password flag tests --------
595 UnescapeRule::NONE, 1283 {"With username and password, omit_username_password=false",
596 // GURL parses %-encoded hostnames into Punycode. 1284 "http://user:passwd@example.com/foo",
597 L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" 1285 "",
598 L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 7}, 1286 kFormatUrlOmitNothing,
599 1287 UnescapeRule::NORMAL,
600 {"Unescape normally", 1288 L"http://user:passwd@example.com/foo",
601 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" 1289 19},
602 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" 1290
603 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", "en", default_format_type, 1291 {"With username and password, omit_username_password=true",
604 UnescapeRule::NORMAL, 1292 "http://user:passwd@example.com/foo",
605 L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB" 1293 "",
606 L"?q=\x30B0\x30FC\x30B0\x30EB", 7}, 1294 default_format_type,
607 1295 UnescapeRule::NORMAL,
608 {"Unescape normally with BiDi control character", 1296 L"http://example.com/foo",
609 "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", "en", default_format_type, 1297 7},
610 UnescapeRule::NORMAL, L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 7}, 1298
611 1299 {"With username and no password",
612 {"Unescape normally including unescape spaces", 1300 "http://user@example.com/foo",
613 "http://www.google.com/search?q=Hello%20World", "en", default_format_type, 1301 "",
614 UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World", 7}, 1302 default_format_type,
615 1303 UnescapeRule::NORMAL,
616 /* 1304 L"http://example.com/foo",
617 {"unescape=true with some special characters", 1305 7},
618 "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", "", 1306
619 kFormatUrlOmitNothing, UnescapeRule::NORMAL, 1307 {"Just '@' without username and password",
620 L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25}, 1308 "http://@example.com/foo",
621 */ 1309 "",
622 // Disabled: the resultant URL becomes "...user%253A:%2540passwd...". 1310 default_format_type,
623 1311 UnescapeRule::NORMAL,
624 // -------- omit http: -------- 1312 L"http://example.com/foo",
625 {"omit http with user name", 1313 7},
626 "http://user@example.com/foo", "", kFormatUrlOmitAll, 1314
627 UnescapeRule::NORMAL, L"example.com/foo", 0}, 1315 // GURL doesn't think local-part of an email address is username for URL.
628 1316 {"mailto:, omit_username_password=true",
629 {"omit http", 1317 "mailto:foo@example.com",
630 "http://www.google.com/", "en", kFormatUrlOmitHTTP, 1318 "",
631 UnescapeRule::NORMAL, L"www.google.com/", 1319 default_format_type,
632 0}, 1320 UnescapeRule::NORMAL,
633 1321 L"mailto:foo@example.com",
634 {"omit http with https", 1322 7},
635 "https://www.google.com/", "en", kFormatUrlOmitHTTP, 1323
636 UnescapeRule::NORMAL, L"https://www.google.com/", 1324 // -------- unescape flag tests --------
637 8}, 1325 {"Do not unescape",
638 1326 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
639 {"omit http starts with ftp.", 1327 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
640 "http://ftp.google.com/", "en", kFormatUrlOmitHTTP, 1328 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
641 UnescapeRule::NORMAL, L"http://ftp.google.com/", 1329 "en",
642 7}, 1330 default_format_type,
643 1331 UnescapeRule::NONE,
644 // -------- omit trailing slash on bare hostname -------- 1332 // GURL parses %-encoded hostnames into Punycode.
645 {"omit slash when it's the entire path", 1333 L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
646 "http://www.google.com/", "en", 1334 L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
647 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, 1335 7},
648 L"http://www.google.com", 7}, 1336
649 {"omit slash when there's a ref", 1337 {"Unescape normally",
650 "http://www.google.com/#ref", "en", 1338 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
651 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, 1339 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
652 L"http://www.google.com/#ref", 7}, 1340 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
653 {"omit slash when there's a query", 1341 "en",
654 "http://www.google.com/?", "en", 1342 default_format_type,
655 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, 1343 UnescapeRule::NORMAL,
656 L"http://www.google.com/?", 7}, 1344 L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB"
657 {"omit slash when it's not the entire path", 1345 L"?q=\x30B0\x30FC\x30B0\x30EB",
658 "http://www.google.com/foo", "en", 1346 7},
659 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, 1347
660 L"http://www.google.com/foo", 7}, 1348 {"Unescape normally with BiDi control character",
661 {"omit slash for nonstandard URLs", 1349 "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy",
662 "data:/", "en", kFormatUrlOmitTrailingSlashOnBareHostname, 1350 "en",
663 UnescapeRule::NORMAL, L"data:/", 5}, 1351 default_format_type,
664 {"omit slash for file URLs", 1352 UnescapeRule::NORMAL,
665 "file:///", "en", kFormatUrlOmitTrailingSlashOnBareHostname, 1353 L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy",
666 UnescapeRule::NORMAL, L"file:///", 7}, 1354 7},
667 1355
668 // -------- view-source: -------- 1356 {"Unescape normally including unescape spaces",
669 {"view-source", 1357 "http://www.google.com/search?q=Hello%20World",
670 "view-source:http://xn--qcka1pmc.jp/", "ja", default_format_type, 1358 "en",
671 UnescapeRule::NORMAL, L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", 1359 default_format_type,
672 19}, 1360 UnescapeRule::SPACES,
673 1361 L"http://www.google.com/search?q=Hello World",
674 {"view-source of view-source", 1362 7},
675 "view-source:view-source:http://xn--qcka1pmc.jp/", "ja", 1363
676 default_format_type, UnescapeRule::NORMAL, 1364 /*
677 L"view-source:view-source:http://xn--qcka1pmc.jp/", 12}, 1365 {"unescape=true with some special characters",
678 1366 "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", "",
679 // view-source should omit http and trailing slash where non-view-source 1367 kFormatUrlOmitNothing, UnescapeRule::NORMAL,
680 // would. 1368 L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25},
681 {"view-source omit http", 1369 */
682 "view-source:http://a.b/c", "en", kFormatUrlOmitAll, 1370 // Disabled: the resultant URL becomes "...user%253A:%2540passwd...".
683 UnescapeRule::NORMAL, L"view-source:a.b/c", 1371
684 12}, 1372 // -------- omit http: --------
685 {"view-source omit http starts with ftp.", 1373 {"omit http with user name",
686 "view-source:http://ftp.b/c", "en", kFormatUrlOmitAll, 1374 "http://user@example.com/foo",
687 UnescapeRule::NORMAL, L"view-source:http://ftp.b/c", 1375 "",
688 19}, 1376 kFormatUrlOmitAll,
689 {"view-source omit slash when it's the entire path", 1377 UnescapeRule::NORMAL,
690 "view-source:http://a.b/", "en", kFormatUrlOmitAll, 1378 L"example.com/foo",
691 UnescapeRule::NORMAL, L"view-source:a.b", 1379 0},
692 12}, 1380
1381 {"omit http",
1382 "http://www.google.com/",
1383 "en",
1384 kFormatUrlOmitHTTP,
1385 UnescapeRule::NORMAL,
1386 L"www.google.com/",
1387 0},
1388
1389 {"omit http with https",
1390 "https://www.google.com/",
1391 "en",
1392 kFormatUrlOmitHTTP,
1393 UnescapeRule::NORMAL,
1394 L"https://www.google.com/",
1395 8},
1396
1397 {"omit http starts with ftp.",
1398 "http://ftp.google.com/",
1399 "en",
1400 kFormatUrlOmitHTTP,
1401 UnescapeRule::NORMAL,
1402 L"http://ftp.google.com/",
1403 7},
1404
1405 // -------- omit trailing slash on bare hostname --------
1406 {"omit slash when it's the entire path",
1407 "http://www.google.com/",
1408 "en",
1409 kFormatUrlOmitTrailingSlashOnBareHostname,
1410 UnescapeRule::NORMAL,
1411 L"http://www.google.com",
1412 7},
1413 {"omit slash when there's a ref",
1414 "http://www.google.com/#ref",
1415 "en",
1416 kFormatUrlOmitTrailingSlashOnBareHostname,
1417 UnescapeRule::NORMAL,
1418 L"http://www.google.com/#ref",
1419 7},
1420 {"omit slash when there's a query",
1421 "http://www.google.com/?",
1422 "en",
1423 kFormatUrlOmitTrailingSlashOnBareHostname,
1424 UnescapeRule::NORMAL,
1425 L"http://www.google.com/?",
1426 7},
1427 {"omit slash when it's not the entire path",
1428 "http://www.google.com/foo",
1429 "en",
1430 kFormatUrlOmitTrailingSlashOnBareHostname,
1431 UnescapeRule::NORMAL,
1432 L"http://www.google.com/foo",
1433 7},
1434 {"omit slash for nonstandard URLs",
1435 "data:/",
1436 "en",
1437 kFormatUrlOmitTrailingSlashOnBareHostname,
1438 UnescapeRule::NORMAL,
1439 L"data:/",
1440 5},
1441 {"omit slash for file URLs",
1442 "file:///",
1443 "en",
1444 kFormatUrlOmitTrailingSlashOnBareHostname,
1445 UnescapeRule::NORMAL,
1446 L"file:///",
1447 7},
1448
1449 // -------- view-source: --------
1450 {"view-source",
1451 "view-source:http://xn--qcka1pmc.jp/",
1452 "ja",
1453 default_format_type,
1454 UnescapeRule::NORMAL,
1455 L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/",
1456 19},
1457
1458 {"view-source of view-source",
1459 "view-source:view-source:http://xn--qcka1pmc.jp/",
1460 "ja",
1461 default_format_type,
1462 UnescapeRule::NORMAL,
1463 L"view-source:view-source:http://xn--qcka1pmc.jp/",
1464 12},
1465
1466 // view-source should omit http and trailing slash where non-view-source
1467 // would.
1468 {"view-source omit http",
1469 "view-source:http://a.b/c",
1470 "en",
1471 kFormatUrlOmitAll,
1472 UnescapeRule::NORMAL,
1473 L"view-source:a.b/c",
1474 12},
1475 {"view-source omit http starts with ftp.",
1476 "view-source:http://ftp.b/c",
1477 "en",
1478 kFormatUrlOmitAll,
1479 UnescapeRule::NORMAL,
1480 L"view-source:http://ftp.b/c",
1481 19},
1482 {"view-source omit slash when it's the entire path",
1483 "view-source:http://a.b/",
1484 "en",
1485 kFormatUrlOmitAll,
1486 UnescapeRule::NORMAL,
1487 L"view-source:a.b",
1488 12},
693 }; 1489 };
694 1490
695 for (size_t i = 0; i < arraysize(tests); ++i) { 1491 for (size_t i = 0; i < arraysize(tests); ++i) {
696 size_t prefix_len; 1492 size_t prefix_len;
697 base::string16 formatted = FormatUrl( 1493 base::string16 formatted = FormatUrl(
698 GURL(tests[i].input), tests[i].languages, tests[i].format_types, 1494 GURL(tests[i].input), tests[i].languages, tests[i].format_types,
699 tests[i].escape_rules, NULL, &prefix_len, NULL); 1495 tests[i].escape_rules, NULL, &prefix_len, NULL);
700 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; 1496 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description;
701 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; 1497 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
702 } 1498 }
703 } 1499 }
704 1500
705 TEST(NetUtilTest, FormatUrlParsed) { 1501 TEST(NetUtilTest, FormatUrlParsed) {
706 // No unescape case. 1502 // No unescape case.
707 url::Parsed parsed; 1503 url::Parsed parsed;
708 base::string16 formatted = FormatUrl( 1504 base::string16 formatted = FormatUrl(
709 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" 1505 GURL(
710 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), 1506 "http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
711 "ja", kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL, 1507 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
712 NULL); 1508 "ja", kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL, NULL);
713 EXPECT_EQ(WideToUTF16( 1509 EXPECT_EQ(WideToUTF16(
714 L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080" 1510 L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
715 L"/%E3%82%B0/?q=%E3%82%B0#\x30B0"), formatted); 1511 L"/%E3%82%B0/?q=%E3%82%B0#\x30B0"),
1512 formatted);
716 EXPECT_EQ(WideToUTF16(L"%E3%82%B0"), 1513 EXPECT_EQ(WideToUTF16(L"%E3%82%B0"),
717 formatted.substr(parsed.username.begin, parsed.username.len)); 1514 formatted.substr(parsed.username.begin, parsed.username.len));
718 EXPECT_EQ(WideToUTF16(L"%E3%83%BC"), 1515 EXPECT_EQ(WideToUTF16(L"%E3%83%BC"),
719 formatted.substr(parsed.password.begin, parsed.password.len)); 1516 formatted.substr(parsed.password.begin, parsed.password.len));
720 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), 1517 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
721 formatted.substr(parsed.host.begin, parsed.host.len)); 1518 formatted.substr(parsed.host.begin, parsed.host.len));
722 EXPECT_EQ(WideToUTF16(L"8080"), 1519 EXPECT_EQ(WideToUTF16(L"8080"),
723 formatted.substr(parsed.port.begin, parsed.port.len)); 1520 formatted.substr(parsed.port.begin, parsed.port.len));
724 EXPECT_EQ(WideToUTF16(L"/%E3%82%B0/"), 1521 EXPECT_EQ(WideToUTF16(L"/%E3%82%B0/"),
725 formatted.substr(parsed.path.begin, parsed.path.len)); 1522 formatted.substr(parsed.path.begin, parsed.path.len));
726 EXPECT_EQ(WideToUTF16(L"q=%E3%82%B0"), 1523 EXPECT_EQ(WideToUTF16(L"q=%E3%82%B0"),
727 formatted.substr(parsed.query.begin, parsed.query.len)); 1524 formatted.substr(parsed.query.begin, parsed.query.len));
728 EXPECT_EQ(WideToUTF16(L"\x30B0"), 1525 EXPECT_EQ(WideToUTF16(L"\x30B0"),
729 formatted.substr(parsed.ref.begin, parsed.ref.len)); 1526 formatted.substr(parsed.ref.begin, parsed.ref.len));
730 1527
731 // Unescape case. 1528 // Unescape case.
732 formatted = FormatUrl( 1529 formatted = FormatUrl(
733 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" 1530 GURL(
734 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), 1531 "http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
735 "ja", kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL, 1532 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
736 NULL); 1533 "ja", kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL, NULL);
737 EXPECT_EQ(WideToUTF16(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080" 1534 EXPECT_EQ(WideToUTF16(
738 L"/\x30B0/?q=\x30B0#\x30B0"), formatted); 1535 L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
1536 L"/\x30B0/?q=\x30B0#\x30B0"),
1537 formatted);
739 EXPECT_EQ(WideToUTF16(L"\x30B0"), 1538 EXPECT_EQ(WideToUTF16(L"\x30B0"),
740 formatted.substr(parsed.username.begin, parsed.username.len)); 1539 formatted.substr(parsed.username.begin, parsed.username.len));
741 EXPECT_EQ(WideToUTF16(L"\x30FC"), 1540 EXPECT_EQ(WideToUTF16(L"\x30FC"),
742 formatted.substr(parsed.password.begin, parsed.password.len)); 1541 formatted.substr(parsed.password.begin, parsed.password.len));
743 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), 1542 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
744 formatted.substr(parsed.host.begin, parsed.host.len)); 1543 formatted.substr(parsed.host.begin, parsed.host.len));
745 EXPECT_EQ(WideToUTF16(L"8080"), 1544 EXPECT_EQ(WideToUTF16(L"8080"),
746 formatted.substr(parsed.port.begin, parsed.port.len)); 1545 formatted.substr(parsed.port.begin, parsed.port.len));
747 EXPECT_EQ(WideToUTF16(L"/\x30B0/"), 1546 EXPECT_EQ(WideToUTF16(L"/\x30B0/"),
748 formatted.substr(parsed.path.begin, parsed.path.len)); 1547 formatted.substr(parsed.path.begin, parsed.path.len));
749 EXPECT_EQ(WideToUTF16(L"q=\x30B0"), 1548 EXPECT_EQ(WideToUTF16(L"q=\x30B0"),
750 formatted.substr(parsed.query.begin, parsed.query.len)); 1549 formatted.substr(parsed.query.begin, parsed.query.len));
751 EXPECT_EQ(WideToUTF16(L"\x30B0"), 1550 EXPECT_EQ(WideToUTF16(L"\x30B0"),
752 formatted.substr(parsed.ref.begin, parsed.ref.len)); 1551 formatted.substr(parsed.ref.begin, parsed.ref.len));
753 1552
754 // Omit_username_password + unescape case. 1553 // Omit_username_password + unescape case.
755 formatted = FormatUrl( 1554 formatted =
756 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" 1555 FormatUrl(GURL(
757 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), 1556 "http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
758 "ja", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed, 1557 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
759 NULL, NULL); 1558 "ja", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
760 EXPECT_EQ(WideToUTF16(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080" 1559 &parsed, NULL, NULL);
761 L"/\x30B0/?q=\x30B0#\x30B0"), formatted); 1560 EXPECT_EQ(WideToUTF16(
1561 L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
1562 L"/\x30B0/?q=\x30B0#\x30B0"),
1563 formatted);
762 EXPECT_FALSE(parsed.username.is_valid()); 1564 EXPECT_FALSE(parsed.username.is_valid());
763 EXPECT_FALSE(parsed.password.is_valid()); 1565 EXPECT_FALSE(parsed.password.is_valid());
764 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), 1566 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
765 formatted.substr(parsed.host.begin, parsed.host.len)); 1567 formatted.substr(parsed.host.begin, parsed.host.len));
766 EXPECT_EQ(WideToUTF16(L"8080"), 1568 EXPECT_EQ(WideToUTF16(L"8080"),
767 formatted.substr(parsed.port.begin, parsed.port.len)); 1569 formatted.substr(parsed.port.begin, parsed.port.len));
768 EXPECT_EQ(WideToUTF16(L"/\x30B0/"), 1570 EXPECT_EQ(WideToUTF16(L"/\x30B0/"),
769 formatted.substr(parsed.path.begin, parsed.path.len)); 1571 formatted.substr(parsed.path.begin, parsed.path.len));
770 EXPECT_EQ(WideToUTF16(L"q=\x30B0"), 1572 EXPECT_EQ(WideToUTF16(L"q=\x30B0"),
771 formatted.substr(parsed.query.begin, parsed.query.len)); 1573 formatted.substr(parsed.query.begin, parsed.query.len));
772 EXPECT_EQ(WideToUTF16(L"\x30B0"), 1574 EXPECT_EQ(WideToUTF16(L"\x30B0"),
773 formatted.substr(parsed.ref.begin, parsed.ref.len)); 1575 formatted.substr(parsed.ref.begin, parsed.ref.len));
774 1576
775 // View-source case. 1577 // View-source case.
776 formatted = 1578 formatted =
777 FormatUrl(GURL("view-source:http://user:passwd@host:81/path?query#ref"), 1579 FormatUrl(GURL("view-source:http://user:passwd@host:81/path?query#ref"),
778 std::string(), 1580 std::string(), kFormatUrlOmitUsernamePassword,
779 kFormatUrlOmitUsernamePassword, 1581 UnescapeRule::NORMAL, &parsed, NULL, NULL);
780 UnescapeRule::NORMAL,
781 &parsed,
782 NULL,
783 NULL);
784 EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"), 1582 EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"),
785 formatted); 1583 formatted);
786 EXPECT_EQ(WideToUTF16(L"view-source:http"), 1584 EXPECT_EQ(WideToUTF16(L"view-source:http"),
787 formatted.substr(parsed.scheme.begin, parsed.scheme.len)); 1585 formatted.substr(parsed.scheme.begin, parsed.scheme.len));
788 EXPECT_FALSE(parsed.username.is_valid()); 1586 EXPECT_FALSE(parsed.username.is_valid());
789 EXPECT_FALSE(parsed.password.is_valid()); 1587 EXPECT_FALSE(parsed.password.is_valid());
790 EXPECT_EQ(WideToUTF16(L"host"), 1588 EXPECT_EQ(WideToUTF16(L"host"),
791 formatted.substr(parsed.host.begin, parsed.host.len)); 1589 formatted.substr(parsed.host.begin, parsed.host.len));
792 EXPECT_EQ(WideToUTF16(L"81"), 1590 EXPECT_EQ(WideToUTF16(L"81"),
793 formatted.substr(parsed.port.begin, parsed.port.len)); 1591 formatted.substr(parsed.port.begin, parsed.port.len));
794 EXPECT_EQ(WideToUTF16(L"/path"), 1592 EXPECT_EQ(WideToUTF16(L"/path"),
795 formatted.substr(parsed.path.begin, parsed.path.len)); 1593 formatted.substr(parsed.path.begin, parsed.path.len));
796 EXPECT_EQ(WideToUTF16(L"query"), 1594 EXPECT_EQ(WideToUTF16(L"query"),
797 formatted.substr(parsed.query.begin, parsed.query.len)); 1595 formatted.substr(parsed.query.begin, parsed.query.len));
798 EXPECT_EQ(WideToUTF16(L"ref"), 1596 EXPECT_EQ(WideToUTF16(L"ref"),
799 formatted.substr(parsed.ref.begin, parsed.ref.len)); 1597 formatted.substr(parsed.ref.begin, parsed.ref.len));
800 1598
801 // omit http case. 1599 // omit http case.
802 formatted = FormatUrl(GURL("http://host:8000/a?b=c#d"), 1600 formatted =
803 std::string(), 1601 FormatUrl(GURL("http://host:8000/a?b=c#d"), std::string(),
804 kFormatUrlOmitHTTP, 1602 kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
805 UnescapeRule::NORMAL,
806 &parsed,
807 NULL,
808 NULL);
809 EXPECT_EQ(WideToUTF16(L"host:8000/a?b=c#d"), formatted); 1603 EXPECT_EQ(WideToUTF16(L"host:8000/a?b=c#d"), formatted);
810 EXPECT_FALSE(parsed.scheme.is_valid()); 1604 EXPECT_FALSE(parsed.scheme.is_valid());
811 EXPECT_FALSE(parsed.username.is_valid()); 1605 EXPECT_FALSE(parsed.username.is_valid());
812 EXPECT_FALSE(parsed.password.is_valid()); 1606 EXPECT_FALSE(parsed.password.is_valid());
813 EXPECT_EQ(WideToUTF16(L"host"), 1607 EXPECT_EQ(WideToUTF16(L"host"),
814 formatted.substr(parsed.host.begin, parsed.host.len)); 1608 formatted.substr(parsed.host.begin, parsed.host.len));
815 EXPECT_EQ(WideToUTF16(L"8000"), 1609 EXPECT_EQ(WideToUTF16(L"8000"),
816 formatted.substr(parsed.port.begin, parsed.port.len)); 1610 formatted.substr(parsed.port.begin, parsed.port.len));
817 EXPECT_EQ(WideToUTF16(L"/a"), 1611 EXPECT_EQ(WideToUTF16(L"/a"),
818 formatted.substr(parsed.path.begin, parsed.path.len)); 1612 formatted.substr(parsed.path.begin, parsed.path.len));
819 EXPECT_EQ(WideToUTF16(L"b=c"), 1613 EXPECT_EQ(WideToUTF16(L"b=c"),
820 formatted.substr(parsed.query.begin, parsed.query.len)); 1614 formatted.substr(parsed.query.begin, parsed.query.len));
821 EXPECT_EQ(WideToUTF16(L"d"), 1615 EXPECT_EQ(WideToUTF16(L"d"),
822 formatted.substr(parsed.ref.begin, parsed.ref.len)); 1616 formatted.substr(parsed.ref.begin, parsed.ref.len));
823 1617
824 // omit http starts with ftp case. 1618 // omit http starts with ftp case.
825 formatted = FormatUrl(GURL("http://ftp.host:8000/a?b=c#d"), 1619 formatted =
826 std::string(), 1620 FormatUrl(GURL("http://ftp.host:8000/a?b=c#d"), std::string(),
827 kFormatUrlOmitHTTP, 1621 kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
828 UnescapeRule::NORMAL,
829 &parsed,
830 NULL,
831 NULL);
832 EXPECT_EQ(WideToUTF16(L"http://ftp.host:8000/a?b=c#d"), formatted); 1622 EXPECT_EQ(WideToUTF16(L"http://ftp.host:8000/a?b=c#d"), formatted);
833 EXPECT_TRUE(parsed.scheme.is_valid()); 1623 EXPECT_TRUE(parsed.scheme.is_valid());
834 EXPECT_FALSE(parsed.username.is_valid()); 1624 EXPECT_FALSE(parsed.username.is_valid());
835 EXPECT_FALSE(parsed.password.is_valid()); 1625 EXPECT_FALSE(parsed.password.is_valid());
836 EXPECT_EQ(WideToUTF16(L"http"), 1626 EXPECT_EQ(WideToUTF16(L"http"),
837 formatted.substr(parsed.scheme.begin, parsed.scheme.len)); 1627 formatted.substr(parsed.scheme.begin, parsed.scheme.len));
838 EXPECT_EQ(WideToUTF16(L"ftp.host"), 1628 EXPECT_EQ(WideToUTF16(L"ftp.host"),
839 formatted.substr(parsed.host.begin, parsed.host.len)); 1629 formatted.substr(parsed.host.begin, parsed.host.len));
840 EXPECT_EQ(WideToUTF16(L"8000"), 1630 EXPECT_EQ(WideToUTF16(L"8000"),
841 formatted.substr(parsed.port.begin, parsed.port.len)); 1631 formatted.substr(parsed.port.begin, parsed.port.len));
842 EXPECT_EQ(WideToUTF16(L"/a"), 1632 EXPECT_EQ(WideToUTF16(L"/a"),
843 formatted.substr(parsed.path.begin, parsed.path.len)); 1633 formatted.substr(parsed.path.begin, parsed.path.len));
844 EXPECT_EQ(WideToUTF16(L"b=c"), 1634 EXPECT_EQ(WideToUTF16(L"b=c"),
845 formatted.substr(parsed.query.begin, parsed.query.len)); 1635 formatted.substr(parsed.query.begin, parsed.query.len));
846 EXPECT_EQ(WideToUTF16(L"d"), 1636 EXPECT_EQ(WideToUTF16(L"d"),
847 formatted.substr(parsed.ref.begin, parsed.ref.len)); 1637 formatted.substr(parsed.ref.begin, parsed.ref.len));
848 1638
849 // omit http starts with 'f' case. 1639 // omit http starts with 'f' case.
850 formatted = FormatUrl(GURL("http://f/"), 1640 formatted = FormatUrl(GURL("http://f/"), std::string(), kFormatUrlOmitHTTP,
851 std::string(), 1641 UnescapeRule::NORMAL, &parsed, NULL, NULL);
852 kFormatUrlOmitHTTP,
853 UnescapeRule::NORMAL,
854 &parsed,
855 NULL,
856 NULL);
857 EXPECT_EQ(WideToUTF16(L"f/"), formatted); 1642 EXPECT_EQ(WideToUTF16(L"f/"), formatted);
858 EXPECT_FALSE(parsed.scheme.is_valid()); 1643 EXPECT_FALSE(parsed.scheme.is_valid());
859 EXPECT_FALSE(parsed.username.is_valid()); 1644 EXPECT_FALSE(parsed.username.is_valid());
860 EXPECT_FALSE(parsed.password.is_valid()); 1645 EXPECT_FALSE(parsed.password.is_valid());
861 EXPECT_FALSE(parsed.port.is_valid()); 1646 EXPECT_FALSE(parsed.port.is_valid());
862 EXPECT_TRUE(parsed.path.is_valid()); 1647 EXPECT_TRUE(parsed.path.is_valid());
863 EXPECT_FALSE(parsed.query.is_valid()); 1648 EXPECT_FALSE(parsed.query.is_valid());
864 EXPECT_FALSE(parsed.ref.is_valid()); 1649 EXPECT_FALSE(parsed.ref.is_valid());
865 EXPECT_EQ(WideToUTF16(L"f"), 1650 EXPECT_EQ(WideToUTF16(L"f"),
866 formatted.substr(parsed.host.begin, parsed.host.len)); 1651 formatted.substr(parsed.host.begin, parsed.host.len));
867 EXPECT_EQ(WideToUTF16(L"/"), 1652 EXPECT_EQ(WideToUTF16(L"/"),
868 formatted.substr(parsed.path.begin, parsed.path.len)); 1653 formatted.substr(parsed.path.begin, parsed.path.len));
869 } 1654 }
870 1655
871 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL 1656 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
872 // results in the original GURL, for each ASCII character in the path. 1657 // results in the original GURL, for each ASCII character in the path.
873 TEST(NetUtilTest, FormatUrlRoundTripPathASCII) { 1658 TEST(NetUtilTest, FormatUrlRoundTripPathASCII) {
874 for (unsigned char test_char = 32; test_char < 128; ++test_char) { 1659 for (unsigned char test_char = 32; test_char < 128; ++test_char) {
875 GURL url(std::string("http://www.google.com/") + 1660 GURL url(std::string("http://www.google.com/") +
876 static_cast<char>(test_char)); 1661 static_cast<char>(test_char));
877 size_t prefix_len; 1662 size_t prefix_len;
878 base::string16 formatted = FormatUrl(url, 1663 base::string16 formatted =
879 std::string(), 1664 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
880 kFormatUrlOmitUsernamePassword, 1665 UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
881 UnescapeRule::NORMAL,
882 NULL,
883 &prefix_len,
884 NULL);
885 EXPECT_EQ(url.spec(), GURL(formatted).spec()); 1666 EXPECT_EQ(url.spec(), GURL(formatted).spec());
886 } 1667 }
887 } 1668 }
888 1669
889 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL 1670 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
890 // results in the original GURL, for each escaped ASCII character in the path. 1671 // results in the original GURL, for each escaped ASCII character in the path.
891 TEST(NetUtilTest, FormatUrlRoundTripPathEscaped) { 1672 TEST(NetUtilTest, FormatUrlRoundTripPathEscaped) {
892 for (unsigned char test_char = 32; test_char < 128; ++test_char) { 1673 for (unsigned char test_char = 32; test_char < 128; ++test_char) {
893 std::string original_url("http://www.google.com/"); 1674 std::string original_url("http://www.google.com/");
894 original_url.push_back('%'); 1675 original_url.push_back('%');
895 original_url.append(base::HexEncode(&test_char, 1)); 1676 original_url.append(base::HexEncode(&test_char, 1));
896 1677
897 GURL url(original_url); 1678 GURL url(original_url);
898 size_t prefix_len; 1679 size_t prefix_len;
899 base::string16 formatted = FormatUrl(url, 1680 base::string16 formatted =
900 std::string(), 1681 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
901 kFormatUrlOmitUsernamePassword, 1682 UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
902 UnescapeRule::NORMAL,
903 NULL,
904 &prefix_len,
905 NULL);
906 EXPECT_EQ(url.spec(), GURL(formatted).spec()); 1683 EXPECT_EQ(url.spec(), GURL(formatted).spec());
907 } 1684 }
908 } 1685 }
909 1686
910 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL 1687 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
911 // results in the original GURL, for each ASCII character in the query. 1688 // results in the original GURL, for each ASCII character in the query.
912 TEST(NetUtilTest, FormatUrlRoundTripQueryASCII) { 1689 TEST(NetUtilTest, FormatUrlRoundTripQueryASCII) {
913 for (unsigned char test_char = 32; test_char < 128; ++test_char) { 1690 for (unsigned char test_char = 32; test_char < 128; ++test_char) {
914 GURL url(std::string("http://www.google.com/?") + 1691 GURL url(std::string("http://www.google.com/?") +
915 static_cast<char>(test_char)); 1692 static_cast<char>(test_char));
916 size_t prefix_len; 1693 size_t prefix_len;
917 base::string16 formatted = FormatUrl(url, 1694 base::string16 formatted =
918 std::string(), 1695 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
919 kFormatUrlOmitUsernamePassword, 1696 UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
920 UnescapeRule::NORMAL,
921 NULL,
922 &prefix_len,
923 NULL);
924 EXPECT_EQ(url.spec(), GURL(formatted).spec()); 1697 EXPECT_EQ(url.spec(), GURL(formatted).spec());
925 } 1698 }
926 } 1699 }
927 1700
928 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL 1701 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
929 // only results in a different GURL for certain characters. 1702 // only results in a different GURL for certain characters.
930 TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) { 1703 TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) {
931 // A full list of characters which FormatURL should unescape and GURL should 1704 // A full list of characters which FormatURL should unescape and GURL should
932 // not escape again, when they appear in a query string. 1705 // not escape again, when they appear in a query string.
933 const char* kUnescapedCharacters = 1706 const char* kUnescapedCharacters =
934 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~"; 1707 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~";
935 for (unsigned char test_char = 0; test_char < 128; ++test_char) { 1708 for (unsigned char test_char = 0; test_char < 128; ++test_char) {
936 std::string original_url("http://www.google.com/?"); 1709 std::string original_url("http://www.google.com/?");
937 original_url.push_back('%'); 1710 original_url.push_back('%');
938 original_url.append(base::HexEncode(&test_char, 1)); 1711 original_url.append(base::HexEncode(&test_char, 1));
939 1712
940 GURL url(original_url); 1713 GURL url(original_url);
941 size_t prefix_len; 1714 size_t prefix_len;
942 base::string16 formatted = FormatUrl(url, 1715 base::string16 formatted =
943 std::string(), 1716 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
944 kFormatUrlOmitUsernamePassword, 1717 UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
945 UnescapeRule::NORMAL,
946 NULL,
947 &prefix_len,
948 NULL);
949 1718
950 if (test_char && 1719 if (test_char &&
951 strchr(kUnescapedCharacters, static_cast<char>(test_char))) { 1720 strchr(kUnescapedCharacters, static_cast<char>(test_char))) {
952 EXPECT_NE(url.spec(), GURL(formatted).spec()); 1721 EXPECT_NE(url.spec(), GURL(formatted).spec());
953 } else { 1722 } else {
954 EXPECT_EQ(url.spec(), GURL(formatted).spec()); 1723 EXPECT_EQ(url.spec(), GURL(formatted).spec());
955 } 1724 }
956 } 1725 }
957 } 1726 }
958 1727
959 TEST(NetUtilTest, FormatUrlWithOffsets) { 1728 TEST(NetUtilTest, FormatUrlWithOffsets) {
960 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing, 1729 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing,
961 UnescapeRule::NORMAL, NULL); 1730 UnescapeRule::NORMAL, NULL);
962 1731
963 const size_t basic_offsets[] = { 1732 const size_t basic_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8,
964 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1733 9, 10, 11, 12, 13, 14, 15, 16, 17,
965 21, 22, 23, 24, 25 1734 18, 19, 20, 21, 22, 23, 24, 25};
966 };
967 CheckAdjustedOffsets("http://www.google.com/foo/", "en", 1735 CheckAdjustedOffsets("http://www.google.com/foo/", "en",
968 kFormatUrlOmitNothing, UnescapeRule::NORMAL, 1736 kFormatUrlOmitNothing, UnescapeRule::NORMAL,
969 basic_offsets); 1737 basic_offsets);
970 1738
971 const size_t omit_auth_offsets_1[] = { 1739 const size_t omit_auth_offsets_1[] = {
972 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7, 1740 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos,
973 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 1741 kNpos, kNpos, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11,
974 }; 1742 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
975 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en", 1743 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en",
976 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, 1744 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
977 omit_auth_offsets_1); 1745 omit_auth_offsets_1);
978 1746
979 const size_t omit_auth_offsets_2[] = { 1747 const size_t omit_auth_offsets_2[] = {
980 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, 1748 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8,
981 15, 16, 17, 18, 19, 20, 21 1749 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
982 };
983 CheckAdjustedOffsets("http://foo@www.google.com/", "en", 1750 CheckAdjustedOffsets("http://foo@www.google.com/", "en",
984 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, 1751 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
985 omit_auth_offsets_2); 1752 omit_auth_offsets_2);
986 1753
987 const size_t dont_omit_auth_offsets[] = { 1754 const size_t dont_omit_auth_offsets[] = {
988 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 1755 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
989 kNpos, kNpos, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 1756 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 11,
990 kNpos, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 1757 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 13,
991 30, 31 1758 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
992 }; 1759 24, 25, 26, 27, 28, 29, 30, 31};
993 // Unescape to "http://foo\x30B0:\x30B0bar@www.google.com". 1760 // Unescape to "http://foo\x30B0:\x30B0bar@www.google.com".
994 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en", 1761 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en",
995 kFormatUrlOmitNothing, UnescapeRule::NORMAL, 1762 kFormatUrlOmitNothing, UnescapeRule::NORMAL,
996 dont_omit_auth_offsets); 1763 dont_omit_auth_offsets);
997 1764
998 const size_t view_source_offsets[] = { 1765 const size_t view_source_offsets[] = {
999 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, kNpos, 1766 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1000 kNpos, kNpos, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 1767 13, 14, 15, 16, 17, 18, 19, kNpos, kNpos, kNpos, 19, 20, 21,
1001 }; 1768 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33};
1002 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en", 1769 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en",
1003 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, 1770 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
1004 view_source_offsets); 1771 view_source_offsets);
1005 1772
1006 const size_t idn_hostname_offsets_1[] = { 1773 const size_t idn_hostname_offsets_1[] = {
1007 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 1774 0, 1, 2, 3, 4, 5, 6, 7, kNpos,
1008 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, 1775 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
1009 13, 14, 15, 16, 17, 18, 19 1776 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, 13,
1010 }; 1777 14, 15, 16, 17, 18, 19};
1011 // Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/". 1778 // Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/".
1012 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja", 1779 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja",
1013 kFormatUrlOmitNothing, UnescapeRule::NORMAL, 1780 kFormatUrlOmitNothing, UnescapeRule::NORMAL,
1014 idn_hostname_offsets_1); 1781 idn_hostname_offsets_1);
1015 1782
1016 const size_t idn_hostname_offsets_2[] = { 1783 const size_t idn_hostname_offsets_2[] = {
1017 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, 1784 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
1018 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 14, 15, kNpos, kNpos, kNpos, 1785 10, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
1019 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 1786 kNpos, kNpos, kNpos, kNpos, 14, 15, kNpos, kNpos, kNpos, kNpos,
1020 kNpos, 19, 20, 21, 22, 23, 24 1787 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
1021 }; 1788 kNpos, 19, 20, 21, 22, 23, 24};
1022 // Convert punycode to 1789 // Convert punycode to
1023 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/". 1790 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/".
1024 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/", 1791 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/",
1025 "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL, 1792 "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL,
1026 idn_hostname_offsets_2); 1793 idn_hostname_offsets_2);
1027 1794
1028 const size_t unescape_offsets[] = { 1795 const size_t unescape_offsets[] = {
1029 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1796 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
1030 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, 28, 29, 30, kNpos, kNpos, kNpos, 1797 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1031 kNpos, kNpos, kNpos, kNpos, kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos, 1798 20, 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27,
1032 kNpos, kNpos, kNpos, 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 1799 28, 29, 30, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
1033 kNpos, 33, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos 1800 kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
1034 }; 1801 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 33,
1802 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos};
1035 // Unescape to "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB". 1803 // Unescape to "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB".
1036 CheckAdjustedOffsets( 1804 CheckAdjustedOffsets(
1037 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 1805 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
1038 "en", kFormatUrlOmitNothing, UnescapeRule::SPACES, unescape_offsets); 1806 "en", kFormatUrlOmitNothing, UnescapeRule::SPACES, unescape_offsets);
1039 1807
1040 const size_t ref_offsets[] = { 1808 const size_t ref_offsets[] = {
1041 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1809 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1042 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos, 1810 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
1043 33 1811 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos, 33};
1044 };
1045 // Unescape to "http://www.google.com/foo.html#\x30B0\x30B0z". 1812 // Unescape to "http://www.google.com/foo.html#\x30B0\x30B0z".
1046 CheckAdjustedOffsets( 1813 CheckAdjustedOffsets(
1047 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en", 1814 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en",
1048 kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_offsets); 1815 kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_offsets);
1049 1816
1050 const size_t omit_http_offsets[] = { 1817 const size_t omit_http_offsets[] = {
1051 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1818 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3,
1052 10, 11, 12, 13, 14 1819 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
1053 };
1054 CheckAdjustedOffsets("http://www.google.com/", "en", kFormatUrlOmitHTTP, 1820 CheckAdjustedOffsets("http://www.google.com/", "en", kFormatUrlOmitHTTP,
1055 UnescapeRule::NORMAL, omit_http_offsets); 1821 UnescapeRule::NORMAL, omit_http_offsets);
1056 1822
1057 const size_t omit_http_start_with_ftp_offsets[] = { 1823 const size_t omit_http_start_with_ftp_offsets[] = {
1058 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 1824 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1059 }; 1825 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
1060 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP, 1826 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP,
1061 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets); 1827 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets);
1062 1828
1063 const size_t omit_all_offsets[] = { 1829 const size_t omit_all_offsets[] = {
1064 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 1830 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos,
1065 0, 1, 2, 3, 4, 5, 6, 7 1831 kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, 7};
1066 };
1067 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, 1832 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll,
1068 UnescapeRule::NORMAL, omit_all_offsets); 1833 UnescapeRule::NORMAL, omit_all_offsets);
1069 } 1834 }
1070 1835
1071 } // namespace net 1836 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698