summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/selectors/has-specificity.html
blob: 69fcb5b1fbe5b1256192d70e7d3262baa03661e5 (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
<!DOCTYPE html>
<title>Specificity for complex :has selectors</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://drafts.csswg.org/selectors/#specificity-rules">
<style>
  main :has(#foo) { --t0:PASS; }
  main :has(.foo) { --t0:FAIL; }

  main :has(span#foo) { --t1:PASS; }
  main :has(#foo) { --t1:FAIL; }

  main :has(.bar, #foo) { --t2:FAIL; }
  main :has(#foo, .bar) { --t2:PASS; }

  main :has(.bar, #foo) { --t3:PASS; }
  main :has(.foo, .bar) { --t3:FAIL; }

  main :has(span + span) { --t4:PASS; }
  main :has(span) { --t4:FAIL; }

  main :has(span, li, #foo) { --t5:PASS; }
  main :has(span, li, p) { --t5:FAIL; }

  main div:has(.foo) { --t6:FAIL; }
  main div.baz { --t6:PASS; }

  main div.baz { --t7:FAIL; }
  main div:has(.foo) { --t7:PASS; }
</style>
<main id=main>
  <div id=div class=baz><p><span id=foo class=foo></span><span class=bar></span><li></li></p></div>
</main>
<script>
  function test_value(name, description) {
    test(function() {
      let actual = getComputedStyle(div).getPropertyValue(name);
      assert_equals(actual, 'PASS');
    }, description);
  }

  test_value('--t0', ':has(#foo) wins over :has(.foo)');
  test_value('--t1', ':has(span#foo) wins over :has(#foo)');
  test_value('--t2', ':has(.bar, #foo) has same specificity as :has(#foo, .bar)');
  test_value('--t3', ':has(.bar, #foo) wins over :has(.foo, .bar)');
  test_value('--t4', ':has(span + span) wins over :has(span)');
  test_value('--t5', ':has(span, li, p) wins over :has(span, lo, p)');
  test_value('--t6', 'latter .baz wins over :has(.foo)');
  test_value('--t7', 'latter :has(.foo) wins over .baz');
</script>