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