From 5e1e03e41e3dba7b1f38a140176eb253e14be233 Mon Sep 17 00:00:00 2001 From: Blair McBride Date: Fri, 7 Mar 2014 05:19:00 -0500 Subject: [PATCH] Bug 980155 - [Australis] Initialization of overflowable toolbars breaks when adding them dynamically. r=Gijs r=jaws --- browser/base/content/browser.xul | 1 + .../customizableui/src/CustomizableUI.jsm | 10 +++- .../customizableui/test/browser.ini | 1 + .../browser_980155_add_overflow_toolbar.js | 51 +++++++++++++++++++ .../components/customizableui/test/head.js | 48 ++++++++++++++++- 5 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 browser/components/customizableui/test/browser_980155_add_overflow_toolbar.js diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 2e945234fc7..e1b99fa71a4 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -631,6 +631,7 @@ overflowable="true" overflowbutton="nav-bar-overflow-button" overflowtarget="widget-overflow-list" + overflowpanel="widget-overflow" context="toolbar-context-menu"> diff --git a/browser/components/customizableui/src/CustomizableUI.jsm b/browser/components/customizableui/src/CustomizableUI.jsm index 80025a67bdb..0473fbccd1d 100644 --- a/browser/components/customizableui/src/CustomizableUI.jsm +++ b/browser/components/customizableui/src/CustomizableUI.jsm @@ -3455,7 +3455,12 @@ function OverflowableToolbar(aToolbarNode) { this._list.toolbox = this._toolbar.toolbox; this._list.customizationTarget = this._list; - Services.obs.addObserver(this, "browser-delayed-startup-finished", false); + let window = this._toolbar.ownerDocument.defaultView; + if (window.gBrowserInit.delayedStartupFinished) { + this.init(); + } else { + Services.obs.addObserver(this, "browser-delayed-startup-finished", false); + } } OverflowableToolbar.prototype = { @@ -3481,7 +3486,8 @@ OverflowableToolbar.prototype = { this._chevron = doc.getElementById(chevronId); this._chevron.addEventListener("command", this); - this._panel = doc.getElementById("widget-overflow"); + let panelId = this._toolbar.getAttribute("overflowpanel"); + this._panel = doc.getElementById(panelId); this._panel.addEventListener("popuphiding", this); CustomizableUIInternal.addPanelCloseListeners(this._panel); diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index c0e9fac4511..e9b27cc9e85 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -74,5 +74,6 @@ skip-if = os == "linux" [browser_973932_addonbar_currentset.js] [browser_975719_customtoolbars_behaviour.js] [browser_978084_dragEnd_after_move.js] +[browser_980155_add_overflow_toolbar.js] [browser_981418-widget-onbeforecreated-handler.js] [browser_panel_toggle.js] diff --git a/browser/components/customizableui/test/browser_980155_add_overflow_toolbar.js b/browser/components/customizableui/test/browser_980155_add_overflow_toolbar.js new file mode 100644 index 00000000000..043645009d0 --- /dev/null +++ b/browser/components/customizableui/test/browser_980155_add_overflow_toolbar.js @@ -0,0 +1,51 @@ +/* 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 kToolbarName = "test-new-overflowable-toolbar"; +const kTestWidgetPrefix = "test-widget-for-overflowable-toolbar-"; + +add_task(function addOverflowingToolbar() { + let originalWindowWidth = window.outerWidth; + + let widgetIds = []; + for (let i = 0; i < 10; i++) { + let id = kTestWidgetPrefix + i; + widgetIds.push(id); + let spec = {id: id, type: "button", removable: true, label: "test", tooltiptext: "" + i}; + CustomizableUI.createWidget(spec); + } + + let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds); + assertAreaPlacements(kToolbarName, widgetIds); + + for (let id of widgetIds) { + document.getElementById(id).style.minWidth = "200px"; + } + + isnot(toolbarNode.overflowable, null, "Toolbar should have overflowable controller"); + isnot(toolbarNode.customizationTarget, null, "Toolbar should have customization target"); + isnot(toolbarNode.customizationTarget, toolbarNode, "Customization target should not be toolbar node"); + + let oldChildCount = toolbarNode.customizationTarget.childElementCount; + let overflowableList = document.getElementById(kToolbarName + "-overflow-list"); + let oldOverflowCount = overflowableList.childElementCount; + + isnot(oldChildCount, 0, "Toolbar should have non-overflowing widgets"); + + window.resizeTo(400, window.outerHeight); + yield waitForCondition(() => toolbarNode.hasAttribute("overflowing")); + ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar."); + ok(toolbarNode.customizationTarget.childElementCount < oldChildCount, "Should have fewer children."); + ok(overflowableList.childElementCount > oldOverflowCount, "Should have more overflowed widgets."); + + window.resizeTo(originalWindowWidth, window.outerHeight); +}); + + +add_task(function asyncCleanup() { + removeCustomToolbars(); + yield resetCustomization(); +}); diff --git a/browser/components/customizableui/test/head.js b/browser/components/customizableui/test/head.js index caf8739f710..f85d9727518 100644 --- a/browser/components/customizableui/test/head.js +++ b/browser/components/customizableui/test/head.js @@ -45,11 +45,57 @@ function createToolbarWithPlacements(id, placements = []) { return tb; } +function createOverflowableToolbarWithPlacements(id, placements) { + gAddedToolbars.add(id); + + let tb = document.createElementNS(kNSXUL, "toolbar"); + tb.id = id; + tb.setAttribute("customizationtarget", id + "-target"); + + let customizationtarget = document.createElementNS(kNSXUL, "hbox"); + customizationtarget.id = id + "-target"; + customizationtarget.setAttribute("flex", "1"); + tb.appendChild(customizationtarget); + + let overflowPanel = document.createElementNS(kNSXUL, "panel"); + overflowPanel.id = id + "-overflow"; + document.getElementById("mainPopupSet").appendChild(overflowPanel); + + let overflowList = document.createElementNS(kNSXUL, "vbox"); + overflowList.id = id + "-overflow-list"; + overflowPanel.appendChild(overflowList); + + let chevron = document.createElementNS(kNSXUL, "toolbarbutton"); + chevron.id = id + "-chevron"; + tb.appendChild(chevron); + + CustomizableUI.registerArea(id, { + type: CustomizableUI.TYPE_TOOLBAR, + defaultPlacements: placements, + overflowable: true, + }); + + tb.setAttribute("customizable", "true"); + tb.setAttribute("overflowable", "true"); + tb.setAttribute("overflowpanel", overflowPanel.id); + tb.setAttribute("overflowtarget", overflowList.id); + tb.setAttribute("overflowbutton", chevron.id); + + gNavToolbox.appendChild(tb); + return tb; +} + function removeCustomToolbars() { CustomizableUI.reset(); for (let toolbarId of gAddedToolbars) { CustomizableUI.unregisterArea(toolbarId, true); - document.getElementById(toolbarId).remove(); + let tb = document.getElementById(toolbarId); + if (tb.hasAttribute("overflowpanel")) { + let panel = document.getElementById(tb.getAttribute("overflowpanel")); + if (panel) + panel.remove(); + } + tb.remove(); } gAddedToolbars.clear(); }