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
--- 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