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

Side by Side Diff: chrome/browser/net/url_fixer_upper_unittest.cc

Issue 16950028: Move file_util::Delete to the base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months 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 | Annotate | Revision Log
OLDNEW
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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 "file://" HOME "foo"}, 452 "file://" HOME "foo"},
453 {"~x/blah", "", 453 {"~x/blah", "",
454 "file://" HOME "x/blah"}, 454 "file://" HOME "x/blah"},
455 }; 455 };
456 #endif 456 #endif
457 for (size_t i = 0; i < arraysize(file_cases); i++) { 457 for (size_t i = 0; i < arraysize(file_cases); i++) {
458 EXPECT_EQ(file_cases[i].output, URLFixerUpper::FixupURL(file_cases[i].input, 458 EXPECT_EQ(file_cases[i].output, URLFixerUpper::FixupURL(file_cases[i].input,
459 file_cases[i].desired_tld).possibly_invalid_spec()); 459 file_cases[i].desired_tld).possibly_invalid_spec());
460 } 460 }
461 461
462 EXPECT_TRUE(file_util::Delete(original, false)); 462 EXPECT_TRUE(base::Delete(original, false));
463 } 463 }
464 464
465 TEST(URLFixerUpperTest, FixupRelativeFile) { 465 TEST(URLFixerUpperTest, FixupRelativeFile) {
466 base::FilePath full_path, dir; 466 base::FilePath full_path, dir;
467 base::FilePath file_part( 467 base::FilePath file_part(
468 FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt")); 468 FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt"));
469 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir)); 469 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir));
470 ASSERT_TRUE(MakeTempFile(dir, file_part, &full_path)); 470 ASSERT_TRUE(MakeTempFile(dir, file_part, &full_path));
471 full_path = base::MakeAbsoluteFilePath(full_path); 471 full_path = base::MakeAbsoluteFilePath(full_path);
472 ASSERT_FALSE(full_path.empty()); 472 ASSERT_FALSE(full_path.empty());
473 473
474 // make sure we pass through good URLs 474 // make sure we pass through good URLs
475 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { 475 for (size_t i = 0; i < arraysize(fixup_cases); ++i) {
476 FixupCase value = fixup_cases[i]; 476 FixupCase value = fixup_cases[i];
477 base::FilePath input = base::FilePath::FromUTF8Unsafe(value.input); 477 base::FilePath input = base::FilePath::FromUTF8Unsafe(value.input);
478 EXPECT_EQ(value.output, 478 EXPECT_EQ(value.output,
479 URLFixerUpper::FixupRelativeFile(dir, input).possibly_invalid_spec()); 479 URLFixerUpper::FixupRelativeFile(dir, input).possibly_invalid_spec());
480 } 480 }
481 481
482 // make sure the existing file got fixed-up to a file URL, and that there 482 // make sure the existing file got fixed-up to a file URL, and that there
483 // are no backslashes 483 // are no backslashes
484 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir, 484 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir,
485 file_part).possibly_invalid_spec(), full_path)); 485 file_part).possibly_invalid_spec(), full_path));
486 EXPECT_TRUE(file_util::Delete(full_path, false)); 486 EXPECT_TRUE(base::Delete(full_path, false));
487 487
488 // create a filename we know doesn't exist and make sure it doesn't get 488 // create a filename we know doesn't exist and make sure it doesn't get
489 // fixed up to a file URL 489 // fixed up to a file URL
490 base::FilePath nonexistent_file( 490 base::FilePath nonexistent_file(
491 FILE_PATH_LITERAL("url_fixer_upper_nonexistent_file.txt")); 491 FILE_PATH_LITERAL("url_fixer_upper_nonexistent_file.txt"));
492 std::string fixedup(URLFixerUpper::FixupRelativeFile(dir, 492 std::string fixedup(URLFixerUpper::FixupRelativeFile(dir,
493 nonexistent_file).possibly_invalid_spec()); 493 nonexistent_file).possibly_invalid_spec());
494 EXPECT_NE(std::string("file:///"), fixedup.substr(0, 8)); 494 EXPECT_NE(std::string("file:///"), fixedup.substr(0, 8));
495 EXPECT_FALSE(IsMatchingFileURL(fixedup, nonexistent_file)); 495 EXPECT_FALSE(IsMatchingFileURL(fixedup, nonexistent_file));
496 496
(...skipping 23 matching lines...) Expand all
520 base::FilePath(relative_file_str)).possibly_invalid_spec(), full_path)); 520 base::FilePath(relative_file_str)).possibly_invalid_spec(), full_path));
521 521
522 // test relative directories and duplicate slashes 522 // test relative directories and duplicate slashes
523 // (should resolve to the same file as above) 523 // (should resolve to the same file as above)
524 relative_file_str = sub_dir.value() + FILE_PATH_LITERAL("/../") + 524 relative_file_str = sub_dir.value() + FILE_PATH_LITERAL("/../") +
525 sub_dir.value() + FILE_PATH_LITERAL("///./") + sub_file.value(); 525 sub_dir.value() + FILE_PATH_LITERAL("///./") + sub_file.value();
526 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir, 526 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir,
527 base::FilePath(relative_file_str)).possibly_invalid_spec(), full_path)); 527 base::FilePath(relative_file_str)).possibly_invalid_spec(), full_path));
528 528
529 // done with the subdir 529 // done with the subdir
530 EXPECT_TRUE(file_util::Delete(full_path, false)); 530 EXPECT_TRUE(base::Delete(full_path, false));
531 EXPECT_TRUE(file_util::Delete(new_dir, true)); 531 EXPECT_TRUE(base::Delete(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 }
OLDNEW
« no previous file with comments | « chrome/browser/net/net_log_temp_file_unittest.cc ('k') | chrome/browser/page_cycler/page_cycler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698