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=478398 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 478398</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="imgutils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478398">Mozilla Bug 478398</a> |
michael@0 | 14 | <pre id="test"> |
michael@0 | 15 | <script class="testbody" type="text/javascript"> |
michael@0 | 16 | |
michael@0 | 17 | /** Test for Bug 399925. **/ |
michael@0 | 18 | var oldTimeoutPref; |
michael@0 | 19 | var oldDiscardPref; |
michael@0 | 20 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 21 | window.onload = stage1; |
michael@0 | 22 | var imageFilename = "bug478398_ONLY.png"; |
michael@0 | 23 | |
michael@0 | 24 | function stage1() |
michael@0 | 25 | { |
michael@0 | 26 | // Get the current pref values |
michael@0 | 27 | oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF); |
michael@0 | 28 | oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF); |
michael@0 | 29 | |
michael@0 | 30 | // We're testing discarding here |
michael@0 | 31 | setImagePref(DISCARD_ENABLED_PREF, true); |
michael@0 | 32 | |
michael@0 | 33 | // Sets the discard timer to 500 ms (max timeout = 2*500ms = 1s) |
michael@0 | 34 | setImagePref(DISCARD_TIMEOUT_PREF, 500); |
michael@0 | 35 | |
michael@0 | 36 | // Create the image _after_ setting the discard timer pref |
michael@0 | 37 | // This image was carefully constructed to make it a "big win" for discarding, |
michael@0 | 38 | // so any reasonable heuristic should still discard it. |
michael@0 | 39 | var image = new Image(); |
michael@0 | 40 | image.setAttribute("id", "testimage"); |
michael@0 | 41 | image.style.display = "none"; |
michael@0 | 42 | image.src = imageFilename; |
michael@0 | 43 | |
michael@0 | 44 | // Put the image into the document |
michael@0 | 45 | document.body.appendChild(image); |
michael@0 | 46 | |
michael@0 | 47 | // Wait for load, then do stage2 |
michael@0 | 48 | image.onload = stage2; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function stage2() |
michael@0 | 52 | { |
michael@0 | 53 | // Make sure we're loaded |
michael@0 | 54 | ok(isImageLoaded("testimage"), "image should be loaded"); |
michael@0 | 55 | |
michael@0 | 56 | // We're loaded - force a synchronous decode |
michael@0 | 57 | forceDecode("testimage"); |
michael@0 | 58 | |
michael@0 | 59 | // We should be decoded |
michael@0 | 60 | ok(isFrameDecoded("testimage"), "image should be decoded"); |
michael@0 | 61 | |
michael@0 | 62 | // Wait 1.5 seconds, then finish the test |
michael@0 | 63 | setTimeout("finishTest();", 1500); |
michael@0 | 64 | |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function finishTest() |
michael@0 | 68 | { |
michael@0 | 69 | // The image should be discarded by now |
michael@0 | 70 | ok(!isFrameDecoded("testimage"), "image should have been discarded!"); |
michael@0 | 71 | |
michael@0 | 72 | // Reset the prefs |
michael@0 | 73 | setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref); |
michael@0 | 74 | setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref); |
michael@0 | 75 | |
michael@0 | 76 | // Finish the test |
michael@0 | 77 | SimpleTest.finish(); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | </script> |
michael@0 | 82 | </pre> |
michael@0 | 83 | </body> |
michael@0 | 84 | </html> |
michael@0 | 85 |