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

"use strict";

// Test that hovering over a box model value will jump to its source CSS rule in the
// rules view when the shift key is pressed.

const TEST_URI = `<style>
    #box {
      margin: 5px;
    }
  </style>
  <div id="box"></div>`;

add_task(async function () {
  await pushPref("devtools.layout.boxmodel.highlightProperty", true);
  await addTab("data:text/html," + encodeURIComponent(TEST_URI));
  const { inspector, boxmodel } = await openLayoutView();
  await selectNode("#box", inspector);

  info(
    "Test that hovering over margin-top value highlights the property in rules view."
  );
  const ruleView = await inspector.getPanel("ruleview").view;
  const el = boxmodel.document.querySelector(
    ".boxmodel-margin.boxmodel-top > span"
  );

  info("Wait for mouse to hover over margin-top element.");
  const onHighlightProperty = ruleView.once("scrolled-to-element");
  EventUtils.synthesizeMouseAtCenter(
    el,
    { type: "mousemove", shiftKey: true },
    boxmodel.document.defaultView
  );
  await onHighlightProperty;

  info("Check that margin-top is visible in the rule view.");
  const { rules, styleWindow } = ruleView;
  const marginTop = rules[1].textProps[0].computed[0];
  ok(
    isInViewport(marginTop.element, styleWindow),
    "margin-top is visible in the rule view."
  );
});

function isInViewport(element, win) {
  const { top, left, bottom, right } = element.getBoundingClientRect();
  return (
    top >= 0 &&
    bottom <= win.innerHeight &&
    left >= 0 &&
    right <= win.innerWidth
  );
}