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