File: interestfor-input-modalities.tentative.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 (144 lines) | stat: -rw-r--r-- 5,416 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<meta charset="utf-8" />
<meta name="timeout" content="long">
<link rel="author" href="mailto:masonf@chromium.org">
<link rel="help" href="https://open-ui.org/components/interest-invokers.explainer/" />
<link rel="help" href="https://github.com/whatwg/html/pull/11006" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/invoker-utils.js"></script>

<meta name=variant content=?method=hover>
<meta name=variant content=?method=focus>

<button data-testcase="<button>" interestfor=target>Button</button>

<a data-testcase="<a>" href=foo interestfor=target>Link</a>

<img src="/images/blue.png" usemap="#map" id=areatarget>
<map id=map>
  <area data-testcase="<area>" data-hover="areatarget" interestfor=target href="/" shape=default>
</map>

<svg viewBox="0 0 100 100" style="width: 100px" xmlns="http://www.w3.org/2000/svg">
  <a data-testcase="SVG <a>" href=foo interestfor=target>
    <text x=50 y=90>SVG A</text>
  </a>
</svg>

<div id=target>Target</div>
<button id=otherbutton>Other button</button>

<style>
  [interestfor] {
    interest-delay: 0s;
  }
</style>

<script>
const allInterestForElements = document.querySelectorAll('[data-testcase]');
assert_true(allInterestForElements.length > 0);
function verifyInterest(onlyElements,description) {
  if (!(onlyElements instanceof Array)) {
    onlyElements = [onlyElements];
  }
  [...allInterestForElements, another].forEach(el => {
    const expectInterest = onlyElements.includes(el);
    assert_equals(el.matches(':interest-source'),expectInterest,`${description}, element ${el.dataset.testcase} should ${expectInterest ? "" : "NOT "}have interest`);
  })
}
function reinsert(element) {
  const parent = element.parentElement;
  const nextSibling = element.nextSibling;
  element.remove();
  parent.insertBefore(element,nextSibling);
}
function preventEvent(shouldCancel,el,type) {
  if (shouldCancel) {
    assert_not_equals(type,'focusin','focusin can\'t be cancelled');
    assert_not_equals(type,'focusout','focusout can\'t be cancelled');
    el.addEventListener(type, (e) => e.preventDefault(), {once:true});
  }
}

const urlParams = new URLSearchParams(window.location.search);
method = urlParams.get('method');
['none','cancel-trigger','cancel-lose'].forEach(cancelEvent => {
  allInterestForElements.forEach(el => {
    const description = `${el.dataset.testcase}, ${cancelEvent}, ${method}`;
    promise_test(async function (t) {
      t.add_cleanup(() => {
        reinsert(el);
        reinsert(target);
      });
      assert_false(el.matches(':interest-source'),'setup');
      assert_false(target.matches(':interest-target'),'setup');
      const signal = t.get_signal();
      let interestCount = 0;
      let loseInterestCount = 0;
      target.addEventListener('interest', (e) => (++interestCount), {signal});
      target.addEventListener('loseinterest', () => (++loseInterestCount), {signal});
      const cancelTrigger = cancelEvent === 'cancel-trigger';
      const cancelLose = cancelEvent === 'cancel-lose';
      assert_true(cancelTrigger || cancelLose || cancelEvent === 'none');

      switch (method) {
        case 'hover':
          preventEvent(cancelTrigger,el,'mouseover');
          hovertarget = el;
          if (el.dataset.hover) {
            hovertarget = document.getElementById(el.dataset.hover);
          }
          await hoverOver(hovertarget)
          break;
        case 'focus':
          if (cancelTrigger) {
            return; // focusin cannot be cancelled, nothing to test
          }
          await focusOn(el);
          break;
        default:
          assert_unreached();
      }
      assert_equals(loseInterestCount, 0, 'Lose interest should not be fired yet');
      if (cancelTrigger) {
        assert_equals(interestCount, 0, 'Because the trigger event was cancelled, interest should not be fired');
        assert_false(el.matches(':interest-source'),':interest-source should not match');
      } else {
        assert_equals(interestCount, 1, 'Interest should be fired');
        assert_true(el.matches(':interest-source'),':interest-source should match');
      }
      interestCount = 0;

      switch (method) {
        case 'hover':
          preventEvent(cancelLose,el,'mouseout');
          await hoverOver(otherbutton);
          break;
        case 'focus':
          if (cancelLose) {
            return; // focusout cannot be cancelled, nothing to test
          }
          await focusOn(otherbutton);
          break;
        default:
          assert_unreached();
      }
      assert_equals(interestCount, 0, 'No new interest event should be fired');
      if (cancelTrigger || cancelLose) {
        assert_equals(loseInterestCount, 0, 'No lose interest event should be fired');
      } else {
        assert_equals(loseInterestCount, 1, 'Lose interest event should be fired');
      }
      if (cancelLose) {
        assert_true(el.matches(':interest-source'),':interest-source should still match because we canceled the triggering event');
      } else {
        assert_false(el.matches(':interest-source'),':interest-source should not match');
      }
    },`Basic behavior, ${description}`);
  });
});
</script>