| OLD | NEW |
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
| 2 <script src="../../../resources/js-test.js"></script> | 2 <script src="../../../resources/js-test.js"></script> |
| 3 <script src="../resources/input-modifiers.js"></script> | 3 <script src="../resources/input-modifiers.js"></script> |
| 4 <style> | 4 <style> |
| 5 div.box { | 5 div.box { |
| 6 margin: 10px; | 6 margin: 10px; |
| 7 padding: 50px; | 7 padding: 50px; |
| 8 float: left; | 8 float: left; |
| 9 } | 9 } |
| 10 </style> | 10 </style> |
| 11 | 11 |
| 12 <div id="target" class="box" style="background-color:red"> | 12 <div id="target" class="box" style="background-color:red"> |
| 13 </div> | 13 </div> |
| 14 | 14 |
| 15 <div id="console"></div> | 15 <div id="console"></div> |
| 16 | 16 |
| 17 <script> | 17 <script> |
| 18 window.name = "mainWindow"; | 18 window.name = "mainWindow"; |
| 19 description("Verifies that pointer event parameters are correct when fired throu
gh mouse events."); | 19 description("Verifies that pointer event parameters are correct when fired throu
gh mouse events."); |
| 20 | 20 |
| 21 var checkKeyModifiers = false; | 21 var checkKeyModifiers = false; |
| 22 | 22 |
| 23 var inputPointerType = ""; |
| 24 |
| 23 var pointerType = ""; | 25 var pointerType = ""; |
| 24 var penId = 0; | 26 var penId = 0; |
| 25 var penPressure = 0; | 27 var penPressure = 0; |
| 26 var penTiltX = 0; | 28 var penTiltX = 0; |
| 27 var penTiltY = 0; | 29 var penTiltY = 0; |
| 28 | 30 |
| 29 var testEventList = ["mouseenter", "mouseleave", "mouseover", "mouseout", "mouse
up", "mousedown", "mousemove", | 31 var testEventList = ["mouseenter", "mouseleave", "mouseover", "mouseout", "mouse
up", "mousedown", "mousemove", |
| 30 "pointerenter", "pointerleave", "pointerover", "pointerout",
"pointerup", "pointerdown", "pointermove"]; | 32 "pointerenter", "pointerleave", "pointerover", "pointerout",
"pointerup", "pointerdown", "pointermove"]; |
| 31 var lastPointerEvents = []; | 33 var lastPointerEvents = []; |
| 32 | 34 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 47 "y", | 49 "y", |
| 48 "button", | 50 "button", |
| 49 "buttons", | 51 "buttons", |
| 50 "pressure", | 52 "pressure", |
| 51 "tiltX", | 53 "tiltX", |
| 52 "tiltY", | 54 "tiltY", |
| 53 "width", | 55 "width", |
| 54 "height", | 56 "height", |
| 55 ]; | 57 ]; |
| 56 | 58 |
| 59 function getExpectedNumericAttributeValueForPE(mouseEvent, attribute) { |
| 60 var expectedValue = eval("mouseEvent." + attribute); |
| 61 |
| 62 // Fix expectedValue for the cases where PE & ME differs |
| 63 if (attribute == "button") { |
| 64 if (mouseEvent.type != "mousedown" && mouseEvent.type != "mouseup") |
| 65 expectedValue = -1; |
| 66 else if (inputPointerType == "eraser") |
| 67 expectedValue = 5; |
| 68 } else if (attribute == "buttons") { |
| 69 if (inputPointerType == "eraser" && mouseEvent.type == "mousedown") |
| 70 expectedValue = 32; |
| 71 } else if (attribute == "width" || attribute == "height") { |
| 72 expectedValue = 1; |
| 73 } else if (attribute == "pressure") { |
| 74 if (pointerType == "mouse") |
| 75 expectedValue = (mouseEvent.buttons == 0)? 0.0 : 0.5; |
| 76 else |
| 77 expectedValue = penPressure; |
| 78 } else if (attribute == "tiltX") { |
| 79 expectedValue = (pointerType == "mouse")? 0 : penTiltX; |
| 80 } else if (attribute == "tiltY") { |
| 81 expectedValue = (pointerType == "mouse")? 0 : penTiltY; |
| 82 } |
| 83 return expectedValue; |
| 84 } |
| 85 |
| 57 function init() { | 86 function init() { |
| 58 var targetDiv = document.getElementById("target"); | 87 var targetDiv = document.getElementById("target"); |
| 59 | 88 |
| 60 testEventList.forEach(function(eventName) { | 89 testEventList.forEach(function(eventName) { |
| 61 | 90 |
| 62 targetDiv.addEventListener(eventName, function(event) { | 91 targetDiv.addEventListener(eventName, function(event) { |
| 63 | 92 |
| 64 debug("Received " + event.type); | 93 debug("Received " + event.type); |
| 65 | 94 |
| 66 if (event.type.startsWith("pointer")) | 95 if (event.type.startsWith("pointer")) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 82 shouldBeTrue("lastPointerEvents[0].bubbles"); | 111 shouldBeTrue("lastPointerEvents[0].bubbles"); |
| 83 shouldBeTrue("lastPointerEvents[0].cancelable"); | 112 shouldBeTrue("lastPointerEvents[0].cancelable"); |
| 84 } | 113 } |
| 85 | 114 |
| 86 shouldBeEqualToNumber("lastPointerEvents[0].pointerId", | 115 shouldBeEqualToNumber("lastPointerEvents[0].pointerId", |
| 87 (pointerType == "mouse")? 1 : penId); | 116 (pointerType == "mouse")? 1 : penId); |
| 88 shouldBeEqualToString("lastPointerEvents[0].pointerType", pointerType)
; | 117 shouldBeEqualToString("lastPointerEvents[0].pointerType", pointerType)
; |
| 89 shouldBeTrue("lastPointerEvents[0].isPrimary"); | 118 shouldBeTrue("lastPointerEvents[0].isPrimary"); |
| 90 | 119 |
| 91 numericAttributes.forEach(function(attribute) { | 120 numericAttributes.forEach(function(attribute) { |
| 92 var expectedValue = eval("event." + attribute); | 121 var expectedValue = getExpectedNumericAttributeValueForPE(event, att
ribute); |
| 93 if (attribute == "button" && event.type != "mousedown" && event.type
!= "mouseup") | |
| 94 expectedValue = -1; | |
| 95 else if (attribute == "width" || attribute == "height") | |
| 96 expectedValue = 1; | |
| 97 else if (attribute == "pressure") { | |
| 98 if (pointerType == "mouse") | |
| 99 expectedValue = (event.buttons == 0)? 0.0 : 0.5; | |
| 100 else | |
| 101 expectedValue = penPressure; | |
| 102 } | |
| 103 else if (attribute == "tiltX") | |
| 104 expectedValue = (pointerType == "mouse")? 0 : penTiltX; | |
| 105 else if (attribute == "tiltY") | |
| 106 expectedValue = (pointerType == "mouse")? 0 : penTiltY; | |
| 107 | |
| 108 shouldBeEqualToNumber("lastPointerEvents[0]." + attribute, expectedV
alue); | 122 shouldBeEqualToNumber("lastPointerEvents[0]." + attribute, expectedV
alue); |
| 109 }); | 123 }); |
| 124 |
| 110 shouldBeEqualToString("lastPointerEvents[0].view.name", "mainWindow"); | 125 shouldBeEqualToString("lastPointerEvents[0].view.name", "mainWindow"); |
| 111 | 126 |
| 112 } else { | 127 } else { |
| 113 | 128 |
| 114 forEachModifier(function(attr, modifierName) { | 129 forEachModifier(function(attr, modifierName) { |
| 115 var getModifierStateStr = ".getModifierState('" + modifierName + "')
;" | 130 var getModifierStateStr = ".getModifierState('" + modifierName + "')
;" |
| 116 if (eval("event" + getModifierStateStr)) | 131 if (eval("event" + getModifierStateStr)) |
| 117 shouldBeTrue("lastPointerEvents[0]" + getModifierStateStr); | 132 shouldBeTrue("lastPointerEvents[0]" + getModifierStateStr); |
| 118 else | 133 else |
| 119 shouldBeFalse("lastPointerEvents[0]" + getModifierStateStr); | 134 shouldBeFalse("lastPointerEvents[0]" + getModifierStateStr); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 }); | 172 }); |
| 158 checkKeyModifiers = false; | 173 checkKeyModifiers = false; |
| 159 debug(""); | 174 debug(""); |
| 160 | 175 |
| 161 debug("--- move mouse out of target ---"); | 176 debug("--- move mouse out of target ---"); |
| 162 eventSender.mouseMoveTo(x - 5, y - 5); | 177 eventSender.mouseMoveTo(x - 5, y - 5); |
| 163 | 178 |
| 164 debug(""); | 179 debug(""); |
| 165 } | 180 } |
| 166 | 181 |
| 167 function runPenTests(x, y) { | 182 function runPenTests(x, y, id, eraseMode) { |
| 168 debug("===== pen tests ====="); | 183 debug("===== pen tests " + (eraseMode? "(erase mode)" : "(draw mode)") + " ===
=="); |
| 169 pointerType = "pen"; | 184 pointerType = "pen"; |
| 170 penId = 2; | 185 inputPointerType = eraseMode? "eraser" : "pen"; |
| 186 penId = id; |
| 171 penPressure = 0.0; | 187 penPressure = 0.0; |
| 172 penTiltX = 0; | 188 penTiltX = 0; |
| 173 penTiltY = 0; | 189 penTiltY = 0; |
| 174 | 190 |
| 175 debug("--- move pen into target ---"); | 191 debug("--- move pen into target ---"); |
| 176 eventSender.mouseMoveTo(x + 5, y + 5, [], "pen", penId, penPressure, penTiltX,
penTiltY); | 192 eventSender.mouseMoveTo(x + 5, y + 5, [], inputPointerType, penId, penPressure
, penTiltX, penTiltY); |
| 177 debug(""); | 193 debug(""); |
| 178 | 194 |
| 179 debug("--- move within target & tap ---"); | 195 debug("--- move within target & tap ---"); |
| 180 penTiltX = 45; | 196 penTiltX = 45; |
| 181 penTiltY = -34; | 197 penTiltY = -34; |
| 182 eventSender.mouseMoveTo(x + 15, y + 15, [], "pen", penId, penPressure, penTilt
X, penTiltY); | 198 eventSender.mouseMoveTo(x + 15, y + 15, [], inputPointerType, penId, penPressu
re, penTiltX, penTiltY); |
| 183 penPressure = 0.75; | 199 penPressure = 0.75; |
| 184 eventSender.mouseDown(0, [], "pen", penId, penPressure, penTiltX, penTiltY); | 200 eventSender.mouseDown(0, [], inputPointerType, penId, penPressure, penTiltX, p
enTiltY); |
| 185 penPressure = 0.0; | 201 penPressure = 0.0; |
| 186 eventSender.mouseUp(0, [], "pen", penId, penPressure, penTiltX, penTiltY); | 202 eventSender.mouseUp(0, [], inputPointerType, penId, penPressure, penTiltX, pen
TiltY); |
| 187 | 203 |
| 188 debug("--- move pen out of target ---"); | 204 debug("--- move pen out of target ---"); |
| 189 eventSender.mouseMoveTo(x - 5, y - 5, [], "pen", penId, penPressure, penTiltX,
penTiltY); | 205 eventSender.mouseMoveTo(x - 5, y - 5, [], inputPointerType, penId, penPressure
, penTiltX, penTiltY); |
| 190 | 206 |
| 191 debug(""); | 207 debug(""); |
| 192 } | 208 } |
| 193 | 209 |
| 194 function runAllTests() { | 210 function runAllTests() { |
| 195 var rect = document.getElementById("target").getBoundingClientRect(); | 211 var rect = document.getElementById("target").getBoundingClientRect(); |
| 196 | 212 |
| 197 runMouseTests(rect.left, rect.top); | 213 runMouseTests(rect.left, rect.top); |
| 198 runPenTests(rect.left, rect.top); | 214 runPenTests(rect.left, rect.top, 2, false); |
| 215 runPenTests(rect.left, rect.top, 3, true); |
| 199 } | 216 } |
| 200 | 217 |
| 201 init(); | 218 init(); |
| 202 if (window.eventSender) | 219 if (window.eventSender) |
| 203 runAllTests(); | 220 runAllTests(); |
| 204 else | 221 else |
| 205 debug("This test requires eventSender"); | 222 debug("This test requires eventSender"); |
| 206 | 223 |
| 207 </script> | 224 </script> |
| OLD | NEW |