chromium/extensions/common/file_util_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "extensions/common/file_util.h"

#include <stddef.h>

#include <optional>
#include <string_view>
#include <utility>

#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/values_test_util.h"
#include "base/types/optional_ref.h"
#include "base/values.h"
#include "build/build_config.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_paths.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/strings/grit/extensions_strings.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"

ManifestLocation;

namespace extensions {

namespace {

constexpr char kManifestContent[] =;
constexpr char kExtensionId[] =;

const char kCustomManifest[] =;
const base::FilePath::CharType kCustomManifestFilename[] =);

scoped_refptr<Extension> LoadExtensionManifest(
    const base::Value::Dict& manifest,
    const base::FilePath& manifest_dir,
    ManifestLocation location,
    int extra_flags,
    std::string* error) {}

scoped_refptr<Extension> LoadExtensionManifest(
    const std::string& manifest_value,
    const base::FilePath& manifest_dir,
    ManifestLocation location,
    int extra_flags,
    std::string* error) {}

void RunUnderscoreDirectoriesTest(
    const std::vector<std::string>& underscore_directories) {}

struct UninstallTestData {};

const std::vector<UninstallTestData>& GetTestData() {}

}  // namespace

FileUtilTest;

// Tests that packed extensions have all their versions deleted when the
// extension is uninstalled.
TEST_F(FileUtilTest, UninstallRemovesAllPackedExtensionVersions) {}

TEST_F(FileUtilTest, LoadExtensionWithMetadataFolder) {}

TEST_F(FileUtilTest, LoadExtensionWithUnderscoreFolder) {}

TEST_F(FileUtilTest, LoadExtensionWithUnderscoreAndMetadataFolder) {}

TEST_F(FileUtilTest, LoadExtensionWithValidLocales) {}

TEST_F(FileUtilTest, LoadExtensionWithGzippedLocalesAllowed) {}

TEST_F(FileUtilTest, LoadExtensionWithGzippedLocalesNotAllowed) {}

TEST_F(FileUtilTest, LoadExtensionWithoutLocalesFolder) {}

TEST_F(FileUtilTest, CheckIllegalFilenamesNoUnderscores) {}

TEST_F(FileUtilTest, CheckIllegalFilenamesOnlyReserved) {}

TEST_F(FileUtilTest, CheckIllegalFilenamesReservedAndIllegal) {}

// These tests do not work on Windows, because it is illegal to create a
// file/directory with a Windows reserved name. Because we cannot create a
// file that will cause the test to fail, let's skip the test.
#if !BUILDFLAG(IS_WIN)
TEST_F(FileUtilTest, CheckIllegalFilenamesDirectoryWindowsReserved) {}

TEST_F(FileUtilTest,
       CheckIllegalFilenamesWindowsReservedFilenameWithExtension) {}
#endif

TEST_F(FileUtilTest, LoadExtensionGivesHelpfullErrorOnMissingManifest) {}

TEST_F(FileUtilTest, LoadExtensionGivesHelpfullErrorOnBadManifest) {}

TEST_F(FileUtilTest, ValidateThemeUTF8) {}

TEST_F(FileUtilTest, BackgroundScriptsMustExist) {}

// Private key, generated by Chrome specifically for this test, and
// never used elsewhere.
constexpr std::string_view private_key =;

TEST_F(FileUtilTest, FindPrivateKeyFiles) {}

TEST_F(FileUtilTest, WarnOnPrivateKey) {}

// Specify a file other than manifest.json
TEST_F(FileUtilTest, SpecifyManifestFile) {}

// Try to install an extension with a zero-length icon file.
TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFile) {}

// Try to install an unpacked extension with a zero-length icon file.
TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFileUnpacked) {}

// Try to install an unpacked extension with an invisible icon. This
// should fail.
TEST_F(FileUtilTest, CheckInvisibleIconFileUnpacked) {}

// Try to install a packed extension with an invisible icon. This should
// succeed.
TEST_F(FileUtilTest, CheckInvisibleIconFilePacked) {}

TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) {}

class UninstallTest : public testing::Test {};

bool UninstallTest::SetupExtensionsDirForUninstall() {}

bool UninstallTest::ExtensionDirectoryDeleted() {}

bool UninstallTest::ExtensionDirectoryNotDeleted() {}

class UninstallTestParameterized
    : public UninstallTest,
      public testing::WithParamInterface<UninstallTestData> {};

// TODO(crbug.com/40875193): Create a custom test name generator that is more
// readable.
// go/gunitadvanced#specifying-names-for-value-parameterized-test-parameters
INSTANTIATE_TEST_SUITE_P();

TEST_P(UninstallTestParameterized, UninstallDirectory) {}

// Tests when the extensions install directory is outside of the profile
// directory.
TEST_F(UninstallTest,
       UninstallDirectory_ExtensionsInstallDirNotSubdirOfProfileDir) {}

// Tests when the extension directory to delete is outside of the extensions
// install directory.
TEST_F(
    UninstallTest,
    UninstallDirectory_ExtensionsDirToDeleteNotSubdirOfExtensionsInstallDir) {}

}  // namespace extensions