зеркало из https://github.com/mozilla/gecko-dev.git
Tests for bug 478398, as well as for a few others, now that we have a discard timer pref.r=joe
This commit is contained in:
Родитель
716f62fd7c
Коммит
4d8ef3bd3e
|
@ -48,12 +48,15 @@ _TEST_FILES = imgutils.js \
|
|||
test_bug399925.html \
|
||||
bug399925.gif \
|
||||
schrep.png \
|
||||
test_bug435296.html \
|
||||
bug468160.sjs \
|
||||
test_bug468160.html \
|
||||
red.png \
|
||||
test_bug466586.html \
|
||||
big.png \
|
||||
blue.png \
|
||||
test_bug478398.html \
|
||||
bug478398_ONLY.png \
|
||||
test_bug490949.html \
|
||||
bug490949-iframe.html \
|
||||
bug490949.sjs \
|
||||
|
@ -72,7 +75,5 @@ _TEST_FILES = imgutils.js \
|
|||
test_bug553982.html \
|
||||
$(NULL)
|
||||
|
||||
#test_bug435296.html disabled until we re-enable decode-on-draw
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
||||
|
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 14 KiB |
|
@ -67,35 +67,55 @@ function forceDecode(id)
|
|||
}
|
||||
|
||||
|
||||
// Functions to facilitate getting/setting the discard timer pref
|
||||
// Functions to facilitate getting/setting various image-related prefs
|
||||
//
|
||||
// Don't forget to reset the pref to the original value!
|
||||
// If you change a pref in a mochitest, Don't forget to reset it to its
|
||||
// original value!
|
||||
//
|
||||
// Null indicates no pref set
|
||||
|
||||
const DISCARD_BRANCH_NAME = "image.cache.";
|
||||
const DISCARD_PREF_NAME = "discard_timer_ms";
|
||||
const DISCARD_ENABLED_PREF = {name: "discardable", branch: "image.mem.", type: "bool"};
|
||||
const DECODEONDRAW_ENABLED_PREF = {name: "decodeondraw", branch: "image.mem.", type: "bool"};
|
||||
const DISCARD_TIMEOUT_PREF = {name: "min_discard_timeout_ms", branch: "image.mem.", type: "int"};
|
||||
|
||||
function setDiscardTimerPref(timeMS)
|
||||
function setImagePref(pref, val)
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefService);
|
||||
var branch = prefService.getBranch(DISCARD_BRANCH_NAME);
|
||||
if (timeMS != null)
|
||||
branch.setIntPref(DISCARD_PREF_NAME, timeMS);
|
||||
else if (branch.prefHasUserValue(DISCARD_PREF_NAME))
|
||||
branch.clearUserPref(DISCARD_PREF_NAME);
|
||||
var branch = prefService.getBranch(pref.branch);
|
||||
if (val != null) {
|
||||
switch(pref.type) {
|
||||
case "bool":
|
||||
branch.setBoolPref(pref.name, val);
|
||||
break;
|
||||
case "int":
|
||||
branch.setIntPref(pref.name, val);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unknown pref type");
|
||||
}
|
||||
}
|
||||
else if (branch.prefHasUserValue(pref.name))
|
||||
branch.clearUserPref(pref.name);
|
||||
}
|
||||
|
||||
function getDiscardTimerPref()
|
||||
function getImagePref(pref)
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefService);
|
||||
var branch = prefService.getBranch(DISCARD_BRANCH_NAME);
|
||||
if (branch.prefHasUserValue(DISCARD_PREF_NAME))
|
||||
return branch.getIntPref("discard_timeout_ms");
|
||||
var branch = prefService.getBranch(pref.branch);
|
||||
if (branch.prefHasUserValue(pref.name)) {
|
||||
switch (pref.type) {
|
||||
case "bool":
|
||||
return branch.getBoolPref(pref.name);
|
||||
case "int":
|
||||
return branch.getIntPref(pref.name);
|
||||
default:
|
||||
throw new Error("Unknown pref type");
|
||||
}
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=399925
|
|||
<title>Test for Bug 399925</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="imgutils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body onload="drawCanvas(); setTimeout('drawCanvas(); allDone();', 20000)">
|
||||
<body>
|
||||
<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">
|
||||
|
@ -19,10 +20,40 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=399925
|
|||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 399925 **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
/** 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);
|
||||
|
||||
// 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()
|
||||
{
|
||||
|
@ -38,6 +69,8 @@ function drawCanvas()
|
|||
function allDone()
|
||||
{
|
||||
is(pngResults[0], pngResults[1], "got different rendered results");
|
||||
setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref);
|
||||
setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=435296
|
|||
// Boilerplate
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// We want to make sure d-o-d is enabled, since that's what we're testing
|
||||
var oldDODPref = getImagePref(DECODEONDRAW_ENABLED_PREF);
|
||||
setImagePref(DECODEONDRAW_ENABLED_PREF, true);
|
||||
|
||||
// We're relying on very particular behavior for certain images - clear the
|
||||
// image cache.
|
||||
clearImageCache();
|
||||
|
@ -58,6 +62,9 @@ function tryToFinish()
|
|||
// By definition, the image is decoded here. Give ourselves a pat on the back.
|
||||
ok(isFrameDecoded("testimage"), "image should be decoded");
|
||||
|
||||
// Restore the decode-on-draw pref
|
||||
setImagePref(DECODEONDRAW_ENABLED_PREF, oldDODPref);
|
||||
|
||||
// All done
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=478398
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 478398</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="imgutils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478398">Mozilla Bug 478398</a>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 399925. **/
|
||||
var oldTimeoutPref;
|
||||
var oldDiscardPref;
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
window.onload = stage1;
|
||||
var imageFilename = "bug478398_ONLY.png";
|
||||
|
||||
function stage1()
|
||||
{
|
||||
// Get the current pref values
|
||||
oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF);
|
||||
oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF);
|
||||
|
||||
// We're testing discarding here
|
||||
setImagePref(DISCARD_ENABLED_PREF, true);
|
||||
|
||||
// Sets the discard timer to 500 ms (max timeout = 2*500ms = 1s)
|
||||
setImagePref(DISCARD_TIMEOUT_PREF, 500);
|
||||
|
||||
// Create the image _after_ setting the discard timer pref
|
||||
// This image was carefully constructed to make it a "big win" for discarding,
|
||||
// so any reasonable heuristic should still discard it.
|
||||
var image = new Image();
|
||||
image.setAttribute("id", "testimage");
|
||||
image.style.display = "none";
|
||||
image.src = imageFilename;
|
||||
|
||||
// Put the image into the document
|
||||
document.body.appendChild(image);
|
||||
|
||||
// Wait for load, then do stage2
|
||||
image.onload = stage2;
|
||||
}
|
||||
|
||||
function stage2()
|
||||
{
|
||||
// Make sure we're loaded
|
||||
ok(isImageLoaded("testimage"), "image should be loaded");
|
||||
|
||||
// We're loaded - force a synchronous decode
|
||||
forceDecode("testimage");
|
||||
|
||||
// We should be decoded
|
||||
ok(isFrameDecoded("testimage"), "image should be decoded");
|
||||
|
||||
// Wait 1.5 seconds, then finish the test
|
||||
setTimeout("finishTest();", 1500);
|
||||
|
||||
}
|
||||
|
||||
function finishTest()
|
||||
{
|
||||
// The image should be discarded by now
|
||||
ok(!isFrameDecoded("testimage"), "image should have been discarded!");
|
||||
|
||||
// Reset the prefs
|
||||
setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref);
|
||||
setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref);
|
||||
|
||||
// Finish the test
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Загрузка…
Ссылка в новой задаче