• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TEST_ANDROID_CONTENT_URI_TEST_UTILS_H_
6 #define BASE_TEST_ANDROID_CONTENT_URI_TEST_UTILS_H_
7 
8 #include <optional>
9 
10 namespace base {
11 class FilePath;
12 
13 namespace test::android {
14 
15 // Returns a content-URI for FileProvider org.chromium.native_test.fileprovider
16 // representing `path` if it is a valid file or dir under the android app cache
17 // dir such as a path created in a ScopedTempDir, else returns std::nullopt.
18 std::optional<FilePath> GetContentUriFromCacheDirFilePath(const FilePath& path);
19 
20 // Similar to GetContentUriFromCacheDirFilePath() but files are first read into
21 // memory and any file descriptor will not be backed by a local file. This
22 // mimics how an in-memory or network-backed ContentProvider will behave.
23 std::optional<FilePath> GetInMemoryContentUriFromCacheDirFilePath(
24     const FilePath& path);
25 
26 // Returns a DocumentFile Tree URI for the specified directory which must be
27 // under the cache dir, else returns std::nullopt. This mimics how a
28 // DocumentsProvider will work with ACTION_OPEN_DOCUMENT_TREE.
29 std::optional<FilePath> GetInMemoryContentTreeUriFromCacheDirDirectory(
30     const FilePath& directory);
31 
32 }  // namespace test::android
33 }  // namespace base
34 
35 #endif  // BASE_TEST_ANDROID_CONTENT_URI_TEST_UTILS_H_
36