summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/boxmodel/test/browser_boxmodel_properties.js
blob: 6ebf5ab761c8ec7e7efd42668abf0e5b32e5b777 (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";

// Test that the box model properties list displays the right values
// and that it updates when the node's style is changed.

const TEST_URI = `
  <style type='text/css'>
    div {
      box-sizing: border-box;
      display: block;
      float: left;
      line-height: 20px;
      position: relative;
      z-index: 2;
      height: 100px;
      width: 100px;
      border: 10px solid black;
      padding: 20px;
      margin: 30px auto;
    }
  </style>
  <div>Test Node</div>
`;

const res1 = [
  {
    property: "box-sizing",
    value: "border-box",
  },
  {
    property: "display",
    value: "block",
  },
  {
    property: "float",
    value: "left",
  },
  {
    property: "line-height",
    value: "20px",
  },
  {
    property: "position",
    value: "relative",
  },
  {
    property: "z-index",
    value: "2",
  },
];

const res2 = [
  {
    property: "box-sizing",
    value: "content-box",
  },
  {
    property: "display",
    value: "block",
  },
  {
    property: "float",
    value: "right",
  },
  {
    property: "line-height",
    value: "10px",
  },
  {
    property: "position",
    value: "static",
  },
  {
    property: "z-index",
    value: "5",
  },
];

add_task(async function () {
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  const { inspector, boxmodel } = await openLayoutView();
  await selectNode("div", inspector);

  await testInitialValues(inspector, boxmodel);
  await testChangingValues(inspector, boxmodel);
});

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

  for (const { property, value } of res1) {
    const elt = doc.querySelector(getPropertySelector(property));
    is(elt.textContent, value, property + " has the right value.");
  }
}

async function testChangingValues(inspector, boxmodel) {
  info("Test that changing the document updates the box model");
  const doc = boxmodel.document;

  const onUpdated = waitForUpdate(inspector);
  await setContentPageElementAttribute(
    "div",
    "style",
    "box-sizing:content-box;float:right;" +
      "line-height:10px;position:static;z-index:5;"
  );
  await onUpdated;

  for (const { property, value } of res2) {
    const elt = doc.querySelector(getPropertySelector(property));
    is(
      elt.textContent,
      value,
      property + " has the right value after style update."
    );
  }
}

function getPropertySelector(propertyName) {
  return (
    `.boxmodel-container .computed-property-view` +
    `[data-property-name=${propertyName}] .computed-property-value`
  );
}