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/chrome.ini | 9 + dom/system/tests/file_bug1197901.html | 16 + 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 ++ dom/system/tests/mochitest.ini | 10 + dom/system/tests/pathutils_worker.js | 37 ++ dom/system/tests/test_bug1197901.html | 96 ++++ dom/system/tests/test_constants.xhtml | 115 ++++ dom/system/tests/test_pathutils.html | 603 +++++++++++++++++++++ dom/system/tests/test_pathutils_worker.xhtml | 38 ++ dom/system/tests/worker_constants.js | 52 ++ 28 files changed, 3770 insertions(+) create mode 100644 dom/system/tests/chrome.ini create mode 100644 dom/system/tests/file_bug1197901.html 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 create mode 100644 dom/system/tests/mochitest.ini create mode 100644 dom/system/tests/pathutils_worker.js create mode 100644 dom/system/tests/test_bug1197901.html create mode 100644 dom/system/tests/test_constants.xhtml create mode 100644 dom/system/tests/test_pathutils.html create mode 100644 dom/system/tests/test_pathutils_worker.xhtml create mode 100644 dom/system/tests/worker_constants.js (limited to 'dom/system/tests') diff --git a/dom/system/tests/chrome.ini b/dom/system/tests/chrome.ini new file mode 100644 index 0000000000..2cee7b4829 --- /dev/null +++ b/dom/system/tests/chrome.ini @@ -0,0 +1,9 @@ +[DEFAULT] + +[test_constants.xhtml] +support-files = + worker_constants.js +[test_pathutils.html] +[test_pathutils_worker.xhtml] +support-files = + pathutils_worker.js diff --git a/dom/system/tests/file_bug1197901.html b/dom/system/tests/file_bug1197901.html new file mode 100644 index 0000000000..e4ca9fd380 --- /dev/null +++ b/dom/system/tests/file_bug1197901.html @@ -0,0 +1,16 @@ +
Sensor events testing
+ 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 @@
+
+
+
+
+  
+
+  
+    

+ +

+  
+  
diff --git a/dom/system/tests/mochitest.ini b/dom/system/tests/mochitest.ini new file mode 100644 index 0000000000..ec18d0016d --- /dev/null +++ b/dom/system/tests/mochitest.ini @@ -0,0 +1,10 @@ +[DEFAULT] +tags = condprof +scheme = https + +support-files = + file_bug1197901.html + +[test_bug1197901.html] +skip-if = os == "android" + condprof #: "Only focused window should get the sensor events" diff --git a/dom/system/tests/pathutils_worker.js b/dom/system/tests/pathutils_worker.js new file mode 100644 index 0000000000..606769d8e1 --- /dev/null +++ b/dom/system/tests/pathutils_worker.js @@ -0,0 +1,37 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* eslint-env mozilla/chrome-worker */ + +"use strict"; + +/* import-globals-from /testing/mochitest/tests/SimpleTest/WorkerSimpleTest.js */ +importScripts("chrome://mochikit/content/tests/SimpleTest/WorkerSimpleTest.js"); + +self.onmessage = async function (message) { + let expected = message.data; + info("ON message"); + info(JSON.stringify(expected)); + const profileDir = await PathUtils.getProfileDir(); + is( + profileDir, + expected.profileDir, + "PathUtils.profileDir() in a worker should match PathUtils.profileDir on main thread" + ); + + const localProfileDir = await PathUtils.getLocalProfileDir(); + is( + localProfileDir, + expected.localProfileDir, + "PathUtils.getLocalProfileDir() in a worker should match PathUtils.localProfileDir on main thread" + ); + + const tempDir = await PathUtils.getTempDir(); + is( + tempDir, + expected.tempDir, + "PathUtils.getTempDir() in a worker should match PathUtils.tempDir on main thread" + ); + + finish(); +}; diff --git a/dom/system/tests/test_bug1197901.html b/dom/system/tests/test_bug1197901.html new file mode 100644 index 0000000000..7e1866ffa3 --- /dev/null +++ b/dom/system/tests/test_bug1197901.html @@ -0,0 +1,96 @@ + + + + + + Test for Bug 1197901 + + + + + +Mozilla Bug +

+ +
+
+ + + + diff --git a/dom/system/tests/test_constants.xhtml b/dom/system/tests/test_constants.xhtml new file mode 100644 index 0000000000..f7450e0a6c --- /dev/null +++ b/dom/system/tests/test_constants.xhtml @@ -0,0 +1,115 @@ + + + + + + + +

+ +

+  
+  
diff --git a/dom/system/tests/test_pathutils.html b/dom/system/tests/test_pathutils.html new file mode 100644 index 0000000000..86ba5c49e9 --- /dev/null +++ b/dom/system/tests/test_pathutils.html @@ -0,0 +1,603 @@ + + + + + + + PathUtils tests + + + + + + + + + + diff --git a/dom/system/tests/test_pathutils_worker.xhtml b/dom/system/tests/test_pathutils_worker.xhtml new file mode 100644 index 0000000000..dc181ce07d --- /dev/null +++ b/dom/system/tests/test_pathutils_worker.xhtml @@ -0,0 +1,38 @@ + + + + + + + + + +

+ +

+  
+  
diff --git a/dom/system/tests/worker_constants.js b/dom/system/tests/worker_constants.js new file mode 100644 index 0000000000..b55bb8d0fa --- /dev/null +++ b/dom/system/tests/worker_constants.js @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +/* eslint-env mozilla/chrome-worker */ +/* global OS */ + +function log(text) { + dump("WORKER " + text + "\n"); +} + +function send(message) { + self.postMessage(message); +} + +self.onmessage = function (msg) { + self.onmessage = function (msgInner) { + log("ignored message " + JSON.stringify(msgInner.data)); + }; + let { umask } = msg.data; + try { + test_umaskWorkerThread(umask); + } catch (x) { + log("Catching error: " + x); + log("Stack: " + x.stack); + log("Source: " + x.toSource()); + ok(false, x.toString() + "\n" + x.stack); + } + finish(); +}; + +function finish() { + send({ kind: "finish" }); +} + +function ok(condition, description) { + send({ kind: "ok", condition, description }); +} +function is(a, b, description) { + send({ kind: "is", a, b, description }); +} +function isnot(a, b, description) { + send({ kind: "isnot", a, b, description }); +} + +// Test that OS.Constants.Sys.umask is set properly in ChromeWorker thread +function test_umaskWorkerThread(umask) { + is( + umask, + OS.Constants.Sys.umask, + "OS.Constants.Sys.umask is set properly on worker thread: " + + ("0000" + umask.toString(8)).slice(-4) + ); +} -- cgit v1.2.3