|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=841579 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 841579</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=841579">Mozilla Bug 841579</a> |
|
15 <p id="display"></p> |
|
16 <div id="content"> |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script type="application/javascript;version=1.8"> |
|
20 /** Test for Bug 841579**/ |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes) |
|
25 |
|
26 const Cc = Components.classes; |
|
27 const Ci = Components.interfaces; |
|
28 const gContent = document.getElementById("content"); |
|
29 |
|
30 var gImg; |
|
31 var gMyDecoderObserver; |
|
32 var gIsTestFinished = false; |
|
33 var gFiles; |
|
34 var gNotifications = 0; |
|
35 var gLoads = 0; |
|
36 |
|
37 function fileToLoad() { |
|
38 yield "red.png"; |
|
39 yield "invalid.jpg"; |
|
40 yield "lime100x100.svg"; |
|
41 yield "bad.jpg"; |
|
42 yield "rillybad.jpg"; |
|
43 } |
|
44 |
|
45 function onSizeAvailable(aRequest) { |
|
46 ok(true, "AfterLoad.onSizeAvailable called for " + gImg.src); |
|
47 } |
|
48 function onLoadComplete(aRequest) { |
|
49 ok(true, "AfterLoad.onLoadComplete called for " + gImg.src); |
|
50 gLoads++; |
|
51 } |
|
52 function onDecodeComplete(aRequest) { |
|
53 ok(true, "AfterLoad.onDecodeComplete called for " + gImg.src); |
|
54 SimpleTest.executeSoon(function() { |
|
55 try { |
|
56 gContent.removeChild(gImg); |
|
57 } |
|
58 catch (e) {} |
|
59 }); |
|
60 } |
|
61 |
|
62 function failTest() { |
|
63 ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " + |
|
64 "currently displaying " + gImg.src); |
|
65 cleanUpAndFinish(); |
|
66 } |
|
67 |
|
68 function onNotification() |
|
69 { |
|
70 gNotifications++; |
|
71 try { |
|
72 gImg.src = gFiles.next(); |
|
73 gContent.appendChild(gImg); |
|
74 } catch(e) { |
|
75 cleanUpAndFinish(); |
|
76 } |
|
77 } |
|
78 |
|
79 function cleanUpAndFinish() { |
|
80 // On the off chance that failTest and myOnStopFrame are triggered |
|
81 // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish. |
|
82 if (gIsTestFinished) { |
|
83 return; |
|
84 } |
|
85 let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
|
86 imgLoadingContent.removeObserver(gMyDecoderObserver); |
|
87 // TODO - this isn't the case until post-bug 716140's refactorings |
|
88 // ok(gNotifications == gLoads, "Should be notified the same number of times as loads"); |
|
89 SimpleTest.finish(); |
|
90 gIsTestFinished = true; |
|
91 } |
|
92 |
|
93 function main() { |
|
94 gFiles = fileToLoad(); |
|
95 gImg = new Image(); |
|
96 gImg.onload = onNotification; |
|
97 gImg.onerror = onNotification; |
|
98 |
|
99 // Create, customize & attach decoder observer |
|
100 observer = new ImageDecoderObserverStub(); |
|
101 observer.sizeAvailable = onSizeAvailable; |
|
102 observer.loadComplete = onLoadComplete; |
|
103 observer.decodeComplete = onDecodeComplete; |
|
104 gMyDecoderObserver = |
|
105 Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) |
|
106 .createScriptedObserver(observer); |
|
107 let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); |
|
108 imgLoadingContent.addObserver(gMyDecoderObserver); |
|
109 |
|
110 // We want to test the cold loading behavior, so clear cache in case an |
|
111 // earlier test got our image in there already. |
|
112 clearImageCache(); |
|
113 |
|
114 // kick off image-loading! myOnStopFrame handles the rest. |
|
115 gImg.setAttribute("src", gFiles.next()); |
|
116 |
|
117 // In case something goes wrong, fail earlier than mochitest timeout, |
|
118 // and with more information. |
|
119 setTimeout(failTest, FAILURE_TIMEOUT); |
|
120 } |
|
121 |
|
122 window.onload = main; |
|
123 |
|
124 </script> |
|
125 </pre> |
|
126 </body> |
|
127 </html> |