Bug 1207734 - Part 9.f. (testing) Implement testAnimationSampleRotate3d. draft
authorcku <cku@mozilla.com>
Mon, 15 Jan 2018 14:18:59 +0800
changeset 720545 2da22266d232344b5574d5b3b87ba498138956ac
parent 720544 abc02b77db587a9b9086a23b003bd4ead92da4fd
child 720546 721c6cb15fa8a427a7207c6b002e8791d050bda7
push id95571
push userbmo:cku@mozilla.com
push dateMon, 15 Jan 2018 18:35:41 +0000
bugs1207734
milestone59.0a1
Bug 1207734 - Part 9.f. (testing) Implement testAnimationSampleRotate3d. testAnimationSamples is not enough for comparing the computed value of rotate property so we need this new function. MozReview-Commit-ID: J77e89BbjLx
testing/web-platform/tests/web-animations/animation-model/animation-types/property-list.js
testing/web-platform/tests/web-animations/testcommon.js
--- a/testing/web-platform/tests/web-animations/animation-model/animation-types/property-list.js
+++ b/testing/web-platform/tests/web-animations/animation-model/animation-types/property-list.js
@@ -1514,16 +1514,28 @@ function testAnimationSampleMatrices(ani
     const actual = getComputedStyle(target)[idlName];
     const expected = createMatrixFromArray(testSample.expected);
     assert_matrix_equals(actual, expected,
                          `The value should be ${expected} at`
                          + ` ${testSample.time}ms but got ${actual}`);
   }
 }
 
+function testAnimationSampleRotate3d(animation, idlName, testSamples) {
+  const target = animation.effect.target;
+  for (const testSample of testSamples) {
+    animation.currentTime = testSample.time;
+    const actual = getComputedStyle(target)[idlName];
+    const expected = testSample.expected;
+    assert_rotate3d_equals(actual, expected,
+                         `The value should be ${expected} at`
+                         + ` ${testSample.time}ms but got ${actual}`);
+  }
+}
+
 function createTestElement(t, setup) {
   return setup ? setup(t) : createElement(t);
 }
 
 function isSupported(property) {
   const testKeyframe = new TestKeyframe(propertyToIDL(property));
   try {
     // Since TestKeyframe returns 'undefined' for |property|,
--- a/testing/web-platform/tests/web-animations/testcommon.js
+++ b/testing/web-platform/tests/web-animations/testcommon.js
@@ -249,8 +249,30 @@ function assert_matrix_equals(actual, ex
 
   assert_equals(actualMatrixArray.length, expectedMatrixArray.length,
     `dimension of the matrix: ${description}`);
   for (let i = 0; i < actualMatrixArray.length; i++) {
     assert_approx_equals(actualMatrixArray[i], expectedMatrixArray[i], 0.0001,
       `expected ${expected} but got ${actual}: ${description}`);
   }
 }
+
+// Compare rotate3d vector like '0 1 0 45deg' with tolerances.
+function assert_rotate3d_equals(actual, expected, description) {
+  const rotationRegExp =/^((([+-]?\d+(\.+\d+)?\s){3})?\d+(\.+\d+)?)deg/;
+
+  assert_regexp_match(actual, rotationRegExp,
+    'Actual value is not a rotate3d vector')
+  assert_regexp_match(expected, rotationRegExp,
+    'Expected value is not a rotate3d vector');
+
+  const actualRotationVector =
+    actual.match(rotationRegExp)[1].split(' ').map(Number);
+  const expectedRotationVector =
+    expected.match(rotationRegExp)[1].split(' ').map(Number);
+
+  assert_equals(actualRotationVector.length, expectedRotationVector.length,
+    `dimension of the matrix: ${description}`);
+  for (let i = 0; i < actualRotationVector.length; i++) {
+    assert_approx_equals(actualRotationVector[i], expectedRotationVector[i], 0.0001,
+      `expected ${expected} but got ${actual}: ${description}`);
+  }
+}
\ No newline at end of file