From 906440ab3795ccfc13f6172fa4d6d6a8d901f27f Mon Sep 17 00:00:00 2001 From: Jordan Santell Date: Thu, 27 Mar 2014 12:32:00 +0100 Subject: [PATCH] Bug 987890 - Hide unused tools when using addon debugger. r=jryans --- browser/devtools/debugger/test/browser.ini | 1 + .../debugger/test/browser_dbg_addon-panels.js | 80 +++++++++++++++++++ browser/devtools/framework/target.js | 4 + browser/devtools/main.js | 14 ++-- 4 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 browser/devtools/debugger/test/browser_dbg_addon-panels.js diff --git a/browser/devtools/debugger/test/browser.ini b/browser/devtools/debugger/test/browser.ini index 01b4f4da386e..366cc8f3d350 100644 --- a/browser/devtools/debugger/test/browser.ini +++ b/browser/devtools/debugger/test/browser.ini @@ -85,6 +85,7 @@ support-files = [browser_dbg_addonactor.js] [browser_dbg_addon-sources.js] [browser_dbg_addon-modules.js] +[browser_dbg_addon-panels.js] [browser_dbg_auto-pretty-print-01.js] [browser_dbg_auto-pretty-print-02.js] [browser_dbg_bfcache.js] diff --git a/browser/devtools/debugger/test/browser_dbg_addon-panels.js b/browser/devtools/debugger/test/browser_dbg_addon-panels.js new file mode 100644 index 000000000000..498b04bfd3d5 --- /dev/null +++ b/browser/devtools/debugger/test/browser_dbg_addon-panels.js @@ -0,0 +1,80 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Ensure that only panels that are relevant to the addon debugger +// display in the toolbox + +const ADDON3_URL = EXAMPLE_URL + "addon3.xpi"; + +let gAddon, gClient, gThreadClient, gDebugger, gSources; + +function test() { + Task.spawn(function () { + if (!DebuggerServer.initialized) { + DebuggerServer.init(() => true); + DebuggerServer.addBrowserActors(); + } + + gBrowser.selectedTab = gBrowser.addTab(); + let iframe = document.createElement("iframe"); + document.documentElement.appendChild(iframe); + + let transport = DebuggerServer.connectPipe(); + gClient = new DebuggerClient(transport); + + let connected = promise.defer(); + gClient.connect(connected.resolve); + yield connected.promise; + + yield installAddon(); + let debuggerPanel = yield initAddonDebugger(gClient, ADDON3_URL, iframe); + gDebugger = debuggerPanel.panelWin; + gThreadClient = gDebugger.gThreadClient; + gSources = gDebugger.DebuggerView.Sources; + + testPanels(iframe); + yield uninstallAddon(); + yield closeConnection(); + yield debuggerPanel._toolbox.destroy(); + iframe.remove(); + finish(); + }); +} + +function installAddon () { + return addAddon(ADDON3_URL).then(aAddon => { + gAddon = aAddon; + }); +} + +function testPanels(frame) { + let tabs = frame.contentDocument.getElementById("toolbox-tabs").children; + let expectedTabs = ["options", "jsdebugger"]; + + is(tabs.length, 2, "displaying only 2 tabs in addon debugger"); + Array.forEach(tabs, (tab, i) => { + let toolName = expectedTabs[i]; + is(tab.getAttribute("toolid"), toolName, "displaying " + toolName); + }); +} + +function uninstallAddon() { + return removeAddon(gAddon); +} + +function closeConnection () { + let deferred = promise.defer(); + gClient.close(deferred.resolve); + return deferred.promise; +} + +registerCleanupFunction(function() { + gClient = null; + gAddon = null; + gThreadClient = null; + gDebugger = null; + gSources = null; + while (gBrowser.tabs.length > 1) { + gBrowser.removeCurrentTab(); + } +}); diff --git a/browser/devtools/framework/target.js b/browser/devtools/framework/target.js index f78bec359d45..770b8061038a 100644 --- a/browser/devtools/framework/target.js +++ b/browser/devtools/framework/target.js @@ -242,6 +242,10 @@ TabTarget.prototype = { return !this.isLocalTab; }, + get isAddon() { + return !!(this._form && this._form.addonActor); + }, + get isLocalTab() { return !!this._tab; }, diff --git a/browser/devtools/main.js b/browser/devtools/main.js index 9f37ef853ea1..6393fefdbc1f 100644 --- a/browser/devtools/main.js +++ b/browser/devtools/main.js @@ -97,7 +97,7 @@ Tools.webConsole = { }, isTargetSupported: function(target) { - return true; + return !target.isAddon; }, build: function(iframeWindow, toolbox) { let panel = new WebConsolePanel(iframeWindow, toolbox); @@ -124,7 +124,7 @@ Tools.inspector = { }, isTargetSupported: function(target) { - return true; + return !target.isAddon; }, build: function(iframeWindow, toolbox) { @@ -171,7 +171,7 @@ Tools.styleEditor = { inMenu: true, isTargetSupported: function(target) { - return true; + return !target.isAddon; }, build: function(iframeWindow, toolbox) { @@ -191,7 +191,7 @@ Tools.shaderEditor = { tooltip: l10n("ToolboxShaderEditor.tooltip", shaderEditorStrings), isTargetSupported: function(target) { - return true; + return !target.isAddon; }, build: function(iframeWindow, toolbox) { @@ -215,7 +215,7 @@ Tools.jsprofiler = { inMenu: true, isTargetSupported: function (target) { - return true; + return !target.isAddon; }, build: function (frame, target) { @@ -240,7 +240,7 @@ Tools.netMonitor = { isTargetSupported: function(target) { let root = target.client.mainRoot; - return root.traits.networkMonitor || !target.isApp; + return !target.isAddon && (root.traits.networkMonitor || !target.isApp); }, build: function(iframeWindow, toolbox) { @@ -261,7 +261,7 @@ Tools.scratchpad = { inMenu: false, isTargetSupported: function(target) { - return target.isRemote; + return !target.isAddon && target.isRemote; }, build: function(iframeWindow, toolbox) {