|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<title>Selectors: :hover is up to date while boundary events are dispatched</title> |
| 4 | +<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> |
| 5 | +<link rel="help" href="https://drafts.csswg.org/selectors/#the-hover-pseudo"> |
| 6 | +<link rel="help" href="https://w3c.github.io/uievents/#events-mouseevent-event-order"> |
| 7 | +<link rel="help" href="https://w3c.github.io/pointerevents/#the-pointerout-event"> |
| 8 | +<script src="/resources/testharness.js"></script> |
| 9 | +<script src="/resources/testharnessreport.js"></script> |
| 10 | +<script src="/resources/testdriver.js"></script> |
| 11 | +<script src="/resources/testdriver-actions.js"></script> |
| 12 | +<script src="/resources/testdriver-vendor.js"></script> |
| 13 | +<style> |
| 14 | +div { width: 100px; height: 100px; } |
| 15 | +</style> |
| 16 | +<div id="a" style="background: green"></div> |
| 17 | +<div id="b" style="background: blue"></div> |
| 18 | +<script> |
| 19 | +const kLeaveEvents = ["mouseout", "mouseleave", "pointerout", "pointerleave"]; |
| 20 | +const kEnterEvents = ["mouseover", "mouseenter", "pointerover", "pointerenter"]; |
| 21 | + |
| 22 | +function hoverStateOnFirstEvent(target, type) { |
| 23 | + return new Promise(resolve => { |
| 24 | + target.addEventListener(type, () => { |
| 25 | + resolve({ a: a.matches(":hover"), b: b.matches(":hover") }); |
| 26 | + }, { once: true }); |
| 27 | + }); |
| 28 | +} |
| 29 | + |
| 30 | +promise_test(async t => { |
| 31 | + // Move the pointer over #a first, so that the gesture under test below is a |
| 32 | + // single move from #a to #b. |
| 33 | + await new test_driver.Actions().pointerMove(10, 10, { origin: a }).send(); |
| 34 | + assert_true(a.matches(":hover"), "#a should be hovered before the gesture"); |
| 35 | + assert_false(b.matches(":hover"), "#b should not be hovered before the gesture"); |
| 36 | + |
| 37 | + const pending = [ |
| 38 | + ...kLeaveEvents.map(type => [type, hoverStateOnFirstEvent(a, type)]), |
| 39 | + ...kEnterEvents.map(type => [type, hoverStateOnFirstEvent(b, type)]), |
| 40 | + ]; |
| 41 | + |
| 42 | + await new test_driver.Actions().pointerMove(10, 10, { origin: b }).send(); |
| 43 | + |
| 44 | + for (const [type, promise] of pending) { |
| 45 | + const state = await promise; |
| 46 | + assert_false(state.a, `#a should not be hovered during ${type}`); |
| 47 | + assert_true(state.b, `#b should be hovered during ${type}`); |
| 48 | + } |
| 49 | +}, "Boundary events for a move from #a to #b observe the new :hover state"); |
| 50 | +</script> |
0 commit comments