Bug 1235612 - Part 6: Add and modify test cases. r=baku

MozReview-Commit-ID: FqIvjv7t2Vp

--HG--
extra : rebase_source : 32826bbbc22e8a99f20bf969e43d876feaa45e61
This commit is contained in:
Alastor Wu 2016-05-03 17:59:49 +08:00
Родитель 9771068fea
Коммит d457b34009
7 изменённых файлов: 191 добавлений и 4 удалений

Двоичные данные
browser/base/content/test/general/audio.ogg

Двоичный файл не отображается.

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

@ -147,6 +147,7 @@ skip-if = os == "linux" # Bug 924307
[browser_addKeywordSearch.js]
[browser_alltabslistener.js]
[browser_audioTabIcon.js]
tags = audiochannel
[browser_backButtonFitts.js]
skip-if = os == "mac" # The Fitt's Law back button is not supported on OS X
[browser_beforeunload_duplicate_dialogs.js]

Двоичные данные
dom/base/test/audioEndedDuringPlaying.webm Normal file

Двоичный файл не отображается.

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

@ -1,6 +1,7 @@
[DEFAULT]
support-files =
audio.ogg
audioEndedDuringPlaying.webm
iframe_bug962251.html
iframe_bug976673.html
iframe_main_bug1022229.html
@ -285,6 +286,10 @@ skip-if = buildapp == 'b2g' # Requires webgl support
[test_audioNotification.html]
tags = audiochannel
skip-if = buildapp == 'mulet'
[test_audioNotificationSilent_audioFile.html]
tags = audiochannel
[test_audioNotificationSilent_webAudio.html]
tags = audiochannel
[test_audioNotificationStream.html]
tags = audiochannel
skip-if = buildapp == 'mulet'

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

@ -0,0 +1,82 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Audio-playback should be inactive when input file is silent</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7">
SimpleTest.waitForExplicitFinish();
var generator = runTest();
var expectedPlaybackActive = null;
var expectedPlaying = 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: function(subject, topic, data) {
is(topic, "audio-playback", "audio-playback received");
is(data, expectedPlaybackActive, "Corrrect audible state");
is(!audio.ended, expectedPlaying, "Corrrect playing state");
continueTest();
}
};
function continueTest() {
try {
generator.next();
} catch (e if e instanceof StopIteration) {
error("Stop test because of exception!");
}
}
function audioPlayingStart() {
observerService.addObserver(observer, "audio-playback", false);
ok(true, "Observer set");
expectedPlaybackActive = 'active';
expectedPlaying = true;
info("Audio playing start");
audio.play();
}
function audioBecomeSilentDuringPlaying() {
info("Audio would become silent during playing");
expectedPlaybackActive = 'inactive';
expectedPlaying = true;
}
function audioPlayingEnd() {
audio.onended = function() {
info("Audio playback ended");
audio.onended = null;
observerService.removeObserver(observer, "audio-playback");
ok(true, "Observer removed");
SimpleTest.finish();
};
}
function runTest() {
yield audioPlayingStart();
yield audioBecomeSilentDuringPlaying();
yield audioPlayingEnd();
}
continueTest();
</script>
</body>
</html>

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

@ -0,0 +1,103 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Audio-playback should be inactive when web-audio is silent</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7">
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: function(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() {
try {
generator.next();
} catch (e if e instanceof StopIteration) {
error("Stop test because of exception!");
}
}
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", false);
ok(true, "Observer set");
expectedPlaybackActive = 'active';
expectedPlaying = "running";
info("Audio playing start");
playOscillatorNode();
}
function audioBecomeSilentDuringPlaying() {
info("Audio would become silent during playing");
expectedPlaybackActive = 'inactive';
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();
yield finish();
}
continueTest();
</script>
</body>
</html>

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

@ -3,10 +3,6 @@
var audio = new Audio();
audio.oncanplay = function() {
audio.oncanplay = null;
audio.onplaying = function() {
audio.onplaying = null;
audio.pause();
};
audio.play();
};
audio.src = "audio.ogg";