image/test/mochitest/test_image_buffer_limit.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/test/mochitest/test_image_buffer_limit.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=878577
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 878577 - Hard limit of decoded image buffer size</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="application/javascript" src="imgutils.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +
    1.16 +<body>
    1.17 +
    1.18 +<!--
    1.19 +  Initial setup: The default size limit is 65M
    1.20 +  Step 1: Load 6M-pixels.png ok
    1.21 +  Step 2: Load 12M-pixels-1.png fail
    1.22 +  Step 3: Remove 6M-pixels.png and clear the decoded image
    1.23 +  Step 4: Load 12M-pixels-2.png ok
    1.24 +-->
    1.25 +
    1.26 +<script>
    1.27 +
    1.28 +SimpleTest.waitForExplicitFinish();
    1.29 +
    1.30 +function loadImage(url) {
    1.31 +  info('loading ' + url);
    1.32 +  var image = new Image(50,50);
    1.33 +  image.src = url;
    1.34 +  document.body.appendChild(image);
    1.35 +  return image;
    1.36 +}
    1.37 +
    1.38 +function fail(msg) {
    1.39 +  return function() {
    1.40 +    ok(false, msg);
    1.41 +    SimpleTest.finish();
    1.42 +  };
    1.43 +}
    1.44 +
    1.45 +function runTest() {
    1.46 +  // provide a clean setup
    1.47 +  clearImageCache();
    1.48 +
    1.49 +  var img_6M = loadImage('6M-pixels.png');
    1.50 +  img_6M.onerror = fail('unable to load 6M-pixels.png');
    1.51 +  img_6M.onload = function() {
    1.52 +    ok(true, 'expect success on loading a 6M-pixel image');
    1.53 +
    1.54 +    var img_12M = loadImage('12M-pixels-1.png');
    1.55 +    img_12M.onload = fail('should fail to load due to image buffer size limit');
    1.56 +    img_12M.onerror = function() {
    1.57 +      ok(true, 'expect fail on loading a 12M-pixel image');
    1.58 +
    1.59 +      // remove image cache
    1.60 +      info('discard decoded image buffer');
    1.61 +      img_6M.onerror = null;
    1.62 +      img_6M.src = null;
    1.63 +      img_12M.onerror = null;
    1.64 +      img_12M.src = null;
    1.65 +      document.body.removeChild(img_6M);
    1.66 +      document.body.removeChild(img_12M);
    1.67 +      clearImageCache();
    1.68 +
    1.69 +      // Spin the event to give the image a chance to be discarded.
    1.70 +      SimpleTest.executeSoon(function() {
    1.71 +        var another_img_12M = loadImage('12M-pixels-2.png');
    1.72 +        another_img_12M.onerror = fail('unable to load 12M-pixels-2.png');
    1.73 +        another_img_12M.onload = function() {
    1.74 +          ok(true, 'expect success on loading another 12M-pixel image');
    1.75 +          another_img_12M.onerror = null;
    1.76 +          another_img_12M.onload = null;
    1.77 +          SimpleTest.finish();
    1.78 +        }; // another_img_12M.onload
    1.79 +      });
    1.80 +
    1.81 +    }; // img_12M.onerror
    1.82 +  }; // img_6M.onload
    1.83 +}
    1.84 +
    1.85 +window.addEventListener("load", function() {
    1.86 +  SpecialPowers.pushPrefEnv({
    1.87 +    "set": [
    1.88 +      // XXX prevent displayed imgFrame been released
    1.89 +      ["image.mem.allow_locking_in_content_processes", true]
    1.90 +    ]
    1.91 +  }, runTest);
    1.92 +});
    1.93 +
    1.94 +</script>
    1.95 +</body>
    1.96 +</html>
    1.97 +

mercurial