michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const BUTTONID = "test-XUL-wrapper-widget"; michael@0: add_task(function() { michael@0: let btn = createDummyXULButton(BUTTONID, "XUL btn"); michael@0: gNavToolbox.palette.appendChild(btn); michael@0: let groupWrapper = CustomizableUI.getWidget(BUTTONID); michael@0: ok(groupWrapper, "Should get a group wrapper"); michael@0: let singleWrapper = groupWrapper.forWindow(window); michael@0: ok(singleWrapper, "Should get a single wrapper"); michael@0: is(singleWrapper.node, btn, "Node should be in the wrapper"); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, btn, "Button should be that instance."); michael@0: michael@0: CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR); michael@0: michael@0: let otherSingleWrapper = groupWrapper.forWindow(window); michael@0: is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after adding the node to the navbar."); michael@0: is(singleWrapper.node, btn, "Node should be in the wrapper"); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, btn, "Button should be that instance."); michael@0: michael@0: CustomizableUI.removeWidgetFromArea(BUTTONID); michael@0: michael@0: otherSingleWrapper = groupWrapper.forWindow(window); michael@0: isnot(singleWrapper, otherSingleWrapper, "Shouldn't get the same wrapper after removing it from the navbar."); michael@0: singleWrapper = otherSingleWrapper; michael@0: is(singleWrapper.node, btn, "Node should be in the wrapper"); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, btn, "Button should be that instance."); michael@0: michael@0: btn.remove(); michael@0: otherSingleWrapper = groupWrapper.forWindow(window); michael@0: is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after physically removing the node."); michael@0: is(singleWrapper.node, null, "Wrapper's node should be null now that it's left the DOM."); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, null, "That instance should be null."); michael@0: michael@0: btn = createDummyXULButton(BUTTONID, "XUL btn"); michael@0: gNavToolbox.palette.appendChild(btn); michael@0: otherSingleWrapper = groupWrapper.forWindow(window); michael@0: is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after readding the node."); michael@0: is(singleWrapper.node, btn, "Node should be in the wrapper"); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, btn, "Button should be that instance."); michael@0: michael@0: CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR); michael@0: michael@0: otherSingleWrapper = groupWrapper.forWindow(window); michael@0: is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after adding the node to the navbar."); michael@0: is(singleWrapper.node, btn, "Node should be in the wrapper"); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, btn, "Button should be that instance."); michael@0: michael@0: CustomizableUI.removeWidgetFromArea(BUTTONID); michael@0: michael@0: otherSingleWrapper = groupWrapper.forWindow(window); michael@0: isnot(singleWrapper, otherSingleWrapper, "Shouldn't get the same wrapper after removing it from the navbar."); michael@0: singleWrapper = otherSingleWrapper; michael@0: is(singleWrapper.node, btn, "Node should be in the wrapper"); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, btn, "Button should be that instance."); michael@0: michael@0: btn.remove(); michael@0: otherSingleWrapper = groupWrapper.forWindow(window); michael@0: is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after physically removing the node."); michael@0: is(singleWrapper.node, null, "Wrapper's node should be null now that it's left the DOM."); michael@0: is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); michael@0: is(groupWrapper.instances[0].node, null, "That instance should be null."); michael@0: });