1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/test/mochitest/test_animation_operators.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,157 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=936720 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 936720</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936720">Mozilla Bug 936720</a> 1.17 +<pre id="test"> 1.18 +<script type="application/javascript"> 1.19 + 1.20 +/** Test for Bug 936720 **/ 1.21 + 1.22 +// Because there is no event telling us when an animated image finishes 1.23 +// animating, tests for the operators used by animated GIFs and PNGs 1.24 +// require that we poll until we get the correct result. A fixed timeout 1.25 +// can easily result in intermittent failures on tests running in VMs. 1.26 + 1.27 +// (Note that we do _not_ poll the reference, so it must not be animated.) 1.28 + 1.29 +var gTests = [ 1.30 + // IMPORTANT NOTE: For these tests, the test and reference are not 1.31 + // snapshotted in the same way. The REFERENCE (second file) is 1.32 + // assumed to be complete when loaded, but we poll the TEST 1.33 + // (first file) until the test passes. 1.34 + 1.35 + // Tests of the allowed disposal operators for both GIF and APNG: keep, clear, 1.36 + // and restore previous. 1.37 + "== green-background.html?clear.gif green.png", 1.38 + "== green-background.html?clear.png green.png", 1.39 + "== keep.gif green.png", 1.40 + "== keep.png green.png", 1.41 + "== restore-previous.gif green.png", 1.42 + "== restore-previous.png green.png", 1.43 + 1.44 + // Tests of the blending/compositing operators that only APNG supports. 1.45 + "== over.png grey.png", 1.46 + "!= source.png grey.png", 1.47 + "== bug900200.png bug900200-ref.png", 1.48 + 1.49 + // Test of subframe updates. 1.50 + "== clear2.gif clear2-results.gif", 1.51 +]; 1.52 + 1.53 +// Maintain a reference count of how many things we're waiting for until 1.54 +// we can say the tests are done. 1.55 +var gDelayCount = 0; 1.56 +function AddFinishDependency() 1.57 + { ++gDelayCount; } 1.58 +function RemoveFinishDependency() 1.59 + { if (--gDelayCount == 0) SimpleTest.finish(); } 1.60 + 1.61 +// We record the maximum number of times we had to look at a test before 1.62 +// it switched to the passing state (though we assume it's 10 to start 1.63 +// rather than 0 so that we have a reasonable default). Then we make a 1.64 +// test "time out" if it takes more than gTimeoutFactor times that 1.65 +// amount of time. This allows us to report a test failure rather than 1.66 +// making a test failure just show up as a timeout. 1.67 +var gMaxPassingTries = 10; 1.68 +var gTimeoutFactor = 10; 1.69 + 1.70 +function takeSnapshot(iframe_element) 1.71 +{ 1.72 + return snapshotWindow(iframe_element.contentWindow, false); 1.73 +} 1.74 + 1.75 +function passes(op, shot1, shot2) 1.76 +{ 1.77 + var [correct, s1, s2] = compareSnapshots(shot1, shot2, op == "=="); 1.78 + return correct; 1.79 +} 1.80 + 1.81 +function startTest(i) 1.82 +{ 1.83 + var testLine = gTests[i]; 1.84 + var splitData = testLine.split(" "); 1.85 + var testData = 1.86 + { op: splitData[0], test: splitData[1], reference: splitData[2] }; 1.87 + var tries = 0; 1.88 + 1.89 + // Maintain state specific to this test in the closure exposed to all 1.90 + // the functions nested inside this one. 1.91 + 1.92 + function startIframe(url) 1.93 + { 1.94 + var element = document.createElement("iframe"); 1.95 + element.addEventListener("load", handleLoad, false); 1.96 + // Smaller than normal reftests, but enough for these. 1.97 + element.setAttribute("style", "width: 100px; height: 100px"); 1.98 + element.setAttribute("frameborder", "0"); 1.99 + element.setAttribute("scrolling", "no"); 1.100 + element.src = url; 1.101 + document.body.appendChild(element); 1.102 + function handleLoad(event) 1.103 + { 1.104 + iframe.loaded = true; 1.105 + if (iframe == reference) { 1.106 + reference.snapshot = takeSnapshot(element); 1.107 + } 1.108 + var other = (iframe == test) ? reference : test; 1.109 + if (other.loaded) { 1.110 + setTimeout(checkTest, 100); 1.111 + } 1.112 + } 1.113 + function checkTest() 1.114 + { 1.115 + var test_snapshot = takeSnapshot(test.element); 1.116 + if (passes(testData.op, test_snapshot, reference.snapshot)) { 1.117 + if (tries > gMaxPassingTries) { 1.118 + gMaxPassingTries = tries; 1.119 + } 1.120 + report(true); 1.121 + } else { 1.122 + ++tries; 1.123 + if (tries > gMaxPassingTries * gTimeoutFactor) { 1.124 + info("Giving up after " + tries + " tries, " + 1.125 + "maxp=" + gMaxPassingTries + 1.126 + "fact=" + gTimeoutFactor); 1.127 + report(false); 1.128 + } else { 1.129 + // The animation might not have finished. Try again in 100ms. 1.130 + setTimeout(checkTest, 100); 1.131 + } 1.132 + } 1.133 + } 1.134 + function report(result) 1.135 + { 1.136 + ok(result, "(" + i + ") " + 1.137 + testData.op + " " + testData.test + " " + testData.reference); 1.138 + RemoveFinishDependency(); 1.139 + } 1.140 + var iframe = { element: element, loaded: false }; 1.141 + 1.142 + return iframe; 1.143 + } 1.144 + 1.145 + AddFinishDependency(); 1.146 + var test = startIframe(testData.test); 1.147 + var reference = startIframe(testData.reference); 1.148 +} 1.149 + 1.150 +SimpleTest.waitForExplicitFinish(); 1.151 + 1.152 +// Run the tests. 1.153 +for (var i = 0; i < gTests.length; ++i) { 1.154 + startTest(i); 1.155 +} 1.156 + 1.157 +</script> 1.158 +</pre> 1.159 +</body> 1.160 +</html>