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

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

Issue 13196006: Move path functions from file_util to FilePath object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move AsAbsolute back out of FilePath Created 7 years, 8 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/string_util.h" 10 #include "base/string_util.h"
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 461
462 EXPECT_TRUE(file_util::Delete(original, false)); 462 EXPECT_TRUE(file_util::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 ASSERT_TRUE(file_util::AbsolutePath(&full_path)); 471 full_path = base::MakeAbsoluteFilePath(full_path);
472 ASSERT_FALSE(full_path.empty());
472 473
473 // make sure we pass through good URLs 474 // make sure we pass through good URLs
474 for (size_t i = 0; i < arraysize(fixup_cases); ++i) { 475 for (size_t i = 0; i < arraysize(fixup_cases); ++i) {
475 fixup_case value = fixup_cases[i]; 476 fixup_case value = fixup_cases[i];
476 #if defined(OS_WIN) 477 #if defined(OS_WIN)
477 base::FilePath input(UTF8ToWide(value.input)); 478 base::FilePath input(UTF8ToWide(value.input));
478 #elif defined(OS_POSIX) 479 #elif defined(OS_POSIX)
479 base::FilePath input(value.input); 480 base::FilePath input(value.input);
480 #endif 481 #endif
481 EXPECT_EQ(value.output, 482 EXPECT_EQ(value.output,
(...skipping 17 matching lines...) Expand all
499 500
500 // make a subdir to make sure relative paths with directories work, also 501 // make a subdir to make sure relative paths with directories work, also
501 // test spaces: 502 // test spaces:
502 // "app_dir\url fixer-upper dir\url fixer-upper existing file.txt" 503 // "app_dir\url fixer-upper dir\url fixer-upper existing file.txt"
503 base::FilePath sub_dir(FILE_PATH_LITERAL("url fixer-upper dir")); 504 base::FilePath sub_dir(FILE_PATH_LITERAL("url fixer-upper dir"));
504 base::FilePath sub_file( 505 base::FilePath sub_file(
505 FILE_PATH_LITERAL("url fixer-upper existing file.txt")); 506 FILE_PATH_LITERAL("url fixer-upper existing file.txt"));
506 base::FilePath new_dir = dir.Append(sub_dir); 507 base::FilePath new_dir = dir.Append(sub_dir);
507 file_util::CreateDirectory(new_dir); 508 file_util::CreateDirectory(new_dir);
508 ASSERT_TRUE(MakeTempFile(new_dir, sub_file, &full_path)); 509 ASSERT_TRUE(MakeTempFile(new_dir, sub_file, &full_path));
509 ASSERT_TRUE(file_util::AbsolutePath(&full_path)); 510 full_path = base::MakeAbsoluteFilePath(full_path);
511 ASSERT_FALSE(full_path.empty());
510 512
511 // test file in the subdir 513 // test file in the subdir
512 base::FilePath relative_file = sub_dir.Append(sub_file); 514 base::FilePath relative_file = sub_dir.Append(sub_file);
513 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir, 515 EXPECT_TRUE(IsMatchingFileURL(URLFixerUpper::FixupRelativeFile(dir,
514 relative_file).possibly_invalid_spec(), full_path)); 516 relative_file).possibly_invalid_spec(), full_path));
515 517
516 // test file in the subdir with different slashes and escaping. 518 // test file in the subdir with different slashes and escaping.
517 base::FilePath::StringType relative_file_str = sub_dir.value() + 519 base::FilePath::StringType relative_file_str = sub_dir.value() +
518 FILE_PATH_LITERAL("/") + sub_file.value(); 520 FILE_PATH_LITERAL("/") + sub_file.value();
519 ReplaceSubstringsAfterOffset(&relative_file_str, 0, 521 ReplaceSubstringsAfterOffset(&relative_file_str, 0,
(...skipping 12 matching lines...) Expand all
532 EXPECT_TRUE(file_util::Delete(full_path, false)); 534 EXPECT_TRUE(file_util::Delete(full_path, false));
533 EXPECT_TRUE(file_util::Delete(new_dir, true)); 535 EXPECT_TRUE(file_util::Delete(new_dir, true));
534 536
535 // Test that an obvious HTTP URL isn't accidentally treated as an absolute 537 // Test that an obvious HTTP URL isn't accidentally treated as an absolute
536 // file path (on account of system-specific craziness). 538 // file path (on account of system-specific craziness).
537 base::FilePath empty_path; 539 base::FilePath empty_path;
538 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); 540 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../"));
539 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( 541 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile(
540 empty_path, http_url_path).SchemeIs("http")); 542 empty_path, http_url_path).SchemeIs("http"));
541 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698