| 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/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 ASSERT_TRUE(MakeTempFile( | 359 ASSERT_TRUE(MakeTempFile( |
| 360 dir, | 360 dir, |
| 361 base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")), | 361 base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")), |
| 362 &original)); | 362 &original)); |
| 363 | 363 |
| 364 // reference path | 364 // reference path |
| 365 GURL golden(net::FilePathToFileURL(original)); | 365 GURL golden(net::FilePathToFileURL(original)); |
| 366 | 366 |
| 367 // c:\foo\bar.txt -> file:///c:/foo/bar.txt (basic) | 367 // c:\foo\bar.txt -> file:///c:/foo/bar.txt (basic) |
| 368 #if defined(OS_WIN) | 368 #if defined(OS_WIN) |
| 369 GURL fixedup(URLFixerUpper::FixupURL(WideToUTF8(original.value()), | 369 GURL fixedup(URLFixerUpper::FixupURL(base::WideToUTF8(original.value()), |
| 370 std::string())); | 370 std::string())); |
| 371 #elif defined(OS_POSIX) | 371 #elif defined(OS_POSIX) |
| 372 GURL fixedup(URLFixerUpper::FixupURL(original.value(), std::string())); | 372 GURL fixedup(URLFixerUpper::FixupURL(original.value(), std::string())); |
| 373 #endif | 373 #endif |
| 374 EXPECT_EQ(golden, fixedup); | 374 EXPECT_EQ(golden, fixedup); |
| 375 | 375 |
| 376 // TODO(port): Make some equivalent tests for posix. | 376 // TODO(port): Make some equivalent tests for posix. |
| 377 #if defined(OS_WIN) | 377 #if defined(OS_WIN) |
| 378 // c|/foo\bar.txt -> file:///c:/foo/bar.txt (pipe allowed instead of colon) | 378 // c|/foo\bar.txt -> file:///c:/foo/bar.txt (pipe allowed instead of colon) |
| 379 std::string cur(WideToUTF8(original.value())); | 379 std::string cur(base::WideToUTF8(original.value())); |
| 380 EXPECT_EQ(':', cur[1]); | 380 EXPECT_EQ(':', cur[1]); |
| 381 cur[1] = '|'; | 381 cur[1] = '|'; |
| 382 EXPECT_EQ(golden, URLFixerUpper::FixupURL(cur, std::string())); | 382 EXPECT_EQ(golden, URLFixerUpper::FixupURL(cur, std::string())); |
| 383 | 383 |
| 384 fixup_case file_cases[] = { | 384 fixup_case file_cases[] = { |
| 385 {"c:\\This%20is a non-existent file.txt", "", | 385 {"c:\\This%20is a non-existent file.txt", "", |
| 386 "file:///C:/This%2520is%20a%20non-existent%20file.txt"}, | 386 "file:///C:/This%2520is%20a%20non-existent%20file.txt"}, |
| 387 | 387 |
| 388 // \\foo\bar.txt -> file://foo/bar.txt | 388 // \\foo\bar.txt -> file://foo/bar.txt |
| 389 // UNC paths, this file won't exist, but since there are no escapes, it | 389 // UNC paths, this file won't exist, but since there are no escapes, it |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 base::FilePath file_part( | 454 base::FilePath file_part( |
| 455 FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt")); | 455 FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt")); |
| 456 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir)); | 456 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir)); |
| 457 ASSERT_TRUE(MakeTempFile(dir, file_part, &full_path)); | 457 ASSERT_TRUE(MakeTempFile(dir, file_part, &full_path)); |
| 458 ASSERT_TRUE(file_util::AbsolutePath(&full_path)); | 458 ASSERT_TRUE(file_util::AbsolutePath(&full_path)); |
| 459 | 459 |
| 460 // make sure we pass through good URLs | 460 // make sure we pass through good URLs |
| 461 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { | 461 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { |
| 462 fixup_case value = fixup_cases[i]; | 462 fixup_case value = fixup_cases[i]; |
| 463 #if defined(OS_WIN) | 463 #if defined(OS_WIN) |
| 464 base::FilePath input(UTF8ToWide(value.input)); | 464 base::FilePath input(base::UTF8ToWide(value.input)); |
| 465 #elif defined(OS_POSIX) | 465 #elif defined(OS_POSIX) |
| 466 base::FilePath input(value.input); | 466 base::FilePath input(value.input); |
| 467 #endif | 467 #endif |
| 468 EXPECT_EQ(value.output, | 468 EXPECT_EQ(value.output, |
| 469 URLFixerUpper::FixupRelativeFile(dir, input).possibly_invalid_spec()); | 469 URLFixerUpper::FixupRelativeFile(dir, input).possibly_invalid_spec()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 // make sure the existing file got fixed-up to a file URL, and that there | 472 // make sure the existing file got fixed-up to a file URL, and that there |
| 473 // are no backslashes | 473 // are no backslashes |
| 474 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir, | 474 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 EXPECT_TRUE(file_util::Delete(full_path, false)); | 519 EXPECT_TRUE(file_util::Delete(full_path, false)); |
| 520 EXPECT_TRUE(file_util::Delete(new_dir, true)); | 520 EXPECT_TRUE(file_util::Delete(new_dir, true)); |
| 521 | 521 |
| 522 // Test that an obvious HTTP URL isn't accidentally treated as an absolute | 522 // Test that an obvious HTTP URL isn't accidentally treated as an absolute |
| 523 // file path (on account of system-specific craziness). | 523 // file path (on account of system-specific craziness). |
| 524 base::FilePath empty_path; | 524 base::FilePath empty_path; |
| 525 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); | 525 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); |
| 526 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( | 526 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( |
| 527 empty_path, http_url_path).SchemeIs("http")); | 527 empty_path, http_url_path).SchemeIs("http")); |
| 528 } | 528 } |
| OLD | NEW |