Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 'use strict'; | |
| 2 | |
| 3 class CompositedAnimationTestCommon { | |
| 4 constructor(disableThreadedAnimation) { | |
| 5 this.disableThreadedAnimation = disableThreadedAnimation; | |
| 6 this.tests = []; | |
| 7 this.next_sample_id = 1; | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Use camel cased variable names.
It's not clear wha
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 8 | |
| 9 this.createStyles(); | |
| 10 this.createStaticElements(); | |
| 11 } | |
| 12 | |
| 13 createStyles() { | |
| 14 var item = document.createElement('style'); | |
| 15 item.type = 'text/css'; | |
| 16 item.textContent = `.item { | |
| 17 width: 20px; | |
| 18 height: 20px; | |
| 19 position: relative; | |
| 20 background: black; | |
| 21 float: left; | |
| 22 }`; | |
| 23 | |
| 24 var marker = document.createElement('style'); | |
| 25 marker.type = 'text/css'; | |
| 26 marker.textContent = `.marker { | |
| 27 width: 5px; | |
| 28 height: 5px; | |
| 29 display: inline-block; | |
| 30 background: orange; | |
| 31 margin: 15px; | |
| 32 }`; | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Can't these be part of the same stylesheet?
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 33 | |
| 34 document.head.appendChild(item); | |
| 35 document.head.appendChild(marker); | |
| 36 } | |
| 37 | |
| 38 createStaticElements() { | |
| 39 var error = document.createElement("span"); | |
| 40 error.id = 'error'; | |
| 41 error.style.color = 'red'; | |
| 42 document.body.appendChild(error); | |
| 43 | |
| 44 var wrapper = document.createElement("div"); | |
| 45 wrapper.id = 'wrapper'; | |
| 46 document.body.appendChild(wrapper); | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
We shouldn't rely on the automatic element id glob
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 47 } | |
| 48 | |
| 49 createTestElements() { | |
| 50 var testId = 1; | |
| 51 | |
| 52 this.tests.forEach(function(test) { | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Use fat arrow notation so you don't have to .bind(
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 53 var testWrapper = document.createElement("div"); | |
| 54 wrapper.appendChild(testWrapper); | |
| 55 | |
| 56 // Create custom styles for this test case. | |
| 57 if (test.data.style) { | |
| 58 var styleForSamples = document.createElement('style'); | |
| 59 styleForSamples.type = 'text/css'; | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
No need to set type.
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 60 styleForSamples.textContent = '.test' + testId + ' {' + test.data.style + '}'; | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Nit, this would be a suitable place to use backtic
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 61 document.head.appendChild(styleForSamples); | |
| 62 } | |
| 63 if (test.data.markerStyle && test.data.markerStyle != '') { | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
No need to check for empty string.
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 64 var styleForMarkers = document.createElement('style'); | |
| 65 styleForMarkers.type = 'text/css'; | |
| 66 styleForMarkers.textContent = '.testMarker' + testId + ' {' + test.data. markerStyle + '}'; | |
| 67 document.head.appendChild(styleForMarkers); | |
| 68 } | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Instead of adding separate stylesheets just set th
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 69 | |
| 70 test.data.samples.forEach(function(sample) { | |
| 71 var element = document.createElement("div"); | |
| 72 | |
| 73 if (!testWrapper.hasChildNodes()) | |
| 74 element.style.clear = "left"; | |
| 75 | |
| 76 if (test.data.markerStyle == null || test.data.markerStyle != '') { | |
| 77 var content = document.createElement("div"); | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Stick with single quotes in this file for consiste
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 78 content.classList.add('marker', 'testMarker' + testId); | |
| 79 element.appendChild(content); | |
| 80 } | |
| 81 | |
| 82 element.classList.add('item', 'test' + testId); | |
| 83 | |
| 84 var sample_id = this.next_sample_id++; | |
| 85 element.id = sample_id; | |
| 86 | |
| 87 testWrapper.appendChild(element); | |
| 88 | |
| 89 test.instances.push({ | |
| 90 element: element, | |
| 91 animation: null, | |
| 92 id: sample_id | |
| 93 }); | |
| 94 }.bind(this)); | |
| 95 | |
| 96 testId++; | |
| 97 }.bind(this)); | |
| 98 | |
| 99 // Update all lifecycle phases to propagate all the objects to | |
| 100 // the compositor and to clear all the dirty flags. | |
| 101 if (window.internals) | |
| 102 internals.forceCompositingUpdate(document); | |
| 103 } | |
| 104 | |
| 105 startAnimations() { | |
| 106 // We want to achieve desired accuracy for splines using a specific duration . | |
| 107 // TODO(loyso): Duration mustn't affect cc/blink consistency. | |
| 108 // Taken from cubic_bezier.cc: | |
| 109 var kBezierEpsilon = 1e-7; | |
| 110 // Reverse the blink::accuracyForDuration function to calculate duration | |
| 111 // from epsilon: | |
| 112 var duration = 1000 * 1.0 / (kBezierEpsilon * 200.0); | |
| 113 | |
| 114 this.tests.forEach(function(test) { | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Assert that samples and instances are the same len
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 115 for (var i = 0; i < test.instances.length; i++) { | |
| 116 var sample = test.data.samples[i]; | |
| 117 var instance = test.instances[i]; | |
| 118 | |
| 119 // Use negative animation delays to specify sampled time for each animat ion. | |
| 120 instance.animation = instance.element.animate(test.data.keyframes, { | |
| 121 duration: duration, | |
| 122 iterations: Infinity, | |
| 123 delay: -duration * sample.at, | |
| 124 easing: test.data.easing | |
| 125 }); | |
| 126 | |
| 127 if (window.internals && this.disableThreadedAnimation) { | |
| 128 internals.disableCompositedAnimation(instance.animation); | |
| 129 } | |
| 130 } | |
| 131 }.bind(this)); | |
| 132 | |
| 133 if (window.internals) { | |
| 134 internals.pauseAnimations(0); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 assertAnimationsRunningOnCompositorThread() { | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
assertAnimationCompositedState() since we could be
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 139 this.tests.forEach(function(test) { | |
| 140 test.instances.forEach(function(instance) { | |
| 141 var composited = internals.isCompositedAnimation(instance.animation); | |
| 142 if (composited != !this.disableThreadedAnimation) | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
This is very confusing to read. If we rename this.
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 143 error.textContent += `Animation ${instance.id} ${composited ? 'is' : ' is not'} running on the compositor.`; | |
| 144 }.bind(this)); | |
| 145 }.bind(this)); | |
| 146 } | |
| 147 | |
| 148 layoutAndPaint() { | |
| 149 if (window.testRunner) { | |
| 150 testRunner.waitUntilDone(); | |
| 151 testRunner.layoutAndPaintAsyncThen(function() { | |
| 152 if (window.internals) { | |
| 153 this.assertAnimationsRunningOnCompositorThread(); | |
| 154 } | |
| 155 testRunner.notifyDone(); | |
| 156 }.bind(this)); | |
| 157 } | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Can we use requestAnimationFrame instead? We shoul
loyso (OOO)
2015/10/06 01:47:49
Done. layoutAndPaintAsyncThen implicitly posts mes
| |
| 158 } | |
| 159 | |
| 160 registerTestData(testData) { | |
| 161 this.tests.push({ | |
| 162 data: testData, | |
| 163 instances: [] | |
| 164 }); | |
| 165 } | |
| 166 | |
| 167 registerTestsData(testsData) { | |
| 168 testsData.forEach(function(test) { | |
| 169 this.registerTestData(test); | |
| 170 }.bind(this)); | |
| 171 } | |
| 172 | |
| 173 run() { | |
| 174 this.createTestElements(); | |
| 175 this.startAnimations(); | |
| 176 this.layoutAndPaint(); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 | |
| 181 class CompositedAnimationTest extends CompositedAnimationTestCommon { | |
| 182 constructor() { | |
| 183 var disableThreadedAnimation = false; | |
| 184 super(disableThreadedAnimation) | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 | |
| 189 class CompositedAnimationTestExpected extends CompositedAnimationTestCommon { | |
| 190 constructor() { | |
| 191 var disableThreadedAnimation = true; | |
| 192 super(disableThreadedAnimation) | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 | |
| 197 var getLinearSamples = function(n, start, end) { | |
| 198 var arr = []; | |
| 199 var spread = end - start; | |
| 200 for (var i=0; i<=n; i++) { | |
|
alancutter (OOO until 2018)
2015/09/30 01:45:27
Spaces around binary operators.
loyso (OOO)
2015/10/06 01:47:49
Done.
| |
| 201 arr.push(i * spread / n + start); | |
| 202 } | |
| 203 return arr.map(function(t) { return { at: t }}); | |
| 204 } | |
| OLD | NEW |