gecko-dev/dom/base/test/test_audioNotificationSilen...

100 строки
2.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Audio-playback should be inactive when web-audio is silent</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
var generator = runTest();
var expectedPlaybackActive = null;
var expectedPlaying = null;
var ac = new AudioContext();
var audibleDuration = 3;
var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
var observer = {
observe(subject, topic, data) {
is(topic, "audio-playback", "audio-playback received");
is(data, expectedPlaybackActive, "Corrrect audible state");
is(ac.state, expectedPlaying, "Corrrect playing state");
continueTest();
}
};
function continueTest() {
generator.next();
}
function playOscillatorNode() {
var dest = ac.destination;
var osc = ac.createOscillator();
osc.connect(dest);
osc.start(0);
osc.stop(ac.currentTime + audibleDuration);
}
function audioPlayingStart() {
observerService.addObserver(observer, "audio-playback");
ok(true, "Observer set");
expectedPlaybackActive = 'active';
expectedPlaying = "running";
info("Audio playing start");
playOscillatorNode();
}
function audioBecomeSilentDuringPlaying() {
info("Audio would become silent during playing");
expectedPlaybackActive = 'inactive-pause';
expectedPlaying = "running";
}
function finish() {
observerService.removeObserver(observer, "audio-playback");
ok(true, "Observer removed");
SimpleTest.finish();
}
function startAudioContext() {
if (ac.state != "running") {
ac.resume();
ac.onstatechange = function() {
if (ac.state == "running") {
ok(true, "AudioContext starts running!");
ac.onstatechange = null;
continueTest();
}
}
} else {
ok(true, "AudioContext is running!");
continueTest();
}
}
function* runTest() {
yield startAudioContext();
yield audioPlayingStart();
yield audioBecomeSilentDuringPlaying();
finish();
}
continueTest();
</script>
</body>
</html>