Bug 1089484 - Have test_reset_src.html test more files to increase test coverage. r=kinetik

This commit is contained in:
JW Wang 2014-10-27 23:34:00 +01:00
Родитель b3d39c0867
Коммит 6eda0adeeb
2 изменённых файлов: 39 добавлений и 26 удалений

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

@ -124,7 +124,7 @@ var gPlayTests = [
// With first frame a "duplicate" (empty) frame.
{ name:"bug500311.ogv", type:"video/ogg", duration:1.96 },
// Small audio file
{ name:"small-shot.ogg", type:"video/ogg", duration:0.276 },
{ name:"small-shot.ogg", type:"audio/ogg", duration:0.276 },
// More audio in file than video.
{ name:"short-video.ogv", type:"video/ogg", duration:1.081 },
// First Theora data packet is zero bytes.
@ -679,13 +679,17 @@ function checkMetadata(msg, e, test) {
// Returns the first test from candidates array which we can play with the
// installed video backends.
function getPlayableVideo(candidates) {
var v = document.createElement("video");
var resources = candidates.filter(function(x){return /^video/.test(x.type) && v.canPlayType(x.type);});
var resources = getPlayableVideos(candidates);
if (resources.length > 0)
return resources[0];
return null;
}
function getPlayableVideos(candidates) {
var v = document.createElement("video");
return candidates.filter(function(x){return /^video/.test(x.type) && v.canPlayType(x.type);});
}
function getPlayableAudio(candidates) {
var v = document.createElement("audio");
var resources = candidates.filter(function(x){return /^audio/.test(x.type) && v.canPlayType(x.type);});

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

@ -14,27 +14,33 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=804875
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=804875">Mozilla Bug 804875</a>
<video style="border: 4px solid red" controls></video>
<canvas></canvas>
<pre id="test">
<script class="testbody" type="text/javascript">
var manager = new MediaTestManager;
function finish(v) {
removeNodeAndSource(v);
manager.finished(v.token);
}
function onLoadedMetadata_Audio(e) {
var t = e.target;
is(t.videoHeight, 0, "videoHeight should be zero when there is no video.");
is(t.videoWidth, 0, "videoWidth should be zero when there is no video.");
is(t.mozPaintedFrames, 0, "mozPaintedFrames should be zero when there is no video.");
is(t.mozFrameDelay, 0, "mozFrameDelay should be zero when there is no video.");
is(t.videoHeight, 0, t.name + ": videoHeight should be zero when there is no video.");
is(t.videoWidth, 0, t.name + ": videoWidth should be zero when there is no video.");
is(t.mozPaintedFrames, 0, t.name + ": mozPaintedFrames should be zero when there is no video.");
is(t.mozFrameDelay, 0, t.name + ": mozFrameDelay should be zero when there is no video.");
var c = document.getElementsByTagName("canvas")[0].getContext("2d");
try {
c.drawImage(t, 0, 0, t.videoHeight, t.videoWidth);
} catch (e) {
ok(true, "Trying to draw to a canvas should throw, since we don't have a frame anymore");
SimpleTest.finish();
ok(true, t.name + ": Trying to draw to a canvas should throw, since we don't have a frame anymore");
finish(t);
return;
}
ok(false, "We should not succeed to draw a video frame on the canvas.");
ok(false, t.name + ": We should not succeed to draw a video frame on the canvas.");
}
function onTimeUpdate_Video(e) {
@ -43,17 +49,17 @@ function onTimeUpdate_Video(e) {
return;
}
t.removeEventListener("timeupdate", onTimeUpdate_Video);
ok(t.mozPaintedFrames > 0, "mozPaintedFrames should be positive, is " + t.mozPaintedFrames + ".");
ok(t.mozFrameDelay >= 0, "mozFrameDelay should be positive or zero, is " + t.mozFrameDelay + ".");
ok(t.mozPaintedFrames > 0, t.name + ": mozPaintedFrames should be positive, is " + t.mozPaintedFrames + ".");
ok(t.mozFrameDelay >= 0, t.name + ": mozFrameDelay should be positive or zero, is " + t.mozFrameDelay + ".");
if (v._firstTime) {
if (t._firstTime) {
t.src = t.src;
v._firstTime = false;
t._firstTime = false;
} else {
var source = getPlayableAudio(gPlayTests);
if (!source) {
todo("No audio file available.")
SimpleTest.finish();
finish(t);
} else {
t.removeEventListener("loadedmetadata", onLoadedMetadata_Video);
t.addEventListener("loadedmetadata", onLoadedMetadata_Audio);
@ -64,22 +70,25 @@ function onTimeUpdate_Video(e) {
function onLoadedMetadata_Video(e) {
var t = e.target;
ok(t.videoHeight != 0, "We should have a videoHeight.");
ok(t.videoWidth != 0, "We should have a videoWidth.");
isnot(t.videoHeight, 0, t.name + ": We should have a videoHeight.");
isnot(t.videoWidth, 0, t.name + ": We should have a videoWidth.");
t.addEventListener("timeupdate", onTimeUpdate_Video);
t.play();
}
var v = document.getElementsByTagName("video")[0];
v._firstTime = true;
var source = getPlayableVideo(gPlayTests);
if (!source) {
todo("No video file available.");
} else {
function startTest(test, token) {
var v = document.createElement('video');
document.body.appendChild(v);
v.preload = "metadata";
v._firstTime = true;
v.addEventListener("loadedmetadata", onLoadedMetadata_Video);
v.src = source.name;
SimpleTest.waitForExplicitFinish();
v.src = test.name;
v.token = token;
v.name = test.name;
manager.started(token);
}
manager.runTests(getPlayableVideos(gSmallTests.concat(gSeekTests)), startTest);
</script>
</pre>
</body>