Bug 1312301 - Part 10: Move some utility functions into test_common.js. r?boris draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 20 Dec 2016 19:13:51 +0900
changeset 451448 317be12bc2ec3be9d94df00b8967e4e1500ad67f
parent 451447 18fa7133227a5af150f83f18085a03035d1b8164
child 451449 3f47091c33468f144a83148f0e3f378776694f45
push id39181
push userhiikezoe@mozilla-japan.org
push dateTue, 20 Dec 2016 10:30:07 +0000
reviewersboris
bugs1312301
milestone53.0a1
Bug 1312301 - Part 10: Move some utility functions into test_common.js. r?boris MozReview-Commit-ID: IUaPSEt8Vg3
testing/web-platform/tests/web-animations/interfaces/KeyframeEffect/iterationComposite.html
testing/web-platform/tests/web-animations/testcommon.js
--- a/testing/web-platform/tests/web-animations/interfaces/KeyframeEffect/iterationComposite.html
+++ b/testing/web-platform/tests/web-animations/interfaces/KeyframeEffect/iterationComposite.html
@@ -4,70 +4,16 @@
 <link rel="help" href="https://w3c.github.io/web-animations/#effect-accumulation-section">
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script src="../../testcommon.js"></script>
 <div id="log"></div>
 <script>
 'use strict';
 
-/*
- * Compare matrix string like 'matrix(1, 0, 0, 1, 100, 0)' with tolerances.
- */
-function assert_matrix_equals(actual, expected, description) {
-  var matrixRegExp = /^matrix(?:3d)*\((.+)\)/;
-  assert_regexp_match(actual, matrixRegExp,
-    'Actual value is not a matrix')
-  assert_regexp_match(expected, matrixRegExp,
-    'Expected value is not a matrix');
-
-  var actualMatrixArray =
-    actual.match(matrixRegExp)[1].split(',').map(Number);
-  var expectedMatrixArray =
-    expected.match(matrixRegExp)[1].split(',').map(Number);
-
-  assert_equals(actualMatrixArray.length, expectedMatrixArray.length,
-    'dimention of the matrix: ' + description);
-  for (var i = 0; i < actualMatrixArray.length; i++) {
-    assert_approx_equals(actualMatrixArray[i], expectedMatrixArray[i], 0.01,
-      'expecetd ' + expected + ' but got ' + actual + ": " + description);
-  }
-}
-
-// https://www.w3.org/TR/css-transforms-1/#Rotate3dDefined
-function rotate3dToMatrix3d(x, y, z, radian) {
-  var sc = Math.sin(radian / 2) * Math.cos(radian / 2);
-  var sq = Math.sin(radian / 2) * Math.sin(radian / 2);
-
-  // Normalize the vector.
-  var length = Math.sqrt(x*x + y*y + z*z);
-  x /= length;
-  y /= length;
-  z /= length;
-
-  return 'matrix3d(' + [
-    1 - 2 * (y*y + z*z) * sq,
-    2 * (x * y * sq + z * sc),
-    2 * (x * z * sq - y * sc),
-    0,
-    2 * (x * y * sq - z * sc),
-    1 - 2 * (x*x + z*z) * sq,
-    2 * (y * z * sq + x * sc),
-    0,
-    2 * (x * z * sq + y * sc),
-    2 * (y * z * sq - x * sc),
-    1 - 2 * (x*x + y*y) * sq,
-    0,
-    0,
-    0,
-    0,
-    1
-  ].join() + ')';
-}
-
 test(function(t) {
   var div = createDiv(t);
   var anim =
     div.animate({ alignContent: ['flex-start', 'flex-end'] },
                 { duration: 100 * MS_PER_SEC,
                   easing: 'linear',
                   iterations: 10,
                   iterationComposite: 'accumulate' });
--- a/testing/web-platform/tests/web-animations/testcommon.js
+++ b/testing/web-platform/tests/web-animations/testcommon.js
@@ -169,8 +169,73 @@ function waitForAnimationFramesWithDelay
       if (document.timeline.currentTime - startTime >= minDelay) {
         resolve();
       } else {
         window.requestAnimationFrame(handleFrame);
       }
     }());
   });
 }
+
+// Returns 'matrix()' or 'matrix3d()' function string generated from an array.
+function createMatrixFromArray(array) {
+  return (array.length == 16 ? 'matrix3d' : 'matrix') +
+         '(' + array.join() + ')';
+}
+
+// Returns 'matrix3d()' function string equivalent to
+// 'rotate3d(x, y, z, radian)'.
+function rotate3dToMatrix3d(x, y, z, radian) {
+  return createMatrixFromArray(rotate3dToMatrix(x, y, z, radian));
+}
+
+// Returns an array of the 4x4 matrix equivalent to 'rotate3d(x, y, z, radian)'.
+// https://www.w3.org/TR/css-transforms-1/#Rotate3dDefined
+function rotate3dToMatrix(x, y, z, radian) {
+  var sc = Math.sin(radian / 2) * Math.cos(radian / 2);
+  var sq = Math.sin(radian / 2) * Math.sin(radian / 2);
+
+  // Normalize the vector.
+  var length = Math.sqrt(x*x + y*y + z*z);
+  x /= length;
+  y /= length;
+  z /= length;
+
+  return [
+    1 - 2 * (y*y + z*z) * sq,
+    2 * (x * y * sq + z * sc),
+    2 * (x * z * sq - y * sc),
+    0,
+    2 * (x * y * sq - z * sc),
+    1 - 2 * (x*x + z*z) * sq,
+    2 * (y * z * sq + x * sc),
+    0,
+    2 * (x * z * sq + y * sc),
+    2 * (y * z * sq - x * sc),
+    1 - 2 * (x*x + y*y) * sq,
+    0,
+    0,
+    0,
+    0,
+    1
+  ];
+}
+
+// Compare matrix string like 'matrix(1, 0, 0, 1, 100, 0)' with tolerances.
+function assert_matrix_equals(actual, expected, description) {
+  var matrixRegExp = /^matrix(?:3d)*\((.+)\)/;
+  assert_regexp_match(actual, matrixRegExp,
+    'Actual value is not a matrix')
+  assert_regexp_match(expected, matrixRegExp,
+    'Expected value is not a matrix');
+
+  var actualMatrixArray =
+    actual.match(matrixRegExp)[1].split(',').map(Number);
+  var expectedMatrixArray =
+    expected.match(matrixRegExp)[1].split(',').map(Number);
+
+  assert_equals(actualMatrixArray.length, expectedMatrixArray.length,
+    'dimension of the matrix: ' + description);
+  for (var i = 0; i < actualMatrixArray.length; i++) {
+    assert_approx_equals(actualMatrixArray[i], expectedMatrixArray[i], 0.0001,
+      'expecetd ' + expected + ' but got ' + actual + ": " + description);
+  }
+}