Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Test runner for the paint worklet to test invalidation behaviour. | |
| 2 // | |
| 3 // Registers an async_test per test case, which: | |
|
Timothy Loh
2016/05/11 06:20:37
promise_test?
ikilpatrick
2016/05/11 23:59:12
Done.
| |
| 4 // - Creates an element. | |
| 5 // - Invalidates the style of that element. | |
| 6 // - [worklet] Worklet code logs if it got the invalidation. | |
| 7 // - Asserts that it got the correct paint invalidation. | |
| 8 // | |
| 9 // Usage: | |
| 10 // testRunnerInvalidationLogging('background-image', [ | |
| 11 // { property: 'max-height', value: '100px' }, | |
| 12 // { property: 'color', prevValue: '#00F', value: 'blue', noInvalidation: t rue }, | |
| 13 // ]); | |
| 14 | |
| 15 function testRunnerInvalidationLogging(imageType, tests) { | |
| 16 const keys = tests.map(function(obj) { return obj.property; }); | |
| 17 const workletCode = 'const properties = ' + JSON.stringify(keys) + ';\n' + ` | |
| 18 for (let i = 0; i < properties.length; i++) { | |
| 19 registerPaint('paint-' + i, class { | |
| 20 static get inputProperties() { return [properties[i]]; } | |
| 21 constructor() { this.hasPainted= false; } | |
| 22 paint(ctx, geom) { | |
| 23 ctx.fillStyle = this.hasPainted ? 'green' : 'blue'; | |
| 24 ctx.fillRect(0, 0, geom.width, geom.height); | |
| 25 if (this.hasPainted) { | |
| 26 console.log('Successful invalidation for: ' + properties [i]); | |
| 27 } | |
| 28 this.hasPainted = true; | |
| 29 } | |
| 30 }); | |
| 31 } | |
| 32 `; | |
| 33 | |
| 34 paintWorklet.import(URL.createObjectURL(new Blob([workletCode]))).then(funct ion() { | |
| 35 for (let i = 0; i < tests.length; i++) { | |
| 36 tests[i].paintName = 'paint-' + i; | |
| 37 registerTest(imageType, tests[i]); | |
| 38 } | |
| 39 }); | |
| 40 } | |
| 41 | |
| 42 function registerTest(imageType, test) { | |
| 43 const testName = test.property + ': ' + (test.prevValue || 'unset') + ' => ' + test.property + ': ' + (test.value || 'unset'); | |
|
Timothy Loh
2016/05/11 06:20:37
unset isn't really the same as what you're doing (
ikilpatrick
2016/05/11 23:59:12
Changed to [inline not set]
| |
| 44 | |
| 45 // We use a promise_test instead of a async_test as they run sequentially. | |
| 46 promise_test(function() { | |
| 47 return new Promise(function(resolve) { | |
| 48 | |
| 49 const msg = ['\n\nTest case:', testName]; | |
| 50 if (test.noInvalidation) { | |
| 51 msg.push('The worklet console should log nothing'); | |
| 52 } else { | |
| 53 msg.push('The worklet console should log: \'Succussful invalidat ion for: ' + test.property + '\''); | |
| 54 } | |
| 55 console.log(msg.join('\n')); | |
| 56 | |
| 57 // Create the test div. | |
| 58 const el = document.createElement('div'); | |
| 59 if (test.prevValue) el.style.setProperty(test.property, test.prevVal ue); | |
| 60 el.style[imageType] = 'paint(' + test.paintName + ')'; | |
| 61 document.body.appendChild(el); | |
| 62 | |
| 63 runAfterLayoutAndPaint(function() { | |
| 64 if (window.internals) | |
| 65 internals.startTrackingRepaints(document); | |
| 66 | |
| 67 // Keep the BCR for the paint invalidation assertion, and invali date paint. | |
| 68 const rect = el.getBoundingClientRect(); | |
| 69 el.style.setProperty(test.property, test.value); | |
| 70 | |
| 71 runAfterLayoutAndPaint(function() { | |
| 72 // Check that the we got the correct paint invalidation. | |
| 73 if (window.internals) { | |
| 74 const layers = JSON.parse(internals.layerTreeAsText(docu ment, internals.LAYER_TREE_INCLUDES_PAINT_INVALIDATIONS)); | |
| 75 const paintInvalidations = layers['children'][0]['paintI nvalidations']; | |
| 76 assert_equals(!!test.noInvalidation, !paintInvalidations ); | |
|
Timothy Loh
2016/05/11 06:20:37
Argument order is reversed in all the assert calls
ikilpatrick
2016/05/11 23:59:12
Done.
| |
| 77 if (paintInvalidations) { | |
| 78 assert_equals(1, paintInvalidations.length, 'There s hould be only one paint invalidation.'); | |
| 79 assert_array_equals( | |
| 80 [rect.left, rect.top, rect.width, rect.heigh t], | |
| 81 paintInvalidations[0]['rect'], | |
| 82 'The paint invalidation should cover the ent ire element.'); | |
| 83 } | |
| 84 internals.stopTrackingRepaints(document); | |
| 85 } | |
| 86 | |
| 87 // Cleanup. | |
| 88 document.body.removeChild(el); | |
| 89 resolve(); | |
| 90 }); | |
| 91 }); | |
| 92 | |
| 93 }); | |
| 94 | |
| 95 }, testName); | |
| 96 } | |
| OLD | NEW |