tor-browser

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

test_AudioNodeDevtoolsAPI.html (1699B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test the devtool AudioNode API</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <pre id="test">
     10 <script class="testbody" type="text/javascript">
     11 
     12  SimpleTest.waitForExplicitFinish();
     13 
     14  function id(node) {
     15    return SpecialPowers.getPrivilegedProps(node, "id");
     16  }
     17 
     18  var ac = new AudioContext();
     19  var ids;
     20  var weak;
     21  (function() {
     22    var src1 = ac.createBufferSource();
     23    var src2 = ac.createBufferSource();
     24    ok(id(src2) > id(src1), "The ID should be monotonic");
     25    ok(id(src1) > id(ac.destination), "The ID of the destination node should be the lowest");
     26    ids = [id(src1), id(src2)];
     27    weak = SpecialPowers.Cu.getWeakReference(src1);
     28    is(SpecialPowers.unwrap(weak.get()), src1, "The node should support a weak reference");
     29  })();
     30  function observer(subject, topic, data) {
     31    var id = parseInt(data);
     32    var index = ids.indexOf(id);
     33    if (index != -1) {
     34      info("Dropping id " + id + " at index " + index);
     35      ids.splice(index, 1);
     36      if (!ids.length) {
     37        SimpleTest.executeSoon(function() {
     38          is(weak.get(), null, "The weak reference must be dropped now");
     39          SpecialPowers.removeObserver(observer, "webaudio-node-demise");
     40          SimpleTest.finish();
     41        });
     42      }
     43    }
     44  }
     45  SpecialPowers.addObserver(observer, "webaudio-node-demise");
     46 
     47  forceCC();
     48  forceCC();
     49 
     50  function forceCC() {
     51    SpecialPowers.DOMWindowUtils.cycleCollect();
     52    SpecialPowers.DOMWindowUtils.garbageCollect();
     53    SpecialPowers.DOMWindowUtils.garbageCollect();
     54  }
     55 
     56 </script>
     57 </pre>
     58 </body>
     59 </html>