1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/test/mochitest/test_bug478398.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=478398 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 478398</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="imgutils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478398">Mozilla Bug 478398</a> 1.17 +<pre id="test"> 1.18 +<script class="testbody" type="text/javascript"> 1.19 + 1.20 +/** Test for Bug 399925. **/ 1.21 +var oldTimeoutPref; 1.22 +var oldDiscardPref; 1.23 +SimpleTest.waitForExplicitFinish(); 1.24 +window.onload = stage1; 1.25 +var imageFilename = "bug478398_ONLY.png"; 1.26 + 1.27 +function stage1() 1.28 +{ 1.29 + // Get the current pref values 1.30 + oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF); 1.31 + oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF); 1.32 + 1.33 + // We're testing discarding here 1.34 + setImagePref(DISCARD_ENABLED_PREF, true); 1.35 + 1.36 + // Sets the discard timer to 500 ms (max timeout = 2*500ms = 1s) 1.37 + setImagePref(DISCARD_TIMEOUT_PREF, 500); 1.38 + 1.39 + // Create the image _after_ setting the discard timer pref 1.40 + // This image was carefully constructed to make it a "big win" for discarding, 1.41 + // so any reasonable heuristic should still discard it. 1.42 + var image = new Image(); 1.43 + image.setAttribute("id", "testimage"); 1.44 + image.style.display = "none"; 1.45 + image.src = imageFilename; 1.46 + 1.47 + // Put the image into the document 1.48 + document.body.appendChild(image); 1.49 + 1.50 + // Wait for load, then do stage2 1.51 + image.onload = stage2; 1.52 +} 1.53 + 1.54 +function stage2() 1.55 +{ 1.56 + // Make sure we're loaded 1.57 + ok(isImageLoaded("testimage"), "image should be loaded"); 1.58 + 1.59 + // We're loaded - force a synchronous decode 1.60 + forceDecode("testimage"); 1.61 + 1.62 + // We should be decoded 1.63 + ok(isFrameDecoded("testimage"), "image should be decoded"); 1.64 + 1.65 + // Wait 1.5 seconds, then finish the test 1.66 + setTimeout("finishTest();", 1500); 1.67 + 1.68 +} 1.69 + 1.70 +function finishTest() 1.71 +{ 1.72 + // The image should be discarded by now 1.73 + ok(!isFrameDecoded("testimage"), "image should have been discarded!"); 1.74 + 1.75 + // Reset the prefs 1.76 + setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref); 1.77 + setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref); 1.78 + 1.79 + // Finish the test 1.80 + SimpleTest.finish(); 1.81 +} 1.82 + 1.83 + 1.84 +</script> 1.85 +</pre> 1.86 +</body> 1.87 +</html> 1.88 +