tor-browser

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

Blob.js (1709B)


      1 'use strict'
      2 
      3 self.test_blob = (fn, expectations) => {
      4  var expected = expectations.expected,
      5      type = expectations.type,
      6      desc = expectations.desc;
      7 
      8  promise_test(async (t) => {
      9    var blob = fn();
     10    assert_true(blob instanceof Blob);
     11    assert_false(blob instanceof File);
     12    assert_equals(blob.type, type);
     13    assert_equals(blob.size, expected.length);
     14 
     15    const text = await blob.text();
     16    assert_equals(text, expected);
     17  }, desc);
     18 }
     19 
     20 self.test_blob_binary = (fn, expectations) => {
     21  var expected = expectations.expected,
     22      type = expectations.type,
     23      desc = expectations.desc;
     24 
     25  promise_test(async (t) => {
     26    var blob = fn();
     27    assert_true(blob instanceof Blob);
     28    assert_false(blob instanceof File);
     29    assert_equals(blob.type, type);
     30    assert_equals(blob.size, expected.length);
     31 
     32    const ab = await blob.arrayBuffer();
     33    assert_true(ab instanceof ArrayBuffer,
     34      "Result should be an ArrayBuffer");
     35    assert_array_equals(new Uint8Array(ab), expected);
     36  }, desc);
     37 }
     38 
     39 // Assert that two TypedArray objects have the same byte values
     40 self.assert_equals_typed_array = (array1, array2) => {
     41  const [view1, view2] = [array1, array2].map((array) => {
     42    assert_true(array.buffer instanceof ArrayBuffer,
     43      'Expect input ArrayBuffers to contain field `buffer`');
     44    return new DataView(array.buffer, array.byteOffset, array.byteLength);
     45  });
     46 
     47  assert_equals(view1.byteLength, view2.byteLength,
     48    'Expect both arrays to be of the same byte length');
     49 
     50  const byteLength = view1.byteLength;
     51 
     52  for (let i = 0; i < byteLength; ++i) {
     53    assert_equals(view1.getUint8(i), view2.getUint8(i),
     54      `Expect byte at buffer position ${i} to be equal`);
     55  }
     56 }