test_slowStart.html (1754B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test AudioContext.currentTime</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 SimpleTest.requestFlakyTimeout("This test needs to periodically query the AudioContext's position."); 14 const CUBEB_INIT_DELAY = 5000; 15 // Delay audio stream start by a good 5 seconds 16 SpecialPowers.pushPrefEnv({"set": [["media.cubeb.slow_stream_init_ms", 17 CUBEB_INIT_DELAY]]}, runTest); 18 19 20 function runTest() { 21 let ac = new AudioContext(); 22 let notStartedYetCount = 0; 23 let startWallClockTime = performance.now(); 24 is(ac.currentTime, 0, "AudioContext.currentTime should be 0 initially"); 25 is(ac.state, "suspended", "AudioContext.currentTime is initially suspended"); 26 let intervalHandle = setInterval(function() { 27 if (ac.state == "running" || ac.currentTime > 0) { 28 clearInterval(intervalHandle); 29 return; 30 } 31 is(ac.currentTime, 0, "AudioContext.currentTime is still 0"); 32 is(ac.state, "suspended", "AudioContext.currentTime is still suspended"); 33 notStartedYetCount++; 34 }); 35 ac.onstatechange = function() { 36 is(ac.state, "running", "The AudioContext eventually started."); 37 var startDuration = performance.now() - startWallClockTime; 38 info(`AudioContext start time with a delay of ${CUBEB_INIT_DELAY}): ${startDuration}`); 39 ok(notStartedYetCount > 0, "We should have observed the AudioContext in \"suspended\" state"); 40 ok(startDuration >= CUBEB_INIT_DELAY, "The AudioContext state transition was correct."); 41 SimpleTest.finish(); 42 } 43 } 44 45 </script> 46 </pre> 47 </body> 48 </html>