summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webtransport/bfcache
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/mozilla/tests/webtransport/bfcache
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/mozilla/tests/webtransport/bfcache')
-rw-r--r--testing/web-platform/mozilla/tests/webtransport/bfcache/closed.tentative.https.html119
-rw-r--r--testing/web-platform/mozilla/tests/webtransport/bfcache/connected.tentative.https.html116
-rw-r--r--testing/web-platform/mozilla/tests/webtransport/bfcache/failed.tentative.https.html120
-rw-r--r--testing/web-platform/mozilla/tests/webtransport/bfcache/helpers.js17
-rw-r--r--testing/web-platform/mozilla/tests/webtransport/bfcache/ports.sub.js12
-rw-r--r--testing/web-platform/mozilla/tests/webtransport/bfcache/worker.js50
6 files changed, 434 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/webtransport/bfcache/closed.tentative.https.html b/testing/web-platform/mozilla/tests/webtransport/bfcache/closed.tentative.https.html
new file mode 100644
index 0000000000..8fbf27922d
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webtransport/bfcache/closed.tentative.https.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>WebTransport API: bfcache closed</title>
+<link rel=help href="https://w3c.github.io/webtransport/">
+<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 src="/common/get-host-info.sub.js"></script>
+<script type="module">
+
+import { runWebTransportBfcacheTest } from "./helpers.js";
+import { webtransport_url } from "./ports.sub.js";
+import { worker_function } from "./worker.js";
+
+const id = token();
+const url = webtransport_url(`client-close.py?token=${id}`);
+
+// We can't load ./worker.js in runWebTransportBfcacheTest, because it uses
+// execute_script, and so the baseurl is helper.sub.js's baseurl.
+// We also can't pass a worker to it. So, load the worker as a string, and pass
+// the string and turn it into a worker via a Blob. Fun!
+const worker_string = worker_function.toString().replace(/^async function .+\{?|\}$/g, '');
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (url) => {
+ window.wt = new WebTransport(url);
+ await window.wt.ready;
+ window.wt.close();
+ await window.wt.closed;
+ },
+ argsBeforeNavigation: [url],
+ shouldBeCached: true
+}, "A closed WebTransport on MainThread must allow bfcache");
+
+// we can't have runWebTransportBfcacheTest use [scripts] to load the helper.js
+// script into the test, due to the same baseurl issue, so just do this inline
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new SharedWorker(URL.createObjectURL(workerBlob));
+ worker.port.start();
+ await postToWorkerAndWait(worker.port, { op: "openandclose", url: url });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: true
+}, "A closed WebTransport in a shared worker must allow bfcache");
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new Worker(URL.createObjectURL(workerBlob));
+ await postToWorkerAndWait(window.worker, { op: "open", url: url });
+ await postToWorkerAndWait(window.worker, { op: "close" });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: true
+}, "A closed WebTransport in a worker must allow bfcache");
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new Worker(URL.createObjectURL(workerBlob));
+ await postToWorkerAndWait(window.worker, { op: "open", url: url });
+ await postToWorkerAndWait(window.worker, { op: "close" });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: true
+}, "A closed WebTransport in a nested worker must allow bfcache");
+
+</script>
diff --git a/testing/web-platform/mozilla/tests/webtransport/bfcache/connected.tentative.https.html b/testing/web-platform/mozilla/tests/webtransport/bfcache/connected.tentative.https.html
new file mode 100644
index 0000000000..de2a2fc7a7
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webtransport/bfcache/connected.tentative.https.html
@@ -0,0 +1,116 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>WebTransport API: bfcache connected</title>
+<link rel=help href="https://w3c.github.io/webtransport/">
+<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 src="/common/get-host-info.sub.js"></script>
+<script type="module">
+
+import { runWebTransportBfcacheTest } from "./helpers.js";
+import { webtransport_url } from "./ports.sub.js";
+import { worker_function } from "./worker.js";
+
+const id = token();
+const url = webtransport_url(`client-close.py?token=${id}`);
+
+// We can't load ./worker.js in runWebTransportBfcacheTest, because it uses
+// execute_script, and so the baseurl is helper.sub.js's baseurl, which is
+// the main wpt test directory.
+// We also can't pass a worker to it. So, load the worker as a string, and pass
+// the string and turn it into a worker via a Blob. Fun!
+const worker_string = worker_function.toString().replace(/^async function .+\{?|\}$/g, '');
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (url) => {
+ window.wt = new WebTransport(url);
+ await window.wt.ready;
+ },
+ argsBeforeNavigation: [url],
+ shouldBeCached: false
+}, "A connected WebTransport on MainThread must prevent bfcache");
+
+// we can't have runWebTransportBfcacheTest use [scripts] to load the helper.js
+// script into the test, due to the same baseurl issue, so just do this inline
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new SharedWorker(URL.createObjectURL(workerBlob));
+ worker.port.start();
+ await postToWorkerAndWait(worker.port, { op: "open", url: url });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: false
+}, "A connected WebTransport in a shared worker must prevent bfcache");
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new Worker(URL.createObjectURL(workerBlob));
+ await postToWorkerAndWait(window.worker, { op: "open", url: url });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: false
+}, "A connected WebTransport in a worker must prevent bfcache");
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new Worker(URL.createObjectURL(workerBlob));
+ await postToWorkerAndWait(window.worker, { op: "open", url: url });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: false
+}, "A connected WebTransport in a nested worker must prevent bfcache");
+
+</script>
diff --git a/testing/web-platform/mozilla/tests/webtransport/bfcache/failed.tentative.https.html b/testing/web-platform/mozilla/tests/webtransport/bfcache/failed.tentative.https.html
new file mode 100644
index 0000000000..94facfa6a8
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webtransport/bfcache/failed.tentative.https.html
@@ -0,0 +1,120 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>WebTransport API: bfcache failed</title>
+<link rel=help href="https://w3c.github.io/webtransport/">
+<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 src="/common/get-host-info.sub.js"></script>
+<script type="module">
+
+import { runWebTransportBfcacheTest } from "./helpers.js";
+import { webtransport_url } from "./ports.sub.js";
+import { worker_function } from "./worker.js";
+
+const id = token();
+const url = webtransport_url('custom-response.py?:status=404');
+
+// We can't load ./worker.js in runWebTransportBfcacheTest, because it uses
+// execute_script, and so the baseurl is helper.sub.js's baseurl.
+// We also can't pass a worker to it. So, load the worker as a string, and pass
+// the string and turn it into a worker via a Blob. Fun!
+const worker_string = worker_function.toString().replace(/^async function .+\{?|\}$/g, '');
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (url) => {
+ // make sure it isn't immediately freed
+ try {
+ window.wt = new WebTransport(url);
+ await window.wt.ready;
+ assert_unreached('Opened invalid URL');
+ } catch(e) {
+ }
+ },
+ argsBeforeNavigation: [url],
+ shouldBeCached: true
+}, "A failed WebTransport on MainThread must allow bfcache");
+
+// we can't have runWebTransportBfcacheTest use [scripts] to load the helper.js
+// script into the test, due to the same baseurl issue, so just do this inline
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new SharedWorker(URL.createObjectURL(workerBlob));
+ worker.port.start();
+ await postToWorkerAndWait(worker.port, { op: "open", url: url });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: true
+}, "A failed WebTransport in a shared worker must allow bfcache");
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new Worker(URL.createObjectURL(workerBlob));
+ await postToWorkerAndWait(window.worker, { op: "open", url: url });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: true
+}, "A failed WebTransport in a worker must allow bfcache");
+
+runWebTransportBfcacheTest({
+ funcBeforeNavigation: async (worker_string, url) => {
+ let next_request_id = 0;
+ function postToWorkerAndWait(worker, data) {
+ return new Promise(resolve => {
+ data.rqid = next_request_id++;
+ worker.postMessage(data);
+ const listener = event => {
+ if (event.data.rqid !== data.rqid)
+ return;
+ worker.removeEventListener('message', listener);
+ resolve(event.data);
+ };
+ worker.addEventListener('message', listener);
+ });
+ };
+
+ let workerBlob = new Blob([worker_string], { type:'text/javascript' });
+ window.worker = new Worker(URL.createObjectURL(workerBlob));
+ await postToWorkerAndWait(window.worker, { op: "open", url: url });
+ },
+ argsBeforeNavigation: [worker_string, url],
+ shouldBeCached: true
+}, "A failed WebTransport in a nested worker must allow bfcache");
+
+</script>
diff --git a/testing/web-platform/mozilla/tests/webtransport/bfcache/helpers.js b/testing/web-platform/mozilla/tests/webtransport/bfcache/helpers.js
new file mode 100644
index 0000000000..d8ab9b62d3
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webtransport/bfcache/helpers.js
@@ -0,0 +1,17 @@
+export function runWebTransportBfcacheTest(params, description) {
+ runBfcacheTest(
+ {
+ // due to the baseurl issue, this would try to load the scripts from
+ // the main wpt test directory
+ // scripts: ["/webtransport/resources/helpers.js"],
+ openFunc: url =>
+ window.open(
+ url + `&prefix=${location.pathname}-${description}`,
+ "_blank",
+ "noopener"
+ ),
+ ...params,
+ },
+ description
+ );
+}
diff --git a/testing/web-platform/mozilla/tests/webtransport/bfcache/ports.sub.js b/testing/web-platform/mozilla/tests/webtransport/bfcache/ports.sub.js
new file mode 100644
index 0000000000..cb4262c9f4
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webtransport/bfcache/ports.sub.js
@@ -0,0 +1,12 @@
+// The file including this must also include /common/get-host-info.sub.js to
+// pick up the necessary constants.
+
+const HOST = get_host_info().ORIGINAL_HOST;
+const PORT = '{{ports[webtransport-h3][0]}}';
+const BASE = `https://${HOST}:${PORT}`;
+
+// Create URL for WebTransport session.
+export function webtransport_url(handler) {
+ return `${BASE}/webtransport/handlers/${handler}`;
+}
+
diff --git a/testing/web-platform/mozilla/tests/webtransport/bfcache/worker.js b/testing/web-platform/mozilla/tests/webtransport/bfcache/worker.js
new file mode 100644
index 0000000000..b0eb890f42
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webtransport/bfcache/worker.js
@@ -0,0 +1,50 @@
+export async function worker_function() {
+
+let wt = null;
+
+async function processMessage(e) {
+ const target = this;
+
+ function respond(data) {
+ target.postMessage(Object.assign(data, {rqid: e.data.rqid}));
+ }
+
+ // ORB will block errors (webtransport_url('custom-response.py?:status=404');)
+ // so we need to try/catch
+ try {
+ switch (e.data.op) {
+ case 'open': {
+ wt = new WebTransport(e.data.url);
+ await wt.ready;
+ respond({ack: 'open'});
+ break;
+ }
+
+ case 'openandclose': {
+ wt = new WebTransport(e.data.url);
+ await wt.ready;
+ wt.close();
+ await wt.closed;
+ respond({ack: 'openandclose'});
+ break;
+ }
+
+ case 'close': {
+ wt.close();
+ await wt.closed;
+ respond({ack: 'close'});
+ break;
+ }
+ }
+ } catch(e) {
+ respond({failed: true});
+ }
+}
+
+self.addEventListener('message', processMessage);
+
+self.addEventListener('connect', ev => {
+ // Shared worker case
+ ev.ports[0].onmessage = processMessage;
+});
+}