Bug 588342 - console should restore focus to proper place when closed, r+a=dietrich

This commit is contained in:
Mihai Sucan 2010-09-17 13:41:33 -03:00
parent 2cc8adc8d3
commit 75a007b4e6
3 changed files with 81 additions and 0 deletions

View File

@ -1352,6 +1352,7 @@ HUD_SERVICE.prototype =
this.unregisterActiveContext(hudId);
this.unregisterDisplay(hudId);
window.focus();
},
/**

View File

@ -20,6 +20,7 @@
# Contributor(s):
# David Dahl <ddahl@mozilla.com>
# Patrick Walton <pcwalton@mozilla.com>
# Mihai Șucan <mihai.sucan@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
@ -58,6 +59,7 @@ _BROWSER_TEST_FILES = \
browser_webconsole_bug_581231_close_button.js \
browser_webconsole_consoleonpage.js \
browser_webconsole_bug_587617_output_copy.js \
browser_webconsole_bug_588342_document_focus.js \
$(NULL)
_BROWSER_TEST_PAGES = \

View File

@ -0,0 +1,78 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*
* Contributor(s):
* Mihai Șucan <mihai.sucan@gmail.com>
*
* ***** END LICENSE BLOCK ***** */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/HUDService.jsm");
const TEST_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-console.html";
let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
let notificationBox;
let input;
function tabLoad(aEvent) {
gBrowser.selectedBrowser.removeEventListener(aEvent.type, arguments.callee, true);
notificationBox = gBrowser.getNotificationBox(gBrowser.selectedBrowser);
let DOMNodeInserted = false;
document.addEventListener("DOMNodeInserted", function(aEvent) {
input = notificationBox.querySelector(".jsterm-input-node");
if (input && !DOMNodeInserted) {
DOMNodeInserted = true;
document.removeEventListener(aEvent.type, arguments.callee, false);
if (!input.getAttribute("focused")) {
input.addEventListener("focus", function(aEvent) {
input.removeEventListener(aEvent.type, arguments.callee, false);
executeSoon(runTest);
}, false);
}
else {
executeSoon(runTest);
}
}
}, false);
waitForFocus(function() {
HUDService.activateHUDForContext(gBrowser.selectedTab);
}, content);
}
function runTest() {
is(input.getAttribute("focused"), "true", "input node is focused");
isnot(fm.focusedWindow, content, "content document has no focus");
let DOMNodeRemoved = false;
document.addEventListener("DOMNodeRemoved", function(aEvent) {
executeSoon(function() {
if (!DOMNodeRemoved && !notificationBox.querySelector(".hud-box")) {
DOMNodeRemoved = true;
document.removeEventListener(aEvent.type, arguments.callee, false);
is(fm.focusedWindow, content, "content document has focus");
input = notificationBox = fm = null;
finish();
}
});
}, false);
HUDService.deactivateHUDForContext(gBrowser.selectedTab);
}
function test() {
waitForExplicitFinish();
gBrowser.selectedBrowser.addEventListener("load", tabLoad, true);
content.location = TEST_URI;
}