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..66f9cc0c85f0fcfd04e56a36e19964a19d48e961 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/csspaint/resources/test-runner-invalidation-logging.js |
@@ -0,0 +1,68 @@ |
+// Test runner for the paint worklet to test invalidation behaviour. |
+// |
+// Calls a given function with a newly created element, and prints the expected |
+// geometry to the console. |
+// |
+// Runs each test sequentially after a layout and a paint. |
+// |
+// Usage: |
+// testRunnerInvalidationLogging('background-image', [ |
+// { property: 'max-height', value: '100px' }, |
+// { property: 'color', value: 'blue' }, |
+// ]); |
+ |
+function testRunnerInvalidationLogging(imageType, tests) { |
+ if (window.testRunner) { |
+ testRunner.waitUntilDone(); |
+ testRunner.dumpAsText(); |
+ } |
+ |
+ var keys = tests.map(function(obj) { return obj.property; }); |
+ var workletCode = 'var properties = ' + JSON.stringify(keys) + ';\n' + ` |
+ for (let i = 0; i < properties.length; i++) { |
+ registerPaint(properties[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() { |
+ var callback = function() { |
+ if (tests.length == 0) { |
+ testRunner.notifyDone(); |
+ return; |
+ } |
+ |
+ var test = tests.shift(); |
+ runIndividualTest(imageType, test, callback); |
+ }; |
+ |
+ callback(); |
+ }); |
+} |
+ |
+function runIndividualTest(imageType, test, callback) { |
+ console.log('The console should log: \'Succussful invalidation for: ' + test.property + '\''); |
+ |
+ // Create the test div. |
+ var el = document.createElement('div'); |
+ el.style[imageType] = 'paint(' + test.property + ')'; |
+ document.body.appendChild(el); |
+ |
+ runAfterLayoutAndPaint(function() { |
+ el.style.setProperty(test.property, test.value); |
+ runAfterLayoutAndPaint(function() { |
+ document.body.removeChild(el); |
+ callback(); |
+ }); |
+ }); |
+} |