summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/boxmodel/test/browser_boxmodel_positions.js
blob: ca182d713011a7aa437b73032fe665eabd0687e9 (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that the box model displays the right values for positions.

const TEST_URI = `
  <style type='text/css'>
    div {
      position: absolute;
      left: 0;
      margin: 0;
      padding: 0;
      display: none;
      height: 100px;
      width: 100px;
      border: 10px solid black;
    }
  </style>
  <div>Test Node</div>
`;

// Expected values:
const res1 = [
  {
    selector: ".boxmodel-position.boxmodel-top > span",
    value: "auto",
  },
  {
    selector: ".boxmodel-position.boxmodel-right > span",
    value: "auto",
  },
  {
    selector: ".boxmodel-position.boxmodel-bottom > span",
    value: "auto",
  },
  {
    selector: ".boxmodel-position.boxmodel-left > span",
    value: "0",
  },
];

add_task(async function () {
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  const { inspector, boxmodel } = await openLayoutView();
  const node = await getNodeFront("div", inspector);
  const children = await inspector.markup.walker.children(node);
  const beforeElement = children.nodes[0];

  await selectNode(beforeElement, inspector);
  await testPositionValues(inspector, boxmodel);
});

function testPositionValues(inspector, boxmodel) {
  info("Test that the position values of the box model are correct");
  const doc = boxmodel.document;

  for (let i = 0; i < res1.length; i++) {
    const elt = doc.querySelector(res1[i].selector);
    is(
      elt.textContent,
      res1[i].value,
      res1[i].selector + " has the right value."
    );
  }
}