зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1705484
- Remove OS.* from most IOUtils tests r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D113451
This commit is contained in:
Родитель
3487bbd1ee
Коммит
154e0379e9
|
@ -9,13 +9,10 @@
|
|||
importScripts("chrome://mochikit/content/tests/SimpleTest/WorkerSimpleTest.js");
|
||||
importScripts("resource://gre/modules/ObjectUtils.jsm");
|
||||
|
||||
// TODO: Remove this import for OS.File. It is currently being used as a
|
||||
// stop gap for missing IOUtils functionality.
|
||||
importScripts("resource://gre/modules/osfile.jsm");
|
||||
importScripts("file_ioutils_test_fixtures.js");
|
||||
|
||||
self.onmessage = async function(msg) {
|
||||
const tmpDir = OS.Constants.Path.tmpDir;
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
|
||||
// IOUtils functionality is the same when called from the main thread, or a
|
||||
// web worker. These tests are a modified subset of the main thread tests, and
|
||||
|
@ -35,7 +32,7 @@ self.onmessage = async function(msg) {
|
|||
|
||||
async function test_full_read_and_write() {
|
||||
// Write a file.
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_numbers.tmp");
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_numbers.tmp");
|
||||
const bytes = Uint8Array.of(...new Array(50).keys());
|
||||
const bytesWritten = await IOUtils.write(tmpFileName, bytes);
|
||||
is(bytesWritten, 50, "IOUtils::write can write entire byte array to file");
|
||||
|
@ -60,8 +57,8 @@ self.onmessage = async function(msg) {
|
|||
}
|
||||
|
||||
async function test_move_file() {
|
||||
const src = OS.Path.join(tmpDir, "test_move_file_src.tmp");
|
||||
const dest = OS.Path.join(tmpDir, "test_move_file_dest.tmp");
|
||||
const src = PathUtils.join(tmpDir, "test_move_file_src.tmp");
|
||||
const dest = PathUtils.join(tmpDir, "test_move_file_dest.tmp");
|
||||
const bytes = Uint8Array.of(...new Array(50).keys());
|
||||
await IOUtils.write(src, bytes);
|
||||
|
||||
|
@ -75,8 +72,8 @@ self.onmessage = async function(msg) {
|
|||
}
|
||||
|
||||
async function test_copy_file() {
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_orig.tmp");
|
||||
const destFileName = OS.Path.join(tmpDir, "test_ioutils_copy.tmp");
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_orig.tmp");
|
||||
const destFileName = PathUtils.join(tmpDir, "test_ioutils_copy.tmp");
|
||||
await createFile(tmpFileName, "original");
|
||||
|
||||
await IOUtils.copy(tmpFileName, destFileName);
|
||||
|
@ -90,10 +87,12 @@ self.onmessage = async function(msg) {
|
|||
}
|
||||
|
||||
async function test_make_directory() {
|
||||
const dir = OS.Path.join(tmpDir, "test_make_dir.tmp.d");
|
||||
const dir = PathUtils.join(tmpDir, "test_make_dir.tmp.d");
|
||||
await IOUtils.makeDirectory(dir);
|
||||
ok(
|
||||
OS.File.stat(dir).isDir,
|
||||
const stat = await IOUtils.stat(dir);
|
||||
is(
|
||||
stat.type,
|
||||
"directory",
|
||||
"IOUtils::makeDirectory can make a new directory from a worker"
|
||||
);
|
||||
|
||||
|
|
|
@ -15,15 +15,9 @@
|
|||
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
|
||||
const { ObjectUtils } = ChromeUtils.import("resource://gre/modules/ObjectUtils.jsm");
|
||||
|
||||
// TODO: Remove this import for OS.File. It is currently being used as a
|
||||
// stop gap for missing IOUtils functionality.
|
||||
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
|
||||
|
||||
const tmpDir = OS.Constants.Path.tmpDir;
|
||||
|
||||
add_task(async function test_move_relative_path() {
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_move_relative_path.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_move_relative_path.tmp");
|
||||
const dest = "relative_to_cwd.tmp";
|
||||
await createFile(tmpFileName, "source");
|
||||
|
||||
|
@ -43,8 +37,9 @@
|
|||
|
||||
add_task(async function test_move_rename() {
|
||||
// Set up.
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_move_src.tmp");
|
||||
const destFileName = OS.Path.join(tmpDir, "test_ioutils_move_dest.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_move_src.tmp");
|
||||
const destFileName = PathUtils.join(tmpDir, "test_ioutils_move_dest.tmp");
|
||||
await createFile(tmpFileName, "dest");
|
||||
// Test.
|
||||
info("Test move to new file in same directory");
|
||||
|
@ -87,9 +82,10 @@
|
|||
add_task(async function test_move_to_dir() {
|
||||
// Set up.
|
||||
info("Test move and rename to non-existing directory");
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_move_to_dir.tmp");
|
||||
const destDir = OS.Path.join(tmpDir, "test_move_to_dir.tmp.d");
|
||||
const dest = OS.Path.join(destDir, "dest.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_move_to_dir.tmp");
|
||||
const destDir = PathUtils.join(tmpDir, "test_move_to_dir.tmp.d");
|
||||
const dest = PathUtils.join(destDir, "dest.tmp");
|
||||
await createFile(tmpFileName);
|
||||
// Test.
|
||||
ok(!await IOUtils.exists(destDir), "Expected path not to exist");
|
||||
|
@ -119,7 +115,7 @@
|
|||
ok(await dirExists(destDir), `Expected ${destDir} to be a directory`);
|
||||
ok(
|
||||
!await fileExists(tmpFileName)
|
||||
&& await fileExists(OS.Path.join(destDir, OS.Path.basename(tmpFileName))),
|
||||
&& await fileExists(PathUtils.join(destDir, PathUtils.filename(tmpFileName))),
|
||||
"IOUtils::move can move a file into an existing dir"
|
||||
);
|
||||
|
||||
|
@ -130,8 +126,9 @@
|
|||
add_task(async function test_move_dir() {
|
||||
// Set up.
|
||||
info("Test rename an empty directory");
|
||||
const srcDir = OS.Path.join(tmpDir, "test_move_dir.tmp.d");
|
||||
const destDir = OS.Path.join(tmpDir, "test_move_dir_dest.tmp.d");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const srcDir = PathUtils.join(tmpDir, "test_move_dir.tmp.d");
|
||||
const destDir = PathUtils.join(tmpDir, "test_move_dir_dest.tmp.d");
|
||||
await createDir(srcDir);
|
||||
// Test.
|
||||
await IOUtils.move(srcDir, destDir);
|
||||
|
@ -143,14 +140,14 @@
|
|||
// Set up.
|
||||
info("Test move directory and its content into another directory");
|
||||
await createDir(srcDir);
|
||||
await createFile(OS.Path.join(srcDir, "file.tmp"), "foo");
|
||||
await createFile(PathUtils.join(srcDir, "file.tmp"), "foo");
|
||||
// Test.
|
||||
await IOUtils.move(srcDir, destDir);
|
||||
const destFile = OS.Path.join(destDir, OS.Path.basename(srcDir), "file.tmp");
|
||||
const destFile = PathUtils.join(destDir, PathUtils.filename(srcDir), "file.tmp");
|
||||
ok(
|
||||
!await IOUtils.exists(srcDir)
|
||||
&& await dirExists(destDir)
|
||||
&& await dirExists(OS.Path.join(destDir, OS.Path.basename(srcDir)))
|
||||
&& await dirExists(PathUtils.join(destDir, PathUtils.filename(srcDir)))
|
||||
&& await fileHasTextContents(destFile, "foo"),
|
||||
"IOUtils::move can move a directory and its contents into another one"
|
||||
)
|
||||
|
@ -162,8 +159,9 @@
|
|||
add_task(async function test_move_failures() {
|
||||
// Set up.
|
||||
info("Test attempt to rename a non-existent source file");
|
||||
const notExistsSrc = OS.Path.join(tmpDir, "not_exists_src.tmp");
|
||||
const notExistsDest = OS.Path.join(tmpDir, "not_exists_dest.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const notExistsSrc = PathUtils.join(tmpDir, "not_exists_src.tmp");
|
||||
const notExistsDest = PathUtils.join(tmpDir, "not_exists_dest.tmp");
|
||||
// Test.
|
||||
await Assert.rejects(
|
||||
IOUtils.move(notExistsSrc, notExistsDest),
|
||||
|
@ -177,8 +175,8 @@
|
|||
|
||||
// Set up.
|
||||
info("Test attempt to move a directory to a file");
|
||||
const destFile = OS.Path.join(tmpDir, "test_move_failures_file_dest.tmp");
|
||||
const srcDir = OS.Path.join(tmpDir, "test_move_failure_src.tmp.d");
|
||||
const destFile = PathUtils.join(tmpDir, "test_move_failures_file_dest.tmp");
|
||||
const srcDir = PathUtils.join(tmpDir, "test_move_failure_src.tmp.d");
|
||||
await createFile(destFile);
|
||||
await createDir(srcDir);
|
||||
// Test.
|
||||
|
@ -194,8 +192,9 @@
|
|||
|
||||
add_task(async function test_copy() {
|
||||
// Set up.
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_orig.tmp");
|
||||
const destFileName = OS.Path.join(tmpDir, "test_ioutils_copy.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_orig.tmp");
|
||||
const destFileName = PathUtils.join(tmpDir, "test_ioutils_copy.tmp");
|
||||
await createFile(tmpFileName, "original");
|
||||
// Test.
|
||||
info("Test copy to new file in same directory");
|
||||
|
@ -237,9 +236,10 @@
|
|||
add_task(async function test_copy_file_to_dir() {
|
||||
// Set up.
|
||||
info("Test copy file to non-existing directory");
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_copy_file_to_dir.tmp");
|
||||
const destDir = OS.Path.join(tmpDir, "test_copy_file_to_dir.tmp.d");
|
||||
const dest = OS.Path.join(destDir, "dest.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_copy_file_to_dir.tmp");
|
||||
const destDir = PathUtils.join(tmpDir, "test_copy_file_to_dir.tmp.d");
|
||||
const dest = PathUtils.join(destDir, "dest.tmp");
|
||||
await createFile(tmpFileName);
|
||||
// Test.
|
||||
ok(!await IOUtils.exists(destDir), "Expected path not to exist");
|
||||
|
@ -269,7 +269,7 @@
|
|||
ok(await dirExists(destDir), `Expected ${destDir} to be a directory`);
|
||||
ok(
|
||||
await fileExists(tmpFileName)
|
||||
&& await fileExists(OS.Path.join(destDir, OS.Path.basename(tmpFileName))),
|
||||
&& await fileExists(PathUtils.join(destDir, PathUtils.filename(tmpFileName))),
|
||||
"IOUtils::copy can copy a file into an existing dir"
|
||||
);
|
||||
|
||||
|
@ -280,8 +280,9 @@
|
|||
add_task(async function test_copy_dir_recursive() {
|
||||
// Set up.
|
||||
info("Test rename an empty directory");
|
||||
const srcDir = OS.Path.join(tmpDir, "test_copy_dir.tmp.d");
|
||||
const destDir = OS.Path.join(tmpDir, "test_copy_dir_dest.tmp.d");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const srcDir = PathUtils.join(tmpDir, "test_copy_dir.tmp.d");
|
||||
const destDir = PathUtils.join(tmpDir, "test_copy_dir_dest.tmp.d");
|
||||
await createDir(srcDir);
|
||||
// Test.
|
||||
await IOUtils.copy(srcDir, destDir, { recursive: true });
|
||||
|
@ -293,14 +294,14 @@
|
|||
// Set up.
|
||||
info("Test copy directory and its content into another directory");
|
||||
await createDir(srcDir);
|
||||
await createFile(OS.Path.join(srcDir, "file.tmp"), "foo");
|
||||
await createFile(PathUtils.join(srcDir, "file.tmp"), "foo");
|
||||
// Test.
|
||||
await IOUtils.copy(srcDir, destDir, { recursive: true });
|
||||
const destFile = OS.Path.join(destDir, OS.Path.basename(srcDir), "file.tmp");
|
||||
const destFile = PathUtils.join(destDir, PathUtils.filename(srcDir), "file.tmp");
|
||||
ok(
|
||||
await dirExists(srcDir)
|
||||
&& await dirExists(destDir)
|
||||
&& await dirExists(OS.Path.join(destDir, OS.Path.basename(srcDir)))
|
||||
&& await dirExists(PathUtils.join(destDir, PathUtils.filename(srcDir)))
|
||||
&& await fileHasTextContents(destFile, "foo"),
|
||||
"IOUtils::copy can move a directory and its contents into another one"
|
||||
)
|
||||
|
@ -312,8 +313,9 @@
|
|||
add_task(async function test_copy_failures() {
|
||||
// Set up.
|
||||
info("Test attempt to copy a non-existent source file");
|
||||
const notExistsSrc = OS.Path.join(tmpDir, "test_copy_not_exists_src.tmp");
|
||||
const notExistsDest = OS.Path.join(tmpDir, "test_copy_not_exists_dest.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const notExistsSrc = PathUtils.join(tmpDir, "test_copy_not_exists_src.tmp");
|
||||
const notExistsDest = PathUtils.join(tmpDir, "test_copy_not_exists_dest.tmp");
|
||||
// Test.
|
||||
await Assert.rejects(
|
||||
IOUtils.copy(notExistsSrc, notExistsDest),
|
||||
|
@ -327,8 +329,8 @@
|
|||
|
||||
// Set up.
|
||||
info("Test attempt to copy a directory to a file");
|
||||
const destFile = OS.Path.join(tmpDir, "test_copy_failures_file_dest.tmp");
|
||||
const srcDir = OS.Path.join(tmpDir, "test_copy_failure_src.tmp.d");
|
||||
const destFile = PathUtils.join(tmpDir, "test_copy_failures_file_dest.tmp");
|
||||
const srcDir = PathUtils.join(tmpDir, "test_copy_failure_src.tmp.d");
|
||||
await createFile(destFile);
|
||||
await createDir(srcDir);
|
||||
// Test.
|
||||
|
|
|
@ -13,12 +13,10 @@
|
|||
"use strict";
|
||||
|
||||
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
|
||||
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
|
||||
const tmpDir = OS.Constants.Path.tmpDir;
|
||||
|
||||
add_task(async function iterate_dir_failure() {
|
||||
let notExists = OS.Path.join(tmpDir, 'does_not_exist_dir.tmp.d');
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
let notExists = PathUtils.join(tmpDir, 'does_not_exist_dir.tmp.d');
|
||||
|
||||
await Assert.rejects(
|
||||
IOUtils.getChildren(notExists),
|
||||
|
@ -29,7 +27,7 @@
|
|||
|
||||
info('Try to get the children of a regular file');
|
||||
|
||||
let tmpFileName = OS.Path.join(tmpDir, 'iterator_file.tmp');
|
||||
let tmpFileName = PathUtils.join(tmpDir, 'iterator_file.tmp');
|
||||
await createFile(tmpFileName)
|
||||
await Assert.rejects(IOUtils.getChildren(tmpFileName),
|
||||
/Could not get children of file\(.*\) because it is not a directory/,
|
||||
|
@ -42,10 +40,11 @@
|
|||
add_task(async function iterate_dir() {
|
||||
info('Try to get the children of a multi-level directory hierarchy');
|
||||
|
||||
let root = OS.Path.join(tmpDir, 'iterator.tmp.d');
|
||||
let child1 = OS.Path.join(root, 'child1.tmp');
|
||||
let child2 = OS.Path.join(root, 'child2.tmp');
|
||||
let grandchild = OS.Path.join(child1, 'grandchild.tmp');
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
let root = PathUtils.join(tmpDir, 'iterator.tmp.d');
|
||||
let child1 = PathUtils.join(root, 'child1.tmp');
|
||||
let child2 = PathUtils.join(root, 'child2.tmp');
|
||||
let grandchild = PathUtils.join(child1, 'grandchild.tmp');
|
||||
|
||||
await createDir(grandchild); // Ancestors will be created.
|
||||
await createDir(child2);
|
||||
|
@ -61,7 +60,8 @@
|
|||
add_task(async function iterate_empty_dir() {
|
||||
info('Try to get the children of an empty directory');
|
||||
|
||||
let emptyDir = OS.Path.join(tmpDir, 'iterator_empty_dir.tmp.d');
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
let emptyDir = PathUtils.join(tmpDir, 'iterator_empty_dir.tmp.d');
|
||||
await createDir(emptyDir);
|
||||
|
||||
is(
|
||||
|
|
|
@ -15,13 +15,11 @@
|
|||
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
|
||||
const { ObjectUtils } = ChromeUtils.import("resource://gre/modules/ObjectUtils.jsm");
|
||||
|
||||
// TODO: Remove this import for OS.File. It is currently being used as a
|
||||
// stop gap for missing IOUtils functionality.
|
||||
// This is presently only used to test compatability between OS.File and
|
||||
// IOUtils when it comes to writing compressed files. The import and the
|
||||
// test `test_lz4_osfile_compat` can be removed with OS.File is removed.
|
||||
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
|
||||
|
||||
const tmpDir = OS.Constants.Path.tmpDir;
|
||||
|
||||
// This is an impossible sequence of bytes in an UTF-8 encoded file.
|
||||
// See section 3.5.3 of this text:
|
||||
// https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
|
||||
|
@ -29,7 +27,8 @@
|
|||
|
||||
add_task(async function test_read_utf8_failure() {
|
||||
info("Test attempt to read non-existent file (UTF8)");
|
||||
const doesNotExist = OS.Path.join(tmpDir, "does_not_exist.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const doesNotExist = PathUtils.join(tmpDir, "does_not_exist.tmp");
|
||||
await Assert.rejects(
|
||||
IOUtils.readUTF8(doesNotExist),
|
||||
/Could not open the file at .*/,
|
||||
|
@ -37,7 +36,7 @@
|
|||
);
|
||||
|
||||
info("Test attempt to read invalid UTF-8");
|
||||
const invalidUTF8File = OS.Path.join(tmpDir, "invalid_utf8.tmp");
|
||||
const invalidUTF8File = PathUtils.join(tmpDir, "invalid_utf8.tmp");
|
||||
|
||||
// Deliberately write the invalid byte sequence to file.
|
||||
await IOUtils.write(invalidUTF8File, invalidUTF8);
|
||||
|
@ -52,8 +51,9 @@
|
|||
});
|
||||
|
||||
add_task(async function test_write_utf8_no_overwrite() {
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
// Make a new file, and try to write to it with overwrites disabled.
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_write_utf8_overwrite.tmp");
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_write_utf8_overwrite.tmp");
|
||||
const untouchableContents = "Can't touch this!\n";
|
||||
await IOUtils.writeUTF8(tmpFileName, untouchableContents);
|
||||
|
||||
|
@ -90,8 +90,9 @@
|
|||
|
||||
add_task(async function test_write_with_backup() {
|
||||
info("Test backup file option with non-existing file");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
let fileContents = "Original file contents";
|
||||
let destFileName = OS.Path.join(tmpDir, "test_write_utf8_with_backup_option.tmp");
|
||||
let destFileName = PathUtils.join(tmpDir, "test_write_utf8_with_backup_option.tmp");
|
||||
let backupFileName = destFileName + ".backup";
|
||||
let bytesWritten =
|
||||
await IOUtils.writeUTF8(destFileName, fileContents, {
|
||||
|
@ -137,10 +138,11 @@
|
|||
|
||||
add_task(async function test_write_with_backup_and_tmp() {
|
||||
info("Test backup with tmp and backup file options, non-existing destination");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
let fileContents = "Original file contents";
|
||||
let destFileName = OS.Path.join(tmpDir, "test_write_utf8_with_backup_and_tmp_options.tmp");
|
||||
let destFileName = PathUtils.join(tmpDir, "test_write_utf8_with_backup_and_tmp_options.tmp");
|
||||
let backupFileName = destFileName + ".backup";
|
||||
let tmpFileName = OS.Path.join(tmpDir, "temp_file.tmp");
|
||||
let tmpFileName = PathUtils.join(tmpDir, "temp_file.tmp");
|
||||
let bytesWritten =
|
||||
await IOUtils.writeUTF8(destFileName, fileContents, {
|
||||
backupFile: backupFileName,
|
||||
|
@ -188,7 +190,8 @@
|
|||
});
|
||||
|
||||
add_task(async function test_empty_read_and_write_utf8() {
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_empty_utf8.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_empty_utf8.tmp");
|
||||
const emptyString = ""
|
||||
const bytesWritten = await IOUtils.writeUTF8(
|
||||
tmpFileName,
|
||||
|
@ -205,7 +208,8 @@
|
|||
add_task(async function test_full_read_and_write_utf8() {
|
||||
// Write a file.
|
||||
info("Test writing emoji file");
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_emoji.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_emoji.tmp");
|
||||
|
||||
// Make sure non-ASCII text is supported for writing and reading back.
|
||||
// For fun, a sampling of space-separated emoji characters from different
|
||||
|
@ -257,7 +261,8 @@
|
|||
|
||||
|
||||
add_task(async function test_utf8_lz4() {
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_utf8_lz4.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_utf8_lz4.tmp");
|
||||
|
||||
info("Test writing lz4 encoded UTF-8 string");
|
||||
const emoji = "☕️ ⚧️ 😀 🖖🏿 🤠 🏳️🌈 🥠 🏴☠️ 🪐";
|
||||
|
@ -293,8 +298,9 @@
|
|||
});
|
||||
|
||||
add_task(async function test_utf8_lz4_osfile_compat() {
|
||||
const osfileTmpFile = OS.Path.join(tmpDir, "test_ioutils_utf8_lz4_compat_osfile.tmp");
|
||||
const ioutilsTmpFile = OS.Path.join(tmpDir, "test_ioutils_utf8_lz4_compat_ioutils.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const osfileTmpFile = PathUtils.join(tmpDir, "test_ioutils_utf8_lz4_compat_osfile.tmp");
|
||||
const ioutilsTmpFile = PathUtils.join(tmpDir, "test_ioutils_utf8_lz4_compat_ioutils.tmp");
|
||||
|
||||
info("Test OS.File and IOUtils write the same UTF-8 file with LZ4 compression enabled")
|
||||
const emoji = "☕️ ⚧️ 😀 🖖🏿 🤠 🏳️🌈 🥠 🏴☠️ 🪐";
|
||||
|
@ -316,7 +322,8 @@
|
|||
});
|
||||
|
||||
add_task(async function test_utf8_lz4_bad_call() {
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_utf8_lz4_bad_call.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_utf8_lz4_bad_call.tmp");
|
||||
|
||||
info("readUTF8 ignores the maxBytes option if provided");
|
||||
const emoji = "☕️ ⚧️ 😀 🖖🏿 🤠 🏳️🌈 🥠 🏴☠️ 🪐";
|
||||
|
@ -330,7 +337,8 @@
|
|||
});
|
||||
|
||||
add_task(async function test_utf8_lz4_failure() {
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_utf8_lz4_fail.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_utf8_lz4_fail.tmp");
|
||||
|
||||
info("Test decompression of non-lz4 UTF-8 string");
|
||||
const repeatedBytes = Uint8Array.of(...new Array(50).fill(1));
|
||||
|
|
|
@ -15,16 +15,10 @@
|
|||
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
|
||||
const { ObjectUtils } = ChromeUtils.import("resource://gre/modules/ObjectUtils.jsm");
|
||||
|
||||
// TODO: Remove this import for OS.File. It is currently being used as a
|
||||
// stop gap for missing IOUtils functionality.
|
||||
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
|
||||
|
||||
const tmpDir = OS.Constants.Path.tmpDir;
|
||||
|
||||
add_task(async function test_create_and_remove_file() {
|
||||
info("Test creating and removing a single file");
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutils_create_and_remove.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutils_create_and_remove.tmp");
|
||||
await IOUtils.write(tmpFileName, new Uint8Array(0));
|
||||
ok(await fileExists(tmpFileName), `Expected file ${tmpFileName} to exist`);
|
||||
|
||||
|
@ -32,7 +26,7 @@
|
|||
ok(!await fileExists(tmpFileName), "IOUtils::remove can remove files");
|
||||
|
||||
info("Test creating and removing an empty directory");
|
||||
const tmpDirName = OS.Path.join(tmpDir, "test_ioutils_create_and_remove.tmp.d");
|
||||
const tmpDirName = PathUtils.join(tmpDir, "test_ioutils_create_and_remove.tmp.d");
|
||||
await IOUtils.makeDirectory(tmpDirName);
|
||||
ok(await dirExists(tmpDirName), `Expected directory ${tmpDirName} to exist`);
|
||||
|
||||
|
@ -41,7 +35,8 @@
|
|||
});
|
||||
|
||||
add_task(async function test_remove_non_existing() {
|
||||
const tmpFileName = OS.Path.join(tmpDir, "test_ioutil_remove_non_existing.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpFileName = PathUtils.join(tmpDir, "test_ioutil_remove_non_existing.tmp");
|
||||
ok(!await fileExists(tmpFileName), `Expected file ${tmpFileName} not to exist`);
|
||||
|
||||
await IOUtils.remove(tmpFileName, { ignoreAbsent: true });
|
||||
|
@ -56,10 +51,11 @@
|
|||
});
|
||||
|
||||
add_task(async function test_remove_recursive() {
|
||||
const tmpParentDir = OS.Path.join(tmpDir, "test_ioutils_remove.tmp.d");
|
||||
const tmpChildDir = OS.Path.join(tmpParentDir, "child.tmp.d");
|
||||
const tmpTopLevelFileName = OS.Path.join(tmpParentDir, "top.tmp");
|
||||
const tmpNestedFileName = OS.Path.join(tmpChildDir, "nested.tmp");
|
||||
const tmpDir = await PathUtils.getTempDir();
|
||||
const tmpParentDir = PathUtils.join(tmpDir, "test_ioutils_remove.tmp.d");
|
||||
const tmpChildDir = PathUtils.join(tmpParentDir, "child.tmp.d");
|
||||
const tmpTopLevelFileName = PathUtils.join(tmpParentDir, "top.tmp");
|
||||
const tmpNestedFileName = PathUtils.join(tmpChildDir, "nested.tmp");
|
||||
await createDir(tmpChildDir);
|
||||
await createFile(tmpTopLevelFileName, "");
|
||||
await createFile(tmpNestedFileName, "");
|
||||
|
|
Загрузка…
Ссылка в новой задаче