Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 'use strict'; | |
| 2 | |
| 3 class CompositedAnimationTestCommon { | |
| 4 constructor(composited) { | |
| 5 this.composited = composited; | |
| 6 this.tests = []; | |
| 7 this.nextInstanceId = 1; | |
| 8 | |
| 9 this.createStyles(); | |
| 10 this.createStaticElements(); | |
| 11 } | |
| 12 | |
| 13 createStyles() { | |
| 14 var styleSheet = document.createElement('style'); | |
| 15 styleSheet.textContent = ` | |
| 16 .item { | |
| 17 width: 20px; | |
| 18 height: 20px; | |
| 19 position: relative; | |
| 20 background: black; | |
| 21 float: left; | |
| 22 } | |
| 23 .marker { | |
| 24 width: 5px; | |
| 25 height: 5px; | |
| 26 display: inline-block; | |
| 27 background: orange; | |
| 28 margin: 15px; | |
| 29 }`; | |
| 30 | |
| 31 document.head.appendChild(styleSheet); | |
| 32 } | |
| 33 | |
| 34 createStaticElements() { | |
| 35 this.error = document.createElement('span'); | |
| 36 this.error.style.color = 'red'; | |
| 37 document.body.appendChild(this.error); | |
| 38 | |
| 39 this.wrapper = document.createElement('div'); | |
| 40 document.body.appendChild(this.wrapper); | |
| 41 } | |
| 42 | |
| 43 createTestElements() { | |
| 44 var testId = 1; | |
|
alancutter (OOO until 2018)
2015/10/06 03:42:49
This is unused.
loyso (OOO)
2015/10/06 04:01:33
Done.
| |
| 45 | |
| 46 this.tests.forEach(test => { | |
| 47 test.testWrapper = document.createElement('div'); | |
| 48 this.wrapper.appendChild(test.testWrapper); | |
| 49 | |
| 50 test.data.samples.forEach(sample => { | |
| 51 var element = document.createElement('div'); | |
| 52 | |
| 53 // Add marker custom style as inline style. | |
| 54 // Do not create marker if empty string specified. | |
| 55 if (test.data.markerStyle == null || test.data.markerStyle != '') { | |
| 56 var content = document.createElement('div'); | |
| 57 content.classList.add('marker'); | |
| 58 content.setAttribute('style', test.data.markerStyle); | |
|
alancutter (OOO until 2018)
2015/10/06 03:42:49
I've heard we have invalidation issues with settin
loyso (OOO)
2015/10/06 04:01:33
Done.
| |
| 59 element.appendChild(content); | |
| 60 } | |
| 61 | |
| 62 element.classList.add('item'); | |
| 63 | |
| 64 // Add custom style as inline style. | |
| 65 var elementStyle = ''; | |
| 66 if (this.suiteStyle) | |
| 67 elementStyle = this.suiteStyle; | |
| 68 if (test.data.style) | |
| 69 elementStyle += test.data.style; | |
| 70 if (elementStyle) | |
| 71 element.setAttribute('style', elementStyle); | |
|
alancutter (OOO until 2018)
2015/10/06 03:42:49
Ditto.
loyso (OOO)
2015/10/06 04:01:33
Done.
| |
| 72 | |
| 73 // New line. | |
| 74 if (!test.testWrapper.hasChildNodes()) | |
| 75 element.style.clear = 'left'; | |
| 76 | |
| 77 test.testWrapper.appendChild(element); | |
| 78 | |
| 79 test.instances.push({ | |
| 80 element: element, | |
| 81 animation: null, | |
| 82 id: this.nextInstanceId++ | |
| 83 }); | |
| 84 }); | |
| 85 | |
| 86 testId++; | |
|
alancutter (OOO until 2018)
2015/10/06 03:42:49
This is unused.
loyso (OOO)
2015/10/06 04:01:33
Done.
| |
| 87 }); | |
| 88 | |
| 89 // Update all lifecycle phases to propagate all the objects to | |
| 90 // the compositor and to clear all the dirty flags. | |
| 91 if (window.internals) | |
| 92 internals.forceCompositingUpdate(document); | |
| 93 } | |
| 94 | |
| 95 startAnimations() { | |
| 96 // We want to achieve desired accuracy for splines using a specific duration . | |
| 97 // TODO(loyso): Duration mustn't affect cc/blink consistency. | |
| 98 // Taken from cubic_bezier.cc: | |
| 99 var kBezierEpsilon = 1e-7; | |
| 100 // Reverse the blink::accuracyForDuration function to calculate duration | |
| 101 // from epsilon: | |
| 102 var duration = 1000 * 1.0 / (kBezierEpsilon * 200.0); | |
| 103 | |
| 104 this.tests.forEach(test => { | |
| 105 if (test.instances.length != test.data.samples.length) | |
| 106 this.reportError(test, `instances.length=${test.instances.length} != sam ples.length=${test.data.samples.length}`); | |
| 107 | |
| 108 for (var i = 0; i < test.instances.length; i++) { | |
| 109 var sample = test.data.samples[i]; | |
| 110 var instance = test.instances[i]; | |
| 111 | |
| 112 // Use negative animation delays to specify sampled time for each animat ion. | |
| 113 instance.animation = instance.element.animate(test.data.keyframes, { | |
| 114 duration: duration, | |
| 115 iterations: Infinity, | |
| 116 delay: -duration * sample.at, | |
| 117 easing: test.data.easing | |
| 118 }); | |
| 119 | |
| 120 if (window.internals && !this.composited) | |
| 121 internals.disableCompositedAnimation(instance.animation); | |
| 122 } | |
| 123 }); | |
| 124 | |
| 125 if (window.internals) | |
| 126 internals.pauseAnimations(0); | |
| 127 } | |
| 128 | |
| 129 assertAnimationCompositedState() { | |
| 130 this.tests.forEach(test => { | |
| 131 test.instances.forEach(instance => { | |
| 132 var composited = internals.isCompositedAnimation(instance.animation); | |
| 133 if (composited != this.composited) | |
| 134 this.reportError(test, `Animation ${composited ? 'is' : 'is not'} runn ing on the compositor.`); | |
| 135 }); | |
| 136 }); | |
| 137 } | |
| 138 | |
| 139 reportError(test, message) { | |
| 140 if (!this.error.textContent) | |
| 141 this.error.textContent = `${this.composited ? 'Tests:' : 'TestExpectations :'} `; | |
| 142 | |
| 143 this.error.textContent += `${test.name}: ${message} `; | |
| 144 } | |
| 145 | |
| 146 layoutAndPaint() { | |
| 147 if (window.testRunner) | |
| 148 testRunner.waitUntilDone(); | |
| 149 | |
| 150 requestAnimationFrame(() => { | |
| 151 if (window.internals) | |
| 152 this.assertAnimationCompositedState(); | |
| 153 if (window.testRunner) | |
| 154 testRunner.notifyDone(); | |
| 155 }); | |
| 156 } | |
| 157 | |
| 158 registerTestsData(testSuiteData) { | |
| 159 this.suiteStyle = testSuiteData.style; | |
| 160 for (var testName in testSuiteData.tests) { | |
| 161 var testData = testSuiteData.tests[testName]; | |
| 162 this.tests.push({ | |
| 163 name: testName, | |
| 164 data: testData, | |
| 165 instances: [] | |
| 166 }); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 run() { | |
| 171 this.createTestElements(); | |
| 172 this.startAnimations(); | |
| 173 this.layoutAndPaint(); | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 | |
| 178 class CompositedAnimationTest extends CompositedAnimationTestCommon { | |
| 179 constructor() { | |
| 180 var composited = true; | |
| 181 super(composited) | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 | |
| 186 class CompositedAnimationTestExpected extends CompositedAnimationTestCommon { | |
| 187 constructor() { | |
| 188 var composited = false; | |
| 189 super(composited) | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 | |
| 194 var runCompositedAnimationTests = function(testSuiteData) { | |
| 195 var test = new CompositedAnimationTest(); | |
| 196 test.registerTestsData(testSuiteData); | |
| 197 test.run(); | |
| 198 } | |
| 199 | |
| 200 var runCompositedAnimationTestExpectations = function(testSuiteData) { | |
| 201 var test = new CompositedAnimationTestExpected(); | |
| 202 test.registerTestsData(testSuiteData); | |
| 203 test.run(); | |
| 204 } | |
| 205 | |
| 206 var getLinearSamples = function(n, start, end) { | |
| 207 var arr = []; | |
| 208 var spread = end - start; | |
| 209 for (var i = 0; i <= n; i++) | |
| 210 arr.push(i * spread / n + start); | |
| 211 return arr.map(t => { return {at: t} }); | |
| 212 } | |
| 213 | |
| OLD | NEW |