image/test/mochitest/test_bug478398.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.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=478398
     5 -->
     6 <head>
     7   <title>Test for Bug 478398</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" src="imgutils.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478398">Mozilla Bug 478398</a>
    14 <pre id="test">
    15 <script class="testbody" type="text/javascript">
    17 /** Test for Bug 399925. **/
    18 var oldTimeoutPref;
    19 var oldDiscardPref;
    20 SimpleTest.waitForExplicitFinish();
    21 window.onload = stage1;
    22 var imageFilename = "bug478398_ONLY.png";
    24 function stage1()
    25 {
    26   // Get the current pref values
    27   oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF);
    28   oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF);
    30   // We're testing discarding here
    31   setImagePref(DISCARD_ENABLED_PREF, true);
    33   // Sets the discard timer to 500 ms (max timeout = 2*500ms = 1s)
    34   setImagePref(DISCARD_TIMEOUT_PREF, 500);
    36   // Create the image _after_ setting the discard timer pref
    37   // This image was carefully constructed to make it a "big win" for discarding,
    38   // so any reasonable heuristic should still discard it.
    39   var image = new Image();
    40   image.setAttribute("id", "testimage");
    41   image.style.display = "none";
    42   image.src = imageFilename;
    44   // Put the image into the document
    45   document.body.appendChild(image);
    47   // Wait for load, then do stage2
    48   image.onload = stage2;
    49 }
    51 function stage2()
    52 {
    53   // Make sure we're loaded
    54   ok(isImageLoaded("testimage"), "image should be loaded");
    56   // We're loaded - force a synchronous decode
    57   forceDecode("testimage");
    59   // We should be decoded
    60   ok(isFrameDecoded("testimage"), "image should be decoded");
    62   // Wait 1.5 seconds, then finish the test
    63   setTimeout("finishTest();", 1500);
    65 }
    67 function finishTest()
    68 {
    69   // The image should be discarded by now
    70   ok(!isFrameDecoded("testimage"), "image should have been discarded!");
    72   // Reset the prefs
    73   setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref);
    74   setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref);
    76   // Finish the test
    77   SimpleTest.finish();
    78 }
    81 </script>
    82 </pre>
    83 </body>
    84 </html>

mercurial