Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Unified Diff: third_party/WebKit/LayoutTests/csspaint/resources/test-runner-invalidation-logging.js

Issue 1896893004: Hook up style invalidation for CSS Paint API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@css-paint-register
Patch Set: fix component build. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698