Skip to content

Commit

Permalink
Add a WPT for PEs after a target element is added under the pointer.
Browse files Browse the repository at this point in the history
This is related to a recent PEWG discussion:
web-platform-tests/interop#380

Bug: 1147998
Change-Id: Icfede5e4d995d2c1d8db2b03e9a915e3b49e3851
  • Loading branch information
mustaqahmed authored and chromium-wpt-export-bot committed Sep 6, 2023
1 parent 3fbfb91 commit 148249e
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions pointerevents/pointerevent_after_target_added.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE HTML>
<title>Enter/leave events fired to parent after child is added</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 = [];

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

function attachChild(e) {
if (e.eventPhase == e.AT_TARGET) {
parent.appendChild(child);
event_log.push("(child-attached)");
}
}

function setup() {
const logged_events = [
"pointerover", "pointerout", "pointerenter", "pointerleave",
"pointerdown", "pointerup"
];
let targets = document.getElementsByClassName("target");
for (let i = 0; i < targets.length; i++) {
logged_events.forEach(ename => {
targets[i].addEventListener(ename, logEvent);
});
}
}

function addPromiseTest(attaching_event, expected_events) {
const test_name = `PointerEvents from ${pointer_type} `+
`received before/after child attached at ${attaching_event}`;

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

// 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;

assert_equals(event_log.toString(), expected_events.toString(),
"events received");
}, test_name);
}

setup();
addPromiseTest("pointerdown", [
"pointerover@parent", "pointerenter@parent",
"pointerdown@parent", "(child-attached)",
"pointerover@child", "pointerenter@child",
"pointerup@child",
"pointerdown@child", "pointerup@child",
"pointerout@child", "pointerleave@child", "pointerleave@parent"
]);
addPromiseTest("pointerup", [
"pointerover@parent", "pointerenter@parent",
"pointerdown@parent", "pointerup@parent", "(child-attached)",
"pointerover@child", "pointerenter@child",
"pointerdown@child", "pointerup@child",
"pointerout@child", "pointerleave@child", "pointerleave@parent"
]);
</script>

0 comments on commit 148249e

Please sign in to comment.