tor-browser

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

encoded-video-chunk.any.js (2351B)


      1 // META: global=window,dedicatedworker
      2 // META: script=/webcodecs/utils.js
      3 
      4 test(t => {
      5  let chunk = new EncodedVideoChunk({type: 'key',
      6                                     timestamp: 10,
      7                                     duration: 300,
      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, 300, '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 EncodedVideoChunk({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, '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 EncodedVideoChunk.');
     32 
     33 test(t => {
     34  let chunk = new EncodedVideoChunk({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 destiation invalid');
     46 
     47 test(t => {
     48  let chunk = new EncodedVideoChunk({type: 'key',
     49                                     timestamp: 10,
     50                                     duration: 300,
     51                                     data: new Uint8Array()});
     52  assert_equals(chunk.byteLength, 0, 'byteLength');
     53  let copyDest = new Uint8Array();
     54  chunk.copyTo(copyDest);
     55  assert_equals(copyDest.length, 0, 'copyDest.length');
     56 }, 'Test we can construct an zero-sized EncodedVideoChunk.');