summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-cascade/scope-focus.html
blob: 578a7702c1dcedebe2933c6a5b25f100a1a58899 (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
<!DOCTYPE html>
<title>@scope and :focus</title>
<link rel="help" href="https://drafts.csswg.org/css-cascade-6/#scope-atrule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<main id=main></main>

<template id=test_subject>
  <div>
    <style>
        @scope (.a:focus) {
          :scope { z-index: 1; }
        }
    </style>
    <div class=a tabindex=0>1</div>
</template>
<script>
promise_test(async (t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_subject.content.cloneNode(true));

  let a = main.querySelector('.a');

  assert_equals(getComputedStyle(a).zIndex, 'auto');
  await test_driver.bless('focus', () => a.focus());
  assert_equals(getComputedStyle(a).zIndex, '1');
}, ':focus via :scope in subject');
</script>

<template id=test_non_subject>
  <div>
    <style>
        @scope (.a:focus) {
          :scope .b { z-index: 1; }
        }
    </style>
    <div class=a tabindex=0>
      <div class=b>2</div>
    </div>
</template>
<script>
promise_test(async (t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_non_subject.content.cloneNode(true));

  let a = main.querySelector('.a');
  let b = main.querySelector('.b');

  assert_equals(getComputedStyle(b).zIndex, 'auto');
  await test_driver.bless('focus', () => a.focus());
  assert_equals(getComputedStyle(b).zIndex, '1');
}, ':focus via :scope in non-subject');
</script>

<template id=test_subject_limit>
  <div>
    <style>
        @scope (.a) to (:scope:focus) {
          :scope { z-index: 1; }
        }
    </style>
    <div class=a tabindex=0>3</div>
</template>
<script>
promise_test(async (t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_subject_limit.content.cloneNode(true));

  let a = main.querySelector('.a');

  assert_equals(getComputedStyle(a).zIndex, '1');
  await test_driver.bless('focus', () => a.focus());
  // After focus(), we're no longer in scope because the limit (to-selector)
  // kicks in.
  assert_equals(getComputedStyle(a).zIndex, 'auto');
}, ':focus in limit, :scope in subject');
</script>

<template id=test_non_subject_limit>
  <div>
    <style>
        @scope (.a) to (.b:focus) {
          .b { z-index: 1; }
        }
    </style>
    <div class=a tabindex=0>
      <div class=b tabindex=1>4</div>
    </div>
</template>
<script>
promise_test(async (t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_non_subject_limit.content.cloneNode(true));

  let a = main.querySelector('.a');
  let b = main.querySelector('.b');

  assert_equals(getComputedStyle(b).zIndex, '1');
  await test_driver.bless('focus', () => b.focus());
  // After focus(), we're no longer in scope because the limit (to-selector)
  // kicks in.
  assert_equals(getComputedStyle(b).zIndex, 'auto');
}, ':focus in intermediate limit, :scope in subject');
</script>