test_bug399925.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. <canvas id="canvas" width="100" height="100"> </canvas>
  17. </div>
  18. <pre id="test">
  19. <script class="testbody" type="text/javascript">
  20. /** Test for Bug 399925. **/
  21. var triggerDiscardingManually = false;
  22. var pngResults = new Array();
  23. SimpleTest.waitForExplicitFinish();
  24. SimpleTest.requestFlakyTimeout("untriaged");
  25. window.onload = function() {
  26. // It'd be nice to reduce the discard timer here, but unfortunately we only
  27. // read that pref on startup. We instead manually trigger discarding on
  28. // platforms where the discard timer is too long (which we'll somewhat
  29. // arbitrarily define as 'longer than 60 seconds').
  30. var expirationMs =
  31. SpecialPowers.getIntPref('image.mem.surfacecache.min_expiration_ms');
  32. if (expirationMs > 60000) {
  33. ok(true, 'Triggering discarding manually because SurfaceCache expiration ' +
  34. 'is ' + expirationMs + ' ms');
  35. triggerDiscardingManually = true;
  36. } else {
  37. ok(true, 'Using normal discarding because SurfaceCache expiration ' +
  38. 'is ' + expirationMs + ' ms');
  39. }
  40. // Enable discarding for the test.
  41. SpecialPowers.pushPrefEnv({
  42. 'set':[['image.mem.discardable',true]]
  43. }, runTest);
  44. }
  45. function runTest() {
  46. var image = new Image();
  47. image.setAttribute("id", "gif");
  48. // 1. Draw the canvas once on loadComplete
  49. // 2. Redraw the canvas and compare the results right on discard
  50. addCallbacks(image, drawCanvas, function() {
  51. drawCanvas();
  52. is(pngResults[0], pngResults[1], "got different rendered results");
  53. SimpleTest.finish();
  54. });
  55. image.src = "bug399925.gif";
  56. document.getElementById("content").appendChild(image);
  57. if (triggerDiscardingManually) {
  58. var request = SpecialPowers.wrap(image)
  59. .QueryInterface(SpecialPowers.Ci.nsIImageLoadingContent)
  60. .getRequest(SpecialPowers.Ci.nsIImageLoadingContent.CURRENT_REQUEST);
  61. setTimeout(() => request.requestDiscard(), 1000);
  62. }
  63. }
  64. function addCallbacks(anImage, loadCompleteCallback, discardCallback) {
  65. var observer = new ImageDecoderObserverStub();
  66. observer.discard = function () {
  67. imgLoadingContent.removeObserver(scriptedObserver);
  68. discardCallback();
  69. }
  70. observer.loadComplete = loadCompleteCallback;
  71. observer = SpecialPowers.wrapCallbackObject(observer);
  72. var scriptedObserver = SpecialPowers.Cc["@mozilla.org/image/tools;1"]
  73. .getService(SpecialPowers.Ci.imgITools)
  74. .createScriptedObserver(observer);
  75. var imgLoadingContent =
  76. SpecialPowers.wrap(anImage)
  77. .QueryInterface(SpecialPowers.Ci.nsIImageLoadingContent);
  78. imgLoadingContent.addObserver(scriptedObserver);
  79. }
  80. function drawCanvas() {
  81. var canvas = document.getElementById('canvas');
  82. var context = canvas.getContext('2d');
  83. var gif = document.getElementById('gif');
  84. context.drawImage(gif, 0, 0);
  85. ok(true, "we got through the drawImage call without an exception being thrown");
  86. pngResults.push(canvas.toDataURL());
  87. }
  88. </script>
  89. </pre>
  90. </body>
  91. </html>