Bug 1287983 part 4 - Add transition event handler test for checking elapsed time. r?birtles draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Wed, 19 Oct 2016 15:16:52 +0900
changeset 427851 5a467b334656b6e34f573f3360b20ce34fbeb165
parent 427850 d6ab373f010658772045642cae3eb5f21a4b66d4
child 427852 62ebe9849929bea3ef7c83140e399db31550bf34
push id33142
push usermantaroh@gmail.com
push dateFri, 21 Oct 2016 00:27:27 +0000
reviewersbirtles
bugs1287983
milestone52.0a1
Bug 1287983 part 4 - Add transition event handler test for checking elapsed time. r?birtles MozReview-Commit-ID: KwtsVbII95v
dom/animation/test/css-transitions/file_csstransition-events.html
dom/animation/test/css-transitions/test_csstransition-events.html
dom/animation/test/mochitest.ini
new file mode 100644
--- /dev/null
+++ b/dom/animation/test/css-transitions/file_csstransition-events.html
@@ -0,0 +1,182 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Tests for CSS-Transition events</title>
+<link rel="help" href="https://drafts.csswg.org/css-transitions-2/#transition-events">
+<script src="../testcommon.js"></script>
+<body>
+<script>
+'use strict';
+
+/**
+ * Helper class to record the elapsedTime member of each event.
+ * The EventWatcher class in testharness.js allows us to wait on
+ * multiple events in a certain order but only records the event
+ * parameters of the most recent event.
+ */
+function TransitionEventHandler(target) {
+  this.target = target;
+  this.target.ontransitionrun = function(evt) {
+    this.transitionrun = evt.elapsedTime;
+  }.bind(this);
+  this.target.ontransitionstart = function(evt) {
+    this.transitionstart = evt.elapsedTime;
+  }.bind(this);
+  this.target.ontransitionend = function(evt) {
+    this.transitionend = evt.elapsedTime;
+  }.bind(this);
+}
+
+TransitionEventHandler.prototype.clear = function() {
+  this.transitionrun   = undefined;
+  this.transitionstart = undefined;
+  this.transitionend   = undefined;
+};
+
+function setupTransition(t) {
+  var div, watcher, handler, transition;
+  div = addDiv(t, { style: 'transition: margin-left 100s 100s' });
+  watcher = new EventWatcher(t, div, [ 'transitionrun',
+                                       'transitionstart',
+                                       'transitionend' ]);
+  handler = new TransitionEventHandler(div);
+  flushComputedStyle(div);
+
+  div.style.marginLeft = '100px';
+  flushComputedStyle(div);
+
+  transition = div.getAnimations()[0];
+
+  return [transition, watcher, handler];
+}
+
+// On the next frame (i.e. when events are queued), whether or not the
+// transition is still pending depends on the implementation.
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  return watcher.wait_for('transitionrun').then(function(evt) {
+    assert_equals(evt.elapsedTime, 0.0);
+  });
+}, 'Idle -> Pending or Before');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  // Force the transition to leave the idle phase
+  transition.startTime = document.timeline.currentTime;
+  return watcher.wait_for('transitionrun').then(function(evt) {
+    assert_equals(evt.elapsedTime, 0.0);
+  });
+}, 'Idle -> Before');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  // Seek to Active phase.
+  transition.currentTime = 100 * MS_PER_SEC;
+  transition.pause();
+  return watcher.wait_for([ 'transitionrun',
+                            'transitionstart' ]).then(function(evt) {
+    assert_equals(handler.transitionrun, 0.0);
+    assert_equals(handler.transitionstart, 0.0);
+  });
+}, 'Idle or Pending -> Active');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  // Seek to After phase.
+  transition.finish();
+  return watcher.wait_for([ 'transitionrun',
+                            'transitionstart',
+                            'transitionend' ]).then(function(evt) {
+    assert_equals(handler.transitionrun, 0.0);
+    assert_equals(handler.transitionstart, 0.0);
+    assert_equals(handler.transitionend, 100.0);
+  });
+}, 'Idle or Pending -> After');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+
+  return Promise.all([ watcher.wait_for('transitionrun'),
+                       transition.ready ]).then(function() {
+    transition.currentTime = 100 * MS_PER_SEC;
+    return watcher.wait_for('transitionstart');
+  }).then(function() {
+    assert_equals(handler.transitionstart, 0.0);
+  });
+}, 'Before -> Active');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  return Promise.all([ watcher.wait_for('transitionrun'),
+                       transition.ready ]).then(function() {
+    // Seek to After phase.
+    transition.currentTime = 200 * MS_PER_SEC;
+    return watcher.wait_for([ 'transitionstart', 'transitionend' ]);
+  }).then(function(evt) {
+    assert_equals(handler.transitionstart, 0.0);
+    assert_equals(handler.transitionend, 100.0);
+  });
+}, 'Before -> After');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  // Seek to Active phase.
+  transition.currentTime = 100 * MS_PER_SEC;
+  return watcher.wait_for([ 'transitionrun',
+                            'transitionstart' ]).then(function(evt) {
+    // Seek to Before phase.
+    transition.currentTime = 0;
+    return watcher.wait_for('transitionend');
+  }).then(function(evt) {
+    assert_equals(evt.elapsedTime, 0.0);
+  });
+}, 'Active -> Before');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  // Seek to Active phase.
+  transition.currentTime = 100 * MS_PER_SEC;
+  return watcher.wait_for([ 'transitionrun',
+                            'transitionstart' ]).then(function(evt) {
+    // Seek to After phase.
+    transition.currentTime = 200 * MS_PER_SEC;
+    return watcher.wait_for('transitionend');
+  }).then(function(evt) {
+    assert_equals(evt.elapsedTime, 100.0);
+  });
+}, 'Active -> After');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  // Seek to After phase.
+  transition.finish();
+  return watcher.wait_for([ 'transitionrun',
+                            'transitionstart',
+                            'transitionend' ]).then(function(evt) {
+    // Seek to Before phase.
+    transition.currentTime = 0;
+    return watcher.wait_for([ 'transitionstart', 'transitionend' ]);
+  }).then(function(evt) {
+    assert_equals(handler.transitionstart, 100.0);
+    assert_equals(handler.transitionend, 0.0);
+  });
+}, 'After -> Before');
+
+promise_test(function(t) {
+  var [transition, watcher, handler] = setupTransition(t);
+  // Seek to After phase.
+  transition.finish();
+  return watcher.wait_for([ 'transitionrun',
+                            'transitionstart',
+                            'transitionend' ]).then(function(evt) {
+    // Seek to Active phase.
+    transition.currentTime = 100 * MS_PER_SEC;
+    return watcher.wait_for('transitionstart');
+  }).then(function(evt) {
+    assert_equals(evt.elapsedTime, 100.0);
+  });
+}, 'After -> Active');
+
+done();
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/animation/test/css-transitions/test_csstransition-events.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<meta charset=utf-8>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+'use strict';
+setup({explicit_done: true});
+SpecialPowers.pushPrefEnv(
+  { "set": [["dom.animations-api.core.enabled", true]]},
+  function() {
+    window.open("file_csstransition-events.html");
+  });
+</script>
--- a/dom/animation/test/mochitest.ini
+++ b/dom/animation/test/mochitest.ini
@@ -23,16 +23,17 @@ support-files =
   css-animations/file_pseudoElement-get-animations.html
   css-transitions/file_animation-cancel.html
   css-transitions/file_animation-computed-timing.html
   css-transitions/file_animation-currenttime.html
   css-transitions/file_animation-finished.html
   css-transitions/file_animation-pausing.html
   css-transitions/file_animation-ready.html
   css-transitions/file_animation-starttime.html
+  css-transitions/file_csstransition-events.html
   css-transitions/file_csstransition-transitionproperty.html
   css-transitions/file_document-get-animations.html
   css-transitions/file_effect-target.html
   css-transitions/file_element-get-animations.html
   css-transitions/file_keyframeeffect-getkeyframes.html
   css-transitions/file_pseudoElement-get-animations.html
   css-transitions/file_setting-effect.html
   document-timeline/file_document-timeline.html
@@ -74,16 +75,17 @@ skip-if = buildapp == 'mulet'
 [css-animations/test_pseudoElement-get-animations.html]
 [css-transitions/test_animation-cancel.html]
 [css-transitions/test_animation-computed-timing.html]
 [css-transitions/test_animation-currenttime.html]
 [css-transitions/test_animation-finished.html]
 [css-transitions/test_animation-pausing.html]
 [css-transitions/test_animation-ready.html]
 [css-transitions/test_animation-starttime.html]
+[css-transitions/test_csstransition-events.html]
 [css-transitions/test_csstransition-transitionproperty.html]
 [css-transitions/test_document-get-animations.html]
 [css-transitions/test_effect-target.html]
 [css-transitions/test_element-get-animations.html]
 skip-if = buildapp == 'mulet'
 [css-transitions/test_keyframeeffect-getkeyframes.html]
 [css-transitions/test_pseudoElement-get-animations.html]
 [css-transitions/test_setting-effect.html]