Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const kToolbarName = "test-unregisterArea-placements-toolbar"; |
michael@0 | 8 | const kTestWidgetPfx = "test-widget-for-unregisterArea-placements-"; |
michael@0 | 9 | const kTestWidgetCount = 3; |
michael@0 | 10 | registerCleanupFunction(removeCustomToolbars); |
michael@0 | 11 | |
michael@0 | 12 | // unregisterArea should keep placements by default and restore them when re-adding the area |
michael@0 | 13 | add_task(function() { |
michael@0 | 14 | let widgetIds = []; |
michael@0 | 15 | for (let i = 0; i < kTestWidgetCount; i++) { |
michael@0 | 16 | let id = kTestWidgetPfx + i; |
michael@0 | 17 | widgetIds.push(id); |
michael@0 | 18 | let spec = {id: id, type: 'button', removable: true, label: "unregisterArea test", tooltiptext: "" + i}; |
michael@0 | 19 | CustomizableUI.createWidget(spec); |
michael@0 | 20 | } |
michael@0 | 21 | for (let i = kTestWidgetCount; i < kTestWidgetCount * 2; i++) { |
michael@0 | 22 | let id = kTestWidgetPfx + i; |
michael@0 | 23 | widgetIds.push(id); |
michael@0 | 24 | createDummyXULButton(id, "unregisterArea XUL test " + i); |
michael@0 | 25 | } |
michael@0 | 26 | let toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds); |
michael@0 | 27 | checkAbstractAndRealPlacements(toolbarNode, widgetIds); |
michael@0 | 28 | |
michael@0 | 29 | // Now move one of them: |
michael@0 | 30 | CustomizableUI.moveWidgetWithinArea(kTestWidgetPfx + kTestWidgetCount, 0); |
michael@0 | 31 | // Clone the array so we know this is the modified one: |
michael@0 | 32 | let modifiedWidgetIds = [...widgetIds]; |
michael@0 | 33 | let movedWidget = modifiedWidgetIds.splice(kTestWidgetCount, 1)[0]; |
michael@0 | 34 | modifiedWidgetIds.unshift(movedWidget); |
michael@0 | 35 | |
michael@0 | 36 | // Check it: |
michael@0 | 37 | checkAbstractAndRealPlacements(toolbarNode, modifiedWidgetIds); |
michael@0 | 38 | |
michael@0 | 39 | // Then unregister |
michael@0 | 40 | CustomizableUI.unregisterArea(kToolbarName); |
michael@0 | 41 | |
michael@0 | 42 | // Check we tell the outside world no dangerous things: |
michael@0 | 43 | checkWidgetFates(widgetIds); |
michael@0 | 44 | // Only then remove the real node |
michael@0 | 45 | toolbarNode.remove(); |
michael@0 | 46 | |
michael@0 | 47 | // Now move one of the items to the palette, and another to the navbar: |
michael@0 | 48 | let lastWidget = modifiedWidgetIds.pop(); |
michael@0 | 49 | CustomizableUI.removeWidgetFromArea(lastWidget); |
michael@0 | 50 | lastWidget = modifiedWidgetIds.pop(); |
michael@0 | 51 | CustomizableUI.addWidgetToArea(lastWidget, CustomizableUI.AREA_NAVBAR); |
michael@0 | 52 | |
michael@0 | 53 | // Recreate ourselves with the default placements being the same: |
michael@0 | 54 | toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds); |
michael@0 | 55 | // Then check that after doing this, our actual placements match |
michael@0 | 56 | // the modified list, not the default one. |
michael@0 | 57 | checkAbstractAndRealPlacements(toolbarNode, modifiedWidgetIds); |
michael@0 | 58 | |
michael@0 | 59 | // Now remove completely: |
michael@0 | 60 | CustomizableUI.unregisterArea(kToolbarName, true); |
michael@0 | 61 | checkWidgetFates(modifiedWidgetIds); |
michael@0 | 62 | toolbarNode.remove(); |
michael@0 | 63 | |
michael@0 | 64 | // One more time: |
michael@0 | 65 | // Recreate ourselves with the default placements being the same: |
michael@0 | 66 | toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds); |
michael@0 | 67 | // Should now be back to default: |
michael@0 | 68 | checkAbstractAndRealPlacements(toolbarNode, widgetIds); |
michael@0 | 69 | CustomizableUI.unregisterArea(kToolbarName, true); |
michael@0 | 70 | checkWidgetFates(widgetIds); |
michael@0 | 71 | toolbarNode.remove(); |
michael@0 | 72 | |
michael@0 | 73 | //XXXgijs: ensure cleanup function doesn't barf: |
michael@0 | 74 | gAddedToolbars.delete(kToolbarName); |
michael@0 | 75 | |
michael@0 | 76 | // Remove all the XUL widgets, destroy the others: |
michael@0 | 77 | for (let widget of widgetIds) { |
michael@0 | 78 | let widgetWrapper = CustomizableUI.getWidget(widget); |
michael@0 | 79 | if (widgetWrapper.provider == CustomizableUI.PROVIDER_XUL) { |
michael@0 | 80 | gNavToolbox.palette.querySelector("#" + widget).remove(); |
michael@0 | 81 | } else { |
michael@0 | 82 | CustomizableUI.destroyWidget(widget); |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | }); |
michael@0 | 86 | |
michael@0 | 87 | function checkAbstractAndRealPlacements(aNode, aExpectedPlacements) { |
michael@0 | 88 | assertAreaPlacements(kToolbarName, aExpectedPlacements); |
michael@0 | 89 | let physicalWidgetIds = [node.id for (node of aNode.childNodes)]; |
michael@0 | 90 | placementArraysEqual(aNode.id, physicalWidgetIds, aExpectedPlacements); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function checkWidgetFates(aWidgetIds) { |
michael@0 | 94 | for (let widget of aWidgetIds) { |
michael@0 | 95 | ok(!CustomizableUI.getPlacementOfWidget(widget), "Widget should be in palette"); |
michael@0 | 96 | ok(!document.getElementById(widget), "Widget should not be in the DOM"); |
michael@0 | 97 | let widgetInPalette = !!gNavToolbox.palette.querySelector("#" + widget); |
michael@0 | 98 | let widgetProvider = CustomizableUI.getWidget(widget).provider; |
michael@0 | 99 | let widgetIsXULWidget = widgetProvider == CustomizableUI.PROVIDER_XUL; |
michael@0 | 100 | is(widgetInPalette, widgetIsXULWidget, "Just XUL Widgets should be in the palette"); |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | add_task(function asyncCleanup() { |
michael@0 | 105 | yield resetCustomization(); |
michael@0 | 106 | }); |