| OLD | NEW |
| 1 /* Copyright 2015 The Chromium Authors. All rights reserved. | 1 /* Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 * | 4 * |
| 5 * Exported function: | 5 * Exported function: |
| 6 * - assertAttributeInterpolation({property, [from], [to], [fromComposite], [to
Composite], [underlying]}, [{at: fraction, is: value}]) | 6 * - assertAttributeInterpolation({property, from, to, [fromComposite], [toComp
osite], [underlying]}, [{at: fraction, is: value}]) |
| 7 * Constructs a test case for each fraction that asserts the expected val
ue | 7 * Constructs a test case for each fraction that asserts the expected val
ue |
| 8 * equals the value produced by interpolation between from and to composi
ted | 8 * equals the value produced by interpolation between from and to composi
ted |
| 9 * onto underlying by fromComposite and toComposite respectively using | 9 * onto underlying by fromComposite and toComposite respectively using |
| 10 * SMIL and Web Animations. | 10 * SMIL and Web Animations. |
| 11 * If from or to are missing then a neutral keyframe will be used and the | 11 * Set from/to to the exported neutralKeyframe object to specify neutral
keyframes. |
| 12 * composite mode will be forced to be 'add'. | |
| 13 * SMIL will only be tested with equal fromComposite and toComposite valu
es. | 12 * SMIL will only be tested with equal fromComposite and toComposite valu
es. |
| 14 */ | 13 */ |
| 15 'use strict'; | 14 'use strict'; |
| 16 (() => { | 15 (() => { |
| 17 var interpolationTests = []; | 16 var interpolationTests = []; |
| 17 var neutralKeyframe = {}; |
| 18 | 18 |
| 19 // Set to true to output rebaselined test expectations. | 19 // Set to true to output rebaselined test expectations. |
| 20 var rebaselineTests = false; | 20 var rebaselineTests = false; |
| 21 | 21 |
| 22 function isNeutralKeyframe(keyframe) { |
| 23 return keyframe === neutralKeyframe; |
| 24 } |
| 25 |
| 22 function createElement(tagName, container) { | 26 function createElement(tagName, container) { |
| 23 var element = document.createElement(tagName); | 27 var element = document.createElement(tagName); |
| 24 if (container) { | 28 if (container) { |
| 25 container.appendChild(element); | 29 container.appendChild(element); |
| 26 } | 30 } |
| 27 return element; | 31 return element; |
| 28 } | 32 } |
| 29 | 33 |
| 30 // Constructs a timing function which produces 'y' at x = 0.5 | 34 // Constructs a timing function which produces 'y' at x = 0.5 |
| 31 function createEasing(y) { | 35 function createEasing(y) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } else { | 317 } else { |
| 314 console.warn(`Unable to test SMIL from ${params.from} to ${params.to}`
); | 318 console.warn(`Unable to test SMIL from ${params.from} to ${params.to}`
); |
| 315 target.container.remove(); | 319 target.container.remove(); |
| 316 target.measure = function() {}; | 320 target.measure = function() {}; |
| 317 } | 321 } |
| 318 break; | 322 break; |
| 319 case 'Web Animations': | 323 case 'Web Animations': |
| 320 // Replace 'transform' with 'svgTransform', etc. This avoids collisions
with CSS properties or the Web Animations API (offset). | 324 // Replace 'transform' with 'svgTransform', etc. This avoids collisions
with CSS properties or the Web Animations API (offset). |
| 321 var prefixedProperty = 'svg' + params.property[0].toUpperCase() + params
.property.slice(1); | 325 var prefixedProperty = 'svg' + params.property[0].toUpperCase() + params
.property.slice(1); |
| 322 var keyframes = []; | 326 var keyframes = []; |
| 323 if ('from' in params) { | 327 if (!isNeutralKeyframe(params.from)) { |
| 324 keyframes.push({ | 328 keyframes.push({ |
| 325 offset: 0, | 329 offset: 0, |
| 326 [prefixedProperty]: params.from, | 330 [prefixedProperty]: params.from, |
| 327 composite: params.fromComposite, | 331 composite: params.fromComposite, |
| 328 }); | 332 }); |
| 329 } else { | |
| 330 console.assert(params.fromComposite === 'add'); | |
| 331 } | 333 } |
| 332 if ('to' in params) { | 334 if (!isNeutralKeyframe(params.to)) { |
| 333 keyframes.push({ | 335 keyframes.push({ |
| 334 offset: 1, | 336 offset: 1, |
| 335 [prefixedProperty]: params.to, | 337 [prefixedProperty]: params.to, |
| 336 composite: params.toComposite, | 338 composite: params.toComposite, |
| 337 }); | 339 }); |
| 338 } else { | |
| 339 console.assert(params.toComposite === 'add'); | |
| 340 } | 340 } |
| 341 target.animate(keyframes, { | 341 target.animate(keyframes, { |
| 342 fill: 'forwards', | 342 fill: 'forwards', |
| 343 duration: 1, | 343 duration: 1, |
| 344 easing: createEasing(expectation.at), | 344 easing: createEasing(expectation.at), |
| 345 delay: -0.5, | 345 delay: -0.5, |
| 346 iterations: 0.5, | 346 iterations: 0.5, |
| 347 }); | 347 }); |
| 348 break; | 348 break; |
| 349 default: | 349 default: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 365 }, `${method}: ${description} at (${expectation.at}) is [${expectation.is}
]`); | 365 }, `${method}: ${description} at (${expectation.at}) is [${expectation.is}
]`); |
| 366 }; | 366 }; |
| 367 | 367 |
| 368 return target; | 368 return target; |
| 369 } | 369 } |
| 370 | 370 |
| 371 function createTestTargets(interpolationTests, container, rebaselineContainer)
{ | 371 function createTestTargets(interpolationTests, container, rebaselineContainer)
{ |
| 372 var targets = []; | 372 var targets = []; |
| 373 for (var interpolationTest of interpolationTests) { | 373 for (var interpolationTest of interpolationTests) { |
| 374 var params = interpolationTest.params; | 374 var params = interpolationTest.params; |
| 375 params.fromComposite = 'from' in params ? (params.fromComposite || 'replac
e') : 'add'; | 375 assert_true('property' in params); |
| 376 params.toComposite = 'to' in params ? (params.toComposite || 'replace') :
'add'; | 376 assert_true('from' in params); |
| 377 assert_true('to' in params); |
| 378 params.fromComposite = isNeutralKeyframe(params.from) ? 'add' : (params.fr
omComposite || 'replace'); |
| 379 params.toComposite = isNeutralKeyframe(params.to) ? 'add' : (params.toComp
osite || 'replace'); |
| 377 var underlyingText = params.underlying ? `with underlying [${params.underl
ying}] ` : ''; | 380 var underlyingText = params.underlying ? `with underlying [${params.underl
ying}] ` : ''; |
| 378 var fromText = 'from' in params ? `${params.fromComposite} [${params.from}
]` : 'neutral'; | 381 var fromText = isNeutralKeyframe(params.from) ? 'neutral' : `${params.from
Composite} [${params.from}]`; |
| 379 var toText = 'to' in params ? `${params.toComposite} [${params.to}]` : 'ne
utral'; | 382 var toText = isNeutralKeyframe(params.to) ? 'neutral' : `${params.toCompos
ite} [${params.to}]`; |
| 380 var description = `Interpolate attribute <${params.property}> ${underlying
Text}from ${fromText} to ${toText}`; | 383 var description = `Interpolate attribute <${params.property}> ${underlying
Text}from ${fromText} to ${toText}`; |
| 381 | 384 |
| 382 if (rebaselineTests) { | 385 if (rebaselineTests) { |
| 383 var rebaseline = createElement('pre', rebaselineContainer); | 386 var rebaseline = createElement('pre', rebaselineContainer); |
| 384 | 387 |
| 385 var fromCode = 'from' in params ? ` | 388 var assertionCode = |
| 386 from: '${params.from}', | 389 `assertAttributeInterpolation({\n` + |
| 387 fromComposite: '${params.fromComposite}',` : ''; | 390 ` property: '${params.property}',\n` + |
| 391 ` underlying: '${params.underlying}',\n`; |
| 388 | 392 |
| 389 var toCode = 'to' in params ? ` | |
| 390 to: '${params.to}', | |
| 391 toComposite: '${params.toComposite}',` : ''; | |
| 392 | 393 |
| 393 rebaseline.appendChild(document.createTextNode(`\ | 394 if (isNeutralKeyframe(params.from)) { |
| 394 assertAttributeInterpolation({ | 395 assertionCode += ` from: neutralKeyframe,\n`; |
| 395 property: '${params.property}', | 396 } else { |
| 396 underlying: '${params.underlying}',${fromCode}${toCode} | 397 assertionCode += |
| 397 }, [\n`)); | 398 ` from: '${params.from}',\n` + |
| 399 ` fromComposite: '${params.fromComposite}',\n`; |
| 400 } |
| 401 |
| 402 if (isNeutralKeyframe(params.to)) { |
| 403 assertionCode += ` to: neutralKeyframe,\n`; |
| 404 } else { |
| 405 assertionCode += |
| 406 ` to: '${params.to}',\n` + |
| 407 ` fromComposite: '${params.fromComposite}',\n`; |
| 408 } |
| 409 |
| 410 assertionCode += `\n}, [\n`; |
| 411 |
| 412 rebaseline.appendChild(document.createTextNode(assertionCode)); |
| 398 var rebaselineExpectation; | 413 var rebaselineExpectation; |
| 399 rebaseline.appendChild(rebaselineExpectation = document.createTextNode('
')); | 414 rebaseline.appendChild(rebaselineExpectation = document.createTextNode('
')); |
| 400 rebaseline.appendChild(document.createTextNode(']);\n\n')); | 415 rebaseline.appendChild(document.createTextNode(']);\n\n')); |
| 401 } | 416 } |
| 402 | 417 |
| 403 for (var method of ['SMIL', 'Web Animations']) { | 418 for (var method of ['SMIL', 'Web Animations']) { |
| 404 if (method === 'SMIL' && params.fromComposite !== params.toComposite) { | 419 if (method === 'SMIL' && params.fromComposite !== params.toComposite) { |
| 405 continue; | 420 continue; |
| 406 } | 421 } |
| 407 createElement('pre', container).textContent = `${method}: ${description}
`; | 422 createElement('pre', container).textContent = `${method}: ${description}
`; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 loadScript('../../resources/testharness.js').then(() => { | 469 loadScript('../../resources/testharness.js').then(() => { |
| 455 return loadScript('../../resources/testharnessreport.js'); | 470 return loadScript('../../resources/testharnessreport.js'); |
| 456 }).then(() => { | 471 }).then(() => { |
| 457 var asyncHandle = async_test('This test uses interpolation-test.js.') | 472 var asyncHandle = async_test('This test uses interpolation-test.js.') |
| 458 requestAnimationFrame(() => { | 473 requestAnimationFrame(() => { |
| 459 runTests().then(() => asyncHandle.done()); | 474 runTests().then(() => asyncHandle.done()); |
| 460 }); | 475 }); |
| 461 }); | 476 }); |
| 462 | 477 |
| 463 window.assertAttributeInterpolation = assertAttributeInterpolation; | 478 window.assertAttributeInterpolation = assertAttributeInterpolation; |
| 479 window.neutralKeyframe = neutralKeyframe; |
| 464 })(); | 480 })(); |
| OLD | NEW |