diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /toolkit/components/promiseworker/tests/xpcshell/test_Promise.js | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/promiseworker/tests/xpcshell/test_Promise.js')
-rw-r--r-- | toolkit/components/promiseworker/tests/xpcshell/test_Promise.js | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js b/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js index f7581b664f..f9091a2b85 100644 --- a/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js +++ b/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js @@ -16,7 +16,22 @@ const { setTimeout } = ChromeUtils.importESModule( var WORKER_SOURCE_URI = "chrome://promiseworker/content/worker.js"; do_load_manifest("data/chrome.manifest"); -var worker = new BasePromiseWorker(WORKER_SOURCE_URI); + +const UUID = crypto.randomUUID(); + +const SOME_ARRAY = new Uint8Array(4); +for (let i = 0; i < 4; ++i) { + SOME_ARRAY[i] = i; +} + +async function echo(message) { + return new BasePromiseWorker.Meta([message, UUID, SOME_ARRAY.buffer], { + transfers: [SOME_ARRAY.buffer], + }); +} + +var worker = new BasePromiseWorker(WORKER_SOURCE_URI, {}, { echo }); + worker.log = function (...args) { info("Controller: " + args.join(" ")); }; @@ -166,3 +181,34 @@ add_task(async function test_terminate() { "ChromeWorker instances should differ" ); }); + +function cloneArrayBuffer(original) { + const clone = new ArrayBuffer(original.byteLength); + const originalView = new Uint8Array(original); + const cloneView = new Uint8Array(clone); + cloneView.set(originalView); + return clone; +} + +add_task(async function test_bidirectional() { + // Before we transfer the array, we clone it + const arrayCopy = cloneArrayBuffer(SOME_ARRAY.buffer); + + let message = ["test_simple_args", Math.random()]; + + // Checking the array buffer size + Assert.equal( + SOME_ARRAY.buffer.byteLength, + 4, + "The buffer is not detached yet" + ); + let result = await worker.post("bounceWithExtraCalls", message); + + // After the post call, the array was transferred and SOME_ARRAY should be empty + Assert.equal(SOME_ARRAY.buffer.byteLength, 0, "The buffer has been detached"); + + // The echo() function in the worker adds to the message a string, an uuid and has the transferred array + message.push(["Posting something unrelated", UUID, arrayCopy]); + + Assert.deepEqual(result, message); +}); |