File: pointerevent_to_slotted_target.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (108 lines) | stat: -rw-r--r-- 3,115 bytes parent folder | download | duplicates (12)
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
<!DOCTYPE HTML>
<link rel="help" href="https://w3c.github.io/pointerevents/#firing-events-using-the-pointerevent-interface">
<title>Enter/leave events fired to parent after child is removed from slot</title>
<meta name="variant" content="?mouse">
<meta name="variant" content="?touch">
<meta name="variant" content="?pen">
<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="pointerevent_support.js"></script>

<template id="template">
  <style>
    div {
      width: 100px;
      height: 100px;
    }
  </style>
  <div id="parent">
    <slot id="slot">slot</slot>
  </div>
</template>

<style>
  div, my-elem {
    width: 100px;
    height: 100px;
    display: block;
  }
</style>

<my-elem id="host">
  <div id="child">child</div>
</my-elem>
<div id="done">done</div>

<script>
  "use strict";

  customElements.define(
    "my-elem",
    class extends HTMLElement {
      constructor() {
        super();
        let content = document.getElementById("template").content;
        const shadowRoot = this.attachShadow({ mode: "open" });
        shadowRoot.appendChild(content.cloneNode(true));
      }
    },
  );

  const pointer_type = location.search.substring(1);

  const shadow_host = document.getElementById("host");
  const parent = shadow_host.shadowRoot.getElementById("parent");
  const slot = parent.firstElementChild;
  const slotted_child = document.getElementById("child");
  const done = document.getElementById("done");

  let event_log = [];

  function logEvent(e) {
    if (e.eventPhase == e.AT_TARGET) {
      event_log.push(e.type + "@" + e.target.id);
    }
  }

  function setup() {
    const events = ["pointerover", "pointerout",
          "pointerenter", "pointerleave", "pointerdown", "pointerup"];
    let targets = [shadow_host, parent, slot, slotted_child];
    for (let i = 0; i < targets.length; i++) {
      events.forEach(event => targets[i].addEventListener(event, logEvent));
    }
  }

  setup();

  promise_test(async test => {
    event_log = [];

    let done_click_promise = getEvent("click", done);

    let actions = new test_driver.Actions()
        .addPointer("TestPointer", pointer_type)
        .pointerMove(0, 0, {origin: shadow_host})
        .pointerDown()
        .pointerUp()
        .pointerMove(0, 0, {origin: done})
        .pointerDown()
        .pointerUp();

    await actions.send();
    await done_click_promise;

    const expected_events = [
      "pointerover@child",
      "pointerenter@host", "pointerenter@parent", "pointerenter@slot", "pointerenter@child",
      "pointerdown@child", "pointerup@child",
      "pointerout@child",
      "pointerleave@child", "pointerleave@slot", "pointerleave@parent", "pointerleave@host"
    ];
    assert_equals(event_log.toString(), expected_events.toString(),
        "events received");
  }, `Pointer events from ${pointer_type} to slotted element and shadow-host`);
</script>