Bug 1406381 - Tidy up simple-iteration-progress.html and current-iteration.html somewhat; r?hiro draft
authorBrian Birtles <birtles@gmail.com>
Fri, 13 Oct 2017 10:45:58 +0900
changeset 679901 11bbae8457babc88058f5112db33b9b7ad266511
parent 679629 25aad10380b10b6efa50c2b4d97245f078d870a0
child 679902 901380dc8da73259346a133f160ab6f1614477fe
child 679913 4df775e4bfed31b4df7403f7a592a213cab999a7
push id84337
push userbmo:bbirtles@mozilla.com
push dateFri, 13 Oct 2017 06:56:36 +0000
reviewershiro
bugs1406381
milestone58.0a1
Bug 1406381 - Tidy up simple-iteration-progress.html and current-iteration.html somewhat; r?hiro This is in preparation for further changes to these files later in this patch series. In particular this patch: * Moves some code to more modern Javascript that should be easier to read and maintain * Makes the tests more strict about when active/after values are specified - If the timing parameters mean there is no active phase, the test should not specify a value to test for that phase. If there *is* an active phase, the test must provide a value to test (if it does not the test will fails when it compares against the undefined value). - Likewise for the after phase This should make it a little easier to incorporate testing the playbackRate. MozReview-Commit-ID: 17vihK5RSbu
testing/web-platform/tests/web-animations/timing-model/animation-effects/current-iteration.html
testing/web-platform/tests/web-animations/timing-model/animation-effects/simple-iteration-progress.html
--- a/testing/web-platform/tests/web-animations/timing-model/animation-effects/current-iteration.html
+++ b/testing/web-platform/tests/web-animations/timing-model/animation-effects/current-iteration.html
@@ -6,36 +6,50 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="../../testcommon.js"></script>
 <body>
 <div id="log"></div>
 <script>
 'use strict';
 
 function runTests(tests, description) {
-  tests.forEach(function(currentTest) {
-    var testParams = '';
-    for (var attr in currentTest.input) {
-      testParams += ' ' + attr + ':' + currentTest.input[attr];
-    }
-    test(function(t) {
-      var div = createDiv(t);
-      var anim = div.animate({ opacity: [ 0, 1 ] }, currentTest.input);
+  for (const currentTest of tests) {
+    const testParams = Object.entries(currentTest.input)
+                             .map(([attr, value]) => `${attr}:${value}`)
+                             .join(' ');
+
+    test(t => {
+      const div = createDiv(t);
+      const anim = div.animate({}, currentTest.input);
+
+      // Before phase
       assert_equals(anim.effect.getComputedTiming().currentIteration,
                     currentTest.before);
-      anim.currentTime = currentTest.input.delay || 0;
-      assert_equals(anim.effect.getComputedTiming().currentIteration,
-                    currentTest.active);
-      if (typeof currentTest.after !== 'undefined') {
+
+      // Active phase
+      if (anim.effect.getComputedTiming().activeDuration > 0) {
+        anim.currentTime = currentTest.input.delay || 0;
+        assert_equals(anim.effect.getComputedTiming().currentIteration,
+                      currentTest.active);
+      } else if (currentTest.active !== undefined) {
+        assert_false('Test specifies an active phase iteration to check but the'
+                     + ' animation has a zero duration');
+      }
+
+      // After phase
+      if (anim.effect.getComputedTiming().activeDuration !== Infinity) {
         anim.finish();
         assert_equals(anim.effect.getComputedTiming().currentIteration,
                       currentTest.after);
+      } else if (currentTest.after !== undefined) {
+        assert_false('Test specifies an after phase iteration to check but the'
+                     + ' animation has an infinite duration');
       }
-    }, description + ':' + testParams);
-  });
+    }, `${description}: ${testParams}`);
+  }
 }
 
 async_test(function(t) {
   var div = createDiv(t);
   var anim = div.animate({ opacity: [ 0, 1 ] }, { delay: 1 });
   assert_equals(anim.effect.getComputedTiming().currentIteration, null);
   anim.finished.then(t.step_func(function() {
     assert_equals(anim.effect.getComputedTiming().currentIteration, null);
@@ -53,105 +67,96 @@ async_test(function(t) {
 runTests([
   {
     input:    { iterations: 0,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 0,
                 duration: Infinity,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 2,
-    active: 2,
     after: 2
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
                 fill: 'both' },
     before: 2,
-    active: 2,
     after: 2
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 2.5,
                 duration: Infinity,
                 delay: 1,
                 fill: 'both' },
     before: 2,
-    active: 2,
     after: 2
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 3,
-    active: 3,
     after: 3
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,
                 fill: 'both' },
     before: 3,
-    active: 3,
     after: 3
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 3,
                 duration: Infinity,
                 delay: 1,
                 fill: 'both' },
     before: 3,
-    active: 3,
     after: 3
   }
 ], 'Test zero iterations');
 
 
 // --------------------------------------------------------------------
 //
 // Tests where the iteration count is an integer
@@ -161,17 +166,16 @@ runTests([
 runTests([
   {
     input:    { iterations: 3,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 2,
     after: 2
   },
 
   {
     input:    { iterations: 3,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
@@ -193,17 +197,16 @@ runTests([
 
   {
     input:    { iterations: 3,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 2,
-    active: 5,
     after: 5
   },
 
   {
     input:    { iterations: 3,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
@@ -225,17 +228,16 @@ runTests([
 
   {
     input:    { iterations: 3,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 3,
-    active: 5,
     after: 5
   },
 
   {
     input:    { iterations: 3,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,
@@ -266,17 +268,16 @@ runTests([
 runTests([
   {
     input:    { iterations: 3.5,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 3,
     after: 3
   },
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
@@ -298,17 +299,16 @@ runTests([
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 2,
-    active: 5,
     after: 5
   },
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
@@ -330,17 +330,16 @@ runTests([
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 3,
-    active: 6,
     after: 6
   },
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,
@@ -371,17 +370,16 @@ runTests([
 runTests([
   {
     input:    { iterations: Infinity,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: Infinity,
     after: Infinity
   },
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
@@ -402,17 +400,16 @@ runTests([
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 2,
-    active: Infinity,
     after: Infinity
   },
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
@@ -433,17 +430,16 @@ runTests([
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 3,
-    active: Infinity,
     after: Infinity
   },
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,
--- a/testing/web-platform/tests/web-animations/timing-model/animation-effects/simple-iteration-progress.html
+++ b/testing/web-platform/tests/web-animations/timing-model/animation-effects/simple-iteration-progress.html
@@ -7,36 +7,50 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="../../testcommon.js"></script>
 <body>
 <div id="log"></div>
 <script>
 'use strict';
 
 function runTests(tests, description) {
-  tests.forEach(function(currentTest) {
-    var testParams = '';
-    for (var attr in currentTest.input) {
-      testParams += ' ' + attr + ':' + currentTest.input[attr];
-    }
-    test(function(t) {
-      var div = createDiv(t);
-      var anim = div.animate({ opacity: [ 0, 1 ] }, currentTest.input);
+  for (const currentTest of tests) {
+    const testParams = Object.entries(currentTest.input)
+                             .map(([attr, value]) => `${attr}:${value}`)
+                             .join(' ');
+
+    test(t => {
+      const div = createDiv(t);
+      const anim = div.animate({}, currentTest.input);
+
+      // Before phase
       assert_equals(anim.effect.getComputedTiming().progress,
                     currentTest.before);
-      anim.currentTime = currentTest.input.delay || 0;
-      assert_equals(anim.effect.getComputedTiming().progress,
-                    currentTest.active);
-      if (typeof currentTest.after !== 'undefined') {
+
+      // Active phase
+      if (anim.effect.getComputedTiming().activeDuration > 0) {
+        anim.currentTime = currentTest.input.delay || 0;
+        assert_equals(anim.effect.getComputedTiming().progress,
+                      currentTest.active);
+      } else if (currentTest.active !== undefined) {
+        assert_false('Test specifies an active progress to check but the'
+                     + ' animation has a zero duration');
+      }
+
+      // After phase
+      if (anim.effect.getComputedTiming().activeDuration !== Infinity) {
         anim.finish();
         assert_equals(anim.effect.getComputedTiming().progress,
                       currentTest.after);
+      } else if (currentTest.after !== undefined) {
+        assert_false('Test specifies an after phase progress to check but the'
+                     + ' animation has an infinite duration');
       }
-    }, description + ':' + testParams);
-  });
+    }, `${description}: ${testParams}`);
+  }
 }
 
 
 // --------------------------------------------------------------------
 //
 // Zero iteration duration tests
 //
 // --------------------------------------------------------------------
@@ -44,105 +58,96 @@ function runTests(tests, description) {
 runTests([
   {
     input:    { iterations: 0,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 0,
                 duration: Infinity,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0.5,
-    active: 0.5,
     after: 0.5
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
                 fill: 'both' },
     before: 0.5,
-    active: 0.5,
     after: 0.5
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 2.5,
                 duration: Infinity,
                 delay: 1,
                 fill: 'both' },
     before: 0.5,
-    active: 0.5,
     after: 0.5
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   },
 
   {
     input:    { iterations: 0,
                 iterationStart: 3,
                 duration: Infinity,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0,
     after: 0
   }
 ], 'Test zero iterations');
 
 
 // --------------------------------------------------------------------
 //
 // Tests where the iteration count is an integer
@@ -152,17 +157,16 @@ runTests([
 runTests([
   {
     input:    { iterations: 3,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 1,
     after: 1
   },
 
   {
     input:    { iterations: 3,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
@@ -184,17 +188,16 @@ runTests([
 
   {
     input:    { iterations: 3,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0.5,
-    active: 0.5,
     after: 0.5
   },
 
   {
     input:    { iterations: 3,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
@@ -216,17 +219,16 @@ runTests([
 
   {
     input:    { iterations: 3,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 1,
     after: 1
   },
 
   {
     input:    { iterations: 3,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,
@@ -257,17 +259,16 @@ runTests([
 runTests([
   {
     input:    { iterations: 3.5,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0.5,
     after: 0.5
   },
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
@@ -289,17 +290,16 @@ runTests([
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0.5,
-    active: 1,
     after: 1
   },
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
@@ -321,17 +321,16 @@ runTests([
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 0.5,
     after: 0.5
   },
 
   {
     input:    { iterations: 3.5,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,
@@ -362,17 +361,16 @@ runTests([
 runTests([
   {
     input:    { iterations: Infinity,
                 iterationStart: 0,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 1,
     after: 1
   },
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 0,
                 duration: 100,
                 delay: 1,
@@ -393,17 +391,16 @@ runTests([
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 2.5,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0.5,
-    active: 0.5,
     after: 0.5
   },
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 2.5,
                 duration: 100,
                 delay: 1,
@@ -424,17 +421,16 @@ runTests([
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 3,
                 duration: 0,
                 delay: 1,
                 fill: 'both' },
     before: 0,
-    active: 1,
     after: 1
   },
 
   {
     input:    { iterations: Infinity,
                 iterationStart: 3,
                 duration: 100,
                 delay: 1,