Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 function test() {
2 waitForExplicitFinish();
4 let fm = Components.classes["@mozilla.org/focus-manager;1"]
5 .getService(Components.interfaces.nsIFocusManager);
7 let tabs = [ gBrowser.selectedTab, gBrowser.addTab() ];
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 ];
16 function runTest() {
17 // Set the focus to the first tab.
18 tabs[0].linkedBrowser.focus();
20 // Load the first tab on background.
21 tabs[1].linkedBrowser.addEventListener("load", onLoadBackgroundTab, true);
22 tabs[1].linkedBrowser.loadURI(testingList[0].uri);
23 }
25 function onLoadBackgroundTab() {
26 tabs[1].linkedBrowser.removeEventListener("load", onLoadBackgroundTab, true);
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 }
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;
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 }
47 // Cleaning up.
48 for (let i = 1; i < tabs.length; i++) {
49 gBrowser.removeTab(tabs[i]);
50 }
51 finish();
52 }
54 runTest();
55 }