tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

wasm_stream_compile_test.any.js (5415B)


      1 // META: title=WebAssembly.compileStreaming
      2 // META: script=/common/get-host-info.sub.js
      3  promise_test(async function() {
      4      const response = await fetch('resources/incrementer.wasm');
      5      const module = await WebAssembly.compileStreaming(response);
      6      assert_true(module instanceof WebAssembly.Module);
      7  }, "compileStreaming using resolved response");
      8 
      9  promise_test(async function() {
     10      const response = await fetch('resources/incrementer.wasm');
     11      const module = await WebAssembly.compileStreaming(response);
     12      const instance = new WebAssembly.Instance(module);
     13      assert_true(instance instanceof WebAssembly.Instance);
     14  }, "compileStreaming using resolved response and check instantiate");
     15 
     16  promise_test(async function() {
     17      const result = fetch('resources/incrementer.wasm');
     18      const module = await WebAssembly.compileStreaming(result);
     19      const instance = new WebAssembly.Instance(module);
     20      assert_true(instance instanceof WebAssembly.Instance);
     21  }, "compileStreaming using promise response from fetch and check instantiate");
     22 
     23  promise_test(async function(t) {
     24      const result = fetch('resources/incrementer.wrong_mime_type.wasm');
     25      await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
     26  }, "compileStreaming raise error if wrong mime type");
     27 
     28  promise_test(async function(t) {
     29      const result = fetch('resources/incrementer.no_mime_type.wasm?pipe=header(Content-Type,)');
     30      await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
     31  }, "compileStreaming raise error if no mime type");
     32 
     33  promise_test(async function(t) {
     34      const result = fetch('webapi/status.py?status=404');
     35      await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
     36  }, "compileStreaming raise error if 404 status");
     37 
     38  const getWasmUrl = fileName => {
     39      const host_info = get_host_info();
     40      const url = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + '/wasm/webapi/';
     41      return url + fileName + "?pipe=header(Access-Control-Allow-Origin,*)";
     42  };
     43 
     44  promise_test(async function() {
     45      const result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "cors"} );
     46      const module = await WebAssembly.compileStreaming(result);
     47      assert_true(module instanceof WebAssembly.Module);
     48  }, "compileStreaming check CORS");
     49 
     50  promise_test(async function(t) {
     51      const result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "no-cors"} );
     52      await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
     53  }, "compileStreaming raise error if no-cors");
     54 
     55  promise_test(async function() {
     56      const v = await fetch('resources/incrementer.wasm');
     57      const buffer = await v.arrayBuffer();
     58      const response = new Response(buffer, { headers: { "Content-Type" : "application/wasm" }});
     59      const module = await WebAssembly.compileStreaming(response);
     60      assert_true(module instanceof WebAssembly.Module);
     61  }, "compileStreaming receive promise with response created from ArrayBuffer");
     62 
     63  promise_test(async function() {
     64      const v = await fetch('resources/incrementer.wasm');
     65      const buffer = await v.arrayBuffer();
     66      const stream = new ReadableStream({
     67        start(controller) {
     68          (async () => {
     69            await Promise.resolve().then(() => controller.enqueue(new Uint8Array(buffer.slice(0, 20))));
     70            await Promise.resolve().then(() => controller.enqueue(new Uint8Array(buffer.slice(20, buffer.byteLength))));
     71            await Promise.resolve().then(() => controller.close());
     72          })();
     73        }
     74      });
     75      const response = new Response(stream, { headers: { "Content-Type" : "application/wasm" }});
     76      const module = await WebAssembly.compileStreaming(response);
     77      assert_true(module instanceof WebAssembly.Module);
     78  }, "compileStreaming using ReadableStream with Uint8Array chunks");
     79 
     80  promise_test(async function(t) {
     81      const v = await fetch('resources/incrementer.wasm');
     82      const buffer = await v.arrayBuffer();
     83      const stream = new ReadableStream({
     84        start(controller) {
     85          // Enqueuing an ArrayBuffer rather a Uint8Array per
     86          // https://streams.spec.whatwg.org/#read-loop
     87          controller.enqueue(buffer);
     88          controller.close();
     89        }
     90      });
     91      const response = new Response(stream, { headers: { "Content-Type" : "application/wasm" }});
     92      await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
     93  }, "compileStreaming using ReadableStream with ArrayBuffer chunk");
     94 
     95  promise_test(async function() {
     96      const response = await fetch('resources/incrementer.wasm');
     97      const blob = await response.blob();
     98      const module = await WebAssembly.compileStreaming(new Response(blob, { headers: { "Content-Type" : "application/wasm" }}));
     99      assert_true(module instanceof WebAssembly.Module);
    100  }, "compileStreaming using blob");
    101 
    102  promise_test(async function(t) {
    103      const response = await fetch('resources/incrementer.wasm');
    104      const blob = await response.blob();
    105      const formData = new FormData;
    106      formData.append('blob', blob);
    107      formData.append('blob2', "Hello");
    108      await promise_rejects_js(t, WebAssembly.CompileError, WebAssembly.compileStreaming(new Response(formData, { headers: { "Content-Type" : "application/wasm" }})));
    109  }, "compileStreaming using FormData");