// Because there is no event telling us when an animated image finishes
// animating, tests for the operators used by animated GIFs and PNGs
// require that we poll until we get the correct result. A fixed timeout
// can easily result in intermittent failures on tests running in VMs.
// (Note that we do _not_ poll the reference, so it must not be animated.)
var gTests = [
// IMPORTANT NOTE: For these tests, the test and reference are not
// snapshotted in the same way. The REFERENCE (second file) is
// assumed to be complete when loaded, but we poll the TEST
// (first file) until the test passes.
// Tests of the allowed disposal operators for GIF, APNG and WebP: keep, clear,
// and restore previous. "== green-background.html?clear.gif green.png", "== green-background.html?clear.png green.png", "== green-background.html?clear.webp green.png", "== green-background.html?clear.avif green.png", "== keep.gif green.png", "== keep.png green.png", "== keep.webp green.png", "== restore-previous.gif green.png", "== restore-previous.png green.png",
// Tests of the blending/compositing operators that only APNG supports. "== over.png grey.png", "!= source.png grey.png", "== bug900200.png bug900200-ref.png", "== bug1319025.png bug1319025-ref.png",
// Test of subframe updates. "== clear2.gif clear2-results.gif", "== clear2.webp clear2-results.gif",
];
// Maintain a reference count of how many things we're waiting for until
// we can say the tests are done. var gDelayCount = 0;
function AddFinishDependency()
{ ++gDelayCount; }
function RemoveFinishDependency()
{ if (--gDelayCount == 0) SimpleTest.finish(); }
// We record the maximum number of times we had to look at a test before
// it switched to the passing state (though we assume it's 10 to start
// rather than 0 so that we have a reasonable default). Then we make a
// test "time out" if it takes more than gTimeoutFactor times that
// amount of time. This allows us to report a test failure rather than
// making a test failure just show up as a timeout. var gMaxPassingTries = 10; var gTimeoutFactor = 10;
function takeSnapshot(iframe_element)
{
return snapshotWindow(iframe_element.contentWindow, false);
}
function passes(op, shot1, shot2)
{ var values = compareSnapshots(shot1, shot2, op == "==");
return values[0];
}
function startTest(i)
{ var testLine = gTests[i]; var splitData = testLine.split(" "); var testData =
{ op: splitData[0], test: splitData[1], reference: splitData[2] }; var tries = 0;
// Maintain state specific to this test in the closure exposed to all
// the functions nested inside this one.
function startIframe(url)
{ var element = document.createElement("iframe");
element.addEventListener("load", handleLoad);
// Smaller than normal reftests, but enough for these.
element.setAttribute("style", "width: 100px; height: 100px");
element.setAttribute("frameborder", "0");
element.setAttribute("scrolling", "no");
element.src = url;
document.body.appendChild(element);
function handleLoad()
{ iframe.loaded = true;
if (iframe == reference) {
reference.snapshot = takeSnapshot(element);
} var other = (iframe == test) ? reference : test;
if (other.loaded) {
setTimeout(checkTest, 100);
}
}
function checkTest()
{ var test_snapshot = takeSnapshot(test.element);
if (passes(testData.op, test_snapshot, reference.snapshot)) {
if (tries > gMaxPassingTries) {
gMaxPassingTries = tries;
}
report(true);
} else {
++tries;
if (tries > gMaxPassingTries * gTimeoutFactor) {
info("Giving up after " + tries + " tries, " + "maxp=" + gMaxPassingTries + "fact=" + gTimeoutFactor);
report(false);
} else {
// The animation might not have finished. Try again in 100ms.
setTimeout(checkTest, 100);
}
}
}
function report(result)
{
ok(result, "(" + i + ") " +
testData.op + " " + testData.test + " " + testData.reference);
RemoveFinishDependency();
} variframe = { element, loaded: false };
return iframe;
}
AddFinishDependency(); var test = startIframe(testData.test); var reference = startIframe(testData.reference);
}
function runTests()
{
// Run the tests.
for (var i = 0; i < gTests.length; ++i) {
startTest(i);
}
}
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.