/image/test/mochitest/test_bug399925.html

http://github.com/zpao/v8monkey · HTML · 80 lines · 64 code · 13 blank · 3 comment · 0 complexity · cc388589a2523051e660d031871280bc MD5 · raw file

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