From d4a3fc2d462e5b99cbd731b9e464443e2dbe6e30 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 19 Jun 2012 18:56:31 +0200 Subject: [PATCH] Bug 764625 - Web Console and Debugger stay checked in Web Developer menu after closing them with the close X button. r=msucan,past --- browser/devtools/debugger/DebuggerUI.jsm | 24 ++++++++-- browser/devtools/debugger/test/Makefile.in | 1 + .../debugger/test/browser_dbg_menustatus.js | 48 +++++++++++++++++++ browser/devtools/shared/DeveloperToolbar.jsm | 3 -- browser/devtools/webconsole/HUDService.jsm | 17 ++++++- browser/devtools/webconsole/test/Makefile.in | 1 + .../test/browser_webconsole_menustatus.js | 33 +++++++++++++ 7 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 browser/devtools/debugger/test/browser_dbg_menustatus.js create mode 100644 browser/devtools/webconsole/test/browser_webconsole_menustatus.js diff --git a/browser/devtools/debugger/DebuggerUI.jsm b/browser/devtools/debugger/DebuggerUI.jsm index 1b8b85fc317..281f0ebbba4 100644 --- a/browser/devtools/debugger/DebuggerUI.jsm +++ b/browser/devtools/debugger/DebuggerUI.jsm @@ -29,22 +29,40 @@ let EXPORTED_SYMBOLS = ["DebuggerUI"]; */ function DebuggerUI(aWindow) { this.chromeWindow = aWindow; + this.listenToTabs(); } 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 * debugger state. */ refreshCommand: function DUI_refreshCommand() { - let selectedTab = this.chromeWindow.getBrowser().selectedTab; + let scriptDebugger = this.getDebugger(); 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"); } else { - command.removeAttribute("checked"); + command.setAttribute("checked", "false"); } }, diff --git a/browser/devtools/debugger/test/Makefile.in b/browser/devtools/debugger/test/Makefile.in index 41cd2446e9b..103539e00c7 100644 --- a/browser/devtools/debugger/test/Makefile.in +++ b/browser/devtools/debugger/test/Makefile.in @@ -56,6 +56,7 @@ _BROWSER_TEST_FILES = \ browser_dbg_iframes.js \ browser_dbg_pause-exceptions.js \ browser_dbg_multiple-windows.js \ + browser_dbg_menustatus.js \ head.js \ $(NULL) diff --git a/browser/devtools/debugger/test/browser_dbg_menustatus.js b/browser/devtools/debugger/test/browser_dbg_menustatus.js new file mode 100644 index 00000000000..6650dec62fc --- /dev/null +++ b/browser/devtools/debugger/test/browser_dbg_menustatus.js @@ -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", " is checked."); + + gBrowser.selectedTab = tab1; + + is(cmd.getAttribute("checked"), "false", " is unchecked after tab switch."); + + gBrowser.selectedTab = tab2; + + is(cmd.getAttribute("checked"), "true", " is checked."); + + let pane = DebuggerUI.toggleDebugger(); + + is(cmd.getAttribute("checked"), "false", " is unchecked once closed."); + }, true); + + frame.addEventListener("Debugger:Unloaded", function dbgUnloaded() { + frame.removeEventListener("Debugger:Unloaded", dbgUnloaded, true); + removeTab(tab1); + removeTab(tab2); + + finish(); + }, true); + }); + }); +} + diff --git a/browser/devtools/shared/DeveloperToolbar.jsm b/browser/devtools/shared/DeveloperToolbar.jsm index d4a5f4f5145..641531dbe04 100644 --- a/browser/devtools/shared/DeveloperToolbar.jsm +++ b/browser/devtools/shared/DeveloperToolbar.jsm @@ -343,9 +343,6 @@ DeveloperToolbar.prototype._notify = function DT_notify(aTopic) DeveloperToolbar.prototype.handleEvent = function DT_handleEvent(aEvent) { if (aEvent.type == "TabSelect" || aEvent.type == "load") { - this._chromeWindow.HUDConsoleUI.refreshCommand(); - this._chromeWindow.DebuggerUI.refreshCommand(); - if (this.visible) { let contentDocument = this._chromeWindow.getBrowser().contentDocument; diff --git a/browser/devtools/webconsole/HUDService.jsm b/browser/devtools/webconsole/HUDService.jsm index bc4e40a53ba..3746251d0ae 100644 --- a/browser/devtools/webconsole/HUDService.jsm +++ b/browser/devtools/webconsole/HUDService.jsm @@ -251,6 +251,7 @@ function HUD_SERVICE() // These methods access the "this" object, but they're registered as // event listeners. So we hammer in the "this" binding. this.onTabClose = this.onTabClose.bind(this); + this.onTabSelect = this.onTabSelect.bind(this); this.onWindowUnload = this.onWindowUnload.bind(this); // Remembers the last console height, in pixels. @@ -317,6 +318,7 @@ HUD_SERVICE.prototype = // TODO: check that this works as intended gBrowser.tabContainer.addEventListener("TabClose", this.onTabClose, false); + gBrowser.tabContainer.addEventListener("TabSelect", this.onTabSelect, false); window.addEventListener("unload", this.onWindowUnload, false); this.registerDisplay(hudId); @@ -616,6 +618,7 @@ HUD_SERVICE.prototype = let gBrowser = window.gBrowser; let tabContainer = gBrowser.tabContainer; tabContainer.removeEventListener("TabClose", this.onTabClose, false); + tabContainer.removeEventListener("TabSelect", this.onTabSelect, false); this.suspend(); } @@ -803,6 +806,17 @@ HUD_SERVICE.prototype = 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 * around. @@ -821,6 +835,7 @@ HUD_SERVICE.prototype = let tabContainer = gBrowser.tabContainer; tabContainer.removeEventListener("TabClose", this.onTabClose, false); + tabContainer.removeEventListener("TabSelect", this.onTabSelect, false); let tab = tabContainer.firstChild; while (tab != null) { @@ -4431,7 +4446,7 @@ HeadsUpDisplayUICommands = { if (this.getOpenHUD() != null) { command.setAttribute("checked", true); } else { - command.removeAttribute("checked"); + command.setAttribute("checked", false); } }, diff --git a/browser/devtools/webconsole/test/Makefile.in b/browser/devtools/webconsole/test/Makefile.in index b6dc1212ca3..3c0babc4e98 100644 --- a/browser/devtools/webconsole/test/Makefile.in +++ b/browser/devtools/webconsole/test/Makefile.in @@ -109,6 +109,7 @@ _BROWSER_TEST_FILES = \ browser_webconsole_window_zombie.js \ browser_cached_messages.js \ browser_bug664688_sandbox_update_after_navigation.js \ + browser_webconsole_menustatus.js \ head.js \ $(NULL) diff --git a/browser/devtools/webconsole/test/browser_webconsole_menustatus.js b/browser/devtools/webconsole/test/browser_webconsole_menustatus.js new file mode 100644 index 00000000000..794122beefc --- /dev/null +++ b/browser/devtools/webconsole/test/browser_webconsole_menustatus.js @@ -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", " is checked."); + + gBrowser.selectedTab = tab1; + + is(cmd.getAttribute("checked"), "false", " is unchecked after tab switch."); + + gBrowser.selectedTab = tab2; + + is(cmd.getAttribute("checked"), "true", " is checked."); + + closeConsole(tab2, function() { + is(cmd.getAttribute("checked"), "false", " is checked once closed."); + + gBrowser.removeTab(tab1); + gBrowser.removeTab(tab2); + + finish(); + }); + }); +}