Bug 1069795 - Use promise and pushEnv instead of setEnv. r=jwwang

This commit is contained in:
Alfredo Yang 2014-09-22 02:21:00 -04:00
parent 49a68ccfb5
commit 3ba92dcaa3
4 changed files with 84 additions and 34 deletions

View File

@ -1,38 +1,78 @@
function check_ogg(v, enabled) {
function check_ogg(v, enabled, finish) {
function check(type, expected) {
is(v.canPlayType(type), enabled ? expected : "", type);
}
// Ogg types
check("video/ogg", "maybe");
check("audio/ogg", "maybe");
check("application/ogg", "maybe");
function basic_test() {
return new Promise(function(resolve, reject) {
// Ogg types
check("video/ogg", "maybe");
check("audio/ogg", "maybe");
check("application/ogg", "maybe");
// Supported Ogg codecs
check("audio/ogg; codecs=vorbis", "probably");
check("video/ogg; codecs=vorbis", "probably");
check("video/ogg; codecs=vorbis,theora", "probably");
check("video/ogg; codecs=\"vorbis, theora\"", "probably");
check("video/ogg; codecs=theora", "probably");
// Supported Ogg codecs
check("audio/ogg; codecs=vorbis", "probably");
check("video/ogg; codecs=vorbis", "probably");
check("video/ogg; codecs=vorbis,theora", "probably");
check("video/ogg; codecs=\"vorbis, theora\"", "probably");
check("video/ogg; codecs=theora", "probably");
resolve();
});
}
// Verify Opus support
var OpusEnabled = undefined;
try {
OpusEnabled = SpecialPowers.getBoolPref("media.opus.enabled");
} catch (ex) {
// SpecialPowers failed, perhaps because Opus isn't compiled in
console.log("media.opus.enabled pref not found; skipping Opus validation");
}
if (OpusEnabled !== undefined) {
SpecialPowers.setBoolPref("media.opus.enabled", true);
check("audio/ogg; codecs=opus", "probably");
SpecialPowers.setBoolPref("media.opus.enabled", false);
check("audio/ogg; codecs=opus", "");
SpecialPowers.setBoolPref("media.opus.enabled", OpusEnabled);
function verify_opus_support() {
return new Promise(function(resolve, reject) {
var OpusEnabled = undefined;
try {
OpusEnabled = SpecialPowers.getBoolPref("media.opus.enabled");
} catch (ex) {
// SpecialPowers failed, perhaps because Opus isn't compiled in
console.log("media.opus.enabled pref not found; skipping Opus validation");
}
if (OpusEnabled != undefined) {
resolve();
} else {
reject();
}
});
}
// Unsupported Ogg codecs
check("video/ogg; codecs=xyz", "");
check("video/ogg; codecs=xyz,vorbis", "");
check("video/ogg; codecs=vorbis,xyz", "");
function opus_enable() {
return new Promise(function(resolve, reject) {
SpecialPowers.pushPrefEnv({"set": [['media.opus.enabled', true]]},
function() {
check("audio/ogg; codecs=opus", "probably");
resolve();
});
});
}
function opus_disable() {
return new Promise(function(resolve, reject) {
SpecialPowers.pushPrefEnv({"set": [['media.opus.enabled', false]]},
function() {
check("audio/ogg; codecs=opus", "");
resolve();
});
});
}
function unspported_ogg() {
// Unsupported Ogg codecs
check("video/ogg; codecs=xyz", "");
check("video/ogg; codecs=xyz,vorbis", "");
check("video/ogg; codecs=vorbis,xyz", "");
finish.call();
}
basic_test()
.then(verify_opus_support)
.then(opus_enable)
.then(opus_disable)
.then(unspported_ogg, unspported_ogg);
}

View File

@ -320,7 +320,6 @@ skip-if = buildapp == 'mulet' || os == 'win' # bug 894922
skip-if = buildapp == 'b2g' # bug 1021675
[test_can_play_type_no_ogg.html]
[test_can_play_type_ogg.html]
skip-if = buildapp == 'b2g' || e10s # b2g(bug 1021675)
[test_chaining.html]
[test_clone_media_element.html]
[test_closing_connections.html]

View File

@ -24,11 +24,15 @@ a Bug 469247</a>
<script>
SimpleTest.waitForExplicitFinish();
function finish() {
mediaTestCleanup();
SimpleTest.finish();
}
SpecialPowers.pushPrefEnv({"set": [["media.ogg.enabled", false]]},
function() {
check_ogg(document.getElementById('v'), false);
mediaTestCleanup();
SimpleTest.finish();
check_ogg(document.getElementById('v'), false, finish);
}
);

View File

@ -21,9 +21,16 @@ a Bug 469247</a>
<pre id="test">
<script src="can_play_type_ogg.js"></script>
<script>
check_ogg(document.getElementById('v'), true);
mediaTestCleanup();
SimpleTest.waitForExplicitFinish();
function finish() {
mediaTestCleanup();
SimpleTest.finish();
}
check_ogg(document.getElementById('v'), true, finish);
</script>
</pre>
</body>