new file mode 100644
--- /dev/null
+++ b/dom/events/test/test_eventHandlingOnlyChrome.html
@@ -0,0 +1,221 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1177346
+-->
+<head>
+ <title>Test for Bug 1177346</title>
+ <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=1177346">Mozilla Bug 1177346</a>
+<p id="display">
+</p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript">
+ var win;
+
+ var mouseDown = 0;
+ var mouseUp = 0;
+ var mouseClick = 0;
+
+ var keyDown = 0;
+ var keyPress = 0;
+ var keyUp = 0;
+
+ var chromeMouseDown = 0;
+ var chromeMouseUp = 0;
+ var chromeMouseClick = 0;
+
+ var chromeKeyDown = 0;
+ var chromeKeyPress = 0;
+ var chromeKeyUp = 0;
+
+ function eventHandlingOnlyChrome(aEnable) {
+ var utils = SpecialPowers.getDOMWindowUtils(win);
+ ok(true, "eventHandlingOnlyChrome: aEnable=" + aEnable);
+ utils.eventHandlingOnlyChrome(aEnable);
+ }
+
+ function dispatchKeyEvent(type) {
+ var utils = SpecialPowers.getDOMWindowUtils(win);
+ ok(true, "Dipatching key event: type=" + type);
+ utils.sendKeyEvent(type,
+ SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_A,
+ 0, 0);
+ }
+
+ function dispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers) {
+ var utils = SpecialPowers.getDOMWindowUtils(win);
+ 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 + ", defaultPrevented=" +
+ aEvent.defaultPrevented + ", 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);
+
+ var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"].
+ getService(SpecialPowers.Ci.nsIFocusManager);
+ ok(true, "focused element is \"" + fm.focusedElement +
+ "\" and focused window is \"" + fm.focusedWindow +
+ "\" (the testing window is \"" + win + "\"");
+ }
+
+ function doTest() {
+ win.document.getElementsByTagName("input")[0].focus();
+
+ // Register content listeners
+ 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);
+
+ // Register chrome listeners
+ var docShell = SpecialPowers.wrap(win)
+ .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+ .getInterface(SpecialPowers.Ci.nsIWebNavigation)
+ .QueryInterface(SpecialPowers.Ci.nsIDocShell);
+ var chromeEventHandler = docShell.chromeEventHandler;
+ chromeEventHandler.addEventListener("keydown",
+ function(e) { dumpEvent(e); ++chromeKeyDown; }, true);
+ chromeEventHandler.addEventListener("keypress",
+ function(e) { dumpEvent(e); ++chromeKeyPress; }, true);
+ chromeEventHandler.addEventListener("keyup",
+ function(e) { dumpEvent(e); ++chromeKeyUp; }, true);
+ chromeEventHandler.addEventListener("mousedown",
+ function(e) { dumpEvent(e); ++chromeMouseDown; }, true);
+ chromeEventHandler.addEventListener("mouseup",
+ function(e) { dumpEvent(e); ++chromeMouseUp; }, true);
+ chromeEventHandler.addEventListener("click",
+ function(e) { dumpEvent(e); ++chromeMouseClick; }, true);
+
+ sanityChecks();
+ }
+
+ function sanityChecks() {
+ ok(true, "Check dispatching events to chrome and content...");
+
+ dispatchKeyEvent("keydown");
+ dispatchKeyEvent("keypress");
+ dispatchKeyEvent("keyup");
+ is(keyDown, 1, "Wrong number events (sanityChecks:1)");
+ is(keyPress, 1, "Wrong number events (sanityChecks:2)");
+ is(keyUp, 1, "Wrong number events (sanityChecks:3)");
+ is(chromeKeyDown, 1, "Wrong number events (sanityChecks:4)");
+ is(chromeKeyPress, 1, "Wrong number events (sanityChecks:5)");
+ is(chromeKeyUp, 1, "Wrong number events (sanityChecks:6)");
+
+ dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
+ dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
+ is(mouseDown, 1, "Wrong number events (sanityChecks:7)");
+ is(mouseUp, 1, "Wrong number events (sanityChecks:8)");
+ is(mouseClick, 1, "Wrong number events (sanityChecks:9)");
+ is(chromeMouseDown, 1, "Wrong number events (sanityChecks:10)");
+ is(chromeMouseUp, 1, "Wrong number events (sanityChecks:11)");
+ is(chromeMouseClick, 1, "Wrong number events (sanityChecks:12)");
+
+ setTimeout(dispatchKeyToChromeOnly, 0);
+ }
+
+ function dispatchKeyToChromeOnly() {
+ ok(true, "Call eventHandlingOnlyChrome(true) and ensure only chrome " +
+ "listeners are called");
+ eventHandlingOnlyChrome(true);
+ dispatchKeyEvent("keydown");
+ dispatchKeyEvent("keypress");
+ dispatchKeyEvent("keyup");
+ is(keyDown, 1, "Wrong number events (keyChromeOnly:1)");
+ is(keyPress, 1, "Wrong number events (keyChromeOnly:2)");
+ is(keyUp, 1, "Wrong number events (keyChromeOnly:3)");
+ is(chromeKeyDown, 2, "Wrong number events (keyChromeOnly:4)");
+ is(chromeKeyPress, 2, "Wrong number events (keyChromeOnly:5)");
+ is(chromeKeyUp, 2, "Wrong number events (keyChromeOnly:6)");
+
+ ok(true, "Then call eventHandlingOnlyChrome(false) and ensure no event " +
+ "get fired");
+ eventHandlingOnlyChrome(false);
+ is(keyDown, 1, "Wrong number events (keyChromeOnly:7)");
+ is(keyPress, 1, "Wrong number events (keyChromeOnly:8)");
+ is(keyUp, 1, "Wrong number events (keyChromeOnly:9)");
+ is(chromeKeyDown, 2, "Wrong number events (keyChromeOnly:10)");
+ is(chromeKeyPress, 2, "Wrong number events (keyChromeOnly:11)");
+ is(chromeKeyUp, 2, "Wrong number events (keyChromeOnly:12)");
+
+ win.close();
+ SimpleTest.finish();
+ //setTimeout(dispatchMouseToChromeOnly, 0);
+ }
+
+ function dispatchMouseToChromeOnly() {
+ ok(true, "Call eventHandlingOnlyChrome(true) and ensure only chrome " +
+ "listeners are called");
+ eventHandlingOnlyChrome(true);
+ dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
+ dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
+ is(mouseDown, 1, "Wrong number events (mouseChromeOnly:1)");
+ is(mouseClick, 1, "Wrong number events (mouseChromeOnly:2)");
+ is(mouseUp, 1, "Wrong number events (mouseChromeOnly:3)");
+ is(chromeMouseDown, 2, "Wrong number events (mouseChromeOnly:4)");
+ is(chromeMouseClick, 2, "Wrong number events (mouseChromeOnly:5)");
+ is(chromeMouseUp, 2, "Wrong number events (mouseChromeOnly:6)");
+
+ ok(true, "Then call eventHandlingOnlyChrome(false) and ensure no event " +
+ "get fired");
+ eventHandlingOnlyChrome(false);
+ is(mouseDown, 1, "Wrong number events (mouseChromeOnly:7)");
+ is(mouseClick, 1, "Wrong number events (mouseChromeOnly:8)");
+ is(mouseUp, 1, "Wrong number events (mouseChromeOnly:9)");
+ is(chromeMouseDown, 2, "Wrong number events (mouseChromeOnly:10)");
+ is(chromeMouseClick, 2, "Wrong number events (mouseChromeOnly:11)");
+ is(chromeMouseUp, 2, "Wrong number events (mouseChromeOnly:12)");
+
+ win.close();
+ SimpleTest.finish();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ win = window.open("window_bug493251.html", "_blank" , "width=500,height=500");
+
+</script>
+</pre>
+</body>
+</html>