2009-05-18 13:17:45 +04:00
|
|
|
<!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;
|
|
|
|
|
2011-01-17 14:52:25 +03:00
|
|
|
function suppressEventHandling(aSuppress) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
ok(true, "suppressEventHandling: aSuppress=" + aSuppress);
|
|
|
|
utils.suppressEventHandling(aSuppress);
|
|
|
|
}
|
|
|
|
|
2009-05-18 13:17:45 +04:00
|
|
|
function dispatchKeyEvent(type) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "Dipatching key event: type=" + type);
|
2009-05-18 13:17:45 +04:00
|
|
|
utils.sendKeyEvent(type,
|
|
|
|
Components.interfaces.nsIDOMKeyEvent.DOM_VK_A,
|
|
|
|
0, 0);
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:52:25 +03:00
|
|
|
function dispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers) {
|
2009-05-18 13:17:45 +04:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "Dipatching mouse event: aType=" + aType + ", aX=" + aX + ", aY" +
|
|
|
|
aY + ", aButton=" + aButton + ", aClickCount=" + aClickCount +
|
|
|
|
", aModifiers=" + aModifiers);
|
|
|
|
utils.sendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dumpEvent(aEvent) {
|
|
|
|
var detail = "target=" + aEvent.target + ", originalTarget=" +
|
|
|
|
aEvent.originalTarget + ", getPreventDefault()=" +
|
|
|
|
aEvent.getPreventDefault() + ", isTrusted=" + aEvent.isTrusted;
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "keydown":
|
|
|
|
case "keypress":
|
|
|
|
case "keyup":
|
|
|
|
detail += ", charCode=0x" + aEvent.charCode.toString(16) +
|
|
|
|
", keyCode=0x" + aEvent.keyCode.toString(16) +
|
|
|
|
", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
|
|
|
|
", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
|
|
|
|
", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
|
|
|
|
", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no");
|
|
|
|
break;
|
|
|
|
case "mousedown":
|
|
|
|
case "mouseup":
|
|
|
|
case "click":
|
|
|
|
detail += ", screenX=" + aEvent.screenX + ", screenY=" + aEvent.screenY +
|
|
|
|
", clientX=" + aEvent.clientX + ", clientY=" + aEvent.clientY +
|
|
|
|
", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
|
|
|
|
", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
|
|
|
|
", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
|
|
|
|
", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no") +
|
|
|
|
", button=" + aEvent.button +
|
|
|
|
", relatedTarget=" + aEvent.relatedTarget;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ok(true, aEvent.type + " event is handled: " + detail);
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var fm = Components.classes["@mozilla.org/focus-manager;1"].
|
|
|
|
getService(Components.interfaces.nsIFocusManager);
|
|
|
|
ok(true, "focused element is \"" + fm.focusedElement +
|
|
|
|
"\" and focused window is \"" + fm.focusedWindow +
|
|
|
|
"\" (the testing window is \"" + win + "\"");
|
|
|
|
}
|
2009-05-18 13:17:45 +04:00
|
|
|
|
2011-01-17 14:52:25 +03:00
|
|
|
function doTest() {
|
|
|
|
win.document.getElementsByTagName("input")[0].focus();
|
|
|
|
win.addEventListener("keydown",
|
|
|
|
function(e) { dumpEvent(e); ++keyDown; }, true);
|
|
|
|
win.addEventListener("keypress",
|
|
|
|
function(e) { dumpEvent(e); ++keyPress; }, true);
|
|
|
|
win.addEventListener("keyup",
|
|
|
|
function(e) { dumpEvent(e); ++keyUp; }, true);
|
|
|
|
win.addEventListener("mousedown",
|
|
|
|
function(e) { dumpEvent(e); ++mouseDown; }, true);
|
|
|
|
win.addEventListener("mouseup",
|
|
|
|
function(e) { dumpEvent(e); ++mouseUp; }, true);
|
|
|
|
win.addEventListener("click",
|
|
|
|
function(e) { dumpEvent(e); ++mouseClick; }, true);
|
|
|
|
|
|
|
|
ok(true, "doTest #1...");
|
2009-05-18 13:17:45 +04:00
|
|
|
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)");
|
|
|
|
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "doTest #2...");
|
|
|
|
suppressEventHandling(true);
|
2009-05-18 13:17:45 +04:00
|
|
|
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)");
|
2011-01-17 14:52:25 +03:00
|
|
|
suppressEventHandling(false);
|
2009-05-18 13:17:45 +04:00
|
|
|
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() {
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "continueTest1...");
|
2009-05-18 13:17:45 +04:00
|
|
|
dispatchKeyEvent("keydown");
|
2011-01-17 14:52:25 +03:00
|
|
|
suppressEventHandling(true);
|
2009-05-18 13:17:45 +04:00
|
|
|
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)");
|
2011-01-17 14:52:25 +03:00
|
|
|
suppressEventHandling(false);
|
2009-05-18 13:17:45 +04:00
|
|
|
setTimeout(continueTest2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function continueTest2() {
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "continueTest2 #1...");
|
2009-05-18 13:17:45 +04:00
|
|
|
is(keyDown, 2, "Wrong number events (13)");
|
|
|
|
is(keyPress, 2, "Wrong number events (14)");
|
|
|
|
is(keyUp, 2, "Wrong number events (15)");
|
|
|
|
|
2011-01-17 14:52:25 +03:00
|
|
|
dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
|
|
|
|
dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
|
2009-05-18 13:17:45 +04:00
|
|
|
is(mouseDown, 1, "Wrong number events (16)");
|
|
|
|
is(mouseUp, 1, "Wrong number events (17)");
|
|
|
|
is(mouseClick, 1, "Wrong number events (18)");
|
|
|
|
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "continueTest2 #2...");
|
|
|
|
suppressEventHandling(true);
|
|
|
|
dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
|
|
|
|
dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
|
|
|
|
suppressEventHandling(false);
|
2009-05-18 13:17:45 +04:00
|
|
|
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() {
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "continueTest3...");
|
|
|
|
dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
|
|
|
|
suppressEventHandling(true);
|
|
|
|
dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
|
|
|
|
suppressEventHandling(false);
|
2009-05-18 13:17:45 +04:00
|
|
|
setTimeout(continueTest4, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function continueTest4() {
|
2011-01-17 14:52:25 +03:00
|
|
|
ok(true, "continueTest4...");
|
2009-05-18 13:17:45 +04:00
|
|
|
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>
|