5 let
testPage1 =
"data:text/html,<html id='tab1'><body><button id='button1'>Tab 1</button></body></html>";
6 let
testPage2 =
"data:text/html,<html id='tab2'><body><button id='button2'>Tab 2</button></body></html>";
7 let
testPage3 =
"data:text/html,<html id='tab3'><body><button id='button3'>Tab 3</button></body></html>";
12 var
tab1 = gBrowser.addTab();
13 var browser1 = gBrowser.getBrowserForTab(tab1);
15 var
tab2 = gBrowser.addTab();
16 var browser2 = gBrowser.getBrowserForTab(tab2);
36 var fm =
Cc[
"@mozilla.org/focus-manager;1"].getService(
Ci.nsIFocusManager);
37 var focusedWindow = {};
38 is(fm.getFocusedElementForWindow(browser1.contentWindow,
false, focusedWindow),
null,
"initial focus in tab 1");
39 is(focusedWindow.value, browser1.contentWindow,
"initial frame focus in tab 1");
40 is(fm.getFocusedElementForWindow(browser2.contentWindow,
false, focusedWindow),
null,
"initial focus in tab 2");
41 is(focusedWindow.value, browser2.contentWindow,
"initial frame focus in tab 2");
44 browser2.contentWindow,
null,
true,
45 "focusedElement after tab change, focus in new tab");
50 window, gURLBar.inputField,
true,
53 browser1.contentWindow,
null,
true,
54 "focusedElement after tab change, focus in new tab");
57 var button1 = browser1.contentWindow.document.getElementById(
"button1");
59 browser1.contentWindow, button1,
true,
60 "focusedWindow after focus in focused tab");
65 var button2 = browser2.contentWindow.document.getElementById(
"button2");
69 browser1.contentWindow, button1,
false,
70 "focusedWindow after focus in unfocused tab");
71 is(fm.getFocusedElementForWindow(browser2.contentWindow,
false, {}), button2,
"focus in unfocused tab");
75 browser2.contentWindow, button2,
true,
76 "focusedWindow after tab change");
81 browser2.contentWindow, button2,
false,
82 "focusedWindow after blur in unfocused tab");
83 is(fm.getFocusedElementForWindow(browser1.contentWindow,
false, {}),
null,
"blur in unfocused tab");
89 window, gURLBar.inputField,
true,
90 "focusedWindow after url field focused");
91 is(fm.getFocusedElementForWindow(browser2.contentWindow,
false, {}), button2,
"url field focused, button in tab");
96 browser1.contentWindow, button1,
true,
97 "focusedWindow after tab change, focus in url field, button focused in new tab");
98 is(fm.getFocusedElementForWindow(browser2.contentWindow,
false, {}), button2,
"after switch tab, focus in unfocused tab");
102 browser1.contentWindow,
null,
true,
103 "focusedWindow after blur in focused tab");
107 browser1.contentWindow,
null,
false,
108 "focusedWindow after blur in unfocused url field");
112 browser2.contentWindow, button2,
true,
113 "focusedWindow after switch from unfocused to focused tab");
119 "focusedWindow after switch to chrome with no focused element");
123 browser1.contentWindow, null,
true,
124 "focusedWindow after tab switch from no focus to no focus");
133 browser1.contentWindow.location =
testPage3;
136 browser1.addEventListener(
"load",
check,
true);
137 browser2.addEventListener(
"load",
check,
true);
138 browser1.contentWindow.location =
testPage1;
139 browser2.contentWindow.location =
testPage2;
150 id =
event.originalTarget.document.documentElement.id +
"-window";
152 id =
event.originalTarget.documentElement.id +
"-document";
153 else if (
event.target.id ==
"urlbar" &&
event.originalTarget.localName ==
"input")
156 id =
event.originalTarget.id;
158 if (_browser_tabfocus_test_events)
159 _browser_tabfocus_test_events +=
" ";
160 _browser_tabfocus_test_events +=
event.type +
": " +
id;
166 var contentwin =
event.target.defaultView;
167 if (contentwin.location.toString().indexOf(
"3") > 0) {
170 setTimeout(
function () contentwin.history.back(), 0);
172 else if (contentwin.location.toString().indexOf(
"2") > 0) {
173 is(
window.document.activeElement, gURLBar.inputField,
"urlbar still focused after navigating back");
174 gBrowser.removeCurrentTab();
175 gBrowser.removeCurrentTab();
188 var expectedEvents =
"";
190 if (_browser_tabfocus_test_lastfocus)
191 expectedEvents +=
"blur: " +
getId(_browser_tabfocus_test_lastfocus);
193 if (_browser_tabfocus_test_lastfocuswindow &&
194 _browser_tabfocus_test_lastfocuswindow != expectedWindow) {
196 expectedEvents +=
" ";
197 var windowid = _browser_tabfocus_test_lastfocuswindow.document.documentElement.id;
198 expectedEvents +=
"blur: " + windowid +
"-document " +
199 "blur: " + windowid +
"-window";
202 if (expectedWindow && _browser_tabfocus_test_lastfocuswindow != expectedWindow) {
204 expectedEvents +=
" ";
205 var windowid = expectedWindow.document.documentElement.id;
206 expectedEvents +=
"focus: " + windowid +
"-document " +
207 "focus: " + windowid +
"-window";
210 if (expectedElement) {
212 expectedEvents +=
" ";
213 expectedEvents +=
"focus: " +
getId(expectedElement);
216 _browser_tabfocus_test_lastfocus = expectedElement;
217 _browser_tabfocus_test_lastfocuswindow = expectedWindow;
222 is(_browser_tabfocus_test_events, expectedEvents, testid +
" events");
223 _browser_tabfocus_test_events =
"";
225 var fm =
Cc[
"@mozilla.org/focus-manager;1"].getService(
Ci.nsIFocusManager);
227 var focusedElement = fm.focusedElement;
228 is(focusedElement ?
getId(focusedElement) :
"none",
229 expectedElement ?
getId(expectedElement) :
"none", testid +
" focusedElement");
230 is(fm.focusedWindow, expectedWindow, testid +
" focusedWindow");
231 var focusedWindow = {};
232 is(fm.getFocusedElementForWindow(expectedWindow,
false, focusedWindow),
233 expectedElement, testid +
" getFocusedElementForWindow");
234 is(focusedWindow.value, expectedWindow, testid +
" getFocusedElementForWindow frame");
235 is(expectedWindow.document.hasFocus(),
true, testid +
" hasFocus");
236 var expectedActive = expectedElement;
238 expectedActive = expectedWindow.document instanceof XULDocument ?
239 expectedWindow.document.documentElement : expectedWindow.document.body;
240 is(expectedWindow.document.activeElement, expectedActive, testid +
" activeElement");
function _browser_tabfocus_test_eventOccured(event)
function _browser_tabfocus_navigation_test_eventOccured(event)
var _browser_tabfocus_test_lastfocuswindow
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function expectFocusShift(callback, expectedWindow, expectedElement, focusChanged, testid)
var _browser_tabfocus_test_lastfocus
var _browser_tabfocus_test_events