chromium/base/files/file_util_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/files/file_util.h"

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>

#include <algorithm>
#include <fstream>
#include <initializer_list>
#include <memory>
#include <set>
#include <utility>
#include <vector>

#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/environment.h"
#include "base/features.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/platform_file.h"
#include "base/files/scoped_file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/scoped_environment_variable_override.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/multiprocess_test.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_file_util.h"
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
#include "testing/platform_test.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"

#if BUILDFLAG(IS_WIN)
#include <tchar.h>
#include <windows.h>

#include <fileapi.h>
#include <shellapi.h>
#include <shlobj.h>

#include "base/scoped_native_library.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/file_path_reparse_point_win.h"
#include "base/test/gtest_util.h"
#include "base/win/scoped_handle.h"
#include "base/win/win_util.h"
#endif

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#endif

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
#include <sys/socket.h>
#endif

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include <linux/fs.h>
#endif

#if BUILDFLAG(IS_ANDROID)
#include "base/android/content_uri_utils.h"
#endif

#if BUILDFLAG(IS_FUCHSIA)
#include "base/test/scoped_dev_zero_fuchsia.h"
#endif

// This macro helps avoid wrapped lines in the test structs.
#define FPL(x)

namespace base {

namespace {

const size_t kLargeFileSize =;

#if BUILDFLAG(IS_WIN)
// Method that wraps the win32 GetShortPathName API. Returns an empty path on
// error.
FilePath MakeShortFilePath(const FilePath& input) {
  DWORD path_short_len = ::GetShortPathName(input.value().c_str(), nullptr, 0);
  if (path_short_len == 0UL) {
    return FilePath();
  }

  std::wstring path_short_str;
  path_short_len = ::GetShortPathName(
      input.value().c_str(), WriteInto(&path_short_str, path_short_len),
      path_short_len);
  if (path_short_len == 0UL) {
    return FilePath();
  }

  return FilePath(path_short_str);
}
#endif  // BUILDFLAG(IS_WIN)

#if BUILDFLAG(IS_MAC)
// Provide a simple way to change the permissions bits on |path| in tests.
// ASSERT failures will return, but not stop the test.  Caller should wrap
// calls to this function in ASSERT_NO_FATAL_FAILURE().
void ChangePosixFilePermissions(const FilePath& path,
                                int mode_bits_to_set,
                                int mode_bits_to_clear) {
  ASSERT_FALSE(mode_bits_to_set & mode_bits_to_clear)
      << "Can't set and clear the same bits.";

  int mode = 0;
  ASSERT_TRUE(GetPosixFilePermissions(path, &mode));
  mode |= mode_bits_to_set;
  mode &= ~mode_bits_to_clear;
  ASSERT_TRUE(SetPosixFilePermissions(path, mode));
}
#endif  // BUILDFLAG(IS_MAC)

// Fuchsia doesn't support file permissions.
#if !BUILDFLAG(IS_FUCHSIA)
// Sets the source file to read-only.
void SetReadOnly(const FilePath& path, bool read_only) {}

bool IsReadOnly(const FilePath& path) {}

#endif  // BUILDFLAG(IS_FUCHSIA)

const wchar_t bogus_content[] =;

const int FILES_AND_DIRECTORIES =;

// file_util winds up using autoreleased objects on the Mac, so this needs
// to be a PlatformTest
class FileUtilTest : public PlatformTest {};

// Collects all the results from the given file enumerator, and provides an
// interface to query whether a given file is present.
class FindResultCollector {};

// Simple function to dump some text into a new file.
void CreateTextFile(const FilePath& filename, const std::wstring& contents) {}

// Simple function to take out some text from a file.
std::wstring ReadTextFile(const FilePath& filename) {}

// Sets |is_inheritable| to indicate whether or not |stream| is set up to be
// inerhited into child processes (i.e., HANDLE_FLAG_INHERIT is set on the
// underlying handle on Windows, or FD_CLOEXEC is not set on the underlying file
// descriptor on POSIX). Calls to this function must be wrapped with
// ASSERT_NO_FATAL_FAILURE to properly abort tests in case of fatal failure.
void GetIsInheritable(FILE* stream, bool* is_inheritable) {}

#if BUILDFLAG(IS_POSIX)
class ScopedWorkingDirectory {};

TEST_F(FileUtilTest, MakeAbsoluteFilePathNoResolveSymbolicLinks) {}
#endif  // BUILDFLAG(IS_POSIX)

TEST_F(FileUtilTest, FileAndDirectorySize) {}

TEST_F(FileUtilTest, NormalizeFilePathBasic) {}

#if BUILDFLAG(IS_WIN)

TEST_F(FileUtilTest, NormalizeFileEmptyFile) {
  // Create a directory under the test dir.  Because we create it,
  // we know it is not a link.
  const wchar_t empty_content[] = L"";

  FilePath file_a_path = temp_dir_.GetPath().Append(FPL("file_empty_a"));
  FilePath dir_path = temp_dir_.GetPath().Append(FPL("dir"));
  FilePath file_b_path = dir_path.Append(FPL("file_empty_b"));
  ASSERT_TRUE(CreateDirectory(dir_path));

  FilePath normalized_file_a_path, normalized_file_b_path;
  ASSERT_FALSE(PathExists(file_a_path));
  EXPECT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path))
      << "NormalizeFilePath() should fail on nonexistent paths.";

  CreateTextFile(file_a_path, empty_content);
  ASSERT_TRUE(PathExists(file_a_path));
  EXPECT_TRUE(NormalizeFilePath(file_a_path, &normalized_file_a_path));

  CreateTextFile(file_b_path, empty_content);
  ASSERT_TRUE(PathExists(file_b_path));
  EXPECT_TRUE(NormalizeFilePath(file_b_path, &normalized_file_b_path));

  // Because this test created |dir_path|, we know it is not a link
  // or junction.  So, the real path of the directory holding file a
  // must be the parent of the path holding file b.
  EXPECT_TRUE(normalized_file_a_path.DirName().IsParent(
      normalized_file_b_path.DirName()));
}

TEST_F(FileUtilTest, NormalizeFilePathReparsePoints) {
  // Build the following directory structure:
  //
  // temp_dir
  // |-> base_a
  // |   |-> sub_a
  // |       |-> file.txt
  // |       |-> long_name___... (Very long name.)
  // |           |-> sub_long
  // |              |-> deep.txt
  // |-> base_b
  //     |-> to_sub_a (reparse point to temp_dir\base_a\sub_a)
  //     |-> to_base_b (reparse point to temp_dir\base_b)
  //     |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long)

  FilePath base_a = temp_dir_.GetPath().Append(FPL("base_a"));
  // TEMP can have a lower case drive letter.
  std::wstring temp_base_a = base_a.value();
  ASSERT_FALSE(temp_base_a.empty());
  temp_base_a[0] = ToUpperASCII(char16_t{temp_base_a[0]});
  base_a = FilePath(temp_base_a);

  ASSERT_TRUE(CreateDirectory(base_a));
  // TEMP might be a short name which is not normalized.
  base_a = MakeLongFilePath(base_a);

  FilePath sub_a = base_a.Append(FPL("sub_a"));
  ASSERT_TRUE(CreateDirectory(sub_a));

  FilePath file_txt = sub_a.Append(FPL("file.txt"));
  CreateTextFile(file_txt, bogus_content);

  // Want a directory whose name is long enough to make the path to the file
  // inside just under MAX_PATH chars.  This will be used to test that when
  // a junction expands to a path over MAX_PATH chars in length,
  // NormalizeFilePath() fails without crashing.
  FilePath sub_long_rel(FPL("sub_long"));
  FilePath deep_txt(FPL("deepfile.txt"));

  int target_length = MAX_PATH - 1;  // One for the string terminator.
  target_length -= (sub_a.value().length() + 1);  // +1 for the separator '\'.
  target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1);
  FilePath::StringType long_name_str = FPL("long_name_");
  long_name_str.resize(target_length, '_');

  FilePath long_name = sub_a.Append(FilePath(long_name_str));
  FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt);
  ASSERT_EQ(static_cast<size_t>(MAX_PATH - 1), deep_file.value().length());

  FilePath sub_long = deep_file.DirName();
  ASSERT_TRUE(CreateDirectory(sub_long));
  CreateTextFile(deep_file, bogus_content);

  FilePath base_b = temp_dir_.GetPath().Append(FPL("base_b"));
  ASSERT_TRUE(CreateDirectory(base_b));
  // TEMP might be a short name which is not normalized.
  base_b = MakeLongFilePath(base_b);

  FilePath to_sub_a = base_b.Append(FPL("to_sub_a"));
  ASSERT_TRUE(CreateDirectory(to_sub_a));
  FilePath normalized_path;
  {
    auto reparse_to_sub_a = test::FilePathReparsePoint::Create(to_sub_a, sub_a);
    ASSERT_TRUE(reparse_to_sub_a.has_value());

    FilePath to_base_b = base_b.Append(FPL("to_base_b"));
    ASSERT_TRUE(CreateDirectory(to_base_b));
    auto reparse_to_base_b =
        test::FilePathReparsePoint::Create(to_base_b, base_b);
    ASSERT_TRUE(reparse_to_base_b.has_value());

    FilePath to_sub_long = base_b.Append(FPL("to_sub_long"));
    ASSERT_TRUE(CreateDirectory(to_sub_long));
    auto reparse_to_sub_long =
        test::FilePathReparsePoint::Create(to_sub_long, sub_long);
    ASSERT_TRUE(reparse_to_sub_long.has_value());

    // Normalize a junction free path: base_a\sub_a\file.txt .
    ASSERT_TRUE(NormalizeFilePath(file_txt, &normalized_path));
    ASSERT_EQ(file_txt.value(), normalized_path.value());

    // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude
    // the junction to_sub_a.
    ASSERT_TRUE(
        NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), &normalized_path));
    ASSERT_EQ(file_txt.value(), normalized_path.value());

    // Check that the path base_b\to_base_b\to_base_b\to_sub_a\file.txt can be
    // normalized to exclude junctions to_base_b and to_sub_a .
    ASSERT_TRUE(NormalizeFilePath(base_b.Append(FPL("to_base_b"))
                                      .Append(FPL("to_base_b"))
                                      .Append(FPL("to_sub_a"))
                                      .Append(FPL("file.txt")),
                                  &normalized_path));
    ASSERT_EQ(file_txt.value(), normalized_path.value());

    // A long enough path will cause NormalizeFilePath() to fail.  Make a long
    // path using to_base_b many times, and check that paths long enough to fail
    // do not cause a crash.
    FilePath long_path = base_b;
    const int kLengthLimit = MAX_PATH + 40;
    while (long_path.value().length() <= kLengthLimit) {
      long_path = long_path.Append(FPL("to_base_b"));
    }
    long_path = long_path.Append(FPL("to_sub_a")).Append(FPL("file.txt"));

    ASSERT_FALSE(NormalizeFilePath(long_path, &normalized_path));

    // Normalizing the junction to deep.txt should pass, because the expanded
    // path to deep.txt is not longer than `MAX_PATH`.
    ASSERT_TRUE(
        NormalizeFilePath(to_sub_long.Append(deep_txt), &normalized_path));
    ASSERT_EQ(normalized_path, deep_file);

    // Delete the reparse points, and see that NormalizeFilePath() fails
    // to traverse them.
  }

  ASSERT_FALSE(
      NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), &normalized_path));
}

TEST_F(FileUtilTest, NormalizeFilePathWithLongPath) {
  // Indicates that the OS should bypass the normal path length limit.
  const FilePath::StringType kPathPrefix(FPL("\\\\?\\"));

  constexpr int kLengthLimit = MAX_PATH + 40;
  FilePath long_path = temp_dir_.GetPath();
  while (long_path.value().length() <= kLengthLimit) {
    long_path = long_path.Append(FPL("to_base_b"));
    const auto path_with_no_check = kPathPrefix + long_path.value();
    ASSERT_TRUE(::CreateDirectoryW(path_with_no_check.c_str(), nullptr));
  }

  auto path_with_no_check = kPathPrefix + long_path.value();
  long_path = FilePath(path_with_no_check);

  // The normalization should fail because the path is too long.
  FilePath normalized_path;
  ASSERT_FALSE(NormalizeFilePath(long_path, &normalized_path));
}

TEST_F(FileUtilTest, DevicePathToDriveLetter) {
  // Get a drive letter.
  std::wstring real_drive_letter = AsWString(
      ToUpperASCII(AsStringPiece16(temp_dir_.GetPath().value().substr(0, 2))));
  if (!IsAsciiAlpha(real_drive_letter[0]) || ':' != real_drive_letter[1]) {
    LOG(ERROR) << "Can't get a drive letter to test with.";
    return;
  }

  // Get the NT style path to that drive.
  wchar_t device_path[MAX_PATH] = {'\0'};
  ASSERT_TRUE(
      ::QueryDosDevice(real_drive_letter.c_str(), device_path, MAX_PATH));
  FilePath actual_device_path(device_path);
  FilePath win32_path;

  // Run DevicePathToDriveLetterPath() on the NT style path we got from
  // QueryDosDevice().  Expect the drive letter we started with.
  ASSERT_TRUE(DevicePathToDriveLetterPath(actual_device_path, &win32_path));
  ASSERT_EQ(real_drive_letter, win32_path.value());

  // Add some directories to the path.  Expect those extra path componenets
  // to be preserved.
  FilePath kRelativePath(FPL("dir1\\dir2\\file.txt"));
  ASSERT_TRUE(DevicePathToDriveLetterPath(
      actual_device_path.Append(kRelativePath), &win32_path));
  EXPECT_EQ(FilePath(real_drive_letter + FILE_PATH_LITERAL("\\"))
                .Append(kRelativePath)
                .value(),
            win32_path.value());

  // Deform the real path so that it is invalid by removing the last four
  // characters.  The way windows names devices that are hard disks
  // (\Device\HardDiskVolume${NUMBER}) guarantees that the string is longer
  // than three characters.  The only way the truncated string could be a
  // real drive is if more than 10^3 disks are mounted:
  // \Device\HardDiskVolume10000 would be truncated to \Device\HardDiskVolume1
  // Check that DevicePathToDriveLetterPath fails.
  size_t path_length = actual_device_path.value().length();
  size_t new_length = path_length - 4;
  ASSERT_GT(new_length, 0u);
  FilePath prefix_of_real_device_path(
      actual_device_path.value().substr(0, new_length));
  ASSERT_FALSE(
      DevicePathToDriveLetterPath(prefix_of_real_device_path, &win32_path));

  ASSERT_FALSE(DevicePathToDriveLetterPath(
      prefix_of_real_device_path.Append(kRelativePath), &win32_path));

  // Deform the real path so that it is invalid by adding some characters. For
  // example, if C: maps to \Device\HardDiskVolume8, then we simulate a
  // request for the drive letter whose native path is
  // \Device\HardDiskVolume812345 .  We assume such a device does not exist,
  // because drives are numbered in order and mounting 112345 hard disks will
  // never happen.
  const FilePath::StringType kExtraChars = FPL("12345");

  FilePath real_device_path_plus_numbers(actual_device_path.value() +
                                         kExtraChars);

  ASSERT_FALSE(
      DevicePathToDriveLetterPath(real_device_path_plus_numbers, &win32_path));

  ASSERT_FALSE(DevicePathToDriveLetterPath(
      real_device_path_plus_numbers.Append(kRelativePath), &win32_path));
}

TEST_F(FileUtilTest, AreShortFilePathsEnabled) {
  constexpr FilePath::CharType kLongDirName[] = FPL("A long path");
  FilePath long_test_dir = temp_dir_.GetPath().Append(kLongDirName);
  ASSERT_TRUE(CreateDirectory(long_test_dir));

  FilePath short_test_dir = MakeShortFilePath(long_test_dir);

  // MakeShortFilePath returns the long file path if short paths are not
  // supported. See
  // https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getshortpathnamew.
  ASSERT_EQ(AreShortFilePathsEnabled(), short_test_dir != long_test_dir);
}

TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) {
  if (!AreShortFilePathsEnabled()) {
    GTEST_SKIP() << "Short filepaths are not supported on this system.";
  }
  // Test that CreateTemporaryFileInDir() creates a path and returns a long path
  // if it is available. This test requires that:
  // - the filesystem at |temp_dir_| supports long filenames.
  // - the account has FILE_LIST_DIRECTORY permission for all ancestor
  //   directories of |temp_dir_|.
  constexpr FilePath::CharType kLongDirName[] = FPL("A long path");
  constexpr FilePath::CharType kTestSubDirName[] = FPL("test");
  FilePath long_test_dir = temp_dir_.GetPath().Append(kLongDirName);
  ASSERT_TRUE(CreateDirectory(long_test_dir));

  // kLongDirName is not a 8.3 component. So ::GetShortPathName() should give us
  // a different short name.
  FilePath short_test_dir = MakeShortFilePath(long_test_dir);
  ASSERT_FALSE(short_test_dir.empty());
  ASSERT_NE(kLongDirName, short_test_dir.BaseName().value());

  FilePath temp_file;
  ASSERT_TRUE(CreateTemporaryFileInDir(short_test_dir, &temp_file));
  EXPECT_EQ(kLongDirName, temp_file.DirName().BaseName().value());
  EXPECT_TRUE(PathExists(temp_file));

  // Create a subdirectory of |long_test_dir| and make |long_test_dir|
  // unreadable. We should still be able to create a temp file in the
  // subdirectory, but we won't be able to determine the long path for it. This
  // mimics the environment that some users run where their user profiles reside
  // in a location where the don't have full access to the higher level
  // directories. (Note that this assumption is true for NTFS, but not for some
  // network file systems. E.g. AFS).
  FilePath access_test_dir = long_test_dir.Append(kTestSubDirName);
  ASSERT_TRUE(CreateDirectory(access_test_dir));
  FilePermissionRestorer long_test_dir_restorer(long_test_dir);
  ASSERT_TRUE(MakeFileUnreadable(long_test_dir));

  // Use the short form of the directory to create a temporary filename.
  ASSERT_TRUE(CreateTemporaryFileInDir(short_test_dir.Append(kTestSubDirName),
                                       &temp_file));
  EXPECT_TRUE(PathExists(temp_file));
  EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName()));

  // Check that the long path can't be determined for |temp_file|.
  // Helper method base::MakeLongFilePath returns an empty path on error.
  FilePath temp_file_long = MakeLongFilePath(temp_file);
  ASSERT_TRUE(temp_file_long.empty());
}

TEST_F(FileUtilTest, MakeLongFilePathTest) {
  if (!AreShortFilePathsEnabled()) {
    GTEST_SKIP() << "Short filepaths are not supported on this system.";
  }
  // Tests helper function base::MakeLongFilePath

  // If a username isn't a valid 8.3 short file name (even just a
  // lengthy name like "user with long name"), Windows will set the TMP and TEMP
  // environment variables to be 8.3 paths. ::GetTempPath (called in
  // base::GetTempDir) just uses the value specified by TMP or TEMP, and so can
  // return a short path. So from the start need to use MakeLongFilePath
  // to normalize the path for such test environments.
  FilePath temp_dir_long = MakeLongFilePath(temp_dir_.GetPath());
  ASSERT_FALSE(temp_dir_long.empty());

  FilePath long_test_dir = temp_dir_long.Append(FPL("A long directory name"));
  ASSERT_TRUE(CreateDirectory(long_test_dir));

  // Directory name is not a 8.3 component. So ::GetShortPathName() should give
  // us a different short name.
  FilePath short_test_dir = MakeShortFilePath(long_test_dir);
  ASSERT_FALSE(short_test_dir.empty());

  EXPECT_NE(long_test_dir, short_test_dir);
  EXPECT_EQ(long_test_dir, MakeLongFilePath(short_test_dir));

  FilePath long_test_file = long_test_dir.Append(FPL("A long file name.1234"));
  CreateTextFile(long_test_file, bogus_content);
  ASSERT_TRUE(PathExists(long_test_file));

  // File name is not a 8.3 component. So ::GetShortPathName() should give us
  // a different short name.
  FilePath short_test_file = MakeShortFilePath(long_test_file);
  ASSERT_FALSE(short_test_file.empty());

  EXPECT_NE(long_test_file, short_test_file);
  EXPECT_EQ(long_test_file, MakeLongFilePath(short_test_file));

  // MakeLongFilePath should return empty path if file does not exist.
  EXPECT_TRUE(DeleteFile(short_test_file));
  EXPECT_TRUE(MakeLongFilePath(short_test_file).empty());

  // MakeLongFilePath should return empty path if directory does not exist.
  EXPECT_TRUE(DeleteFile(short_test_dir));
  EXPECT_TRUE(MakeLongFilePath(short_test_dir).empty());
}

TEST_F(FileUtilTest, CreateWinHardlinkTest) {
  // Link to a different file name in a sub-directory of |temp_dir_|.
  FilePath test_dir = temp_dir_.GetPath().Append(FPL("test"));
  ASSERT_TRUE(CreateDirectory(test_dir));
  FilePath temp_file;
  ASSERT_TRUE(CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file));
  FilePath link_to_file = test_dir.Append(FPL("linked_name"));
  EXPECT_TRUE(CreateWinHardLink(link_to_file, temp_file));
  EXPECT_TRUE(PathExists(link_to_file));

  // Link two directories. This should fail. Verify that failure is returned
  // by CreateWinHardLink.
  EXPECT_FALSE(CreateWinHardLink(temp_dir_.GetPath(), test_dir));
}

TEST_F(FileUtilTest, PreventExecuteMappingNewFile) {
  base::test::ScopedFeatureList enforcement_feature;
  enforcement_feature.InitAndEnableFeature(
      features::kEnforceNoExecutableFileHandles);
  FilePath file = temp_dir_.GetPath().Append(FPL("afile.txt"));

  ASSERT_FALSE(PathExists(file));
  {
    File new_file(file, File::FLAG_WRITE | File::FLAG_WIN_NO_EXECUTE |
                            File::FLAG_CREATE_ALWAYS);
    ASSERT_TRUE(new_file.IsValid());
  }

  {
    File open_file(file, File::FLAG_READ | File::FLAG_WIN_EXECUTE |
                             File::FLAG_OPEN_ALWAYS);
    EXPECT_FALSE(open_file.IsValid());
  }
  // Verify the deny ACL did not prevent deleting the file.
  EXPECT_TRUE(DeleteFile(file));
}

TEST_F(FileUtilTest, PreventExecuteMappingExisting) {
  base::test::ScopedFeatureList enforcement_feature;
  enforcement_feature.InitAndEnableFeature(
      features::kEnforceNoExecutableFileHandles);
  FilePath file = temp_dir_.GetPath().Append(FPL("afile.txt"));
  CreateTextFile(file, bogus_content);
  ASSERT_TRUE(PathExists(file));
  {
    File open_file(file, File::FLAG_READ | File::FLAG_WIN_EXECUTE |
                             File::FLAG_OPEN_ALWAYS);
    EXPECT_TRUE(open_file.IsValid());
  }
  EXPECT_TRUE(PreventExecuteMapping(file));
  {
    File open_file(file, File::FLAG_READ | File::FLAG_WIN_EXECUTE |
                             File::FLAG_OPEN_ALWAYS);
    EXPECT_FALSE(open_file.IsValid());
  }
  // Verify the deny ACL did not prevent deleting the file.
  EXPECT_TRUE(DeleteFile(file));
}

TEST_F(FileUtilTest, PreventExecuteMappingOpenFile) {
  base::test::ScopedFeatureList enforcement_feature;
  enforcement_feature.InitAndEnableFeature(
      features::kEnforceNoExecutableFileHandles);
  FilePath file = temp_dir_.GetPath().Append(FPL("afile.txt"));
  CreateTextFile(file, bogus_content);
  ASSERT_TRUE(PathExists(file));
  File open_file(file, File::FLAG_READ | File::FLAG_WRITE |
                           File::FLAG_WIN_EXECUTE | File::FLAG_OPEN_ALWAYS);
  EXPECT_TRUE(open_file.IsValid());
  // Verify ACE can be set even on an open file.
  EXPECT_TRUE(PreventExecuteMapping(file));
  {
    File second_open_file(
        file, File::FLAG_READ | File::FLAG_WRITE | File::FLAG_OPEN_ALWAYS);
    EXPECT_TRUE(second_open_file.IsValid());
  }
  {
    File third_open_file(file, File::FLAG_READ | File::FLAG_WIN_EXECUTE |
                                   File::FLAG_OPEN_ALWAYS);
    EXPECT_FALSE(third_open_file.IsValid());
  }

  open_file.Close();
  // Verify the deny ACL did not prevent deleting the file.
  EXPECT_TRUE(DeleteFile(file));
}

TEST(FileUtilDeathTest, DisallowNoExecuteOnUnsafeFile) {
  base::test::ScopedFeatureList enforcement_feature;
  enforcement_feature.InitAndEnableFeature(
      features::kEnforceNoExecutableFileHandles);
  base::FilePath local_app_data;
  // This test places a file in %LOCALAPPDATA% to verify that the checks in
  // IsPathSafeToSetAclOn work correctly.
  ASSERT_TRUE(
      base::PathService::Get(base::DIR_LOCAL_APP_DATA, &local_app_data));

  base::FilePath file_path;
  EXPECT_DCHECK_DEATH_WITH(
      {
        {
          base::File temp_file =
              base::CreateAndOpenTemporaryFileInDir(local_app_data, &file_path);
        }
        File reopen_file(file_path, File::FLAG_READ | File::FLAG_WRITE |
                                        File::FLAG_WIN_NO_EXECUTE |
                                        File::FLAG_OPEN_ALWAYS |
                                        File::FLAG_DELETE_ON_CLOSE);
      },
      "Unsafe to deny execute access to path");
}

MULTIPROCESS_TEST_MAIN(NoExecuteOnSafeFileMain) {
  base::FilePath temp_file;
  CHECK(base::CreateTemporaryFile(&temp_file));

  // A file with FLAG_WIN_NO_EXECUTE created in temp dir should always be
  // permitted.
  File reopen_file(temp_file, File::FLAG_READ | File::FLAG_WRITE |
                                  File::FLAG_WIN_NO_EXECUTE |
                                  File::FLAG_OPEN_ALWAYS |
                                  File::FLAG_DELETE_ON_CLOSE);
  return 0;
}

TEST_F(FileUtilTest, NoExecuteOnSafeFile) {
  FilePath new_dir;
  ASSERT_TRUE(CreateTemporaryDirInDir(
      temp_dir_.GetPath(), FILE_PATH_LITERAL("NoExecuteOnSafeFileLongPath"),
      &new_dir));

  FilePath short_dir = base::MakeShortFilePath(new_dir);

  LaunchOptions options;
  options.environment[L"TMP"] = short_dir.value();

  CommandLine child_command_line(GetMultiProcessTestChildBaseCommandLine());

  Process child_process = SpawnMultiProcessTestChild(
      "NoExecuteOnSafeFileMain", child_command_line, options);
  ASSERT_TRUE(child_process.IsValid());
  int rv = -1;
  ASSERT_TRUE(WaitForMultiprocessTestChildExit(
      child_process, TestTimeouts::action_timeout(), &rv));
  ASSERT_EQ(0, rv);
}

class FileUtilExecuteEnforcementTest
    : public FileUtilTest,
      public ::testing::WithParamInterface<bool> {
 public:
  FileUtilExecuteEnforcementTest() {
    if (IsEnforcementEnabled()) {
      enforcement_feature_.InitAndEnableFeature(
          features::kEnforceNoExecutableFileHandles);
    } else {
      enforcement_feature_.InitAndDisableFeature(
          features::kEnforceNoExecutableFileHandles);
    }
  }

 protected:
  bool IsEnforcementEnabled() { return GetParam(); }

 private:
  base::test::ScopedFeatureList enforcement_feature_;
};

// This test verifies that if a file has been passed to `PreventExecuteMapping`
// and enforcement is enabled, then it cannot be mapped as executable into
// memory.
TEST_P(FileUtilExecuteEnforcementTest, Functional) {
  FilePath dir_exe;
  EXPECT_TRUE(PathService::Get(DIR_EXE, &dir_exe));
  // This DLL is built as part of base_unittests so is guaranteed to be present.
  FilePath test_dll(dir_exe.Append(FPL("scoped_handle_test_dll.dll")));

  EXPECT_TRUE(base::PathExists(test_dll));

  FilePath dll_copy_path = temp_dir_.GetPath().Append(FPL("test.dll"));

  ASSERT_TRUE(CopyFile(test_dll, dll_copy_path));
  ASSERT_TRUE(PreventExecuteMapping(dll_copy_path));
  ScopedNativeLibrary module(dll_copy_path);

  // If enforcement is enabled, then `PreventExecuteMapping` will have prevented
  // the load, and the module will be invalid.
  EXPECT_EQ(IsEnforcementEnabled(), !module.is_valid());
}

INSTANTIATE_TEST_SUITE_P(EnforcementEnabled,
                         FileUtilExecuteEnforcementTest,
                         ::testing::Values(true));
INSTANTIATE_TEST_SUITE_P(EnforcementDisabled,
                         FileUtilExecuteEnforcementTest,
                         ::testing::Values(false));

#endif  // BUILDFLAG(IS_WIN)

#if BUILDFLAG(IS_POSIX)

TEST_F(FileUtilTest, CreateAndReadSymlinks) {}

TEST_F(FileUtilTest, CreateAndReadRelativeSymlinks) {}

// The following test of NormalizeFilePath() require that we create a symlink.
// This can not be done on Windows before Vista.  On Vista, creating a symlink
// requires privilege "SeCreateSymbolicLinkPrivilege".
// TODO(skerner): Investigate the possibility of giving base_unittests the
// privileges required to create a symlink.
TEST_F(FileUtilTest, NormalizeFilePathSymlinks) {}

TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) {}

TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) {}

TEST_F(FileUtilTest, CopyFileFollowsSymlinks) {}

TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) {}

TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) {}

TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) {}

TEST_F(FileUtilTest, ExecutableExistsInPath) {}

TEST_F(FileUtilTest, CopyDirectoryPermissions) {}

TEST_F(FileUtilTest, CopyDirectoryPermissionsOverExistingFile) {}

TEST_F(FileUtilTest, CopyDirectoryExclDoesNotOverwrite) {}

TEST_F(FileUtilTest, CopyDirectoryExclDirectoryOverExistingFile) {}

TEST_F(FileUtilTest, CopyDirectoryExclDirectoryOverExistingDirectory) {}

TEST_F(FileUtilTest, CopyFileExecutablePermission) {}

#endif  // BUILDFLAG(IS_POSIX)

#if !BUILDFLAG(IS_FUCHSIA)

TEST_F(FileUtilTest, CopyFileACL) {}

TEST_F(FileUtilTest, CopyDirectoryACL) {}

#endif  // !BUILDFLAG(IS_FUCHSIA)

TEST_F(FileUtilTest, DeleteNonExistent) {}

TEST_F(FileUtilTest, DeleteNonExistentWithNonExistentParent) {}

TEST_F(FileUtilTest, DeleteFile) {}

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
TEST_F(FileUtilTest, DeleteDeep) {}
#endif  // BUILDFLAG(IS_POSIX)

#if BUILDFLAG(IS_ANDROID)
TEST_F(FileUtilTest, DeleteContentUri) {
  // Get the path to the test file.
  FilePath data_dir;
  ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir));
  data_dir = data_dir.Append(FPL("file_util"));
  ASSERT_TRUE(PathExists(data_dir));
  FilePath image_file = data_dir.Append(FPL("red.png"));
  ASSERT_TRUE(PathExists(image_file));

  // Make a copy (we don't want to delete the original red.png when deleting the
  // content URI).
  FilePath image_copy = data_dir.Append(FPL("redcopy.png"));
  ASSERT_TRUE(CopyFile(image_file, image_copy));

  // Insert the image into MediaStore and get a content URI.
  FilePath uri_path = InsertImageIntoMediaStore(image_copy);
  ASSERT_TRUE(uri_path.IsContentUri());
  ASSERT_TRUE(PathExists(uri_path));

  // Try deleting the content URI.
  EXPECT_TRUE(DeleteFile(uri_path));
  EXPECT_FALSE(PathExists(image_copy));
  EXPECT_FALSE(PathExists(uri_path));
}
#endif  // BUILDFLAG(IS_ANDROID)

#if BUILDFLAG(IS_WIN)
// Tests that the Delete function works for wild cards, especially
// with the recursion flag.  Also coincidentally tests PathExists.
// TODO(erikkay): see if anyone's actually using this feature of the API
TEST_F(FileUtilTest, DeleteWildCard) {
  // Create a file and a directory
  FilePath file_name =
      temp_dir_.GetPath().Append(FPL("Test DeleteWildCard.txt"));
  CreateTextFile(file_name, bogus_content);
  ASSERT_TRUE(PathExists(file_name));

  FilePath subdir_path = temp_dir_.GetPath().Append(FPL("DeleteWildCardDir"));
  CreateDirectory(subdir_path);
  ASSERT_TRUE(PathExists(subdir_path));

  // Create the wildcard path
  FilePath directory_contents = temp_dir_.GetPath();
  directory_contents = directory_contents.Append(FPL("*"));

  // Delete non-recursively and check that only the file is deleted
  EXPECT_TRUE(DeleteFile(directory_contents));
  EXPECT_FALSE(PathExists(file_name));
  EXPECT_TRUE(PathExists(subdir_path));

  // Delete recursively and make sure all contents are deleted
  EXPECT_TRUE(DeletePathRecursively(directory_contents));
  EXPECT_FALSE(PathExists(file_name));
  EXPECT_FALSE(PathExists(subdir_path));
}

// TODO(erikkay): see if anyone's actually using this feature of the API
TEST_F(FileUtilTest, DeleteNonExistantWildCard) {
  // Create a file and a directory
  FilePath subdir_path =
      temp_dir_.GetPath().Append(FPL("DeleteNonExistantWildCard"));
  CreateDirectory(subdir_path);
  ASSERT_TRUE(PathExists(subdir_path));

  // Create the wildcard path
  FilePath directory_contents = subdir_path;
  directory_contents = directory_contents.Append(FPL("*"));

  // Delete non-recursively and check nothing got deleted
  EXPECT_TRUE(DeleteFile(directory_contents));
  EXPECT_TRUE(PathExists(subdir_path));

  // Delete recursively and check nothing got deleted
  EXPECT_TRUE(DeletePathRecursively(directory_contents));
  EXPECT_TRUE(PathExists(subdir_path));
}
#endif

// Tests non-recursive Delete() for a directory.
TEST_F(FileUtilTest, DeleteDirNonRecursive) {}

// Tests recursive Delete() for a directory.
TEST_F(FileUtilTest, DeleteDirRecursive) {}

// Tests recursive Delete() for a directory.
TEST_F(FileUtilTest, DeleteDirRecursiveWithOpenFile) {}

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// This test will validate that files which would block when read result in a
// failure on a call to ReadFileToStringNonBlocking. To accomplish this we will
// use a named pipe because it appears as a file on disk and we can control how
// much data is available to read. This allows us to simulate a file which would
// block.
TEST_F(FileUtilTest, TestNonBlockingFileReadLinux) {}
#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

TEST_F(FileUtilTest, MoveFileNew) {}

TEST_F(FileUtilTest, MoveFileExists) {}

TEST_F(FileUtilTest, MoveFileDirExists) {}

TEST_F(FileUtilTest, MoveNew) {}

TEST_F(FileUtilTest, MoveExist) {}

TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) {}

TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) {}

TEST_F(FileUtilTest, CopyDirectoryNew) {}

TEST_F(FileUtilTest, CopyDirectoryExists) {}

TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) {}

TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) {}

TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) {}

TEST_F(FileUtilTest, CopyFileFailureWithCopyDirectoryExcl) {}

TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) {}

#if BUILDFLAG(IS_POSIX)
TEST_F(FileUtilTest, CopyDirectoryWithNonRegularFiles) {}

TEST_F(FileUtilTest, CopyDirectoryExclFileOverSymlink) {}

TEST_F(FileUtilTest, CopyDirectoryExclDirectoryOverSymlink) {}

TEST_F(FileUtilTest, CopyDirectoryExclFileOverDanglingSymlink) {}

TEST_F(FileUtilTest, CopyDirectoryExclDirectoryOverDanglingSymlink) {}

TEST_F(FileUtilTest, CopyDirectoryExclFileOverFifo) {}
#endif  // BUILDFLAG(IS_POSIX)

TEST_F(FileUtilTest, CopyFile) {}

// file_util winds up using autoreleased objects on the Mac, so this needs
// to be a PlatformTest.
ReadOnlyFileUtilTest;

TEST_F(ReadOnlyFileUtilTest, ContentsEqual) {}

TEST_F(ReadOnlyFileUtilTest, TextContentsEqual) {}

// We don't need equivalent functionality outside of Windows.
#if BUILDFLAG(IS_WIN)
TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) {
  // Create a directory
  FilePath dir_name_from = temp_dir_.GetPath().Append(
      FILE_PATH_LITERAL("CopyAndDelete_From_Subdir"));
  CreateDirectory(dir_name_from);
  ASSERT_TRUE(PathExists(dir_name_from));

  // Create a file under the directory
  FilePath file_name_from =
      dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt"));
  CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
  ASSERT_TRUE(PathExists(file_name_from));

  // Move the directory by using CopyAndDeleteDirectory
  FilePath dir_name_to =
      temp_dir_.GetPath().Append(FILE_PATH_LITERAL("CopyAndDelete_To_Subdir"));
  FilePath file_name_to =
      dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt"));

  ASSERT_FALSE(PathExists(dir_name_to));

  EXPECT_TRUE(internal::CopyAndDeleteDirectory(dir_name_from, dir_name_to));

  // Check everything has been moved.
  EXPECT_FALSE(PathExists(dir_name_from));
  EXPECT_FALSE(PathExists(file_name_from));
  EXPECT_TRUE(PathExists(dir_name_to));
  EXPECT_TRUE(PathExists(file_name_to));
}

TEST_F(FileUtilTest, GetTempDirTest) {
  const TCHAR* kTmpKey = _T("TMP");
  std::array<const TCHAR*, 5> kTmpValues = {_T(""), _T("C:"), _T("C:\\"),
                                            _T("C:\\tmp"), _T("C:\\tmp\\")};
  // Save the original $TMP.
  size_t original_tmp_size;
  TCHAR* original_tmp;
  ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey));
  // original_tmp may be NULL.

  for (const TCHAR* val : kTmpValues) {
    FilePath path;
    ::_tputenv_s(kTmpKey, val);
    GetTempDir(&path);
    EXPECT_TRUE(path.IsAbsolute())
        << "$TMP=" << val << " result=" << path.value();
  }

  // Restore the original $TMP.
  if (original_tmp) {
    ::_tputenv_s(kTmpKey, original_tmp);
    free(original_tmp);
  } else {
    ::_tputenv_s(kTmpKey, _T(""));
  }
}
#endif  // BUILDFLAG(IS_WIN)

// Test that files opened by OpenFile are not set up for inheritance into child
// procs.
TEST_F(FileUtilTest, OpenFileNoInheritance) {}

TEST_F(FileUtilTest, CreateAndOpenTemporaryFileInDir) {}

TEST_F(FileUtilTest, CreateTemporaryFileTest) {}

TEST_F(FileUtilTest, CreateAndOpenTemporaryStreamTest) {}

TEST_F(FileUtilTest, GetUniquePath) {}

TEST_F(FileUtilTest, GetUniquePathTooManyFiles) {}

TEST_F(FileUtilTest, GetUniquePathWithSuffixFormat) {}

TEST_F(FileUtilTest, FileToFILE) {}

TEST_F(FileUtilTest, FILEToFile) {}

TEST_F(FileUtilTest, CreateNewTempDirectoryTest) {}

#if BUILDFLAG(IS_WIN)
TEST_F(FileUtilTest, TempDirectoryParentTest) {
  if (!::IsUserAnAdmin()) {
    GTEST_SKIP() << "This test must be run by an admin user";
  }
  FilePath temp_dir;
  ASSERT_TRUE(CreateNewTempDirectory(FilePath::StringType(), &temp_dir));
  EXPECT_TRUE(PathExists(temp_dir));

  FilePath expected_parent_dir;
  if (!::IsUserAnAdmin() ||
      !PathService::Get(DIR_SYSTEM_TEMP, &expected_parent_dir)) {
    EXPECT_TRUE(PathService::Get(DIR_TEMP, &expected_parent_dir));
  }
  EXPECT_TRUE(expected_parent_dir.IsParent(temp_dir));
  EXPECT_TRUE(DeleteFile(temp_dir));
}
#endif  // BUILDFLAG(IS_WIN)

TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) {}

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
TEST_F(FileUtilTest, GetShmemTempDirTest) {}

TEST_F(FileUtilTest, AllocateFileRegionTest_ZeroOffset) {}

TEST_F(FileUtilTest, AllocateFileRegionTest_NonZeroOffset) {}

TEST_F(FileUtilTest, AllocateFileRegionTest_DontTruncate) {}
#endif

TEST_F(FileUtilTest, GetHomeDirTest) {}

TEST_F(FileUtilTest, CreateDirectoryTest) {}

TEST_F(FileUtilTest, DetectDirectoryTest) {}

TEST_F(FileUtilTest, FileEnumeratorTest) {}

TEST_F(FileUtilTest, AppendToFile) {}

TEST_F(FileUtilTest, ReadFile) {}

TEST_F(FileUtilTest, ReadFileToBytes) {}

TEST_F(FileUtilTest, ReadFileToString) {}

#if !BUILDFLAG(IS_WIN)
TEST_F(FileUtilTest, ReadFileToStringWithUnknownFileSize) {}
#endif  // !BUILDFLAG(IS_WIN)

#if !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_FUCHSIA) && \
    !BUILDFLAG(IS_IOS)
#define ChildMain
#define ChildMainString

MULTIPROCESS_TEST_MAIN(ChildMain) {}

#define MoreThanBufferSizeChildMain
#define MoreThanBufferSizeChildMainString

MULTIPROCESS_TEST_MAIN(MoreThanBufferSizeChildMain) {}

TEST_F(FileUtilTest, ReadFileToStringWithNamedPipe) {}
#endif  // !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_FUCHSIA)
        // && !BUILDFLAG(IS_IOS)

#if BUILDFLAG(IS_WIN)
#define ChildMain
#define ChildMainString

MULTIPROCESS_TEST_MAIN(ChildMain) {
  const char kTestData[] = "0123";
  CommandLine* command_line = CommandLine::ForCurrentProcess();
  const FilePath pipe_path = command_line->GetSwitchValuePath("pipe-path");
  std::string switch_string = command_line->GetSwitchValueASCII("sync_event");
  EXPECT_FALSE(switch_string.empty());
  unsigned int switch_uint = 0;
  EXPECT_TRUE(StringToUint(switch_string, &switch_uint));
  win::ScopedHandle sync_event(win::Uint32ToHandle(switch_uint));

  HANDLE ph = CreateNamedPipe(pipe_path.value().c_str(), PIPE_ACCESS_OUTBOUND,
                              PIPE_WAIT, 1, 0, 0, 0, NULL);
  EXPECT_NE(ph, INVALID_HANDLE_VALUE);
  EXPECT_TRUE(SetEvent(sync_event.get()));
  if (!::ConnectNamedPipe(ph, /*lpOverlapped=*/nullptr)) {
    // ERROR_PIPE_CONNECTED means that the other side has already connected.
    auto error = ::GetLastError();
    EXPECT_EQ(error, DWORD{ERROR_PIPE_CONNECTED});
  }

  DWORD written;
  EXPECT_TRUE(::WriteFile(ph, kTestData, strlen(kTestData), &written, NULL));
  EXPECT_EQ(strlen(kTestData), written);
  CloseHandle(ph);
  return 0;
}

#define MoreThanBufferSizeChildMain
#define MoreThanBufferSizeChildMainString

MULTIPROCESS_TEST_MAIN(MoreThanBufferSizeChildMain) {
  std::string data(kLargeFileSize, 'c');
  CommandLine* command_line = CommandLine::ForCurrentProcess();
  const FilePath pipe_path = command_line->GetSwitchValuePath("pipe-path");
  std::string switch_string = command_line->GetSwitchValueASCII("sync_event");
  EXPECT_FALSE(switch_string.empty());
  unsigned int switch_uint = 0;
  EXPECT_TRUE(StringToUint(switch_string, &switch_uint));
  win::ScopedHandle sync_event(win::Uint32ToHandle(switch_uint));

  HANDLE ph = CreateNamedPipe(pipe_path.value().c_str(), PIPE_ACCESS_OUTBOUND,
                              PIPE_WAIT, 1, data.size(), data.size(), 0, NULL);
  EXPECT_NE(ph, INVALID_HANDLE_VALUE);
  EXPECT_TRUE(SetEvent(sync_event.get()));
  if (!::ConnectNamedPipe(ph, /*lpOverlapped=*/nullptr)) {
    // ERROR_PIPE_CONNECTED means that the other side has already connected.
    auto error = ::GetLastError();
    EXPECT_EQ(error, DWORD{ERROR_PIPE_CONNECTED});
  }

  DWORD written;
  EXPECT_TRUE(::WriteFile(ph, data.c_str(), data.size(), &written, NULL));
  EXPECT_EQ(data.size(), written);
  CloseHandle(ph);
  return 0;
}

TEST_F(FileUtilTest, ReadFileToStringWithNamedPipe) {
  FilePath pipe_path(FILE_PATH_LITERAL("\\\\.\\pipe\\test_pipe"));
  win::ScopedHandle sync_event(CreateEvent(0, false, false, nullptr));

  CommandLine child_command_line(GetMultiProcessTestChildBaseCommandLine());
  child_command_line.AppendSwitchPath("pipe-path", pipe_path);
  child_command_line.AppendSwitchASCII(
      "sync_event", NumberToString(win::HandleToUint32(sync_event.get())));

  LaunchOptions options;
  options.handles_to_inherit.push_back(sync_event.get());

  {
    Process child_process = SpawnMultiProcessTestChild(
        ChildMainString, child_command_line, options);
    ASSERT_TRUE(child_process.IsValid());
    // Wait for pipe creation in child process.
    EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(sync_event.get(), INFINITE));

    std::string data = "temp";
    EXPECT_FALSE(ReadFileToStringWithMaxSize(pipe_path, &data, 2));
    EXPECT_EQ("01", data);

    int rv = -1;
    ASSERT_TRUE(WaitForMultiprocessTestChildExit(
        child_process, TestTimeouts::action_timeout(), &rv));
    ASSERT_EQ(0, rv);
  }
  {
    Process child_process = SpawnMultiProcessTestChild(
        ChildMainString, child_command_line, options);
    ASSERT_TRUE(child_process.IsValid());
    // Wait for pipe creation in child process.
    EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(sync_event.get(), INFINITE));

    std::string data = "temp";
    EXPECT_TRUE(ReadFileToStringWithMaxSize(pipe_path, &data, 6));
    EXPECT_EQ("0123", data);

    int rv = -1;
    ASSERT_TRUE(WaitForMultiprocessTestChildExit(
        child_process, TestTimeouts::action_timeout(), &rv));
    ASSERT_EQ(0, rv);
  }
  {
    Process child_process = SpawnMultiProcessTestChild(
        MoreThanBufferSizeChildMainString, child_command_line, options);
    ASSERT_TRUE(child_process.IsValid());
    // Wait for pipe creation in child process.
    EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(sync_event.get(), INFINITE));

    std::string data = "temp";
    EXPECT_FALSE(ReadFileToStringWithMaxSize(pipe_path, &data, 6));
    EXPECT_EQ("cccccc", data);

    int rv = -1;
    ASSERT_TRUE(WaitForMultiprocessTestChildExit(
        child_process, TestTimeouts::action_timeout(), &rv));
    ASSERT_EQ(0, rv);
  }
  {
    Process child_process = SpawnMultiProcessTestChild(
        MoreThanBufferSizeChildMainString, child_command_line, options);
    ASSERT_TRUE(child_process.IsValid());
    // Wait for pipe creation in child process.
    EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(sync_event.get(), INFINITE));

    std::string data = "temp";
    EXPECT_FALSE(
        ReadFileToStringWithMaxSize(pipe_path, &data, kLargeFileSize - 1));
    EXPECT_EQ(std::string(kLargeFileSize - 1, 'c'), data);

    int rv = -1;
    ASSERT_TRUE(WaitForMultiprocessTestChildExit(
        child_process, TestTimeouts::action_timeout(), &rv));
    ASSERT_EQ(0, rv);
  }
  {
    Process child_process = SpawnMultiProcessTestChild(
        MoreThanBufferSizeChildMainString, child_command_line, options);
    ASSERT_TRUE(child_process.IsValid());
    // Wait for pipe creation in child process.
    EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(sync_event.get(), INFINITE));

    std::string data = "temp";
    EXPECT_TRUE(ReadFileToStringWithMaxSize(pipe_path, &data, kLargeFileSize));
    EXPECT_EQ(std::string(kLargeFileSize, 'c'), data);

    int rv = -1;
    ASSERT_TRUE(WaitForMultiprocessTestChildExit(
        child_process, TestTimeouts::action_timeout(), &rv));
    ASSERT_EQ(0, rv);
  }
  {
    Process child_process = SpawnMultiProcessTestChild(
        MoreThanBufferSizeChildMainString, child_command_line, options);
    ASSERT_TRUE(child_process.IsValid());
    // Wait for pipe creation in child process.
    EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(sync_event.get(), INFINITE));

    std::string data = "temp";
    EXPECT_TRUE(
        ReadFileToStringWithMaxSize(pipe_path, &data, kLargeFileSize * 5));
    EXPECT_EQ(std::string(kLargeFileSize, 'c'), data);

    int rv = -1;
    ASSERT_TRUE(WaitForMultiprocessTestChildExit(
        child_process, TestTimeouts::action_timeout(), &rv));
    ASSERT_EQ(0, rv);
  }
}
#endif  // BUILDFLAG(IS_WIN)

#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
TEST_F(FileUtilTest, ReadFileToStringWithProcFileSystem) {}
#endif  // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)

TEST_F(FileUtilTest, ReadFileToStringWithLargeFile) {}

TEST_F(FileUtilTest, ReadStreamToString) {}

#if BUILDFLAG(IS_POSIX)
TEST_F(FileUtilTest, ReadStreamToString_ZeroLengthFile) {}
#endif

TEST_F(FileUtilTest, ReadStreamToStringWithMaxSize) {}

TEST_F(FileUtilTest, ReadStreamToStringNullStream) {}

TEST_F(FileUtilTest, TouchFile) {}

TEST_F(FileUtilTest, WriteFileSpanVariant) {}

TEST_F(FileUtilTest, WriteFileStringVariant) {}

TEST_F(FileUtilTest, IsDirectoryEmpty) {}

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

TEST_F(FileUtilTest, SetNonBlocking) {}

TEST_F(FileUtilTest, SetCloseOnExec) {}

#endif

#if BUILDFLAG(IS_MAC)

// Testing VerifyPathControlledByAdmin() is hard, because there is no
// way a test can make a file owned by root, or change file paths
// at the root of the file system.  VerifyPathControlledByAdmin()
// is implemented as a call to VerifyPathControlledByUser, which gives
// us the ability to test with paths under the test's temp directory,
// using a user id we control.
// Pull tests of VerifyPathControlledByUserTest() into a separate test class
// with a common SetUp() method.
class VerifyPathControlledByUserTest : public FileUtilTest {
 protected:
  void SetUp() override {
    FileUtilTest::SetUp();

    // Create a basic structure used by each test.
    // base_dir_
    //  |-> sub_dir_
    //       |-> text_file_

    base_dir_ = temp_dir_.GetPath().AppendASCII("base_dir");
    ASSERT_TRUE(CreateDirectory(base_dir_));

    sub_dir_ = base_dir_.AppendASCII("sub_dir");
    ASSERT_TRUE(CreateDirectory(sub_dir_));

    text_file_ = sub_dir_.AppendASCII("file.txt");
    CreateTextFile(text_file_, L"This text file has some text in it.");

    // Get the user and group files are created with from |base_dir_|.
    stat_wrapper_t stat_buf;
    ASSERT_EQ(0, File::Stat(base_dir_, &stat_buf));
    uid_ = stat_buf.st_uid;
    ok_gids_.insert(stat_buf.st_gid);
    bad_gids_.insert(stat_buf.st_gid + 1);

    ASSERT_EQ(uid_, getuid());  // This process should be the owner.

    // To ensure that umask settings do not cause the initial state
    // of permissions to be different from what we expect, explicitly
    // set permissions on the directories we create.
    // Make all files and directories non-world-writable.

    // Users and group can read, write, traverse
    int enabled_permissions =
        FILE_PERMISSION_USER_MASK | FILE_PERMISSION_GROUP_MASK;
    // Other users can't read, write, traverse
    int disabled_permissions = FILE_PERMISSION_OTHERS_MASK;

    ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(
        base_dir_, enabled_permissions, disabled_permissions));
    ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(
        sub_dir_, enabled_permissions, disabled_permissions));
  }

  FilePath base_dir_;
  FilePath sub_dir_;
  FilePath text_file_;
  uid_t uid_;

  std::set<gid_t> ok_gids_;
  std::set<gid_t> bad_gids_;
};

TEST_F(VerifyPathControlledByUserTest, BadPaths) {
  // File does not exist.
  FilePath does_not_exist =
      base_dir_.AppendASCII("does").AppendASCII("not").AppendASCII("exist");
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, does_not_exist, uid_, ok_gids_));

  // |base| not a subpath of |path|.
  EXPECT_FALSE(VerifyPathControlledByUser(sub_dir_, base_dir_, uid_, ok_gids_));

  // An empty base path will fail to be a prefix for any path.
  FilePath empty;
  EXPECT_FALSE(VerifyPathControlledByUser(empty, base_dir_, uid_, ok_gids_));

  // Finding that a bad call fails proves nothing unless a good call succeeds.
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
}

TEST_F(VerifyPathControlledByUserTest, Symlinks) {
  // Symlinks in the path should cause failure.

  // Symlink to the file at the end of the path.
  FilePath file_link = base_dir_.AppendASCII("file_link");
  ASSERT_TRUE(CreateSymbolicLink(text_file_, file_link))
      << "Failed to create symlink.";

  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, file_link, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(file_link, file_link, uid_, ok_gids_));

  // Symlink from one directory to another within the path.
  FilePath link_to_sub_dir = base_dir_.AppendASCII("link_to_sub_dir");
  ASSERT_TRUE(CreateSymbolicLink(sub_dir_, link_to_sub_dir))
      << "Failed to create symlink.";

  FilePath file_path_with_link = link_to_sub_dir.AppendASCII("file.txt");
  ASSERT_TRUE(PathExists(file_path_with_link));

  EXPECT_FALSE(VerifyPathControlledByUser(base_dir_, file_path_with_link, uid_,
                                          ok_gids_));

  EXPECT_FALSE(VerifyPathControlledByUser(link_to_sub_dir, file_path_with_link,
                                          uid_, ok_gids_));

  // Symlinks in parents of base path are allowed.
  EXPECT_TRUE(VerifyPathControlledByUser(file_path_with_link,
                                         file_path_with_link, uid_, ok_gids_));
}

TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) {
  // Get a uid that is not the uid of files we create.
  uid_t bad_uid = uid_ + 1;

  // Make all files and directories non-world-writable.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH));
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH));
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(text_file_, 0u, S_IWOTH));

  // We control these paths.
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  // Another user does not control these paths.
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, sub_dir_, bad_uid, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, bad_uid, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(sub_dir_, text_file_, bad_uid, ok_gids_));

  // Another group does not control the paths.
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, bad_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, bad_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, bad_gids_));
}

TEST_F(VerifyPathControlledByUserTest, GroupWriteTest) {
  // Make all files and directories writable only by their owner.
  ASSERT_NO_FATAL_FAILURE(
      ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH | S_IWGRP));
  ASSERT_NO_FATAL_FAILURE(
      ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH | S_IWGRP));
  ASSERT_NO_FATAL_FAILURE(
      ChangePosixFilePermissions(text_file_, 0u, S_IWOTH | S_IWGRP));

  // Any group is okay because the path is not group-writable.
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, bad_gids_));
  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, bad_gids_));
  EXPECT_TRUE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, bad_gids_));

  // No group is okay, because we don't check the group
  // if no group can write.
  std::set<gid_t> no_gids;  // Empty set of gids.
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, no_gids));
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, text_file_, uid_, no_gids));
  EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, no_gids));

  // Make all files and directories writable by their group.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(base_dir_, S_IWGRP, 0u));
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(sub_dir_, S_IWGRP, 0u));
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(text_file_, S_IWGRP, 0u));

  // Now |ok_gids_| works, but |bad_gids_| fails.
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, bad_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, bad_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, bad_gids_));

  // Because any group in the group set is allowed,
  // the union of good and bad gids passes.

  std::set<gid_t> multiple_gids;
  std::set_union(ok_gids_.begin(), ok_gids_.end(), bad_gids_.begin(),
                 bad_gids_.end(),
                 std::inserter(multiple_gids, multiple_gids.begin()));

  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, multiple_gids));
  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, multiple_gids));
  EXPECT_TRUE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, multiple_gids));
}

TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) {
  // Make all files and directories non-world-writable.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH));
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH));
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(text_file_, 0u, S_IWOTH));

  // Initialy, we control all parts of the path.
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  // Make base_dir_ world-writable.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u));
  EXPECT_FALSE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  // Make sub_dir_ world writable.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(sub_dir_, S_IWOTH, 0u));
  EXPECT_FALSE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  // Make text_file_ world writable.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(text_file_, S_IWOTH, 0u));
  EXPECT_FALSE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  // Make sub_dir_ non-world writable.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH));
  EXPECT_FALSE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  // Make base_dir_ non-world-writable.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH));
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_FALSE(
      VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));

  // Back to the initial state: Nothing is writable, so every path
  // should pass.
  ASSERT_NO_FATAL_FAILURE(ChangePosixFilePermissions(text_file_, 0u, S_IWOTH));
  EXPECT_TRUE(VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, ok_gids_));
  EXPECT_TRUE(
      VerifyPathControlledByUser(base_dir_, text_file_, uid_, ok_gids_));
  EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));
}

#endif  // BUILDFLAG(IS_MAC)

// Flaky test: crbug/1054637
#if BUILDFLAG(IS_ANDROID)
TEST_F(FileUtilTest, DISABLED_ValidContentUriTest) {
  // Get the test image path.
  FilePath data_dir;
  ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir));
  data_dir = data_dir.AppendASCII("file_util");
  ASSERT_TRUE(PathExists(data_dir));
  FilePath image_file = data_dir.Append(FILE_PATH_LITERAL("red.png"));
  int64_t image_size;
  GetFileSize(image_file, &image_size);
  ASSERT_GT(image_size, 0);

  // Insert the image into MediaStore. MediaStore will do some conversions, and
  // return the content URI.
  FilePath path = InsertImageIntoMediaStore(image_file);
  EXPECT_TRUE(path.IsContentUri());
  EXPECT_TRUE(PathExists(path));
  // The file size may not equal to the input image as MediaStore may convert
  // the image.
  int64_t content_uri_size;
  GetFileSize(path, &content_uri_size);
  EXPECT_EQ(image_size, content_uri_size);

  // We should be able to read the file.
  File file = OpenContentUri(path, File::FLAG_OPEN | File::FLAG_READ);
  EXPECT_TRUE(file.IsValid());
  auto buffer = std::make_unique<char[]>(image_size);
  // SAFETY: required for test.
  EXPECT_TRUE(UNSAFE_BUFFERS(file.ReadAtCurrentPos(buffer.get(), image_size)));

  // We should be able to open the file as writable.
  file = OpenContentUri(path, File::FLAG_CREATE_ALWAYS | File::FLAG_WRITE);
  EXPECT_TRUE(file.IsValid());
}

TEST_F(FileUtilTest, NonExistentContentUriTest) {
  FilePath path("content://foo.bar");
  EXPECT_TRUE(path.IsContentUri());
  EXPECT_FALSE(PathExists(path));
  // Size should be smaller than 0.
  int64_t size;
  EXPECT_FALSE(GetFileSize(path, &size));

  // We should not be able to read the file.
  File file = OpenContentUri(path, File::FLAG_OPEN | File::FLAG_READ);
  EXPECT_FALSE(file.IsValid());
}
#endif

#if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) && \
    defined(ARCH_CPU_32_BITS)
// TODO(crbug.com/327582285): Re-enable these tests. They may be failing due to
// prefetching failing under memory pressure.
#define FLAKY_327582285
#endif

#if defined(FLAKY_327582285)
#define MAYBE_PreReadFileExistingFileNoSize
#else
#define MAYBE_PreReadFileExistingFileNoSize
#endif
TEST_F(FileUtilTest, MAYBE_PreReadFileExistingFileNoSize) {}

#if defined(FLAKY_327582285)
#define MAYBE_PreReadFileExistingFileExactSize
#else
#define MAYBE_PreReadFileExistingFileExactSize
#endif
TEST_F(FileUtilTest, MAYBE_PreReadFileExistingFileExactSize) {}

#if defined(FLAKY_327582285)
#define MAYBE_PreReadFileExistingFileOverSized
#else
#define MAYBE_PreReadFileExistingFileOverSized
#endif
TEST_F(FileUtilTest, MAYBE_PreReadFileExistingFileOverSized) {}

#if defined(FLAKY_327582285)
#define MAYBE_PreReadFileExistingFileUnderSized
#else
#define MAYBE_PreReadFileExistingFileUnderSized
#endif
TEST_F(FileUtilTest, MAYBE_PreReadFileExistingFileUnderSized) {}

TEST_F(FileUtilTest, PreReadFileExistingFileZeroSize) {}

TEST_F(FileUtilTest, PreReadFileExistingEmptyFileNoSize) {}

TEST_F(FileUtilTest, PreReadFileExistingEmptyFileZeroSize) {}

TEST_F(FileUtilTest, PreReadFileInexistentFile) {}

#if defined(FLAKY_327582285)
#define MAYBE_PreReadFileExecutable
#else
#define MAYBE_PreReadFileExecutable
#endif
TEST_F(FileUtilTest, MAYBE_PreReadFileExecutable) {}

#if defined(FLAKY_327582285)
#define MAYBE_PreReadFileWithSequentialAccess
#else
#define MAYBE_PreReadFileWithSequentialAccess
#endif
TEST_F(FileUtilTest, MAYBE_PreReadFileWithSequentialAccess) {}

#undef FLAKY_327582285

// Test that temp files obtained racily are all unique (no interference between
// threads). Mimics file operations in DoLaunchChildTestProcess() to rule out
// thread-safety issues @ https://crbug.com/826408#c17.
TEST(FileUtilMultiThreadedTest, MultiThreadedTempFiles) {}

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

TEST(ScopedFD, ScopedFDDoesClose) {}

#if defined(GTEST_HAS_DEATH_TEST)
void CloseWithScopedFD(int fd) {}
#endif

TEST(ScopedFD, ScopedFDCrashesOnCloseFailure) {}

#endif  // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
TEST_F(FileUtilTest, CopyFileContentsWithSendfile) {}

TEST_F(FileUtilTest, CopyFileContentsWithSendfileEmpty) {}

TEST_F(FileUtilTest, CopyFileContentsWithSendfilePipe) {}

TEST_F(FileUtilTest, CopyFileContentsWithSendfileSocket) {}

TEST_F(FileUtilTest, CopyFileContentsWithSendfileSeqFile) {}

#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
        // BUILDFLAG(IS_ANDROID)

}  // namespace

}  // namespace base