Simple Cache: a few tests for rare corner cases with CRC check missing.
[chromium-blink-merge.git] / base / test / test_file_util.h
blob418c4800df3939f80d6fa22db1900299aa019eae
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.
10 #include <string>
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
15 namespace base {
17 class FilePath;
19 // Clear a specific file from the system cache like EvictFileFromSystemCache,
20 // 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
22 // rely on uncached files.
23 bool EvictFileFromSystemCacheWithRetry(const FilePath& file);
25 } // namespace base
27 // TODO(brettw) move all of this to the base namespace.
28 namespace file_util {
30 // Wrapper over file_util::Delete. On Windows repeatedly invokes Delete in case
31 // of failure to workaround Windows file locking semantics. Returns true on
32 // success.
33 bool DieFileDie(const base::FilePath& file, bool recurse);
35 // Clear a specific file from the system cache. After this call, trying
36 // to access this file will result in a cold load from the hard drive.
37 bool EvictFileFromSystemCache(const base::FilePath& file);
39 #if defined(OS_WIN)
40 // Returns true if the volume supports Alternate Data Streams.
41 bool VolumeSupportsADS(const base::FilePath& path);
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
45 // the one that set the zone identifier. I.e. don't use it in UI/automation
46 // based tests.
47 bool HasInternetZoneIdentifier(const base::FilePath& full_path);
48 #endif // defined(OS_WIN)
50 // In general it's not reliable to convert a FilePath to a wstring and we use
51 // string16 elsewhere for Unicode strings, but in tests it is frequently
52 // convenient to be able to compare paths to literals like L"foobar".
53 std::wstring FilePathAsWString(const base::FilePath& path);
54 base::FilePath WStringAsFilePath(const std::wstring& path);
56 // For testing, make the file unreadable or unwritable.
57 // In POSIX, this does not apply to the root user.
58 bool MakeFileUnreadable(const base::FilePath& path) WARN_UNUSED_RESULT;
59 bool MakeFileUnwritable(const base::FilePath& path) WARN_UNUSED_RESULT;
61 // Saves the current permissions for a path, and restores it on destruction.
62 class PermissionRestorer {
63 public:
64 explicit PermissionRestorer(const base::FilePath& path);
65 ~PermissionRestorer();
67 private:
68 const base::FilePath path_;
69 void* info_; // The opaque stored permission information.
70 size_t length_; // The length of the stored permission information.
72 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer);
75 } // namespace file_util
77 #endif // BASE_TEST_TEST_FILE_UTIL_H_