diff -r 000000000000 -r 6474c204b198 dom/tests/browser/browser_focus_steal_from_chrome_during_mousedown.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dom/tests/browser/browser_focus_steal_from_chrome_during_mousedown.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,59 @@ +function test() { + waitForExplicitFinish(); + + const kTestURI = + "data:text/html," + + "" + + "
" + + "" + + ""; + + let tab = gBrowser.addTab(); + gBrowser.selectedTab = tab; + + // Set the focus to the contents. + tab.linkedBrowser.focus(); + // Load on the tab + tab.linkedBrowser.addEventListener("load", onLoadTab, true); + tab.linkedBrowser.loadURI(kTestURI); + + function onLoadTab() { + tab.linkedBrowser.removeEventListener("load", onLoadTab, true); + setTimeout(doTest, 0); + } + + function doTest() { + let fm = Components.classes["@mozilla.org/focus-manager;1"]. + getService(Components.interfaces.nsIFocusManager); + let eventTarget = + tab.linkedBrowser.contentDocument.getElementById("eventTarget"); + + for (var button = 0; button < 3; button++) { + // Set focus to a chrome element before synthesizing a mouse down event. + document.getElementById("urlbar").focus(); + + is(fm.focusedElement, document.getElementById("urlbar").inputField, + "Failed to move focus to search bar: button=" + + button); + + EventUtils.synthesizeMouse(eventTarget, 10, 10, { "button": button }, + tab.linkedBrowser.contentWindow); + + let e = tab.linkedBrowser.contentDocument.activeElement; + is(e.id, "willBeFocused", + "The input element isn't active element: button=" + button); + + is(fm.focusedElement, e, + "The active element isn't focused element in App level: button=" + + button); + } + + gBrowser.removeTab(tab); + finish(); + } +}