test_drawDiscardedImage.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=731419
  5. -->
  6. <head>
  7. <title>Test for Bug 731419 - Draw an ostensibly discarded image to a canvas</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. </head>
  11. <body>
  12. <!--
  13. Load an image in an iframe, then draw that image to a canvas. Then set the
  14. iframe to display:none (after bug 731419, this causes the image's decoded
  15. data to be discarded) and draw the image to a canvas again. We should draw
  16. the same image data both times.
  17. -->
  18. <script>
  19. SimpleTest.waitForExplicitFinish();
  20. var data1;
  21. function drawImage()
  22. {
  23. var canvas = document.getElementById('canvas');
  24. var ctx = canvas.getContext('2d');
  25. var iframeDoc = document.getElementById('iframe').contentDocument;
  26. ctx.clearRect(0, 0, canvas.height, canvas.width);
  27. ctx.drawImage(iframeDoc.getElementById('image'), 0, 0);
  28. return canvas.toDataURL();
  29. }
  30. function iframeLoad()
  31. {
  32. data1 = drawImage();
  33. document.getElementById('iframe').style.display = 'none';
  34. // Spin the event loop a few times to give the image in the display:none
  35. // iframe a chance to be discarded.
  36. SimpleTest.executeSoon(function() {
  37. SimpleTest.executeSoon(function() {
  38. SimpleTest.executeSoon(function() {
  39. step2();
  40. });
  41. });
  42. });
  43. }
  44. function step2()
  45. {
  46. is(drawImage(), data1, "Same image before and after iframe display:none");
  47. SimpleTest.finish();
  48. }
  49. </script>
  50. <canvas id='canvas'></canvas>
  51. <iframe id='iframe' onload='iframeLoad()' src='data:text/html,<img id="image"
  52. src="data:image/png;base64,
  53. iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADRElEQVQ4EQXBTWgcZQCA4ff7ZmZ3
  54. NpvNZLObTWpCuoZGIxWJplAKb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fT1aWJwtyYea9VEXoAo
  68. RfHGYhTfvRfF48BdYB3YAPgfnOuE39kFlREAAAAASUVORK5CYII=">'></iframe>
  69. </body>
  70. </html>