File: interestfor-basic-behavior.tentative.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (160 lines) | stat: -rw-r--r-- 6,168 bytes parent folder | download
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!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="#" 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="#" interestfor=target>
    <text x=50 y=90>SVG A</text>
  </a>
</svg>

<a data-testcase="Broken img" href="#" interestfor=target>
  <img src="broken" width="50" height="50">
</a>

<a data-testcase="SVG <use>" href="#" interestfor=target>
  <svg width="50" height="50" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
    <use xlink:href="#thick-star"></use>
  </svg>
</a>
<svg style="display: none;">
  <symbol id="thick-star" viewBox="0 0 24 24">
    <path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"
          fill="yellow" stroke="black" stroke-width="2" stroke-linejoin="round"/>
  </symbol>
</svg>

<menulist style="display:block; inset:auto; top: 300px">
  <menuitem data-testcase="<menuitem>" interestfor=target>menuitem</menuitem>
</menulist>

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

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

<script>
const menuSupported = document.createElement('menuitem') instanceof HTMLMenuItemElement;
const menu = document.querySelector('menulist:has(menuitem[data-testcase])');
if (menuSupported) {
  // A menulist needs to be open to be interactive.
  menu.showPopover();
}
let allInterestForElements = [...document.querySelectorAll('[data-testcase]')];
if (!menuSupported) {
  allInterestForElements = allInterestForElements.filter(el => el.localName !== 'menuitem');
}
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');
      assert_equals(interestCount, 1, 'Interest should be fired (cancelling the trigger event shouldn\'t cancel interest)');
      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');
      assert_equals(loseInterestCount, 1, 'Lose interest event should be fired (cancelling the trigger event shouldn\'t cancel loseinterest)' );
      assert_false(el.matches(':interest-source'),':interest-source should not match');
    },`Basic behavior, ${description}`);
  });
});
</script>