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 | add_task(function customizeToolbarAndKeepIt() { |
michael@0 | 8 | ok(gNavToolbox.toolbarset, "There should be a toolbarset"); |
michael@0 | 9 | let toolbarID = "testAustralisCustomToolbar"; |
michael@0 | 10 | gNavToolbox.appendCustomToolbar(toolbarID, ""); |
michael@0 | 11 | let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); |
michael@0 | 12 | let toolbarElement = document.getElementById(toolbarDOMID); |
michael@0 | 13 | ok(toolbarElement, "There should be a toolbar"); |
michael@0 | 14 | if (!toolbarElement) { |
michael@0 | 15 | ok(false, "No toolbar created, bailing out of the test."); |
michael@0 | 16 | return; |
michael@0 | 17 | } |
michael@0 | 18 | is(toolbarElement.nextSibling, gNavToolbox.toolbarset, |
michael@0 | 19 | "Toolbar should have been inserted in toolbox, before toolbarset element"); |
michael@0 | 20 | let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
michael@0 | 21 | is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, |
michael@0 | 22 | "CustomizableUI should know the area and think it's a toolbar"); |
michael@0 | 23 | if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { |
michael@0 | 24 | ok(false, "Toolbar not registered successfully, bailing out of the test."); |
michael@0 | 25 | toolbarElement.remove(); |
michael@0 | 26 | return; |
michael@0 | 27 | } |
michael@0 | 28 | ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); |
michael@0 | 29 | CustomizableUI.addWidgetToArea("open-file-button", toolbarDOMID, 0); |
michael@0 | 30 | ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); |
michael@0 | 31 | assertAreaPlacements(toolbarDOMID, ["open-file-button"]); |
michael@0 | 32 | |
michael@0 | 33 | gNavToolbox.toolbarset.setAttribute("toolbar1", toolbarID + ":open-file-button"); |
michael@0 | 34 | document.persist(gNavToolbox.toolbarset.id, "toolbar1"); |
michael@0 | 35 | |
michael@0 | 36 | yield startCustomizing(); |
michael@0 | 37 | // First, exit customize mode without doing anything, and verify the toolbar doesn't get removed. |
michael@0 | 38 | yield endCustomizing(); |
michael@0 | 39 | ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state, the toolbar should still be there."); |
michael@0 | 40 | cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
michael@0 | 41 | is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, |
michael@0 | 42 | "CustomizableUI should still know the area and think it's a toolbar"); |
michael@0 | 43 | ok(toolbarElement.parentNode, "Toolbar should still be in the DOM."); |
michael@0 | 44 | ok(toolbarElement.hasChildNodes(), "Toolbar should still have items in it."); |
michael@0 | 45 | assertAreaPlacements(toolbarDOMID, ["open-file-button"]); |
michael@0 | 46 | |
michael@0 | 47 | let newWindow = yield openAndLoadWindow({}, true); |
michael@0 | 48 | is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar1"), |
michael@0 | 49 | gNavToolbox.toolbarset.getAttribute("toolbar1"), |
michael@0 | 50 | "Attribute should be the same in new window"); |
michael@0 | 51 | yield promiseWindowClosed(newWindow); |
michael@0 | 52 | |
michael@0 | 53 | // Then customize again, and this time empty out the toolbar and verify it *does* get removed. |
michael@0 | 54 | yield startCustomizing(); |
michael@0 | 55 | let openFileButton = document.getElementById("open-file-button"); |
michael@0 | 56 | let palette = document.getElementById("customization-palette"); |
michael@0 | 57 | simulateItemDrag(openFileButton, palette); |
michael@0 | 58 | ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's still a non-collapsed toolbar."); |
michael@0 | 59 | ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); |
michael@0 | 60 | |
michael@0 | 61 | toolbarElement.collapsed = true; |
michael@0 | 62 | ok(CustomizableUI.inDefaultState, "Should be in default state because there's now just a collapsed toolbar."); |
michael@0 | 63 | toolbarElement.collapsed = false; |
michael@0 | 64 | ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's a non-collapsed toolbar again."); |
michael@0 | 65 | yield endCustomizing(); |
michael@0 | 66 | ok(CustomizableUI.inDefaultState, "Should be in default state because the toolbar should have been removed."); |
michael@0 | 67 | |
michael@0 | 68 | newWindow = yield openAndLoadWindow({}, true); |
michael@0 | 69 | ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar1"), |
michael@0 | 70 | "Attribute should be gone in new window"); |
michael@0 | 71 | yield promiseWindowClosed(newWindow); |
michael@0 | 72 | |
michael@0 | 73 | ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); |
michael@0 | 74 | cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
michael@0 | 75 | is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); |
michael@0 | 76 | }); |
michael@0 | 77 | |
michael@0 | 78 | add_task(function resetShouldDealWithCustomToolbars() { |
michael@0 | 79 | ok(gNavToolbox.toolbarset, "There should be a toolbarset"); |
michael@0 | 80 | let toolbarID = "testAustralisCustomToolbar"; |
michael@0 | 81 | gNavToolbox.appendCustomToolbar(toolbarID, ""); |
michael@0 | 82 | let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); |
michael@0 | 83 | let toolbarElement = document.getElementById(toolbarDOMID); |
michael@0 | 84 | ok(toolbarElement, "There should be a toolbar"); |
michael@0 | 85 | if (!toolbarElement) { |
michael@0 | 86 | ok(false, "No toolbar created, bailing out of the test."); |
michael@0 | 87 | return; |
michael@0 | 88 | } |
michael@0 | 89 | is(toolbarElement.nextSibling, gNavToolbox.toolbarset, |
michael@0 | 90 | "Toolbar should have been inserted in toolbox, before toolbarset element"); |
michael@0 | 91 | let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
michael@0 | 92 | is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, |
michael@0 | 93 | "CustomizableUI should know the area and think it's a toolbar"); |
michael@0 | 94 | if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { |
michael@0 | 95 | ok(false, "Toolbar not registered successfully, bailing out of the test."); |
michael@0 | 96 | toolbarElement.remove(); |
michael@0 | 97 | return; |
michael@0 | 98 | } |
michael@0 | 99 | ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); |
michael@0 | 100 | CustomizableUI.addWidgetToArea("sync-button", toolbarDOMID, 0); |
michael@0 | 101 | ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); |
michael@0 | 102 | assertAreaPlacements(toolbarDOMID, ["sync-button"]); |
michael@0 | 103 | |
michael@0 | 104 | gNavToolbox.toolbarset.setAttribute("toolbar2", toolbarID + ":sync-button"); |
michael@0 | 105 | document.persist(gNavToolbox.toolbarset.id, "toolbar2"); |
michael@0 | 106 | |
michael@0 | 107 | let newWindow = yield openAndLoadWindow({}, true); |
michael@0 | 108 | is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar2"), |
michael@0 | 109 | gNavToolbox.toolbarset.getAttribute("toolbar2"), |
michael@0 | 110 | "Attribute should be the same in new window"); |
michael@0 | 111 | yield promiseWindowClosed(newWindow); |
michael@0 | 112 | |
michael@0 | 113 | CustomizableUI.reset(); |
michael@0 | 114 | |
michael@0 | 115 | newWindow = yield openAndLoadWindow({}, true); |
michael@0 | 116 | ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar2"), |
michael@0 | 117 | "Attribute should be gone in new window"); |
michael@0 | 118 | yield promiseWindowClosed(newWindow); |
michael@0 | 119 | |
michael@0 | 120 | ok(CustomizableUI.inDefaultState, "Should be in default state after reset."); |
michael@0 | 121 | let syncButton = document.getElementById("sync-button"); |
michael@0 | 122 | ok(!syncButton, "Sync button shouldn't be in the document anymore."); |
michael@0 | 123 | ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button should be in the palette"); |
michael@0 | 124 | ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); |
michael@0 | 125 | ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); |
michael@0 | 126 | cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
michael@0 | 127 | is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); |
michael@0 | 128 | }); |
michael@0 | 129 | |
michael@0 | 130 | |
michael@0 | 131 | add_task(function() { |
michael@0 | 132 | let newWin = yield openAndLoadWindow({}, true); |
michael@0 | 133 | ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar1"), "New window shouldn't have attribute toolbar1"); |
michael@0 | 134 | ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar2"), "New window shouldn't have attribute toolbar2"); |
michael@0 | 135 | yield promiseWindowClosed(newWin); |
michael@0 | 136 | }); |