1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/customizableui/test/browser_987177_xul_wrapper_updating.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +const BUTTONID = "test-XUL-wrapper-widget"; 1.11 +add_task(function() { 1.12 + let btn = createDummyXULButton(BUTTONID, "XUL btn"); 1.13 + gNavToolbox.palette.appendChild(btn); 1.14 + let groupWrapper = CustomizableUI.getWidget(BUTTONID); 1.15 + ok(groupWrapper, "Should get a group wrapper"); 1.16 + let singleWrapper = groupWrapper.forWindow(window); 1.17 + ok(singleWrapper, "Should get a single wrapper"); 1.18 + is(singleWrapper.node, btn, "Node should be in the wrapper"); 1.19 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.20 + is(groupWrapper.instances[0].node, btn, "Button should be that instance."); 1.21 + 1.22 + CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR); 1.23 + 1.24 + let otherSingleWrapper = groupWrapper.forWindow(window); 1.25 + is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after adding the node to the navbar."); 1.26 + is(singleWrapper.node, btn, "Node should be in the wrapper"); 1.27 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.28 + is(groupWrapper.instances[0].node, btn, "Button should be that instance."); 1.29 + 1.30 + CustomizableUI.removeWidgetFromArea(BUTTONID); 1.31 + 1.32 + otherSingleWrapper = groupWrapper.forWindow(window); 1.33 + isnot(singleWrapper, otherSingleWrapper, "Shouldn't get the same wrapper after removing it from the navbar."); 1.34 + singleWrapper = otherSingleWrapper; 1.35 + is(singleWrapper.node, btn, "Node should be in the wrapper"); 1.36 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.37 + is(groupWrapper.instances[0].node, btn, "Button should be that instance."); 1.38 + 1.39 + btn.remove(); 1.40 + otherSingleWrapper = groupWrapper.forWindow(window); 1.41 + is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after physically removing the node."); 1.42 + is(singleWrapper.node, null, "Wrapper's node should be null now that it's left the DOM."); 1.43 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.44 + is(groupWrapper.instances[0].node, null, "That instance should be null."); 1.45 + 1.46 + btn = createDummyXULButton(BUTTONID, "XUL btn"); 1.47 + gNavToolbox.palette.appendChild(btn); 1.48 + otherSingleWrapper = groupWrapper.forWindow(window); 1.49 + is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after readding the node."); 1.50 + is(singleWrapper.node, btn, "Node should be in the wrapper"); 1.51 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.52 + is(groupWrapper.instances[0].node, btn, "Button should be that instance."); 1.53 + 1.54 + CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR); 1.55 + 1.56 + otherSingleWrapper = groupWrapper.forWindow(window); 1.57 + is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after adding the node to the navbar."); 1.58 + is(singleWrapper.node, btn, "Node should be in the wrapper"); 1.59 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.60 + is(groupWrapper.instances[0].node, btn, "Button should be that instance."); 1.61 + 1.62 + CustomizableUI.removeWidgetFromArea(BUTTONID); 1.63 + 1.64 + otherSingleWrapper = groupWrapper.forWindow(window); 1.65 + isnot(singleWrapper, otherSingleWrapper, "Shouldn't get the same wrapper after removing it from the navbar."); 1.66 + singleWrapper = otherSingleWrapper; 1.67 + is(singleWrapper.node, btn, "Node should be in the wrapper"); 1.68 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.69 + is(groupWrapper.instances[0].node, btn, "Button should be that instance."); 1.70 + 1.71 + btn.remove(); 1.72 + otherSingleWrapper = groupWrapper.forWindow(window); 1.73 + is(singleWrapper, otherSingleWrapper, "Should get the same wrapper after physically removing the node."); 1.74 + is(singleWrapper.node, null, "Wrapper's node should be null now that it's left the DOM."); 1.75 + is(groupWrapper.instances.length, 1, "There should be 1 instance on the group wrapper"); 1.76 + is(groupWrapper.instances[0].node, null, "That instance should be null."); 1.77 +});