summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/CSS2/normal-flow/block-in-inline-hittest-relpos-zindex.html
blob: 221b70d44b30ebe0bb32d0949706f5b06afaa633 (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
<!DOCTYPE html>
<link rel="help" href="http://www.w3.org/TR/CSS21/visuren.html#anonymous-block-level">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
section {
  margin-bottom: 5px;
}
.target {
  background: blue;
  width: 100px;
  height: 10px;
}
</style>
<body>
  <section>
    <a href="#">
      <div class="target"></div>
    </a>
  </section>
  <section>
    <a href="#">
      <div class="target" style="z-index: 1"></div>
    </a>
  </section>
  <section>
    <a href="#">
      <div class="target" style="z-index: -1"></div>
    </a>
  </section>
  <section>
    <a href="#">
      <div class="target" style="position: relative"></div>
    </a>
  </section>
  <section>
    <a href="#">
      <div class="target" style="position: relative; z-index: 1"></div>
    </a>
  </section>
  <section>
    <a href="#">
      <div class="target" style="position: relative; z-index: -1"></div>
    </a>
  </section>
<script>
function isAncestorOf(target, ancestor) {
  for (; target; target = target.parentElement) {
    if (target === ancestor)
      return true;
  }
  return false;
}

for (const root of document.getElementsByTagName('section')) {
  const target = root.querySelector('.target');
  const target_bounds = target.getBoundingClientRect();
  const x = target_bounds.x + target_bounds.width / 2;
  const y = target_bounds.y + target_bounds.height / 2;
  const result = document.elementFromPoint(x, y);
  const a = root.querySelector('a');
  test(() => {
    // For the `<a>` link to work, the `result` must be `a` or its descendant.
    assert_true(isAncestorOf(result, a));
  }, target.style.cssText);
}
</script>
</body>