Bug 764625 - Web Console and Debugger stay checked in Web Developer menu after closing them with the close X button. r=msucan,past

This commit is contained in:
Paul Rouget 2012-06-19 18:56:31 +02:00
parent 5f34f42dff
commit dc10a49782
7 changed files with 120 additions and 7 deletions

View File

@ -29,22 +29,40 @@ let EXPORTED_SYMBOLS = ["DebuggerUI"];
*/ */
function DebuggerUI(aWindow) { function DebuggerUI(aWindow) {
this.chromeWindow = aWindow; this.chromeWindow = aWindow;
this.listenToTabs();
} }
DebuggerUI.prototype = { DebuggerUI.prototype = {
/**
* Update the status of tool's menuitems and buttons when
* the user switch tabs.
*/
listenToTabs: function DUI_listenToTabs() {
let win = this.chromeWindow;
let tabs = win.gBrowser.tabContainer;
let bound_refreshCommand = this.refreshCommand.bind(this);
tabs.addEventListener("TabSelect", bound_refreshCommand, true);
win.addEventListener("unload", function onClose(aEvent) {
tabs.removeEventListener("TabSelect", bound_refreshCommand, true);
win.removeEventListener("unload", onClose, false);
}, false);
},
/** /**
* Called by the DebuggerPane to update the Debugger toggle switches with the * Called by the DebuggerPane to update the Debugger toggle switches with the
* debugger state. * debugger state.
*/ */
refreshCommand: function DUI_refreshCommand() { refreshCommand: function DUI_refreshCommand() {
let selectedTab = this.chromeWindow.getBrowser().selectedTab; let scriptDebugger = this.getDebugger();
let command = this.chromeWindow.document.getElementById("Tools:Debugger"); let command = this.chromeWindow.document.getElementById("Tools:Debugger");
let selectedTab = this.chromeWindow.gBrowser.selectedTab;
if (this.getDebugger()) { if (scriptDebugger && scriptDebugger.ownerTab === selectedTab) {
command.setAttribute("checked", "true"); command.setAttribute("checked", "true");
} else { } else {
command.removeAttribute("checked"); command.setAttribute("checked", "false");
} }
}, },

View File

@ -56,6 +56,7 @@ _BROWSER_TEST_FILES = \
browser_dbg_iframes.js \ browser_dbg_iframes.js \
browser_dbg_pause-exceptions.js \ browser_dbg_pause-exceptions.js \
browser_dbg_multiple-windows.js \ browser_dbg_multiple-windows.js \
browser_dbg_menustatus.js \
head.js \ head.js \
$(NULL) $(NULL)

View File

@ -0,0 +1,48 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// We make sure the menuitems in the application menubar
// are checked.
function test() {
var tab1 = addTab("about:blank", function() {
var tab2 = addTab("about:blank", function() {
gBrowser.selectedTab = tab2;
let pane = DebuggerUI.toggleDebugger();
ok(pane, "toggleDebugger() should return a pane.");
let frame = pane._frame;
frame.addEventListener("Debugger:Loaded", function dbgLoaded() {
frame.removeEventListener("Debugger:Loaded", dbgLoaded, true);
let cmd = document.getElementById("Tools:Debugger");
is(cmd.getAttribute("checked"), "true", "<command Tools:Debugger> is checked.");
gBrowser.selectedTab = tab1;
is(cmd.getAttribute("checked"), "false", "<command Tools:Debugger> is unchecked after tab switch.");
gBrowser.selectedTab = tab2;
is(cmd.getAttribute("checked"), "true", "<command Tools:Debugger> is checked.");
let pane = DebuggerUI.toggleDebugger();
is(cmd.getAttribute("checked"), "false", "<command Tools:Debugger> is unchecked once closed.");
}, true);
frame.addEventListener("Debugger:Unloaded", function dbgUnloaded() {
frame.removeEventListener("Debugger:Unloaded", dbgUnloaded, true);
removeTab(tab1);
removeTab(tab2);
finish();
}, true);
});
});
}

View File

@ -343,9 +343,6 @@ DeveloperToolbar.prototype._notify = function DT_notify(aTopic)
DeveloperToolbar.prototype.handleEvent = function DT_handleEvent(aEvent) DeveloperToolbar.prototype.handleEvent = function DT_handleEvent(aEvent)
{ {
if (aEvent.type == "TabSelect" || aEvent.type == "load") { if (aEvent.type == "TabSelect" || aEvent.type == "load") {
this._chromeWindow.HUDConsoleUI.refreshCommand();
this._chromeWindow.DebuggerUI.refreshCommand();
if (this.visible) { if (this.visible) {
let contentDocument = this._chromeWindow.getBrowser().contentDocument; let contentDocument = this._chromeWindow.getBrowser().contentDocument;

View File

@ -251,6 +251,7 @@ function HUD_SERVICE()
// These methods access the "this" object, but they're registered as // These methods access the "this" object, but they're registered as
// event listeners. So we hammer in the "this" binding. // event listeners. So we hammer in the "this" binding.
this.onTabClose = this.onTabClose.bind(this); this.onTabClose = this.onTabClose.bind(this);
this.onTabSelect = this.onTabSelect.bind(this);
this.onWindowUnload = this.onWindowUnload.bind(this); this.onWindowUnload = this.onWindowUnload.bind(this);
// Remembers the last console height, in pixels. // Remembers the last console height, in pixels.
@ -317,6 +318,7 @@ HUD_SERVICE.prototype =
// TODO: check that this works as intended // TODO: check that this works as intended
gBrowser.tabContainer.addEventListener("TabClose", this.onTabClose, false); gBrowser.tabContainer.addEventListener("TabClose", this.onTabClose, false);
gBrowser.tabContainer.addEventListener("TabSelect", this.onTabSelect, false);
window.addEventListener("unload", this.onWindowUnload, false); window.addEventListener("unload", this.onWindowUnload, false);
this.registerDisplay(hudId); this.registerDisplay(hudId);
@ -616,6 +618,7 @@ HUD_SERVICE.prototype =
let gBrowser = window.gBrowser; let gBrowser = window.gBrowser;
let tabContainer = gBrowser.tabContainer; let tabContainer = gBrowser.tabContainer;
tabContainer.removeEventListener("TabClose", this.onTabClose, false); tabContainer.removeEventListener("TabClose", this.onTabClose, false);
tabContainer.removeEventListener("TabSelect", this.onTabSelect, false);
this.suspend(); this.suspend();
} }
@ -803,6 +806,17 @@ HUD_SERVICE.prototype =
this.deactivateHUDForContext(aEvent.target, false); this.deactivateHUDForContext(aEvent.target, false);
}, },
/**
* onTabSelect event handler function
*
* @param aEvent
* @returns void
*/
onTabSelect: function HS_onTabSelect(aEvent)
{
HeadsUpDisplayUICommands.refreshCommand();
},
/** /**
* Called whenever a browser window closes. Cleans up any consoles still * Called whenever a browser window closes. Cleans up any consoles still
* around. * around.
@ -821,6 +835,7 @@ HUD_SERVICE.prototype =
let tabContainer = gBrowser.tabContainer; let tabContainer = gBrowser.tabContainer;
tabContainer.removeEventListener("TabClose", this.onTabClose, false); tabContainer.removeEventListener("TabClose", this.onTabClose, false);
tabContainer.removeEventListener("TabSelect", this.onTabSelect, false);
let tab = tabContainer.firstChild; let tab = tabContainer.firstChild;
while (tab != null) { while (tab != null) {
@ -4431,7 +4446,7 @@ HeadsUpDisplayUICommands = {
if (this.getOpenHUD() != null) { if (this.getOpenHUD() != null) {
command.setAttribute("checked", true); command.setAttribute("checked", true);
} else { } else {
command.removeAttribute("checked"); command.setAttribute("checked", false);
} }
}, },

View File

@ -109,6 +109,7 @@ _BROWSER_TEST_FILES = \
browser_webconsole_window_zombie.js \ browser_webconsole_window_zombie.js \
browser_cached_messages.js \ browser_cached_messages.js \
browser_bug664688_sandbox_update_after_navigation.js \ browser_bug664688_sandbox_update_after_navigation.js \
browser_webconsole_menustatus.js \
head.js \ head.js \
$(NULL) $(NULL)

View File

@ -0,0 +1,33 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
var tab1 = gBrowser.addTab();
var tab2 = gBrowser.addTab();
gBrowser.selectedTab = tab2;
openConsole(tab2, function() {
let cmd = document.getElementById("Tools:WebConsole");
is(cmd.getAttribute("checked"), "true", "<command Tools:WebConsole> is checked.");
gBrowser.selectedTab = tab1;
is(cmd.getAttribute("checked"), "false", "<command Tools:WebConsole> is unchecked after tab switch.");
gBrowser.selectedTab = tab2;
is(cmd.getAttribute("checked"), "true", "<command Tools:WebConsole> is checked.");
closeConsole(tab2, function() {
is(cmd.getAttribute("checked"), "false", "<command Tools:WebConsole> is checked once closed.");
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
finish();
});
});
}