Bug 1244635 - Part3 Add enddelay tests in testing/web-platform/tests/web-animations r=hiro draft
authorRyo Motozawa <motozawa@mozilla-japan.org>
Tue, 08 Mar 2016 10:31:36 +0900
changeset 337572 32b89433a64de2f2d49c240fa5cf246d19777fe1
parent 337571 5f43fe24f921dcecf3a091e4c37feabd38a3e2b5
child 337573 fc51c2e7de640e293fd09e2aa52c15f48c0f4223
push id12400
push userbmo:motoryo1@gmail.com
push dateTue, 08 Mar 2016 01:36:13 +0000
reviewershiro
bugs1244635
milestone48.0a1
Bug 1244635 - Part3 Add enddelay tests in testing/web-platform/tests/web-animations r=hiro MozReview-Commit-ID: GnIp7BmwPxw
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/web-animations/animation-effect-timing/endDelay.html
testing/web-platform/tests/web-animations/animation-effect-timing/getAnimations.html
testing/web-platform/tests/web-animations/animation-effect-timing/getComputedStyle.html
testing/web-platform/tests/web-animations/testcommon.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -28329,16 +28329,20 @@
         "path": "web-animations/animatable/animate.html",
         "url": "/web-animations/animatable/animate.html"
       },
       {
         "path": "web-animations/animation-effect-timing/duration.html",
         "url": "/web-animations/animation-effect-timing/duration.html"
       },
       {
+        "path": "web-animations/animation-effect-timing/endDelay.html",
+        "url": "/web-animations/animation-effect-timing/endDelay.html"
+      },
+      {
         "path": "web-animations/animation-effect-timing/getAnimations.html",
         "url": "/web-animations/animation-effect-timing/getAnimations.html"
       },
       {
         "path": "web-animations/animation-effect-timing/getComputedStyle.html",
         "url": "/web-animations/animation-effect-timing/getComputedStyle.html"
       },
       {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/web-animations/animation-effect-timing/endDelay.html
@@ -0,0 +1,99 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>endDelay tests</title>
+<link rel="help" href="http://w3c.github.io/web-animations/#dom-animationeffecttiming-enddelay">
+<link rel="author" title="Ryo Motozawa" href="mailto:motozawa@mozilla-japan.org">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../testcommon.js"></script>
+<link rel="stylesheet" href="/resources/testharness.css">
+<body>
+<div id="log"></div>
+<script>
+'use strict';
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
+  anim.effect.timing.endDelay = 123.45;
+  assert_approx_equals(anim.effect.timing.endDelay, 123.45, 0.000001,
+                       'set endDelay 123.45');
+  assert_approx_equals(anim.effect.getComputedTiming().endDelay, 123.45,
+                       0.000001,
+                       'getComputedTiming() after set endDelay 123.45');
+}, 'set endDelay 123.45');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
+  anim.effect.timing.endDelay = -1000;
+  assert_equals(anim.effect.timing.endDelay, -1000, 'set endDelay -1000');
+  assert_equals(anim.effect.getComputedTiming().endDelay, -1000,
+                'getComputedTiming() after set endDelay -1000');
+}, 'set endDelay -1000');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
+  assert_throws({name: "TypeError"}, function() {
+    anim.effect.timing.endDelay = Infinity;
+  }, 'we can not assign Infinity to timing.endDelay');
+}, 'set endDelay Infinity');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
+  assert_throws({name: "TypeError"}, function() {
+    anim.effect.timing.endDelay = -Infinity;
+  }, 'we can not assign negative Infinity to timing.endDelay');
+}, 'set endDelay negative Infinity');
+
+async_test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] },
+                         { duration: 100000, endDelay: 50000 });
+  anim.onfinish = t.step_func(function(event) {
+    assert_unreached('onfinish event should not be fired');
+  });
+
+  anim.ready.then(function() {
+    anim.currentTime = 100000;
+    return waitForAnimationFrames(2);
+  }).then(t.step_func(function() {
+    t.done();
+  }));
+}, 'onfinish event is not fired duration endDelay');
+
+async_test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] },
+                         { duration: 100000, endDelay: 30000 });
+  var finishedTimelineTime;
+  anim.finished.then(function() {
+    finishedTimelineTime = anim.timeline.currentTime;
+  });
+
+  var receivedEvents = [];
+  anim.onfinish = function(event) {
+    receivedEvents.push(event);
+  }
+
+  anim.ready.then(function() {
+    anim.currentTime = 110000; // during endDelay
+    return waitForAnimationFrames(2);
+  }).then(t.step_func(function() {
+    assert_equals(receivedEvents.length, 0,
+      'onfinish event is should not be fired' +
+      'when currentTime is during endDelay');
+    anim.currentTime = 130000; // after endTime
+    return waitForAnimationFrames(2);
+  })).then(t.step_func_done(function() {
+    assert_equals(receivedEvents.length, 1, 'length of array should be one');
+    assert_equals(receivedEvents[0].timelineTime, finishedTimelineTime,
+      'receivedEvents[0].timelineTime should equal to the animation timeline '
+      + 'when finished promise is resolved');
+  }));
+}, 'onfinish event is fired currentTime is after endTime');
+
+</script>
+</body>
--- a/testing/web-platform/tests/web-animations/animation-effect-timing/getAnimations.html
+++ b/testing/web-platform/tests/web-animations/animation-effect-timing/getAnimations.html
@@ -20,10 +20,60 @@ test(function(t) {
   anim.effect.timing.duration += 100000;
   assert_equals(div.getAnimations()[0], anim, 'set duration 102000');
   anim.effect.timing.duration = 0;
   assert_equals(div.getAnimations().length, 0, 'set duration 0');
   anim.effect.timing.duration = 'auto';
   assert_equals(div.getAnimations().length, 0, 'set duration \'auto\'');
 }, 'when duration is changed');
 
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
+
+  anim.effect.timing.endDelay = -3000;
+  assert_equals(div.getAnimations().length, 0,
+    'set negative endDelay so as endTime is less than currentTime');
+  anim.effect.timing.endDelay = 1000;
+  assert_equals(div.getAnimations()[0], anim,
+    'set positive endDelay so as endTime is more than currentTime');
+
+  anim.effect.timing.duration = 1000;
+  anim.currentTime = 1500;
+  assert_equals(div.getAnimations().length, 0,
+    'set currentTime less than endTime');
+  anim.effect.timing.endDelay = -500;
+  anim.currentTime = 400;
+  assert_equals(div.getAnimations()[0], anim,
+    'set currentTime less than endTime when endDelay is negative value');
+  anim.currentTime = 500;
+  assert_equals(div.getAnimations().length, 0,
+    'set currentTime same as endTime when endDelay is negative value');
+  anim.currentTime = 1000;
+  assert_equals(div.getAnimations().length, 0,
+    'set currentTime same as duration when endDelay is negative value');
+}, 'when endDelay is changed');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] },
+                         { duration: 1000, delay: 500, endDelay: -500 });
+  assert_equals(div.getAnimations()[0], anim, 'when currentTime 0');
+  anim.currentTime = 500;
+  assert_equals(div.getAnimations()[0], anim, 'set currentTime 500');
+  anim.currentTime = 1000;
+  assert_equals(div.getAnimations().length, 0, 'set currentTime 1000');
+}, 'when currentTime changed in duration:1000, delay: 500, endDelay: -500');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 0, 1 ] },
+                         { duration: 1000, delay: -500, endDelay: -500 });
+  assert_equals(div.getAnimations().length, 0, 'when currentTime 0');
+  anim.currentTime = 500;
+  assert_equals(div.getAnimations().length, 0, 'set currentTime 500');
+  anim.currentTime = 1000;
+  assert_equals(div.getAnimations().length, 0, 'set currentTime 1000');
+}, 'when currentTime changed in duration:1000, delay: -500, endDelay: -500');
+
+
 </script>
 </body>
--- a/testing/web-platform/tests/web-animations/animation-effect-timing/getComputedStyle.html
+++ b/testing/web-platform/tests/web-animations/animation-effect-timing/getComputedStyle.html
@@ -20,10 +20,89 @@ test(function(t) {
   anim.effect.timing.duration *= 2;
   assert_equals(getComputedStyle(div).opacity, '0.5', 'set double duration');
   anim.effect.timing.duration = 0;
   assert_equals(getComputedStyle(div).opacity, '1', 'set duration 0');
   anim.effect.timing.duration = 'auto';
   assert_equals(getComputedStyle(div).opacity, '1', 'set duration \'auto\'');
 }, 'changed duration immediately updates its computed styles');
 
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 1, 0 ] },
+                         { duration: 10000, endDelay: 1000, fill: 'none' });
+
+  anim.currentTime = 9000;
+  assert_equals(getComputedStyle(div).opacity, '0.1',
+                'set currentTime during duration');
+
+  anim.currentTime = 10900;
+  assert_equals(getComputedStyle(div).opacity, '1',
+                'set currentTime during endDelay');
+
+  anim.currentTime = 11100;
+  assert_equals(getComputedStyle(div).opacity, '1',
+                'set currentTime after endDelay');
+}, 'change currentTime when fill is none and endDelay is positive');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 1, 0 ] },
+                         { duration: 10000,
+                           endDelay: 1000,
+                           fill: 'forwards' });
+  anim.currentTime = 5000;
+  assert_equals(getComputedStyle(div).opacity, '0.5',
+                'set currentTime during duration');
+
+  anim.currentTime = 9999;
+  assert_equals(getComputedStyle(div).opacity, '0.0001',
+                'set currentTime just a little before duration');
+
+  anim.currentTime = 10900;
+  assert_equals(getComputedStyle(div).opacity, '0',
+                'set currentTime during endDelay');
+
+  anim.currentTime = 11100;
+  assert_equals(getComputedStyle(div).opacity, '0',
+                'set currentTime after endDelay');
+}, 'change currentTime when fill forwards and endDelay is positive');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 1, 0 ] },
+                         { duration: 10000, endDelay: -5000, fill: 'none' });
+
+  anim.currentTime = 1000;
+  assert_equals(getComputedStyle(div).opacity, '0.9',
+                'set currentTime before endTime');
+
+  anim.currentTime = 10000;
+  assert_equals(getComputedStyle(div).opacity, '1',
+                'set currentTime after endTime');
+}, 'change currentTime when fill none and endDelay is negative');
+
+test(function(t) {
+  var div = createDiv(t);
+  var anim = div.animate({ opacity: [ 1, 0 ] },
+                         { duration: 10000,
+                           endDelay: -5000,
+                           fill: 'forwards' });
+
+  anim.currentTime = 1000;
+  assert_equals(getComputedStyle(div).opacity, '0.9',
+                'set currentTime before endTime');
+
+  anim.currentTime = 5000;
+  assert_equals(getComputedStyle(div).opacity, '0',
+                'set currentTime same as endTime');
+
+  anim.currentTime = 9999;
+  assert_equals(getComputedStyle(div).opacity, '0',
+                'set currentTime during duration');
+
+  anim.currentTime = 10000;
+  assert_equals(getComputedStyle(div).opacity, '0',
+                'set currentTime after endTime');
+}, 'change currentTime when fill forwards and endDelay is negative');
+
 </script>
 </body>
--- a/testing/web-platform/tests/web-animations/testcommon.js
+++ b/testing/web-platform/tests/web-animations/testcommon.js
@@ -108,8 +108,20 @@ function stepEnd(nsteps) {
 
 function stepStart(nsteps) {
   return function stepStartClosure(x) {
     var result = Math.floor(x * nsteps + 1.0) / nsteps;
     return (result > 1.0) ? 1.0 : result;
   }
 }
 
+function waitForAnimationFrames(frameCount) {
+  return new Promise(function(resolve, reject) {
+    function handleFrame() {
+      if (--frameCount <= 0) {
+        resolve();
+      } else {
+        window.requestAnimationFrame(handleFrame); // wait another frame
+      }
+    }
+    window.requestAnimationFrame(handleFrame);
+  });
+}