fune/toolkit/components/osfile/tests/xpcshell/test_osfile_error.js
Victor Porof 4a06c925ac Bug 1561435 - Format toolkit/components/, a=automatic-formatting
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D36052

--HG--
extra : source : b5be5b4f4b47c256e28a29f665dc754f6407ee7f
2019-07-05 11:14:05 +02:00

56 lines
1.7 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var {
OS: { File, Path, Constants },
} = ChromeUtils.import("resource://gre/modules/osfile.jsm");
add_task(async function testFileError_with_writeAtomic() {
let DEFAULT_CONTENTS = "default contents" + Math.random();
let path = Path.join(Constants.Path.tmpDir, "testFileError.tmp");
await File.remove(path);
await File.writeAtomic(path, DEFAULT_CONTENTS);
let exception;
try {
await File.writeAtomic(path, DEFAULT_CONTENTS, { noOverwrite: true });
} catch (ex) {
exception = ex;
}
Assert.ok(exception instanceof File.Error);
Assert.ok(exception.path == path);
});
add_task(async function testFileError_with_makeDir() {
let path = Path.join(Constants.Path.tmpDir, "directory");
await File.removeDir(path);
await File.makeDir(path);
let exception;
try {
await File.makeDir(path, { ignoreExisting: false });
} catch (ex) {
exception = ex;
}
Assert.ok(exception instanceof File.Error);
Assert.ok(exception.path == path);
});
add_task(async function testFileError_with_move() {
let DEFAULT_CONTENTS = "default contents" + Math.random();
let sourcePath = Path.join(Constants.Path.tmpDir, "src.tmp");
let destPath = Path.join(Constants.Path.tmpDir, "dest.tmp");
await File.remove(sourcePath);
await File.remove(destPath);
await File.writeAtomic(sourcePath, DEFAULT_CONTENTS);
await File.writeAtomic(destPath, DEFAULT_CONTENTS);
let exception;
try {
await File.move(sourcePath, destPath, { noOverwrite: true });
} catch (ex) {
exception = ex;
}
info(exception);
Assert.ok(exception instanceof File.Error);
Assert.ok(exception.path == sourcePath);
});