| 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> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // Returns true if the volume supports Alternate Data Streams. | 40 // Returns true if the volume supports Alternate Data Streams. |
| 41 bool VolumeSupportsADS(const FilePath& path); | 41 bool VolumeSupportsADS(const FilePath& path); |
| 42 | 42 |
| 43 // Returns true if the ZoneIdentifier is correctly set to "Internet" (3). | 43 // Returns true if the ZoneIdentifier is correctly set to "Internet" (3). |
| 44 // 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 |
| 45 // 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 |
| 46 // based tests. | 46 // based tests. |
| 47 bool HasInternetZoneIdentifier(const FilePath& full_path); | 47 bool HasInternetZoneIdentifier(const FilePath& full_path); |
| 48 #endif // defined(OS_WIN) | 48 #endif // defined(OS_WIN) |
| 49 | 49 |
| 50 } // namespace base | |
| 51 | |
| 52 // TODO(brettw) move all of this to the base namespace. | |
| 53 namespace file_util { | |
| 54 | |
| 55 // For testing, make the file unreadable or unwritable. | 50 // For testing, make the file unreadable or unwritable. |
| 56 // In POSIX, this does not apply to the root user. | 51 // In POSIX, this does not apply to the root user. |
| 57 bool MakeFileUnreadable(const base::FilePath& path) WARN_UNUSED_RESULT; | 52 bool MakeFileUnreadable(const FilePath& path) WARN_UNUSED_RESULT; |
| 58 bool MakeFileUnwritable(const base::FilePath& path) WARN_UNUSED_RESULT; | 53 bool MakeFileUnwritable(const FilePath& path) WARN_UNUSED_RESULT; |
| 54 |
| 55 // Saves the current permissions for a path, and restores it on destruction. |
| 56 class FilePermissionRestorer { |
| 57 public: |
| 58 explicit FilePermissionRestorer(const FilePath& path); |
| 59 ~FilePermissionRestorer(); |
| 60 |
| 61 private: |
| 62 const FilePath path_; |
| 63 void* info_; // The opaque stored permission information. |
| 64 size_t length_; // The length of the stored permission information. |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(FilePermissionRestorer); |
| 67 }; |
| 59 | 68 |
| 60 #if defined(OS_ANDROID) | 69 #if defined(OS_ANDROID) |
| 61 // Register the ContentUriTestUrils JNI bindings. | 70 // Register the ContentUriTestUrils JNI bindings. |
| 62 bool RegisterContentUriTestUtils(JNIEnv* env); | 71 bool RegisterContentUriTestUtils(JNIEnv* env); |
| 63 | 72 |
| 64 // Insert an image file into the MediaStore, and retrieve the content URI for | 73 // Insert an image file into the MediaStore, and retrieve the content URI for |
| 65 // testing purpose. | 74 // testing purpose. |
| 66 base::FilePath InsertImageIntoMediaStore(const base::FilePath& path); | 75 FilePath InsertImageIntoMediaStore(const FilePath& path); |
| 67 #endif // defined(OS_ANDROID) | 76 #endif // defined(OS_ANDROID) |
| 68 | 77 |
| 69 // Saves the current permissions for a path, and restores it on destruction. | 78 } // namespace base |
| 70 class PermissionRestorer { | |
| 71 public: | |
| 72 explicit PermissionRestorer(const base::FilePath& path); | |
| 73 ~PermissionRestorer(); | |
| 74 | |
| 75 private: | |
| 76 const base::FilePath path_; | |
| 77 void* info_; // The opaque stored permission information. | |
| 78 size_t length_; // The length of the stored permission information. | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer); | |
| 81 }; | |
| 82 | |
| 83 } // namespace file_util | |
| 84 | 79 |
| 85 #endif // BASE_TEST_TEST_FILE_UTIL_H_ | 80 #endif // BASE_TEST_TEST_FILE_UTIL_H_ |
| OLD | NEW |