|
17 | 17 | <button id=otherbutton>Other button</button>
|
18 | 18 | <style>
|
19 | 19 | [interestfor] { interest-delay: 0s; }
|
| 20 | + :interest-source { background-color: lightgreen;} |
| 21 | + :interest-target { background-color: lightblue;} |
20 | 22 | </style>
|
21 | 23 |
|
22 | 24 | <script>
|
|
25 | 27 | const target = document.getElementById('target');
|
26 | 28 | const otherbutton = document.getElementById('otherbutton');
|
27 | 29 |
|
28 |
| -promise_test(async function (t) { |
29 |
| - t.add_cleanup(() => focusOn(otherbutton)); |
30 |
| - const signal = t.get_signal(); |
31 |
| - let interestCount = 0; |
32 |
| - let loseInterestCount = 0; |
33 |
| - target.addEventListener('interest',() => (++interestCount),{signal}); |
34 |
| - target.addEventListener('loseinterest',() => (++loseInterestCount),{signal}); |
35 |
| - await focusOn(invoker); |
36 |
| - assert_true(invoker.matches(':interest-source'),'focusing invoker should show interest'); |
37 |
| - assert_equals(interestCount,1,'One interest event'); |
38 |
| - interestCount = 0; |
39 |
| - assert_equals(loseInterestCount,0,'No loseinterest events'); |
40 |
| - await focusOn(innerSpan); |
41 |
| - assert_true(invoker.matches(':interest-source'),'focusing inner span should keep interest'); |
42 |
| - assert_equals(interestCount,0,'No extra interest events'); |
43 |
| - assert_equals(loseInterestCount,0,'No loseinterest events'); |
44 |
| - await focusOn(invoker); |
45 |
| - assert_true(invoker.matches(':interest-source'),'focusing back to outer button should keep interest'); |
46 |
| - assert_equals(interestCount,0,'No extra interest events'); |
47 |
| - assert_equals(loseInterestCount,0,'No loseinterest events'); |
48 |
| - await focusOn(otherbutton); |
49 |
| - assert_false(invoker.matches(':interest-source'),'focusing outside should lose interest'); |
50 |
| - assert_equals(interestCount,0,'No extra interest events'); |
51 |
| - assert_equals(loseInterestCount,1,'Finally got loseinterest event'); |
52 |
| -},'Moving focus within invoker works correctly'); |
| 30 | +async function showInterest(el, method) { |
| 31 | + if (method === 'focus') { |
| 32 | + await focusOn(el); |
| 33 | + } else { |
| 34 | + assert_equals(method,'hover'); |
| 35 | + await hoverOver(el); |
| 36 | + } |
| 37 | +} |
53 | 38 |
|
54 |
| -promise_test(async function (t) { |
55 |
| - t.add_cleanup(() => focusOn(otherbutton)); |
56 |
| - const signal = t.get_signal(); |
57 |
| - let interestCount = 0; |
58 |
| - let loseInterestCount = 0; |
59 |
| - target.addEventListener('interest',() => (++interestCount),{signal}); |
60 |
| - target.addEventListener('loseinterest',() => (++loseInterestCount),{signal}); |
61 |
| - await hoverOver(invoker); |
62 |
| - assert_true(invoker.matches(':interest-source'),'hovering invoker should show interest'); |
63 |
| - assert_equals(interestCount,1,'One interest event'); |
64 |
| - interestCount = 0; |
65 |
| - assert_equals(loseInterestCount,0,'No loseinterest events'); |
66 |
| - await hoverOver(innerSpan); |
67 |
| - assert_true(invoker.matches(':interest-source'),'hovering inner span should keep interest'); |
68 |
| - assert_equals(interestCount,0,'No extra interest events'); |
69 |
| - assert_equals(loseInterestCount,0,'No loseinterest events'); |
70 |
| - await hoverOver(invoker); |
71 |
| - assert_true(invoker.matches(':interest-source'),'hovering back to outer button should keep interest'); |
72 |
| - assert_equals(interestCount,0,'No extra interest events'); |
73 |
| - assert_equals(loseInterestCount,0,'No loseinterest events'); |
74 |
| - await hoverOver(otherbutton); |
75 |
| - assert_false(invoker.matches(':interest-source'),'hovering outside should lose interest'); |
76 |
| - assert_equals(interestCount,0,'No extra interest events'); |
77 |
| - assert_equals(loseInterestCount,1,'Finally got loseinterest event'); |
78 |
| -},'Moving hover within invoker works correctly'); |
| 39 | +['focus','hover'].forEach(method => { |
| 40 | + promise_test(async function (t) { |
| 41 | + t.add_cleanup(() => showInterest(otherbutton, method)); |
| 42 | + const signal = t.get_signal(); |
| 43 | + let interestCount = 0; |
| 44 | + let loseInterestCount = 0; |
| 45 | + target.addEventListener('interest',() => (++interestCount),{signal}); |
| 46 | + target.addEventListener('loseinterest',() => (++loseInterestCount),{signal}); |
| 47 | + await showInterest(invoker, method); |
| 48 | + assert_true(invoker.matches(':interest-source'),'focusing invoker should show interest'); |
| 49 | + assert_equals(interestCount,1,'One interest event'); |
| 50 | + interestCount = 0; |
| 51 | + assert_equals(loseInterestCount,0,'No loseinterest events'); |
| 52 | + await showInterest(innerSpan, method); |
| 53 | + assert_true(invoker.matches(':interest-source'),'focusing inner span should keep interest'); |
| 54 | + assert_equals(interestCount,0,'No extra interest events'); |
| 55 | + assert_equals(loseInterestCount,0,'No loseinterest events'); |
| 56 | + await showInterest(invoker, method); |
| 57 | + assert_true(invoker.matches(':interest-source'),'focusing back to outer button should keep interest'); |
| 58 | + assert_equals(interestCount,0,'No extra interest events'); |
| 59 | + assert_equals(loseInterestCount,0,'No loseinterest events'); |
| 60 | + await showInterest(otherbutton, method); |
| 61 | + assert_false(invoker.matches(':interest-source'),'focusing outside should lose interest'); |
| 62 | + assert_equals(interestCount,0,'No extra interest events'); |
| 63 | + assert_equals(loseInterestCount,1,'Finally got loseinterest event'); |
| 64 | + },`Moving focus within invoker, ${method}`); |
| 65 | +}); |
79 | 66 | </script>
|
80 | 67 |
|
81 | 68 | <a id=outer href="#" interestfor="middle">Outer</a>
|
|
90 | 77 | const middleLink = document.getElementById('middle-link');
|
91 | 78 | const inner = document.getElementById('inner');
|
92 | 79 | const innerButton = document.getElementById('inner-button');
|
93 |
| -promise_test(async function (t) { |
94 |
| - t.add_cleanup(() => focusOn(otherbutton)); |
95 |
| - assert_false(middle.matches(':popover-open'),'middle starts closed'); |
96 |
| - await focusOn(outer); |
97 |
| - assert_true(outer.matches(':interest-source'),'focusing outer should show interest'); |
98 |
| - assert_true(middle.matches(':popover-open'),'outer popover open'); |
99 | 80 |
|
100 |
| - await focusOn(middleLink); |
101 |
| - assert_true(middleLink.matches(':interest-source'),'focusing middle should show interest'); |
102 |
| - assert_true(outer.matches(':interest-source'),'outer keeps interest'); |
103 |
| - assert_true(middle.matches(':popover-open'),'middle popover stays open'); |
104 |
| - assert_true(inner.matches(':popover-open'),'inner popover opens'); |
| 81 | +['focus','hover'].forEach(method => { |
| 82 | + promise_test(async function (t) { |
| 83 | + t.add_cleanup(() => showInterest(otherbutton, method)); |
| 84 | + assert_false(middle.matches(':popover-open'),'middle starts closed'); |
| 85 | + await showInterest(outer, method); |
| 86 | + assert_true(outer.matches(':interest-source'),'focusing outer should show interest'); |
| 87 | + assert_true(middle.matches(':popover-open'),'outer popover open'); |
105 | 88 |
|
106 |
| - await focusOn(innerButton); |
107 |
| - assert_true(outer.matches(':interest-source'),'outer keeps interest'); |
108 |
| - assert_true(middleLink.matches(':interest-source'),'middle keeps interest'); |
109 |
| - assert_true(middle.matches(':popover-open'),'middle popover stays open'); |
110 |
| - assert_true(inner.matches(':popover-open'),'inner popover stays open'); |
111 |
| -},'Nested invokers maintain interest properly (focus)'); |
| 89 | + await showInterest(middleLink, method); |
| 90 | + assert_true(middleLink.matches(':interest-source'),'focusing middle should show interest'); |
| 91 | + assert_true(outer.matches(':interest-source'),'outer keeps interest'); |
| 92 | + assert_true(middle.matches(':popover-open'),'middle popover stays open'); |
| 93 | + assert_true(inner.matches(':popover-open'),'inner popover opens'); |
112 | 94 |
|
113 |
| -promise_test(async function (t) { |
114 |
| - t.add_cleanup(() => focusOn(otherbutton)); |
115 |
| - assert_false(middle.matches(':popover-open'),'middle starts closed'); |
116 |
| - await hoverOver(outer); |
117 |
| - assert_true(outer.matches(':interest-source'),'hovering outer should show interest'); |
118 |
| - assert_true(middle.matches(':popover-open'),'outer popover open'); |
119 |
| - |
120 |
| - await hoverOver(middleLink); |
121 |
| - assert_true(outer.matches(':interest-source'),'outer keeps interest'); |
122 |
| - assert_true(middle.matches(':popover-open'),'middle popover stays open'); |
123 |
| - assert_true(middleLink.matches(':interest-source'),'hovering middle should show interest'); |
124 |
| - assert_true(inner.matches(':popover-open'),'inner popover opens'); |
125 |
| - |
126 |
| - await hoverOver(innerButton); |
127 |
| - assert_true(outer.matches(':interest-source'),'outer keeps interest'); |
128 |
| - assert_true(middleLink.matches(':interest-source'),'middle keeps interest'); |
129 |
| - assert_true(middle.matches(':popover-open'),'middle popover stays open'); |
130 |
| - assert_true(inner.matches(':popover-open'),'inner popover stays open'); |
131 |
| -},'Nested invokers maintain interest properly (hover)'); |
| 95 | + await showInterest(innerButton, method); |
| 96 | + assert_true(outer.matches(':interest-source'),'outer keeps interest'); |
| 97 | + assert_true(middleLink.matches(':interest-source'),'middle keeps interest'); |
| 98 | + assert_true(middle.matches(':popover-open'),'middle popover stays open'); |
| 99 | + assert_true(inner.matches(':popover-open'),'inner popover stays open'); |
| 100 | + },`Nested invokers, ${method}`); |
| 101 | +}); |
132 | 102 | </script>
|
0 commit comments