| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 bool DeleteReparsePoint(HANDLE source) { | 109 bool DeleteReparsePoint(HANDLE source) { |
| 110 DWORD returned; | 110 DWORD returned; |
| 111 REPARSE_DATA_BUFFER data = {0}; | 111 REPARSE_DATA_BUFFER data = {0}; |
| 112 data.ReparseTag = 0xa0000003; | 112 data.ReparseTag = 0xa0000003; |
| 113 if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, | 113 if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, |
| 114 &returned, NULL)) { | 114 &returned, NULL)) { |
| 115 return false; | 115 return false; |
| 116 } | 116 } |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | |
| 120 // Manages a reparse point for a test. | |
| 121 class ReparsePoint { | |
| 122 public: | |
| 123 // Creates a reparse point from |source| (an empty directory) to |target|. | |
| 124 ReparsePoint(const FilePath& source, const FilePath& target) { | |
| 125 dir_.Set( | |
| 126 ::CreateFile(source.value().c_str(), | |
| 127 FILE_ALL_ACCESS, | |
| 128 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | |
| 129 NULL, | |
| 130 OPEN_EXISTING, | |
| 131 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | |
| 132 NULL)); | |
| 133 created_ = dir_.IsValid() && SetReparsePoint(dir_, target); | |
| 134 } | |
| 135 | |
| 136 ~ReparsePoint() { | |
| 137 if (created_) | |
| 138 DeleteReparsePoint(dir_); | |
| 139 } | |
| 140 | |
| 141 bool IsValid() { return created_; } | |
| 142 | |
| 143 private: | |
| 144 base::win::ScopedHandle dir_; | |
| 145 bool created_; | |
| 146 DISALLOW_COPY_AND_ASSIGN(ReparsePoint); | |
| 147 }; | |
| 148 | |
| 149 #endif | 119 #endif |
| 150 | 120 |
| 151 #if defined(OS_POSIX) | 121 #if defined(OS_POSIX) |
| 152 // Provide a simple way to change the permissions bits on |path| in tests. | 122 // Provide a simple way to change the permissions bits on |path| in tests. |
| 153 // ASSERT failures will return, but not stop the test. Caller should wrap | 123 // ASSERT failures will return, but not stop the test. Caller should wrap |
| 154 // calls to this function in ASSERT_NO_FATAL_FAILURE(). | 124 // calls to this function in ASSERT_NO_FATAL_FAILURE(). |
| 155 void ChangePosixFilePermissions(const FilePath& path, | 125 void ChangePosixFilePermissions(const FilePath& path, |
| 156 int mode_bits_to_set, | 126 int mode_bits_to_set, |
| 157 int mode_bits_to_clear) { | 127 int mode_bits_to_clear) { |
| 158 ASSERT_FALSE(mode_bits_to_set & mode_bits_to_clear) | 128 ASSERT_FALSE(mode_bits_to_set & mode_bits_to_clear) |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 424 |
| 455 FilePath sub_long = deep_file.DirName(); | 425 FilePath sub_long = deep_file.DirName(); |
| 456 ASSERT_TRUE(file_util::CreateDirectory(sub_long)); | 426 ASSERT_TRUE(file_util::CreateDirectory(sub_long)); |
| 457 CreateTextFile(deep_file, bogus_content); | 427 CreateTextFile(deep_file, bogus_content); |
| 458 | 428 |
| 459 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); | 429 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); |
| 460 ASSERT_TRUE(file_util::CreateDirectory(base_b)); | 430 ASSERT_TRUE(file_util::CreateDirectory(base_b)); |
| 461 | 431 |
| 462 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); | 432 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); |
| 463 ASSERT_TRUE(file_util::CreateDirectory(to_sub_a)); | 433 ASSERT_TRUE(file_util::CreateDirectory(to_sub_a)); |
| 434 base::win::ScopedHandle reparse_to_sub_a( |
| 435 ::CreateFile(to_sub_a.value().c_str(), |
| 436 FILE_ALL_ACCESS, |
| 437 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 438 NULL, |
| 439 OPEN_EXISTING, |
| 440 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
| 441 NULL)); |
| 442 ASSERT_TRUE(reparse_to_sub_a.IsValid()); |
| 443 ASSERT_TRUE(SetReparsePoint(reparse_to_sub_a, sub_a)); |
| 444 |
| 445 FilePath to_base_b = base_b.Append(FPL("to_base_b")); |
| 446 ASSERT_TRUE(file_util::CreateDirectory(to_base_b)); |
| 447 base::win::ScopedHandle reparse_to_base_b( |
| 448 ::CreateFile(to_base_b.value().c_str(), |
| 449 FILE_ALL_ACCESS, |
| 450 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 451 NULL, |
| 452 OPEN_EXISTING, |
| 453 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
| 454 NULL)); |
| 455 ASSERT_TRUE(reparse_to_base_b.IsValid()); |
| 456 ASSERT_TRUE(SetReparsePoint(reparse_to_base_b, base_b)); |
| 457 |
| 458 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); |
| 459 ASSERT_TRUE(file_util::CreateDirectory(to_sub_long)); |
| 460 base::win::ScopedHandle reparse_to_sub_long( |
| 461 ::CreateFile(to_sub_long.value().c_str(), |
| 462 FILE_ALL_ACCESS, |
| 463 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 464 NULL, |
| 465 OPEN_EXISTING, |
| 466 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
| 467 NULL)); |
| 468 ASSERT_TRUE(reparse_to_sub_long.IsValid()); |
| 469 ASSERT_TRUE(SetReparsePoint(reparse_to_sub_long, sub_long)); |
| 470 |
| 471 // Normalize a junction free path: base_a\sub_a\file.txt . |
| 464 FilePath normalized_path; | 472 FilePath normalized_path; |
| 465 { | 473 ASSERT_TRUE(file_util::NormalizeFilePath(file_txt, &normalized_path)); |
| 466 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); | 474 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); |
| 467 ASSERT_TRUE(reparse_to_sub_a.IsValid()); | |
| 468 | 475 |
| 469 FilePath to_base_b = base_b.Append(FPL("to_base_b")); | 476 // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude |
| 470 ASSERT_TRUE(file_util::CreateDirectory(to_base_b)); | 477 // the junction to_sub_a. |
| 471 ReparsePoint reparse_to_base_b(to_base_b, base_b); | 478 ASSERT_TRUE(file_util::NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), |
| 472 ASSERT_TRUE(reparse_to_base_b.IsValid()); | 479 &normalized_path)); |
| 480 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); |
| 473 | 481 |
| 474 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); | 482 // Check that the path base_b\to_base_b\to_base_b\to_sub_a\file.txt can be |
| 475 ASSERT_TRUE(file_util::CreateDirectory(to_sub_long)); | 483 // normalized to exclude junctions to_base_b and to_sub_a . |
| 476 ReparsePoint reparse_to_sub_long(to_sub_long, sub_long); | 484 ASSERT_TRUE(file_util::NormalizeFilePath(base_b.Append(FPL("to_base_b")) |
| 477 ASSERT_TRUE(reparse_to_sub_long.IsValid()); | 485 .Append(FPL("to_base_b")) |
| 486 .Append(FPL("to_sub_a")) |
| 487 .Append(FPL("file.txt")), |
| 488 &normalized_path)); |
| 489 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); |
| 478 | 490 |
| 479 // Normalize a junction free path: base_a\sub_a\file.txt . | 491 // A long enough path will cause NormalizeFilePath() to fail. Make a long |
| 480 ASSERT_TRUE(file_util::NormalizeFilePath(file_txt, &normalized_path)); | 492 // path using to_base_b many times, and check that paths long enough to fail |
| 481 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); | 493 // do not cause a crash. |
| 494 FilePath long_path = base_b; |
| 495 const int kLengthLimit = MAX_PATH + 200; |
| 496 while (long_path.value().length() <= kLengthLimit) { |
| 497 long_path = long_path.Append(FPL("to_base_b")); |
| 498 } |
| 499 long_path = long_path.Append(FPL("to_sub_a")) |
| 500 .Append(FPL("file.txt")); |
| 482 | 501 |
| 483 // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude | 502 ASSERT_FALSE(file_util::NormalizeFilePath(long_path, &normalized_path)); |
| 484 // the junction to_sub_a. | |
| 485 ASSERT_TRUE(file_util::NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), | |
| 486 &normalized_path)); | |
| 487 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); | |
| 488 | 503 |
| 489 // Check that the path base_b\to_base_b\to_base_b\to_sub_a\file.txt can be | 504 // Normalizing the junction to deep.txt should fail, because the expanded |
| 490 // normalized to exclude junctions to_base_b and to_sub_a . | 505 // path to deep.txt is longer than MAX_PATH. |
| 491 ASSERT_TRUE(file_util::NormalizeFilePath(base_b.Append(FPL("to_base_b")) | 506 ASSERT_FALSE(file_util::NormalizeFilePath(to_sub_long.Append(deep_txt), |
| 492 .Append(FPL("to_base_b")) | 507 &normalized_path)); |
| 493 .Append(FPL("to_sub_a")) | |
| 494 .Append(FPL("file.txt")), | |
| 495 &normalized_path)); | |
| 496 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); | |
| 497 | 508 |
| 498 // A long enough path will cause NormalizeFilePath() to fail. Make a long | 509 // Delete the reparse points, and see that NormalizeFilePath() fails |
| 499 // path using to_base_b many times, and check that paths long enough to fail | 510 // to traverse them. |
| 500 // do not cause a crash. | 511 ASSERT_TRUE(DeleteReparsePoint(reparse_to_sub_a)); |
| 501 FilePath long_path = base_b; | 512 ASSERT_TRUE(DeleteReparsePoint(reparse_to_base_b)); |
| 502 const int kLengthLimit = MAX_PATH + 200; | 513 ASSERT_TRUE(DeleteReparsePoint(reparse_to_sub_long)); |
| 503 while (long_path.value().length() <= kLengthLimit) { | |
| 504 long_path = long_path.Append(FPL("to_base_b")); | |
| 505 } | |
| 506 long_path = long_path.Append(FPL("to_sub_a")) | |
| 507 .Append(FPL("file.txt")); | |
| 508 | |
| 509 ASSERT_FALSE(file_util::NormalizeFilePath(long_path, &normalized_path)); | |
| 510 | |
| 511 // Normalizing the junction to deep.txt should fail, because the expanded | |
| 512 // path to deep.txt is longer than MAX_PATH. | |
| 513 ASSERT_FALSE(file_util::NormalizeFilePath(to_sub_long.Append(deep_txt), | |
| 514 &normalized_path)); | |
| 515 | |
| 516 // Delete the reparse points, and see that NormalizeFilePath() fails | |
| 517 // to traverse them. | |
| 518 } | |
| 519 | 514 |
| 520 ASSERT_FALSE(file_util::NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), | 515 ASSERT_FALSE(file_util::NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), |
| 521 &normalized_path)); | 516 &normalized_path)); |
| 522 } | 517 } |
| 523 | 518 |
| 524 TEST_F(FileUtilTest, DevicePathToDriveLetter) { | 519 TEST_F(FileUtilTest, DevicePathToDriveLetter) { |
| 525 // Get a drive letter. | 520 // Get a drive letter. |
| 526 std::wstring real_drive_letter = temp_dir_.path().value().substr(0, 2); | 521 std::wstring real_drive_letter = temp_dir_.path().value().substr(0, 2); |
| 527 if (!isalpha(real_drive_letter[0]) || ':' != real_drive_letter[1]) { | 522 if (!isalpha(real_drive_letter[0]) || ':' != real_drive_letter[1]) { |
| 528 LOG(ERROR) << "Can't get a drive letter to test with."; | 523 LOG(ERROR) << "Can't get a drive letter to test with."; |
| (...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 EXPECT_TRUE(base::PathExists(test_path)); | 1814 EXPECT_TRUE(base::PathExists(test_path)); |
| 1820 EXPECT_FALSE(DirectoryExists(test_path)); | 1815 EXPECT_FALSE(DirectoryExists(test_path)); |
| 1821 EXPECT_TRUE(base::DeleteFile(test_path, false)); | 1816 EXPECT_TRUE(base::DeleteFile(test_path, false)); |
| 1822 | 1817 |
| 1823 EXPECT_TRUE(base::DeleteFile(test_root, true)); | 1818 EXPECT_TRUE(base::DeleteFile(test_root, true)); |
| 1824 } | 1819 } |
| 1825 | 1820 |
| 1826 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1821 TEST_F(FileUtilTest, FileEnumeratorTest) { |
| 1827 // Test an empty directory. | 1822 // Test an empty directory. |
| 1828 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1823 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
| 1829 EXPECT_EQ(f0.Next().value(), FPL("")); | 1824 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
| 1830 EXPECT_EQ(f0.Next().value(), FPL("")); | 1825 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
| 1831 | 1826 |
| 1832 // Test an empty directory, non-recursively, including "..". | 1827 // Test an empty directory, non-recursively, including "..". |
| 1833 FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1828 FileEnumerator f0_dotdot(temp_dir_.path(), false, |
| 1834 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); | 1829 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); |
| 1835 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), | 1830 EXPECT_EQ(temp_dir_.path().Append(FILE_PATH_LITERAL("..")).value(), |
| 1836 f0_dotdot.Next().value()); | 1831 f0_dotdot.Next().value()); |
| 1837 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); | 1832 EXPECT_EQ(FILE_PATH_LITERAL(""), |
| 1833 f0_dotdot.Next().value()); |
| 1838 | 1834 |
| 1839 // create the directories | 1835 // create the directories |
| 1840 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); | 1836 FilePath dir1 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir1")); |
| 1841 EXPECT_TRUE(file_util::CreateDirectory(dir1)); | 1837 EXPECT_TRUE(file_util::CreateDirectory(dir1)); |
| 1842 FilePath dir2 = temp_dir_.path().Append(FPL("dir2")); | 1838 FilePath dir2 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir2")); |
| 1843 EXPECT_TRUE(file_util::CreateDirectory(dir2)); | 1839 EXPECT_TRUE(file_util::CreateDirectory(dir2)); |
| 1844 FilePath dir2inner = dir2.Append(FPL("inner")); | 1840 FilePath dir2inner = dir2.Append(FILE_PATH_LITERAL("inner")); |
| 1845 EXPECT_TRUE(file_util::CreateDirectory(dir2inner)); | 1841 EXPECT_TRUE(file_util::CreateDirectory(dir2inner)); |
| 1846 | 1842 |
| 1847 // create the files | 1843 // create the files |
| 1848 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); | 1844 FilePath dir2file = dir2.Append(FILE_PATH_LITERAL("dir2file.txt")); |
| 1849 CreateTextFile(dir2file, std::wstring()); | 1845 CreateTextFile(dir2file, std::wstring()); |
| 1850 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); | 1846 FilePath dir2innerfile = dir2inner.Append(FILE_PATH_LITERAL("innerfile.txt")); |
| 1851 CreateTextFile(dir2innerfile, std::wstring()); | 1847 CreateTextFile(dir2innerfile, std::wstring()); |
| 1852 FilePath file1 = temp_dir_.path().Append(FPL("file1.txt")); | 1848 FilePath file1 = temp_dir_.path().Append(FILE_PATH_LITERAL("file1.txt")); |
| 1853 CreateTextFile(file1, std::wstring()); | 1849 CreateTextFile(file1, std::wstring()); |
| 1854 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) | 1850 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) |
| 1855 .Append(FPL("file2.txt")); | 1851 .Append(FILE_PATH_LITERAL("file2.txt")); |
| 1856 CreateTextFile(file2_rel, std::wstring()); | 1852 CreateTextFile(file2_rel, std::wstring()); |
| 1857 FilePath file2_abs = temp_dir_.path().Append(FPL("file2.txt")); | 1853 FilePath file2_abs = temp_dir_.path().Append(FILE_PATH_LITERAL("file2.txt")); |
| 1858 | 1854 |
| 1859 // Only enumerate files. | 1855 // Only enumerate files. |
| 1860 FileEnumerator f1(temp_dir_.path(), true, FileEnumerator::FILES); | 1856 FileEnumerator f1(temp_dir_.path(), true, FileEnumerator::FILES); |
| 1861 FindResultCollector c1(f1); | 1857 FindResultCollector c1(f1); |
| 1862 EXPECT_TRUE(c1.HasFile(file1)); | 1858 EXPECT_TRUE(c1.HasFile(file1)); |
| 1863 EXPECT_TRUE(c1.HasFile(file2_abs)); | 1859 EXPECT_TRUE(c1.HasFile(file2_abs)); |
| 1864 EXPECT_TRUE(c1.HasFile(dir2file)); | 1860 EXPECT_TRUE(c1.HasFile(dir2file)); |
| 1865 EXPECT_TRUE(c1.HasFile(dir2innerfile)); | 1861 EXPECT_TRUE(c1.HasFile(dir2innerfile)); |
| 1866 EXPECT_EQ(c1.size(), 4); | 1862 EXPECT_EQ(c1.size(), 4); |
| 1867 | 1863 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1881 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); | 1877 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); |
| 1882 EXPECT_EQ(c2_non_recursive.size(), 2); | 1878 EXPECT_EQ(c2_non_recursive.size(), 2); |
| 1883 | 1879 |
| 1884 // Only enumerate directories, non-recursively, including "..". | 1880 // Only enumerate directories, non-recursively, including "..". |
| 1885 FileEnumerator f2_dotdot(temp_dir_.path(), false, | 1881 FileEnumerator f2_dotdot(temp_dir_.path(), false, |
| 1886 FileEnumerator::DIRECTORIES | | 1882 FileEnumerator::DIRECTORIES | |
| 1887 FileEnumerator::INCLUDE_DOT_DOT); | 1883 FileEnumerator::INCLUDE_DOT_DOT); |
| 1888 FindResultCollector c2_dotdot(f2_dotdot); | 1884 FindResultCollector c2_dotdot(f2_dotdot); |
| 1889 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); | 1885 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); |
| 1890 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); | 1886 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); |
| 1891 EXPECT_TRUE(c2_dotdot.HasFile(temp_dir_.path().Append(FPL("..")))); | 1887 EXPECT_TRUE(c2_dotdot.HasFile( |
| 1888 temp_dir_.path().Append(FILE_PATH_LITERAL("..")))); |
| 1892 EXPECT_EQ(c2_dotdot.size(), 3); | 1889 EXPECT_EQ(c2_dotdot.size(), 3); |
| 1893 | 1890 |
| 1894 // Enumerate files and directories. | 1891 // Enumerate files and directories. |
| 1895 FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1892 FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
| 1896 FindResultCollector c3(f3); | 1893 FindResultCollector c3(f3); |
| 1897 EXPECT_TRUE(c3.HasFile(dir1)); | 1894 EXPECT_TRUE(c3.HasFile(dir1)); |
| 1898 EXPECT_TRUE(c3.HasFile(dir2)); | 1895 EXPECT_TRUE(c3.HasFile(dir2)); |
| 1899 EXPECT_TRUE(c3.HasFile(file1)); | 1896 EXPECT_TRUE(c3.HasFile(file1)); |
| 1900 EXPECT_TRUE(c3.HasFile(file2_abs)); | 1897 EXPECT_TRUE(c3.HasFile(file2_abs)); |
| 1901 EXPECT_TRUE(c3.HasFile(dir2file)); | 1898 EXPECT_TRUE(c3.HasFile(dir2file)); |
| 1902 EXPECT_TRUE(c3.HasFile(dir2inner)); | 1899 EXPECT_TRUE(c3.HasFile(dir2inner)); |
| 1903 EXPECT_TRUE(c3.HasFile(dir2innerfile)); | 1900 EXPECT_TRUE(c3.HasFile(dir2innerfile)); |
| 1904 EXPECT_EQ(c3.size(), 7); | 1901 EXPECT_EQ(c3.size(), 7); |
| 1905 | 1902 |
| 1906 // Non-recursive operation. | 1903 // Non-recursive operation. |
| 1907 FileEnumerator f4(temp_dir_.path(), false, FILES_AND_DIRECTORIES); | 1904 FileEnumerator f4(temp_dir_.path(), false, FILES_AND_DIRECTORIES); |
| 1908 FindResultCollector c4(f4); | 1905 FindResultCollector c4(f4); |
| 1909 EXPECT_TRUE(c4.HasFile(dir2)); | 1906 EXPECT_TRUE(c4.HasFile(dir2)); |
| 1910 EXPECT_TRUE(c4.HasFile(dir2)); | 1907 EXPECT_TRUE(c4.HasFile(dir2)); |
| 1911 EXPECT_TRUE(c4.HasFile(file1)); | 1908 EXPECT_TRUE(c4.HasFile(file1)); |
| 1912 EXPECT_TRUE(c4.HasFile(file2_abs)); | 1909 EXPECT_TRUE(c4.HasFile(file2_abs)); |
| 1913 EXPECT_EQ(c4.size(), 4); | 1910 EXPECT_EQ(c4.size(), 4); |
| 1914 | 1911 |
| 1915 // Enumerate with a pattern. | 1912 // Enumerate with a pattern. |
| 1916 FileEnumerator f5(temp_dir_.path(), true, FILES_AND_DIRECTORIES, FPL("dir*")); | 1913 FileEnumerator f5(temp_dir_.path(), true, FILES_AND_DIRECTORIES, |
| 1914 FILE_PATH_LITERAL("dir*")); |
| 1917 FindResultCollector c5(f5); | 1915 FindResultCollector c5(f5); |
| 1918 EXPECT_TRUE(c5.HasFile(dir1)); | 1916 EXPECT_TRUE(c5.HasFile(dir1)); |
| 1919 EXPECT_TRUE(c5.HasFile(dir2)); | 1917 EXPECT_TRUE(c5.HasFile(dir2)); |
| 1920 EXPECT_TRUE(c5.HasFile(dir2file)); | 1918 EXPECT_TRUE(c5.HasFile(dir2file)); |
| 1921 EXPECT_TRUE(c5.HasFile(dir2inner)); | 1919 EXPECT_TRUE(c5.HasFile(dir2inner)); |
| 1922 EXPECT_TRUE(c5.HasFile(dir2innerfile)); | 1920 EXPECT_TRUE(c5.HasFile(dir2innerfile)); |
| 1923 EXPECT_EQ(c5.size(), 5); | 1921 EXPECT_EQ(c5.size(), 5); |
| 1924 | 1922 |
| 1925 #if defined(OS_WIN) | |
| 1926 { | |
| 1927 // Make dir1 point to dir2. | |
| 1928 ReparsePoint reparse_point(dir1, dir2); | |
| 1929 EXPECT_TRUE(reparse_point.IsValid()); | |
| 1930 | |
| 1931 // Enumerate the reparse point. | |
| 1932 FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES); | |
| 1933 FindResultCollector c6(f6); | |
| 1934 FilePath inner2 = dir1.Append(FPL("inner")); | |
| 1935 EXPECT_TRUE(c6.HasFile(inner2)); | |
| 1936 EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt")))); | |
| 1937 EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt")))); | |
| 1938 EXPECT_EQ(c6.size(), 3); | |
| 1939 | |
| 1940 // No changes for non recursive operation. | |
| 1941 FileEnumerator f7(temp_dir_.path(), false, FILES_AND_DIRECTORIES); | |
| 1942 FindResultCollector c7(f7); | |
| 1943 EXPECT_TRUE(c7.HasFile(dir2)); | |
| 1944 EXPECT_TRUE(c7.HasFile(dir2)); | |
| 1945 EXPECT_TRUE(c7.HasFile(file1)); | |
| 1946 EXPECT_TRUE(c7.HasFile(file2_abs)); | |
| 1947 EXPECT_EQ(c7.size(), 4); | |
| 1948 | |
| 1949 // Should not enumerate inside dir1 when using recursion. | |
| 1950 FileEnumerator f8(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | |
| 1951 FindResultCollector c8(f8); | |
| 1952 EXPECT_TRUE(c8.HasFile(dir1)); | |
| 1953 EXPECT_TRUE(c8.HasFile(dir2)); | |
| 1954 EXPECT_TRUE(c8.HasFile(file1)); | |
| 1955 EXPECT_TRUE(c8.HasFile(file2_abs)); | |
| 1956 EXPECT_TRUE(c8.HasFile(dir2file)); | |
| 1957 EXPECT_TRUE(c8.HasFile(dir2inner)); | |
| 1958 EXPECT_TRUE(c8.HasFile(dir2innerfile)); | |
| 1959 EXPECT_EQ(c8.size(), 7); | |
| 1960 } | |
| 1961 #endif | |
| 1962 | |
| 1963 // Make sure the destructor closes the find handle while in the middle of a | 1923 // Make sure the destructor closes the find handle while in the middle of a |
| 1964 // query to allow TearDown to delete the directory. | 1924 // query to allow TearDown to delete the directory. |
| 1965 FileEnumerator f9(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1925 FileEnumerator f6(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
| 1966 EXPECT_FALSE(f9.Next().value().empty()); // Should have found something | 1926 EXPECT_FALSE(f6.Next().value().empty()); // Should have found something |
| 1967 // (we don't care what). | 1927 // (we don't care what). |
| 1968 } | 1928 } |
| 1969 | 1929 |
| 1970 TEST_F(FileUtilTest, AppendToFile) { | 1930 TEST_F(FileUtilTest, AppendToFile) { |
| 1971 FilePath data_dir = | 1931 FilePath data_dir = |
| 1972 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1932 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 1973 | 1933 |
| 1974 // Create a fresh, empty copy of this directory. | 1934 // Create a fresh, empty copy of this directory. |
| 1975 if (base::PathExists(data_dir)) { | 1935 if (base::PathExists(data_dir)) { |
| 1976 ASSERT_TRUE(base::DeleteFile(data_dir, true)); | 1936 ASSERT_TRUE(base::DeleteFile(data_dir, true)); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2412 file_util::VerifyPathControlledByUser( | 2372 file_util::VerifyPathControlledByUser( |
| 2413 base_dir_, text_file_, uid_, ok_gids_)); | 2373 base_dir_, text_file_, uid_, ok_gids_)); |
| 2414 EXPECT_TRUE( | 2374 EXPECT_TRUE( |
| 2415 file_util::VerifyPathControlledByUser( | 2375 file_util::VerifyPathControlledByUser( |
| 2416 sub_dir_, text_file_, uid_, ok_gids_)); | 2376 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2417 } | 2377 } |
| 2418 | 2378 |
| 2419 #endif // defined(OS_POSIX) | 2379 #endif // defined(OS_POSIX) |
| 2420 | 2380 |
| 2421 } // namespace | 2381 } // namespace |
| OLD | NEW |