|
1 function test() { |
|
2 waitForExplicitFinish(); |
|
3 |
|
4 let fm = Components.classes["@mozilla.org/focus-manager;1"] |
|
5 .getService(Components.interfaces.nsIFocusManager); |
|
6 |
|
7 let tabs = [ gBrowser.selectedTab, gBrowser.addTab() ]; |
|
8 |
|
9 // The first tab has an autofocused element. |
|
10 // The second tab is exactly like the first one without the autofocus. |
|
11 let testingList = [ |
|
12 { uri: "data:text/html,<!DOCTYPE html><html><body><input autofocus id='target'></body></html>", |
|
13 tagName: "INPUT"}, |
|
14 ]; |
|
15 |
|
16 function runTest() { |
|
17 // Set the focus to the first tab. |
|
18 tabs[0].linkedBrowser.focus(); |
|
19 |
|
20 // Load the first tab on background. |
|
21 tabs[1].linkedBrowser.addEventListener("load", onLoadBackgroundTab, true); |
|
22 tabs[1].linkedBrowser.loadURI(testingList[0].uri); |
|
23 } |
|
24 |
|
25 function onLoadBackgroundTab() { |
|
26 tabs[1].linkedBrowser.removeEventListener("load", onLoadBackgroundTab, true); |
|
27 |
|
28 // The focus event (from autofocus) has been sent, |
|
29 // let's test with executeSoon so we are sure the test is done |
|
30 // after the focus event is processed. |
|
31 executeSoon(doTest); |
|
32 } |
|
33 |
|
34 function doTest() { |
|
35 for (var i=0; i<testingList.length; ++i) { |
|
36 // Get active element in the tab. |
|
37 var e = tabs[i+1].linkedBrowser.contentDocument.activeElement; |
|
38 |
|
39 is(e.tagName, testingList[i].tagName, |
|
40 "The background tab's focused element should be " + |
|
41 testingList[i].tagName); |
|
42 isnot(fm.focusedElement, e, |
|
43 "The background tab's focused element should not be the focus " + |
|
44 "manager focused element"); |
|
45 } |
|
46 |
|
47 // Cleaning up. |
|
48 for (let i = 1; i < tabs.length; i++) { |
|
49 gBrowser.removeTab(tabs[i]); |
|
50 } |
|
51 finish(); |
|
52 } |
|
53 |
|
54 runTest(); |
|
55 } |