image/test/mochitest/test_bug399925.html

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

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=399925
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 399925</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="text/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 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=399925">Mozilla Bug 399925</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content" style="display: none">
michael@0 16 <img src="bug399925.gif" id="gif" />
michael@0 17 <canvas id="canvas" width="100" height="100"> </canvas>
michael@0 18 </div>
michael@0 19 <pre id="test">
michael@0 20 <script class="testbody" type="text/javascript">
michael@0 21
michael@0 22 /** Test for Bug 399925. **/
michael@0 23 var pngResults = new Array();
michael@0 24 var oldTimeoutPref;
michael@0 25 var oldDiscardPref;
michael@0 26 SimpleTest.waitForExplicitFinish();
michael@0 27 window.onload = runTest;
michael@0 28
michael@0 29 function runTest()
michael@0 30 {
michael@0 31 // Get the old discard timeout
michael@0 32 oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF);
michael@0 33
michael@0 34 // We're testing discarding here, so we should make sure it's flipped on
michael@0 35 oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF);
michael@0 36
michael@0 37 // Enable Discarding
michael@0 38 setImagePref(DISCARD_ENABLED_PREF, true);
michael@0 39
michael@0 40 // Sets the discard timer to 500ms so we don't have to wait so long. The
michael@0 41 // actual time is nondeterministic, but is bounded by 2 * timer = 1 second.
michael@0 42 setImagePref(DISCARD_TIMEOUT_PREF, 1000);
michael@0 43
michael@0 44 // Create the image _after_ setting the discard timer pref
michael@0 45 var image = new Image();
michael@0 46 image.setAttribute("id", "gif");
michael@0 47 image.src = "bug399925.gif";
michael@0 48 document.getElementById("content").appendChild(image);
michael@0 49
michael@0 50 // draw the canvas once
michael@0 51 drawCanvas();
michael@0 52
michael@0 53 // Set the timeout to draw it after discard
michael@0 54 setTimeout('drawCanvas(); allDone();', 3000);
michael@0 55 }
michael@0 56
michael@0 57 function drawCanvas()
michael@0 58 {
michael@0 59 var canvas = document.getElementById('canvas');
michael@0 60 var context = canvas.getContext('2d');
michael@0 61 var gif = document.getElementById('gif');
michael@0 62
michael@0 63 context.drawImage(gif, 0, 0);
michael@0 64 ok(true, "we got through the drawImage call without an exception being thrown");
michael@0 65 pngResults.push(canvas.toDataURL);
michael@0 66 }
michael@0 67
michael@0 68 function allDone()
michael@0 69 {
michael@0 70 is(pngResults[0], pngResults[1], "got different rendered results");
michael@0 71 setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref);
michael@0 72 setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref);
michael@0 73 SimpleTest.finish();
michael@0 74 }
michael@0 75
michael@0 76 </script>
michael@0 77 </pre>
michael@0 78 </body>
michael@0 79 </html>
michael@0 80

mercurial