tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug478398.html (2231B)


      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 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">
     16 
     17 /** Test for Bug 399925. */
     18 var oldTimeoutPref;
     19 var oldDiscardPref;
     20 SimpleTest.waitForExplicitFinish();
     21 window.onload = stage1;
     22 var imageFilename = "bug478398_ONLY.png";
     23 
     24 function stage1()
     25 {
     26  // Get the current pref values
     27  oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF);
     28  oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF);
     29 
     30  // We're testing discarding here
     31  setImagePref(DISCARD_ENABLED_PREF, true);
     32 
     33  // Sets the discard timer to 500 ms (max timeout = 2*500ms = 1s)
     34  setImagePref(DISCARD_TIMEOUT_PREF, 500);
     35 
     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;
     43 
     44  // Put the image into the document
     45  document.body.appendChild(image);
     46 
     47  // Wait for load, then do stage2
     48  image.onload = stage2;
     49 }
     50 
     51 function stage2()
     52 {
     53  // Make sure we're loaded
     54  ok(isImageLoaded("testimage"), "image should be loaded");
     55 
     56  // We're loaded - force a synchronous decode
     57  forceDecode("testimage");
     58 
     59  // We should be decoded
     60  ok(isFrameDecoded("testimage"), "image should be decoded");
     61 
     62  // Wait 1.5 seconds, then finish the test
     63  setTimeout(function() {
     64    finishTest();;
     65  }, 1500);
     66 
     67 }
     68 
     69 function finishTest()
     70 {
     71  // The image should be discarded by now
     72  ok(!isFrameDecoded("testimage"), "image should have been discarded!");
     73 
     74  // Reset the prefs
     75  setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref);
     76  setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref);
     77 
     78  // Finish the test
     79  SimpleTest.finish();
     80 }
     81 
     82 
     83 </script>
     84 </pre>
     85 </body>
     86 </html>