Bug 1455204 - Hide close button on browser console and browser toolbox. r=jdescottes
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Thu, 19 Apr 2018 14:56:42 +0900
changeset 785554 52c80343da5c424f9c4fd546c1b35fbb86623087
parent 785553 fe6ac84d5ee45f7ddd9e4ffa494c3404fccbf20f
child 785555 2c056f8eeb11e1358fc9a2fce970bf7c86a87b76
push id107257
push userdgottwald@mozilla.com
push dateFri, 20 Apr 2018 10:55:57 +0000
reviewersjdescottes
bugs1455204
milestone61.0a1
Bug 1455204 - Hide close button on browser console and browser toolbox. r=jdescottes This patch will hide toolbar's close button if debug target is not local tab like browser toolbox. MozReview-Commit-ID: Guf6QhzkGIV
devtools/client/framework/test/browser_browser_toolbox.js
devtools/client/framework/toolbox.js
--- a/devtools/client/framework/test/browser_browser_toolbox.js
+++ b/devtools/client/framework/test/browser_browser_toolbox.js
@@ -24,30 +24,33 @@ add_task(async function() {
       ["devtools.debugger.remote-timeout", 120000]
     ]};
     SpecialPowers.pushPrefEnv(options, done);
   });
 
   // Wait for a notification sent by a script evaluated in the webconsole
   // of the browser toolbox.
   let onCustomMessage = new Promise(done => {
-    Services.obs.addObserver(function listener() {
+    Services.obs.addObserver(function listener(target, aTop, data) {
       Services.obs.removeObserver(listener, "browser-toolbox-console-works");
-      done();
+      done(data === "true");
     }, "browser-toolbox-console-works");
   });
 
   // Be careful, this JS function is going to be executed in the addon toolbox,
   // which lives in another process. So do not try to use any scope variable!
   let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
   let testScript = function() {
     toolbox.selectTool("webconsole")
       .then(console => {
+        // This is for checking Browser Toolbox doesn't have a close button.
+        let hasCloseButton = !!toolbox.doc.getElementById("toolbox-close");
         let { jsterm } = console.hud;
-        let js = "Services.obs.notifyObservers(null, 'browser-toolbox-console-works', null);";
+        let js = "Services.obs.notifyObservers(null, 'browser-toolbox-console-works', " +
+            hasCloseButton + ");";
         return jsterm.execute(js);
       })
       .then(() => toolbox.destroy());
   };
   env.set("MOZ_TOOLBOX_TEST_SCRIPT", "new " + testScript);
   registerCleanupFunction(() => {
     env.set("MOZ_TOOLBOX_TEST_SCRIPT", "");
   });
@@ -60,15 +63,16 @@ add_task(async function() {
     closePromise = new Promise(onClose => {
       info("Opening the browser toolbox\n");
       BrowserToolboxProcess.init(onClose, onRun);
     });
   });
   ok(true, "Browser toolbox started\n");
   is(BrowserToolboxProcess.getBrowserToolboxSessionState(), true, "Has session state");
 
-  await onCustomMessage;
+  let hasCloseButton = await onCustomMessage;
   ok(true, "Received the custom message");
+  ok(!hasCloseButton, "Browser toolbox doesn't have a close button");
 
   await closePromise;
   ok(true, "Browser toolbox process just closed");
   is(BrowserToolboxProcess.getBrowserToolboxSessionState(), false, "No session state after closing");
 });
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -1077,16 +1077,17 @@ Toolbox.prototype = {
 
   /**
    * Build the options for changing hosts. Called every time
    * the host changes.
    */
   _buildDockOptions: function() {
     if (!this._target.isLocalTab) {
       this.component.setDockOptionsEnabled(false);
+      this.component.setCanCloseToolbox(false);
       return;
     }
 
     this.component.setDockOptionsEnabled(true);
     this.component.setCanCloseToolbox(this.hostType !== Toolbox.HostType.WINDOW);
 
     let sideEnabled = Services.prefs.getBoolPref(this._prefs.SIDE_ENABLED);