gecko/content/events/test/test_bug493251.html

145 lines
5.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=493251
-->
<head>
<title>Test for Bug 493251</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=493251">Mozilla Bug 493251</a>
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 493251 **/
var win;
var mouseDown = 0;
var mouseUp = 0;
var mouseClick = 0;
var keyDown = 0;
var keyPress = 0;
var keyUp = 0;
function dispatchKeyEvent(type) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendKeyEvent(type,
Components.interfaces.nsIDOMKeyEvent.DOM_VK_A,
0, 0);
}
function doTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
win.document.getElementsByTagName("input")[0].focus();
win.addEventListener("keydown", function(e) { ++keyDown; }, true);
win.addEventListener("keypress", function(e) { ++keyPress; }, true);
win.addEventListener("keyup", function(e) { ++keyUp; }, true);
win.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
win.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
win.addEventListener("click", function(e) { ++mouseClick; }, true);
dispatchKeyEvent("keydown");
dispatchKeyEvent("keypress");
dispatchKeyEvent("keyup");
is(keyDown, 1, "Wrong number events (1)");
is(keyPress, 1, "Wrong number events (2)");
is(keyUp, 1, "Wrong number events (3)");
utils.suppressEventHandling(true);
dispatchKeyEvent("keydown");
dispatchKeyEvent("keypress");
dispatchKeyEvent("keyup");
is(keyDown, 1, "Wrong number events (4)");
is(keyPress, 1, "Wrong number events (5)");
is(keyUp, 1, "Wrong number events (6)");
utils.suppressEventHandling(false);
is(keyDown, 1, "Wrong number events (7)");
is(keyPress, 1, "Wrong number events (8)");
is(keyUp, 1, "Wrong number events (9)");
setTimeout(continueTest1, 0);
}
function continueTest1() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
dispatchKeyEvent("keydown");
utils.suppressEventHandling(true);
dispatchKeyEvent("keypress");
dispatchKeyEvent("keyup");
is(keyDown, 2, "Wrong number events (10)");
is(keyPress, 1, "Wrong number events (11)");
is(keyUp, 1, "Wrong number events (12)");
utils.suppressEventHandling(false);
setTimeout(continueTest2, 0);
}
function continueTest2() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
is(keyDown, 2, "Wrong number events (13)");
is(keyPress, 2, "Wrong number events (14)");
is(keyUp, 2, "Wrong number events (15)");
utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
is(mouseDown, 1, "Wrong number events (16)");
is(mouseUp, 1, "Wrong number events (17)");
is(mouseClick, 1, "Wrong number events (18)");
utils.suppressEventHandling(true);
utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
utils.suppressEventHandling(false);
is(mouseDown, 1, "Wrong number events (19)");
is(mouseUp, 1, "Wrong number events (20)");
is(mouseClick, 1, "Wrong number events (21)");
setTimeout(continueTest3, 0);
}
function continueTest3() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
utils.suppressEventHandling(true);
utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
utils.suppressEventHandling(false);
setTimeout(continueTest4, 1000);
}
function continueTest4() {
is(mouseDown, 2, "Wrong number events (19)");
is(mouseUp, 2, "Wrong number events (20)");
is(mouseClick, 2, "Wrong number events (21)");
win.close();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
win = window.open("data:text/html,<input>", "" , "");
win.onload = doTest;
</script>
</pre>
</body>
</html>