test_animSVGImage2.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=907503
  5. -->
  6. <head>
  7. <title>Test for Bug 907503</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
  10. <script type="application/javascript" src="imgutils.js"></script>
  11. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  12. </head>
  13. <body>
  14. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=907503">Mozilla Bug 907503</a>
  15. <p id="display"></p>
  16. <div id="content">
  17. <div id="referenceDiv" style="height: 100px; width: 100px;
  18. display: none; background: lime"></div>
  19. <img>
  20. </div>
  21. <pre id="test">
  22. <script type="application/javascript;version=1.8">
  23. /** Test for Bug 907503**/
  24. SimpleTest.requestFlakyTimeout("Early failure timeout");
  25. SimpleTest.waitForExplicitFinish();
  26. const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
  27. const Cc = SpecialPowers.Cc;
  28. const Ci = SpecialPowers.Ci;
  29. const gImg = document.getElementsByTagName("img")[0];
  30. var gMyDecoderObserver; // value will be set in main()
  31. var gReferenceSnapshot; // value will be set in takeReferenceSnapshot()
  32. var gOnFrameUpdateCounter = 0;
  33. var gIsTestFinished = false;
  34. function takeReferenceSnapshot() {
  35. // Take a snapshot of the initial (essentially blank) page
  36. let blankSnapshot = snapshotWindow(window, false);
  37. // Show reference div, & take a snapshot
  38. let referenceDiv = document.getElementById("referenceDiv");
  39. referenceDiv.style.display = "block";
  40. gReferenceSnapshot = snapshotWindow(window, false);
  41. ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0],
  42. "reference snapshot shouldn't match blank page snapshot");
  43. // Re-hide reference div, and take another snapshot to be sure it's gone
  44. referenceDiv.style.display = "none";
  45. let blankSnapshot2 = snapshotWindow(window, false);
  46. ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0],
  47. "reference div should disappear when it becomes display:none");
  48. }
  49. function myOnFrameUpdate(aRequest) {
  50. if (gIsTestFinished) {
  51. return;
  52. }
  53. gOnFrameUpdateCounter++;
  54. ok(true, "myOnFrameUpdate called");
  55. let currentSnapshot = snapshotWindow(window, false);
  56. if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) {
  57. // SUCCESS!
  58. ok(true, "Animated image looks correct, " +
  59. "at call #" + gOnFrameUpdateCounter + " to myOnFrameUpdate");
  60. cleanUpAndFinish();
  61. }
  62. }
  63. function failTest() {
  64. if (gIsTestFinished) {
  65. return;
  66. }
  67. ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " +
  68. "Animated image still doesn't look correct, " +
  69. "after call #" + gOnFrameUpdateCounter + " to myOnFrameUpdate");
  70. cleanUpAndFinish();
  71. }
  72. function cleanUpAndFinish() {
  73. // On the off chance that failTest and myOnFrameUpdate are triggered
  74. // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
  75. if (gIsTestFinished) {
  76. return;
  77. }
  78. let imgLoadingContent = SpecialPowers.wrap(gImg).QueryInterface(Ci.nsIImageLoadingContent);
  79. imgLoadingContent.removeObserver(gMyDecoderObserver);
  80. SimpleTest.finish();
  81. gIsTestFinished = true;
  82. }
  83. function main() {
  84. takeReferenceSnapshot();
  85. // Create, customize & attach decoder observer
  86. observer = new ImageDecoderObserverStub();
  87. observer.frameUpdate = myOnFrameUpdate;
  88. gMyDecoderObserver =
  89. Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
  90. .createScriptedObserver(SpecialPowers.wrapCallbackObject(observer));
  91. let imgLoadingContent = SpecialPowers.wrap(gImg).QueryInterface(Ci.nsIImageLoadingContent);
  92. imgLoadingContent.addObserver(gMyDecoderObserver);
  93. // We want to test the cold loading behavior, so clear cache in case an
  94. // earlier test got our image in there already.
  95. clearAllImageCaches();
  96. // kick off image-loading! myOnFrameUpdate handles the rest.
  97. gImg.setAttribute("src", "lime-anim-100x100-2.svg");
  98. // In case something goes wrong, fail earlier than mochitest timeout,
  99. // and with more information.
  100. setTimeout(failTest, FAILURE_TIMEOUT);
  101. }
  102. window.onload = main;
  103. </script>
  104. </pre>
  105. </body>
  106. </html>