Bug 1747468 - Remove FileUtils.getFile from devtools/ r=devtools-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D180461
This commit is contained in:
Barret Rennie 2023-06-15 01:59:11 +00:00
parent 858e5c3440
commit f25dfce61d
17 changed files with 55 additions and 28 deletions

View File

@ -125,9 +125,9 @@ add_task(async function testSimpleSourcesWithManualClickExpand() {
// Before trigerring the menu, mock the file picker
const MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
const nsiFile = FileUtils.getFile("TmpD", [
`export_source_content_${Date.now()}.log`,
]);
const nsiFile = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, `export_source_content_${Date.now()}.log`)
);
MockFilePicker.setFiles([nsiFile]);
const path = nsiFile.path;

View File

@ -71,7 +71,9 @@ add_task(async function () {
info("Select test.js tree node, and add override");
const MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
const nsiFile = FileUtils.getFile("TmpD", [`test.js`]);
const nsiFile = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, "test.js")
);
MockFilePicker.setFiles([nsiFile]);
const path = nsiFile.path;

View File

@ -137,7 +137,9 @@ function waitUntilCensusState(store, getCensus, expected) {
}
async function createTempFile() {
const file = FileUtils.getFile("TmpD", ["tmp.fxsnapshot"]);
const file = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, "tmp.fxsnapshot")
);
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
const destPath = file.path;
const stat = await IOUtils.stat(destPath);

View File

@ -25,9 +25,11 @@ add_task(async function () {
await reloadBrowser();
info("Wait until the HAR file is created in the profile directory");
await waitUntil(() => FileUtils.getFile("ProfD", HAR_PATH).exists());
const harFile = new FileUtils.File(
PathUtils.join(PathUtils.profileDir, ...HAR_PATH)
);
const harFile = FileUtils.getFile("ProfD", HAR_PATH);
await waitUntil(() => harFile.exists());
ok(harFile.exists(), "HAR file was automatically created");
await toolbox.destroy();

View File

@ -49,7 +49,9 @@ add_task(async function () {
function copy(srcChromeURL, destFileName) {
return new Promise(resolve => {
const destFile = FileUtils.getFile("ProfD", [destFileName]);
const destFile = new FileUtils.File(
PathUtils.join(PathUtils.profileDir, destFileName)
);
write(read(srcChromeURL), destFile, resolve);
});
}

View File

@ -33,7 +33,9 @@ add_task(async function () {
function importSheet(ui, panelWindow) {
// create file to import first
const file = FileUtils.getFile("ProfD", [FILENAME]);
const file = new FileUtils.File(
PathUtils.join(PathUtils.profileDir, FILENAME)
);
const ostream = FileUtils.openSafeFileOutputStream(file);
const istream = getInputStream(SOURCE);

View File

@ -51,7 +51,9 @@ function testIndentifierGeneration(ui) {
function saveFirstInlineStyleSheet(ui) {
return new Promise(resolve => {
const editor = ui.editors[0];
const destFile = FileUtils.getFile("ProfD", [SAVE_PATH]);
const destFile = new FileUtils.File(
PathUtils.join(PathUtils.profileDir, SAVE_PATH)
);
editor.saveToFile(destFile, function (file) {
ok(file, "File was correctly saved.");

View File

@ -113,7 +113,9 @@ function getStylesheetNameFor(editor) {
}
function copy(srcChromeURL, destFilePath) {
const destFile = FileUtils.getFile("ProfD", destFilePath);
const destFile = new FileUtils.File(
PathUtils.join(PathUtils.profileDir, ...destFilePath)
);
return write(read(srcChromeURL), destFile);
}

View File

@ -36,7 +36,9 @@ add_task(async function () {
const hud = await BrowserConsoleManager.toggleBrowserConsole();
info("Execute :screenshot");
const file = FileUtils.getFile("TmpD", ["TestScreenshotFile.png"]);
const file = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, "TestScreenshotFile.png")
);
// on some machines, such as macOS, dpr is set to 2. This is expected behavior, however
// to keep tests consistant across OSs we are setting the dpr to 1
const command = `:screenshot ${file.path} --dpr 1`;

View File

@ -46,7 +46,9 @@ add_task(async function () {
info("Change the input content");
await setInputValue(hud, LOCAL_FILE_NEW_CONTENT);
const nsiFile = FileUtils.getFile("TmpD", [`console_input_${Date.now()}.js`]);
const nsiFile = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, `console_input_${Date.now()}.js`)
);
MockFilePicker.setFiles([nsiFile]);
info("Save the input content");
@ -66,7 +68,9 @@ add_task(async function () {
});
async function createLocalFile() {
const file = FileUtils.getFile("TmpD", [LOCAL_FILE_NAME]);
const file = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, LOCAL_FILE_NAME)
);
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("666", 8));
await writeInFile(LOCAL_FILE_ORIGINAL_CONTENT, file);
return file;

View File

@ -24,7 +24,9 @@ add_task(async function () {
});
info("Test :screenshot to file");
const file = FileUtils.getFile("TmpD", ["TestScreenshotFile.png"]);
const file = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, "TestScreenshotFile.png")
);
const command = `:screenshot ${file.path} ${dpr}`;
await executeAndWaitForMessageByType(
hud,

View File

@ -23,7 +23,9 @@ add_task(async function () {
});
info("Execute :screenshot --fullpage");
const file = FileUtils.getFile("TmpD", ["TestScreenshotFile.png"]);
const file = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, "TestScreenshotFile.png")
);
const command = `:screenshot ${file.path} ${dpr} --fullpage`;
// `-fullpage` is appended at the end of the provided filename
const actualFilePath = file.path.replace(".png", "-fullpage.png");

View File

@ -26,9 +26,12 @@ add_task(async function () {
});
info("Test :screenshot --selector iframe");
const sameOriginIframeScreenshotFile = FileUtils.getFile("TmpD", [
"TestScreenshotFile-same-origin-iframe.png",
]);
const sameOriginIframeScreenshotFile = new FileUtils.File(
PathUtils.join(
PathUtils.tempDir,
"TestScreenshotFile-same-origin-iframe.png"
)
);
await executeAndWaitForMessageByType(
hud,
`:screenshot --selector #same-origin-iframe ${sameOriginIframeScreenshotFile.path} ${dpr}`,
@ -91,9 +94,9 @@ add_task(async function () {
evaluationContextSelectorButton.innerText.includes("example.org")
);
const remoteIframeSpanScreenshot = FileUtils.getFile("TmpD", [
"TestScreenshotFile-remote-iframe.png",
]);
const remoteIframeSpanScreenshot = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, "TestScreenshotFile-remote-iframe.png")
);
await executeAndWaitForMessageByType(
hud,
`:screenshot --selector span ${remoteIframeSpanScreenshot.path} ${dpr}`,

View File

@ -161,9 +161,9 @@ async function exportAllToFile(hud, message) {
const exportFile = menuPopup.querySelector("#console-menu-export-file");
ok(exportFile, "copy menu item is enabled");
const nsiFile = FileUtils.getFile("TmpD", [
`export_console_${Date.now()}.log`,
]);
const nsiFile = new FileUtils.File(
PathUtils.join(PathUtils.tempDir, `export_console_${Date.now()}.log`)
);
MockFilePicker.setFiles([nsiFile]);
exportFile.click();
info("Exporting to file");

View File

@ -212,7 +212,7 @@ window.onload = async function() {
ok(true, "Tests finished");
const file = FileUtils.getFile("TmpD", [`test_render_perf_${Date.now()}.json`]);
const file = new FileUtils.File(PathUtils.join(PathUtils.tempDir, `test_render_perf_${Date.now()}.json`));
Services.profiler.dumpProfileToFile(file.path);
Services.profiler.StopProfiler();

View File

@ -102,7 +102,7 @@ add_task(async function test_schemeless_files() {
*/
function createTemporaryFile(extension) {
const name = "test_fetch-file-" + Math.random() + (extension || "");
const file = FileUtils.getFile("TmpD", [name]);
const file = new FileUtils.File(PathUtils.join(PathUtils.tempDir, name));
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0755", 8));
registerCleanupFunction(() => {

View File

@ -27,7 +27,7 @@ function doFileActivity()
info("doFileActivity");
const fileContent = "<p>hello world from bug 798764";
gTmpFile = FileUtils.getFile("TmpD", ["bug798764.html"]);
gTmpFile = new FileUtils.File(PathUtils.join(PathUtils.tempDir, "bug798764.html"));
gTmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
const fout = FileUtils.openSafeFileOutputStream(gTmpFile,