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 TOOLBARID = "test-toolbar-added-during-customize-mode"; |
michael@0 | 8 | |
michael@0 | 9 | add_task(function*() { |
michael@0 | 10 | yield startCustomizing(); |
michael@0 | 11 | let toolbar = createToolbarWithPlacements(TOOLBARID, []); |
michael@0 | 12 | CustomizableUI.addWidgetToArea("sync-button", TOOLBARID); |
michael@0 | 13 | let syncButton = document.getElementById("sync-button"); |
michael@0 | 14 | ok(syncButton, "Sync button should exist."); |
michael@0 | 15 | is(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should be a wrapper."); |
michael@0 | 16 | |
michael@0 | 17 | simulateItemDrag(syncButton, gNavToolbox.palette); |
michael@0 | 18 | ok(!CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved to the palette"); |
michael@0 | 19 | ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button really is in palette."); |
michael@0 | 20 | |
michael@0 | 21 | simulateItemDrag(syncButton, toolbar); |
michael@0 | 22 | ok(CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved out of palette"); |
michael@0 | 23 | is(CustomizableUI.getPlacementOfWidget("sync-button").area, TOOLBARID, "Button's back on toolbar"); |
michael@0 | 24 | ok(toolbar.querySelector("#sync-button"), "Sync button really is on toolbar."); |
michael@0 | 25 | |
michael@0 | 26 | yield endCustomizing(); |
michael@0 | 27 | isnot(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should not be a wrapper outside customize mode."); |
michael@0 | 28 | yield startCustomizing(); |
michael@0 | 29 | |
michael@0 | 30 | is(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should be a wrapper back in customize mode."); |
michael@0 | 31 | |
michael@0 | 32 | simulateItemDrag(syncButton, gNavToolbox.palette); |
michael@0 | 33 | ok(!CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved to the palette"); |
michael@0 | 34 | ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button really is in palette."); |
michael@0 | 35 | |
michael@0 | 36 | ok(!CustomizableUI.inDefaultState, "Not in default state while toolbar is not collapsed yet."); |
michael@0 | 37 | setToolbarVisibility(toolbar, false); |
michael@0 | 38 | ok(CustomizableUI.inDefaultState, "In default state while toolbar is collapsed."); |
michael@0 | 39 | |
michael@0 | 40 | setToolbarVisibility(toolbar, true); |
michael@0 | 41 | |
michael@0 | 42 | info("Check that removing the area registration from within customize mode works"); |
michael@0 | 43 | CustomizableUI.unregisterArea(TOOLBARID); |
michael@0 | 44 | ok(CustomizableUI.inDefaultState, "Now that the toolbar is no longer registered, should be in default state."); |
michael@0 | 45 | ok(!(new Set(gCustomizeMode.areas)).has(toolbar), "Toolbar shouldn't be known to customize mode."); |
michael@0 | 46 | |
michael@0 | 47 | CustomizableUI.registerArea(TOOLBARID, {legacy: true, defaultPlacements: []}); |
michael@0 | 48 | CustomizableUI.registerToolbarNode(toolbar, []); |
michael@0 | 49 | ok(!CustomizableUI.inDefaultState, "Now that the toolbar is registered again, should no longer be in default state."); |
michael@0 | 50 | ok((new Set(gCustomizeMode.areas)).has(toolbar), "Toolbar should be known to customize mode again."); |
michael@0 | 51 | |
michael@0 | 52 | simulateItemDrag(syncButton, toolbar); |
michael@0 | 53 | ok(CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved out of palette"); |
michael@0 | 54 | is(CustomizableUI.getPlacementOfWidget("sync-button").area, TOOLBARID, "Button's back on toolbar"); |
michael@0 | 55 | ok(toolbar.querySelector("#sync-button"), "Sync button really is on toolbar."); |
michael@0 | 56 | |
michael@0 | 57 | let otherWin = yield openAndLoadWindow({}, true); |
michael@0 | 58 | let otherTB = otherWin.document.createElementNS(kNSXUL, "toolbar"); |
michael@0 | 59 | otherTB.id = TOOLBARID; |
michael@0 | 60 | otherTB.setAttribute("customizable", "true"); |
michael@0 | 61 | let wasInformedCorrectlyOfAreaAppearing = false; |
michael@0 | 62 | let listener = { |
michael@0 | 63 | onAreaNodeRegistered: function(aArea, aNode) { |
michael@0 | 64 | if (aNode == otherTB) { |
michael@0 | 65 | wasInformedCorrectlyOfAreaAppearing = true; |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | }; |
michael@0 | 69 | CustomizableUI.addListener(listener); |
michael@0 | 70 | otherWin.gNavToolbox.appendChild(otherTB); |
michael@0 | 71 | ok(wasInformedCorrectlyOfAreaAppearing, "Should have been told area was registered."); |
michael@0 | 72 | CustomizableUI.removeListener(listener); |
michael@0 | 73 | |
michael@0 | 74 | ok(otherTB.querySelector("#sync-button"), "Sync button is on other toolbar, too."); |
michael@0 | 75 | |
michael@0 | 76 | simulateItemDrag(syncButton, gNavToolbox.palette); |
michael@0 | 77 | ok(!CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved to the palette"); |
michael@0 | 78 | ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button really is in palette."); |
michael@0 | 79 | ok(!otherTB.querySelector("#sync-button"), "Sync button is in palette in other window, too."); |
michael@0 | 80 | |
michael@0 | 81 | simulateItemDrag(syncButton, toolbar); |
michael@0 | 82 | ok(CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved out of palette"); |
michael@0 | 83 | is(CustomizableUI.getPlacementOfWidget("sync-button").area, TOOLBARID, "Button's back on toolbar"); |
michael@0 | 84 | ok(toolbar.querySelector("#sync-button"), "Sync button really is on toolbar."); |
michael@0 | 85 | ok(otherTB.querySelector("#sync-button"), "Sync button is on other toolbar, too."); |
michael@0 | 86 | |
michael@0 | 87 | let wasInformedCorrectlyOfAreaDisappearing = false; |
michael@0 | 88 | //XXXgijs So we could be using promiseWindowClosed here. However, after |
michael@0 | 89 | // repeated random oranges, I'm instead relying on onWindowClosed below to |
michael@0 | 90 | // fire appropriately - it is linked to an unload event as well, and so |
michael@0 | 91 | // reusing it prevents a potential race between unload handlers where the |
michael@0 | 92 | // one from promiseWindowClosed could fire before the onWindowClosed |
michael@0 | 93 | // (and therefore onAreaNodeRegistered) one, causing the test to fail. |
michael@0 | 94 | let windowCloseDeferred = Promise.defer(); |
michael@0 | 95 | listener = { |
michael@0 | 96 | onAreaNodeUnregistered: function(aArea, aNode, aReason) { |
michael@0 | 97 | if (aArea == TOOLBARID) { |
michael@0 | 98 | is(aNode, otherTB, "Should be informed about other toolbar"); |
michael@0 | 99 | is(aReason, CustomizableUI.REASON_WINDOW_CLOSED, "Reason should be correct."); |
michael@0 | 100 | wasInformedCorrectlyOfAreaDisappearing = (aReason === CustomizableUI.REASON_WINDOW_CLOSED); |
michael@0 | 101 | } |
michael@0 | 102 | }, |
michael@0 | 103 | onWindowClosed: function(aWindow) { |
michael@0 | 104 | if (aWindow == otherWin) { |
michael@0 | 105 | windowCloseDeferred.resolve(aWindow); |
michael@0 | 106 | } else { |
michael@0 | 107 | info("Other window was closed!"); |
michael@0 | 108 | info("Other window title: " + (aWindow.document && aWindow.document.title)); |
michael@0 | 109 | info("Our window title: " + (otherWin.document && otherWin.document.title)); |
michael@0 | 110 | } |
michael@0 | 111 | }, |
michael@0 | 112 | }; |
michael@0 | 113 | CustomizableUI.addListener(listener); |
michael@0 | 114 | otherWin.close(); |
michael@0 | 115 | let windowClosed = yield windowCloseDeferred.promise; |
michael@0 | 116 | |
michael@0 | 117 | is(windowClosed, otherWin, "Window should have sent onWindowClosed notification."); |
michael@0 | 118 | ok(wasInformedCorrectlyOfAreaDisappearing, "Should be told about window closing."); |
michael@0 | 119 | // Closing the other window should not be counted against this window's customize mode: |
michael@0 | 120 | is(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should still be a wrapper."); |
michael@0 | 121 | isnot(gCustomizeMode.areas.indexOf(toolbar), -1, "Toolbar should still be a customizable area for this customize mode instance."); |
michael@0 | 122 | |
michael@0 | 123 | yield gCustomizeMode.reset(); |
michael@0 | 124 | |
michael@0 | 125 | yield endCustomizing(); |
michael@0 | 126 | |
michael@0 | 127 | CustomizableUI.removeListener(listener); |
michael@0 | 128 | wasInformedCorrectlyOfAreaDisappearing = false; |
michael@0 | 129 | listener = { |
michael@0 | 130 | onAreaNodeUnregistered: function(aArea, aNode, aReason) { |
michael@0 | 131 | if (aArea == TOOLBARID) { |
michael@0 | 132 | is(aNode, toolbar, "Should be informed about this window's toolbar"); |
michael@0 | 133 | is(aReason, CustomizableUI.REASON_AREA_UNREGISTERED, "Reason for final removal should be correct."); |
michael@0 | 134 | wasInformedCorrectlyOfAreaDisappearing = (aReason === CustomizableUI.REASON_AREA_UNREGISTERED); |
michael@0 | 135 | } |
michael@0 | 136 | }, |
michael@0 | 137 | } |
michael@0 | 138 | CustomizableUI.addListener(listener); |
michael@0 | 139 | removeCustomToolbars(); |
michael@0 | 140 | ok(wasInformedCorrectlyOfAreaDisappearing, "Should be told about area being unregistered."); |
michael@0 | 141 | CustomizableUI.removeListener(listener); |
michael@0 | 142 | ok(CustomizableUI.inDefaultState, "Should be fine after exiting customize mode."); |
michael@0 | 143 | }); |