gecko-dev/testing/web-platform/tests/common/worklet-reftest.js
Anders Hartvoll Ruud a59d54df31 Bug 1503698 [wpt PR 13822] - [css-properties-values-api] Invalidate paint worklet on registration., a=testonly
Automatic update from web-platform-tests[css-properties-values-api] Invalidate paint worklet on registration.

Due to how initial values of registered custom properties used to be
handled, the style diff function for custom paint could not discover that
the computed value for some property changed due to a new property
registration.

This meant that, if you used the property '--x' in your paint worklet
(without applying '--x' on any element in the document), and _then_
registered the property '--x' (giving it an initial value), the worklet
would not repaint even though the computed value of --x changed from
"nothing" to the registered initial value.

Now that initial values are returned from ::GetRegisteredVariable, simply
compare those values when diffing for custom paint invalidation.

Note that the second test in this CL is already passing before this CL,
but I'm including it anyway since that case is also mentioned in the bug.

R=ikilpatrick@chromium.org

Bug: 657706
Change-Id: I2b7707d48d73693a70b100fe1121bd7f977b4db1
Reviewed-on: https://chromium-review.googlesource.com/c/1309788
Commit-Queue: Anders Ruud <andruud@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604607}

--

wpt-commits: 2a5673603f719fed9b3dce2f6bde705057b90599
wpt-pr: 13822
2018-11-10 09:03:04 +00:00

38 lines
1.1 KiB
JavaScript

// Imports code into a worklet. E.g.
//
// importWorklet(CSS.paintWorklet, {url: 'script.js'});
// importWorklet(CSS.paintWorklet, '/* javascript string */');
function importWorklet(worklet, code) {
let url;
if (typeof code === 'object') {
url = code.url;
} else {
const blob = new Blob([code], {type: 'text/javascript'});
url = URL.createObjectURL(blob);
}
return worklet.addModule(url);
}
async function animationFrames(frames) {
for (let i = 0; i < frames; i++)
await new Promise(requestAnimationFrame);
}
async function workletPainted() {
await animationFrames(2);
}
// To make sure that we take the snapshot at the right time, we do double
// requestAnimationFrame. In the second frame, we take a screenshot, that makes
// sure that we already have a full frame.
async function importWorkletAndTerminateTestAfterAsyncPaint(worklet, code) {
if (typeof worklet === 'undefined') {
takeScreenshot();
return;
}
await importWorklet(worklet, code);
await workletPainted();
takeScreenshot();
}