OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 cssAnimationsData.sharedStyle.textContent += '' + | 72 cssAnimationsData.sharedStyle.textContent += '' + |
73 '@keyframes animation' + id + ' {' + | 73 '@keyframes animation' + id + ' {' + |
74 'from {' + property + ': ' + from + ';}' + | 74 'from {' + property + ': ' + from + ';}' + |
75 'to {' + property + ': ' + to + ';}' + | 75 'to {' + property + ': ' + to + ';}' + |
76 '}'; | 76 '}'; |
77 target.style.animationName = 'animation' + id; | 77 target.style.animationName = 'animation' + id; |
78 target.style.animationDuration = '2e10s'; | 78 target.style.animationDuration = '2e10s'; |
79 target.style.animationDelay = '-1e10s'; | 79 target.style.animationDelay = '-1e10s'; |
80 target.style.animationTimingFunction = createEasing(at); | 80 target.style.animationTimingFunction = createEasing(at); |
81 }, | 81 }, |
| 82 rebaseline: false, |
82 }; | 83 }; |
83 | 84 |
84 var cssTransitionsInterpolation = { | 85 var cssTransitionsInterpolation = { |
85 name: 'CSS Transitions', | 86 name: 'CSS Transitions', |
86 supportsProperty: function() {return true;}, | 87 supportsProperty: function() {return true;}, |
87 supportsValue: function() {return true;}, | 88 supportsValue: function() {return true;}, |
88 setup: function(property, from, target) { | 89 setup: function(property, from, target) { |
89 target.style[property] = from; | 90 target.style[property] = from; |
90 }, | 91 }, |
91 nonInterpolationExpectations: function(from, to) { | 92 nonInterpolationExpectations: function(from, to) { |
92 return expectFlip(from, to, -Infinity); | 93 return expectFlip(from, to, -Infinity); |
93 }, | 94 }, |
94 interpolate: function(property, from, to, at, target) { | 95 interpolate: function(property, from, to, at, target) { |
95 target.style.transitionDuration = '2e10s'; | 96 target.style.transitionDuration = '2e10s'; |
96 target.style.transitionDelay = '-1e10s'; | 97 target.style.transitionDelay = '-1e10s'; |
97 target.style.transitionTimingFunction = createEasing(at); | 98 target.style.transitionTimingFunction = createEasing(at); |
98 target.style.transitionProperty = property; | 99 target.style.transitionProperty = property; |
99 target.style[property] = to; | 100 target.style[property] = to; |
100 }, | 101 }, |
| 102 rebaseline: false, |
101 }; | 103 }; |
102 | 104 |
103 var webAnimationsInterpolation = { | 105 var webAnimationsInterpolation = { |
104 name: 'Web Animations', | 106 name: 'Web Animations', |
105 supportsProperty: function(property) {return property.indexOf('-webkit-') !=
= 0;}, | 107 supportsProperty: function(property) {return property.indexOf('-webkit-') !=
= 0;}, |
106 supportsValue: function(value) {return value !== '';}, | 108 supportsValue: function(value) {return value !== '';}, |
107 setup: function() {}, | 109 setup: function() {}, |
108 nonInterpolationExpectations: function(from, to) { | 110 nonInterpolationExpectations: function(from, to) { |
109 return expectFlip(from, to, 0.5); | 111 return expectFlip(from, to, 0.5); |
110 }, | 112 }, |
111 interpolate: function(property, from, to, at, target) { | 113 interpolate: function(property, from, to, at, target) { |
112 var keyframes = [{}, {}]; | 114 var keyframes = [{}, {}]; |
113 keyframes[0][property] = from; | 115 keyframes[0][property] = from; |
114 keyframes[1][property] = to; | 116 keyframes[1][property] = to; |
115 var player = target.animate(keyframes, { | 117 var player = target.animate(keyframes, { |
116 fill: 'forwards', | 118 fill: 'forwards', |
117 duration: 1, | 119 duration: 1, |
118 easing: createEasing(at), | 120 easing: createEasing(at), |
119 delay: -0.5, | 121 delay: -0.5, |
120 iterations: 0.5, | 122 iterations: 0.5, |
121 }); | 123 }); |
122 }, | 124 }, |
| 125 rebaseline: false, |
123 }; | 126 }; |
124 | 127 |
125 function expectFlip(from, to, flipAt) { | 128 function expectFlip(from, to, flipAt) { |
126 return [-0.3, 0, 0.3, 0.5, 0.6, 1, 1.5].map(function(at) { | 129 return [-0.3, 0, 0.3, 0.5, 0.6, 1, 1.5].map(function(at) { |
127 return { | 130 return { |
128 at: at, | 131 at: at, |
129 is: at < flipAt ? from : to | 132 is: at < flipAt ? from : to |
130 }; | 133 }; |
131 }); | 134 }); |
132 } | 135 } |
(...skipping 27 matching lines...) Expand all Loading... |
160 return new Promise(function(resolve) { | 163 return new Promise(function(resolve) { |
161 var script = document.createElement('script'); | 164 var script = document.createElement('script'); |
162 script.src = url; | 165 script.src = url; |
163 script.onload = resolve; | 166 script.onload = resolve; |
164 document.head.appendChild(script); | 167 document.head.appendChild(script); |
165 }); | 168 }); |
166 } | 169 } |
167 | 170 |
168 function createTargetContainer(parent) { | 171 function createTargetContainer(parent) { |
169 var targetContainer = createElement(parent); | 172 var targetContainer = createElement(parent); |
| 173 targetContainer.classList.add('container'); |
170 var template = document.querySelector('#target-template'); | 174 var template = document.querySelector('#target-template'); |
171 if (template) { | 175 if (template) { |
172 targetContainer.appendChild(template.content.cloneNode(true)); | 176 targetContainer.appendChild(template.content.cloneNode(true)); |
173 } | 177 } |
174 var target = targetContainer.querySelector('.target') || targetContainer; | 178 var target = targetContainer.querySelector('.target') || targetContainer; |
175 target.classList.add('target'); | 179 target.classList.add('target'); |
176 target.parentElement.classList.add('parent'); | 180 target.parentElement.classList.add('parent'); |
177 targetContainer.target = target; | 181 targetContainer.target = target; |
178 return targetContainer; | 182 return targetContainer; |
179 } | 183 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 226 } |
223 if (options.to) { | 227 if (options.to) { |
224 console.assert(CSS.supports(options.property, options.to)); | 228 console.assert(CSS.supports(options.property, options.to)); |
225 } | 229 } |
226 interpolationTests.push({ | 230 interpolationTests.push({ |
227 options: options, | 231 options: options, |
228 expectations: expectations, | 232 expectations: expectations, |
229 }); | 233 }); |
230 } | 234 } |
231 | 235 |
232 function createTestTargets(interpolationMethods, interpolationTests, container
) { | 236 function createTestTargets(interpolationMethods, interpolationTests, container
, rebaselineContainer) { |
233 var targets = []; | 237 var targets = []; |
234 interpolationMethods.forEach(function(interpolationMethod) { | 238 interpolationMethods.forEach(function(interpolationMethod, interpolationMeth
odIndex) { |
235 var methodContainer = createElement(container); | 239 var methodContainer = createElement(container); |
236 interpolationTests.forEach(function(interpolationTest) { | 240 interpolationTests.forEach(function(interpolationTest) { |
237 var property = interpolationTest.options.property; | 241 var property = interpolationTest.options.property; |
238 var from = interpolationTest.options.from; | 242 var from = interpolationTest.options.from; |
239 var to = interpolationTest.options.to; | 243 var to = interpolationTest.options.to; |
240 if ((interpolationTest.options.method && interpolationTest.options.metho
d != interpolationMethod.name) | 244 if ((interpolationTest.options.method && interpolationTest.options.metho
d != interpolationMethod.name) |
241 || !interpolationMethod.supportsProperty(property) | 245 || !interpolationMethod.supportsProperty(property) |
242 || !interpolationMethod.supportsValue(from) | 246 || !interpolationMethod.supportsValue(from) |
243 || !interpolationMethod.supportsValue(to)) { | 247 || !interpolationMethod.supportsValue(to)) { |
244 return; | 248 return; |
245 } | 249 } |
| 250 if (interpolationMethod.rebaseline) { |
| 251 var rebaseline = createElement(rebaselineContainer, 'pre'); |
| 252 rebaseline.appendChild(document.createTextNode(`\ |
| 253 assertInterpolation({ |
| 254 property: '${property}', |
| 255 from: '${from}', |
| 256 to: '${to}', |
| 257 }, [\n`)); |
| 258 var rebaselineExpectation; |
| 259 rebaseline.appendChild(rebaselineExpectation = document.createTextNode
('')); |
| 260 rebaseline.appendChild(document.createTextNode(']);\n\n')); |
| 261 } |
246 var testText = interpolationMethod.name + ': property <' + property + '>
from [' + from + '] to [' + to + ']'; | 262 var testText = interpolationMethod.name + ': property <' + property + '>
from [' + from + '] to [' + to + ']'; |
247 var testContainer = createElement(methodContainer, 'div', testText); | 263 var testContainer = createElement(methodContainer, 'div', testText); |
248 createElement(testContainer, 'br'); | 264 createElement(testContainer, 'br'); |
249 var expectations = interpolationTest.expectations; | 265 var expectations = interpolationTest.expectations; |
250 if (expectations === expectNoInterpolation) { | 266 if (expectations === expectNoInterpolation) { |
251 expectations = interpolationMethod.nonInterpolationExpectations(from,
to); | 267 expectations = interpolationMethod.nonInterpolationExpectations(from,
to); |
252 } | 268 } |
253 expectations.forEach(function(expectation) { | 269 expectations.forEach(function(expectation) { |
254 var actualTargetContainer = createTargetContainer(testContainer); | 270 var actualTargetContainer = createTargetContainer(testContainer); |
255 var expectedTargetContainer = createTargetContainer(testContainer); | 271 var expectedTargetContainer = createTargetContainer(testContainer); |
256 expectedTargetContainer.target.classList.add('expected'); | 272 expectedTargetContainer.target.classList.add('expected'); |
257 expectedTargetContainer.target.style[property] = expectation.is; | 273 expectedTargetContainer.target.style[property] = expectation.is; |
258 var target = actualTargetContainer.target; | 274 var target = actualTargetContainer.target; |
259 target.classList.add('actual'); | 275 target.classList.add('actual'); |
260 interpolationMethod.setup(property, from, target); | 276 interpolationMethod.setup(property, from, target); |
261 target.interpolate = function() { | 277 target.interpolate = function() { |
262 interpolationMethod.interpolate(property, from, to, expectation.at,
target); | 278 interpolationMethod.interpolate(property, from, to, expectation.at,
target); |
263 }; | 279 }; |
264 target.measure = function() { | 280 target.measure = function() { |
265 var actualValue = getComputedStyle(target)[property]; | 281 var actualValue = getComputedStyle(target)[property]; |
266 test(function() { | 282 test(function() { |
267 assert_equals( | 283 assert_equals( |
268 normalizeValue(actualValue), | 284 normalizeValue(actualValue), |
269 normalizeValue(getComputedStyle(expectedTargetContainer.target)[
property])); | 285 normalizeValue(getComputedStyle(expectedTargetContainer.target)[
property])); |
270 }, testText + ' at (' + expectation.at + ') is [' + sanitizeUrls(act
ualValue) + ']'); | 286 }, testText + ' at (' + expectation.at + ') is [' + sanitizeUrls(act
ualValue) + ']'); |
| 287 if (interpolationMethod.rebaseline) { |
| 288 rebaselineExpectation.textContent += ` {at: ${expectation.at}, is
: '${actualValue}'},\n`; |
| 289 } |
271 }; | 290 }; |
272 targets.push(target); | 291 targets.push(target); |
273 }); | 292 }); |
274 }); | 293 }); |
275 }); | 294 }); |
276 return targets; | 295 return targets; |
277 } | 296 } |
278 | 297 |
279 function runInterpolationTests() { | 298 function runInterpolationTests() { |
280 var interpolationMethods = [ | 299 var interpolationMethods = [ |
281 cssTransitionsInterpolation, | 300 cssTransitionsInterpolation, |
282 cssAnimationsInterpolation, | 301 cssAnimationsInterpolation, |
283 ]; | 302 ]; |
284 if (webAnimationsEnabled) { | 303 if (webAnimationsEnabled) { |
285 interpolationMethods.push(webAnimationsInterpolation); | 304 interpolationMethods.push(webAnimationsInterpolation); |
286 } | 305 } |
| 306 var rebaselineContainer = createElement(document.body); |
287 var container = createElement(document.body); | 307 var container = createElement(document.body); |
288 var targets = createTestTargets(interpolationMethods, interpolationTests, co
ntainer); | 308 var targets = createTestTargets(interpolationMethods, interpolationTests, co
ntainer, rebaselineContainer); |
289 getComputedStyle(document.documentElement).left; // Force a style recalc for
transitions. | 309 getComputedStyle(document.documentElement).left; // Force a style recalc for
transitions. |
290 // Separate interpolation and measurement into different phases to avoid (ta
rgets.length) style recalcs. | 310 // Separate interpolation and measurement into different phases to avoid O(n
^2) of the number of targets. |
291 for (var target of targets) { | 311 for (var target of targets) { |
292 target.interpolate(); | 312 target.interpolate(); |
293 } | 313 } |
294 for (var target of targets) { | 314 for (var target of targets) { |
295 target.measure(); | 315 target.measure(); |
296 } | 316 } |
297 if (window.testRunner) { | 317 if (window.testRunner) { |
298 container.remove(); | 318 container.remove(); |
299 } | 319 } |
300 afterTestHook(); | 320 afterTestHook(); |
(...skipping 10 matching lines...) Expand all Loading... |
311 loadScript('../../resources/testharness.js').then(function() { | 331 loadScript('../../resources/testharness.js').then(function() { |
312 return loadScript('../../resources/testharnessreport.js'); | 332 return loadScript('../../resources/testharnessreport.js'); |
313 }).then(function() { | 333 }).then(function() { |
314 var asyncHandle = async_test('This test uses interpolation-test.js.') | 334 var asyncHandle = async_test('This test uses interpolation-test.js.') |
315 requestAnimationFrame(function() { | 335 requestAnimationFrame(function() { |
316 runInterpolationTests(); | 336 runInterpolationTests(); |
317 asyncHandle.done() | 337 asyncHandle.done() |
318 }); | 338 }); |
319 }); | 339 }); |
320 })(); | 340 })(); |
OLD | NEW |