Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 'use strict'; | 1 'use strict'; |
| 2 | 2 |
| 3 class CompositedAnimationTestCommon { | 3 class CompositedAnimationTestCommon { |
| 4 constructor(composited) { | 4 constructor(composited) { |
| 5 this.composited = composited; | 5 this.composited = composited; |
| 6 this.tests = []; | 6 this.tests = []; |
| 7 this.nextInstanceId = 1; | 7 this.nextInstanceId = 1; |
| 8 this.errorCount = 0; | |
| 8 | 9 |
| 9 this.createStyles(); | 10 this.createStyles(); |
| 10 this.createStaticElements(); | 11 this.createStaticElements(); |
| 11 } | 12 } |
| 12 | 13 |
| 13 createStyles() { | 14 createStyles() { |
| 14 var styleSheet = document.createElement('style'); | 15 var styleSheet = document.createElement('style'); |
| 15 styleSheet.textContent = ` | 16 styleSheet.textContent = ` |
| 16 .item { | 17 .item { |
| 17 width: 20px; | 18 width: 20px; |
| 18 height: 20px; | 19 height: 20px; |
| 19 position: relative; | 20 position: relative; |
| 20 background: black; | 21 background: black; |
| 21 float: left; | 22 float: left; |
| 22 } | 23 } |
| 23 .marker { | 24 .marker { |
| 24 width: 5px; | 25 width: 5px; |
| 25 height: 5px; | 26 height: 5px; |
| 26 display: inline-block; | 27 display: inline-block; |
| 27 background: orange; | 28 background: orange; |
| 28 margin: 15px; | 29 margin: 15px; |
| 29 }`; | 30 }`; |
| 30 | 31 |
| 31 document.head.appendChild(styleSheet); | 32 document.head.appendChild(styleSheet); |
| 32 } | 33 } |
| 33 | 34 |
| 34 createStaticElements() { | 35 createStaticElements() { |
| 35 this.error = document.createElement('span'); | 36 this.error = document.createElement('span'); |
| 36 this.error.style.color = 'red'; | 37 this.error.style = 'color: red; font-family: monospace; font-size: 12px'; |
| 37 // The element must have some painted content in order to be composited. | 38 // The error element must have some painted content in order to be |
| 38 this.error.textContent = 'x'; | 39 // composited when animated in SPv2. |
| 40 this.error.innerText = '(no errors)'; | |
| 39 document.body.appendChild(this.error); | 41 document.body.appendChild(this.error); |
| 40 | 42 |
| 41 this.wrapper = document.createElement('div'); | 43 this.wrapper = document.createElement('div'); |
| 42 document.body.appendChild(this.wrapper); | 44 document.body.appendChild(this.wrapper); |
| 43 } | 45 } |
| 44 | 46 |
| 45 createTestElements() { | 47 createTestElements() { |
| 46 this.tests.forEach(test => { | 48 this.tests.forEach(test => { |
| 47 test.testWrapper = document.createElement('div'); | 49 test.testWrapper = document.createElement('div'); |
| 48 this.wrapper.appendChild(test.testWrapper); | 50 this.wrapper.appendChild(test.testWrapper); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 103 |
| 102 this.tests.forEach(test => { | 104 this.tests.forEach(test => { |
| 103 if (test.instances.length != test.data.samples.length) | 105 if (test.instances.length != test.data.samples.length) |
| 104 this.reportError(test, `instances.length=${test.instances.length} != sam ples.length=${test.data.samples.length}`); | 106 this.reportError(test, `instances.length=${test.instances.length} != sam ples.length=${test.data.samples.length}`); |
| 105 | 107 |
| 106 for (var i = 0; i < test.instances.length; i++) { | 108 for (var i = 0; i < test.instances.length; i++) { |
| 107 var sample = test.data.samples[i]; | 109 var sample = test.data.samples[i]; |
| 108 var instance = test.instances[i]; | 110 var instance = test.instances[i]; |
| 109 | 111 |
| 110 // Use negative animation delays to specify sampled time for each animat ion. | 112 // Use negative animation delays to specify sampled time for each animat ion. |
| 113 // console.log('Creating test instance [duration=' + duration + ', delay =' + (-duration * sample.at) + ', easing=' + test.data.easing + '].'); | |
|
pdr.
2017/03/24 20:37:47
nit: did you mean to leave this in?
wkorman
2017/03/24 20:59:26
Ah, good catch, removed.
| |
| 111 instance.animation = instance.element.animate(test.data.keyframes, { | 114 instance.animation = instance.element.animate(test.data.keyframes, { |
| 112 duration: duration, | 115 duration: duration, |
| 113 iterations: Infinity, | 116 iterations: Infinity, |
| 114 delay: -duration * sample.at, | 117 delay: -duration * sample.at, |
| 115 easing: test.data.easing | 118 easing: test.data.easing |
| 116 }); | 119 }); |
| 117 | 120 |
| 118 if (window.internals && !this.composited) | 121 if (window.internals && !this.composited) |
| 119 internals.disableCompositedAnimation(instance.animation); | 122 internals.disableCompositedAnimation(instance.animation); |
| 120 } | 123 } |
| 121 }); | 124 }); |
| 122 | 125 |
| 123 if (window.internals) | 126 if (window.internals) |
| 124 internals.pauseAnimations(0); | 127 internals.pauseAnimations(0); |
| 125 } | 128 } |
| 126 | 129 |
| 127 assertAnimationCompositedState() { | 130 assertAnimationCompositedState() { |
| 128 this.tests.forEach(test => { | 131 this.tests.forEach(test => { |
| 129 test.instances.forEach(instance => { | 132 test.instances.forEach(instance => { |
| 130 var composited = internals.isCompositedAnimation(instance.animation); | 133 var composited = internals.isCompositedAnimation(instance.animation); |
| 131 if (composited != this.composited) | 134 if (composited != this.composited) |
| 132 this.reportError(test, `Animation ${composited ? 'is' : 'is not'} runn ing on the compositor.`); | 135 this.reportError(test, `Animation ${composited ? 'is' : 'is not'} runn ing on the compositor [id=${instance.id}].`); |
| 133 }); | 136 }); |
| 134 }); | 137 }); |
| 135 } | 138 } |
| 136 | 139 |
| 137 reportError(test, message) { | 140 reportError(test, message) { |
| 138 if (!this.error.textContent) | 141 if (this.errorCount == 0) |
| 139 this.error.textContent = `${this.composited ? 'Tests:' : 'TestExpectations :'} `; | 142 this.error.innerHTML = `${this.composited ? 'Tests:' : 'TestExpectations:' }<br>`; |
| 140 | 143 |
| 141 this.error.textContent += `${test.name}: ${message} `; | 144 if (this.errorCount > 0) |
| 145 this.error.innerHTML += '<br>'; | |
| 146 this.error.innerHTML += `${test.name}: ${message} `; | |
| 147 this.errorCount++; | |
| 142 } | 148 } |
| 143 | 149 |
| 144 waitForCompositor() { | 150 waitForCompositor() { |
| 145 return this.error.animate({opacity: ['1', '1']}, 1).ready; | 151 return this.error.animate({opacity: ['1', '1']}, 1).ready; |
| 146 } | 152 } |
| 147 | 153 |
| 148 layoutAndPaint() { | 154 layoutAndPaint() { |
| 149 if (window.testRunner) | 155 if (window.testRunner) |
| 150 testRunner.waitUntilDone(); | 156 testRunner.waitUntilDone(); |
| 151 | 157 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 214 } |
| 209 | 215 |
| 210 var getLinearSamples = function(n, start, end) { | 216 var getLinearSamples = function(n, start, end) { |
| 211 var arr = []; | 217 var arr = []; |
| 212 var spread = end - start; | 218 var spread = end - start; |
| 213 for (var i = 0; i <= n; i++) | 219 for (var i = 0; i <= n; i++) |
| 214 arr.push(i * spread / n + start); | 220 arr.push(i * spread / n + start); |
| 215 return arr.map(t => { return {at: t} }); | 221 return arr.map(t => { return {at: t} }); |
| 216 } | 222 } |
| 217 | 223 |
| OLD | NEW |