Bug 878577 - Part 2, test case for the hard limit of image buffer size. r=seth.

This commit is contained in:
Shih-Chiang Chien 2014-01-20 16:53:42 +08:00
parent 61cb3c939f
commit 90a908ec6e
5 changed files with 100 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

@ -1,5 +1,4 @@
[DEFAULT]
skip-if = buildapp == 'b2g'
support-files =
INT32_MIN.bmp
animated-gif2.gif
@ -54,10 +53,13 @@ support-files =
short_header.gif
source.png
over.png
6M-pixels.png
12M-pixels-1.png
12M-pixels-2.png
[test_ImageContentLoaded.html]
[test_bug399925.html]
skip-if = e10s
skip-if = e10s || buildapp == 'b2g' #Bug 969779 - should set preference via SpecialPowers.pushPrefEnv()
# [test_bug435296.html]
# disabled - See bug 578591
[test_bug466586.html]
@ -84,3 +86,5 @@ skip-if = e10s
[test_drawDiscardedImage.html]
[test_error_events.html]
[test_short_gif_header.html]
[test_image_buffer_limit.html]
run-if = toolkit == "gonk"

View File

@ -0,0 +1,94 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=878577
-->
<head>
<title>Test for Bug 878577 - Hard limit of decoded image buffer size</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="imgutils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<!--
Initial setup: The default size limit is 65M
Step 1: Load 6M-pixels.png ok
Step 2: Load 12M-pixels-1.png fail
Step 3: Remove 6M-pixels.png and clear the decoded image
Step 4: Load 12M-pixels-2.png ok
-->
<script>
SimpleTest.waitForExplicitFinish();
function loadImage(url) {
info('loading ' + url);
var image = new Image(50,50);
image.src = url;
document.body.appendChild(image);
return image;
}
function fail(msg) {
return function() {
ok(false, msg);
SimpleTest.finish();
};
}
function runTest() {
// provide a clean setup
clearImageCache();
var img_6M = loadImage('6M-pixels.png');
img_6M.onerror = fail('unable to load 6M-pixels.png');
img_6M.onload = function() {
ok(true, 'expect success on loading a 6M-pixel image');
var img_12M = loadImage('12M-pixels-1.png');
img_12M.onload = fail('should fail to load due to image buffer size limit');
img_12M.onerror = function() {
ok(true, 'expect fail on loading a 12M-pixel image');
// remove image cache
info('discard decoded image buffer');
img_6M.onerror = null;
img_6M.src = null;
img_12M.onerror = null;
img_12M.src = null;
document.body.removeChild(img_6M);
document.body.removeChild(img_12M);
clearImageCache();
// Spin the event to give the image a chance to be discarded.
SimpleTest.executeSoon(function() {
var another_img_12M = loadImage('12M-pixels-2.png');
another_img_12M.onerror = fail('unable to load 12M-pixels-2.png');
another_img_12M.onload = function() {
ok(true, 'expect success on loading another 12M-pixel image');
another_img_12M.onerror = null;
another_img_12M.onload = null;
SimpleTest.finish();
}; // another_img_12M.onload
});
}; // img_12M.onerror
}; // img_6M.onload
}
window.addEventListener("load", function() {
SpecialPowers.pushPrefEnv({
"set": [
// XXX prevent displayed imgFrame been released
["image.mem.allow_locking_in_content_processes", true]
]
}, runTest);
});
</script>
</body>
</html>