|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#activation-triggering-input-event"> |
| 5 | + <script src="/resources/testharness.js"></script> |
| 6 | + <script src="/resources/testharnessreport.js"></script> |
| 7 | + <script src="/resources/testdriver.js"></script> |
| 8 | + <script src="/resources/testdriver-actions.js"></script> |
| 9 | + <script src="/resources/testdriver-vendor.js"></script> |
| 10 | + <script src="resources/utils.js"></script> |
| 11 | +</head> |
| 12 | +<body onload="runTests()"> |
| 13 | + <p>Tests user activation from a touch actions.</p> |
| 14 | + <div id="scroller" style="width: 100%; height: 500px; overflow-y: scroll;"> |
| 15 | + <div id="content" style="width: 100%; height: 2000px;"></div> |
| 16 | + </div> |
| 17 | + <script> |
| 18 | + |
| 19 | + async function onEventReceived(event) { |
| 20 | + let shouldResultInActivation = event.type === "pointerup"; |
| 21 | + assert_equals(navigator.userActivation.isActive, shouldResultInActivation, |
| 22 | + `${event.type} event should ${shouldResultInActivation ? "" : "not "}result in activation`); |
| 23 | + await consumeTransientActivation(); |
| 24 | + } |
| 25 | + |
| 26 | + async function onEventUnreached(event) { |
| 27 | + assert_unreached(`should not receive ${event.type} event`); |
| 28 | + } |
| 29 | + |
| 30 | + function runTests() { |
| 31 | + promise_test(async () => { |
| 32 | + document.body.addEventListener("pointerdown", onEventReceived); |
| 33 | + document.body.addEventListener("pointerup", onEventUnreached); |
| 34 | + document.body.addEventListener("pointercancel", onEventReceived); |
| 35 | + document.body.addEventListener("touchend", onEventReceived); |
| 36 | + |
| 37 | + const touchend_event = getEvent('touchend'); |
| 38 | + const scroller = document.getElementById("scroller"); |
| 39 | + await new test_driver.Actions().addPointer("TestPointer", "touch") |
| 40 | + .pointerMove(0, 0, {origin: scroller, sourceName: "TestPointer"}) |
| 41 | + .pointerDown({sourceName: "TestPointer"}) |
| 42 | + .pointerMove(0, 100, {origin: scroller, sourceName: "TestPointer"}) |
| 43 | + .pointerUp({sourceName: "TestPointer"}) |
| 44 | + .send(); |
| 45 | + |
| 46 | + await touchend_event; |
| 47 | + |
| 48 | + document.body.removeEventListener("pointerdown", onEventReceived); |
| 49 | + document.body.removeEventListener("pointerup", onEventUnreached); |
| 50 | + document.body.removeEventListener("pointercancel", onEventReceived); |
| 51 | + document.body.removeEventListener("touchend", onEventReceived); |
| 52 | + }, "Activation through touch actions which cause scrolling"); |
| 53 | + |
| 54 | + promise_test(async () => { |
| 55 | + document.body.addEventListener("pointerdown", onEventReceived); |
| 56 | + document.body.addEventListener("pointerup", onEventUnreached); |
| 57 | + document.body.addEventListener("pointercancel", onEventReceived); |
| 58 | + document.body.addEventListener("touchend", onEventReceived); |
| 59 | + |
| 60 | + document.body.addEventListener("touchmove", (event) => { |
| 61 | + event.preventDefault(); |
| 62 | + }, {once: true}); |
| 63 | + const touchend_event = getEvent('touchend'); |
| 64 | + const scroller = document.getElementById("scroller"); |
| 65 | + await new test_driver.Actions().addPointer("TestPointer", "touch") |
| 66 | + .pointerMove(0, 0, {origin: scroller, sourceName: "TestPointer"}) |
| 67 | + .pointerDown({sourceName: "TestPointer"}) |
| 68 | + .pointerMove(0, 100, {origin: scroller, sourceName: "TestPointer"}) |
| 69 | + .pointerUp({sourceName: "TestPointer"}) |
| 70 | + .send(); |
| 71 | + |
| 72 | + await touchend_event; |
| 73 | + |
| 74 | + document.body.removeEventListener("pointerdown", onEventReceived); |
| 75 | + document.body.removeEventListener("pointerup", onEventReceived); |
| 76 | + document.body.removeEventListener("pointercancel", onEventUnreached); |
| 77 | + document.body.removeEventListener("touchend", onEventReceived); |
| 78 | + }, "Activation through touch actions which doesn't cause scrolling"); |
| 79 | + } |
| 80 | + </script> |
| 81 | +</body> |
| 82 | +</html> |
0 commit comments