|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <title>Pointer Events properties tests</title> |
| 5 | + <meta name="viewport" content="width=device-width"> |
| 6 | + <meta name="variant" content="?mouse"> |
| 7 | + <meta name="variant" content="?pen"> |
| 8 | + <link rel="stylesheet" type="text/css" href="pointerevent_styles.css"> |
| 9 | + <script src="/resources/testharness.js"></script> |
| 10 | + <script src="/resources/testharnessreport.js"></script> |
| 11 | + <script src="/resources/testdriver.js"></script> |
| 12 | + <script src="/resources/testdriver-actions.js"></script> |
| 13 | + <script src="/resources/testdriver-vendor.js"></script> |
| 14 | + <!-- Additional helper script for common checks across event types --> |
| 15 | + <script type="text/javascript" src="pointerevent_support.js"></script> |
| 16 | + <script> |
| 17 | + var input_pointertype = location.search.substring(1); |
| 18 | + var detected_eventTypes = {}; |
| 19 | + var eventList = [ |
| 20 | + 'pointerover', 'pointerenter', 'pointermove', 'pointerdown', |
| 21 | + 'pointerup', 'pointerout', 'pointerleave' |
| 22 | + ]; |
| 23 | + var expectedPointerId = NaN; |
| 24 | + |
| 25 | + function resetTestState() { |
| 26 | + detected_eventTypes = {}; |
| 27 | + document.getElementById("square1").style.visibility = 'visible'; |
| 28 | + document.getElementById('innerFrame').contentDocument |
| 29 | + .getElementById("square2").style.visibility = 'hidden'; |
| 30 | + expectedPointerId = NaN; |
| 31 | + } |
| 32 | + function checkPointerEventAttributes( |
| 33 | + event, targetBoundingClientRect, testNamePrefix) { |
| 34 | + if (detected_eventTypes[event.type]) |
| 35 | + return; |
| 36 | + var expectedEventType = |
| 37 | + eventList[Object.keys(detected_eventTypes).length]; |
| 38 | + detected_eventTypes[event.type] = true; |
| 39 | + var pointerTestName = (testNamePrefix ? testNamePrefix + ' ' : '') |
| 40 | + + expectedPointerType + ' ' + expectedEventType; |
| 41 | + |
| 42 | + test(function() { |
| 43 | + assert_equals(event.type, expectedEventType); |
| 44 | + }, pointerTestName + "'s type should be " + expectedEventType); |
| 45 | + |
| 46 | + // Test button and buttons |
| 47 | + if (event.type == 'pointerdown') { |
| 48 | + test(function() { |
| 49 | + assert_equals(event.button, 2); |
| 50 | + }, pointerTestName + "'s button attribute is 2 when right mouse " |
| 51 | + + "button is pressed."); |
| 52 | + test(function() { |
| 53 | + assert_equals(event.buttons, 2); |
| 54 | + }, pointerTestName + "'s buttons attribute is 2 when right mouse " |
| 55 | + + "button is pressed."); |
| 56 | + } else if (event.type == 'pointerup') { |
| 57 | + test(function() { |
| 58 | + assert_equals(event.button, 2); |
| 59 | + }, pointerTestName + "'s button attribute is 0 when right mouse " |
| 60 | + + "button is just released."); |
| 61 | + test(function() { |
| 62 | + assert_equals(event.buttons, 0); |
| 63 | + }, pointerTestName + "'s buttons attribute is 0 when right mouse " |
| 64 | + + "button is just released."); |
| 65 | + } else { |
| 66 | + test(function() { |
| 67 | + assert_equals(event.button, -1); |
| 68 | + }, pointerTestName + "'s button is -1 when mouse buttons are in " |
| 69 | + + "released state."); |
| 70 | + test(function() { |
| 71 | + assert_equals(event.buttons, 0); |
| 72 | + }, pointerTestName + "'s buttons is 0 when mouse buttons are in " |
| 73 | + + "released state."); |
| 74 | + } |
| 75 | + |
| 76 | + // Test clientX and clientY |
| 77 | + if (event.type != 'pointerout' && event.type != 'pointerleave' ) { |
| 78 | + test(function () { |
| 79 | + assert_greater_than_equal( |
| 80 | + event.clientX, targetBoundingClientRect.left, |
| 81 | + "clientX should be greater or equal than left of the box"); |
| 82 | + assert_greater_than_equal( |
| 83 | + event.clientY, targetBoundingClientRect.top, |
| 84 | + "clientY should be greater or equal than top of the box"); |
| 85 | + assert_less_than_equal( |
| 86 | + event.clientX, targetBoundingClientRect.right, |
| 87 | + "clientX should be less or equal than right of the box"); |
| 88 | + assert_less_than_equal( |
| 89 | + event.clientY, targetBoundingClientRect.bottom, |
| 90 | + "clientY should be less or equal than bottom of the box"); |
| 91 | + }, pointerTestName + "'s ClientX and ClientY attributes are correct."); |
| 92 | + } else { |
| 93 | + test(function () { |
| 94 | + assert_true( |
| 95 | + event.clientX < targetBoundingClientRect.left |
| 96 | + || event.clientX >= targetBoundingClientRect.right |
| 97 | + || event.clientY < targetBoundingClientRect.top |
| 98 | + || event.clientY >= targetBoundingClientRect.bottom, |
| 99 | + "ClientX/Y should be out of the boundaries of the box"); |
| 100 | + }, pointerTestName + "'s ClientX and ClientY attributes are correct."); |
| 101 | + } |
| 102 | + |
| 103 | + check_PointerEvent(event, testNamePrefix); |
| 104 | + |
| 105 | + // Test isPrimary |
| 106 | + test(function () { |
| 107 | + assert_equals(event.isPrimary, true); |
| 108 | + }, pointerTestName + ".isPrimary attribute is correct."); |
| 109 | + |
| 110 | + // Test pointerId value |
| 111 | + if (isNaN(expectedPointerId)) { |
| 112 | + expectedPointerId = event.pointerId; |
| 113 | + } else { |
| 114 | + test(function () { |
| 115 | + assert_equals(event.pointerId, expectedPointerId); |
| 116 | + }, pointerTestName + ".pointerId should be the same as previous " |
| 117 | + + "pointer events for this active pointer."); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + async function run() { |
| 122 | + var test_pointerEvent = setup_pointerevent_test( |
| 123 | + "pointerevent attributes", [input_pointertype]); |
| 124 | + var square1 = document.getElementById("square1"); |
| 125 | + var rectSquare1 = square1.getBoundingClientRect(); |
| 126 | + var innerFrame = document.getElementById('innerFrame'); |
| 127 | + var square2 = innerFrame.contentDocument.getElementById('square2'); |
| 128 | + var rectSquare2 = square2.getBoundingClientRect(); |
| 129 | + var actions_promise; |
| 130 | + |
| 131 | + eventList.forEach(function(eventName) { |
| 132 | + on_event(square1, eventName, function (event) { |
| 133 | + if (square1.style.visibility == 'hidden') |
| 134 | + return; |
| 135 | + checkPointerEventAttributes(event, rectSquare1, ""); |
| 136 | + if (Object.keys(detected_eventTypes).length == eventList.length) { |
| 137 | + square1.style.visibility = 'hidden'; |
| 138 | + detected_eventTypes = {}; |
| 139 | + square2.style.visibility = 'visible'; |
| 140 | + expectedPointerId = NaN; |
| 141 | + } |
| 142 | + }); |
| 143 | + on_event(square2, eventName, function (event) { |
| 144 | + checkPointerEventAttributes(event, rectSquare2, "Inner frame"); |
| 145 | + if (Object.keys(detected_eventTypes).length == eventList.length) { |
| 146 | + square2.style.visibility = 'hidden'; |
| 147 | + test_pointerEvent.done(); |
| 148 | + } |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + // Inject mouse or pen inputs. |
| 153 | + await rightClickInTarget(input_pointertype, square1); |
| 154 | + await moveToDocument(input_pointertype); |
| 155 | + await rightClickInTarget(input_pointertype, square2); |
| 156 | + await moveToDocument(input_pointertype); |
| 157 | + } |
| 158 | + </script> |
| 159 | + </head> |
| 160 | + <body onload="run()"> |
| 161 | + <h1>Pointer Events hoverable pointer attributes test</h1> |
| 162 | + <h2 id="pointerTypeDescription"></h2> |
| 163 | + <div id="square1" class="square"></div> |
| 164 | + <iframe id="innerFrame" |
| 165 | + src="resources/pointerevent_attributes_hoverable_pointers-iframe.html"> |
| 166 | + </iframe> |
| 167 | + </body> |
| 168 | +</html> |
0 commit comments