tor-browser

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

test_setValueCurveWithNonFiniteElements.html (1565B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <meta charset=utf-8>
      4 <head>
      5  <title>Bug 1308437 - setValueCurve should throw on non-finite elements</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 SimpleTest.waitForExplicitFinish();
     13 
     14 function testInfiniteElement(audioContext, audioParam) {
     15  // create value curve with infinite element
     16  var arr = new Float32Array(5);
     17  arr[0] = 0.5;
     18  arr[1] = 1;
     19  arr[2] = Infinity;
     20  arr[3] = 1;
     21  arr[4] = 0.5;
     22 
     23  try {
     24    audioParam.setValueCurveAtTime(arr, audioContext.currentTime(), 2);
     25    ok(false, "We shouldn't be able to call setValueCurve with Infinity but we can");
     26  } catch(e) {
     27    ok(e instanceof TypeError, "TypeError is thrown");
     28  }
     29 };
     30 
     31 function testNanElement(audioContext, audioParam) {
     32  // create value curve with infinite element
     33  var arr = new Float32Array(5);
     34  arr[0] = 0.5;
     35  arr[1] = 1;
     36  arr[2] = NaN;
     37  arr[3] = 1;
     38  arr[4] = 0.5;
     39 
     40  try {
     41    audioParam.setValueCurveAtTime(arr, audioContext.currentTime(), 2);
     42    ok(false, "We shouldn't be able to call setValueCurve with NaN but we can");
     43  } catch(e) {
     44    ok(e instanceof TypeError, "TypeError is thrown");
     45  }
     46 };
     47 
     48 addLoadEvent(function() {
     49  var audioContext = new AudioContext();
     50  var gainNode = audioContext.createGain();
     51 
     52  testInfiniteElement(audioContext, gainNode.gain);
     53  testNanElement(audioContext, gainNode.gain);
     54 
     55  SimpleTest.finish();
     56 });
     57 </script>
     58 </pre>
     59 </body>
     60 </html>