tor-browser

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

encoded-audio-chunk.any.js (1899B)


      1 // META: global=window,dedicatedworker
      2 // META: script=/webcodecs/utils.js
      3 
      4 test(t => {
      5  let chunk = new EncodedAudioChunk({type: 'key',
      6                                     timestamp: 10,
      7                                     duration: 123,
      8                                     data: new Uint8Array([0x0A, 0x0B, 0x0C])});
      9  assert_equals(chunk.type, 'key', 'type');
     10  assert_equals(chunk.timestamp, 10, 'timestamp');
     11  assert_equals(chunk.duration, 123, 'duration');
     12  assert_equals(chunk.byteLength, 3, 'byteLength');
     13  let copyDest = new Uint8Array(3);
     14  chunk.copyTo(copyDest);
     15  assert_equals(copyDest[0], 0x0A, 'copyDest[0]');
     16  assert_equals(copyDest[1], 0x0B, 'copyDest[1]');
     17  assert_equals(copyDest[2], 0x0C, 'copyDest[2]');
     18 
     19  // Make another chunk with different values for good measure.
     20  chunk = new EncodedAudioChunk({type: 'delta',
     21                                 timestamp: 100,
     22                                 data: new Uint8Array([0x00, 0x01])});
     23  assert_equals(chunk.type, 'delta', 'type');
     24  assert_equals(chunk.timestamp, 100, 'timestamp');
     25  assert_equals(chunk.duration, null, 'missing duration');
     26  assert_equals(chunk.byteLength, 2, 'byteLength');
     27  copyDest = new Uint8Array(2);
     28  chunk.copyTo(copyDest);
     29  assert_equals(copyDest[0], 0x00, 'copyDest[0]');
     30  assert_equals(copyDest[1], 0x01, 'copyDest[1]');
     31 }, 'Test we can construct an EncodedAudioChunk.');
     32 
     33 test(t => {
     34  let chunk = new EncodedAudioChunk({type: 'delta',
     35                                     timestamp: 100,
     36                                     data: new Uint8Array([0x00, 0x01, 0x02])});
     37  assert_throws_js(
     38    TypeError,
     39    () => chunk.copyTo(new Uint8Array(2)), 'destination is not large enough');
     40 
     41  const detached = makeDetachedArrayBuffer();
     42  assert_throws_js(
     43    TypeError,
     44    () => chunk.copyTo(detached), 'destination is detached');
     45 }, 'Test copyTo() exception if destination invalid');