| 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/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 | 14 |
| 15 #if defined(OS_ANDROID) |
| 16 #include <jni.h> |
| 17 #include "base/basictypes.h" |
| 18 #endif |
| 19 |
| 15 namespace base { | 20 namespace base { |
| 16 | 21 |
| 17 class FilePath; | 22 class FilePath; |
| 18 | 23 |
| 19 // Clear a specific file from the system cache like EvictFileFromSystemCache, | 24 // Clear a specific file from the system cache like EvictFileFromSystemCache, |
| 20 // but on failure it will sleep and retry. On the Windows buildbots, eviction | 25 // but on failure it will sleep and retry. On the Windows buildbots, eviction |
| 21 // can fail if the file is marked in use, and this will throw off timings that | 26 // can fail if the file is marked in use, and this will throw off timings that |
| 22 // rely on uncached files. | 27 // rely on uncached files. |
| 23 bool EvictFileFromSystemCacheWithRetry(const FilePath& file); | 28 bool EvictFileFromSystemCacheWithRetry(const FilePath& file); |
| 24 | 29 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 51 // string16 elsewhere for Unicode strings, but in tests it is frequently | 56 // string16 elsewhere for Unicode strings, but in tests it is frequently |
| 52 // convenient to be able to compare paths to literals like L"foobar". | 57 // convenient to be able to compare paths to literals like L"foobar". |
| 53 std::wstring FilePathAsWString(const base::FilePath& path); | 58 std::wstring FilePathAsWString(const base::FilePath& path); |
| 54 base::FilePath WStringAsFilePath(const std::wstring& path); | 59 base::FilePath WStringAsFilePath(const std::wstring& path); |
| 55 | 60 |
| 56 // For testing, make the file unreadable or unwritable. | 61 // For testing, make the file unreadable or unwritable. |
| 57 // In POSIX, this does not apply to the root user. | 62 // In POSIX, this does not apply to the root user. |
| 58 bool MakeFileUnreadable(const base::FilePath& path) WARN_UNUSED_RESULT; | 63 bool MakeFileUnreadable(const base::FilePath& path) WARN_UNUSED_RESULT; |
| 59 bool MakeFileUnwritable(const base::FilePath& path) WARN_UNUSED_RESULT; | 64 bool MakeFileUnwritable(const base::FilePath& path) WARN_UNUSED_RESULT; |
| 60 | 65 |
| 66 #if defined(OS_ANDROID) |
| 67 // Register the ContentUriTestUrils JNI bindings. |
| 68 bool RegisterContentUriTestUtils(JNIEnv* env); |
| 69 |
| 70 // Insert an image file into the MediaStore, and retrieve the content URI for |
| 71 // testing purpose. |
| 72 base::FilePath InsertImageIntoMediaStore(const base::FilePath& path); |
| 73 #endif // defined(OS_ANDROID) |
| 74 |
| 61 // Saves the current permissions for a path, and restores it on destruction. | 75 // Saves the current permissions for a path, and restores it on destruction. |
| 62 class PermissionRestorer { | 76 class PermissionRestorer { |
| 63 public: | 77 public: |
| 64 explicit PermissionRestorer(const base::FilePath& path); | 78 explicit PermissionRestorer(const base::FilePath& path); |
| 65 ~PermissionRestorer(); | 79 ~PermissionRestorer(); |
| 66 | 80 |
| 67 private: | 81 private: |
| 68 const base::FilePath path_; | 82 const base::FilePath path_; |
| 69 void* info_; // The opaque stored permission information. | 83 void* info_; // The opaque stored permission information. |
| 70 size_t length_; // The length of the stored permission information. | 84 size_t length_; // The length of the stored permission information. |
| 71 | 85 |
| 72 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer); | 86 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer); |
| 73 }; | 87 }; |
| 74 | 88 |
| 75 } // namespace file_util | 89 } // namespace file_util |
| 76 | 90 |
| 77 #endif // BASE_TEST_TEST_FILE_UTIL_H_ | 91 #endif // BASE_TEST_TEST_FILE_UTIL_H_ |
| OLD | NEW |