Bug 1406381 - Factor out common code from simple-iteration-progress.html and current-iteration.html; r?hiro draft
authorBrian Birtles <birtles@gmail.com>
Fri, 13 Oct 2017 10:53:10 +0900
changeset 679913 4df775e4bfed31b4df7403f7a592a213cab999a7
parent 679901 11bbae8457babc88058f5112db33b9b7ad266511
child 679914 0ad7e986d9c433aa37f3923ed63b1c321bdb7020
child 679929 acf69a25294f35b73d67aa8bad0895d4181858d6
push id84340
push userbmo:bbirtles@mozilla.com
push dateFri, 13 Oct 2017 07:04:42 +0000
reviewershiro
bugs1406381
milestone58.0a1
Bug 1406381 - Factor out common code from simple-iteration-progress.html and current-iteration.html; r?hiro This will become all the more necessary when we extend these definitions to work with negative playback rates. MozReview-Commit-ID: ITHEqjprWUy
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/web-animations/resources/effect-tests.js
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/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -309380,16 +309380,21 @@
      {}
     ]
    ],
    "web-animations/resources/easing-tests.js": [
     [
      {}
     ]
    ],
+   "web-animations/resources/effect-tests.js": [
+    [
+     {}
+    ]
+   ],
    "web-animations/resources/keyframe-utils.js": [
     [
      {}
     ]
    ],
    "web-animations/resources/xhr-doc.py": [
     [
      {}
@@ -631298,16 +631303,20 @@
   "web-animations/interfaces/KeyframeEffectReadOnly/copy-constructor.html": [
    "8ef986f13e7fe7ffeb7403f647b4169ac0d6a138",
    "testharness"
   ],
   "web-animations/resources/easing-tests.js": [
    "c255d606d00296b4c6957435773a20a9d8d0bd0b",
    "support"
   ],
+  "web-animations/resources/effect-tests.js": [
+   "2c52f4dd0562683459ed6b4df24c07b5401cb88e",
+   "support"
+  ],
   "web-animations/resources/keyframe-utils.js": [
    "a9c574e206087c02834e9836ea7625d843427a17",
    "support"
   ],
   "web-animations/resources/xhr-doc.py": [
    "de68c45fc1d38a49946f9046f34031e9278a1531",
    "support"
   ],
@@ -631315,29 +631324,29 @@
    "d057ad66c4561ef32f83770e4948f2019da89d48",
    "support"
   ],
   "web-animations/timing-model/animation-effects/active-time.html": [
    "42eb1a23e89ae60ccd0a3664a9a583df1eb30d49",
    "testharness"
   ],
   "web-animations/timing-model/animation-effects/current-iteration.html": [
-   "b08a35ae832ce33da7fe7fee22e589a6b85a6353",
+   "fdfc86ef16ff5fbb2df0d174f9be3e7fc6388c03",
    "testharness"
   ],
   "web-animations/timing-model/animation-effects/local-time.html": [
    "4b24cf2374a690395398f8caed9d340667dd0a9d",
    "testharness"
   ],
   "web-animations/timing-model/animation-effects/phases-and-states.html": [
    "ce3652c8a6fdd8a6019fd665bca28ed725bacd71",
    "testharness"
   ],
   "web-animations/timing-model/animation-effects/simple-iteration-progress.html": [
-   "53a4a6c6c6d07e00fecc50e5de831862e7bf4b2e",
+   "e3326f365ca153bb193166826f767149446975a3",
    "testharness"
   ],
   "web-animations/timing-model/animations/canceling-an-animation.html": [
    "079bc0e0f7ea60b94999ed1b4f92c1aa2fc2c7bb",
    "testharness"
   ],
   "web-animations/timing-model/animations/current-time.html": [
    "b1ea8e490cbfb69fd71b91a90e7e2d9ce99f42d3",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/web-animations/resources/effect-tests.js
@@ -0,0 +1,44 @@
+// Common utility methods for testing animation effects
+
+// Tests the |property| member of |animation's| target effect's computed timing
+// at the various points indicated by |values|.
+//
+// |values| has the format:
+//
+//   {
+//     before, // value to test during before phase
+//     active, // value to test during at the very beginning of the active phase
+//             // or undefined if the active duration is zero,
+//     after,  // value to test during the after phase or undefined if the
+//             // active duration is infinite
+//   }
+//
+function assert_computed_timing_for_each_phase(animation, property, values) {
+  const effect = animation.effect;
+
+  // Before phase
+  assert_equals(effect.getComputedTiming()[property], values.before,
+                `Value of ${property} in the before phase`);
+
+  // Active phase
+  if (effect.getComputedTiming().activeDuration > 0) {
+    animation.currentTime = effect.getComputedTiming().delay;
+    assert_equals(effect.getComputedTiming()[property], values.active,
+                  `Value of ${property} in the active phase`);
+  } else {
+    assert_equals(values.active, undefined,
+                  'Test specifies a value to check during the active phase but'
+                  + ' the animation has a zero duration');
+  }
+
+  // After phase
+  if (effect.getComputedTiming().activeDuration !== Infinity) {
+    animation.finish();
+    assert_equals(effect.getComputedTiming()[property], values.after,
+                  `Value of ${property} in the after phase`);
+  } else {
+    assert_equals(values.after, undefined,
+                  'Test specifies a value to check during the after phase but'
+                  + ' the animation has an infinite duration');
+  }
+}
--- 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
@@ -1,53 +1,38 @@
 <!DOCTYPE html>
 <meta charset=utf-8>
 <title>Current iteration tests</title>
 <link rel="help" href="https://w3c.github.io/web-animations/#current-iteration">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="../../testcommon.js"></script>
+<script src="../../resources/effect-tests.js"></script>
 <body>
 <div id="log"></div>
 <script>
 'use strict';
 
 function runTests(tests, description) {
   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);
-
-      // 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');
-      }
+      assert_computed_timing_for_each_phase(
+        anim,
+        'currentIteration',
+        { before: currentTest.before,
+          active: currentTest.active,
+          after: currentTest.after },
+      );
     }, `${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);
--- 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
@@ -1,54 +1,39 @@
 <!DOCTYPE html>
 <meta charset=utf-8>
 <title>Simple iteration progress tests</title>
 <link rel="help"
       href="https://w3c.github.io/web-animations/#simple-iteration-progress">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="../../testcommon.js"></script>
+<script src="../../resources/effect-tests.js"></script>
 <body>
 <div id="log"></div>
 <script>
 'use strict';
 
 function runTests(tests, description) {
   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);
-
-      // 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');
-      }
+      assert_computed_timing_for_each_phase(
+        anim,
+        'progress',
+        { before: currentTest.before,
+          active: currentTest.active,
+          after: currentTest.after },
+      );
     }, `${description}: ${testParams}`);
   }
 }
 
 
 // --------------------------------------------------------------------
 //
 // Zero iteration duration tests