blob: 772b08ee4be9a25d22c31092492645a4a146a06d [file] [log] [blame]
<!DOCTYPE html><!-- webkit-test-runner [ CSSPaintingAPIEnabled=true ] -->
<meta name="author" title="Justin Michaud" href="mailto:justin_michaud@webkit.org">
<meta name="assert" content="Test that paint worklets repaint when modules are added, and correctly watch properties">
<link rel="help" content="https://drafts.css-houdini.org/css-paint-api-1/">
<script src="resources/testharness.js"></script>
<script id="code" type="text/worklet">
class MyPaint {
static get inputProperties() { return ['--my-prop']; }
paint(ctx, geom, properties) {
if (properties.get('--my-prop') == 5) {
ctx.fillStyle = "green";
} else {
ctx.fillStyle = "red";
}
ctx.fillRect(0, 0, geom.width, geom.height);
}
}
registerPaint('my-paint', MyPaint);
</script>
<script type="text/javascript">
function onload() {
if (window.testRunner && window.internals) {
window.testRunner.dumpAsText(false);
window.internals.startTrackingRepaints();
}
// FIXME: Once importWorklet returns a promise, these setTimeouts should go away.
setTimeout(function() {
importWorklet(CSS.paintWorklet, document.getElementById('code').textContent);
}, 500);
setTimeout(function() {
paint.style.setProperty('--my-prop', 5);
}, 2000);
setTimeout(function() {
var repaintRects = "No test runner";
if (window.testRunner && window.internals) {
// force a style recalc.
var dummy = document.body.offsetTop;
repaintRects = window.internals.repaintRectsAsText();
window.internals.stopTrackingRepaints();
}
var pre = document.createElement('pre');
document.body.appendChild(pre);
pre.innerHTML = repaintRects;
}, 2500);
}
</script>
<style>
#paint {
background-image: paint(my-paint);
width: 150px;
height: 150px;
}
</style>
<body onload="onload()">
<div id="paint"></div>
</body>