tor-browser

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

retrospective-setValueAtTime.html (2380B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>Test setValueAtTime with startTime in the past</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7    <script src="/webaudio/resources/audit-util.js"></script>
      8    <script src="retrospective-test.js"></script>
      9  </head>
     10  <body>
     11    <script>
     12      // Test setValueAtTime with startTime in the past
     13      promise_test(async () => {
     14        const {context, source, test, reference} = setupRetrospectiveGraph();
     15        // Suspend the context at this frame so we can synchronously set up
     16        // automations.
     17        const suspendFrame = 128;
     18 
     19        // Use a ramp of slope 1 per frame to measure time.
     20        // The end value is the extent of exact precision in single
     21        // precision float.
     22        const rampEnd = context.length - suspendFrame;
     23        const rampEndSeconds = context.length / context.sampleRate;
     24 
     25        context.suspend(suspendFrame / context.sampleRate)
     26            .then(() => {
     27              // Call setValueAtTime with a time in the past
     28              test.gain.setValueAtTime(0.0, 0.5 * context.currentTime);
     29              test.gain.linearRampToValueAtTime(rampEnd, rampEndSeconds);
     30              reference.gain.setValueAtTime(0.0, context.currentTime);
     31              reference.gain.linearRampToValueAtTime(
     32                  rampEnd, rampEndSeconds);
     33              context.resume();
     34            });
     35 
     36        source.start();
     37 
     38        const resultBuffer = await context.startRendering();
     39        const actualChannelData = resultBuffer.getChannelData(0);
     40        const expectedChannelData = resultBuffer.getChannelData(1);
     41 
     42        // Until the suspendFrame, both should be exactly equal to 1.
     43        assert_constant_value(
     44            actualChannelData.slice(0, suspendFrame),
     45            1,
     46            `Test[0:${suspendFrame - 1}]`);
     47        assert_constant_value(
     48            expectedChannelData.slice(0, suspendFrame),
     49            1,
     50            `Reference[0:${suspendFrame - 1}]`);
     51 
     52        // After the suspendFrame, both should be equal (and not constant)
     53        assert_array_equals_exact(
     54            actualChannelData.slice(suspendFrame),
     55            expectedChannelData.slice(suspendFrame),
     56            `Test[${suspendFrame}:]`);
     57      }, 'Test setValueAtTime with startTime in the past');
     58    </script>
     59  </body>
     60 </html>