| 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 #ifndef BASE_TEST_TEST_FILE_UTIL_H_ | 5 #ifndef BASE_TEST_TEST_FILE_UTIL_H_ |
| 6 #define BASE_TEST_TEST_FILE_UTIL_H_ | 6 #define BASE_TEST_TEST_FILE_UTIL_H_ |
| 7 | 7 |
| 8 // File utility functions used only by tests. | 8 // File utility functions used only by tests. |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 | 14 |
| 15 namespace base { |
| 15 class FilePath; | 16 class FilePath; |
| 17 } |
| 16 | 18 |
| 17 namespace file_util { | 19 namespace file_util { |
| 18 | 20 |
| 19 // Wrapper over file_util::Delete. On Windows repeatedly invokes Delete in case | 21 // Wrapper over file_util::Delete. On Windows repeatedly invokes Delete in case |
| 20 // of failure to workaround Windows file locking semantics. Returns true on | 22 // of failure to workaround Windows file locking semantics. Returns true on |
| 21 // success. | 23 // success. |
| 22 bool DieFileDie(const FilePath& file, bool recurse); | 24 bool DieFileDie(const base::FilePath& file, bool recurse); |
| 23 | 25 |
| 24 // Clear a specific file from the system cache. After this call, trying | 26 // Clear a specific file from the system cache. After this call, trying |
| 25 // to access this file will result in a cold load from the hard drive. | 27 // to access this file will result in a cold load from the hard drive. |
| 26 bool EvictFileFromSystemCache(const FilePath& file); | 28 bool EvictFileFromSystemCache(const base::FilePath& file); |
| 27 | 29 |
| 28 // Like CopyFileNoCache but recursively copies all files and subdirectories | 30 // Like CopyFileNoCache but recursively copies all files and subdirectories |
| 29 // in the given input directory to the output directory. Any files in the | 31 // in the given input directory to the output directory. Any files in the |
| 30 // destination that already exist will be overwritten. | 32 // destination that already exist will be overwritten. |
| 31 // | 33 // |
| 32 // Returns true on success. False means there was some error copying, so the | 34 // Returns true on success. False means there was some error copying, so the |
| 33 // state of the destination is unknown. | 35 // state of the destination is unknown. |
| 34 bool CopyRecursiveDirNoCache(const FilePath& source_dir, | 36 bool CopyRecursiveDirNoCache(const base::FilePath& source_dir, |
| 35 const FilePath& dest_dir); | 37 const base::FilePath& dest_dir); |
| 36 | 38 |
| 37 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 38 // Returns true if the volume supports Alternate Data Streams. | 40 // Returns true if the volume supports Alternate Data Streams. |
| 39 bool VolumeSupportsADS(const FilePath& path); | 41 bool VolumeSupportsADS(const base::FilePath& path); |
| 40 | 42 |
| 41 // Returns true if the ZoneIdentifier is correctly set to "Internet" (3). | 43 // Returns true if the ZoneIdentifier is correctly set to "Internet" (3). |
| 42 // Note that this function must be called from the same process as | 44 // Note that this function must be called from the same process as |
| 43 // the one that set the zone identifier. I.e. don't use it in UI/automation | 45 // the one that set the zone identifier. I.e. don't use it in UI/automation |
| 44 // based tests. | 46 // based tests. |
| 45 bool HasInternetZoneIdentifier(const FilePath& full_path); | 47 bool HasInternetZoneIdentifier(const base::FilePath& full_path); |
| 46 #endif // defined(OS_WIN) | 48 #endif // defined(OS_WIN) |
| 47 | 49 |
| 48 // In general it's not reliable to convert a FilePath to a wstring and we use | 50 // In general it's not reliable to convert a FilePath to a wstring and we use |
| 49 // string16 elsewhere for Unicode strings, but in tests it is frequently | 51 // string16 elsewhere for Unicode strings, but in tests it is frequently |
| 50 // convenient to be able to compare paths to literals like L"foobar". | 52 // convenient to be able to compare paths to literals like L"foobar". |
| 51 std::wstring FilePathAsWString(const FilePath& path); | 53 std::wstring FilePathAsWString(const base::FilePath& path); |
| 52 FilePath WStringAsFilePath(const std::wstring& path); | 54 base::FilePath WStringAsFilePath(const std::wstring& path); |
| 53 | 55 |
| 54 // For testing, make the file unreadable or unwritable. | 56 // For testing, make the file unreadable or unwritable. |
| 55 // In POSIX, this does not apply to the root user. | 57 // In POSIX, this does not apply to the root user. |
| 56 bool MakeFileUnreadable(const FilePath& path) WARN_UNUSED_RESULT; | 58 bool MakeFileUnreadable(const base::FilePath& path) WARN_UNUSED_RESULT; |
| 57 bool MakeFileUnwritable(const FilePath& path) WARN_UNUSED_RESULT; | 59 bool MakeFileUnwritable(const base::FilePath& path) WARN_UNUSED_RESULT; |
| 58 | 60 |
| 59 // Saves the current permissions for a path, and restores it on destruction. | 61 // Saves the current permissions for a path, and restores it on destruction. |
| 60 class PermissionRestorer { | 62 class PermissionRestorer { |
| 61 public: | 63 public: |
| 62 explicit PermissionRestorer(const FilePath& path); | 64 explicit PermissionRestorer(const base::FilePath& path); |
| 63 ~PermissionRestorer(); | 65 ~PermissionRestorer(); |
| 64 | 66 |
| 65 private: | 67 private: |
| 66 const FilePath path_; | 68 const base::FilePath path_; |
| 67 void* info_; // The opaque stored permission information. | 69 void* info_; // The opaque stored permission information. |
| 68 size_t length_; // The length of the stored permission information. | 70 size_t length_; // The length of the stored permission information. |
| 69 | 71 |
| 70 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer); | 72 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer); |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 } // namespace file_util | 75 } // namespace file_util |
| 74 | 76 |
| 75 #endif // BASE_TEST_TEST_FILE_UTIL_H_ | 77 #endif // BASE_TEST_TEST_FILE_UTIL_H_ |
| OLD | NEW |