Bug 969779 - Use SpecialPowers to enable preference setting in oop. r=seth

1. Use |SpecialPowers.pushPrefEnv| to enable preference setting in oop.
2. Set the time of redrawing to be the time right after the image is discarded.
3. Modify the assertion to make the comparison non-trivial.
4. Remove <img>.
5. Move drawCanvas() on the image loadComplete.
This commit is contained in:
Junior Hsu 2014-04-28 15:39:03 +08:00
Родитель 5ba363afb4
Коммит 4d640b2d3b
2 изменённых файлов: 44 добавлений и 41 удалений

Просмотреть файл

@ -59,7 +59,6 @@ support-files =
[test_ImageContentLoaded.html]
[test_bug399925.html]
skip-if = e10s || buildapp == 'b2g' #Bug 969779 - should set preference via SpecialPowers.pushPrefEnv()
# [test_bug435296.html]
# disabled - See bug 578591
[test_bug466586.html]

Просмотреть файл

@ -13,7 +13,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=399925
<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">
<img src="bug399925.gif" id="gif" />
<canvas id="canvas" width="100" height="100"> </canvas>
</div>
<pre id="test">
@ -21,56 +20,61 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=399925
/** Test for Bug 399925. **/
var pngResults = new Array();
var oldTimeoutPref;
var oldDiscardPref;
SimpleTest.waitForExplicitFinish();
window.onload = runTest;
function runTest()
{
// Get the old discard timeout
oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF);
// We're testing discarding here, so we should make sure it's flipped on
oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF);
// Enable Discarding
setImagePref(DISCARD_ENABLED_PREF, true);
// Sets the discard timer to 500ms so we don't have to wait so long. The
// actual time is nondeterministic, but is bounded by 2 * timer = 1 second.
setImagePref(DISCARD_TIMEOUT_PREF, 1000);
window.onload = function() {
// 1. Enable Discarding
// 2. Sets the discard timer to 500ms so we don't have to wait so long. The
// actual time is nondeterministic, but is bounded by 2 * timer = 1 second.
SpecialPowers.pushPrefEnv({
'set':[['image.mem.discardable',true],
['image.mem.min_discard_timeout_ms',1000]]
}, runTest);
}
function runTest() {
// Create the image _after_ setting the discard timer pref
var image = new Image();
image.setAttribute("id", "gif");
image.src = "bug399925.gif";
document.getElementById("content").appendChild(image);
// draw the canvas once
drawCanvas();
// Set the timeout to draw it after discard
setTimeout('drawCanvas(); allDone();', 3000);
}
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);
}
function allDone()
{
// 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");
setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref);
setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref);
SimpleTest.finish();
});
}
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);
var imgLoadingContent =
SpecialPowers.wrap(anImage)
.QueryInterface(SpecialPowers.Ci.nsIImageLoadingContent);
imgLoadingContent.addObserver(scriptedObserver);
}
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());
}
</script>