Skip to content

Commit

Permalink
[Interop] Add a WPT that canceling mousemove doesn't affect drag.
Browse files Browse the repository at this point in the history
This is related to w3c/uievents#278.

Bug: 346473
Change-Id: I0bc9d732369a0fa5eb8f4a4bcc04c7eabce26e6b
  • Loading branch information
mustaqahmed authored and chromium-wpt-export-bot committed Dec 7, 2022
1 parent 749e04e commit 67c753e
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions uievents/mouse/mousemove_prevent_default_action.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
<body>
<div id="a">div a</div>
<div id="b">div b</div>
<div id="c" draggable="true">div c</div>
</body>

<script>
'use strict';

const a = document.getElementById("a");
const b = document.getElementById("b");

const expected_events = ["mousemove", "mousedown", "selectionchange",
"mousemove", "selectionchange"];

let event_log = [];

function logEvents(e) {
Expand All @@ -32,15 +27,18 @@

// Deliberately avoiding mouseup here because the last selectionchange
// may be fired before or after the mouseup.
["mousedown", "mousemove", "selectionchange"].forEach(ename => {
["mousedown", "mousemove", "selectionchange", "dragstart"].forEach(ename => {
document.addEventListener(ename, logEvents);
});
document.addEventListener("mousemove", e => e.preventDefault());

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

let mouseup_promise = getEvent("mouseup", document);
const a = document.getElementById("a");
const b = document.getElementById("b");

let mouseup_promise = getEvent("mouseup", document);

await new test_driver.Actions()
.pointerMove(0, 0, {origin: a})
Expand All @@ -55,7 +53,41 @@

await mouseup_promise;

const expected_events = ["mousemove", "mousedown", "selectionchange",
"mousemove", "selectionchange"];

assert_equals(event_log.toString(), expected_events.toString(),
"received events");
}, "selectionchange event firing when mousemove event is prevented");

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

const b = document.getElementById("b");
const c = document.getElementById("c");

let dragstart_promise = getEvent("dragstart", document);

// A mouseup event is not expected. This avoids timing out when the
// dragstart event is missing.
let mouseup_promise = getEvent("mouseup", document);

await new test_driver.Actions()
.pointerMove(0, 0, {origin: c})
.pointerDown()
.addTick()
.addTick()
.pointerMove(0, 0, {origin: b})
.addTick()
.addTick()
.pointerUp()
.send();

await Promise.race([dragstart_promise, mouseup_promise]);

const expected_events = ["mousemove", "mousedown", "mousemove", "dragstart"];

assert_equals(event_log.toString(), expected_events.toString(),
"received events");
}, "dragstart event firing when mousemove event is prevented");
</script>

0 comments on commit 67c753e

Please sign in to comment.