File: heading.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (58 lines) | stat: -rw-r--r-- 1,933 bytes parent folder | download | duplicates (2)
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
<!doctype html>
<meta charset=utf-8>
<title>:heading and :heading() pseudo-classes</title>
<link rel="help" href="https://drafts.csswg.org/selectors-5/#headings">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<h1 data-expect-match="1"></h1>
<h2 data-expect-match="2"></h2>
<h3 data-expect-match="3"></h3>
<h4 data-expect-match="4"></h4>
<h5 data-expect-match="5"></h5>
<h6 data-expect-match="6"></h6>
<h7 data-expect-match=""></h7>
<h8 data-expect-match=""></h8>
<h9 data-expect-match=""></h9>
<h0 data-expect-match=""></h0>
<h1 data-expect-match="1" aria-level="2"></h1>
<section><h1 data-expect-match="1"></h1></section>
<hgroup data-expect-match=""></hgroup>
<p role="heading" aria-level="1" data-expect-match=""></p>

<script>
const els = document.querySelectorAll('[data-expect-match]');
const tests = [
  {args: ['1'], match: [1]},
  {args: ['2'], match: [2]},
  {args: ['3'], match: [3]},
  {args: ['4'], match: [4]},
  {args: ['5'], match: [5]},
  {args: ['6'], match: [6]},
  {args: ['7'], match: []},
  {args: ['8'], match: []},
  {args: ['9'], match: []},
  {args: ['0'], match: []},
  {args: ['0', '1', '2'], match: [1, 2]},
  {args: ['6', '7'], match: [6]},
];
for (const el of els) {
  const testName = el.outerHTML + (el.parentNode === document.body ? '' : ' in ' + el.parentNode.localName);

  test(() => {
    const matches = el.matches(':heading');
    const shouldMatch = el.dataset.expectMatch !== "";
    assert_equals(matches, shouldMatch);
  }, testName + ' :heading');

  for (const t of tests) {
    const selector = `:heading(${t.args.join(', ')})`;
    test(() => {
      const matches = el.matches(selector);
      const expectMatchLevel = parseInt(el.dataset.expectMatch, 10);
      const shouldMatch = t.match.includes(expectMatchLevel);
      assert_equals(matches, shouldMatch, selector);
    }, testName + ' ' + selector);
  }
}
</script>