summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/grids/test/browser_grids_grid-outline-writing-mode.js
blob: c27a8b481f070a55d080a2f87fb6ab2238dcb834 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that the grid outline adjusts to match the container's writing mode.

const TEST_URI = `
  <style type='text/css'>
    .grid {
      display: grid;
      width: 400px;
      height: 300px;
    }
    .rtl {
      direction: rtl;
    }
    .v-rl {
      writing-mode: vertical-rl;
    }
    .v-lr {
      writing-mode: vertical-lr;
    }
    .s-rl {
      writing-mode: sideways-rl;
    }
    .s-lr {
      writing-mode: sideways-lr;
    }
  </style>
  <div class="grid">
    <div id="cella">Cell A</div>
    <div id="cellb">Cell B</div>
    <div id="cellc">Cell C</div>
  </div>
  <div class="grid rtl">
    <div id="cella">Cell A</div>
    <div id="cellb">Cell B</div>
    <div id="cellc">Cell C</div>
  </div>
  <div class="grid v-rl">
    <div id="cella">Cell A</div>
    <div id="cellb">Cell B</div>
    <div id="cellc">Cell C</div>
  </div>
  <div class="grid v-lr">
    <div id="cella">Cell A</div>
    <div id="cellb">Cell B</div>
    <div id="cellc">Cell C</div>
  </div>
  <div class="grid s-rl">
    <div id="cella">Cell A</div>
    <div id="cellb">Cell B</div>
    <div id="cellc">Cell C</div>
  </div>
  <div class="grid s-lr">
    <div id="cella">Cell A</div>
    <div id="cellb">Cell B</div>
    <div id="cellc">Cell C</div>
  </div>
`;

add_task(async function () {
  await pushPref("devtools.gridinspector.maxHighlighters", 1);
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));

  const { inspector, gridInspector } = await openLayoutView();
  const { document: doc } = gridInspector;
  const { highlighters, store } = inspector;

  info("Checking the initial state of the Grid Inspector.");
  ok(
    !doc.getElementById("grid-outline-container"),
    "There should be no grid outline shown."
  );

  let elements;

  elements = await enableGrid(doc, highlighters, store, 0);
  is(
    elements[0].style.transform,
    "matrix(1, 0, 0, 1, 0, 0)",
    "Transform matches for horizontal-tb and ltr."
  );
  await disableGrid(doc, highlighters, store, 0);

  elements = await enableGrid(doc, highlighters, store, 1);
  is(
    elements[0].style.transform,
    "matrix(-1, 0, 0, 1, 200, 0)",
    "Transform matches for horizontal-tb and rtl"
  );
  await disableGrid(doc, highlighters, store, 1);

  elements = await enableGrid(doc, highlighters, store, 2);
  is(
    elements[0].style.transform,
    "matrix(6.12323e-17, 1, -1, 6.12323e-17, 200, 0)",
    "Transform matches for vertical-rl and ltr"
  );
  await disableGrid(doc, highlighters, store, 2);

  elements = await enableGrid(doc, highlighters, store, 3);
  is(
    elements[0].style.transform,
    "matrix(-6.12323e-17, 1, 1, 6.12323e-17, 0, 0)",
    "Transform matches for vertical-lr and ltr"
  );
  await disableGrid(doc, highlighters, store, 3);

  elements = await enableGrid(doc, highlighters, store, 4);
  is(
    elements[0].style.transform,
    "matrix(6.12323e-17, 1, -1, 6.12323e-17, 200, 0)",
    "Transform matches for sideways-rl and ltr"
  );
  await disableGrid(doc, highlighters, store, 4);

  elements = await enableGrid(doc, highlighters, store, 5);
  is(
    elements[0].style.transform,
    "matrix(6.12323e-17, -1, 1, 6.12323e-17, -9.18485e-15, 150)",
    "Transform matches for sideways-lr and ltr"
  );
  await disableGrid(doc, highlighters, store, 5);
});

async function enableGrid(doc, highlighters, store, index) {
  info(`Enabling the CSS grid highlighter for grid ${index}.`);
  const onHighlighterShown = highlighters.once("grid-highlighter-shown");
  const onCheckboxChange = waitUntilState(
    store,
    state => state.grids.length == 6 && state.grids[index].highlighted
  );
  const onGridOutlineRendered = waitForDOM(doc, "#grid-cell-group");
  const gridList = doc.getElementById("grid-list");
  gridList.children[index].querySelector("input").click();
  await onHighlighterShown;
  await onCheckboxChange;
  return onGridOutlineRendered;
}

async function disableGrid(doc, highlighters, store, index) {
  info(`Disabling the CSS grid highlighter for grid ${index}.`);
  const onHighlighterShown = highlighters.once("grid-highlighter-hidden");
  const onCheckboxChange = waitUntilState(
    store,
    state => state.grids.length == 6 && !state.grids[index].highlighted
  );
  const onGridOutlineRemoved = waitForDOM(doc, "#grid-cell-group", 0);
  const gridList = doc.getElementById("grid-list");
  gridList.children[index].querySelector("input").click();
  await onHighlighterShown;
  await onCheckboxChange;
  return onGridOutlineRemoved;
}