Access-Control-Expose-Headers parsed incorrectly
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / wasm / wasm_stream_instantiate_test.html
1 <!DOCTYPE html>
2 <script src="/resources/testharness.js"></script>
3 <script src="/resources/testharnessreport.js"></script>
4 <script src="/common/get-host-info.sub.js"></script>
5 <script>
6   promise_test(async function() {
7       var response = await fetch('resources/incrementer.wasm');
8       const { instance, module } = await WebAssembly.instantiateStreaming(response);
9       assert_true(instance instanceof WebAssembly.Instance);
10       assert_true(module instanceof WebAssembly.Module);
11   }, "instantiateStreaming using resolved response");
12
13   promise_test(async function() {
14       var response = await fetch('resources/incrementer.wasm');
15       const { instance } = await WebAssembly.instantiateStreaming(response);
16       assert_true(instance instanceof WebAssembly.Instance);
17   }, "instantiateStreaming using resolved response and check instantiate");
18
19   promise_test(async function() {
20       var result = fetch('resources/incrementer.wasm');
21       const { instance } = await WebAssembly.instantiateStreaming(result);
22       assert_true(instance instanceof WebAssembly.Instance);
23   }, "instantiateStreaming using promise response from fetch and check instantiate");
24
25   promise_test(async function() {
26     try {
27       var result = fetch('resources/incrementer.wrong_mime_type.wasm');
28       const { instance } = await WebAssembly.instantiateStreaming(result);
29       assert_true(false);
30     } catch (e) {
31       assert_true(e.message.includes('MIME type'));
32       assert_true(e instanceof Error);
33     }
34   }, "instantiateStreaming raise error if wrong mime type");
35
36   promise_test(async function() {
37     try {
38       var result = fetch('resources/incrementer.no_mime_type.wasm');
39       const { instance } = await WebAssembly.instantiateStreaming(result);
40       assert_true(false);
41     } catch (e) {
42       assert_true(e.message.includes('MIME type'));
43       assert_true(e instanceof Error);
44     }
45   }, "instantiateStreaming raise error if no mime type");
46
47   promise_test(async function() {
48     try {
49       var result = fetch('resources/incrementer1.wasm');
50       const { instance } = await WebAssembly.instantiateStreaming(result);
51       assert_true(false);
52     } catch (e) {
53       assert_equals(e.message, "Response has not returned OK status");
54       assert_true(e instanceof Error);
55     }
56   }, "instantiateStreaming raise error if 404 status");
57
58   const getWasmUrl = fileName => { 
59     var host_info = get_host_info();
60     var url = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT  +  '/wasm/';
61     return url + fileName + "?pipe=header(Access-Control-Allow-Origin,*)";
62   };
63
64   promise_test(async function() {
65       var result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "cors"} );
66       const { instance } = await WebAssembly.instantiateStreaming(result);
67       assert_true(instance instanceof WebAssembly.Instance);
68   }, "instantiateStreaming check CORS");
69
70   promise_test(async function() {
71     try {
72       var result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "no-cors"} );
73       const { instance } = await WebAssembly.instantiateStreaming(result);
74       assert_true(false);
75     } catch (e) {
76       assert_equals(e.message, "Response is not CORS-same-origin");
77       assert_true(e instanceof Error);
78     }
79   }, "instantiateStreaming raise error if no-cors");
80
81   promise_test(async function() {
82     const { instance } = await fetch('resources/incrementer.wasm')
83       .then(v => v.arrayBuffer())
84       .then(v => WebAssembly.instantiateStreaming(new Response(v, { headers: { "Content-Type" : "application/wasm" }})));
85     assert_true(instance instanceof WebAssembly.Instance);
86   }, "instantiateStreaming receive promise with response created from ArrayBuffer");
87
88   promise_test(async function() {
89     const { instance } = a = await fetch('resources/incrementer.wasm')
90       .then(v => v.arrayBuffer())
91       .then(buffer => {
92         const stream = new ReadableStream({ 
93           start(controller) {
94             (async () => {
95               await Promise.resolve().then(() => controller.enqueue(buffer.slice(0, 20)));
96               await Promise.resolve().then(() => controller.enqueue(buffer.slice(20, buffer.byteLength)));
97               await Promise.resolve().then(() => controller.close());
98             })();
99           }
100         });
101         return stream; 
102       }) 
103       .then(stream => WebAssembly.instantiateStreaming(new Response(stream, { headers: { "Content-Type" : "application/wasm" }})));
104     assert_true(instance instanceof WebAssembly.Instance);
105   }, "instantiateStreaming receive response that deliver data by chunks as bufferArray");
106 </script>