| 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     this.tests.forEach(test => { | 
|  | 45       test.testWrapper = document.createElement('div'); | 
|  | 46       this.wrapper.appendChild(test.testWrapper); | 
|  | 47 | 
|  | 48       test.data.samples.forEach(sample => { | 
|  | 49         var element = document.createElement('div'); | 
|  | 50 | 
|  | 51         // Add marker custom style as inline style. | 
|  | 52         // Do not create marker if empty string specified. | 
|  | 53         if (test.data.markerStyle == null || test.data.markerStyle != '') { | 
|  | 54           var content = document.createElement('div'); | 
|  | 55           content.classList.add('marker'); | 
|  | 56           content.style.cssText = test.data.markerStyle; | 
|  | 57           element.appendChild(content); | 
|  | 58         } | 
|  | 59 | 
|  | 60         element.classList.add('item'); | 
|  | 61 | 
|  | 62         // Add custom style as inline style. | 
|  | 63         var elementStyle = ''; | 
|  | 64         if (this.suiteStyle) | 
|  | 65           elementStyle = this.suiteStyle; | 
|  | 66         if (test.data.style) | 
|  | 67           elementStyle += test.data.style; | 
|  | 68         if (elementStyle) | 
|  | 69           element.style.cssText = elementStyle; | 
|  | 70 | 
|  | 71         // New line. | 
|  | 72         if (!test.testWrapper.hasChildNodes()) | 
|  | 73           element.style.clear = 'left'; | 
|  | 74 | 
|  | 75         test.testWrapper.appendChild(element); | 
|  | 76 | 
|  | 77         test.instances.push({ | 
|  | 78           element: element, | 
|  | 79           animation: null, | 
|  | 80           id: this.nextInstanceId++ | 
|  | 81         }); | 
|  | 82       }); | 
|  | 83     }); | 
|  | 84 | 
|  | 85     // Update all lifecycle phases to propagate all the objects to | 
|  | 86     // the compositor and to clear all the dirty flags. | 
|  | 87     if (window.internals) | 
|  | 88       internals.forceCompositingUpdate(document); | 
|  | 89   } | 
|  | 90 | 
|  | 91   startAnimations() { | 
|  | 92     // We want to achieve desired accuracy for splines using a specific duration
     . | 
|  | 93     // TODO(loyso): Duration mustn't affect cc/blink consistency. | 
|  | 94     // Taken from cubic_bezier.cc: | 
|  | 95     var kBezierEpsilon = 1e-7; | 
|  | 96     // Reverse the blink::accuracyForDuration function to calculate duration | 
|  | 97     // from epsilon: | 
|  | 98     var duration = 1000 * 1.0 / (kBezierEpsilon * 200.0); | 
|  | 99 | 
|  | 100     this.tests.forEach(test => { | 
|  | 101       if (test.instances.length != test.data.samples.length) | 
|  | 102         this.reportError(test, `instances.length=${test.instances.length} != sam
     ples.length=${test.data.samples.length}`); | 
|  | 103 | 
|  | 104       for (var i = 0; i < test.instances.length; i++) { | 
|  | 105         var sample = test.data.samples[i]; | 
|  | 106         var instance = test.instances[i]; | 
|  | 107 | 
|  | 108         // Use negative animation delays to specify sampled time for each animat
     ion. | 
|  | 109         instance.animation = instance.element.animate(test.data.keyframes, { | 
|  | 110             duration: duration, | 
|  | 111             iterations: Infinity, | 
|  | 112             delay: -duration * sample.at, | 
|  | 113             easing: test.data.easing | 
|  | 114         }); | 
|  | 115 | 
|  | 116         if (window.internals && !this.composited) | 
|  | 117           internals.disableCompositedAnimation(instance.animation); | 
|  | 118       } | 
|  | 119     }); | 
|  | 120 | 
|  | 121     if (window.internals) | 
|  | 122       internals.pauseAnimations(0); | 
|  | 123   } | 
|  | 124 | 
|  | 125   assertAnimationCompositedState() { | 
|  | 126     this.tests.forEach(test => { | 
|  | 127       test.instances.forEach(instance => { | 
|  | 128         var composited = internals.isCompositedAnimation(instance.animation); | 
|  | 129         if (composited != this.composited) | 
|  | 130           this.reportError(test, `Animation ${composited ? 'is' : 'is not'} runn
     ing on the compositor.`); | 
|  | 131       }); | 
|  | 132     }); | 
|  | 133   } | 
|  | 134 | 
|  | 135   reportError(test, message) { | 
|  | 136     if (!this.error.textContent) | 
|  | 137       this.error.textContent = `${this.composited ? 'Tests:' : 'TestExpectations
     :'} `; | 
|  | 138 | 
|  | 139     this.error.textContent += `${test.name}: ${message} `; | 
|  | 140   } | 
|  | 141 | 
|  | 142   layoutAndPaint() { | 
|  | 143     if (window.testRunner) | 
|  | 144       testRunner.waitUntilDone(); | 
|  | 145 | 
|  | 146     requestAnimationFrame(() => { | 
|  | 147       if (window.internals) | 
|  | 148         this.assertAnimationCompositedState(); | 
|  | 149       if (window.testRunner) | 
|  | 150         testRunner.notifyDone(); | 
|  | 151     }); | 
|  | 152   } | 
|  | 153 | 
|  | 154   registerTestsData(testSuiteData) { | 
|  | 155     this.suiteStyle = testSuiteData.style; | 
|  | 156     for (var testName in testSuiteData.tests) { | 
|  | 157       var testData = testSuiteData.tests[testName]; | 
|  | 158       this.tests.push({ | 
|  | 159         name: testName, | 
|  | 160         data: testData, | 
|  | 161         instances: [] | 
|  | 162       }); | 
|  | 163     } | 
|  | 164   } | 
|  | 165 | 
|  | 166   run() { | 
|  | 167     this.createTestElements(); | 
|  | 168     this.startAnimations(); | 
|  | 169     this.layoutAndPaint(); | 
|  | 170   } | 
|  | 171 } | 
|  | 172 | 
|  | 173 | 
|  | 174 class CompositedAnimationTest extends CompositedAnimationTestCommon { | 
|  | 175   constructor() { | 
|  | 176     var composited = true; | 
|  | 177     super(composited) | 
|  | 178   } | 
|  | 179 } | 
|  | 180 | 
|  | 181 | 
|  | 182 class CompositedAnimationTestExpected extends CompositedAnimationTestCommon { | 
|  | 183   constructor() { | 
|  | 184     var composited = false; | 
|  | 185     super(composited) | 
|  | 186   } | 
|  | 187 } | 
|  | 188 | 
|  | 189 | 
|  | 190 var runCompositedAnimationTests = function(testSuiteData) { | 
|  | 191   var test = new CompositedAnimationTest(); | 
|  | 192   test.registerTestsData(testSuiteData); | 
|  | 193   test.run(); | 
|  | 194 } | 
|  | 195 | 
|  | 196 var runCompositedAnimationTestExpectations = function(testSuiteData) { | 
|  | 197   var test = new CompositedAnimationTestExpected(); | 
|  | 198   test.registerTestsData(testSuiteData); | 
|  | 199   test.run(); | 
|  | 200 } | 
|  | 201 | 
|  | 202 var getLinearSamples = function(n, start, end) { | 
|  | 203   var arr = []; | 
|  | 204   var spread = end - start; | 
|  | 205   for (var i = 0; i <= n; i++) | 
|  | 206     arr.push(i * spread / n + start); | 
|  | 207   return arr.map(t => { return {at: t} }); | 
|  | 208 } | 
|  | 209 | 
| OLD | NEW | 
|---|