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

Side by Side Diff: LayoutTests/animations/interpolation/resources/interpolation-test.js

Issue 1262283002: Fix 50% flip handling of CSS Animations using CSS wide keywords (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 5 years, 4 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved. 2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 var cssAnimationsData = { 51 var cssAnimationsData = {
52 sharedStyle: null, 52 sharedStyle: null,
53 nextID: 0, 53 nextID: 0,
54 }; 54 };
55 var webAnimationsEnabled = typeof Element.prototype.animate === 'function'; 55 var webAnimationsEnabled = typeof Element.prototype.animate === 'function';
56 var expectNoInterpolation = {}; 56 var expectNoInterpolation = {};
57 var afterTestHook = function() {}; 57 var afterTestHook = function() {};
58 58
59 var cssAnimationsInterpolation = { 59 var cssAnimationsInterpolation = {
60 name: 'CSS Animations', 60 name: 'CSS Animations',
61 supports: function() {return true;}, 61 supportsProperty: function() {return true;},
62 supportsValue: function() {return true;},
62 setup: function() {}, 63 setup: function() {},
63 nonInterpolationExpectations: function(from, to) { 64 nonInterpolationExpectations: function(from, to) {
64 return expectFlip(from, to, 0.5); 65 return expectFlip(from, to, 0.5);
65 }, 66 },
66 interpolate: function(property, from, to, at, target) { 67 interpolate: function(property, from, to, at, target) {
67 var id = cssAnimationsData.nextID++; 68 var id = cssAnimationsData.nextID++;
68 if (!cssAnimationsData.sharedStyle) { 69 if (!cssAnimationsData.sharedStyle) {
69 cssAnimationsData.sharedStyle = createElement(document.body, 'style'); 70 cssAnimationsData.sharedStyle = createElement(document.body, 'style');
70 } 71 }
71 cssAnimationsData.sharedStyle.textContent += '' + 72 cssAnimationsData.sharedStyle.textContent += '' +
72 '@keyframes animation' + id + ' {' + 73 '@keyframes animation' + id + ' {' +
73 'from {' + property + ': ' + from + ';}' + 74 'from {' + property + ': ' + from + ';}' +
74 'to {' + property + ': ' + to + ';}' + 75 'to {' + property + ': ' + to + ';}' +
75 '}'; 76 '}';
76 target.style.animationName = 'animation' + id; 77 target.style.animationName = 'animation' + id;
77 target.style.animationDuration = '2e10s'; 78 target.style.animationDuration = '2e10s';
78 target.style.animationDelay = '-1e10s'; 79 target.style.animationDelay = '-1e10s';
79 target.style.animationTimingFunction = createEasing(at); 80 target.style.animationTimingFunction = createEasing(at);
80 }, 81 },
81 }; 82 };
82 83
83 var cssTransitionsInterpolation = { 84 var cssTransitionsInterpolation = {
84 name: 'CSS Transitions', 85 name: 'CSS Transitions',
85 supports: function() {return true;}, 86 supportsProperty: function() {return true;},
87 supportsValue: function() {return true;},
86 setup: function(property, from, target) { 88 setup: function(property, from, target) {
87 target.style[property] = from; 89 target.style[property] = from;
88 }, 90 },
89 nonInterpolationExpectations: function(from, to) { 91 nonInterpolationExpectations: function(from, to) {
90 return expectFlip(from, to, -Infinity); 92 return expectFlip(from, to, -Infinity);
91 }, 93 },
92 interpolate: function(property, from, to, at, target) { 94 interpolate: function(property, from, to, at, target) {
93 target.style.transitionDuration = '2e10s'; 95 target.style.transitionDuration = '2e10s';
94 target.style.transitionDelay = '-1e10s'; 96 target.style.transitionDelay = '-1e10s';
95 target.style.transitionTimingFunction = createEasing(at); 97 target.style.transitionTimingFunction = createEasing(at);
96 target.style.transitionProperty = property; 98 target.style.transitionProperty = property;
97 target.style[property] = to; 99 target.style[property] = to;
98 }, 100 },
99 }; 101 };
100 102
101 var webAnimationsInterpolation = { 103 var webAnimationsInterpolation = {
102 name: 'Web Animations', 104 name: 'Web Animations',
103 supports: function(property) {return property.indexOf('-webkit-') != 0;}, 105 supportsProperty: function(property) {return property.indexOf('-webkit-') != = 0;},
106 supportsValue: function(value) {return value !== '';},
104 setup: function() {}, 107 setup: function() {},
105 nonInterpolationExpectations: function(from, to) { 108 nonInterpolationExpectations: function(from, to) {
106 return expectFlip(from, to, 0.5); 109 return expectFlip(from, to, 0.5);
107 }, 110 },
108 interpolate: function(property, from, to, at, target) { 111 interpolate: function(property, from, to, at, target) {
109 var keyframes = [{}, {}]; 112 var keyframes = [{}, {}];
110 keyframes[0][property] = from; 113 keyframes[0][property] = from;
111 keyframes[1][property] = to; 114 keyframes[1][property] = to;
112 var player = target.animate(keyframes, { 115 var player = target.animate(keyframes, {
113 fill: 'forwards', 116 fill: 'forwards',
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 166 }
164 167
165 function createTargetContainer(parent) { 168 function createTargetContainer(parent) {
166 var targetContainer = createElement(parent); 169 var targetContainer = createElement(parent);
167 var template = document.querySelector('#target-template'); 170 var template = document.querySelector('#target-template');
168 if (template) { 171 if (template) {
169 targetContainer.appendChild(template.content.cloneNode(true)); 172 targetContainer.appendChild(template.content.cloneNode(true));
170 } 173 }
171 var target = targetContainer.querySelector('.target') || targetContainer; 174 var target = targetContainer.querySelector('.target') || targetContainer;
172 target.classList.add('target'); 175 target.classList.add('target');
176 target.parentElement.classList.add('parent');
173 targetContainer.target = target; 177 targetContainer.target = target;
174 return targetContainer; 178 return targetContainer;
175 } 179 }
176 180
177 function roundNumbers(value) { 181 function roundNumbers(value) {
178 return value. 182 return value.
179 // Round numbers to two decimal places. 183 // Round numbers to two decimal places.
180 replace(/-?\d*\.\d+(e-?\d+)?/g, function(n) { 184 replace(/-?\d*\.\d+(e-?\d+)?/g, function(n) {
181 return (parseFloat(n).toFixed(2)). 185 return (parseFloat(n).toFixed(2)).
182 replace(/\.\d+/, function(m) { 186 replace(/\.\d+/, function(m) {
(...skipping 23 matching lines...) Expand all
206 // Place whitespace between tokens. 210 // Place whitespace between tokens.
207 replace(/([\w\d.]+|[^\s])/g, '$1 '). 211 replace(/([\w\d.]+|[^\s])/g, '$1 ').
208 replace(/\s+/g, ' '); 212 replace(/\s+/g, ' ');
209 } 213 }
210 214
211 function assertNoInterpolation(options) { 215 function assertNoInterpolation(options) {
212 assertInterpolation(options, expectNoInterpolation); 216 assertInterpolation(options, expectNoInterpolation);
213 } 217 }
214 218
215 function assertInterpolation(options, expectations) { 219 function assertInterpolation(options, expectations) {
216 console.assert(CSS.supports(options.property, options.from)); 220 if (options.from) {
217 console.assert(CSS.supports(options.property, options.to)); 221 console.assert(CSS.supports(options.property, options.from));
222 }
223 if (options.to) {
224 console.assert(CSS.supports(options.property, options.to));
225 }
218 interpolationTests.push({ 226 interpolationTests.push({
219 options: options, 227 options: options,
220 expectations: expectations, 228 expectations: expectations,
221 }); 229 });
222 } 230 }
223 231
224 function createTestTargets(interpolationMethods, interpolationTests, container ) { 232 function createTestTargets(interpolationMethods, interpolationTests, container ) {
225 var targets = []; 233 var targets = [];
226 interpolationMethods.forEach(function(interpolationMethod) { 234 interpolationMethods.forEach(function(interpolationMethod) {
227 var methodContainer = createElement(container); 235 var methodContainer = createElement(container);
228 interpolationTests.forEach(function(interpolationTest) { 236 interpolationTests.forEach(function(interpolationTest) {
229 var property = interpolationTest.options.property; 237 var property = interpolationTest.options.property;
230 if (!interpolationMethod.supports(property)) { 238 var from = interpolationTest.options.from;
239 var to = interpolationTest.options.to;
240 if ((interpolationTest.options.method && interpolationTest.options.metho d != interpolationMethod.name)
241 || !interpolationMethod.supportsProperty(property)
242 || !interpolationMethod.supportsValue(from)
243 || !interpolationMethod.supportsValue(to)) {
231 return; 244 return;
232 } 245 }
233 if (interpolationTest.options.method && interpolationTest.options.method != interpolationMethod.name) {
234 return;
235 }
236 var from = interpolationTest.options.from;
237 var to = interpolationTest.options.to;
238 var testText = interpolationMethod.name + ': property <' + property + '> from [' + from + '] to [' + to + ']'; 246 var testText = interpolationMethod.name + ': property <' + property + '> from [' + from + '] to [' + to + ']';
239 var testContainer = createElement(methodContainer, 'div', testText); 247 var testContainer = createElement(methodContainer, 'div', testText);
240 createElement(testContainer, 'br'); 248 createElement(testContainer, 'br');
241 var expectations = interpolationTest.expectations; 249 var expectations = interpolationTest.expectations;
242 if (expectations === expectNoInterpolation) { 250 if (expectations === expectNoInterpolation) {
243 expectations = interpolationMethod.nonInterpolationExpectations(from, to); 251 expectations = interpolationMethod.nonInterpolationExpectations(from, to);
244 } 252 }
245 expectations.forEach(function(expectation) { 253 expectations.forEach(function(expectation) {
246 var actualTargetContainer = createTargetContainer(testContainer); 254 var actualTargetContainer = createTargetContainer(testContainer);
247 var expectedTargetContainer = createTargetContainer(testContainer); 255 var expectedTargetContainer = createTargetContainer(testContainer);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 loadScript('../../resources/testharness.js').then(function() { 311 loadScript('../../resources/testharness.js').then(function() {
304 return loadScript('../../resources/testharnessreport.js'); 312 return loadScript('../../resources/testharnessreport.js');
305 }).then(function() { 313 }).then(function() {
306 var asyncHandle = async_test('This test uses interpolation-test.js.') 314 var asyncHandle = async_test('This test uses interpolation-test.js.')
307 requestAnimationFrame(function() { 315 requestAnimationFrame(function() {
308 runInterpolationTests(); 316 runInterpolationTests();
309 asyncHandle.done() 317 asyncHandle.done()
310 }); 318 });
311 }); 319 });
312 })(); 320 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698