The toolbox should expect the previously selected tool to be unavailable (bug 915448). r=bgrins
authorPanos Astithas <past@mozilla.com>
Mon, 11 May 2015 12:27:23 +0300
changeset 263026 a6b952b85bc6b79e277667048bf1d59da9bbc473
parent 263025 9068caa791d14a505942650f326bb7972bacbe0a
child 263027 cf1c3e838ac128e67c9f384767c85ecb35eb38f6
push id8157
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:36:23 +0000
treeherdermozilla-aurora@d480e05bd276 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs915448
milestone40.0a1
The toolbox should expect the previously selected tool to be unavailable (bug 915448). r=bgrins
browser/devtools/framework/test/browser.ini
browser/devtools/framework/test/browser_toolbox_selected_tool_unavailable.js
browser/devtools/framework/toolbox.js
--- a/browser/devtools/framework/test/browser.ini
+++ b/browser/devtools/framework/test/browser.ini
@@ -59,12 +59,13 @@ skip-if = e10s # Bug 1069044 - destroyIn
 [browser_toolbox_window_shortcuts.js]
 skip-if = os == "mac" && os_version == "10.8" || os == "win" && os_version == "5.1" # Bug 851129 - Re-enable browser_toolbox_window_shortcuts.js test after leaks are fixed
 [browser_toolbox_window_title_changes.js]
 [browser_toolbox_zoom.js]
 [browser_toolbox_custom_host.js]
 [browser_toolbox_theme_registration.js]
 [browser_toolbox_options_enable_serviceworkers_testing.js]
 skip-if = true # Bug 1153407 - this test breaks subsequent tests and is not e10s compatible
+[browser_toolbox_selected_tool_unavailable.js]
 
 # We want this test to run for mochitest-dt as well, so we include it here:
 [../../../base/content/test/general/browser_parsable_css.js]
 
new file mode 100644
--- /dev/null
+++ b/browser/devtools/framework/test/browser_toolbox_selected_tool_unavailable.js
@@ -0,0 +1,43 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Test that opening the toolbox doesn't throw when the previously selected
+// tool is not supported.
+
+const testToolDefinition = {
+    id: "test-tool",
+    isTargetSupported: () => true,
+    visibilityswitch: "devtools.test-tool.enabled",
+    url: "about:blank",
+    label: "someLabel",
+    build: (iframeWindow, toolbox) => {
+      return {
+        target: toolbox.target,
+        toolbox: toolbox,
+        isReady: true,
+        destroy: () => {},
+        panelDoc: iframeWindow.document
+      };
+    }
+  };
+
+add_task(function*() {
+  gDevTools.registerTool(testToolDefinition);
+  let tab = yield addTab("about:blank");
+  let target = TargetFactory.forTab(tab);
+
+  let toolbox = yield gDevTools.showToolbox(target, testToolDefinition.id);
+  is(toolbox.currentToolId, "test-tool", "test-tool was selected");
+  yield gDevTools.closeToolbox(target);
+
+  // Make the previously selected tool unavailable.
+  testToolDefinition.isTargetSupported = () => false;
+
+  target = TargetFactory.forTab(tab);
+  toolbox = yield gDevTools.showToolbox(target);
+  is(toolbox.currentToolId, "webconsole", "web console was selected");
+
+  gDevTools.unregisterTool(testToolDefinition.id);
+  gBrowser.removeCurrentTab();
+});
--- a/browser/devtools/framework/toolbox.js
+++ b/browser/devtools/framework/toolbox.js
@@ -132,19 +132,16 @@ function Toolbox(target, selectedTool, h
   this._target.on("close", this.destroy);
 
   if (!hostType) {
     hostType = Services.prefs.getCharPref(this._prefs.LAST_HOST);
   }
   if (!selectedTool) {
     selectedTool = Services.prefs.getCharPref(this._prefs.LAST_TOOL);
   }
-  if (!gDevTools.getToolDefinition(selectedTool)) {
-    selectedTool = "webconsole";
-  }
   this._defaultToolId = selectedTool;
 
   this._hostOptions = hostOptions;
   this._host = this._createHost(hostType, hostOptions);
 
   EventEmitter.decorate(this);
 
   this._target.on("navigate", this._refreshHostTitle);
@@ -365,16 +362,24 @@ Toolbox.prototype = {
       this.webconsolePanel = this.doc.querySelector("#toolbox-panel-webconsole");
       this.webconsolePanel.height = Services.prefs.getIntPref(SPLITCONSOLE_HEIGHT_PREF);
       this.webconsolePanel.addEventListener("resize", this._saveSplitConsoleHeight);
 
       let buttonsPromise = this._buildButtons();
 
       this._pingTelemetry();
 
+      // The isTargetSupported check needs to happen after the target is
+      // remoted, otherwise we could have done it in the toolbox constructor
+      // (bug 1072764).
+      let toolDef = gDevTools.getToolDefinition(this._defaultToolId);
+      if (!toolDef || !toolDef.isTargetSupported(this._target)) {
+        this._defaultToolId = "webconsole";
+      }
+
       yield this.selectTool(this._defaultToolId);
 
       // Wait until the original tool is selected so that the split
       // console input will receive focus.
       let splitConsolePromise = promise.resolve();
       if (Services.prefs.getBoolPref(SPLITCONSOLE_ENABLED_PREF)) {
         splitConsolePromise = this.openSplitConsole();
       }