Chromium Code Reviews| 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 { | 5 div { |
| 6 margin: 10px; | 6 margin: 10px; |
| 7 padding: 50px; | 7 padding: 50px; |
| 8 float: left; | 8 float: left; |
| 9 } | 9 } |
| 10 #console { | 10 #console { |
| 11 padding: 0px; | 11 padding: 0px; |
| 12 float: none; | 12 float: none; |
| 13 } | 13 } |
| 14 </style> | 14 </style> |
| 15 | 15 |
| 16 <div id="target" style="background-color:red"> | 16 <div id="target" style="background-color:red"> |
| 17 </div> | 17 </div> |
| 18 | 18 |
| 19 <div id="console"></div> | 19 <div id="console"></div> |
| 20 | 20 |
| 21 <script> | 21 <script> |
| 22 description("Verifies that pointer event parameters are correct when fired for m ouse events."); | 22 description("Verifies that pointer event parameters are correct when fired for m ouse events."); |
| 23 | 23 |
| 24 // TODO(mustaq): Grow the list as we add support for more PEs | 24 // TODO(mustaq): Grow the list as we add support for more PEs |
| 25 var testEventList = ["mouseenter", "mouseleave", "mouseover", "mouseout", | 25 var testEventList = ["mouseenter", "mouseleave", "mouseover", "mouseout", "mouse up", "mousedown", |
| 26 "pointerenter", "pointerleave", "pointerover", "pointerout"]; | 26 "pointerenter", "pointerleave", "pointerover", "pointerout", "pointerup", "pointerdown"]; |
| 27 var lastPointerEvent = null; | 27 var lastPointerEvent = null; |
| 28 | 28 |
| 29 var checkKeyModifiers = false; | |
| 30 | |
| 29 var numericAttributes = [ | 31 var numericAttributes = [ |
| 30 "clientX", | 32 "clientX", |
| 31 "clientY", | 33 "clientY", |
| 32 "layerX", | 34 "layerX", |
| 33 "layerY", | 35 "layerY", |
| 34 "movementX", | 36 "movementX", |
| 35 "movementY", | 37 "movementY", |
| 36 "offsetX", | 38 "offsetX", |
| 37 "offsetY", | 39 "offsetY", |
| 38 "pageX", | 40 "pageX", |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 51 testEventList.forEach(function(eventName) { | 53 testEventList.forEach(function(eventName) { |
| 52 | 54 |
| 53 targetDiv.addEventListener(eventName, function(event) { | 55 targetDiv.addEventListener(eventName, function(event) { |
| 54 | 56 |
| 55 debug("Received " + event.type); | 57 debug("Received " + event.type); |
| 56 | 58 |
| 57 if (event.type.startsWith("pointer")) | 59 if (event.type.startsWith("pointer")) |
| 58 lastPointerEvent = event; | 60 lastPointerEvent = event; |
| 59 else { | 61 else { |
| 60 shouldBeNonNull("lastPointerEvent"); | 62 shouldBeNonNull("lastPointerEvent"); |
| 63 shouldBeEqualToString("lastPointerEvent.type", event.type.replace("mouse ", "pointer")); | |
| 61 | 64 |
| 62 shouldBeEqualToString("lastPointerEvent.type", event.type.replace("mouse ", "pointer")); | 65 if (!checkKeyModifiers) { |
| 63 if (lastPointerEvent.type=="pointerenter" || lastPointerEvent.type=="poi nterleave") { | 66 |
| 64 shouldBeFalse("lastPointerEvent.bubbles"); | 67 if (lastPointerEvent.type=="pointerenter" || lastPointerEvent.type=="p ointerleave") { |
| 65 shouldBeFalse("lastPointerEvent.cancelable"); | 68 shouldBeFalse("lastPointerEvent.bubbles"); |
| 69 shouldBeFalse("lastPointerEvent.cancelable"); | |
| 70 } else { | |
| 71 shouldBeTrue("lastPointerEvent.bubbles"); | |
| 72 shouldBeTrue("lastPointerEvent.cancelable"); | |
| 73 } | |
| 74 | |
| 75 shouldBeEqualToNumber("lastPointerEvent.pointerId", 0); | |
|
Rick Byers
2015/10/20 19:09:50
curious: does Edge still have this behavior of alw
mustaq
2015/10/21 15:17:21
Edge uses id=1 for mouse.
I am tracking this thou
Rick Byers
2015/10/22 21:31:51
Ok, added comments there - but let's not block thi
| |
| 76 shouldBeEqualToString("lastPointerEvent.pointerType", "mouse"); | |
| 77 shouldBeTrue("lastPointerEvent.isPrimary"); | |
| 78 | |
| 79 numericAttributes.forEach(function(attribute) { | |
| 80 shouldBeEqualToNumber("lastPointerEvent." + attribute, eval("event." + attribute)); | |
| 81 }); | |
| 82 | |
| 66 } else { | 83 } else { |
| 67 shouldBeTrue("lastPointerEvent.bubbles"); | 84 |
| 68 shouldBeTrue("lastPointerEvent.cancelable"); | 85 forEachModifier(function(attr, modifierName) { |
| 86 var getModifierStateStr = ".getModifierState('" + modifierName + "') ;" | |
| 87 if (eval("event" + getModifierStateStr)) | |
| 88 shouldBeTrue("lastPointerEvent" + getModifierStateStr); | |
| 89 else | |
| 90 shouldBeFalse("lastPointerEvent" + getModifierStateStr); | |
| 91 }); | |
| 92 | |
| 69 } | 93 } |
| 70 | 94 |
| 71 shouldBeEqualToNumber("lastPointerEvent.pointerId", 0); | |
| 72 shouldBeEqualToString("lastPointerEvent.pointerType", "mouse"); | |
| 73 shouldBeTrue("lastPointerEvent.isPrimary"); | |
| 74 | |
| 75 numericAttributes.forEach(function(attribute) { | |
| 76 shouldBeEqualToNumber("lastPointerEvent." + attribute, eval("event." + attribute)); | |
| 77 }); | |
| 78 | |
| 79 forEachModifier(function(attr, modifierName) { | |
| 80 var getModifierStateStr = ".getModifierState('" + modifierName + "');" | |
| 81 if (eval("event" + getModifierStateStr)) | |
| 82 shouldBeTrue("lastPointerEvent" + getModifierStateStr); | |
| 83 else | |
| 84 shouldBeFalse("lastPointerEvent" + getModifierStateStr); | |
| 85 }); | |
| 86 | |
| 87 lastPointerEvent = null; | 95 lastPointerEvent = null; |
| 88 } | 96 } |
| 89 }); | 97 }); |
| 90 | 98 |
| 91 }); | 99 }); |
| 92 } | 100 } |
| 93 | 101 |
| 94 function runTests() { | 102 function runTests() { |
| 95 var rect = document.getElementById("target").getBoundingClientRect(); | 103 var rect = document.getElementById("target").getBoundingClientRect(); |
| 104 | |
| 105 debug("--- move mouse into target ---"); | |
| 96 eventSender.mouseMoveTo(rect.left + 5, rect.top + 5); | 106 eventSender.mouseMoveTo(rect.left + 5, rect.top + 5); |
| 107 debug(""); | |
| 108 | |
| 109 debug("--- click each button ---"); | |
| 110 for (var button = 0; button <=2; button++) { | |
| 111 eventSender.mouseDown(button); | |
| 112 eventSender.mouseUp(button); | |
| 113 } | |
| 114 debug(""); | |
| 115 | |
| 116 debug("--- click with each modifier ---"); | |
| 117 checkKeyModifiers = true; | |
| 118 forEachModifier(function(attr, modifierName, eventSenderName) { | |
| 119 eventSender.mouseDown(0, [eventSenderName]); | |
| 120 eventSender.mouseUp(0, [eventSenderName]); | |
| 121 }); | |
| 122 checkKeyModifiers = false; | |
| 123 debug(""); | |
| 124 | |
| 125 debug("--- move mouse out of target ---"); | |
| 97 eventSender.mouseMoveTo(rect.left - 5, rect.top - 5); | 126 eventSender.mouseMoveTo(rect.left - 5, rect.top - 5); |
| 98 | |
| 99 //TODO(mustaq): add tests for buttons & modifierStates when doing pointerdown/ up. | |
| 100 } | 127 } |
| 101 | 128 |
| 102 init(); | 129 init(); |
| 103 if (window.eventSender) | 130 if (window.eventSender) |
| 104 runTests(); | 131 runTests(); |
| 105 else | 132 else |
| 106 debug("This test requires eventSender"); | 133 debug("This test requires eventSender"); |
| 107 | 134 |
| 108 </script> | 135 </script> |
| OLD | NEW |