Runs: Chrome 160.0.8195.0 (wpt@1ab8957e4, 2026-12-01) | Firefox 163.0a1 (wpt@1ab8957e4, 2026-12-01) | Safari 257 preview (wpt@13099faa1, 2026-12-02) | Ladybird 1.0-cbbd8 (wpt@954cf6bb2, 2026-12-02) | Servo Servo 0.8 (wpt@75c11f957, 2026-12-01) | Blitz af350c0af (wpt@705f393a6, 2026-12-02)
| Chrome | Firefox | Safari | Ladybird | Servo | Blitz | |
|---|---|---|---|---|---|---|
| Total | 1/1 | 1/1 | 1/1 | 1/1 | 0/1 | NOT RUN |
| Subtest | Chrome | Firefox | Safari | Ladybird | Servo | Blitz |
|---|---|---|---|---|---|---|
| hasPointerCapture | PASS | PASS | PASS | PASS | FAIL | — |
/pointerevents/pointerevent_element_haspointercapture.html
<!doctype html> <html> <head> <title>Element.hasPointerCapture test</title> <meta name="viewport" content="width=device-width"> <meta name="variant" content="?mouse"> <meta name="variant" content="?pen"> <meta name="variant" content="?touch"> <link rel="stylesheet" type="text/css" href="pointerevent_styles.css"> <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 type="text/javascript" src="pointerevent_support.js"></script> <script> const pointer_type = location.search.substring(1); var detected_pointertypes = {}; add_completion_callback(showPointerTypes); var test_pointerEvent = async_test("hasPointerCapture"); var listening_events = [ "pointerover", "pointerenter", "pointerout", "pointerleave", "pointermove", "gotpointercapture" ]; var set_capture_to_target0 = false; function run() { var target0 = document.getElementById("target0"); var target1 = document.getElementById("target1"); var actions_promise; var target1_capture = null; on_event(target0, "pointerdown", function (e) { detected_pointertypes[e.pointerType] = true; test_pointerEvent.step(function () { if (pointer_type === "pen") { // Implicit capture for pen is platform-dependent. return; } const expected_default_capture = pointer_type !== "mouse"; assert_equals(target0.hasPointerCapture(e.pointerId), expected_default_capture, "before target0.setPointerCapture, target0.hasPointerCapture should be " + expected_default_capture); }); target1.setPointerCapture(e.pointerId); test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), false, "after target1.setPointerCapture, target0.hasPointerCapture should be false"); assert_equals(target1.hasPointerCapture(e.pointerId), true, "after target1.setPointerCapture, target1.hasPointerCapture should be true"); }); target0.setPointerCapture(e.pointerId); set_capture_to_target0 = true; // hasPointerCapture will return true immediately after a call to setPointerCapture test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), true, "after target0.setPointerCapture, target0.hasPointerCapture should be true"); }); // hasPointerCapture will return false immediately after a call to releasePointerCapture target0.releasePointerCapture(e.pointerId); set_capture_to_target0 = false; test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), false, "after target0.releasePointerCapture, target0.hasPointerCapture should be false"); assert_equals(target1.hasPointerCapture(e.pointerId), false, "after target0.releasePointerCapture, target1.hasPointerCapture should be false"); }); target0.setPointerCapture(e.pointerId); set_capture_to_target0 = true; test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), true, "after target0.setPointerCapture, target0.hasPointerCapture should be true"); }); // If the element.hasPointerCapture is false element.releasePointerCapture does nothing target1.releasePointerCapture(e.pointerId); test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), true, "while target1.hasPointerCapture is false, target1.releasePointerCapture should not change hasPointerCapture"); }); }); for (var i = 0; i < listening_events.length; i++) { on_event(target0, listening_events[i], function (e) { test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), set_capture_to_target0, "Received " + e.type + " target0.hasPointerCapture should be " + set_capture_to_target0); }); }); } on_event(target0, "pointerup", function (e) { // Immediately after firing the pointerup or pointercancel events, a user agent must clear // the pending pointer capture target override for the pointerId, and then run // "Process Pending Pointer Capture" steps to fire lostpointercapture if necessary. test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), true, "pointerup target0.hasPointerCapture should be true"); }); set_capture_to_target0 = false; }); on_event(target0, "lostpointercapture", function (e) { test_pointerEvent.step(function () { assert_equals(target0.hasPointerCapture(e.pointerId), false, "pointerup target0.hasPointerCapture should be false"); }); }); on_event(target1, "pointerdown", test_pointerEvent.step_func(function (e) { target1_capture = target1.hasPointerCapture(e.pointerId); if (pointer_type !== "pen") { // Implicit capture for pen is platform-dependent. assert_equals(target1_capture, pointer_type === "touch", "pointerdown target1.hasPointerCapture should reflect implicit capture"); } })); on_event(target1, "pointerup", function (e) { test_pointerEvent.step(function () { assert_equals(target1.hasPointerCapture(e.pointerId), target1_capture, "implicit capture should persist during pointerup"); }); // Make sure the test finishes after all the input actions are completed. actions_promise.then(test_pointerEvent.step_func_done(function () { assert_false(target0.hasPointerCapture(e.pointerId), "target0 should not have capture after the actions complete"); assert_false(target1.hasPointerCapture(e.pointerId), "target1 should release capture after pointerup"); })); }); // Inject mouse inputs. actions_promise = new test_driver.Actions() .addPointer("TestPointer", pointer_type) .pointerMove(0, 0, {origin: target0}) .pointerDown() .pointerMove(0, 10, {origin: target0}) .pointerMove(0, 20, {origin: target0}) .pointerMove(0, -10, {origin: target1}) .pointerMove(0, 0, {origin: target1}) .pointerMove(0, 10, {origin: target1}) .pointerUp() .pointerMove(0, 0, {origin: target1}) .pointerDown() .pointerUp() .send().catch(test_pointerEvent.step_func(function (error) { assert_unreached("Input actions failed: " + error); })); } </script> </head> <body onload="run()"> <h1>Element.hasPointerCapture test</h1> <h4> Test Description: This test checks if Element.hasPointerCapture returns value correctly <ol> <li> Press black rectangle and do not release <li> Move your pointer to purple rectangle <li> Release the pointer <li> Click purple rectangle </ol> </h4> <p> <div id="target0" style="touch-action:none"></div> <div id="target1"></div> <div id="complete-notice"> <p>The following pointer types were detected: <span id="pointertype-log"></span>.</p> </div> <div id="log"></div> </body> </html>