Bug 1767549 - Ensure that AudioContext state transition happen at the right time w.r.t. cubeb stream initialization time. r=karlt

Differential Revision: https://phabricator.services.mozilla.com/D146713
This commit is contained in:
Paul Adenot 2022-05-24 08:52:13 +00:00
Родитель 3f95ffa19f
Коммит 376ac34fe5
2 изменённых файлов: 50 добавлений и 0 удалений

Просмотреть файл

@ -134,6 +134,7 @@ skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1538360
[test_pannerNodeHRTFSymmetry.html]
[test_pannerNodeTail.html]
[test_pannerNode_maxDistance.html]
[test_slowStart.html]
[test_setValueCurveWithNonFiniteElements.html]
[test_stereoPannerNode.html]
[test_stereoPannerNodePassThrough.html]

Просмотреть файл

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AudioContext.currentTime</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("This test needs to periodically query the AudioContext's position.");
const CUBEB_INIT_DELAY = 5000;
// Delay audio stream start by a good 5 seconds
SpecialPowers.pushPrefEnv({"set": [["media.cubeb.slow_stream_init_ms",
CUBEB_INIT_DELAY]]}, runTest);
function runTest() {
let ac = new AudioContext();
let notStartedYetCount = 0;
let startWallClockTime = performance.now();
is(ac.currentTime, 0, "AudioContext.currentTime should be 0 initially");
is(ac.state, "suspended", "AudioContext.currentTime is initially suspended");
let intervalHandle = setInterval(function() {
if (ac.state == "running") {
clearInterval(intervalHandle);
return;
}
is(ac.currentTime, 0, "AudioContext.currentTime is still 0");
is(ac.state, "suspended", "AudioContext.currentTime is still suspended");
notStartedYetCount++;
});
ac.onstatechange = function() {
is(ac.state, "running", "The AudioContext eventually started.");
var startDuration = performance.now() - startWallClockTime;
info(`AudioContext start time with a delay of ${CUBEB_INIT_DELAY}):
${startDuration}`);
ok(notStartedYetCount > 0, "We should have observed the AudioContext in \"suspended\" state");
ok(startDuration >= CUBEB_INIT_DELAY, "The AudioContext state transition was correct.");
SimpleTest.finish();
}
}
</script>
</pre>
</body>
</html>