Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: third_party/WebKit/LayoutTests/animations/svg-attribute-interpolation/resources/interpolation-test.js

Issue 1459093002: Make neutral keyframes explicit in SVG attribute interpolation test API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/animations/svg-attribute-composition/svg-z-composition.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 createElement(tagName, container) { 22 function createElement(tagName, container) {
23 var element = document.createElement(tagName); 23 var element = document.createElement(tagName);
24 if (container) { 24 if (container) {
25 container.appendChild(element); 25 container.appendChild(element);
26 } 26 }
27 return element; 27 return element;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } else { 313 } else {
314 console.warn(`Unable to test SMIL from ${params.from} to ${params.to}` ); 314 console.warn(`Unable to test SMIL from ${params.from} to ${params.to}` );
315 target.container.remove(); 315 target.container.remove();
316 target.measure = function() {}; 316 target.measure = function() {};
317 } 317 }
318 break; 318 break;
319 case 'Web Animations': 319 case 'Web Animations':
320 // Replace 'transform' with 'svgTransform', etc. This avoids collisions with CSS properties or the Web Animations API (offset). 320 // 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); 321 var prefixedProperty = 'svg' + params.property[0].toUpperCase() + params .property.slice(1);
322 var keyframes = []; 322 var keyframes = [];
323 if ('from' in params) { 323 if (params.from !== neutralKeyframe) {
suzyh_UTC10 (ex-contributor) 2015/11/19 22:48:28 if equal { A } else { B } is easier to understand
alancutter (OOO until 2018) 2015/11/20 02:21:41 There is no longer an else branch.
suzyh_UTC10 (ex-contributor) 2015/11/20 04:37:17 haha whoops, I misread the diff.
324 keyframes.push({ 324 keyframes.push({
325 offset: 0, 325 offset: 0,
326 [prefixedProperty]: params.from, 326 [prefixedProperty]: params.from,
327 composite: params.fromComposite, 327 composite: params.fromComposite,
328 }); 328 });
329 } else {
330 console.assert(params.fromComposite === 'add');
331 } 329 }
332 if ('to' in params) { 330 if (params.to !== neutralKeyframe) {
333 keyframes.push({ 331 keyframes.push({
334 offset: 1, 332 offset: 1,
335 [prefixedProperty]: params.to, 333 [prefixedProperty]: params.to,
336 composite: params.toComposite, 334 composite: params.toComposite,
337 }); 335 });
338 } else {
339 console.assert(params.toComposite === 'add');
340 } 336 }
341 target.animate(keyframes, { 337 target.animate(keyframes, {
342 fill: 'forwards', 338 fill: 'forwards',
343 duration: 1, 339 duration: 1,
344 easing: createEasing(expectation.at), 340 easing: createEasing(expectation.at),
345 delay: -0.5, 341 delay: -0.5,
346 iterations: 0.5, 342 iterations: 0.5,
347 }); 343 });
348 break; 344 break;
349 default: 345 default:
(...skipping 15 matching lines...) Expand all
365 }, `${method}: ${description} at (${expectation.at}) is [${expectation.is} ]`); 361 }, `${method}: ${description} at (${expectation.at}) is [${expectation.is} ]`);
366 }; 362 };
367 363
368 return target; 364 return target;
369 } 365 }
370 366
371 function createTestTargets(interpolationTests, container, rebaselineContainer) { 367 function createTestTargets(interpolationTests, container, rebaselineContainer) {
372 var targets = []; 368 var targets = [];
373 for (var interpolationTest of interpolationTests) { 369 for (var interpolationTest of interpolationTests) {
374 var params = interpolationTest.params; 370 var params = interpolationTest.params;
375 params.fromComposite = 'from' in params ? (params.fromComposite || 'replac e') : 'add'; 371 assert_true('property' in params);
376 params.toComposite = 'to' in params ? (params.toComposite || 'replace') : 'add'; 372 assert_true('from' in params);
373 assert_true('to' in params);
374 params.fromComposite = params.from === neutralKeyframe ? 'add' : (params.f romComposite || 'replace');
375 params.toComposite = params.to === neutralKeyframe ? 'add' : (params.toCom posite || 'replace');
377 var underlyingText = params.underlying ? `with underlying [${params.underl ying}] ` : ''; 376 var underlyingText = params.underlying ? `with underlying [${params.underl ying}] ` : '';
378 var fromText = 'from' in params ? `${params.fromComposite} [${params.from} ]` : 'neutral'; 377 var fromText = params.from === neutralKeyframe ? 'neutral' : `${params.fro mComposite} [${params.from}]`;
379 var toText = 'to' in params ? `${params.toComposite} [${params.to}]` : 'ne utral'; 378 var toText = params.to === neutralKeyframe ? 'neutral' : `${params.toCompo site} [${params.to}]`;
380 var description = `Interpolate attribute <${params.property}> ${underlying Text}from ${fromText} to ${toText}`; 379 var description = `Interpolate attribute <${params.property}> ${underlying Text}from ${fromText} to ${toText}`;
381 380
382 if (rebaselineTests) { 381 if (rebaselineTests) {
383 var rebaseline = createElement('pre', rebaselineContainer); 382 var rebaseline = createElement('pre', rebaselineContainer);
384 383
385 var fromCode = 'from' in params ? ` 384 var fromCode = params.from === neutralKeyframe ? `
385 from: neutralKeyframe,` : `
suzyh_UTC10 (ex-contributor) 2015/11/19 22:48:28 This code is quite difficult to read. Can the `...
alancutter (OOO until 2018) 2015/11/20 02:21:41 Agreed, this is hard to read. Rewrote it to avoid
386 from: '${params.from}', 386 from: '${params.from}',
387 fromComposite: '${params.fromComposite}',` : ''; 387 fromComposite: '${params.fromComposite}',`;
388 388
389 var toCode = 'to' in params ? ` 389 var toCode = params.to === neutralKeyframe ? `
suzyh_UTC10 (ex-contributor) 2015/11/19 22:48:28 Given the number of times you've had to write this
alancutter (OOO until 2018) 2015/11/20 02:21:41 Done.
390 to: neutralKeyframe,` : `
390 to: '${params.to}', 391 to: '${params.to}',
391 toComposite: '${params.toComposite}',` : ''; 392 toComposite: '${params.toComposite}',`;
392 393
393 rebaseline.appendChild(document.createTextNode(`\ 394 rebaseline.appendChild(document.createTextNode(`\
394 assertAttributeInterpolation({ 395 assertAttributeInterpolation({
395 property: '${params.property}', 396 property: '${params.property}',
396 underlying: '${params.underlying}',${fromCode}${toCode} 397 underlying: '${params.underlying}',${fromCode}${toCode}
397 }, [\n`)); 398 }, [\n`));
398 var rebaselineExpectation; 399 var rebaselineExpectation;
399 rebaseline.appendChild(rebaselineExpectation = document.createTextNode(' ')); 400 rebaseline.appendChild(rebaselineExpectation = document.createTextNode(' '));
400 rebaseline.appendChild(document.createTextNode(']);\n\n')); 401 rebaseline.appendChild(document.createTextNode(']);\n\n'));
401 } 402 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 loadScript('../../resources/testharness.js').then(() => { 455 loadScript('../../resources/testharness.js').then(() => {
455 return loadScript('../../resources/testharnessreport.js'); 456 return loadScript('../../resources/testharnessreport.js');
456 }).then(() => { 457 }).then(() => {
457 var asyncHandle = async_test('This test uses interpolation-test.js.') 458 var asyncHandle = async_test('This test uses interpolation-test.js.')
458 requestAnimationFrame(() => { 459 requestAnimationFrame(() => {
459 runTests().then(() => asyncHandle.done()); 460 runTests().then(() => asyncHandle.done());
460 }); 461 });
461 }); 462 });
462 463
463 window.assertAttributeInterpolation = assertAttributeInterpolation; 464 window.assertAttributeInterpolation = assertAttributeInterpolation;
465 window.neutralKeyframe = neutralKeyframe;
464 })(); 466 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/animations/svg-attribute-composition/svg-z-composition.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698