pointerevent_attributes_nohover_pointers-manual.html (6645B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Pointer Events properties tests</title> 5 <meta name="viewport" content="width=device-width"> 6 <link rel="stylesheet" type="text/css" href="pointerevent_styles.css"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <!-- Additional helper script for common checks across event types --> 10 <script type="text/javascript" src="pointerevent_support.js"></script> 11 <script> 12 var detected_pointertypes = {}; 13 var detected_eventTypes = {}; 14 var eventList = ['pointerover', 'pointerenter', 'pointerdown', 'pointerup', 'pointerout', 'pointerleave']; 15 var expectedPointerId = NaN; 16 17 function resetTestState() { 18 detected_eventTypes = {}; 19 document.getElementById("square1").style.visibility = 'visible'; 20 document.getElementById('innerFrame').contentDocument.getElementById("square2").style.visibility = 'hidden'; 21 } 22 function checkPointerEventAttributes(event, targetBoundingClientRect, testNamePrefix) { 23 if (detected_eventTypes[event.type]) 24 return; 25 var expectedEventType = eventList[Object.keys(detected_eventTypes).length]; 26 detected_eventTypes[event.type] = true; 27 var pointerTestName = testNamePrefix + ' ' + expectedPointerType + ' ' + expectedEventType; 28 29 detected_pointertypes[event.pointerType] = true; 30 31 test(function() { 32 assert_equals(event.type, expectedEventType, "Event.type should be " + expectedEventType) 33 }, pointerTestName + "'s type should be " + expectedEventType); 34 35 // Test button and buttons 36 test(function() { 37 assert_true(event.button == 0, "Button attribute is 0") 38 }, pointerTestName + "'s button attribute is 0 when left mouse button is pressed."); 39 40 if (event.type == 'pointerdown' || event.type == 'pointerover' || event.type == 'pointerenter') { 41 test(function() { 42 assert_true(event.buttons == 1, "Buttons attribute is 1") 43 }, pointerTestName + "'s buttons attribute is 1 when left mouse button is pressed."); 44 } else { 45 test(function() { 46 assert_true(event.buttons == 0, "Buttons attribute is 0") 47 }, pointerTestName + "'s buttons is 0 when mouse buttons are in released state."); 48 } 49 50 // Test clientX and clientY 51 test(function () { 52 assert_true(event.clientX >= targetBoundingClientRect.left && event.clientX < targetBoundingClientRect.right && event.clientY >= targetBoundingClientRect.top && event.clientY < targetBoundingClientRect.bottom, "ClientX/Y should be in the boundaries of the box"); 53 }, pointerTestName + "'s ClientX and ClientY attributes are correct."); 54 55 check_PointerEvent(event, testNamePrefix); 56 57 // Test isPrimary 58 test(function () { 59 assert_equals(event.isPrimary, true, "isPrimary should be true"); 60 }, pointerTestName + ".isPrimary attribute is correct."); 61 62 // Test pointerId value 63 if (isNaN(expectedPointerId)) { 64 expectedPointerId = event.pointerId; 65 } else { 66 test(function () { 67 assert_equals(event.pointerId, expectedPointerId, "pointerId should remain the same for the same active pointer"); 68 }, pointerTestName + ".pointerId should be the same as previous pointer events for this active pointer."); 69 } 70 } 71 72 function run() { 73 var test_pointerEvent = setup_pointerevent_test("pointerevent attributes", NOHOVER_POINTERS); 74 var square1 = document.getElementById("square1"); 75 var rectSquare1 = square1.getBoundingClientRect(); 76 var innerFrame = document.getElementById('innerFrame'); 77 var square2 = innerFrame.contentDocument.getElementById('square2'); 78 var rectSquare2 = square2.getBoundingClientRect(); 79 80 eventList.forEach(function(eventName) { 81 on_event(square1, eventName, function (event) { 82 if (square1.style.visibility == 'hidden') 83 return; 84 checkPointerEventAttributes(event, rectSquare1, ""); 85 if (Object.keys(detected_eventTypes).length == eventList.length) { 86 square1.style.visibility = 'hidden'; 87 detected_eventTypes = {}; 88 square2.style.visibility = 'visible'; 89 expectedPointerId = NaN; 90 } 91 }); 92 on_event(square2, eventName, function (event) { 93 checkPointerEventAttributes(event, rectSquare2, "Inner frame "); 94 if (Object.keys(detected_eventTypes).length == eventList.length) { 95 square2.style.visibility = 'hidden'; 96 test_pointerEvent.done(); 97 } 98 }); 99 }); 100 } 101 </script> 102 </head> 103 <body onload="run()"> 104 <h1>Pointer Events no-hover pointer attributes test</h1> 105 <h2 id="pointerTypeDescription"></h2> 106 <h4> 107 Test Description: This test checks the properties of pointer events that do not support hover. 108 <ol> 109 <li>Tap the black square.</li> 110 <li>Then move it off the black square so that it disappears.</li> 111 <li>When the red square appears tap on that as well.</li> 112 </ol> 113 114 Test passes if the proper behavior of the events is observed. 115 </h4> 116 <div id="square1" class="square"></div> 117 <iframe id="innerFrame" src="resources/pointerevent_attributes_hoverable_pointers-iframe.html"></iframe> 118 <div class="spacer"></div> 119 <div id="complete-notice"> 120 <p>The following pointer types were detected: <span id="pointertype-log"></span>.</p> 121 <p>Refresh the page to run the tests again with a different pointer type.</p> 122 </div> 123 <div id="log"></div> 124 </body> 125 </html>