| 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 description("Verifies that pointer event parameters are correct when fired for m
ouse events."); | 18 description("Verifies that pointer event parameters are correct when fired for m
ouse events."); |
| 19 | 19 |
| 20 var testEventList = ["mouseenter", "mouseleave", "mouseover", "mouseout", "mouse
up", "mousedown", "mousemove", | 20 var testEventList = ["mouseenter", "mouseleave", "mouseover", "mouseout", "mouse
up", "mousedown", "mousemove", |
| 21 "pointerenter", "pointerleave", "pointerover", "pointerout",
"pointerup", "pointerdown", "pointermove"]; | 21 "pointerenter", "pointerleave", "pointerover", "pointerout",
"pointerup", "pointerdown", "pointermove"]; |
| 22 var lastPointerEvent = null; | 22 var lastPointerEvents = []; |
| 23 | 23 |
| 24 var checkKeyModifiers = false; | 24 var checkKeyModifiers = false; |
| 25 | 25 |
| 26 var numericAttributes = [ | 26 var numericAttributes = [ |
| 27 "clientX", | 27 "clientX", |
| 28 "clientY", | 28 "clientY", |
| 29 "layerX", | 29 "layerX", |
| 30 "layerY", | 30 "layerY", |
| 31 "movementX", | 31 "movementX", |
| 32 "movementY", | 32 "movementY", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 function init() { | 46 function init() { |
| 47 var targetDiv = document.getElementById("target"); | 47 var targetDiv = document.getElementById("target"); |
| 48 | 48 |
| 49 testEventList.forEach(function(eventName) { | 49 testEventList.forEach(function(eventName) { |
| 50 | 50 |
| 51 targetDiv.addEventListener(eventName, function(event) { | 51 targetDiv.addEventListener(eventName, function(event) { |
| 52 | 52 |
| 53 debug("Received " + event.type); | 53 debug("Received " + event.type); |
| 54 | 54 |
| 55 if (event.type.startsWith("pointer")) | 55 if (event.type.startsWith("pointer")) |
| 56 lastPointerEvent = event; | 56 lastPointerEvents.push(event); |
| 57 else { | 57 else { |
| 58 shouldBeNonNull("lastPointerEvent"); | 58 if (event.type == "mouseout" || event.type == "mouseover") { |
| 59 shouldBeEqualToString("lastPointerEvent.type", event.type.replace("mouse
", "pointer")); | 59 shouldBeEqualToNumber("lastPointerEvents.length", 2); |
| 60 } else { |
| 61 shouldBeEqualToNumber("lastPointerEvents.length", 1); |
| 62 } |
| 63 shouldBeEqualToString("lastPointerEvents[0].type", event.type.replace("m
ouse", "pointer")); |
| 60 | 64 |
| 61 if (!checkKeyModifiers) { | 65 if (!checkKeyModifiers) { |
| 62 | 66 |
| 63 if (lastPointerEvent.type=="pointerenter" || lastPointerEvent.type=="p
ointerleave") { | 67 if (lastPointerEvents[0].type=="pointerenter" || lastPointerEvents[0].
type=="pointerleave") { |
| 64 shouldBeFalse("lastPointerEvent.bubbles"); | 68 shouldBeFalse("lastPointerEvents[0].bubbles"); |
| 65 shouldBeFalse("lastPointerEvent.cancelable"); | 69 shouldBeFalse("lastPointerEvents[0].cancelable"); |
| 66 } else { | 70 } else { |
| 67 shouldBeTrue("lastPointerEvent.bubbles"); | 71 shouldBeTrue("lastPointerEvents[0].bubbles"); |
| 68 shouldBeTrue("lastPointerEvent.cancelable"); | 72 shouldBeTrue("lastPointerEvents[0].cancelable"); |
| 69 } | 73 } |
| 70 | 74 |
| 71 shouldBeEqualToNumber("lastPointerEvent.pointerId", 1); | 75 shouldBeEqualToNumber("lastPointerEvents[0].pointerId", 1); |
| 72 shouldBeEqualToString("lastPointerEvent.pointerType", "mouse"); | 76 shouldBeEqualToString("lastPointerEvents[0].pointerType", "mouse"); |
| 73 shouldBeTrue("lastPointerEvent.isPrimary"); | 77 shouldBeTrue("lastPointerEvents[0].isPrimary"); |
| 74 | 78 |
| 75 numericAttributes.forEach(function(attribute) { | 79 numericAttributes.forEach(function(attribute) { |
| 76 var expectedValue = eval("event." + attribute); | 80 var expectedValue = eval("event." + attribute); |
| 77 if (attribute == "button" && event.type != "mousedown" && event.type
!= "mouseup") | 81 if (attribute == "button" && event.type != "mousedown" && event.type
!= "mouseup") |
| 78 expectedValue = -1; | 82 expectedValue = -1; |
| 79 if (attribute == "pressure") { | 83 if (attribute == "pressure") { |
| 80 if (event.buttons == 0) | 84 if (event.buttons == 0) |
| 81 expectedValue = 0.0; | 85 expectedValue = 0.0; |
| 82 else | 86 else |
| 83 expectedValue = 0.5; | 87 expectedValue = 0.5; |
| 84 } | 88 } |
| 85 shouldBeEqualToNumber("lastPointerEvent." + attribute, expectedValue
); | 89 shouldBeEqualToNumber("lastPointerEvents[0]." + attribute, expectedV
alue); |
| 86 }); | 90 }); |
| 87 | 91 |
| 88 } else { | 92 } else { |
| 89 | 93 |
| 90 forEachModifier(function(attr, modifierName) { | 94 forEachModifier(function(attr, modifierName) { |
| 91 var getModifierStateStr = ".getModifierState('" + modifierName + "')
;" | 95 var getModifierStateStr = ".getModifierState('" + modifierName + "')
;" |
| 92 if (eval("event" + getModifierStateStr)) | 96 if (eval("event" + getModifierStateStr)) |
| 93 shouldBeTrue("lastPointerEvent" + getModifierStateStr); | 97 shouldBeTrue("lastPointerEvents[0]" + getModifierStateStr); |
| 94 else | 98 else |
| 95 shouldBeFalse("lastPointerEvent" + getModifierStateStr); | 99 shouldBeFalse("lastPointerEvents[0]" + getModifierStateStr); |
| 96 }); | 100 }); |
| 97 | 101 |
| 98 } | 102 } |
| 99 | 103 |
| 100 lastPointerEvent = null; | 104 lastPointerEvents.splice(0, 1); |
| 101 } | 105 } |
| 102 }); | 106 }); |
| 103 | 107 |
| 104 }); | 108 }); |
| 105 } | 109 } |
| 106 | 110 |
| 107 function runTests() { | 111 function runTests() { |
| 108 var rect = document.getElementById("target").getBoundingClientRect(); | 112 var rect = document.getElementById("target").getBoundingClientRect(); |
| 109 | 113 |
| 110 debug("--- move mouse into target ---"); | 114 debug("--- move mouse into target ---"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 137 eventSender.mouseMoveTo(rect.left - 5, rect.top - 5); | 141 eventSender.mouseMoveTo(rect.left - 5, rect.top - 5); |
| 138 } | 142 } |
| 139 | 143 |
| 140 init(); | 144 init(); |
| 141 if (window.eventSender) | 145 if (window.eventSender) |
| 142 runTests(); | 146 runTests(); |
| 143 else | 147 else |
| 144 debug("This test requires eventSender"); | 148 debug("This test requires eventSender"); |
| 145 | 149 |
| 146 </script> | 150 </script> |
| OLD | NEW |