coalesced_events_attributes_on_redispatch.https.html (3446B)
1 <!doctype html> 2 <title>Coalesced event properties after JS redispatches a trusted event</title> 3 <meta name="variant" content="?mouse"> 4 <meta name="variant" content="?pen"> 5 <meta name="variant" content="?touch"> 6 <meta name="viewport" content="width=device-width"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-actions.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <script src="pointerevent_support.js"></script> 13 <link rel="stylesheet" type="text/css" href="pointerevent_styles.css"> 14 <style> 15 div { 16 width: 100px; 17 height: 100px; 18 } 19 </style> 20 <div id="target"></div> 21 <div id="target2"></div> 22 23 <script> 24 "use strict"; 25 const pointer_type = location.search.substring(1); 26 const target = document.getElementById("target"); 27 const target2 = document.getElementById("target2"); 28 29 let received_num_coalesced; 30 31 function checkListAttributesBeforeRedispatch(event) { 32 assert_equals(event.type, "pointermove"); 33 assert_equals(event.isTrusted, true); 34 assert_equals(event.target, target); 35 36 received_num_coalesced = event.getCoalescedEvents().length; 37 assert_greater_than_equal(received_num_coalesced, 1, 38 "pointermove.getCoalescedEvents() has at least 1 entry"); 39 40 for (const coalesced_event of event.getCoalescedEvents()) { 41 assert_equals(coalesced_event.isTrusted, true, 42 "coalesced_event.isTrusted is true"); 43 assert_equals(coalesced_event.target, target, 44 "coalesced_event.target matches dispatch target"); 45 } 46 } 47 48 // This WPT minimally tests redispatched event attributes. For trusted 49 // event tests, see coalesced_events_attributes.https.html. 50 function checkListAttributesAfterRedispatch(event) { 51 assert_equals(event.type, "pointermove"); 52 assert_equals(event.isTrusted, false); 53 assert_equals(event.target, target2); 54 55 assert_greater_than_equal(event.getCoalescedEvents().length, 56 received_num_coalesced, 57 "pointermove.getCoalescedEvents() has the same number of entries"); 58 59 for (const coalesced_event of event.getCoalescedEvents()) { 60 assert_equals(coalesced_event.isTrusted, true, 61 "coalesced_event.isTrusted maintains its original value"); 62 assert_equals(coalesced_event.target, target, 63 "coalesced_event.target maintains its original value"); 64 } 65 } 66 67 promise_test(async () => { 68 // We need "touch-action:none" to guarantee pointermove events. 69 target.classList.add("touchActionNone"); 70 71 let pointermove_promise = getEvent("pointermove", target); 72 let pointerup_promise = getEvent("pointerup", target); 73 74 await new test_driver.Actions() 75 .addPointer("TestPointer", pointer_type) 76 .pointerMove(0, 0, {origin: target}) 77 .pointerDown() 78 .pointerMove(20, 20, {origin: target}) 79 .pointerUp() 80 .send(); 81 82 let pointermove_event = await pointermove_promise; 83 await pointerup_promise; 84 85 checkListAttributesBeforeRedispatch(pointermove_event); 86 87 let pointermove_promise2 = getEvent("pointermove", target2); 88 target2.dispatchEvent(pointermove_event); 89 let pointermove_event2 = await pointermove_promise2; 90 91 checkListAttributesAfterRedispatch(pointermove_event2); 92 93 target.classList.remove("touchActionNone"); 94 }, "Coalesced list in pointerdown/move/up events"); 95 </script>