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

70 строки
1.5 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Audio-playback should be inactive when input file 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 audio = new Audio();
audio.src = "audioEndedDuringPlaying.webm";
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");
continueTest();
}
};
function continueTest() {
generator.next();
}
function audioPlayingStart() {
observerService.addObserver(observer, "audio-playback");
ok(true, "Observer set");
expectedPlaybackActive = 'active';
info("Audio playing start");
audio.play();
}
function audioBecomeSilentDuringPlaying() {
info("Audio would become silent during playing");
expectedPlaybackActive = 'inactive-nonaudible';
}
function finish() {
observerService.removeObserver(observer, "audio-playback");
ok(true, "Observer removed");
SimpleTest.finish();
}
function* runTest() {
yield audioPlayingStart();
yield audioBecomeSilentDuringPlaying();
finish();
}
continueTest();
</script>
</body>
</html>