Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=936720 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 936720</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936720">Mozilla Bug 936720</a> |
michael@0 | 14 | <pre id="test"> |
michael@0 | 15 | <script type="application/javascript"> |
michael@0 | 16 | |
michael@0 | 17 | /** Test for Bug 936720 **/ |
michael@0 | 18 | |
michael@0 | 19 | // Because there is no event telling us when an animated image finishes |
michael@0 | 20 | // animating, tests for the operators used by animated GIFs and PNGs |
michael@0 | 21 | // require that we poll until we get the correct result. A fixed timeout |
michael@0 | 22 | // can easily result in intermittent failures on tests running in VMs. |
michael@0 | 23 | |
michael@0 | 24 | // (Note that we do _not_ poll the reference, so it must not be animated.) |
michael@0 | 25 | |
michael@0 | 26 | var gTests = [ |
michael@0 | 27 | // IMPORTANT NOTE: For these tests, the test and reference are not |
michael@0 | 28 | // snapshotted in the same way. The REFERENCE (second file) is |
michael@0 | 29 | // assumed to be complete when loaded, but we poll the TEST |
michael@0 | 30 | // (first file) until the test passes. |
michael@0 | 31 | |
michael@0 | 32 | // Tests of the allowed disposal operators for both GIF and APNG: keep, clear, |
michael@0 | 33 | // and restore previous. |
michael@0 | 34 | "== green-background.html?clear.gif green.png", |
michael@0 | 35 | "== green-background.html?clear.png green.png", |
michael@0 | 36 | "== keep.gif green.png", |
michael@0 | 37 | "== keep.png green.png", |
michael@0 | 38 | "== restore-previous.gif green.png", |
michael@0 | 39 | "== restore-previous.png green.png", |
michael@0 | 40 | |
michael@0 | 41 | // Tests of the blending/compositing operators that only APNG supports. |
michael@0 | 42 | "== over.png grey.png", |
michael@0 | 43 | "!= source.png grey.png", |
michael@0 | 44 | "== bug900200.png bug900200-ref.png", |
michael@0 | 45 | |
michael@0 | 46 | // Test of subframe updates. |
michael@0 | 47 | "== clear2.gif clear2-results.gif", |
michael@0 | 48 | ]; |
michael@0 | 49 | |
michael@0 | 50 | // Maintain a reference count of how many things we're waiting for until |
michael@0 | 51 | // we can say the tests are done. |
michael@0 | 52 | var gDelayCount = 0; |
michael@0 | 53 | function AddFinishDependency() |
michael@0 | 54 | { ++gDelayCount; } |
michael@0 | 55 | function RemoveFinishDependency() |
michael@0 | 56 | { if (--gDelayCount == 0) SimpleTest.finish(); } |
michael@0 | 57 | |
michael@0 | 58 | // We record the maximum number of times we had to look at a test before |
michael@0 | 59 | // it switched to the passing state (though we assume it's 10 to start |
michael@0 | 60 | // rather than 0 so that we have a reasonable default). Then we make a |
michael@0 | 61 | // test "time out" if it takes more than gTimeoutFactor times that |
michael@0 | 62 | // amount of time. This allows us to report a test failure rather than |
michael@0 | 63 | // making a test failure just show up as a timeout. |
michael@0 | 64 | var gMaxPassingTries = 10; |
michael@0 | 65 | var gTimeoutFactor = 10; |
michael@0 | 66 | |
michael@0 | 67 | function takeSnapshot(iframe_element) |
michael@0 | 68 | { |
michael@0 | 69 | return snapshotWindow(iframe_element.contentWindow, false); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function passes(op, shot1, shot2) |
michael@0 | 73 | { |
michael@0 | 74 | var [correct, s1, s2] = compareSnapshots(shot1, shot2, op == "=="); |
michael@0 | 75 | return correct; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function startTest(i) |
michael@0 | 79 | { |
michael@0 | 80 | var testLine = gTests[i]; |
michael@0 | 81 | var splitData = testLine.split(" "); |
michael@0 | 82 | var testData = |
michael@0 | 83 | { op: splitData[0], test: splitData[1], reference: splitData[2] }; |
michael@0 | 84 | var tries = 0; |
michael@0 | 85 | |
michael@0 | 86 | // Maintain state specific to this test in the closure exposed to all |
michael@0 | 87 | // the functions nested inside this one. |
michael@0 | 88 | |
michael@0 | 89 | function startIframe(url) |
michael@0 | 90 | { |
michael@0 | 91 | var element = document.createElement("iframe"); |
michael@0 | 92 | element.addEventListener("load", handleLoad, false); |
michael@0 | 93 | // Smaller than normal reftests, but enough for these. |
michael@0 | 94 | element.setAttribute("style", "width: 100px; height: 100px"); |
michael@0 | 95 | element.setAttribute("frameborder", "0"); |
michael@0 | 96 | element.setAttribute("scrolling", "no"); |
michael@0 | 97 | element.src = url; |
michael@0 | 98 | document.body.appendChild(element); |
michael@0 | 99 | function handleLoad(event) |
michael@0 | 100 | { |
michael@0 | 101 | iframe.loaded = true; |
michael@0 | 102 | if (iframe == reference) { |
michael@0 | 103 | reference.snapshot = takeSnapshot(element); |
michael@0 | 104 | } |
michael@0 | 105 | var other = (iframe == test) ? reference : test; |
michael@0 | 106 | if (other.loaded) { |
michael@0 | 107 | setTimeout(checkTest, 100); |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | function checkTest() |
michael@0 | 111 | { |
michael@0 | 112 | var test_snapshot = takeSnapshot(test.element); |
michael@0 | 113 | if (passes(testData.op, test_snapshot, reference.snapshot)) { |
michael@0 | 114 | if (tries > gMaxPassingTries) { |
michael@0 | 115 | gMaxPassingTries = tries; |
michael@0 | 116 | } |
michael@0 | 117 | report(true); |
michael@0 | 118 | } else { |
michael@0 | 119 | ++tries; |
michael@0 | 120 | if (tries > gMaxPassingTries * gTimeoutFactor) { |
michael@0 | 121 | info("Giving up after " + tries + " tries, " + |
michael@0 | 122 | "maxp=" + gMaxPassingTries + |
michael@0 | 123 | "fact=" + gTimeoutFactor); |
michael@0 | 124 | report(false); |
michael@0 | 125 | } else { |
michael@0 | 126 | // The animation might not have finished. Try again in 100ms. |
michael@0 | 127 | setTimeout(checkTest, 100); |
michael@0 | 128 | } |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | function report(result) |
michael@0 | 132 | { |
michael@0 | 133 | ok(result, "(" + i + ") " + |
michael@0 | 134 | testData.op + " " + testData.test + " " + testData.reference); |
michael@0 | 135 | RemoveFinishDependency(); |
michael@0 | 136 | } |
michael@0 | 137 | var iframe = { element: element, loaded: false }; |
michael@0 | 138 | |
michael@0 | 139 | return iframe; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | AddFinishDependency(); |
michael@0 | 143 | var test = startIframe(testData.test); |
michael@0 | 144 | var reference = startIframe(testData.reference); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 148 | |
michael@0 | 149 | // Run the tests. |
michael@0 | 150 | for (var i = 0; i < gTests.length; ++i) { |
michael@0 | 151 | startTest(i); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | </script> |
michael@0 | 155 | </pre> |
michael@0 | 156 | </body> |
michael@0 | 157 | </html> |