summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-layout-api/edges/support/edges.js
blob: b70a42f398c34f0d3a7981fec16447ffa8a1e97e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {areArraysEqual} from '/common/arrays.js';

function parseNumber(value) {
  const num = parseInt(value.toString());
  if (isNaN(num)) return 0;
  return num;
}

registerLayout('test', class {
  static get inputProperties() {
    return [
      '--edges-inline-start-expected',
      '--edges-inline-end-expected',
      '--edges-block-start-expected',
      '--edges-block-end-expected',
    ];
  }

  async intrinsicSizes() {}
  async layout(children, edges, constraints, styleMap) {
    const actual = this.constructor.inputProperties.map(
      prop => parseNumber(styleMap.get(prop))
    );

    const expected = [
      edges.inlineStart,
      edges.inlineEnd,
      edges.blockStart,
      edges.blockEnd,
    ];

    if (!areArraysEqual(expected, actual)) {
      return {autoBlockSize: 0, childFragments: []};
    }

    return {autoBlockSize: 100, childFragment: []};
  }
});