| 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 (attribute == "buttons") { |
| 67 if (inputPointerType == "eraser" && mouseEvent.type == "mousedown") |
| 68 expectedValue |= 32; |
| 69 } else if (attribute == "width" || attribute == "height") { |
| 70 expectedValue = 1; |
| 71 } else if (attribute == "pressure") { |
| 72 if (pointerType == "mouse") |
| 73 expectedValue = (mouseEvent.buttons == 0)? 0.0 : 0.5; |
| 74 else |
| 75 expectedValue = penPressure; |
| 76 } else if (attribute == "tiltX") { |
| 77 expectedValue = (pointerType == "mouse")? 0 : penTiltX; |
| 78 } else if (attribute == "tiltY") { |
| 79 expectedValue = (pointerType == "mouse")? 0 : penTiltY; |
| 80 } |
| 81 return expectedValue; |
| 82 } |
| 83 |
| 57 function init() { | 84 function init() { |
| 58 var targetDiv = document.getElementById("target"); | 85 var targetDiv = document.getElementById("target"); |
| 59 | 86 |
| 60 testEventList.forEach(function(eventName) { | 87 testEventList.forEach(function(eventName) { |
| 61 | 88 |
| 62 targetDiv.addEventListener(eventName, function(event) { | 89 targetDiv.addEventListener(eventName, function(event) { |
| 63 | 90 |
| 64 debug("Received " + event.type); | 91 debug("Received " + event.type); |
| 65 | 92 |
| 66 if (event.type.startsWith("pointer")) | 93 if (event.type.startsWith("pointer")) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 82 shouldBeTrue("lastPointerEvents[0].bubbles"); | 109 shouldBeTrue("lastPointerEvents[0].bubbles"); |
| 83 shouldBeTrue("lastPointerEvents[0].cancelable"); | 110 shouldBeTrue("lastPointerEvents[0].cancelable"); |
| 84 } | 111 } |
| 85 | 112 |
| 86 shouldBeEqualToNumber("lastPointerEvents[0].pointerId", | 113 shouldBeEqualToNumber("lastPointerEvents[0].pointerId", |
| 87 (pointerType == "mouse")? 1 : penId); | 114 (pointerType == "mouse")? 1 : penId); |
| 88 shouldBeEqualToString("lastPointerEvents[0].pointerType", pointerType)
; | 115 shouldBeEqualToString("lastPointerEvents[0].pointerType", pointerType)
; |
| 89 shouldBeTrue("lastPointerEvents[0].isPrimary"); | 116 shouldBeTrue("lastPointerEvents[0].isPrimary"); |
| 90 | 117 |
| 91 numericAttributes.forEach(function(attribute) { | 118 numericAttributes.forEach(function(attribute) { |
| 92 var expectedValue = eval("event." + attribute); | 119 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); | 120 shouldBeEqualToNumber("lastPointerEvents[0]." + attribute, expectedV
alue); |
| 109 }); | 121 }); |
| 122 |
| 110 shouldBeEqualToString("lastPointerEvents[0].view.name", "mainWindow"); | 123 shouldBeEqualToString("lastPointerEvents[0].view.name", "mainWindow"); |
| 111 | 124 |
| 112 } else { | 125 } else { |
| 113 | 126 |
| 114 forEachModifier(function(attr, modifierName) { | 127 forEachModifier(function(attr, modifierName) { |
| 115 var getModifierStateStr = ".getModifierState('" + modifierName + "')
;" | 128 var getModifierStateStr = ".getModifierState('" + modifierName + "')
;" |
| 116 if (eval("event" + getModifierStateStr)) | 129 if (eval("event" + getModifierStateStr)) |
| 117 shouldBeTrue("lastPointerEvents[0]" + getModifierStateStr); | 130 shouldBeTrue("lastPointerEvents[0]" + getModifierStateStr); |
| 118 else | 131 else |
| 119 shouldBeFalse("lastPointerEvents[0]" + getModifierStateStr); | 132 shouldBeFalse("lastPointerEvents[0]" + getModifierStateStr); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 }); | 170 }); |
| 158 checkKeyModifiers = false; | 171 checkKeyModifiers = false; |
| 159 debug(""); | 172 debug(""); |
| 160 | 173 |
| 161 debug("--- move mouse out of target ---"); | 174 debug("--- move mouse out of target ---"); |
| 162 eventSender.mouseMoveTo(x - 5, y - 5); | 175 eventSender.mouseMoveTo(x - 5, y - 5); |
| 163 | 176 |
| 164 debug(""); | 177 debug(""); |
| 165 } | 178 } |
| 166 | 179 |
| 167 function runPenTests(x, y) { | 180 function runPenTests(x, y, id, eraseMode) { |
| 168 debug("===== pen tests ====="); | 181 debug("===== pen tests " + (eraseMode? "(erase mode)" : "(draw mode)") + " ===
=="); |
| 169 pointerType = "pen"; | 182 pointerType = "pen"; |
| 170 penId = 2; | 183 inputPointerType = eraseMode? "eraser" : "pen"; |
| 184 penId = id; |
| 171 penPressure = 0.0; | 185 penPressure = 0.0; |
| 172 penTiltX = 0; | 186 penTiltX = 0; |
| 173 penTiltY = 0; | 187 penTiltY = 0; |
| 174 | 188 |
| 175 debug("--- move pen into target ---"); | 189 debug("--- move pen into target ---"); |
| 176 eventSender.mouseMoveTo(x + 5, y + 5, [], "pen", penId, penPressure, penTiltX,
penTiltY); | 190 eventSender.mouseMoveTo(x + 5, y + 5, [], inputPointerType, penId, penPressure
, penTiltX, penTiltY); |
| 177 debug(""); | 191 debug(""); |
| 178 | 192 |
| 179 debug("--- move within target & tap ---"); | 193 debug("--- move within target & tap ---"); |
| 180 penTiltX = 45; | 194 penTiltX = 45; |
| 181 penTiltY = -34; | 195 penTiltY = -34; |
| 182 eventSender.mouseMoveTo(x + 15, y + 15, [], "pen", penId, penPressure, penTilt
X, penTiltY); | 196 eventSender.mouseMoveTo(x + 15, y + 15, [], inputPointerType, penId, penPressu
re, penTiltX, penTiltY); |
| 183 penPressure = 0.75; | 197 penPressure = 0.75; |
| 184 eventSender.mouseDown(0, [], "pen", penId, penPressure, penTiltX, penTiltY); | 198 eventSender.mouseDown(0, [], inputPointerType, penId, penPressure, penTiltX, p
enTiltY); |
| 185 penPressure = 0.0; | 199 penPressure = 0.0; |
| 186 eventSender.mouseUp(0, [], "pen", penId, penPressure, penTiltX, penTiltY); | 200 eventSender.mouseUp(0, [], inputPointerType, penId, penPressure, penTiltX, pen
TiltY); |
| 187 | 201 |
| 188 debug("--- move pen out of target ---"); | 202 debug("--- move pen out of target ---"); |
| 189 eventSender.mouseMoveTo(x - 5, y - 5, [], "pen", penId, penPressure, penTiltX,
penTiltY); | 203 eventSender.mouseMoveTo(x - 5, y - 5, [], inputPointerType, penId, penPressure
, penTiltX, penTiltY); |
| 190 | 204 |
| 191 debug(""); | 205 debug(""); |
| 192 } | 206 } |
| 193 | 207 |
| 194 function runAllTests() { | 208 function runAllTests() { |
| 195 var rect = document.getElementById("target").getBoundingClientRect(); | 209 var rect = document.getElementById("target").getBoundingClientRect(); |
| 196 | 210 |
| 197 runMouseTests(rect.left, rect.top); | 211 runMouseTests(rect.left, rect.top); |
| 198 runPenTests(rect.left, rect.top); | 212 runPenTests(rect.left, rect.top, 2, false); |
| 213 runPenTests(rect.left, rect.top, 3, true); |
| 199 } | 214 } |
| 200 | 215 |
| 201 init(); | 216 init(); |
| 202 if (window.eventSender) | 217 if (window.eventSender) |
| 203 runAllTests(); | 218 runAllTests(); |
| 204 else | 219 else |
| 205 debug("This test requires eventSender"); | 220 debug("This test requires eventSender"); |
| 206 | 221 |
| 207 </script> | 222 </script> |
| OLD | NEW |