From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/system/tests/ioutils/chrome.toml | 39 ++ .../tests/ioutils/file_ioutils_test_fixtures.js | 78 +++ dom/system/tests/ioutils/file_ioutils_worker.js | 219 +++++++++ dom/system/tests/ioutils/test_ioutils.html | 26 + .../ioutils/test_ioutils_compute_hex_digest.html | 55 +++ .../tests/ioutils/test_ioutils_copy_move.html | 360 ++++++++++++++ .../tests/ioutils/test_ioutils_create_unique.html | 86 ++++ .../tests/ioutils/test_ioutils_dir_iteration.html | 96 ++++ dom/system/tests/ioutils/test_ioutils_getfile.html | 84 ++++ .../tests/ioutils/test_ioutils_mac_xattr.html | 91 ++++ dom/system/tests/ioutils/test_ioutils_mkdir.html | 135 ++++++ .../tests/ioutils/test_ioutils_read_write.html | 524 +++++++++++++++++++++ .../ioutils/test_ioutils_read_write_json.html | 193 ++++++++ .../ioutils/test_ioutils_read_write_utf8.html | 384 +++++++++++++++ dom/system/tests/ioutils/test_ioutils_remove.html | 118 +++++ .../ioutils/test_ioutils_set_permissions.html | 84 ++++ .../test_ioutils_stat_set_modification_time.html | 242 ++++++++++ .../test_ioutils_windows_file_attributes.html | 137 ++++++ dom/system/tests/ioutils/test_ioutils_worker.xhtml | 40 ++ 19 files changed, 2991 insertions(+) create mode 100644 dom/system/tests/ioutils/chrome.toml 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.toml b/dom/system/tests/ioutils/chrome.toml new file mode 100644 index 0000000000..16434b5bb6 --- /dev/null +++ b/dom/system/tests/ioutils/chrome.toml @@ -0,0 +1,39 @@ +[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_set_permissions.html"] + +["test_ioutils_stat_set_modification_time.html"] + +["test_ioutils_windows_file_attributes.html"] +skip-if = ["(os != 'win')"] + +["test_ioutils_worker.xhtml"] 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..e367eb4d99 --- /dev/null +++ b/dom/system/tests/ioutils/file_ioutils_worker.js @@ -0,0 +1,219 @@ +// Any copyright is dedicated to the Public Domain. +// - http://creativecommons.org/publicdomain/zero/1.0/ + +// Portions of this file are originally from narwhal.js (http://narwhaljs.org) +// Copyright (c) 2009 Thomas Robinson <280north.com> +// MIT license: http://opensource.org/licenses/MIT + +/* eslint-env worker */ + +"use strict"; + +/* import-globals-from /testing/mochitest/tests/SimpleTest/WorkerSimpleTest.js */ +importScripts("chrome://mochikit/content/tests/SimpleTest/WorkerSimpleTest.js"); + +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( + _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( + _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); + } +}; + +// This is copied from the ObjectUtils module, as it is difficult to translate +// file_ioutils_test_fixtures.js into a ES module and have it used in non-module +// contexts. + +// ... Start of previously MIT-licensed code. +// This deepEqual implementation is originally from narwhal.js (http://narwhaljs.org) +// Copyright (c) 2009 Thomas Robinson <280north.com> +// MIT license: http://opensource.org/licenses/MIT + +function _deepEqual(a, b) { + // The numbering below refers to sections in the CommonJS spec. + + // 7.1 All identical values are equivalent, as determined by ===. + if (a === b) { + return true; + // 7.2 If the b value is a Date object, the a value is + // equivalent if it is also a Date object that refers to the same time. + } + let aIsDate = instanceOf(a, "Date"); + let bIsDate = instanceOf(b, "Date"); + if (aIsDate || bIsDate) { + if (!aIsDate || !bIsDate) { + return false; + } + if (isNaN(a.getTime()) && isNaN(b.getTime())) { + return true; + } + return a.getTime() === b.getTime(); + // 7.3 If the b value is a RegExp object, the a value is + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). + } + let aIsRegExp = instanceOf(a, "RegExp"); + let bIsRegExp = instanceOf(b, "RegExp"); + if (aIsRegExp || bIsRegExp) { + return ( + aIsRegExp && + bIsRegExp && + a.source === b.source && + a.global === b.global && + a.multiline === b.multiline && + a.lastIndex === b.lastIndex && + a.ignoreCase === b.ignoreCase + ); + // 7.4 Other pairs that do not both pass typeof value == "object", + // equivalence is determined by ==. + } + if (typeof a != "object" || typeof b != "object") { + return a == b; + } + // 7.5 For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical 'prototype' property. Note: this + // accounts for both named and indexed properties on Arrays. + return objEquiv(a, b); +} + +function instanceOf(object, type) { + return Object.prototype.toString.call(object) == "[object " + type + "]"; +} + +function isUndefinedOrNull(value) { + return value === null || value === undefined; +} + +function isArguments(object) { + return instanceOf(object, "Arguments"); +} + +function objEquiv(a, b) { + if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) { + return false; + } + // An identical 'prototype' property. + if ((a.prototype || undefined) != (b.prototype || undefined)) { + return false; + } + // Object.keys may be broken through screwy arguments passing. Converting to + // an array solves the problem. + if (isArguments(a)) { + if (!isArguments(b)) { + return false; + } + a = Array.prototype.slice.call(a); + b = Array.prototype.slice.call(b); + return _deepEqual(a, b); + } + let ka, kb; + try { + ka = Object.keys(a); + kb = Object.keys(b); + } catch (e) { + // Happens when one is a string literal and the other isn't + return false; + } + // Having the same number of owned properties (keys incorporates + // hasOwnProperty) + if (ka.length != kb.length) { + return false; + } + // The same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + // Equivalent values for every corresponding key, and possibly expensive deep + // test + for (let key of ka) { + if (!_deepEqual(a[key], b[key])) { + return false; + } + } + return true; +} + +// ... End of previously MIT-licensed code. 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..7a98f83a1f
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+  
+  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..408bb82f39
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_copy_move.html
@@ -0,0 +1,360 @@
+
+
+
+
+
+  
+  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..be7ab23697
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_create_unique.html
@@ -0,0 +1,86 @@
+
+
+
+
+
+  
+  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..54168235b0
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_dir_iteration.html
@@ -0,0 +1,96 @@
+
+
+
+
+
+  
+  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..077f0b5c1c
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_getfile.html
@@ -0,0 +1,84 @@
+
+
+
+
+
+  
+  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..6af9b2e6f8
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_mac_xattr.html
@@ -0,0 +1,91 @@
+
+
+
+
+
+  
+  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..6827b24cc6
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_mkdir.html
@@ -0,0 +1,135 @@
+
+
+
+
+
+  
+  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..2243eb1eda
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_read_write.html
@@ -0,0 +1,524 @@
+
+
+
+
+
+  
+  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..0acb191e1b
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_read_write_json.html
@@ -0,0 +1,193 @@
+
+
+
+
+
+  
+  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..cdea016732
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_read_write_utf8.html
@@ -0,0 +1,384 @@
+
+
+
+
+
+  
+  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..f368fc09d3
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_remove.html
@@ -0,0 +1,118 @@
+
+
+
+
+
+  
+  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..e508817a41
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_stat_set_modification_time.html
@@ -0,0 +1,242 @@
+
+
+
+
+
+  
+  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..a5b72bd078
--- /dev/null
+++ b/dom/system/tests/ioutils/test_ioutils_windows_file_attributes.html
@@ -0,0 +1,137 @@
+
+
+
+
+
+  
+  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