dom/tests/browser/browser_autofocus_background.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial