diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/css/css-paint-api/resources | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/css-paint-api/resources')
-rw-r--r-- | testing/web-platform/tests/css/css-paint-api/resources/html5.png | bin | 0 -> 1302 bytes | |||
-rw-r--r-- | testing/web-platform/tests/css/css-paint-api/resources/imported-module.mjs | 2 | ||||
-rw-r--r-- | testing/web-platform/tests/css/css-paint-api/resources/utils.js | 58 |
3 files changed, 60 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-paint-api/resources/html5.png b/testing/web-platform/tests/css/css-paint-api/resources/html5.png Binary files differnew file mode 100644 index 0000000000..e34419263f --- /dev/null +++ b/testing/web-platform/tests/css/css-paint-api/resources/html5.png diff --git a/testing/web-platform/tests/css/css-paint-api/resources/imported-module.mjs b/testing/web-platform/tests/css/css-paint-api/resources/imported-module.mjs new file mode 100644 index 0000000000..2a23b33414 --- /dev/null +++ b/testing/web-platform/tests/css/css-paint-api/resources/imported-module.mjs @@ -0,0 +1,2 @@ +// This doesn't need to contain anything. If it's dynamically import()ed +// successfully, the test fails. diff --git a/testing/web-platform/tests/css/css-paint-api/resources/utils.js b/testing/web-platform/tests/css/css-paint-api/resources/utils.js new file mode 100644 index 0000000000..e968644136 --- /dev/null +++ b/testing/web-platform/tests/css/css-paint-api/resources/utils.js @@ -0,0 +1,58 @@ + +// Register a property, and interpolate its value to the halfway point. +function registerAndInterpolateProperty(options) { + CSS.registerProperty({ + name: options.name, + syntax: `${options.syntax} | none`, + initialValue: 'none', + inherits: false + }); + let animation = options.on.animate([ + { [options.name]: options.from }, + { [options.name]: options.to } + ], 1000); + animation.currentTime = 500; + animation.pause(); +} + +// Apply a paint worklet to 'target' which verifies that the worklet-side value +// of a set of properties is what we expect. +// +// The 'expected' parameter is an object where each key is the name of a +// property to check, and each corresponding value is an array with the expected +// (serialized) values for that property. +function expectWorkletValues(target, expected) { + const workletName = 'registered-property-value'; + + // Wrap any single values in an array. This makes it possible to omit the + // array if there is only one value. + const ensureArray = x => x.constructor === Array ? x : [x]; + expected = Object.entries(expected).map(([k, v]) => [k, ensureArray(v)]) + .map(x => ({[x[0]]: x[1]})) + .reduce((a, b) => Object.assign(a, b), {}); + + target.style.setProperty('width', '100px'); + target.style.setProperty('height', '100px'); + target.style.setProperty('background-image', `paint(${workletName})`); + + const worklet = ` + const expectedData = ${JSON.stringify(expected)}; + const expectedKeys = Object.keys(expectedData).sort(); + registerPaint('${workletName}', class { + static get inputProperties() { return expectedKeys; } + paint(ctx, geom, styleMap) { + let serialize = (v) => '[' + v.constructor.name + ' ' + v.toString() + ']'; + let actual = expectedKeys.map(k => styleMap.getAll(k).map(serialize).join(', ')).join(' | '); + let expected = expectedKeys.map(k => expectedData[k].join(', ')).join(' | '); + ctx.fillStyle = (actual === expected) ? 'green' : 'red'; + ctx.fillRect(0, 0, geom.width, geom.height); + } + });` + + importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, worklet); +} + +// Like expectWorkletValues, but can only test a single property. +function expectWorkletValue(target, property, expected) { + expectWorkletValues(target, { [property]: expected }); +} |