Chromium Code Reviews| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 int mode = 0; | 123 int mode = 0; |
| 124 ASSERT_TRUE(file_util::GetPosixFilePermissions(path, &mode)); | 124 ASSERT_TRUE(file_util::GetPosixFilePermissions(path, &mode)); |
| 125 mode |= mode_bits_to_set; | 125 mode |= mode_bits_to_set; |
| 126 mode &= ~mode_bits_to_clear; | 126 mode &= ~mode_bits_to_clear; |
| 127 ASSERT_TRUE(file_util::SetPosixFilePermissions(path, mode)); | 127 ASSERT_TRUE(file_util::SetPosixFilePermissions(path, mode)); |
| 128 } | 128 } |
| 129 #endif // defined(OS_POSIX) | 129 #endif // defined(OS_POSIX) |
| 130 | 130 |
| 131 const wchar_t bogus_content[] = L"I'm cannon fodder."; | 131 const wchar_t bogus_content[] = L"I'm cannon fodder."; |
| 132 | 132 |
| 133 const file_util::FileEnumerator::FileType FILES_AND_DIRECTORIES = | 133 const int FILES_AND_DIRECTORIES = |
| 134 static_cast<file_util::FileEnumerator::FileType>( | 134 file_util::FileEnumerator::FILES | file_util::FileEnumerator::DIRECTORIES; |
| 135 file_util::FileEnumerator::FILES | | |
| 136 file_util::FileEnumerator::DIRECTORIES); | |
| 137 | 135 |
| 138 // file_util winds up using autoreleased objects on the Mac, so this needs | 136 // file_util winds up using autoreleased objects on the Mac, so this needs |
| 139 // to be a PlatformTest | 137 // to be a PlatformTest |
| 140 class FileUtilTest : public PlatformTest { | 138 class FileUtilTest : public PlatformTest { |
| 141 protected: | 139 protected: |
| 142 virtual void SetUp() OVERRIDE { | 140 virtual void SetUp() OVERRIDE { |
| 143 PlatformTest::SetUp(); | 141 PlatformTest::SetUp(); |
| 144 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 142 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 145 } | 143 } |
| 146 | 144 |
| (...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 EXPECT_TRUE(file_util::Delete(test_root, true)); | 1853 EXPECT_TRUE(file_util::Delete(test_root, true)); |
| 1856 } | 1854 } |
| 1857 | 1855 |
| 1858 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1856 TEST_F(FileUtilTest, FileEnumeratorTest) { |
| 1859 // Test an empty directory. | 1857 // Test an empty directory. |
| 1860 file_util::FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1858 file_util::FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
| 1861 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); | 1859 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
| 1862 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); | 1860 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
| 1863 | 1861 |
| 1864 // Test an empty directory, non-recursively, including "..". | 1862 // Test an empty directory, non-recursively, including "..". |
| 1865 file_util::FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1863 file_util::FileEnumerator f0_dotdot( |
| 1866 static_cast<file_util::FileEnumerator::FileType>( | 1864 temp_dir_.path(), false, |
| 1867 FILES_AND_DIRECTORIES | file_util::FileEnumerator::INCLUDE_DOT_DOT)); | 1865 (FILES_AND_DIRECTORIES | file_util::FileEnumerator::INCLUDE_DOT_DOT)); |
|
jar (doing other things)
2012/08/06 18:27:02
nit: I don't see value in the paren around this or
Haruki Sato
2012/08/06 23:22:18
Done.
| |
| 1868 EXPECT_EQ(temp_dir_.path().Append(FILE_PATH_LITERAL("..")).value(), | 1866 EXPECT_EQ(temp_dir_.path().Append(FILE_PATH_LITERAL("..")).value(), |
| 1869 f0_dotdot.Next().value()); | 1867 f0_dotdot.Next().value()); |
| 1870 EXPECT_EQ(FILE_PATH_LITERAL(""), | 1868 EXPECT_EQ(FILE_PATH_LITERAL(""), |
| 1871 f0_dotdot.Next().value()); | 1869 f0_dotdot.Next().value()); |
| 1872 | 1870 |
| 1873 // create the directories | 1871 // create the directories |
| 1874 FilePath dir1 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir1")); | 1872 FilePath dir1 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir1")); |
| 1875 EXPECT_TRUE(file_util::CreateDirectory(dir1)); | 1873 EXPECT_TRUE(file_util::CreateDirectory(dir1)); |
| 1876 FilePath dir2 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir2")); | 1874 FilePath dir2 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir2")); |
| 1877 EXPECT_TRUE(file_util::CreateDirectory(dir2)); | 1875 EXPECT_TRUE(file_util::CreateDirectory(dir2)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1914 file_util::FileEnumerator f2_non_recursive( | 1912 file_util::FileEnumerator f2_non_recursive( |
| 1915 temp_dir_.path(), false, file_util::FileEnumerator::DIRECTORIES); | 1913 temp_dir_.path(), false, file_util::FileEnumerator::DIRECTORIES); |
| 1916 FindResultCollector c2_non_recursive(f2_non_recursive); | 1914 FindResultCollector c2_non_recursive(f2_non_recursive); |
| 1917 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); | 1915 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); |
| 1918 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); | 1916 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); |
| 1919 EXPECT_EQ(c2_non_recursive.size(), 2); | 1917 EXPECT_EQ(c2_non_recursive.size(), 2); |
| 1920 | 1918 |
| 1921 // Only enumerate directories, non-recursively, including "..". | 1919 // Only enumerate directories, non-recursively, including "..". |
| 1922 file_util::FileEnumerator f2_dotdot( | 1920 file_util::FileEnumerator f2_dotdot( |
| 1923 temp_dir_.path(), false, | 1921 temp_dir_.path(), false, |
| 1924 static_cast<file_util::FileEnumerator::FileType>( | 1922 (file_util::FileEnumerator::DIRECTORIES | |
| 1925 file_util::FileEnumerator::DIRECTORIES | | 1923 file_util::FileEnumerator::INCLUDE_DOT_DOT)); |
| 1926 file_util::FileEnumerator::INCLUDE_DOT_DOT)); | |
| 1927 FindResultCollector c2_dotdot(f2_dotdot); | 1924 FindResultCollector c2_dotdot(f2_dotdot); |
| 1928 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); | 1925 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); |
| 1929 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); | 1926 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); |
| 1930 EXPECT_TRUE(c2_dotdot.HasFile( | 1927 EXPECT_TRUE(c2_dotdot.HasFile( |
| 1931 temp_dir_.path().Append(FILE_PATH_LITERAL("..")))); | 1928 temp_dir_.path().Append(FILE_PATH_LITERAL("..")))); |
| 1932 EXPECT_EQ(c2_dotdot.size(), 3); | 1929 EXPECT_EQ(c2_dotdot.size(), 3); |
| 1933 | 1930 |
| 1934 // Enumerate files and directories. | 1931 // Enumerate files and directories. |
| 1935 file_util::FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1932 file_util::FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
| 1936 FindResultCollector c3(f3); | 1933 FindResultCollector c3(f3); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2459 file_util::VerifyPathControlledByUser( | 2456 file_util::VerifyPathControlledByUser( |
| 2460 base_dir_, text_file_, uid_, ok_gids_)); | 2457 base_dir_, text_file_, uid_, ok_gids_)); |
| 2461 EXPECT_TRUE( | 2458 EXPECT_TRUE( |
| 2462 file_util::VerifyPathControlledByUser( | 2459 file_util::VerifyPathControlledByUser( |
| 2463 sub_dir_, text_file_, uid_, ok_gids_)); | 2460 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2464 } | 2461 } |
| 2465 | 2462 |
| 2466 #endif // defined(OS_POSIX) | 2463 #endif // defined(OS_POSIX) |
| 2467 | 2464 |
| 2468 } // namespace | 2465 } // namespace |
| OLD | NEW |