Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | Tor bug |
michael@0 | 5 | https://trac.torproject.org/projects/tor/ticket/4755 |
michael@0 | 6 | --> |
michael@0 | 7 | <head> |
michael@0 | 8 | <meta charset="utf-8"> |
michael@0 | 9 | <title>Test for Tor Bug #4755: Return client window coordinates for mouse event screenX/Y.</title> |
michael@0 | 10 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 12 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 13 | </head> |
michael@0 | 14 | <body> |
michael@0 | 15 | <a target="_blank" href="https://trac.torproject.org/projects/tor/ticket/4755">Tor Bug 4755</a> |
michael@0 | 16 | <p id="display"></p> |
michael@0 | 17 | <pre id="test"></pre> |
michael@0 | 18 | <script type="application/javascript"> |
michael@0 | 19 | // This test produces fake mouse events and checks that the screenX and screenY |
michael@0 | 20 | // properties of the received event objects provide client window coordinates. |
michael@0 | 21 | function test_go () { |
michael@0 | 22 | // Listening for asynchronous events, so we need to use the following call. |
michael@0 | 23 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 24 | // A full list of possible mouse and touch events. |
michael@0 | 25 | var eventTypes = ["mousedown", "mouseup"], |
michael@0 | 26 | // TODO: get the following events working. No success so far. |
michael@0 | 27 | /* ["click", "contextmenu", "DOMMouseScroll", "dblclick", "wheel", |
michael@0 | 28 | "mouseenter", "mouseleave", "mousemove", "mouseout", "mouseover", |
michael@0 | 29 | "MozEdgeUIGesture", "MozMagnifyGesture", "MozMagnifyGestureStart", |
michael@0 | 30 | "MozMagnifyGestureUpdate", "MozPressTapGesture", "MozRotateGesture", |
michael@0 | 31 | "MozRotateGestureStart", "MozRotateGestureUpdate", "MozSwipeGesture", |
michael@0 | 32 | "MozTapGesture", "MozTouchDown", "MozTouchMove", "MozTouchUp", |
michael@0 | 33 | "touchcancel", "touchend", "touchenter", "touchleave", "touchmove", |
michael@0 | 34 | "touchstart"], */ |
michael@0 | 35 | n = eventTypes.length, |
michael@0 | 36 | examineEvent = function examineEvent (event) { |
michael@0 | 37 | console.log(n, event.type, event.screenX, event.clientX, event.screenY, event.clientY); |
michael@0 | 38 | is(event.screenX, event.clientX, "event.screenX and event.clientX should be the same"); |
michael@0 | 39 | is(event.screenY, event.clientY, "event.screenY and event.clientY should be the same"); |
michael@0 | 40 | --n; |
michael@0 | 41 | if (n === 0) { |
michael@0 | 42 | // We have now received all posted events. |
michael@0 | 43 | SimpleTest.finish(); |
michael@0 | 44 | } |
michael@0 | 45 | }, |
michael@0 | 46 | pretest = document.querySelector("pre#test"); |
michael@0 | 47 | // The following loop creates a new div for each event in eventTypes, |
michael@0 | 48 | // attaches a listener to listen for the event, and then generates |
michael@0 | 49 | // a fake event at the center of the div. |
michael@0 | 50 | for (var i = 0; i < eventTypes.length; ++i) { |
michael@0 | 51 | var div = document.createElement("div"); |
michael@0 | 52 | div.style = "width:10px;height:10px;background-color:red;"; |
michael@0 | 53 | // Name the div after the event we're listening for. |
michael@0 | 54 | div.id = eventTypes[i]; |
michael@0 | 55 | document.body.appendChild(div); |
michael@0 | 56 | div.addEventListener(eventTypes[i], examineEvent, false); |
michael@0 | 57 | // For some reason, the following synthesizeMouseAtCenter call only seems to run if we |
michael@0 | 58 | // wrap it in a window.setTimeout(..., 0). |
michael@0 | 59 | window.setTimeout(() => synthesizeMouseAtCenter(div, {type : eventTypes[i]}), 0); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | // Run the test once the window has loaded. |
michael@0 | 63 | window.onload = test_go; |
michael@0 | 64 | </script> |
michael@0 | 65 | </body> |
michael@0 | 66 | </html> |