Commit 5a94fda8 authored by alancutter's avatar alancutter Committed by Commit bot

Make neutral keyframes explicit in SVG attribute interpolation test API

This patch changes the way neutral keyframes are specified in
SVG attribute interpolation tests to be more explicit using an exported
neutralKeyframe object.

BUG=530436

Review URL: https://codereview.chromium.org/1459093002

Cr-Commit-Position: refs/heads/master@{#361063}
parent c9930753
...@@ -46,6 +46,7 @@ assertAttributeInterpolation({ ...@@ -46,6 +46,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'amplitude', property: 'amplitude',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'azimuth', property: 'azimuth',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'bias', property: 'bias',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'diffuseConstant', property: 'diffuseConstant',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'divisor', property: 'divisor',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'elevation', property: 'elevation',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -46,6 +46,7 @@ assertAttributeInterpolation({ ...@@ -46,6 +46,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'exponent', property: 'exponent',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -46,6 +46,7 @@ assertAttributeInterpolation({ ...@@ -46,6 +46,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'intercept', property: 'intercept',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'k1', property: 'k1',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
...@@ -90,6 +91,7 @@ assertAttributeInterpolation({ ...@@ -90,6 +91,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'k2', property: 'k2',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
...@@ -136,6 +138,7 @@ assertAttributeInterpolation({ ...@@ -136,6 +138,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'k3', property: 'k3',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
...@@ -182,6 +185,7 @@ assertAttributeInterpolation({ ...@@ -182,6 +185,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'k4', property: 'k4',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -48,6 +48,7 @@ assertAttributeInterpolation({ ...@@ -48,6 +48,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'limitingConeAngle', property: 'limitingConeAngle',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -28,6 +28,7 @@ assertAttributeInterpolation({ ...@@ -28,6 +28,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'mode', property: 'mode',
underlying: 'multiply' underlying: 'multiply'
from: neutralKeyframe,
to: 'lighten', to: 'lighten',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -60,6 +60,7 @@ assertAttributeInterpolation({ ...@@ -60,6 +60,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'numOctaves', property: 'numOctaves',
underlying: '2', underlying: '2',
from: neutralKeyframe,
to: '7', to: '7',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'offset', property: 'offset',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -59,6 +59,7 @@ assertAttributeInterpolation({ ...@@ -59,6 +59,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'orient', property: 'orient',
underlying: '20', underlying: '20',
from: neutralKeyframe,
to: '180', to: '180',
toComposite: 'replace' toComposite: 'replace'
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'pathLength', property: 'pathLength',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -108,6 +108,7 @@ assertAttributeInterpolation({ ...@@ -108,6 +108,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'points', property: 'points',
underlying: '10 10, 20 20', underlying: '10 10, 20 20',
from: neutralKeyframe,
to: '90 90, -10 -10', to: '90 90, -10 -10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
...@@ -122,6 +123,7 @@ assertAttributeInterpolation({ ...@@ -122,6 +123,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'points', property: 'points',
underlying: '10 10, 20 20', underlying: '10 10, 20 20',
from: neutralKeyframe,
to: '90 90, -10 -10, 50 50', to: '90 90, -10 -10, 50 50',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'pointsAtX', property: 'pointsAtX',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
...@@ -90,6 +91,7 @@ assertAttributeInterpolation({ ...@@ -90,6 +91,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'pointsAtY', property: 'pointsAtY',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
...@@ -136,6 +138,7 @@ assertAttributeInterpolation({ ...@@ -136,6 +138,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'pointsAtZ', property: 'pointsAtZ',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -48,6 +48,7 @@ assertAttributeInterpolation({ ...@@ -48,6 +48,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'scale', property: 'scale',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -48,6 +48,7 @@ assertAttributeInterpolation({ ...@@ -48,6 +48,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'seed', property: 'seed',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -46,6 +46,7 @@ assertAttributeInterpolation({ ...@@ -46,6 +46,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'slope', property: 'slope',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'specularConstant', property: 'specularConstant',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'specularExponent', property: 'specularExponent',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -44,6 +44,7 @@ assertAttributeInterpolation({ ...@@ -44,6 +44,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'surfaceScale', property: 'surfaceScale',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -48,6 +48,7 @@ assertAttributeInterpolation({ ...@@ -48,6 +48,7 @@ assertAttributeInterpolation({
assertAttributeInterpolation({ assertAttributeInterpolation({
property: 'z', property: 'z',
underlying: '5', underlying: '5',
from: neutralKeyframe,
to: '10', to: '10',
toComposite: 'replace', toComposite: 'replace',
}, [ }, [
......
...@@ -3,22 +3,26 @@ ...@@ -3,22 +3,26 @@
* found in the LICENSE file. * found in the LICENSE file.
* *
* Exported function: * Exported function:
* - assertAttributeInterpolation({property, [from], [to], [fromComposite], [toComposite], [underlying]}, [{at: fraction, is: value}]) * - assertAttributeInterpolation({property, from, to, [fromComposite], [toComposite], [underlying]}, [{at: fraction, is: value}])
* Constructs a test case for each fraction that asserts the expected value * Constructs a test case for each fraction that asserts the expected value
* equals the value produced by interpolation between from and to composited * equals the value produced by interpolation between from and to composited
* onto underlying by fromComposite and toComposite respectively using * onto underlying by fromComposite and toComposite respectively using
* SMIL and Web Animations. * SMIL and Web Animations.
* If from or to are missing then a neutral keyframe will be used and the * Set from/to to the exported neutralKeyframe object to specify neutral keyframes.
* composite mode will be forced to be 'add'.
* SMIL will only be tested with equal fromComposite and toComposite values. * SMIL will only be tested with equal fromComposite and toComposite values.
*/ */
'use strict'; 'use strict';
(() => { (() => {
var interpolationTests = []; var interpolationTests = [];
var neutralKeyframe = {};
// Set to true to output rebaselined test expectations. // Set to true to output rebaselined test expectations.
var rebaselineTests = false; var rebaselineTests = false;
function isNeutralKeyframe(keyframe) {
return keyframe === neutralKeyframe;
}
function createElement(tagName, container) { function createElement(tagName, container) {
var element = document.createElement(tagName); var element = document.createElement(tagName);
if (container) { if (container) {
...@@ -320,23 +324,19 @@ ...@@ -320,23 +324,19 @@
// Replace 'transform' with 'svgTransform', etc. This avoids collisions with CSS properties or the Web Animations API (offset). // Replace 'transform' with 'svgTransform', etc. This avoids collisions with CSS properties or the Web Animations API (offset).
var prefixedProperty = 'svg' + params.property[0].toUpperCase() + params.property.slice(1); var prefixedProperty = 'svg' + params.property[0].toUpperCase() + params.property.slice(1);
var keyframes = []; var keyframes = [];
if ('from' in params) { if (!isNeutralKeyframe(params.from)) {
keyframes.push({ keyframes.push({
offset: 0, offset: 0,
[prefixedProperty]: params.from, [prefixedProperty]: params.from,
composite: params.fromComposite, composite: params.fromComposite,
}); });
} else {
console.assert(params.fromComposite === 'add');
} }
if ('to' in params) { if (!isNeutralKeyframe(params.to)) {
keyframes.push({ keyframes.push({
offset: 1, offset: 1,
[prefixedProperty]: params.to, [prefixedProperty]: params.to,
composite: params.toComposite, composite: params.toComposite,
}); });
} else {
console.assert(params.toComposite === 'add');
} }
target.animate(keyframes, { target.animate(keyframes, {
fill: 'forwards', fill: 'forwards',
...@@ -372,29 +372,44 @@ ...@@ -372,29 +372,44 @@
var targets = []; var targets = [];
for (var interpolationTest of interpolationTests) { for (var interpolationTest of interpolationTests) {
var params = interpolationTest.params; var params = interpolationTest.params;
params.fromComposite = 'from' in params ? (params.fromComposite || 'replace') : 'add'; assert_true('property' in params);
params.toComposite = 'to' in params ? (params.toComposite || 'replace') : 'add'; assert_true('from' in params);
assert_true('to' in params);
params.fromComposite = isNeutralKeyframe(params.from) ? 'add' : (params.fromComposite || 'replace');
params.toComposite = isNeutralKeyframe(params.to) ? 'add' : (params.toComposite || 'replace');
var underlyingText = params.underlying ? `with underlying [${params.underlying}] ` : ''; var underlyingText = params.underlying ? `with underlying [${params.underlying}] ` : '';
var fromText = 'from' in params ? `${params.fromComposite} [${params.from}]` : 'neutral'; var fromText = isNeutralKeyframe(params.from) ? 'neutral' : `${params.fromComposite} [${params.from}]`;
var toText = 'to' in params ? `${params.toComposite} [${params.to}]` : 'neutral'; var toText = isNeutralKeyframe(params.to) ? 'neutral' : `${params.toComposite} [${params.to}]`;
var description = `Interpolate attribute <${params.property}> ${underlyingText}from ${fromText} to ${toText}`; var description = `Interpolate attribute <${params.property}> ${underlyingText}from ${fromText} to ${toText}`;
if (rebaselineTests) { if (rebaselineTests) {
var rebaseline = createElement('pre', rebaselineContainer); var rebaseline = createElement('pre', rebaselineContainer);
var fromCode = 'from' in params ? ` var assertionCode =
from: '${params.from}', `assertAttributeInterpolation({\n` +
fromComposite: '${params.fromComposite}',` : ''; ` property: '${params.property}',\n` +
` underlying: '${params.underlying}',\n`;
if (isNeutralKeyframe(params.from)) {
assertionCode += ` from: neutralKeyframe,\n`;
} else {
assertionCode +=
` from: '${params.from}',\n` +
` fromComposite: '${params.fromComposite}',\n`;
}
if (isNeutralKeyframe(params.to)) {
assertionCode += ` to: neutralKeyframe,\n`;
} else {
assertionCode +=
` to: '${params.to}',\n` +
` fromComposite: '${params.fromComposite}',\n`;
}
var toCode = 'to' in params ? ` assertionCode += `\n}, [\n`;
to: '${params.to}',
toComposite: '${params.toComposite}',` : '';
rebaseline.appendChild(document.createTextNode(`\ rebaseline.appendChild(document.createTextNode(assertionCode));
assertAttributeInterpolation({
property: '${params.property}',
underlying: '${params.underlying}',${fromCode}${toCode}
}, [\n`));
var rebaselineExpectation; var rebaselineExpectation;
rebaseline.appendChild(rebaselineExpectation = document.createTextNode('')); rebaseline.appendChild(rebaselineExpectation = document.createTextNode(''));
rebaseline.appendChild(document.createTextNode(']);\n\n')); rebaseline.appendChild(document.createTextNode(']);\n\n'));
...@@ -461,4 +476,5 @@ assertAttributeInterpolation({ ...@@ -461,4 +476,5 @@ assertAttributeInterpolation({
}); });
window.assertAttributeInterpolation = assertAttributeInterpolation; window.assertAttributeInterpolation = assertAttributeInterpolation;
window.neutralKeyframe = neutralKeyframe;
})(); })();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment