diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/web-locks/bfcache | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/web-locks/bfcache')
6 files changed, 287 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-locks/bfcache/abort.tentative.https.html b/testing/web-platform/tests/web-locks/bfcache/abort.tentative.https.html new file mode 100644 index 0000000000..35d9b11270 --- /dev/null +++ b/testing/web-platform/tests/web-locks/bfcache/abort.tentative.https.html @@ -0,0 +1,64 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>Web Locks API: bfcache</title> +<link rel=help href="https://w3c.github.io/web-locks/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/common/dispatcher/dispatcher.js"></script> +<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> +<script type="module"> + import { runWebLocksBfcacheTest } from "./helpers.js"; + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + const controller = new AbortController(); + const promise = navigator.locks.request( + uniqueNameByQuery(), + { signal: controller.signal }, + () => new Promise(() => { }) + ); + controller.abort(); + await promise.catch(() => { }); + }, + shouldBeCached: true + }, "An immediately aborted lock on main thread should not prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new Worker("/web-locks/resources/worker.js"); + await postToWorkerAndWait(worker, { + op: "request", + name: uniqueNameByQuery(), + abortImmediately: true + }); + }, + shouldBeCached: true + }, "An immediately aborted lock on a worker should not prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new Worker("/web-locks/resources/parentworker.js"); + await postToWorkerAndWait(worker, { + op: "request", + name: uniqueNameByQuery(), + abortImmediately: true + }); + }, + shouldBeCached: true + }, "An immediately aborted lock on a nested worker should not prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new SharedWorker("/web-locks/resources/worker.js"); + worker.port.start(); + await postToWorkerAndWait(worker.port, { + op: "request", + name: uniqueNameByQuery(), + abortImmediately: true + }); + }, + shouldBeCached: true + }, "An immediately aborted lock on a shared worker should not prevent bfcache"); +</script> diff --git a/testing/web-platform/tests/web-locks/bfcache/held.tentative.https.html b/testing/web-platform/tests/web-locks/bfcache/held.tentative.https.html new file mode 100644 index 0000000000..9d670c5889 --- /dev/null +++ b/testing/web-platform/tests/web-locks/bfcache/held.tentative.https.html @@ -0,0 +1,45 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>Web Locks API: bfcache</title> +<link rel=help href="https://w3c.github.io/web-locks/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/common/dispatcher/dispatcher.js"></script> +<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> +<script type="module"> + import { runWebLocksBfcacheTest } from "./helpers.js"; + + runWebLocksBfcacheTest({ + funcBeforeNavigation: () => { + navigator.locks.request(uniqueNameByQuery(), () => new Promise(() => { })); + }, + shouldBeCached: false + }, "A held lock on the main thread must prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new Worker("/web-locks/resources/worker.js"); + await postToWorkerAndWait(worker, { op: "request", name: uniqueNameByQuery() }); + }, + shouldBeCached: false + }, "A held lock on a worker must prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new Worker("/web-locks/resources/parentworker.js"); + await postToWorkerAndWait(worker, { op: "request", name: uniqueNameByQuery() }); + }, + shouldBeCached: false + }, "A held lock on a nested worker must prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new SharedWorker("/web-locks/resources/worker.js"); + worker.port.start(); + await postToWorkerAndWait(worker.port, { op: "request", name: uniqueNameByQuery() }); + }, + shouldBeCached: false + }, "A held lock on a shared worker must prevent bfcache"); +</script> diff --git a/testing/web-platform/tests/web-locks/bfcache/helpers.js b/testing/web-platform/tests/web-locks/bfcache/helpers.js new file mode 100644 index 0000000000..7997f982a8 --- /dev/null +++ b/testing/web-platform/tests/web-locks/bfcache/helpers.js @@ -0,0 +1,15 @@ +export function runWebLocksBfcacheTest(params, description) { + runBfcacheTest( + { + scripts: ["/web-locks/resources/helpers.js"], + openFunc: url => + window.open( + url + `&prefix=${location.pathname}-${description}`, + "_blank", + "noopener" + ), + ...params, + }, + description + ); +} diff --git a/testing/web-platform/tests/web-locks/bfcache/release-across-thread.tentative.https.html b/testing/web-platform/tests/web-locks/bfcache/release-across-thread.tentative.https.html new file mode 100644 index 0000000000..374cee8b6d --- /dev/null +++ b/testing/web-platform/tests/web-locks/bfcache/release-across-thread.tentative.https.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>Web Locks API: bfcache</title> +<link rel=help href="https://w3c.github.io/web-locks/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/common/dispatcher/dispatcher.js"></script> +<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> +<script type="module"> + import { runWebLocksBfcacheTest } from "./helpers.js"; + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + navigator.locks.request(uniqueNameByQuery(), () => new Promise(() => { })); + window.worker = new Worker("/web-locks/resources/worker.js"); + const { lock_id } = await postToWorkerAndWait(worker, { op: "request", name: uniqueNameByQuery() }); + await postToWorkerAndWait(worker, { op: "release", lock_id }); + }, + shouldBeCached: false, + }, "A held lock on main thread must prevent bfcache even after worker releases locks"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + const controller = new AbortController(); + navigator.locks.request(uniqueNameByQuery(), { signal: controller.signal }, () => new Promise(() => { })); + window.worker = new Worker("/web-locks/resources/worker.js"); + await postToWorkerAndWait(worker, { op: "request", name: uniqueNameByQuery() }); + controller.abort(); + }, + shouldBeCached: false, + }, "A held lock on worker must prevent bfcache even after main thread releases locks"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + const controller = new AbortController(); + navigator.locks.request(uniqueNameByQuery(), { signal: controller.signal }, () => new Promise(() => { })); + window.worker = new SharedWorker("/web-locks/resources/worker.js"); + worker.port.start(); + await postToWorkerAndWait(worker.port, { op: "request", name: uniqueNameByQuery() }); + controller.abort(); + }, + shouldBeCached: false, + }, "A held lock on shared worker must prevent bfcache even after main thread releases locks"); +</script> diff --git a/testing/web-platform/tests/web-locks/bfcache/release.tentative.https.html b/testing/web-platform/tests/web-locks/bfcache/release.tentative.https.html new file mode 100644 index 0000000000..97f542fc2e --- /dev/null +++ b/testing/web-platform/tests/web-locks/bfcache/release.tentative.https.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>Web Locks API: bfcache</title> +<link rel=help href="https://w3c.github.io/web-locks/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/common/dispatcher/dispatcher.js"></script> +<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> +<script type="module"> + import { runWebLocksBfcacheTest } from "./helpers.js"; + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + await navigator.locks.request(uniqueNameByQuery(), () => { }); + }, + shouldBeCached: true, + }, "A released lock on the main thread should not prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new Worker("/web-locks/resources/worker.js"); + const { lock_id } = await postToWorkerAndWait(worker, { op: "request", name: uniqueNameByQuery() }); + await postToWorkerAndWait(worker, { op: "release", lock_id }); + }, + shouldBeCached: true, + }, "A released lock on a worker should not prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new Worker("/web-locks/resources/parentworker.js"); + const { lock_id } = await postToWorkerAndWait(worker, { op: "request", name: uniqueNameByQuery() }); + await postToWorkerAndWait(worker, { op: "release", lock_id }); + }, + shouldBeCached: true, + }, "A released lock on a nested worker should not prevent bfcache"); + + runWebLocksBfcacheTest({ + funcBeforeNavigation: async () => { + window.worker = new SharedWorker("/web-locks/resources/worker.js"); + worker.port.start(); + const { lock_id } = await postToWorkerAndWait(worker.port, { op: "request", name: uniqueNameByQuery() }); + await postToWorkerAndWait(worker.port, { op: "release", lock_id }); + }, + shouldBeCached: true, + }, "A released lock on a shared worker should not prevent bfcache"); +</script> diff --git a/testing/web-platform/tests/web-locks/bfcache/sharedworker-multiple.tentative.https.html b/testing/web-platform/tests/web-locks/bfcache/sharedworker-multiple.tentative.https.html new file mode 100644 index 0000000000..71a79bc5fa --- /dev/null +++ b/testing/web-platform/tests/web-locks/bfcache/sharedworker-multiple.tentative.https.html @@ -0,0 +1,69 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>Web Locks API: bfcache</title> +<link rel=help href="https://w3c.github.io/web-locks/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/common/dispatcher/dispatcher.js"></script> +<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> +<script> + const connectToSharedWorker = async () => { + await window.pageShowPromise; + window.worker = new SharedWorker("/web-locks/resources/worker.js"); + worker.port.start(); + } + function double_docs_test(func, description) { + promise_test(async t => { + const pageA1 = new RemoteContext(token()); + const pageA2 = new RemoteContext(token()); + const pageB1 = new RemoteContext(token()); + const pageB2 = new RemoteContext(token()); + + const urlA1 = executorPath + pageA1.context_id; + const urlA2 = executorPath + pageA2.context_id; + const urlB1 = originCrossSite + executorPath + pageB1.context_id; + const urlB2 = originCrossSite + executorPath + pageB2.context_id; + + window.open(urlA1, "_blank", "noopener"); + window.open(urlA2, "_blank", "noopener"); + + await func(pageA1, pageA2); + + await Promise.all([ + navigateAndThenBack(pageA1, pageB1, urlB1), + navigateAndThenBack(pageA2, pageB2, urlB2), + ]); + + await assert_not_bfcached(pageA1); + await assert_not_bfcached(pageA2); + }, description); + } + + double_docs_test(async (pageA1, pageA2) => { + await Promise.all([ + pageA1.execute_script(connectToSharedWorker), + pageA2.execute_script(connectToSharedWorker), + ]); + await pageA1.execute_script(async () => { + const script = document.createElement("script"); + script.src = "/web-locks/resources/helpers.js"; + document.head.append(script); + await new Promise(resolve => script.onload = resolve); + await postToWorkerAndWait(worker.port, { op: "request", name: uniqueNameByQuery() }); + }); + }, "A new held lock must prevent bfcache on all connected documents"); + + double_docs_test(async (pageA1, pageA2) => { + await pageA1.execute_script(connectToSharedWorker); + await pageA1.execute_script(async () => { + const script = document.createElement("script"); + script.src = "/web-locks/resources/helpers.js"; + document.head.append(script); + await new Promise(resolve => script.onload = resolve); + await postToWorkerAndWait(worker.port, { op: "request", name: uniqueNameByQuery() }); + }); + await pageA2.execute_script(connectToSharedWorker); + }, "An existing held lock must prevent bfcache on all connected documents"); +</script> |