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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
<!DOCTYPE HTML>
<!--
Tentative due to:
https://github.com/w3c/pointerevents/issues/492
-->
<title>
Enter/leave events fired to parent after child is added
right before compat mouse-event
</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>
<style>
div.target {
width: 100px;
height: 100px;
}
</style>
<div class="target" id="parent">
<div class="target" id="child">child</div>
</div>
<div id="done">done</div>
<script>
'use strict';
const pointer_type = location.search.substring(1);
const parent = document.getElementById("parent");
const child = document.getElementById("child");
const done = document.getElementById("done");
let event_log = [];
let logged_event_prefix = "";
let received_compat_mouse_events = false;
function logEvent(e) {
if (e.type.startsWith(logged_event_prefix) && e.eventPhase == e.AT_TARGET) {
event_log.push(e.type + "@" + e.target.id);
}
if (e.type.startsWith("mouse")) {
received_compat_mouse_events = true;
}
}
function attachChild(e) {
if (e.eventPhase == e.AT_TARGET) {
parent.appendChild(child);
event_log.push("(child-attached)");
}
}
let child_moved = false;
function moveChild(e) {
if (!child_moved) {
child_moved = true;
parent.appendChild(child);
event_log.push("(child-moved)");
}
}
function setup() {
const logged_event_suffixes =
["over", "out", "enter", "leave", "down", "up"];
let targets = document.getElementsByClassName("target");
for (let i = 0; i < targets.length; i++) {
logged_event_suffixes.forEach(suffix => {
targets[i].addEventListener("pointer" + suffix, logEvent);
targets[i].addEventListener("mouse" + suffix, logEvent);
});
targets[i].addEventListener("click", logEvent);
}
}
function addPromiseTestForNewChild(attaching_event,
tested_event_prefix, expected_events) {
const test_name = `${tested_event_prefix} events from ${pointer_type} `+
`received before/after child attached at ${attaching_event}`;
promise_test(async test => {
event_log = [];
logged_event_prefix = tested_event_prefix;
// We started with child attached to ease event listener setup above.
parent.removeChild(child);
parent.addEventListener(attaching_event, attachChild);
test.add_cleanup(() => {
parent.removeEventListener(attaching_event, attachChild);
});
let done_click_promise = getEvent("click", done);
let actions = new test_driver.Actions()
.addPointer("TestPointer", pointer_type)
.pointerMove(-30, -30, {origin: parent})
.pointerDown()
.pointerUp()
.pointerMove(30, 30, {origin: parent})
.pointerDown()
.pointerUp()
.pointerMove(0, 0, {origin: done})
.pointerDown()
.pointerUp();
await actions.send();
await done_click_promise;
if (tested_event_prefix == "mouse" && !received_compat_mouse_events) {
expected_events = [];
}
assert_equals(event_log.toString(), expected_events.toString(),
"events received");
}, test_name);
}
function addPromiseTestForMovedChild(mover_event,
tested_event_prefix, expected_events) {
const test_name = `${tested_event_prefix} events from ${pointer_type} `+
`received before/after child moved at ${mover_event}`;
promise_test(async test => {
event_log = [];
logged_event_prefix = tested_event_prefix;
child_moved = false;
child.addEventListener(mover_event, moveChild);
test.add_cleanup(() => {
child.removeEventListener(mover_event, moveChild);
});
let done_click_promise = getEvent("click", done);
let actions = new test_driver.Actions()
.addPointer("TestPointer", pointer_type)
.pointerMove(-30, -30, {origin: parent})
.pointerDown()
.pointerUp()
.pointerMove(30, 30, {origin: parent})
.pointerDown()
.pointerUp()
.pointerMove(0, 0, {origin: done})
.pointerDown()
.pointerUp();
await actions.send();
await done_click_promise;
if (tested_event_prefix == "mouse" && !received_compat_mouse_events) {
expected_events = [];
}
assert_equals(event_log.toString(), expected_events.toString(),
"events received");
}, test_name);
}
setup();
// Tests for dispatched compatibility mouse events
// after DOM modification through pointer events.
addPromiseTestForNewChild("pointerdown", "mouse", [
"mouseover@parent", "mouseenter@parent",
"mousedown@parent", "(child-attached)",
"mouseover@child", "mouseenter@child",
"mouseup@child", "click@parent",
"mousedown@child", "mouseup@child", "click@child",
"mouseout@child", "mouseleave@child", "mouseleave@parent"
]);
addPromiseTestForNewChild("pointerup", "mouse", [
"mouseover@parent", "mouseenter@parent",
"mousedown@parent", "mouseup@parent", "(child-attached)", "click@parent",
"mouseover@child", "mouseenter@child",
"mousedown@child", "mouseup@child", "click@child",
"mouseout@child", "mouseleave@child", "mouseleave@parent"
]);
addPromiseTestForMovedChild("pointerdown", "mouse", [
"mouseover@child", "mouseenter@parent", "mouseenter@child",
"mousedown@child", "(child-moved)",
"mouseover@child", "mouseenter@child",
"mouseup@child", "click@child",
"mousedown@child", "mouseup@child", "click@child",
"mouseout@child", "mouseleave@child", "mouseleave@parent"
]);
addPromiseTestForMovedChild("pointerup", "mouse", [
"mouseover@child", "mouseenter@parent", "mouseenter@child",
"mousedown@child", "mouseup@child", "(child-moved)", "click@child",
"mouseover@child", "mouseenter@child",
"mousedown@child", "mouseup@child", "click@child",
"mouseout@child", "mouseleave@child", "mouseleave@parent"
]);
</script>
|