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 kXULWidgetId = "sync-button"; |
michael@0 | 8 | const kAPIWidgetId = "feed-button"; |
michael@0 | 9 | const kPanel = CustomizableUI.AREA_PANEL; |
michael@0 | 10 | const kToolbar = CustomizableUI.AREA_NAVBAR; |
michael@0 | 11 | const kVisiblePalette = "customization-palette"; |
michael@0 | 12 | const kPlaceholderClass = "panel-customization-placeholder"; |
michael@0 | 13 | |
michael@0 | 14 | function checkWrapper(id) { |
michael@0 | 15 | is(document.querySelectorAll("#wrapper-" + id).length, 1, "There should be exactly 1 wrapper for " + id + " in the customizing window."); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | let move = { |
michael@0 | 19 | "drag": function(id, target) { |
michael@0 | 20 | let targetNode = document.getElementById(target); |
michael@0 | 21 | if (targetNode.customizationTarget) { |
michael@0 | 22 | targetNode = targetNode.customizationTarget; |
michael@0 | 23 | } |
michael@0 | 24 | simulateItemDrag(document.getElementById(id), targetNode); |
michael@0 | 25 | }, |
michael@0 | 26 | "dragToItem": function(id, target) { |
michael@0 | 27 | let targetNode = document.getElementById(target); |
michael@0 | 28 | if (targetNode.customizationTarget) { |
michael@0 | 29 | targetNode = targetNode.customizationTarget; |
michael@0 | 30 | } |
michael@0 | 31 | let items = targetNode.querySelectorAll("toolbarpaletteitem:not(." + kPlaceholderClass + ")"); |
michael@0 | 32 | if (target == kPanel) { |
michael@0 | 33 | targetNode = items[items.length - 1]; |
michael@0 | 34 | } else { |
michael@0 | 35 | targetNode = items[0]; |
michael@0 | 36 | } |
michael@0 | 37 | simulateItemDrag(document.getElementById(id), targetNode); |
michael@0 | 38 | }, |
michael@0 | 39 | "API": function(id, target) { |
michael@0 | 40 | if (target == kVisiblePalette) { |
michael@0 | 41 | return CustomizableUI.removeWidgetFromArea(id); |
michael@0 | 42 | } |
michael@0 | 43 | return CustomizableUI.addWidgetToArea(id, target, null); |
michael@0 | 44 | } |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | function isLast(containerId, defaultPlacements, id) { |
michael@0 | 48 | assertAreaPlacements(containerId, defaultPlacements.concat([id])); |
michael@0 | 49 | is(document.getElementById(containerId).customizationTarget.lastChild.firstChild.id, id, |
michael@0 | 50 | "Widget " + id + " should be in " + containerId + " in customizing window."); |
michael@0 | 51 | is(otherWin.document.getElementById(containerId).customizationTarget.lastChild.id, id, |
michael@0 | 52 | "Widget " + id + " should be in " + containerId + " in other window."); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function getLastVisibleNodeInToolbar(containerId, win=window) { |
michael@0 | 56 | let container = win.document.getElementById(containerId).customizationTarget; |
michael@0 | 57 | let rv = container.lastChild; |
michael@0 | 58 | while (rv && (rv.getAttribute('hidden') == 'true' || (rv.firstChild && rv.firstChild.getAttribute('hidden') == 'true'))) { |
michael@0 | 59 | rv = rv.previousSibling; |
michael@0 | 60 | } |
michael@0 | 61 | return rv; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function isLastVisibleInToolbar(containerId, defaultPlacements, id) { |
michael@0 | 65 | let newPlacements; |
michael@0 | 66 | for (let i = defaultPlacements.length - 1; i >= 0; i--) { |
michael@0 | 67 | let el = document.getElementById(defaultPlacements[i]); |
michael@0 | 68 | if (el && el.getAttribute('hidden') != 'true') { |
michael@0 | 69 | newPlacements = [...defaultPlacements]; |
michael@0 | 70 | newPlacements.splice(i + 1, 0, id); |
michael@0 | 71 | break; |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | if (!newPlacements) { |
michael@0 | 75 | assertAreaPlacements(containerId, defaultPlacements.concat([id])); |
michael@0 | 76 | } else { |
michael@0 | 77 | assertAreaPlacements(containerId, newPlacements); |
michael@0 | 78 | } |
michael@0 | 79 | is(getLastVisibleNodeInToolbar(containerId).firstChild.id, id, |
michael@0 | 80 | "Widget " + id + " should be in " + containerId + " in customizing window."); |
michael@0 | 81 | is(getLastVisibleNodeInToolbar(containerId, otherWin).id, id, |
michael@0 | 82 | "Widget " + id + " should be in " + containerId + " in other window."); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function isFirst(containerId, defaultPlacements, id) { |
michael@0 | 86 | assertAreaPlacements(containerId, [id].concat(defaultPlacements)); |
michael@0 | 87 | is(document.getElementById(containerId).customizationTarget.firstChild.firstChild.id, id, |
michael@0 | 88 | "Widget " + id + " should be in " + containerId + " in customizing window."); |
michael@0 | 89 | is(otherWin.document.getElementById(containerId).customizationTarget.firstChild.id, id, |
michael@0 | 90 | "Widget " + id + " should be in " + containerId + " in other window."); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function checkToolbar(id, method) { |
michael@0 | 94 | // Place at start of the toolbar: |
michael@0 | 95 | let toolbarPlacements = getAreaWidgetIds(kToolbar); |
michael@0 | 96 | move[method](id, kToolbar); |
michael@0 | 97 | if (method == "dragToItem") { |
michael@0 | 98 | isFirst(kToolbar, toolbarPlacements, id); |
michael@0 | 99 | } else if (method == "drag") { |
michael@0 | 100 | isLastVisibleInToolbar(kToolbar, toolbarPlacements, id); |
michael@0 | 101 | } else { |
michael@0 | 102 | isLast(kToolbar, toolbarPlacements, id); |
michael@0 | 103 | } |
michael@0 | 104 | checkWrapper(id); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function checkPanel(id, method) { |
michael@0 | 108 | let panelPlacements = getAreaWidgetIds(kPanel); |
michael@0 | 109 | move[method](id, kPanel); |
michael@0 | 110 | let children = document.getElementById(kPanel).querySelectorAll("toolbarpaletteitem:not(." + kPlaceholderClass + ")"); |
michael@0 | 111 | let otherChildren = otherWin.document.getElementById(kPanel).children; |
michael@0 | 112 | let newPlacements = panelPlacements.concat([id]); |
michael@0 | 113 | // Relative position of the new item from the end: |
michael@0 | 114 | let position = -1; |
michael@0 | 115 | // For the drag to item case, we drag to the last item, making the dragged item the |
michael@0 | 116 | // penultimate item. We can't well use the first item because the panel has complicated |
michael@0 | 117 | // rules about rearranging wide items (which, by default, the first two items are). |
michael@0 | 118 | if (method == "dragToItem") { |
michael@0 | 119 | newPlacements.pop(); |
michael@0 | 120 | newPlacements.splice(panelPlacements.length - 1, 0, id); |
michael@0 | 121 | position = -2; |
michael@0 | 122 | } |
michael@0 | 123 | assertAreaPlacements(kPanel, newPlacements); |
michael@0 | 124 | is(children[children.length + position].firstChild.id, id, |
michael@0 | 125 | "Widget " + id + " should be in " + kPanel + " in customizing window."); |
michael@0 | 126 | is(otherChildren[otherChildren.length + position].id, id, |
michael@0 | 127 | "Widget " + id + " should be in " + kPanel + " in other window."); |
michael@0 | 128 | checkWrapper(id); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | function checkPalette(id, method) { |
michael@0 | 132 | // Move back to palette: |
michael@0 | 133 | move[method](id, kVisiblePalette); |
michael@0 | 134 | ok(CustomizableUI.inDefaultState, "Should end in default state"); |
michael@0 | 135 | let visibleChildren = gCustomizeMode.visiblePalette.children; |
michael@0 | 136 | let expectedChild = method == "dragToItem" ? visibleChildren[0] : visibleChildren[visibleChildren.length - 1]; |
michael@0 | 137 | is(expectedChild.firstChild.id, id, "Widget " + id + " was moved using " + method + " and should now be wrapped in palette in customizing window."); |
michael@0 | 138 | if (id == kXULWidgetId) { |
michael@0 | 139 | ok(otherWin.gNavToolbox.palette.querySelector("#" + id), "Widget " + id + " should be in invisible palette in other window."); |
michael@0 | 140 | } |
michael@0 | 141 | checkWrapper(id); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | let otherWin; |
michael@0 | 145 | |
michael@0 | 146 | // Moving widgets in two windows, one with customize mode and one without, should work. |
michael@0 | 147 | add_task(function MoveWidgetsInTwoWindows() { |
michael@0 | 148 | yield startCustomizing(); |
michael@0 | 149 | otherWin = yield openAndLoadWindow(null, true); |
michael@0 | 150 | yield otherWin.PanelUI.ensureReady(); |
michael@0 | 151 | ok(CustomizableUI.inDefaultState, "Should start in default state"); |
michael@0 | 152 | |
michael@0 | 153 | for (let widgetId of [kXULWidgetId, kAPIWidgetId]) { |
michael@0 | 154 | for (let method of ["API", "drag", "dragToItem"]) { |
michael@0 | 155 | info("Moving widget " + widgetId + " using " + method); |
michael@0 | 156 | checkToolbar(widgetId, method); |
michael@0 | 157 | checkPanel(widgetId, method); |
michael@0 | 158 | checkPalette(widgetId, method); |
michael@0 | 159 | checkPanel(widgetId, method); |
michael@0 | 160 | checkToolbar(widgetId, method); |
michael@0 | 161 | checkPalette(widgetId, method); |
michael@0 | 162 | } |
michael@0 | 163 | } |
michael@0 | 164 | yield promiseWindowClosed(otherWin); |
michael@0 | 165 | otherWin = null; |
michael@0 | 166 | yield endCustomizing(); |
michael@0 | 167 | }); |
michael@0 | 168 | |
michael@0 | 169 | add_task(function asyncCleanup() { |
michael@0 | 170 | yield resetCustomization(); |
michael@0 | 171 | }); |