|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=907503 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 907503</title> |
|
8 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script> |
|
10 <script type="application/javascript" src="imgutils.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=907503">Mozilla Bug 907503</a> |
|
15 <p id="display"></p> |
|
16 <div id="content"> |
|
17 <div id="referenceDiv" style="height: 100px; width: 100px; |
|
18 display: none; background: lime"></div> |
|
19 <img> |
|
20 </div> |
|
21 <pre id="test"> |
|
22 <script type="application/javascript;version=1.8"> |
|
23 /** Test for Bug 907503**/ |
|
24 |
|
25 SimpleTest.waitForExplicitFinish(); |
|
26 |
|
27 const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes) |
|
28 |
|
29 const Cc = Components.classes; |
|
30 const Ci = Components.interfaces; |
|
31 const gImg = document.getElementsByTagName("img")[0]; |
|
32 |
|
33 var gMyDecoderObserver; // value will be set in main() |
|
34 var gReferenceSnapshot; // value will be set in takeReferenceSnapshot() |
|
35 var gOnStopFrameCounter = 0; |
|
36 var gIsTestFinished = false; |
|
37 var gTimer = null; |
|
38 |
|
39 |
|
40 function takeReferenceSnapshot() { |
|
41 // Take a snapshot of the initial (essentially blank) page |
|
42 let blankSnapshot = snapshotWindow(window, false); |
|
43 |
|
44 // Show reference div, & take a snapshot |
|
45 let referenceDiv = document.getElementById("referenceDiv"); |
|
46 referenceDiv.style.display = "block"; |
|
47 gReferenceSnapshot = snapshotWindow(window, false); |
|
48 ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0], |
|
49 "reference snapshot shouldn't match blank page snapshot"); |
|
50 |
|
51 // Re-hide reference div, and take another snapshot to be sure it's gone |
|
52 referenceDiv.style.display = "none"; |
|
53 let blankSnapshot2 = snapshotWindow(window, false); |
|
54 ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0], |
|
55 "reference div should disappear when it becomes display:none"); |
|
56 } |
|
57 |
|
58 function myOnStopFrame(aRequest) { |
|
59 gOnStopFrameCounter++; |
|
60 ok(true, "myOnStopFrame called"); |
|
61 let currentSnapshot = snapshotWindow(window, false); |
|
62 if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) { |
|
63 // SUCCESS! |
|
64 ok(true, "Animated image looks correct, " + |
|
65 "at call #" + gOnStopFrameCounter + " to onStopFrame"); |
|
66 cleanUpAndFinish(); |
|
67 } |
|
68 if (!gTimer) |
|
69 gTimer = setTimeout(function() { gTimer = null; myOnStopFrame(0, 0); }, 1000); |
|
70 } |
|
71 |
|
72 function failTest() { |
|
73 ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " + |
|
74 "Animated image still doesn't look correct, " + |
|
75 "after call #" + gOnStopFrameCounter + " to onStopFrame"); |
|
76 cleanUpAndFinish(); |
|
77 } |
|
78 |
|
79 function cleanUpAndFinish() { |
|
80 clearTimeout(gTimer); |
|
81 // On the off chance that failTest and myOnStopFrame are triggered |
|
82 // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish. |
|
83 if (gIsTestFinished) { |
|
84 return; |
|
85 } |
|
86 let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
|
87 imgLoadingContent.removeObserver(gMyDecoderObserver); |
|
88 SimpleTest.finish(); |
|
89 gIsTestFinished = true; |
|
90 } |
|
91 |
|
92 function main() { |
|
93 takeReferenceSnapshot(); |
|
94 |
|
95 // Create, customize & attach decoder observer |
|
96 observer = new ImageDecoderObserverStub(); |
|
97 observer.frameComplete = myOnStopFrame; |
|
98 gMyDecoderObserver = |
|
99 Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) |
|
100 .createScriptedObserver(observer); |
|
101 let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
|
102 imgLoadingContent.addObserver(gMyDecoderObserver); |
|
103 |
|
104 // We want to test the cold loading behavior, so clear cache in case an |
|
105 // earlier test got our image in there already. |
|
106 clearImageCache(); |
|
107 |
|
108 // kick off image-loading! myOnStopFrame handles the rest. |
|
109 gImg.setAttribute("src", "lime-anim-100x100-2.svg"); |
|
110 |
|
111 // In case something goes wrong, fail earlier than mochitest timeout, |
|
112 // and with more information. |
|
113 setTimeout(failTest, FAILURE_TIMEOUT); |
|
114 } |
|
115 |
|
116 window.onload = main; |
|
117 |
|
118 </script> |
|
119 </pre> |
|
120 </body> |
|
121 </html> |