Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | function test() { |
michael@0 | 2 | waitForExplicitFinish(); |
michael@0 | 3 | |
michael@0 | 4 | const kTestURI = |
michael@0 | 5 | "data:text/html," + |
michael@0 | 6 | "<script type=\"text/javascript\">" + |
michael@0 | 7 | " function onMouseDown(aEvent) {" + |
michael@0 | 8 | " document.getElementById('willBeFocused').focus();" + |
michael@0 | 9 | " aEvent.preventDefault();" + |
michael@0 | 10 | " }" + |
michael@0 | 11 | "</script>" + |
michael@0 | 12 | "<body id=\"body\">" + |
michael@0 | 13 | "<button id=\"eventTarget\" onmousedown=\"onMouseDown(event);\">click here</button>" + |
michael@0 | 14 | "<input id=\"willBeFocused\"></body>"; |
michael@0 | 15 | |
michael@0 | 16 | let tab = gBrowser.addTab(); |
michael@0 | 17 | gBrowser.selectedTab = tab; |
michael@0 | 18 | |
michael@0 | 19 | // Set the focus to the contents. |
michael@0 | 20 | tab.linkedBrowser.focus(); |
michael@0 | 21 | // Load on the tab |
michael@0 | 22 | tab.linkedBrowser.addEventListener("load", onLoadTab, true); |
michael@0 | 23 | tab.linkedBrowser.loadURI(kTestURI); |
michael@0 | 24 | |
michael@0 | 25 | function onLoadTab() { |
michael@0 | 26 | tab.linkedBrowser.removeEventListener("load", onLoadTab, true); |
michael@0 | 27 | setTimeout(doTest, 0); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function doTest() { |
michael@0 | 31 | let fm = Components.classes["@mozilla.org/focus-manager;1"]. |
michael@0 | 32 | getService(Components.interfaces.nsIFocusManager); |
michael@0 | 33 | let eventTarget = |
michael@0 | 34 | tab.linkedBrowser.contentDocument.getElementById("eventTarget"); |
michael@0 | 35 | |
michael@0 | 36 | for (var button = 0; button < 3; button++) { |
michael@0 | 37 | // Set focus to a chrome element before synthesizing a mouse down event. |
michael@0 | 38 | document.getElementById("urlbar").focus(); |
michael@0 | 39 | |
michael@0 | 40 | is(fm.focusedElement, document.getElementById("urlbar").inputField, |
michael@0 | 41 | "Failed to move focus to search bar: button=" + |
michael@0 | 42 | button); |
michael@0 | 43 | |
michael@0 | 44 | EventUtils.synthesizeMouse(eventTarget, 10, 10, { "button": button }, |
michael@0 | 45 | tab.linkedBrowser.contentWindow); |
michael@0 | 46 | |
michael@0 | 47 | let e = tab.linkedBrowser.contentDocument.activeElement; |
michael@0 | 48 | is(e.id, "willBeFocused", |
michael@0 | 49 | "The input element isn't active element: button=" + button); |
michael@0 | 50 | |
michael@0 | 51 | is(fm.focusedElement, e, |
michael@0 | 52 | "The active element isn't focused element in App level: button=" + |
michael@0 | 53 | button); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | gBrowser.removeTab(tab); |
michael@0 | 57 | finish(); |
michael@0 | 58 | } |
michael@0 | 59 | } |