| 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/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 TEST(URLFixerTest, FixupURL) { | 315 TEST(URLFixerTest, FixupURL) { |
| 316 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { | 316 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { |
| 317 FixupCase value = fixup_cases[i]; | 317 FixupCase value = fixup_cases[i]; |
| 318 EXPECT_EQ(value.output, | 318 EXPECT_EQ(value.output, |
| 319 url_fixer::FixupURL(value.input, "").possibly_invalid_spec()) | 319 url_fixer::FixupURL(value.input, "").possibly_invalid_spec()) |
| 320 << "input: " << value.input; | 320 << "input: " << value.input; |
| 321 } | 321 } |
| 322 | 322 |
| 323 // Check the TLD-appending functionality. | 323 // Check the TLD-appending functionality. |
| 324 FixupCase tld_cases[] = { | 324 FixupCase tld_cases[] = { |
| 325 {"google", "http://www.google.com/"}, | 325 {"somedomainthatwillnotbeagtld", |
| 326 {"google.", "http://www.google.com/"}, | 326 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 327 {"google..", "http://www.google.com/"}, | 327 {"somedomainthatwillnotbeagtld.", |
| 328 {".google", "http://www.google.com/"}, | 328 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 329 {"www.google", "http://www.google.com/"}, | 329 {"somedomainthatwillnotbeagtld..", |
| 330 {"google.com", "http://google.com/"}, | 330 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 331 {"http://google", "http://www.google.com/"}, | 331 {".somedomainthatwillnotbeagtld", |
| 332 {"..google..", "http://www.google.com/"}, | 332 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 333 {"http://www.google", "http://www.google.com/"}, | 333 {"www.somedomainthatwillnotbeagtld", |
| 334 {"9999999999999999", "http://www.9999999999999999.com/"}, | 334 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 335 {"google/foo", "http://www.google.com/foo"}, | 335 {"somedomainthatwillnotbeagtld.com", |
| 336 {"google.com/foo", "http://google.com/foo"}, | 336 "http://somedomainthatwillnotbeagtld.com/"}, |
| 337 {"google/?foo=.com", "http://www.google.com/?foo=.com"}, | 337 {"http://somedomainthatwillnotbeagtld", |
| 338 {"www.google/?foo=www.", "http://www.google.com/?foo=www."}, | 338 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 339 {"google.com/?foo=.com", "http://google.com/?foo=.com"}, | 339 {"..somedomainthatwillnotbeagtld..", |
| 340 {"http://www.google.com", "http://www.google.com/"}, | 340 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 341 {"google:123", "http://www.google.com:123/"}, | 341 {"http://www.somedomainthatwillnotbeagtld", |
| 342 {"http://google:123", "http://www.google.com:123/"}, | 342 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 343 {"9999999999999999", "http://www.9999999999999999.com/"}, |
| 344 {"somedomainthatwillnotbeagtld/foo", |
| 345 "http://www.somedomainthatwillnotbeagtld.com/foo"}, |
| 346 {"somedomainthatwillnotbeagtld.com/foo", |
| 347 "http://somedomainthatwillnotbeagtld.com/foo"}, |
| 348 {"somedomainthatwillnotbeagtld/?foo=.com", |
| 349 "http://www.somedomainthatwillnotbeagtld.com/?foo=.com"}, |
| 350 {"www.somedomainthatwillnotbeagtld/?foo=www.", |
| 351 "http://www.somedomainthatwillnotbeagtld.com/?foo=www."}, |
| 352 {"somedomainthatwillnotbeagtld.com/?foo=.com", |
| 353 "http://somedomainthatwillnotbeagtld.com/?foo=.com"}, |
| 354 {"http://www.somedomainthatwillnotbeagtld.com", |
| 355 "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 356 {"somedomainthatwillnotbeagtld:123", |
| 357 "http://www.somedomainthatwillnotbeagtld.com:123/"}, |
| 358 {"http://somedomainthatwillnotbeagtld:123", |
| 359 "http://www.somedomainthatwillnotbeagtld.com:123/"}, |
| 343 }; | 360 }; |
| 344 for (size_t i = 0; i < arraysize(tld_cases); ++i) { | 361 for (size_t i = 0; i < arraysize(tld_cases); ++i) { |
| 345 FixupCase value = tld_cases[i]; | 362 FixupCase value = tld_cases[i]; |
| 346 EXPECT_EQ(value.output, | 363 EXPECT_EQ(value.output, |
| 347 url_fixer::FixupURL(value.input, "com").possibly_invalid_spec()); | 364 url_fixer::FixupURL(value.input, "com").possibly_invalid_spec()); |
| 348 } | 365 } |
| 349 } | 366 } |
| 350 | 367 |
| 351 // Test different types of file inputs to URIFixerUpper::FixupURL. This | 368 // Test different types of file inputs to URIFixerUpper::FixupURL. This |
| 352 // doesn't go into the nice array of fixups above since the file input | 369 // doesn't go into the nice array of fixups above since the file input |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 EXPECT_TRUE(base::DeleteFile(full_path, false)); | 528 EXPECT_TRUE(base::DeleteFile(full_path, false)); |
| 512 EXPECT_TRUE(base::DeleteFile(new_dir, true)); | 529 EXPECT_TRUE(base::DeleteFile(new_dir, true)); |
| 513 | 530 |
| 514 // Test that an obvious HTTP URL isn't accidentally treated as an absolute | 531 // Test that an obvious HTTP URL isn't accidentally treated as an absolute |
| 515 // file path (on account of system-specific craziness). | 532 // file path (on account of system-specific craziness). |
| 516 base::FilePath empty_path; | 533 base::FilePath empty_path; |
| 517 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); | 534 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); |
| 518 EXPECT_TRUE( | 535 EXPECT_TRUE( |
| 519 url_fixer::FixupRelativeFile(empty_path, http_url_path).SchemeIs("http")); | 536 url_fixer::FixupRelativeFile(empty_path, http_url_path).SchemeIs("http")); |
| 520 } | 537 } |
| OLD | NEW |