const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
const gContent = document.getElementById("content");
var gCanvas; var gCanvasCtx; var gImg; var gMyDecoderObserver; var gIsTestFinished = false; var gFiles; var gCurrentFileIsTransparent = false; var gHasTransparencyWasCalled = false;
function* testFiles() {
// [A, B] where 'A' is the image and 'B' is whether it's transparent.
// PNGs and GIFs may be transparent or not.
yield ["red.png", false];
yield ["transparent.png", true];
yield ["animated-gif-finalframe.gif", false];
yield ["transparent.gif", true];
// GIFs with padding on the first frame are always transparent.
yield ["first-frame-padding.gif", true];
// JPEGs are never transparent.
yield ["damon.jpg", false];
// Most BMPs are not transparent. (The TestMetadata GTest, which will
// eventually replace this test totally, has coverage for the kinds that can be
// transparent.)
yield ["opaque.bmp", false];
// ICO files which contain BMPs have an additional type of transparency - the
// AND mask - that warrants separate testing. (Although, after bug 1201796,
// all ICOs are considered transparent.)
yield ["ico-bmp-opaque.ico", true];
yield ["ico-bmp-transparent.ico", true];
// SVGs are always transparent.
yield ["lime100x100.svg", true];
}
function loadNext() { var currentFile = "";
gHasTransparencyWasCalled = false;
let {done, value} = gFiles.next();
if (done) {
// We ran out of test files.
cleanUpAndFinish();
return;
}
[currentFile, gCurrentFileIsTransparent] = value;
gImg.setAttribute("src", currentFile);
}
function onHasTransparency() {
gHasTransparencyWasCalled = true;
}
function onDecodeComplete() {
if (!gCurrentFileIsTransparent) {
ok(!gHasTransparencyWasCalled, "onHasTransparency was not called for non-transparent file " + gImg.src);
} else {
ok(gHasTransparencyWasCalled, "onHasTransparency was called for transparent file " + gImg.src);
}
loadNext();
}
function onError() {
if (gIsTestFinished) {
return;
}
ok(false, "Should successfully load " + gImg.src);
loadNext();
}
function onLoad() {
if (gIsTestFinished) {
return;
}
ok(true, "Should successfully load " + gImg.src);
// Force decoding of the image.
SimpleTest.executeSoon(function() {
gCanvasCtx.drawImage(gImg, 0, 0);
});
}
function failTest() {
ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " + "currently displaying " + gImg.src);
cleanUpAndFinish();
}
function cleanUpAndFinish() {
if (gIsTestFinished) {
return;
}
gIsTestFinished = true;
let imgLoadingContent = SpecialPowers.wrap(gImg);
imgLoadingContent.removeObserver(gMyDecoderObserver);
SimpleTest.finish();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.