test_animations_event_handler_attribute.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!doctype html>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=911987
  5. -->
  6. <head>
  7. <meta charset=utf-8>
  8. <title>Test for CSS Animation and Transition event handler
  9. attributes. (Bug 911987)</title>
  10. <script type="application/javascript"
  11. src="/tests/SimpleTest/SimpleTest.js"></script>
  12. <script type="application/javascript" src="animation_utils.js"></script>
  13. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  14. <style>
  15. @keyframes anim { to { margin-left: 100px } }
  16. </style>
  17. </head>
  18. <body>
  19. <a target="_blank"
  20. href="https://bugzilla.mozilla.org/show_bug.cgi?id=911987">Mozilla Bug
  21. 911987</a>
  22. <div id="display"></div>
  23. <pre id="test">
  24. <script type="application/javascript">
  25. 'use strict';
  26. // Create the div element with event handlers.
  27. // We need two elements: one with the content attribute speficied and one
  28. // with the IDL attribute specified since we can't set these independently.
  29. function createAndRegisterTargets(eventAttributes) {
  30. var displayElement = document.getElementById('display');
  31. var contentAttributeElement = document.createElement("div");
  32. var idlAttributeElement = document.createElement("div");
  33. displayElement.appendChild(contentAttributeElement);
  34. displayElement.appendChild(idlAttributeElement);
  35. // Add handlers
  36. eventAttributes.forEach(event => {
  37. contentAttributeElement.setAttribute(event, 'handleEvent(event);');
  38. contentAttributeElement.handlerType = 'content attribute';
  39. idlAttributeElement[event] = handleEvent;
  40. idlAttributeElement.handlerType = 'IDL attribute';
  41. });
  42. return [contentAttributeElement, idlAttributeElement];
  43. }
  44. function handleEvent(event) {
  45. if (event.target.receivedEventType) {
  46. ok(false, `Received ${event.type} event, but this element have previous `
  47. `received event '${event.target.receivedEventType}'.`);
  48. return;
  49. }
  50. event.target.receivedEventType = event.type;
  51. }
  52. function checkReceivedEvents(eventType, elements) {
  53. elements.forEach(element => {
  54. is(element.receivedEventType, eventType,
  55. `Expected to receive '${eventType}', got
  56. '${element.receivedEventType}', for event handler registered
  57. using ${element.handlerType}`);
  58. element.receivedEventType = undefined;
  59. });
  60. }
  61. // Take over the refresh driver right from the start.
  62. advance_clock(0);
  63. // 1. Test CSS Animation event handlers.
  64. var targets = createAndRegisterTargets([ 'onanimationstart',
  65. 'onanimationiteration',
  66. 'onanimationend' ]);
  67. targets.forEach(div => {
  68. div.setAttribute('style', 'animation: anim 100ms 2');
  69. getComputedStyle(div).animationName; // flush
  70. });
  71. advance_clock(0);
  72. checkReceivedEvents("animationstart", targets);
  73. advance_clock(100);
  74. checkReceivedEvents("animationiteration", targets);
  75. advance_clock(200);
  76. checkReceivedEvents("animationend", targets);
  77. targets.forEach(div => { div.remove(); });
  78. // 2a. Test CSS Transition event handlers (without transitioncancel)
  79. var targets = createAndRegisterTargets([ 'ontransitionrun',
  80. 'ontransitionstart',
  81. 'ontransitionend',
  82. 'ontransitioncancel' ]);
  83. targets.forEach(div => {
  84. div.style.transition = 'margin-left 100ms 200ms';
  85. getComputedStyle(div).marginLeft; // flush
  86. div.style.marginLeft = "200px";
  87. getComputedStyle(div).marginLeft; // flush
  88. });
  89. advance_clock(0);
  90. checkReceivedEvents("transitionrun", targets);
  91. advance_clock(200);
  92. checkReceivedEvents("transitionstart", targets);
  93. advance_clock(100);
  94. checkReceivedEvents("transitionend", targets);
  95. targets.forEach(div => { div.remove(); });
  96. // 2b. Test CSS Transition cancel event handler.
  97. var targets = createAndRegisterTargets([ 'ontransitioncancel' ]);
  98. targets.forEach(div => {
  99. div.style.transition = 'margin-left 100ms 200ms';
  100. getComputedStyle(div).marginLeft; // flush
  101. div.style.marginLeft = "200px";
  102. getComputedStyle(div).marginLeft; // flush
  103. });
  104. advance_clock(200);
  105. targets.forEach(div => {
  106. div.style.display = "none"
  107. });
  108. getComputedStyle(targets[0]).display; // flush
  109. advance_clock(0);
  110. checkReceivedEvents("transitioncancel", targets);
  111. advance_clock(100);
  112. targets.forEach( div => { is(div.receivedEventType, undefined); });
  113. targets.forEach(div => { div.remove(); });
  114. // 3. Test prefixed CSS Animation event handlers.
  115. var targets = createAndRegisterTargets([ 'onwebkitanimationstart',
  116. 'onwebkitanimationiteration',
  117. 'onwebkitanimationend' ]);
  118. targets.forEach(div => {
  119. div.setAttribute('style', 'animation: anim 100ms 2');
  120. getComputedStyle(div).animationName; // flush
  121. });
  122. advance_clock(0);
  123. checkReceivedEvents("webkitAnimationStart", targets);
  124. advance_clock(100);
  125. checkReceivedEvents("webkitAnimationIteration", targets);
  126. advance_clock(200);
  127. checkReceivedEvents("webkitAnimationEnd", targets);
  128. targets.forEach(div => { div.remove(); });
  129. // 4. Test prefixed CSS Transition event handlers.
  130. advance_clock(0);
  131. var targets = createAndRegisterTargets([ 'onwebkittransitionend' ]);
  132. targets.forEach(div => {
  133. div.style.transition = 'margin-left 100ms';
  134. getComputedStyle(div).marginLeft; // flush
  135. div.style.marginLeft = "200px";
  136. getComputedStyle(div).marginLeft; // flush
  137. });
  138. advance_clock(100);
  139. checkReceivedEvents("webkitTransitionEnd", targets);
  140. targets.forEach(div => { div.remove(); });
  141. SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
  142. </script>
  143. </body>
  144. </html>