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