Bug 1745352 - Remove osfile.jsm from browser/components/extensions r=mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D133843
This commit is contained in:
Barret Rennie 2022-01-25 12:16:17 +00:00
Родитель 7eb153953c
Коммит 0a8aa2c5d4
2 изменённых файлов: 50 добавлений и 31 удалений

Просмотреть файл

@ -7,7 +7,6 @@
XPCOMUtils.defineLazyModuleGetters(this, {
ctypes: "resource://gre/modules/ctypes.jsm",
NativeManifests: "resource://gre/modules/NativeManifests.jsm",
OS: "resource://gre/modules/osfile.jsm",
});
XPCOMUtils.defineLazyServiceGetter(
@ -17,6 +16,9 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIPKCS11ModuleDB"
);
// eslint-disable-next-line mozilla/reject-importGlobalProperties
Cu.importGlobalProperties(["PathUtils"]);
var { DefaultMap } = ExtensionUtils;
const findModuleByPath = function(path) {
@ -38,12 +40,18 @@ this.pkcs11 = class extends ExtensionAPI {
);
if (hostInfo) {
if (AppConstants.platform === "win") {
hostInfo.manifest.path = OS.Path.join(
OS.Path.dirname(hostInfo.path),
hostInfo.manifest.path
);
// If the path specified in the manifest is not an abslute path,
// translate it relative to manifest's directory.
if (!PathUtils.isAbsolute(hostInfo.manifest.path)) {
hostInfo.manifest.path = PathUtils.normalize(
PathUtils.joinRelative(
PathUtils.parent(hostInfo.path),
hostInfo.manifest.path
)
);
}
}
let manifestLib = OS.Path.basename(hostInfo.manifest.path);
let manifestLib = PathUtils.filename(hostInfo.manifest.path);
if (AppConstants.platform !== "linux") {
manifestLib = manifestLib.toLowerCase(manifestLib);
}

Просмотреть файл

@ -3,28 +3,39 @@
XPCOMUtils.defineLazyModuleGetters(this, {
ctypes: "resource://gre/modules/ctypes.jsm",
MockRegistry: "resource://testing-common/MockRegistry.jsm",
OS: "resource://gre/modules/osfile.jsm",
});
do_get_profile();
let tmpDir = FileUtils.getDir("TmpD", ["PKCS11"]);
let tmpDir;
let baseDir;
let slug =
AppConstants.platform === "linux" ? "pkcs11-modules" : "PKCS11Modules";
tmpDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
let baseDir = OS.Path.join(tmpDir.path, slug);
OS.File.makeDir(baseDir);
registerCleanupFunction(() => {
tmpDir.remove(true);
add_task(async function setupTest() {
tmpDir = await IOUtils.createUniqueDirectory(
Services.dirsvc.get("TmpD", Ci.nsIFile).path,
"PKCS11"
);
baseDir = PathUtils.join(tmpDir, slug);
await IOUtils.makeDirectory(baseDir);
});
function getPath(filename) {
return OS.Path.join(baseDir, filename);
}
registerCleanupFunction(async () => {
await IOUtils.remove(tmpDir, { recursive: true });
});
const testmodule =
"../../../../../security/manager/ssl/tests/unit/pkcs11testmodule/" +
ctypes.libraryName("pkcs11testmodule");
const testmodule = PathUtils.join(
PathUtils.parent(Services.dirsvc.get("CurWorkD", Ci.nsIFile).path, 5),
"security",
"manager",
"ssl",
"tests",
"unit",
"pkcs11testmodule",
ctypes.libraryName("pkcs11testmodule")
);
// This function was inspired by the native messaging test under
// toolkit/components/extensions
@ -39,8 +50,8 @@ async function setupManifests(modules) {
allowed_extensions: [module.id],
};
let manifestPath = getPath(`${module.name}.json`);
await OS.File.writeAtomic(manifestPath, JSON.stringify(manifest));
let manifestPath = PathUtils.join(baseDir, `${module.name}.json`);
await IOUtils.writeJSON(manifestPath, manifest);
return manifestPath;
}
@ -50,10 +61,11 @@ async function setupManifests(modules) {
case "linux":
let dirProvider = {
getFile(property) {
if (property == "XREUserNativeManifests") {
return tmpDir.clone();
} else if (property == "XRESysNativeManifests") {
return tmpDir.clone();
if (
property == "XREUserNativeManifests" ||
property == "XRESysNativeManifests"
) {
return new FileUtils.File(tmpDir);
}
return null;
},
@ -78,10 +90,6 @@ async function setupManifests(modules) {
});
for (let module of modules) {
if (!OS.Path.winIsAbsolute(module.path)) {
let cwd = await OS.File.getCurrentDirectory();
module.path = OS.Path.join(cwd, module.path);
}
let manifestPath = await writeManifest(module);
registry.setValue(
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
@ -248,13 +256,16 @@ add_task(async function test_pkcs11() {
{
name: "internalmodule",
description: "Builtin Roots Module",
path: ctypes.libraryName("nssckbi"),
path: PathUtils.join(
Services.dirsvc.get("CurWorkD", Ci.nsIFile).path,
ctypes.libraryName("nssckbi")
),
id: "pkcs11@tests.mozilla.org",
},
{
name: "osclientcerts",
description: "OS Client Cert Module",
path: OS.Path.join(libDir.path, ctypes.libraryName("osclientcerts")),
path: PathUtils.join(libDir.path, ctypes.libraryName("osclientcerts")),
id: "pkcs11@tests.mozilla.org",
},
]);