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 --- ...-writable_unlocked_on_tab_close.https.window.js | 70 ++++++++++++++++++++++ .../fs-open_writable_after_trigger.sub.html | 45 ++++++++++++++ .../fs-open_writable_then_close_tab.sub.html | 20 +++++++ .../mozilla/tests/dom/fs/support/testHelpers.js | 15 +++++ 4 files changed, 150 insertions(+) create mode 100644 testing/web-platform/mozilla/tests/dom/fs/fs-writable_unlocked_on_tab_close.https.window.js create mode 100644 testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_after_trigger.sub.html create mode 100644 testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_then_close_tab.sub.html create mode 100644 testing/web-platform/mozilla/tests/dom/fs/support/testHelpers.js (limited to 'testing/web-platform/mozilla/tests/dom/fs') diff --git a/testing/web-platform/mozilla/tests/dom/fs/fs-writable_unlocked_on_tab_close.https.window.js b/testing/web-platform/mozilla/tests/dom/fs/fs-writable_unlocked_on_tab_close.https.window.js new file mode 100644 index 0000000000..6e8192aaef --- /dev/null +++ b/testing/web-platform/mozilla/tests/dom/fs/fs-writable_unlocked_on_tab_close.https.window.js @@ -0,0 +1,70 @@ +// META: title=Origin private file system used from multiple tabs +// META: script=support/testHelpers.js + +promise_test(async t => { + const bc = new BroadcastChannel("Coordinate writables"); + + function firstReady(win) { + return new Promise(resolve => { + // Blur triggers after the unload event and after window.closed is set + win.onblur = () => { + // Closing the low-level file handle may get stuck, but the unlocking + // request can only be sent to the parent after the handle is closed. + // There is no guarantee when or if the closing will be complete. + // + // Therefore, the content process shutdown does not wait for the + // completion but sets window.closed and calls the unload listeners + // while actually still holding onto some resources. + // + // Since in this test we mainly want to ensure that a file + // does not remain locked indefinitely, we wait for a reasonable amount + // of time before creating a new writable, corresponding roughly to + // a 500ms closing delay. + const timeoutMs = 400; + setTimeout(() => { + resolve(win); + }, timeoutMs); + }; + }); + } + + const firstTabName = "support/fs-open_writable_then_close_tab.sub.html"; + const firstTab = await firstReady(window.open(firstTabName)); + assert_true(firstTab.closed, "Is the first tab already closed?"); + + function secondReady(win) { + return new Promise(resolve => { + bc.onmessage = e => { + if (e.data === "Second window ready!") { + resolve(win); + } + }; + }); + } + + const secondTabName = "support/fs-open_writable_after_trigger.sub.html"; + const secondTab = await secondReady(window.open(secondTabName)); + + let isDone = false; + let childStatus = "Success"; + + const secondSucceeded = new Promise(resolve => { + bc.onmessage = e => { + isDone = true; + if (e.data !== "Success") { + childStatus = e.data; + } + + resolve(); + }; + }); + + bc.postMessage("Create writable in the second window"); + + await secondSucceeded; + assert_true(isDone, "Did the second tab respond?"); + + await fetch_tests_from_window(secondTab); + + assert_equals(childStatus, "Success"); +}, `writable available for other tabs after one tab is closed`); diff --git a/testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_after_trigger.sub.html b/testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_after_trigger.sub.html new file mode 100644 index 0000000000..b64d97083f --- /dev/null +++ b/testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_after_trigger.sub.html @@ -0,0 +1,45 @@ + + +Child context test(s) + + + + + +
+ + + diff --git a/testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_then_close_tab.sub.html b/testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_then_close_tab.sub.html new file mode 100644 index 0000000000..098fe83b1f --- /dev/null +++ b/testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_then_close_tab.sub.html @@ -0,0 +1,20 @@ + + +Child context test(s) + + + + +
+ + + diff --git a/testing/web-platform/mozilla/tests/dom/fs/support/testHelpers.js b/testing/web-platform/mozilla/tests/dom/fs/support/testHelpers.js new file mode 100644 index 0000000000..5cf47435c1 --- /dev/null +++ b/testing/web-platform/mozilla/tests/dom/fs/support/testHelpers.js @@ -0,0 +1,15 @@ +async function waitUntil(isWaitDone, untilMs, stepMs = 25) { + const startMs = Date.now(); + + return new Promise((resolve, reject) => { + const areWeDoneYet = setInterval(async function() { + if (await isWaitDone()) { + clearInterval(areWeDoneYet); + resolve(); + } else if (Date.now() > startMs + untilMs) { + clearInterval(areWeDoneYet); + reject(new Error("Timed out after " + untilMs + "ms")); + } + }, stepMs); + }); +} -- cgit v1.2.3