OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/common/net/url_fixer_upper.h" | 13 #include "chrome/common/net/url_fixer_upper.h" |
14 #include "net/base/filename_util.h" | 14 #include "net/base/filename_util.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 #include "url/url_parse.h" | 17 #include "url/url_parse.h" |
18 | 18 |
19 namespace { | |
20 class URLFixerUpperTest : public testing::Test { | |
21 }; | |
22 }; | |
23 | |
24 namespace url { | 19 namespace url { |
25 | 20 |
26 std::ostream& operator<<(std::ostream& os, const Component& part) { | 21 std::ostream& operator<<(std::ostream& os, const Component& part) { |
27 return os << "(begin=" << part.begin << ", len=" << part.len << ")"; | 22 return os << "(begin=" << part.begin << ", len=" << part.len << ")"; |
28 } | 23 } |
29 | 24 |
30 } // namespace url | 25 } // namespace url |
31 | 26 |
32 struct SegmentCase { | 27 struct SegmentCase { |
33 const std::string input; | 28 const std::string input; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 url::Component(), // username | 185 url::Component(), // username |
191 url::Component(), // password | 186 url::Component(), // password |
192 url::Component(), // host | 187 url::Component(), // host |
193 url::Component(), // port | 188 url::Component(), // port |
194 url::Component(), // path | 189 url::Component(), // path |
195 url::Component(), // query | 190 url::Component(), // query |
196 url::Component(), // ref | 191 url::Component(), // ref |
197 }, | 192 }, |
198 }; | 193 }; |
199 | 194 |
| 195 typedef testing::Test URLFixerUpperTest; |
| 196 |
200 TEST(URLFixerUpperTest, SegmentURL) { | 197 TEST(URLFixerUpperTest, SegmentURL) { |
201 std::string result; | 198 std::string result; |
202 url::Parsed parts; | 199 url::Parsed parts; |
203 | 200 |
204 for (size_t i = 0; i < arraysize(segment_cases); ++i) { | 201 for (size_t i = 0; i < arraysize(segment_cases); ++i) { |
205 SegmentCase value = segment_cases[i]; | 202 SegmentCase value = segment_cases[i]; |
206 result = URLFixerUpper::SegmentURL(value.input, &parts); | 203 result = URLFixerUpper::SegmentURL(value.input, &parts); |
207 EXPECT_EQ(value.result, result); | 204 EXPECT_EQ(value.result, result); |
208 EXPECT_EQ(value.scheme, parts.scheme); | 205 EXPECT_EQ(value.scheme, parts.scheme); |
209 EXPECT_EQ(value.username, parts.username); | 206 EXPECT_EQ(value.username, parts.username); |
(...skipping 30 matching lines...) Expand all Loading... |
240 | 237 |
241 base::FilePath derived_path; | 238 base::FilePath derived_path; |
242 net::FileURLToFilePath(GURL(url), &derived_path); | 239 net::FileURLToFilePath(GURL(url), &derived_path); |
243 | 240 |
244 return base::FilePath::CompareEqualIgnoreCase(derived_path.value(), | 241 return base::FilePath::CompareEqualIgnoreCase(derived_path.value(), |
245 full_file_path.value()); | 242 full_file_path.value()); |
246 } | 243 } |
247 | 244 |
248 struct FixupCase { | 245 struct FixupCase { |
249 const std::string input; | 246 const std::string input; |
250 const std::string desired_tld; | |
251 const std::string output; | 247 const std::string output; |
252 } fixup_cases[] = { | 248 } fixup_cases[] = { |
253 {"www.google.com", "", "http://www.google.com/"}, | 249 {"www.google.com", "http://www.google.com/"}, |
254 {" www.google.com ", "", "http://www.google.com/"}, | 250 {" www.google.com ", "http://www.google.com/"}, |
255 {" foo.com/asdf bar", "", "http://foo.com/asdf%20%20bar"}, | 251 {" foo.com/asdf bar", "http://foo.com/asdf%20%20bar"}, |
256 {"..www.google.com..", "", "http://www.google.com./"}, | 252 {"..www.google.com..", "http://www.google.com./"}, |
257 {"http://......", "", "http://....../"}, | 253 {"http://......", "http://....../"}, |
258 {"http://host.com:ninety-two/", "", "http://host.com:ninety-two/"}, | 254 {"http://host.com:ninety-two/", "http://host.com:ninety-two/"}, |
259 {"http://host.com:ninety-two?foo", "", "http://host.com:ninety-two/?foo"}, | 255 {"http://host.com:ninety-two?foo", "http://host.com:ninety-two/?foo"}, |
260 {"google.com:123", "", "http://google.com:123/"}, | 256 {"google.com:123", "http://google.com:123/"}, |
261 {"about:", "", "chrome://version/"}, | 257 {"about:", "chrome://version/"}, |
262 {"about:foo", "", "chrome://foo/"}, | 258 {"about:foo", "chrome://foo/"}, |
263 {"about:version", "", "chrome://version/"}, | 259 {"about:version", "chrome://version/"}, |
264 {"about:usr:pwd@hst/pth?qry#ref", "", "chrome://usr:pwd@hst/pth?qry#ref"}, | 260 {"about:blank", "about:blank"}, |
265 {"about://usr:pwd@hst/pth?qry#ref", "", "chrome://usr:pwd@hst/pth?qry#ref"}, | 261 {"about:usr:pwd@hst/pth?qry#ref", "chrome://usr:pwd@hst/pth?qry#ref"}, |
266 {"chrome:usr:pwd@hst/pth?qry#ref", "", "chrome://usr:pwd@hst/pth?qry#ref"}, | 262 {"about://usr:pwd@hst/pth?qry#ref", "chrome://usr:pwd@hst/pth?qry#ref"}, |
267 {"chrome://usr:pwd@hst/pth?qry#ref", "", "chrome://usr:pwd@hst/pth?qry#ref"}, | 263 {"chrome:usr:pwd@hst/pth?qry#ref", "chrome://usr:pwd@hst/pth?qry#ref"}, |
268 {"www:123", "", "http://www:123/"}, | 264 {"chrome://usr:pwd@hst/pth?qry#ref", "chrome://usr:pwd@hst/pth?qry#ref"}, |
269 {" www:123", "", "http://www:123/"}, | 265 {"www:123", "http://www:123/"}, |
270 {"www.google.com?foo", "", "http://www.google.com/?foo"}, | 266 {" www:123", "http://www:123/"}, |
271 {"www.google.com#foo", "", "http://www.google.com/#foo"}, | 267 {"www.google.com?foo", "http://www.google.com/?foo"}, |
272 {"www.google.com?", "", "http://www.google.com/?"}, | 268 {"www.google.com#foo", "http://www.google.com/#foo"}, |
273 {"www.google.com#", "", "http://www.google.com/#"}, | 269 {"www.google.com?", "http://www.google.com/?"}, |
274 {"www.google.com:123?foo#bar", "", "http://www.google.com:123/?foo#bar"}, | 270 {"www.google.com#", "http://www.google.com/#"}, |
275 {"user@www.google.com", "", "http://user@www.google.com/"}, | 271 {"www.google.com:123?foo#bar", "http://www.google.com:123/?foo#bar"}, |
276 {"\xE6\xB0\xB4.com" , "", "http://xn--1rw.com/"}, | 272 {"user@www.google.com", "http://user@www.google.com/"}, |
| 273 {"\xE6\xB0\xB4.com", "http://xn--1rw.com/"}, |
277 // It would be better if this next case got treated as http, but I don't see | 274 // It would be better if this next case got treated as http, but I don't see |
278 // a clean way to guess this isn't the new-and-exciting "user" scheme. | 275 // a clean way to guess this isn't the new-and-exciting "user" scheme. |
279 {"user:passwd@www.google.com:8080/", "", "user:passwd@www.google.com:8080/"}, | 276 {"user:passwd@www.google.com:8080/", "user:passwd@www.google.com:8080/"}, |
280 // {"file:///c:/foo/bar%20baz.txt", "", "file:///C:/foo/bar%20baz.txt"}, | 277 // {"file:///c:/foo/bar%20baz.txt", "file:///C:/foo/bar%20baz.txt"}, |
281 {"ftp.google.com", "", "ftp://ftp.google.com/"}, | 278 {"ftp.google.com", "ftp://ftp.google.com/"}, |
282 {" ftp.google.com", "", "ftp://ftp.google.com/"}, | 279 {" ftp.google.com", "ftp://ftp.google.com/"}, |
283 {"FTP.GooGle.com", "", "ftp://ftp.google.com/"}, | 280 {"FTP.GooGle.com", "ftp://ftp.google.com/"}, |
284 {"ftpblah.google.com", "", "http://ftpblah.google.com/"}, | 281 {"ftpblah.google.com", "http://ftpblah.google.com/"}, |
285 {"ftp", "", "http://ftp/"}, | 282 {"ftp", "http://ftp/"}, |
286 {"google.ftp.com", "", "http://google.ftp.com/"}, | 283 {"google.ftp.com", "http://google.ftp.com/"}, |
287 // URLs which end with 0x85 (NEL in ISO-8859). | 284 // URLs which end with 0x85 (NEL in ISO-8859). |
288 { "http://google.com/search?q=\xd0\x85", "", | 285 {"http://foo.com/s?q=\xd0\x85", "http://foo.com/s?q=%D0%85"}, |
289 "http://google.com/search?q=%D0%85" | 286 {"http://foo.com/s?q=\xec\x97\x85", "http://foo.com/s?q=%EC%97%85"}, |
290 }, | 287 {"http://foo.com/s?q=\xf0\x90\x80\x85", "http://foo.com/s?q=%F0%90%80%85"}, |
291 { "http://google.com/search?q=\xec\x97\x85", "", | |
292 "http://google.com/search?q=%EC%97%85" | |
293 }, | |
294 { "http://google.com/search?q=\xf0\x90\x80\x85", "", | |
295 "http://google.com/search?q=%F0%90%80%85" | |
296 }, | |
297 // URLs which end with 0xA0 (non-break space in ISO-8859). | 288 // URLs which end with 0xA0 (non-break space in ISO-8859). |
298 { "http://google.com/search?q=\xd0\xa0", "", | 289 {"http://foo.com/s?q=\xd0\xa0", "http://foo.com/s?q=%D0%A0"}, |
299 "http://google.com/search?q=%D0%A0" | 290 {"http://foo.com/s?q=\xec\x97\xa0", "http://foo.com/s?q=%EC%97%A0"}, |
300 }, | 291 {"http://foo.com/s?q=\xf0\x90\x80\xa0", "http://foo.com/s?q=%F0%90%80%A0"}, |
301 { "http://google.com/search?q=\xec\x97\xa0", "", | |
302 "http://google.com/search?q=%EC%97%A0" | |
303 }, | |
304 { "http://google.com/search?q=\xf0\x90\x80\xa0", "", | |
305 "http://google.com/search?q=%F0%90%80%A0" | |
306 }, | |
307 // URLs containing IPv6 literals. | 292 // URLs containing IPv6 literals. |
308 {"[2001:db8::2]", "", "http://[2001:db8::2]/"}, | 293 {"[2001:db8::2]", "http://[2001:db8::2]/"}, |
309 {"[::]:80", "", "http://[::]/"}, | 294 {"[::]:80", "http://[::]/"}, |
310 {"[::]:80/path", "", "http://[::]/path"}, | 295 {"[::]:80/path", "http://[::]/path"}, |
311 {"[::]:180/path", "", "http://[::]:180/path"}, | 296 {"[::]:180/path", "http://[::]:180/path"}, |
312 // TODO(pmarks): Maybe we should parse bare IPv6 literals someday. | 297 // TODO(pmarks): Maybe we should parse bare IPv6 literals someday. |
313 {"::1", "", "::1"}, | 298 {"::1", "::1"}, |
314 // Semicolon as scheme separator for standard schemes. | 299 // Semicolon as scheme separator for standard schemes. |
315 {"http;//www.google.com/", "", "http://www.google.com/"}, | 300 {"http;//www.google.com/", "http://www.google.com/"}, |
316 {"about;chrome", "", "chrome://chrome/"}, | 301 {"about;chrome", "chrome://chrome/"}, |
317 // Semicolon left as-is for non-standard schemes. | 302 // Semicolon left as-is for non-standard schemes. |
318 {"whatsup;//fool", "", "whatsup://fool"}, | 303 {"whatsup;//fool", "whatsup://fool"}, |
319 // Semicolon left as-is in URL itself. | 304 // Semicolon left as-is in URL itself. |
320 {"http://host/port?query;moar", "", "http://host/port?query;moar"}, | 305 {"http://host/port?query;moar", "http://host/port?query;moar"}, |
321 // Fewer slashes than expected. | 306 // Fewer slashes than expected. |
322 {"http;www.google.com/", "", "http://www.google.com/"}, | 307 {"http;www.google.com/", "http://www.google.com/"}, |
323 {"http;/www.google.com/", "", "http://www.google.com/"}, | 308 {"http;/www.google.com/", "http://www.google.com/"}, |
324 // Semicolon at start. | 309 // Semicolon at start. |
325 {";http://www.google.com/", "", "http://%3Bhttp//www.google.com/"}, | 310 {";http://www.google.com/", "http://%3Bhttp//www.google.com/"}, |
326 }; | 311 }; |
327 | 312 |
328 TEST(URLFixerUpperTest, FixupURL) { | 313 TEST(URLFixerUpperTest, FixupURL) { |
329 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { | 314 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { |
330 FixupCase value = fixup_cases[i]; | 315 FixupCase value = fixup_cases[i]; |
331 EXPECT_EQ(value.output, URLFixerUpper::FixupURL(value.input, | 316 EXPECT_EQ(value.output, |
332 value.desired_tld).possibly_invalid_spec()) | 317 URLFixerUpper::FixupURL(value.input, "").possibly_invalid_spec()) |
333 << "input: " << value.input; | 318 << "input: " << value.input; |
334 } | 319 } |
335 | 320 |
336 // Check the TLD-appending functionality | 321 // Check the TLD-appending functionality. |
337 FixupCase tld_cases[] = { | 322 FixupCase tld_cases[] = { |
338 {"google", "com", "http://www.google.com/"}, | 323 {"google", "http://www.google.com/"}, |
339 {"google.", "com", "http://www.google.com/"}, | 324 {"google.", "http://www.google.com/"}, |
340 {"google..", "com", "http://www.google.com/"}, | 325 {"google..", "http://www.google.com/"}, |
341 {".google", "com", "http://www.google.com/"}, | 326 {".google", "http://www.google.com/"}, |
342 {"www.google", "com", "http://www.google.com/"}, | 327 {"www.google", "http://www.google.com/"}, |
343 {"google.com", "com", "http://google.com/"}, | 328 {"google.com", "http://google.com/"}, |
344 {"http://google", "com", "http://www.google.com/"}, | 329 {"http://google", "http://www.google.com/"}, |
345 {"..google..", "com", "http://www.google.com/"}, | 330 {"..google..", "http://www.google.com/"}, |
346 {"http://www.google", "com", "http://www.google.com/"}, | 331 {"http://www.google", "http://www.google.com/"}, |
347 {"9999999999999999", "com", "http://www.9999999999999999.com/"}, | 332 {"9999999999999999", "http://www.9999999999999999.com/"}, |
348 {"google/foo", "com", "http://www.google.com/foo"}, | 333 {"google/foo", "http://www.google.com/foo"}, |
349 {"google.com/foo", "com", "http://google.com/foo"}, | 334 {"google.com/foo", "http://google.com/foo"}, |
350 {"google/?foo=.com", "com", "http://www.google.com/?foo=.com"}, | 335 {"google/?foo=.com", "http://www.google.com/?foo=.com"}, |
351 {"www.google/?foo=www.", "com", "http://www.google.com/?foo=www."}, | 336 {"www.google/?foo=www.", "http://www.google.com/?foo=www."}, |
352 {"google.com/?foo=.com", "com", "http://google.com/?foo=.com"}, | 337 {"google.com/?foo=.com", "http://google.com/?foo=.com"}, |
353 {"http://www.google.com", "com", "http://www.google.com/"}, | 338 {"http://www.google.com", "http://www.google.com/"}, |
354 {"google:123", "com", "http://www.google.com:123/"}, | 339 {"google:123", "http://www.google.com:123/"}, |
355 {"http://google:123", "com", "http://www.google.com:123/"}, | 340 {"http://google:123", "http://www.google.com:123/"}, |
356 }; | 341 }; |
357 for (size_t i = 0; i < arraysize(tld_cases); ++i) { | 342 for (size_t i = 0; i < arraysize(tld_cases); ++i) { |
358 FixupCase value = tld_cases[i]; | 343 FixupCase value = tld_cases[i]; |
359 EXPECT_EQ(value.output, URLFixerUpper::FixupURL(value.input, | 344 EXPECT_EQ(value.output, |
360 value.desired_tld).possibly_invalid_spec()); | 345 URLFixerUpper::FixupURL(value.input, "com").possibly_invalid_spec()); |
361 } | 346 } |
362 } | 347 } |
363 | 348 |
364 // Test different types of file inputs to URIFixerUpper::FixupURL. This | 349 // Test different types of file inputs to URIFixerUpper::FixupURL. This |
365 // doesn't go into the nice array of fixups above since the file input | 350 // doesn't go into the nice array of fixups above since the file input |
366 // has to exist. | 351 // has to exist. |
367 TEST(URLFixerUpperTest, FixupFile) { | 352 TEST(URLFixerUpperTest, FixupFile) { |
368 // this "original" filename is the one we tweak to get all the variations | 353 // this "original" filename is the one we tweak to get all the variations |
369 base::FilePath dir; | 354 base::FilePath dir; |
370 base::FilePath original; | 355 base::FilePath original; |
371 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir)); | 356 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir)); |
372 ASSERT_TRUE(MakeTempFile( | 357 ASSERT_TRUE(MakeTempFile( |
373 dir, | 358 dir, |
374 base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")), | 359 base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")), |
375 &original)); | 360 &original)); |
376 | 361 |
377 // reference path | 362 // reference path |
378 GURL golden(net::FilePathToFileURL(original)); | 363 GURL golden(net::FilePathToFileURL(original)); |
379 | 364 |
380 // c:\foo\bar.txt -> file:///c:/foo/bar.txt (basic) | 365 // c:\foo\bar.txt -> file:///c:/foo/bar.txt (basic) |
381 #if defined(OS_WIN) | 366 GURL fixedup(URLFixerUpper::FixupURL(original.AsUTF8Unsafe(), std::string())); |
382 GURL fixedup(URLFixerUpper::FixupURL(base::WideToUTF8(original.value()), | |
383 std::string())); | |
384 #elif defined(OS_POSIX) | |
385 GURL fixedup(URLFixerUpper::FixupURL(original.value(), std::string())); | |
386 #endif | |
387 EXPECT_EQ(golden, fixedup); | 367 EXPECT_EQ(golden, fixedup); |
388 | 368 |
389 // TODO(port): Make some equivalent tests for posix. | 369 // TODO(port): Make some equivalent tests for posix. |
390 #if defined(OS_WIN) | 370 #if defined(OS_WIN) |
391 // c|/foo\bar.txt -> file:///c:/foo/bar.txt (pipe allowed instead of colon) | 371 // c|/foo\bar.txt -> file:///c:/foo/bar.txt (pipe allowed instead of colon) |
392 std::string cur(base::WideToUTF8(original.value())); | 372 std::string cur(base::WideToUTF8(original.value())); |
393 EXPECT_EQ(':', cur[1]); | 373 EXPECT_EQ(':', cur[1]); |
394 cur[1] = '|'; | 374 cur[1] = '|'; |
395 EXPECT_EQ(golden, URLFixerUpper::FixupURL(cur, std::string())); | 375 EXPECT_EQ(golden, URLFixerUpper::FixupURL(cur, std::string())); |
396 | 376 |
397 FixupCase file_cases[] = { | 377 FixupCase cases[] = { |
398 {"c:\\This%20is a non-existent file.txt", "", | 378 {"c:\\Non-existent%20file.txt", "file:///C:/Non-existent%2520file.txt"}, |
399 "file:///C:/This%2520is%20a%20non-existent%20file.txt"}, | |
400 | 379 |
401 // \\foo\bar.txt -> file://foo/bar.txt | 380 // \\foo\bar.txt -> file://foo/bar.txt |
402 // UNC paths, this file won't exist, but since there are no escapes, it | 381 // UNC paths, this file won't exist, but since there are no escapes, it |
403 // should be returned just converted to a file: URL. | 382 // should be returned just converted to a file: URL. |
404 {"\\\\SomeNonexistentHost\\foo\\bar.txt", "", | 383 {"\\\\NonexistentHost\\foo\\bar.txt", "file://nonexistenthost/foo/bar.txt"}, |
405 "file://somenonexistenthost/foo/bar.txt"}, | |
406 // We do this strictly, like IE8, which only accepts this form using | 384 // We do this strictly, like IE8, which only accepts this form using |
407 // backslashes and not forward ones. Turning "//foo" into "http" matches | 385 // backslashes and not forward ones. Turning "//foo" into "http" matches |
408 // Firefox and IE, silly though it may seem (it falls out of adding "http" | 386 // Firefox and IE, silly though it may seem (it falls out of adding "http" |
409 // as the default protocol if you haven't entered one). | 387 // as the default protocol if you haven't entered one). |
410 {"//SomeNonexistentHost\\foo/bar.txt", "", | 388 {"//NonexistentHost\\foo/bar.txt", "http://nonexistenthost/foo/bar.txt"}, |
411 "http://somenonexistenthost/foo/bar.txt"}, | 389 {"file:///C:/foo/bar", "file:///C:/foo/bar"}, |
412 {"file:///C:/foo/bar", "", "file:///C:/foo/bar"}, | |
413 | 390 |
414 // Much of the work here comes from GURL's canonicalization stage. | 391 // Much of the work here comes from GURL's canonicalization stage. |
415 {"file://C:/foo/bar", "", "file:///C:/foo/bar"}, | 392 {"file://C:/foo/bar", "file:///C:/foo/bar"}, |
416 {"file:c:", "", "file:///C:/"}, | 393 {"file:c:", "file:///C:/"}, |
417 {"file:c:WINDOWS", "", "file:///C:/WINDOWS"}, | 394 {"file:c:WINDOWS", "file:///C:/WINDOWS"}, |
418 {"file:c|Program Files", "", "file:///C:/Program%20Files"}, | 395 {"file:c|Program Files", "file:///C:/Program%20Files"}, |
419 {"file:/file", "", "file://file/"}, | 396 {"file:/file", "file://file/"}, |
420 {"file:////////c:\\foo", "", "file:///C:/foo"}, | 397 {"file:////////c:\\foo", "file:///C:/foo"}, |
421 {"file://server/folder/file", "", "file://server/folder/file"}, | 398 {"file://server/folder/file", "file://server/folder/file"}, |
422 | 399 |
423 // These are fixups we don't do, but could consider: | 400 // These are fixups we don't do, but could consider: |
424 // | 401 // {"file:///foo:/bar", "file://foo/bar"}, |
425 // {"file:///foo:/bar", "", "file://foo/bar"}, | 402 // {"file:/\\/server\\folder/file", "file://server/folder/file"}, |
426 // {"file:/\\/server\\folder/file", "", "file://server/folder/file"}, | |
427 }; | 403 }; |
428 #elif defined(OS_POSIX) | 404 #elif defined(OS_POSIX) |
429 | 405 |
430 #if defined(OS_MACOSX) | 406 #if defined(OS_MACOSX) |
431 #define HOME "/Users/" | 407 #define HOME "/Users/" |
432 #else | 408 #else |
433 #define HOME "/home/" | 409 #define HOME "/home/" |
434 #endif | 410 #endif |
435 URLFixerUpper::home_directory_override = "/foo"; | 411 URLFixerUpper::home_directory_override = "/foo"; |
436 FixupCase file_cases[] = { | 412 FixupCase cases[] = { |
437 // File URLs go through GURL, which tries to escape intelligently. | 413 // File URLs go through GURL, which tries to escape intelligently. |
438 {"/This%20is a non-existent file.txt", "", | 414 {"/A%20non-existent file.txt", "file:///A%2520non-existent%20file.txt"}, |
439 "file:///This%2520is%20a%20non-existent%20file.txt"}, | |
440 // A plain "/" refers to the root. | 415 // A plain "/" refers to the root. |
441 {"/", "", | 416 {"/", "file:///"}, |
442 "file:///"}, | |
443 | 417 |
444 // These rely on the above home_directory_override. | 418 // These rely on the above home_directory_override. |
445 {"~", "", | 419 {"~", "file:///foo"}, |
446 "file:///foo"}, | 420 {"~/bar", "file:///foo/bar"}, |
447 {"~/bar", "", | |
448 "file:///foo/bar"}, | |
449 | 421 |
450 // References to other users' homedirs. | 422 // References to other users' homedirs. |
451 {"~foo", "", | 423 {"~foo", "file://" HOME "foo"}, |
452 "file://" HOME "foo"}, | 424 {"~x/blah", "file://" HOME "x/blah"}, |
453 {"~x/blah", "", | |
454 "file://" HOME "x/blah"}, | |
455 }; | 425 }; |
456 #endif | 426 #endif |
457 for (size_t i = 0; i < arraysize(file_cases); i++) { | 427 |
458 EXPECT_EQ(file_cases[i].output, URLFixerUpper::FixupURL(file_cases[i].input, | 428 for (size_t i = 0; i < arraysize(cases); i++) { |
459 file_cases[i].desired_tld).possibly_invalid_spec()); | 429 EXPECT_EQ(cases[i].output, |
| 430 URLFixerUpper::FixupURL(cases[i].input, "").possibly_invalid_spec()); |
460 } | 431 } |
461 | 432 |
462 EXPECT_TRUE(base::DeleteFile(original, false)); | 433 EXPECT_TRUE(base::DeleteFile(original, false)); |
463 } | 434 } |
464 | 435 |
465 TEST(URLFixerUpperTest, FixupRelativeFile) { | 436 TEST(URLFixerUpperTest, FixupRelativeFile) { |
466 base::FilePath full_path, dir; | 437 base::FilePath full_path, dir; |
467 base::FilePath file_part( | 438 base::FilePath file_part( |
468 FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt")); | 439 FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt")); |
469 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir)); | 440 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 EXPECT_TRUE(base::DeleteFile(full_path, false)); | 501 EXPECT_TRUE(base::DeleteFile(full_path, false)); |
531 EXPECT_TRUE(base::DeleteFile(new_dir, true)); | 502 EXPECT_TRUE(base::DeleteFile(new_dir, true)); |
532 | 503 |
533 // Test that an obvious HTTP URL isn't accidentally treated as an absolute | 504 // Test that an obvious HTTP URL isn't accidentally treated as an absolute |
534 // file path (on account of system-specific craziness). | 505 // file path (on account of system-specific craziness). |
535 base::FilePath empty_path; | 506 base::FilePath empty_path; |
536 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); | 507 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); |
537 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( | 508 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( |
538 empty_path, http_url_path).SchemeIs("http")); | 509 empty_path, http_url_path).SchemeIs("http")); |
539 } | 510 } |
OLD | NEW |