image/test/mochitest/test_image_buffer_limit.html

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:88b2fd72564d
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=878577
5 -->
6 <head>
7 <title>Test for Bug 878577 - Hard limit of decoded image buffer size</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="imgutils.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12
13 <body>
14
15 <!--
16 Initial setup: The default size limit is 65M
17 Step 1: Load 6M-pixels.png ok
18 Step 2: Load 12M-pixels-1.png fail
19 Step 3: Remove 6M-pixels.png and clear the decoded image
20 Step 4: Load 12M-pixels-2.png ok
21 -->
22
23 <script>
24
25 SimpleTest.waitForExplicitFinish();
26
27 function loadImage(url) {
28 info('loading ' + url);
29 var image = new Image(50,50);
30 image.src = url;
31 document.body.appendChild(image);
32 return image;
33 }
34
35 function fail(msg) {
36 return function() {
37 ok(false, msg);
38 SimpleTest.finish();
39 };
40 }
41
42 function runTest() {
43 // provide a clean setup
44 clearImageCache();
45
46 var img_6M = loadImage('6M-pixels.png');
47 img_6M.onerror = fail('unable to load 6M-pixels.png');
48 img_6M.onload = function() {
49 ok(true, 'expect success on loading a 6M-pixel image');
50
51 var img_12M = loadImage('12M-pixels-1.png');
52 img_12M.onload = fail('should fail to load due to image buffer size limit');
53 img_12M.onerror = function() {
54 ok(true, 'expect fail on loading a 12M-pixel image');
55
56 // remove image cache
57 info('discard decoded image buffer');
58 img_6M.onerror = null;
59 img_6M.src = null;
60 img_12M.onerror = null;
61 img_12M.src = null;
62 document.body.removeChild(img_6M);
63 document.body.removeChild(img_12M);
64 clearImageCache();
65
66 // Spin the event to give the image a chance to be discarded.
67 SimpleTest.executeSoon(function() {
68 var another_img_12M = loadImage('12M-pixels-2.png');
69 another_img_12M.onerror = fail('unable to load 12M-pixels-2.png');
70 another_img_12M.onload = function() {
71 ok(true, 'expect success on loading another 12M-pixel image');
72 another_img_12M.onerror = null;
73 another_img_12M.onload = null;
74 SimpleTest.finish();
75 }; // another_img_12M.onload
76 });
77
78 }; // img_12M.onerror
79 }; // img_6M.onload
80 }
81
82 window.addEventListener("load", function() {
83 SpecialPowers.pushPrefEnv({
84 "set": [
85 // XXX prevent displayed imgFrame been released
86 ["image.mem.allow_locking_in_content_processes", true]
87 ]
88 }, runTest);
89 });
90
91 </script>
92 </body>
93 </html>
94

mercurial