1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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>
|