| 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" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 ASSERT_TRUE(MakeTempFile( | 372 ASSERT_TRUE(MakeTempFile( |
| 373 dir, | 373 dir, |
| 374 base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")), | 374 base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")), |
| 375 &original)); | 375 &original)); |
| 376 | 376 |
| 377 // reference path | 377 // reference path |
| 378 GURL golden(net::FilePathToFileURL(original)); | 378 GURL golden(net::FilePathToFileURL(original)); |
| 379 | 379 |
| 380 // c:\foo\bar.txt -> file:///c:/foo/bar.txt (basic) | 380 // c:\foo\bar.txt -> file:///c:/foo/bar.txt (basic) |
| 381 #if defined(OS_WIN) | 381 #if defined(OS_WIN) |
| 382 GURL fixedup(URLFixerUpper::FixupURL(WideToUTF8(original.value()), | 382 GURL fixedup(URLFixerUpper::FixupURL(base::WideToUTF8(original.value()), |
| 383 std::string())); | 383 std::string())); |
| 384 #elif defined(OS_POSIX) | 384 #elif defined(OS_POSIX) |
| 385 GURL fixedup(URLFixerUpper::FixupURL(original.value(), std::string())); | 385 GURL fixedup(URLFixerUpper::FixupURL(original.value(), std::string())); |
| 386 #endif | 386 #endif |
| 387 EXPECT_EQ(golden, fixedup); | 387 EXPECT_EQ(golden, fixedup); |
| 388 | 388 |
| 389 // TODO(port): Make some equivalent tests for posix. | 389 // TODO(port): Make some equivalent tests for posix. |
| 390 #if defined(OS_WIN) | 390 #if defined(OS_WIN) |
| 391 // c|/foo\bar.txt -> file:///c:/foo/bar.txt (pipe allowed instead of colon) | 391 // c|/foo\bar.txt -> file:///c:/foo/bar.txt (pipe allowed instead of colon) |
| 392 std::string cur(WideToUTF8(original.value())); | 392 std::string cur(base::WideToUTF8(original.value())); |
| 393 EXPECT_EQ(':', cur[1]); | 393 EXPECT_EQ(':', cur[1]); |
| 394 cur[1] = '|'; | 394 cur[1] = '|'; |
| 395 EXPECT_EQ(golden, URLFixerUpper::FixupURL(cur, std::string())); | 395 EXPECT_EQ(golden, URLFixerUpper::FixupURL(cur, std::string())); |
| 396 | 396 |
| 397 FixupCase file_cases[] = { | 397 FixupCase file_cases[] = { |
| 398 {"c:\\This%20is a non-existent file.txt", "", | 398 {"c:\\This%20is a non-existent file.txt", "", |
| 399 "file:///C:/This%2520is%20a%20non-existent%20file.txt"}, | 399 "file:///C:/This%2520is%20a%20non-existent%20file.txt"}, |
| 400 | 400 |
| 401 // \\foo\bar.txt -> file://foo/bar.txt | 401 // \\foo\bar.txt -> file://foo/bar.txt |
| 402 // UNC paths, this file won't exist, but since there are no escapes, it | 402 // UNC paths, this file won't exist, but since there are no escapes, it |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 EXPECT_TRUE(base::DeleteFile(full_path, false)); | 530 EXPECT_TRUE(base::DeleteFile(full_path, false)); |
| 531 EXPECT_TRUE(base::DeleteFile(new_dir, true)); | 531 EXPECT_TRUE(base::DeleteFile(new_dir, true)); |
| 532 | 532 |
| 533 // Test that an obvious HTTP URL isn't accidentally treated as an absolute | 533 // Test that an obvious HTTP URL isn't accidentally treated as an absolute |
| 534 // file path (on account of system-specific craziness). | 534 // file path (on account of system-specific craziness). |
| 535 base::FilePath empty_path; | 535 base::FilePath empty_path; |
| 536 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); | 536 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); |
| 537 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( | 537 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( |
| 538 empty_path, http_url_path).SchemeIs("http")); | 538 empty_path, http_url_path).SchemeIs("http")); |
| 539 } | 539 } |
| OLD | NEW |