2008-03-29 09:53:25 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=399925
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 399925</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
2010-07-13 21:30:39 +04:00
|
|
|
<script type="text/javascript" src="imgutils.js"></script>
|
2008-03-29 09:53:25 +03:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
2010-07-13 21:30:39 +04:00
|
|
|
<body>
|
2008-03-29 09:53:25 +03:00
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=399925">Mozilla Bug 399925</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
<canvas id="canvas" width="100" height="100"> </canvas>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
2010-07-13 21:30:39 +04:00
|
|
|
/** Test for Bug 399925. **/
|
2014-11-28 06:55:57 +03:00
|
|
|
var triggerDiscardingManually = false;
|
2010-07-13 21:30:39 +04:00
|
|
|
var pngResults = new Array();
|
2008-03-29 09:53:25 +03:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2014-12-11 21:34:40 +03:00
|
|
|
SimpleTest.requestFlakyTimeout("untriaged");
|
2008-03-29 09:53:25 +03:00
|
|
|
|
2014-04-28 11:39:03 +04:00
|
|
|
window.onload = function() {
|
2014-11-28 06:55:57 +03:00
|
|
|
// It'd be nice to reduce the discard timer here, but unfortunately we only
|
|
|
|
// read that pref on startup. We instead manually trigger discarding on
|
|
|
|
// platforms where the discard timer is too long (which we'll somewhat
|
|
|
|
// arbitrarily define as 'longer than 60 seconds').
|
|
|
|
var expirationMs =
|
|
|
|
SpecialPowers.getIntPref('image.mem.surfacecache.min_expiration_ms');
|
|
|
|
if (expirationMs > 60000) {
|
|
|
|
ok(true, 'Triggering discarding manually because SurfaceCache expiration ' +
|
|
|
|
'is ' + expirationMs + ' ms');
|
|
|
|
triggerDiscardingManually = true;
|
|
|
|
} else {
|
|
|
|
ok(true, 'Using normal discarding because SurfaceCache expiration ' +
|
|
|
|
'is ' + expirationMs + ' ms');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable discarding for the test.
|
2014-04-28 11:39:03 +04:00
|
|
|
SpecialPowers.pushPrefEnv({
|
2014-11-28 06:55:57 +03:00
|
|
|
'set':[['image.mem.discardable',true]]
|
2014-04-28 11:39:03 +04:00
|
|
|
}, runTest);
|
|
|
|
}
|
2010-07-13 21:30:39 +04:00
|
|
|
|
2014-04-28 11:39:03 +04:00
|
|
|
function runTest() {
|
2010-07-13 21:30:39 +04:00
|
|
|
var image = new Image();
|
|
|
|
image.setAttribute("id", "gif");
|
|
|
|
|
2014-04-28 11:39:03 +04:00
|
|
|
// 1. Draw the canvas once on loadComplete
|
|
|
|
// 2. Redraw the canvas and compare the results right on discard
|
|
|
|
addCallbacks(image, drawCanvas, function() {
|
|
|
|
drawCanvas();
|
|
|
|
is(pngResults[0], pngResults[1], "got different rendered results");
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
2014-11-28 06:55:57 +03:00
|
|
|
|
|
|
|
image.src = "bug399925.gif";
|
|
|
|
document.getElementById("content").appendChild(image);
|
|
|
|
|
|
|
|
if (triggerDiscardingManually) {
|
|
|
|
var request = SpecialPowers.wrap(image)
|
|
|
|
.QueryInterface(SpecialPowers.Ci.nsIImageLoadingContent)
|
|
|
|
.getRequest(SpecialPowers.Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
|
|
|
setTimeout(() => request.requestDiscard(), 1000);
|
|
|
|
}
|
2010-07-13 21:30:39 +04:00
|
|
|
}
|
2008-03-29 09:53:25 +03:00
|
|
|
|
2014-04-28 11:39:03 +04:00
|
|
|
function addCallbacks(anImage, loadCompleteCallback, discardCallback) {
|
|
|
|
var observer = new ImageDecoderObserverStub();
|
|
|
|
observer.discard = function () {
|
|
|
|
imgLoadingContent.removeObserver(scriptedObserver);
|
|
|
|
discardCallback();
|
|
|
|
}
|
|
|
|
observer.loadComplete = loadCompleteCallback;
|
|
|
|
observer = SpecialPowers.wrapCallbackObject(observer);
|
|
|
|
|
|
|
|
var scriptedObserver = SpecialPowers.Cc["@mozilla.org/image/tools;1"]
|
|
|
|
.getService(SpecialPowers.Ci.imgITools)
|
|
|
|
.createScriptedObserver(observer);
|
2008-03-29 09:53:25 +03:00
|
|
|
|
2014-04-28 11:39:03 +04:00
|
|
|
var imgLoadingContent =
|
|
|
|
SpecialPowers.wrap(anImage)
|
|
|
|
.QueryInterface(SpecialPowers.Ci.nsIImageLoadingContent);
|
|
|
|
imgLoadingContent.addObserver(scriptedObserver);
|
2008-03-29 09:53:25 +03:00
|
|
|
}
|
|
|
|
|
2014-04-28 11:39:03 +04:00
|
|
|
function drawCanvas() {
|
|
|
|
var canvas = document.getElementById('canvas');
|
|
|
|
var context = canvas.getContext('2d');
|
|
|
|
var gif = document.getElementById('gif');
|
|
|
|
|
|
|
|
context.drawImage(gif, 0, 0);
|
|
|
|
ok(true, "we got through the drawImage call without an exception being thrown");
|
|
|
|
pngResults.push(canvas.toDataURL());
|
2008-03-29 09:53:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|