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
3 // found in the LICENSE file.
5 #ifndef BASE_TEST_TEST_FILE_UTIL_H_
6 #define BASE_TEST_TEST_FILE_UTIL_H_
8 // File utility functions used only by tests.
12 #include "base/compiler_specific.h"
13 #include "base/file_path.h"
19 // 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 bool DieFileDie(const FilePath
& file
, bool recurse
);
24 // 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.
26 bool EvictFileFromSystemCache(const FilePath
& file
);
28 // Like CopyFileNoCache but recursively copies all files and subdirectories
29 // in the given input directory to the output directory. Any files in the
30 // destination that already exist will be overwritten.
32 // Returns true on success. False means there was some error copying, so the
33 // state of the destination is unknown.
34 bool CopyRecursiveDirNoCache(const FilePath
& source_dir
,
35 const FilePath
& dest_dir
);
38 // Returns true if the volume supports Alternate Data Streams.
39 bool VolumeSupportsADS(const FilePath
& path
);
41 // Returns true if the ZoneIdentifier is correctly set to "Internet" (3).
42 // 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 bool HasInternetZoneIdentifier(const FilePath
& full_path
);
46 #endif // defined(OS_WIN)
48 // 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
50 // convenient to be able to compare paths to literals like L"foobar".
51 std::wstring
FilePathAsWString(const FilePath
& path
);
52 FilePath
WStringAsFilePath(const std::wstring
& path
);
54 // For testing, make the file unreadable or unwritable.
55 // In POSIX, this does not apply to the root user.
56 bool MakeFileUnreadable(const FilePath
& path
) WARN_UNUSED_RESULT
;
57 bool MakeFileUnwritable(const FilePath
& path
) WARN_UNUSED_RESULT
;
59 // Saves the current permissions for a path, and restores it on destruction.
60 class PermissionRestorer
{
62 explicit PermissionRestorer(const FilePath
& path
);
63 ~PermissionRestorer();
67 void* info_
; // The opaque stored permission information.
68 size_t length_
; // The length of the stored permission information.
70 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer
);
73 } // namespace file_util
75 #endif // BASE_TEST_TEST_FILE_UTIL_H_