1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tbb-tests/test_tor_bug4755.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +Tor bug 1.8 +https://trac.torproject.org/projects/tor/ticket/4755 1.9 +--> 1.10 +<head> 1.11 + <meta charset="utf-8"> 1.12 + <title>Test for Tor Bug #4755: Return client window coordinates for mouse event screenX/Y.</title> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.15 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.16 +</head> 1.17 +<body> 1.18 +<a target="_blank" href="https://trac.torproject.org/projects/tor/ticket/4755">Tor Bug 4755</a> 1.19 +<p id="display"></p> 1.20 +<pre id="test"></pre> 1.21 +<script type="application/javascript"> 1.22 + // This test produces fake mouse events and checks that the screenX and screenY 1.23 + // properties of the received event objects provide client window coordinates. 1.24 + function test_go () { 1.25 + // Listening for asynchronous events, so we need to use the following call. 1.26 + SimpleTest.waitForExplicitFinish(); 1.27 + // A full list of possible mouse and touch events. 1.28 + var eventTypes = ["mousedown", "mouseup"], 1.29 + // TODO: get the following events working. No success so far. 1.30 + /* ["click", "contextmenu", "DOMMouseScroll", "dblclick", "wheel", 1.31 + "mouseenter", "mouseleave", "mousemove", "mouseout", "mouseover", 1.32 + "MozEdgeUIGesture", "MozMagnifyGesture", "MozMagnifyGestureStart", 1.33 + "MozMagnifyGestureUpdate", "MozPressTapGesture", "MozRotateGesture", 1.34 + "MozRotateGestureStart", "MozRotateGestureUpdate", "MozSwipeGesture", 1.35 + "MozTapGesture", "MozTouchDown", "MozTouchMove", "MozTouchUp", 1.36 + "touchcancel", "touchend", "touchenter", "touchleave", "touchmove", 1.37 + "touchstart"], */ 1.38 + n = eventTypes.length, 1.39 + examineEvent = function examineEvent (event) { 1.40 + console.log(n, event.type, event.screenX, event.clientX, event.screenY, event.clientY); 1.41 + is(event.screenX, event.clientX, "event.screenX and event.clientX should be the same"); 1.42 + is(event.screenY, event.clientY, "event.screenY and event.clientY should be the same"); 1.43 + --n; 1.44 + if (n === 0) { 1.45 + // We have now received all posted events. 1.46 + SimpleTest.finish(); 1.47 + } 1.48 + }, 1.49 + pretest = document.querySelector("pre#test"); 1.50 + // The following loop creates a new div for each event in eventTypes, 1.51 + // attaches a listener to listen for the event, and then generates 1.52 + // a fake event at the center of the div. 1.53 + for (var i = 0; i < eventTypes.length; ++i) { 1.54 + var div = document.createElement("div"); 1.55 + div.style = "width:10px;height:10px;background-color:red;"; 1.56 + // Name the div after the event we're listening for. 1.57 + div.id = eventTypes[i]; 1.58 + document.body.appendChild(div); 1.59 + div.addEventListener(eventTypes[i], examineEvent, false); 1.60 + // For some reason, the following synthesizeMouseAtCenter call only seems to run if we 1.61 + // wrap it in a window.setTimeout(..., 0). 1.62 + window.setTimeout(() => synthesizeMouseAtCenter(div, {type : eventTypes[i]}), 0); 1.63 + } 1.64 + } 1.65 + // Run the test once the window has loaded. 1.66 + window.onload = test_go; 1.67 +</script> 1.68 +</body> 1.69 +</html>