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