From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- dom/system/tests/ioutils/chrome.ini | 23 + .../tests/ioutils/file_ioutils_test_fixtures.js | 78 ++++ dom/system/tests/ioutils/file_ioutils_worker.js | 102 ++++ dom/system/tests/ioutils/test_ioutils.html | 26 ++ .../ioutils/test_ioutils_compute_hex_digest.html | 54 +++ .../tests/ioutils/test_ioutils_copy_move.html | 359 ++++++++++++++ .../tests/ioutils/test_ioutils_create_unique.html | 88 ++++ .../tests/ioutils/test_ioutils_dir_iteration.html | 94 ++++ dom/system/tests/ioutils/test_ioutils_getfile.html | 86 ++++ .../tests/ioutils/test_ioutils_mac_xattr.html | 90 ++++ dom/system/tests/ioutils/test_ioutils_mkdir.html | 133 ++++++ .../tests/ioutils/test_ioutils_read_write.html | 520 +++++++++++++++++++++ .../ioutils/test_ioutils_read_write_json.html | 165 +++++++ .../ioutils/test_ioutils_read_write_utf8.html | 359 ++++++++++++++ dom/system/tests/ioutils/test_ioutils_remove.html | 117 +++++ .../ioutils/test_ioutils_set_permissions.html | 84 ++++ .../test_ioutils_stat_set_modification_time.html | 241 ++++++++++ .../test_ioutils_windows_file_attributes.html | 135 ++++++ dom/system/tests/ioutils/test_ioutils_worker.xhtml | 40 ++ 19 files changed, 2794 insertions(+) create mode 100644 dom/system/tests/ioutils/chrome.ini create mode 100644 dom/system/tests/ioutils/file_ioutils_test_fixtures.js create mode 100644 dom/system/tests/ioutils/file_ioutils_worker.js create mode 100644 dom/system/tests/ioutils/test_ioutils.html create mode 100644 dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html create mode 100644 dom/system/tests/ioutils/test_ioutils_copy_move.html create mode 100644 dom/system/tests/ioutils/test_ioutils_create_unique.html create mode 100644 dom/system/tests/ioutils/test_ioutils_dir_iteration.html create mode 100644 dom/system/tests/ioutils/test_ioutils_getfile.html create mode 100644 dom/system/tests/ioutils/test_ioutils_mac_xattr.html create mode 100644 dom/system/tests/ioutils/test_ioutils_mkdir.html create mode 100644 dom/system/tests/ioutils/test_ioutils_read_write.html create mode 100644 dom/system/tests/ioutils/test_ioutils_read_write_json.html create mode 100644 dom/system/tests/ioutils/test_ioutils_read_write_utf8.html create mode 100644 dom/system/tests/ioutils/test_ioutils_remove.html create mode 100644 dom/system/tests/ioutils/test_ioutils_set_permissions.html create mode 100644 dom/system/tests/ioutils/test_ioutils_stat_set_modification_time.html create mode 100644 dom/system/tests/ioutils/test_ioutils_windows_file_attributes.html create mode 100644 dom/system/tests/ioutils/test_ioutils_worker.xhtml (limited to 'dom/system/tests/ioutils') diff --git a/dom/system/tests/ioutils/chrome.ini b/dom/system/tests/ioutils/chrome.ini new file mode 100644 index 0000000000..a961f45631 --- /dev/null +++ b/dom/system/tests/ioutils/chrome.ini @@ -0,0 +1,23 @@ +[DEFAULT] +support-files = + file_ioutils_test_fixtures.js + file_ioutils_worker.js + +[test_ioutils.html] +[test_ioutils_compute_hex_digest.html] +[test_ioutils_copy_move.html] +[test_ioutils_create_unique.html] +[test_ioutils_dir_iteration.html] +[test_ioutils_getfile.html] +[test_ioutils_mac_xattr.html] +skip-if = (os != "mac") +[test_ioutils_mkdir.html] +[test_ioutils_read_write.html] +[test_ioutils_read_write_json.html] +[test_ioutils_read_write_utf8.html] +[test_ioutils_remove.html] +[test_ioutils_stat_set_modification_time.html] +[test_ioutils_worker.xhtml] +[test_ioutils_set_permissions.html] +[test_ioutils_windows_file_attributes.html] +skip-if = (os != 'win') diff --git a/dom/system/tests/ioutils/file_ioutils_test_fixtures.js b/dom/system/tests/ioutils/file_ioutils_test_fixtures.js new file mode 100644 index 0000000000..5d2e5011c9 --- /dev/null +++ b/dom/system/tests/ioutils/file_ioutils_test_fixtures.js @@ -0,0 +1,78 @@ +// Utility functions. + +Uint8Array.prototype.equals = function equals(other) { + if (this.byteLength !== other.byteLength) { + return false; + } + return this.every((val, i) => val === other[i]); +}; + +async function createFile(location, contents = "") { + if (typeof contents === "string") { + contents = new TextEncoder().encode(contents); + } + await IOUtils.write(location, contents); + const exists = await fileExists(location); + ok(exists, `Created temporary file at: ${location}`); +} + +async function createDir(location) { + await IOUtils.makeDirectory(location, { + ignoreExisting: true, + createAncestors: true, + }); + const exists = await dirExists(location); + ok(exists, `Created temporary directory at: ${location}`); +} + +async function fileHasBinaryContents(location, expectedContents) { + if (!(expectedContents instanceof Uint8Array)) { + throw new TypeError("expectedContents must be a byte array"); + } + info(`Opening ${location} for reading`); + const bytes = await IOUtils.read(location); + return bytes.equals(expectedContents); +} + +async function fileHasTextContents(location, expectedContents) { + if (typeof expectedContents !== "string") { + throw new TypeError("expectedContents must be a string"); + } + info(`Opening ${location} for reading`); + const bytes = await IOUtils.read(location); + const contents = new TextDecoder().decode(bytes); + return contents === expectedContents; +} + +async function fileExists(file) { + try { + let { type } = await IOUtils.stat(file); + return type === "regular"; + } catch (ex) { + return false; + } +} + +async function dirExists(dir) { + try { + let { type } = await IOUtils.stat(dir); + return type === "directory"; + } catch (ex) { + return false; + } +} + +async function cleanup(...files) { + for (const file of files) { + await IOUtils.remove(file, { + ignoreAbsent: true, + recursive: true, + }); + const exists = await IOUtils.exists(file); + ok(!exists, `Removed temporary file: ${file}`); + } +} + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} diff --git a/dom/system/tests/ioutils/file_ioutils_worker.js b/dom/system/tests/ioutils/file_ioutils_worker.js new file mode 100644 index 0000000000..9f9dfc899b --- /dev/null +++ b/dom/system/tests/ioutils/file_ioutils_worker.js @@ -0,0 +1,102 @@ +// Any copyright is dedicated to the Public Domain. +// - http://creativecommons.org/publicdomain/zero/1.0/ + +/* eslint-env mozilla/chrome-worker, node */ + +"use strict"; + +/* import-globals-from /testing/mochitest/tests/SimpleTest/WorkerSimpleTest.js */ +importScripts("chrome://mochikit/content/tests/SimpleTest/WorkerSimpleTest.js"); +/* import-globals-from /toolkit/modules/ObjectUtils.jsm */ +importScripts("resource://gre/modules/ObjectUtils.jsm"); + +importScripts("file_ioutils_test_fixtures.js"); + +self.onmessage = async function (msg) { + 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 + // serve as a confidence check that the implementation is thread-safe. + await test_api_is_available_on_worker(); + await test_full_read_and_write(); + await test_move_file(); + await test_copy_file(); + await test_make_directory(); + + finish(); + info("test_ioutils_worker.xhtml: Test finished"); + + async function test_api_is_available_on_worker() { + ok(self.IOUtils, "IOUtils is present in web workers"); + } + + async function test_full_read_and_write() { + // Write a file. + 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"); + + // Read it back. + let fileContents = await IOUtils.read(tmpFileName); + ok( + ObjectUtils.deepEqual(bytes, fileContents) && + bytes.length == fileContents.length, + "IOUtils::read can read back entire file" + ); + + const tooManyBytes = bytes.length + 1; + fileContents = await IOUtils.read(tmpFileName, { maxBytes: tooManyBytes }); + ok( + ObjectUtils.deepEqual(bytes, fileContents) && + fileContents.length == bytes.length, + "IOUtils::read can read entire file when requested maxBytes is too large" + ); + + await cleanup(tmpFileName); + } + + async function test_move_file() { + 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); + + await IOUtils.move(src, dest); + ok( + !(await fileExists(src)) && (await fileExists(dest)), + "IOUtils::move can move files from a worker" + ); + + await cleanup(dest); + } + + async function test_copy_file() { + 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); + ok( + (await fileExists(tmpFileName)) && + (await fileHasTextContents(destFileName, "original")), + "IOUtils::copy can copy source to dest in same directory" + ); + + await cleanup(tmpFileName, destFileName); + } + + async function test_make_directory() { + const dir = PathUtils.join(tmpDir, "test_make_dir.tmp.d"); + await IOUtils.makeDirectory(dir); + const stat = await IOUtils.stat(dir); + is( + stat.type, + "directory", + "IOUtils::makeDirectory can make a new directory from a worker" + ); + + await cleanup(dir); + } +}; diff --git a/dom/system/tests/ioutils/test_ioutils.html b/dom/system/tests/ioutils/test_ioutils.html new file mode 100644 index 0000000000..cf62c4c388 --- /dev/null +++ b/dom/system/tests/ioutils/test_ioutils.html @@ -0,0 +1,26 @@ + + + + + + + Test the IOUtils file I/O API + + + + + + +

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html b/dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html
new file mode 100644
index 0000000000..1c27a28822
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_copy_move.html b/dom/system/tests/ioutils/test_ioutils_copy_move.html
new file mode 100644
index 0000000000..ba55eb8463
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_copy_move.html
@@ -0,0 +1,359 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_create_unique.html b/dom/system/tests/ioutils/test_ioutils_create_unique.html
new file mode 100644
index 0000000000..e447964343
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_create_unique.html
@@ -0,0 +1,88 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_dir_iteration.html b/dom/system/tests/ioutils/test_ioutils_dir_iteration.html
new file mode 100644
index 0000000000..93e2c60039
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_dir_iteration.html
@@ -0,0 +1,94 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_getfile.html b/dom/system/tests/ioutils/test_ioutils_getfile.html
new file mode 100644
index 0000000000..d5295f469f
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_getfile.html
@@ -0,0 +1,86 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_mac_xattr.html b/dom/system/tests/ioutils/test_ioutils_mac_xattr.html
new file mode 100644
index 0000000000..cd6e7aeb5d
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_mac_xattr.html
@@ -0,0 +1,90 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_mkdir.html b/dom/system/tests/ioutils/test_ioutils_mkdir.html
new file mode 100644
index 0000000000..c1a073dea6
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_mkdir.html
@@ -0,0 +1,133 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_read_write.html b/dom/system/tests/ioutils/test_ioutils_read_write.html
new file mode 100644
index 0000000000..f52115d261
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_read_write.html
@@ -0,0 +1,520 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_read_write_json.html b/dom/system/tests/ioutils/test_ioutils_read_write_json.html
new file mode 100644
index 0000000000..e356e50c47
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_read_write_json.html
@@ -0,0 +1,165 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_read_write_utf8.html b/dom/system/tests/ioutils/test_ioutils_read_write_utf8.html
new file mode 100644
index 0000000000..196f5d4862
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_read_write_utf8.html
@@ -0,0 +1,359 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_remove.html b/dom/system/tests/ioutils/test_ioutils_remove.html
new file mode 100644
index 0000000000..85ffa481a4
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_remove.html
@@ -0,0 +1,117 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_set_permissions.html b/dom/system/tests/ioutils/test_ioutils_set_permissions.html
new file mode 100644
index 0000000000..36f7dab72a
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_set_permissions.html
@@ -0,0 +1,84 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_stat_set_modification_time.html b/dom/system/tests/ioutils/test_ioutils_stat_set_modification_time.html
new file mode 100644
index 0000000000..8f8328bd81
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_stat_set_modification_time.html
@@ -0,0 +1,241 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_windows_file_attributes.html b/dom/system/tests/ioutils/test_ioutils_windows_file_attributes.html
new file mode 100644
index 0000000000..b452b4f6db
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_windows_file_attributes.html
@@ -0,0 +1,135 @@
+
+
+
+
+
+  
+  Test the IOUtils file I/O API
+  
+  
+  
+  
+
+
+
+  

+ +

+
+
+
diff --git a/dom/system/tests/ioutils/test_ioutils_worker.xhtml b/dom/system/tests/ioutils/test_ioutils_worker.xhtml
new file mode 100644
index 0000000000..df67d48676
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_worker.xhtml
@@ -0,0 +1,40 @@
+
+
+
+
+  
+
+  
+    

+ +

+  
+  
-- cgit v1.2.3