tor-browser

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

audioworkletnode-onerror.https.html (2433B)


      1 <!DOCTYPE html>
      2 <title>Test onprocessorerror handler in AudioWorkletNode</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script>
      6 let context = null;
      7 
      8 promise_setup(async () => {
      9  const sampleRate = 48000;
     10  const renderLength = sampleRate * 0.1;
     11  context = new OfflineAudioContext(1, renderLength, sampleRate);
     12 
     13  // Loads all processor definitions that are necessary for tests in this file.
     14  await context.audioWorklet.addModule('./processors/error-processor.js');
     15 });
     16 
     17 promise_test(async () => {
     18  const constructorErrorWorkletNode =
     19      new AudioWorkletNode(context, 'constructor-error');
     20  let error = await new Promise(resolve => {
     21    constructorErrorWorkletNode.onprocessorerror = (e) => resolve(e);
     22  });
     23  assert_true(error instanceof ErrorEvent,
     24      'onprocessorerror argument should be an ErrorEvent when ' +
     25      'the constructor of AudioWorkletProcessor has an error.');
     26 }, 'Test if |onprocessorerror| is called for an exception thrown from the ' +
     27    'processor constructor.');
     28 
     29 promise_test(async () => {
     30  // An arbitrary Blob for testing. This is not deserializable on
     31  // AudioWorkletGlobalScope.
     32  const blob = new Blob([JSON.stringify({ hello: "world"}, null, 2)], {
     33    type: "application/json",
     34  });
     35  const emptyErrorWorkletNode =
     36      new AudioWorkletNode(context, 'empty-error', {processorOptions: {blob}});
     37  let error = await new Promise(resolve => {
     38    emptyErrorWorkletNode.onprocessorerror = (e) => resolve(e);
     39  });
     40  assert_true(error instanceof ErrorEvent,
     41      'onprocessorerror argument should be an ErrorEvent when ' +
     42      'the constructor of AudioWorkletProcessor has an error.');
     43 }, 'Test if |onprocessorerror| is called for a transfered object that cannot ' +
     44   'be deserialized on the AudioWorkletGlobalScope.');
     45 
     46 promise_test(async () => {
     47  const processErrorWorkletNode =
     48      new AudioWorkletNode(context, 'process-error');
     49  let error = await new Promise(resolve => {
     50    processErrorWorkletNode.onprocessorerror = (e) => resolve(e);
     51    // Need to start render to cause an exception in process().
     52    context.startRendering();
     53  });
     54  assert_true(error instanceof ErrorEvent,
     55      'onprocessorerror argument should be an ErrorEvent when the ' +
     56      'process method of the AudioWorkletProcessor has an error.');
     57 }, 'Test if |onprocessorerror| is called upon failure of process() method.');
     58 </script>