tor-browser

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

test_large_arraybuffers.html (4141B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1688616
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for large ArrayBuffers and views</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1688616">Mozilla Bug 1688616</a>
     14 <p id="display"></p>
     15 <div id="content" style="display: none">
     16 
     17 </div>
     18 <pre id="test">
     19 </pre>
     20  <script type="application/javascript">
     21    /* global TestFunctions */
     22 
     23    SimpleTest.waitForExplicitFinish();
     24    SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, go);
     25 
     26    function checkThrowsTooLarge(f) {
     27      let ex;
     28      try{
     29        f();
     30        ok(false, "Should have thrown!");
     31      } catch (e) {
     32        ex = e;
     33      }
     34      ok(ex.toString().includes("larger than 2 GB"), "Got exception: " + ex);
     35    }
     36 
     37    function go() {
     38      let test = new TestFunctions();
     39 
     40      const gb = 1 * 1024 * 1024 * 1024;
     41      let ab = new ArrayBuffer(5 * gb);
     42      checkThrowsTooLarge(() => test.testNotAllowShared(ab));
     43      checkThrowsTooLarge(() => test.testAllowShared(ab));
     44      checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBuffer: ab}));
     45      checkThrowsTooLarge(() => test.testUnionOfBufferSource(ab));
     46      checkThrowsTooLarge(() => { test.arrayBuffer = ab; });
     47      checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = ab; });
     48      checkThrowsTooLarge(() => { test.sequenceOfArrayBuffer = [ab]; });
     49      checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [ab]; });
     50 
     51      let ta = new Int8Array(ab, 0, 3 * gb);
     52      checkThrowsTooLarge(() => test.testNotAllowShared(ta));
     53      checkThrowsTooLarge(() => test.testAllowShared(ta));
     54      checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: ta}));
     55      checkThrowsTooLarge(() => test.testUnionOfBufferSource(ta));
     56      checkThrowsTooLarge(() => { test.arrayBufferView = ta; });
     57      checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = ta; });
     58      checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [ta]; });
     59      checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [ta]; });
     60 
     61      let dv = new DataView(ab);
     62      checkThrowsTooLarge(() => test.testNotAllowShared(dv));
     63      checkThrowsTooLarge(() => test.testAllowShared(dv));
     64      checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: dv}));
     65      checkThrowsTooLarge(() => test.testUnionOfBufferSource(dv));
     66      checkThrowsTooLarge(() => { test.arrayBufferView = dv; });
     67      checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = dv; });
     68      checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [dv]; });
     69      checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [dv]; });
     70 
     71      if (this.SharedArrayBuffer) {
     72        let sab = new SharedArrayBuffer(5 * gb);
     73        checkThrowsTooLarge(() => test.testAllowShared(sab));
     74        checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBuffer: sab}));
     75        checkThrowsTooLarge(() => test.testUnionOfAllowSharedBufferSource(sab));
     76        checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = sab; });
     77        checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [sab]; });
     78 
     79        let sta = new Int8Array(sab);
     80        checkThrowsTooLarge(() => test.testAllowShared(sta));
     81        checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBufferView: sta}));
     82        checkThrowsTooLarge(() => test.testUnionOfAllowSharedBufferSource(sta));
     83        checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = sta; });
     84        checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [sta]; });
     85      }
     86 
     87      // Small views on large buffers are fine.
     88      let ta2 = new Int8Array(ab, 4 * gb);
     89      is(ta2.byteLength, 1 * gb, "Small view on large ArrayBuffer");
     90      test.testNotAllowShared(ta2);
     91      test.arrayBufferView = ta2;
     92 
     93      SimpleTest.finish();
     94    }
     95  </script>
     96 </body>
     97 </html>