Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/csspaint/resources/test-runner-invalidation-logging.js |
| diff --git a/third_party/WebKit/LayoutTests/csspaint/resources/test-runner-invalidation-logging.js b/third_party/WebKit/LayoutTests/csspaint/resources/test-runner-invalidation-logging.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4035fd36948e78db3a25e99ce8b3e6ab5b166733 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/csspaint/resources/test-runner-invalidation-logging.js |
| @@ -0,0 +1,96 @@ |
| +// Test runner for the paint worklet to test invalidation behaviour. |
| +// |
| +// 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.
|
| +// - Creates an element. |
| +// - Invalidates the style of that element. |
| +// - [worklet] Worklet code logs if it got the invalidation. |
| +// - Asserts that it got the correct paint invalidation. |
| +// |
| +// Usage: |
| +// testRunnerInvalidationLogging('background-image', [ |
| +// { property: 'max-height', value: '100px' }, |
| +// { property: 'color', prevValue: '#00F', value: 'blue', noInvalidation: true }, |
| +// ]); |
| + |
| +function testRunnerInvalidationLogging(imageType, tests) { |
| + const keys = tests.map(function(obj) { return obj.property; }); |
| + const workletCode = 'const properties = ' + JSON.stringify(keys) + ';\n' + ` |
| + for (let i = 0; i < properties.length; i++) { |
| + registerPaint('paint-' + i, class { |
| + static get inputProperties() { return [properties[i]]; } |
| + constructor() { this.hasPainted= false; } |
| + paint(ctx, geom) { |
| + ctx.fillStyle = this.hasPainted ? 'green' : 'blue'; |
| + ctx.fillRect(0, 0, geom.width, geom.height); |
| + if (this.hasPainted) { |
| + console.log('Successful invalidation for: ' + properties[i]); |
| + } |
| + this.hasPainted = true; |
| + } |
| + }); |
| + } |
| + `; |
| + |
| + paintWorklet.import(URL.createObjectURL(new Blob([workletCode]))).then(function() { |
| + for (let i = 0; i < tests.length; i++) { |
| + tests[i].paintName = 'paint-' + i; |
| + registerTest(imageType, tests[i]); |
| + } |
| + }); |
| +} |
| + |
| +function registerTest(imageType, test) { |
| + 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]
|
| + |
| + // We use a promise_test instead of a async_test as they run sequentially. |
| + promise_test(function() { |
| + return new Promise(function(resolve) { |
| + |
| + const msg = ['\n\nTest case:', testName]; |
| + if (test.noInvalidation) { |
| + msg.push('The worklet console should log nothing'); |
| + } else { |
| + msg.push('The worklet console should log: \'Succussful invalidation for: ' + test.property + '\''); |
| + } |
| + console.log(msg.join('\n')); |
| + |
| + // Create the test div. |
| + const el = document.createElement('div'); |
| + if (test.prevValue) el.style.setProperty(test.property, test.prevValue); |
| + el.style[imageType] = 'paint(' + test.paintName + ')'; |
| + document.body.appendChild(el); |
| + |
| + runAfterLayoutAndPaint(function() { |
| + if (window.internals) |
| + internals.startTrackingRepaints(document); |
| + |
| + // Keep the BCR for the paint invalidation assertion, and invalidate paint. |
| + const rect = el.getBoundingClientRect(); |
| + el.style.setProperty(test.property, test.value); |
| + |
| + runAfterLayoutAndPaint(function() { |
| + // Check that the we got the correct paint invalidation. |
| + if (window.internals) { |
| + const layers = JSON.parse(internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_PAINT_INVALIDATIONS)); |
| + const paintInvalidations = layers['children'][0]['paintInvalidations']; |
| + 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.
|
| + if (paintInvalidations) { |
| + assert_equals(1, paintInvalidations.length, 'There should be only one paint invalidation.'); |
| + assert_array_equals( |
| + [rect.left, rect.top, rect.width, rect.height], |
| + paintInvalidations[0]['rect'], |
| + 'The paint invalidation should cover the entire element.'); |
| + } |
| + internals.stopTrackingRepaints(document); |
| + } |
| + |
| + // Cleanup. |
| + document.body.removeChild(el); |
| + resolve(); |
| + }); |
| + }); |
| + |
| + }); |
| + |
| + }, testName); |
| +} |