summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/grids/test/xpcshell/test_compare_fragments_geometry.js
blob: 57f617a3ec0c9ac159f5c6a31a55b83d3a8de8bc (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const {
  compareFragmentsGeometry,
} = require("resource://devtools/client/inspector/grids/utils/utils.js");

const TESTS = [
  {
    desc: "No fragments",
    grids: [[], []],
    expected: true,
  },
  {
    desc: "Different number of fragments",
    grids: [
      [{}, {}, {}],
      [{}, {}],
    ],
    expected: false,
  },
  {
    desc: "Different number of columns",
    grids: [
      [{ cols: { lines: [{}, {}] }, rows: { lines: [] } }],
      [{ cols: { lines: [{}] }, rows: { lines: [] } }],
    ],
    expected: false,
  },
  {
    desc: "Different number of rows",
    grids: [
      [{ cols: { lines: [{}, {}] }, rows: { lines: [{}] } }],
      [{ cols: { lines: [{}, {}] }, rows: { lines: [{}, {}] } }],
    ],
    expected: false,
  },
  {
    desc: "Different number of rows and columns",
    grids: [
      [{ cols: { lines: [{}] }, rows: { lines: [{}] } }],
      [{ cols: { lines: [{}, {}] }, rows: { lines: [{}, {}] } }],
    ],
    expected: false,
  },
  {
    desc: "Different column sizes",
    grids: [
      [
        {
          cols: { lines: [{ start: 0 }, { start: 500 }] },
          rows: { lines: [] },
        },
      ],
      [
        {
          cols: { lines: [{ start: 0 }, { start: 1000 }] },
          rows: { lines: [] },
        },
      ],
    ],
    expected: false,
  },
  {
    desc: "Different row sizes",
    grids: [
      [
        {
          cols: { lines: [{ start: 0 }, { start: 500 }] },
          rows: { lines: [{ start: -100 }] },
        },
      ],
      [
        {
          cols: { lines: [{ start: 0 }, { start: 500 }] },
          rows: { lines: [{ start: 0 }] },
        },
      ],
    ],
    expected: false,
  },
  {
    desc: "Different row and column sizes",
    grids: [
      [
        {
          cols: { lines: [{ start: 0 }, { start: 500 }] },
          rows: { lines: [{ start: -100 }] },
        },
      ],
      [
        {
          cols: { lines: [{ start: 0 }, { start: 505 }] },
          rows: { lines: [{ start: 0 }] },
        },
      ],
    ],
    expected: false,
  },
  {
    desc: "Complete structure, same fragments",
    grids: [
      [
        {
          cols: { lines: [{ start: 0 }, { start: 100.3 }, { start: 200.6 }] },
          rows: { lines: [{ start: 0 }, { start: 1000 }, { start: 2000 }] },
        },
      ],
      [
        {
          cols: { lines: [{ start: 0 }, { start: 100.3 }, { start: 200.6 }] },
          rows: { lines: [{ start: 0 }, { start: 1000 }, { start: 2000 }] },
        },
      ],
    ],
    expected: true,
  },
];

function run_test() {
  for (const { desc, grids, expected } of TESTS) {
    if (desc) {
      info(desc);
    }
    equal(compareFragmentsGeometry(grids[0], grids[1]), expected);
  }
}