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-layout-api/child-constraints/support/layout-child-sizes-worklet.js | |
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-layout-api/child-constraints/support/layout-child-sizes-worklet.js')
-rw-r--r-- | testing/web-platform/tests/css/css-layout-api/child-constraints/support/layout-child-sizes-worklet.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-layout-api/child-constraints/support/layout-child-sizes-worklet.js b/testing/web-platform/tests/css/css-layout-api/child-constraints/support/layout-child-sizes-worklet.js new file mode 100644 index 0000000000..5956c9a70c --- /dev/null +++ b/testing/web-platform/tests/css/css-layout-api/child-constraints/support/layout-child-sizes-worklet.js @@ -0,0 +1,67 @@ +import {areArraysEqual} from '/common/arrays.js'; + +function parseNumber(value) { + const num = parseInt(value.toString()); + if (isNaN(num)) return undefined; + return num; +} + +registerLayout('test', class { + static get childInputProperties() { + return [ + '--available-inline-size', + '--available-block-size', + '--fixed-inline-size', + '--fixed-block-size', + '--percentage-inline-size', + '--percentage-block-size', + '--inline-size-expected', + '--block-size-expected' + ]; + } + + async intrinsicSizes() {} + async layout(children, edges, constraints, styleMap) { + const childFragments = await Promise.all(children.map((child) => { + const childConstraints = {}; + const availableInlineSize = parseNumber(child.styleMap.get('--available-inline-size')); + const availableBlockSize = parseNumber(child.styleMap.get('--available-block-size')); + const fixedInlineSize = parseNumber(child.styleMap.get('--fixed-inline-size')); + const fixedBlockSize = parseNumber(child.styleMap.get('--fixed-block-size')); + const percentageInlineSize = parseNumber(child.styleMap.get('--percentage-inline-size')); + const percentageBlockSize = parseNumber(child.styleMap.get('--percentage-block-size')); + return child.layoutNextFragment({ + availableInlineSize, + availableBlockSize, + fixedInlineSize, + fixedBlockSize, + percentageInlineSize, + percentageBlockSize, + }); + })); + + const actual = childFragments.map((childFragment) => { + return { + inlineSize: childFragment.inlineSize, + blockSize: childFragment.blockSize, + }; + }); + + const expected = children.map((child) => { + return { + inlineSize: parseInt(child.styleMap.get('--inline-size-expected').toString()), + blockSize: parseInt(child.styleMap.get('--block-size-expected').toString()), + }; + }); + + const equalityFunc = (a, b) => { + return a.inlineSize == b.inlineSize && a.blockSize == b.blockSize; + }; + + if (!areArraysEqual(expected, actual, equalityFunc)) { + return {autoBlockSize: 0, childFragments}; + } + + return {autoBlockSize: 100, childFragments}; + } +}); |