test_animation_operators.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=936720
  5. -->
  6. <head>
  7. <title>Test for Bug 936720</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.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=936720">Mozilla Bug 936720</a>
  14. <pre id="test">
  15. <script type="application/javascript">
  16. /** Test for Bug 936720 **/
  17. // Because there is no event telling us when an animated image finishes
  18. // animating, tests for the operators used by animated GIFs and PNGs
  19. // require that we poll until we get the correct result. A fixed timeout
  20. // can easily result in intermittent failures on tests running in VMs.
  21. // (Note that we do _not_ poll the reference, so it must not be animated.)
  22. var gTests = [
  23. // IMPORTANT NOTE: For these tests, the test and reference are not
  24. // snapshotted in the same way. The REFERENCE (second file) is
  25. // assumed to be complete when loaded, but we poll the TEST
  26. // (first file) until the test passes.
  27. // Tests of the allowed disposal operators for both GIF and APNG: keep, clear,
  28. // and restore previous.
  29. "== green-background.html?clear.gif green.png",
  30. "== green-background.html?clear.png green.png",
  31. "== keep.gif green.png",
  32. "== keep.png green.png",
  33. "== restore-previous.gif green.png",
  34. "== restore-previous.png green.png",
  35. // Tests of the blending/compositing operators that only APNG supports.
  36. "== over.png grey.png",
  37. "!= source.png grey.png",
  38. "== bug900200.png bug900200-ref.png",
  39. "== bug1319025.png bug1319025-ref.png",
  40. // Test of subframe updates.
  41. "== clear2.gif clear2-results.gif",
  42. ];
  43. // Maintain a reference count of how many things we're waiting for until
  44. // we can say the tests are done.
  45. var gDelayCount = 0;
  46. function AddFinishDependency()
  47. { ++gDelayCount; }
  48. function RemoveFinishDependency()
  49. { if (--gDelayCount == 0) SimpleTest.finish(); }
  50. // We record the maximum number of times we had to look at a test before
  51. // it switched to the passing state (though we assume it's 10 to start
  52. // rather than 0 so that we have a reasonable default). Then we make a
  53. // test "time out" if it takes more than gTimeoutFactor times that
  54. // amount of time. This allows us to report a test failure rather than
  55. // making a test failure just show up as a timeout.
  56. var gMaxPassingTries = 10;
  57. var gTimeoutFactor = 10;
  58. function takeSnapshot(iframe_element)
  59. {
  60. return snapshotWindow(iframe_element.contentWindow, false);
  61. }
  62. function passes(op, shot1, shot2)
  63. {
  64. var [correct, s1, s2] = compareSnapshots(shot1, shot2, op == "==");
  65. return correct;
  66. }
  67. function startTest(i)
  68. {
  69. var testLine = gTests[i];
  70. var splitData = testLine.split(" ");
  71. var testData =
  72. { op: splitData[0], test: splitData[1], reference: splitData[2] };
  73. var tries = 0;
  74. // Maintain state specific to this test in the closure exposed to all
  75. // the functions nested inside this one.
  76. function startIframe(url)
  77. {
  78. var element = document.createElement("iframe");
  79. element.addEventListener("load", handleLoad, false);
  80. // Smaller than normal reftests, but enough for these.
  81. element.setAttribute("style", "width: 100px; height: 100px");
  82. element.setAttribute("frameborder", "0");
  83. element.setAttribute("scrolling", "no");
  84. element.src = url;
  85. document.body.appendChild(element);
  86. function handleLoad(event)
  87. {
  88. iframe.loaded = true;
  89. if (iframe == reference) {
  90. reference.snapshot = takeSnapshot(element);
  91. }
  92. var other = (iframe == test) ? reference : test;
  93. if (other.loaded) {
  94. setTimeout(checkTest, 100);
  95. }
  96. }
  97. function checkTest()
  98. {
  99. var test_snapshot = takeSnapshot(test.element);
  100. if (passes(testData.op, test_snapshot, reference.snapshot)) {
  101. if (tries > gMaxPassingTries) {
  102. gMaxPassingTries = tries;
  103. }
  104. report(true);
  105. } else {
  106. ++tries;
  107. if (tries > gMaxPassingTries * gTimeoutFactor) {
  108. info("Giving up after " + tries + " tries, " +
  109. "maxp=" + gMaxPassingTries +
  110. "fact=" + gTimeoutFactor);
  111. report(false);
  112. } else {
  113. // The animation might not have finished. Try again in 100ms.
  114. setTimeout(checkTest, 100);
  115. }
  116. }
  117. }
  118. function report(result)
  119. {
  120. ok(result, "(" + i + ") " +
  121. testData.op + " " + testData.test + " " + testData.reference);
  122. RemoveFinishDependency();
  123. }
  124. var iframe = { element: element, loaded: false };
  125. return iframe;
  126. }
  127. AddFinishDependency();
  128. var test = startIframe(testData.test);
  129. var reference = startIframe(testData.reference);
  130. }
  131. SimpleTest.waitForExplicitFinish();
  132. SimpleTest.requestFlakyTimeout("untriaged");
  133. // Run the tests.
  134. for (var i = 0; i < gTests.length; ++i) {
  135. startTest(i);
  136. }
  137. </script>
  138. </pre>
  139. </body>
  140. </html>