OLD | NEW |
(Empty) | |
| 1 // Test runner for the paint worklet to test invalidation behaviour. |
| 2 // |
| 3 // Calls a given function with a newly created element, and prints the expected |
| 4 // geometry to the console. |
| 5 // |
| 6 // Runs each test sequentially after a layout and a paint. |
| 7 // |
| 8 // Usage: |
| 9 // testRunnerInvalidationLogging('background-image', [ |
| 10 // { property: 'max-height', value: '100px' }, |
| 11 // { property: 'color', value: 'blue' }, |
| 12 // ]); |
| 13 |
| 14 function testRunnerInvalidationLogging(imageType, tests) { |
| 15 if (window.testRunner) { |
| 16 testRunner.waitUntilDone(); |
| 17 testRunner.dumpAsText(); |
| 18 } |
| 19 |
| 20 var keys = tests.map(function(obj) { return obj.property; }); |
| 21 var workletCode = 'var properties = ' + JSON.stringify(keys) + ';\n' + ` |
| 22 for (let i = 0; i < properties.length; i++) { |
| 23 registerPaint(properties[i], class { |
| 24 static get inputProperties() { return [properties[i]]; } |
| 25 constructor() { this.hasPainted= false; } |
| 26 paint(ctx, geom) { |
| 27 ctx.fillStyle = this.hasPainted ? 'green' : 'blue'; |
| 28 ctx.fillRect(0, 0, geom.width, geom.height); |
| 29 if (this.hasPainted) { |
| 30 console.log('Successful invalidation for: ' + properties
[i]); |
| 31 } |
| 32 this.hasPainted = true; |
| 33 } |
| 34 }); |
| 35 } |
| 36 `; |
| 37 |
| 38 paintWorklet.import(URL.createObjectURL(new Blob([workletCode]))).then(funct
ion() { |
| 39 var callback = function() { |
| 40 if (tests.length == 0) { |
| 41 testRunner.notifyDone(); |
| 42 return; |
| 43 } |
| 44 |
| 45 var test = tests.shift(); |
| 46 runIndividualTest(imageType, test, callback); |
| 47 }; |
| 48 |
| 49 callback(); |
| 50 }); |
| 51 } |
| 52 |
| 53 function runIndividualTest(imageType, test, callback) { |
| 54 console.log('The console should log: \'Succussful invalidation for: ' + test
.property + '\''); |
| 55 |
| 56 // Create the test div. |
| 57 var el = document.createElement('div'); |
| 58 el.style[imageType] = 'paint(' + test.property + ')'; |
| 59 document.body.appendChild(el); |
| 60 |
| 61 runAfterLayoutAndPaint(function() { |
| 62 el.style.setProperty(test.property, test.value); |
| 63 runAfterLayoutAndPaint(function() { |
| 64 document.body.removeChild(el); |
| 65 callback(); |
| 66 }); |
| 67 }); |
| 68 } |
OLD | NEW |