Bug 992747 - toolbar visibility setting doesn't work for non-customizable toolbars, r=jaws, a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 09 Apr 2014 01:35:58 +0100
changeset 192789 0708916df1f5d0936f1e01a82ca3ed2b49088d9f
parent 192788 45bc38355d994390ce29ab174f6a7390e9ae7f9f
child 192790 3617c980e9e168273f9c805f4de1a8cc0b939d7e
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, sylvestre
bugs992747
milestone30.0a2
Bug 992747 - toolbar visibility setting doesn't work for non-customizable toolbars, r=jaws, a=sylvestre
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_992747_toggle_noncustomizable_toolbar.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -2407,30 +2407,24 @@ let CustomizableUIInternal = {
       LOG(kPrefDrawInTitlebar + " pref is non-default");
       return false;
     }
 
     return true;
   },
 
   setToolbarVisibility: function(aToolbarId, aIsVisible) {
-    let area = gAreas.get(aToolbarId);
-    if (area.get("type") != CustomizableUI.TYPE_TOOLBAR) {
-      return;
-    }
-    let areaNodes = gBuildAreas.get(aToolbarId);
-    if (!areaNodes) {
-      return;
-    }
     // We only persist the attribute the first time.
     let isFirstChangedToolbar = true;
-    for (let areaNode of areaNodes) {
-      let window = areaNode.ownerDocument.defaultView;
-      window.setToolbarVisibility(areaNode, aIsVisible, isFirstChangedToolbar);
-      isFirstChangedToolbar = false;
+    for (let window of CustomizableUI.windows) {
+      let toolbar = window.document.getElementById(aToolbarId);
+      if (toolbar) {
+        window.setToolbarVisibility(toolbar, aIsVisible, isFirstChangedToolbar);
+        isFirstChangedToolbar = false;
+      }
     }
   },
 };
 Object.freeze(CustomizableUIInternal);
 
 this.CustomizableUI = {
   /**
    * Constant reference to the ID of the menu panel.
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -87,9 +87,10 @@ skip-if = os == "linux"
 skip-if = os == "linux"
 
 [browser_985815_propagate_setToolbarVisibility.js]
 [browser_981305_separator_insertion.js]
 [browser_989609_bootstrapped_custom_toolbar.js]
 [browser_987177_destroyWidget_xul.js]
 [browser_987177_xul_wrapper_updating.js]
 [browser_987492_window_api.js]
+[browser_992747_toggle_noncustomizable_toolbar.js]
 [browser_panel_toggle.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_992747_toggle_noncustomizable_toolbar.js
@@ -0,0 +1,26 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const TOOLBARID = "test-noncustomizable-toolbar-for-toggling";
+function test() {
+  let tb = document.createElementNS(kNSXUL, "toolbar");
+  tb.id = TOOLBARID;
+  gNavToolbox.appendChild(tb);
+  try {
+    CustomizableUI.setToolbarVisibility(TOOLBARID, false);
+  } catch (ex) {
+    ok(false, "Should not throw exceptions trying to set toolbar visibility.");
+  }
+  is(tb.getAttribute("collapsed"), "true", "Toolbar should be collapsed");
+  try {
+    CustomizableUI.setToolbarVisibility(TOOLBARID, true);
+  } catch (ex) {
+    ok(false, "Should not throw exceptions trying to set toolbar visibility.");
+  }
+  is(tb.getAttribute("collapsed"), "false", "Toolbar should be uncollapsed");
+  tb.remove();
+};
+