Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=435296
5 -->
6 <head>
7 <title>Test for Bug 435296</title>
8 <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <script type="application/javascript" src="imgutils.js"></script>
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
12 </head>
13 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=435296">Mozilla Bug 435296</a>
15 <img id="testimage" style="display: none;">
16 <pre id="test">
17 <script type="application/javascript">
19 // Boilerplate
20 SimpleTest.waitForExplicitFinish();
22 // Assert that discarding isn't enabled, which might make this test go orange.
23 ok(!getImagePref(DISCARD_ENABLED_PREF), "discarding should NOT be enabled here");
25 // We want to make sure d-o-d is enabled, since that's what we're testing
26 var oldDODPref = getImagePref(DECODEONDRAW_ENABLED_PREF);
27 setImagePref(DECODEONDRAW_ENABLED_PREF, true);
29 // We're relying on very particular behavior for certain images - clear the
30 // image cache.
31 clearImageCache();
33 // In order to work around the effects introduced in bug 512435, we only load
34 // the image after window onload fires
35 function windowLoadHandler()
36 {
37 // Set the source and an onload handler
38 var image = document.getElementById("testimage");
39 image.src = "schrep.png";
40 image.onload = imageLoadHandler;
41 }
43 function imageLoadHandler()
44 {
45 // The image is hidden, so it should not be decoded
46 ok(!isFrameDecoded("testimage"), "image should not be decoded");
48 // Make the image visible
49 var image = document.getElementById("testimage");
50 image.style.display = "inline";
52 // Wait for the image to decode
53 setTimeout("tryToFinish();", 500);
54 }
56 function tryToFinish()
57 {
58 // If it hasn't happened yet, wait longer. If it never happens, this test
59 // will timeout after 300 seconds...
60 if (!isFrameDecoded("testimage")) {
61 setTimeout("tryToFinish();", 500);
62 return;
63 }
65 // By definition, the image is decoded here. Give ourselves a pat on the back.
66 ok(isFrameDecoded("testimage"), "image should be decoded");
68 // Restore the decode-on-draw pref
69 setImagePref(DECODEONDRAW_ENABLED_PREF, oldDODPref);
71 // All done
72 SimpleTest.finish();
73 }
75 // Set our onload handler, making sure we have focus
76 window.onload = SimpleTest.waitForFocus(windowLoadHandler);
78 </script>
79 </pre>
80 </body>
81 </html>