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