-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathcontenttype.any.js
64 lines (56 loc) · 2.44 KB
/
contenttype.any.js
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
// META: global=window,worker
// META: script=/wasm/jsapi/assertions.js
promise_test(t => {
const response = fetch("/wasm/incrementer.wasm").then(res => new Response(res.body));
return promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
}, "Response with no Content-Type: compileStreaming");
promise_test(t => {
const response = fetch("/wasm/incrementer.wasm").then(res => new Response(res.body));
return promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(response));
}, "Response with no Content-Type: instantiateStreaming");
const invalidContentTypes = [
"",
"application/javascript",
"application/octet-stream",
"text/wasm",
"application/wasm;",
"application/wasm;x",
"application/wasm;charset=UTF-8",
];
for (const contenttype of invalidContentTypes) {
promise_test(t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
return promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
}, `Response with Content-Type ${format_value(contenttype)}: compileStreaming`);
promise_test(t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
return promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(response));
}, `Response with Content-Type ${format_value(contenttype)}: instantiateStreaming`);
}
const validContentTypes = [
"application/wasm",
"APPLICATION/wasm",
"APPLICATION/WASM",
];
for (const contenttype of validContentTypes) {
promise_test(async t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
const module = await WebAssembly.compileStreaming(response);
assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype,
"prototype");
}, `Response with Content-Type ${format_value(contenttype)}: compileStreaming`);
promise_test(async t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
const result = await WebAssembly.instantiateStreaming(response);
assert_WebAssemblyInstantiatedSource(
result,
{
"increment": {
"kind": "function",
"name": "0",
"length": 1
}
}
);
}, `Response with Content-Type ${format_value(contenttype)}: instantiateStreaming`);
}