pointerevent_pointercancel_touch.html (5677B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>PointerCancel - touch</title> 5 <meta name="viewport" content="width=device-width"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-actions.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 <link rel="stylesheet" type="text/css" href="pointerevent_styles.css"> 12 <!-- Additional helper script for common checks across event types --> 13 <script type="text/javascript" src="pointerevent_support.js"></script> 14 </head> 15 <body class="scrollable" onload="run()"> 16 <h1>pointercancel test</h1> 17 <h3>Warning: this test works properly only for devices that have touchscreen</h3> 18 <h4> 19 Test Description: This test checks if pointercancel event triggers. 20 <p>Start touch over the black rectangle and then move your finger to scroll the page.</p> 21 </h4> 22 <p> 23 <div id="target0" style="background: black"></div> 24 <script> 25 var detected_pointertypes = {}; 26 var test_pointerEvent = async_test("pointercancel event received"); 27 // showPointerTypes is defined in pointerevent_support.js 28 // Requirements: the callback function will reference the test_pointerEvent object and 29 // will fail unless the async_test is created with the var name "test_pointerEvent". 30 add_completion_callback(showPointerTypes); 31 32 var pointerdown_event = null; 33 var pointercancel_event = null; 34 35 function run() { 36 var target0 = document.getElementById("target0"); 37 var actions_promise; 38 39 on_event(target0, "pointerdown", function (event) { 40 pointerdown_event = event; 41 detected_pointertypes[event.pointerType] = true; 42 }); 43 44 on_event(target0, "pointercancel", function (event) { 45 pointercancel_event = event; 46 test_pointerEvent.step(function () { 47 assert_not_equals(pointerdown_event, null, "pointerdown was received: "); 48 const properties = [ 49 "pointerId", "width", "height", 50 "pressure", "tangentialPressure", "tiltX", "tiltY", 51 "twist", "altitudeAngle", "azimuthAngle", 52 "pointerType", "isPrimary" 53 ]; 54 for (let property in properties) { 55 assert_equals(event[property], 56 pointerdown_event[property], 57 property + " should be the same for pointerdown and pointercancel"); 58 } 59 }); 60 test_pointerEvent.step(function () { 61 check_PointerEvent(event); 62 }); 63 test_pointerEvent.step(function () { 64 assert_equals(event.x, 0, "pointercancel.x must be zero"); 65 assert_equals(event.y, 0, "pointercancel.x must be zero"); 66 assert_equals(event.clientX, 0, "pointercancel.clientX must be zero"); 67 assert_equals(event.clientY, 0, "pointercancel.clientY must be zero"); 68 }); 69 }); 70 71 on_event(target0, "pointerout", function (event) { 72 test_pointerEvent.step(function () { 73 assert_not_equals(pointercancel_event, null, "pointercancel was received before pointerout: "); 74 assert_equals(event.pointerId, pointerdown_event.pointerId, "pointerId should be the same for pointerout and pointercancel"); 75 assert_equals(event.pointerType, pointerdown_event.pointerType, "pointerType should be the same for pointerout and pointercancel"); 76 assert_equals(event.isPrimary, pointerdown_event.isPrimary, "isPrimary should be the same for pointerout and pointercancel"); 77 }); 78 }); 79 80 on_event(target0, "pointerleave", function (event) { 81 test_pointerEvent.step(function () { 82 assert_not_equals(pointercancel_event, null, "pointercancel was received before pointerleave: "); 83 assert_equals(event.pointerId, pointerdown_event.pointerId, "pointerId should be the same for pointerleave and pointercancel"); 84 assert_equals(event.pointerType, pointerdown_event.pointerType, "pointerType should be the same for pointerleave and pointercancel"); 85 assert_equals(event.isPrimary, pointerdown_event.isPrimary, "isPrimary should be the same for pointerleave and pointercancel"); 86 }); 87 // Make sure the test finishes after all the input actions are completed. 88 actions_promise.then( () => { 89 test_pointerEvent.done(); 90 }); 91 }); 92 93 // Inject touch inputs. 94 actions_promise = touchScrollInTarget(target0, 'down'); 95 } 96 </script> 97 <h1>Pointer Events pointercancel Tests</h1> 98 <div id="complete-notice"> 99 <p>The following pointer types were detected: <span id="pointertype-log"></span>.</p> 100 </div> 101 <div id="log"></div> 102 </body> 103 </html>