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('paint-' + 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 for (let i = 0; i < tests.length; i++) { |
| 39 tests[i].paintName = 'paint-' + i; |
| 40 } |
| 41 |
| 42 paintWorklet.import(URL.createObjectURL(new Blob([workletCode]))).then(funct
ion() { |
| 43 var callback = function() { |
| 44 if (tests.length == 0) { |
| 45 if (window.testRunner) |
| 46 testRunner.notifyDone(); |
| 47 return; |
| 48 } |
| 49 |
| 50 var test = tests.shift(); |
| 51 runIndividualTest(imageType, test, callback); |
| 52 }; |
| 53 |
| 54 callback(); |
| 55 }); |
| 56 } |
| 57 |
| 58 function runIndividualTest(imageType, test, callback) { |
| 59 var msg = ['', '']; |
| 60 msg.push('Test case:'); |
| 61 msg.push(test.property + ': ' + (test.prevValue || 'unset') + ' => ' + test.
property + ': ' + (test.value || 'unset')); |
| 62 if (test.noInvalidation) { |
| 63 msg.push('The worklet console should log nothing'); |
| 64 } else { |
| 65 msg.push('The worklet console should log: \'Succussful invalidation for:
' + test.property + '\''); |
| 66 } |
| 67 console.log(msg.join('\n')); |
| 68 |
| 69 // Create the test div. |
| 70 var el = document.createElement('div'); |
| 71 if (test.prevValue) el.style.setProperty(test.property, test.prevValue); |
| 72 el.style[imageType] = 'paint(' + test.paintName + ')'; |
| 73 document.body.appendChild(el); |
| 74 |
| 75 runAfterLayoutAndPaint(function() { |
| 76 el.style.setProperty(test.property, test.value); |
| 77 runAfterLayoutAndPaint(function() { |
| 78 document.body.removeChild(el); |
| 79 callback(); |
| 80 }); |
| 81 }); |
| 82 } |
OLD | NEW |