michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: add_task(function customizeToolbarAndKeepIt() { michael@0: ok(gNavToolbox.toolbarset, "There should be a toolbarset"); michael@0: let toolbarID = "testAustralisCustomToolbar"; michael@0: gNavToolbox.appendCustomToolbar(toolbarID, ""); michael@0: let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); michael@0: let toolbarElement = document.getElementById(toolbarDOMID); michael@0: ok(toolbarElement, "There should be a toolbar"); michael@0: if (!toolbarElement) { michael@0: ok(false, "No toolbar created, bailing out of the test."); michael@0: return; michael@0: } michael@0: is(toolbarElement.nextSibling, gNavToolbox.toolbarset, michael@0: "Toolbar should have been inserted in toolbox, before toolbarset element"); michael@0: let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); michael@0: is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, michael@0: "CustomizableUI should know the area and think it's a toolbar"); michael@0: if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { michael@0: ok(false, "Toolbar not registered successfully, bailing out of the test."); michael@0: toolbarElement.remove(); michael@0: return; michael@0: } michael@0: ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); michael@0: CustomizableUI.addWidgetToArea("open-file-button", toolbarDOMID, 0); michael@0: ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); michael@0: assertAreaPlacements(toolbarDOMID, ["open-file-button"]); michael@0: michael@0: gNavToolbox.toolbarset.setAttribute("toolbar1", toolbarID + ":open-file-button"); michael@0: document.persist(gNavToolbox.toolbarset.id, "toolbar1"); michael@0: michael@0: yield startCustomizing(); michael@0: // First, exit customize mode without doing anything, and verify the toolbar doesn't get removed. michael@0: yield endCustomizing(); michael@0: ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state, the toolbar should still be there."); michael@0: cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); michael@0: is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, michael@0: "CustomizableUI should still know the area and think it's a toolbar"); michael@0: ok(toolbarElement.parentNode, "Toolbar should still be in the DOM."); michael@0: ok(toolbarElement.hasChildNodes(), "Toolbar should still have items in it."); michael@0: assertAreaPlacements(toolbarDOMID, ["open-file-button"]); michael@0: michael@0: let newWindow = yield openAndLoadWindow({}, true); michael@0: is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar1"), michael@0: gNavToolbox.toolbarset.getAttribute("toolbar1"), michael@0: "Attribute should be the same in new window"); michael@0: yield promiseWindowClosed(newWindow); michael@0: michael@0: // Then customize again, and this time empty out the toolbar and verify it *does* get removed. michael@0: yield startCustomizing(); michael@0: let openFileButton = document.getElementById("open-file-button"); michael@0: let palette = document.getElementById("customization-palette"); michael@0: simulateItemDrag(openFileButton, palette); michael@0: ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's still a non-collapsed toolbar."); michael@0: ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); michael@0: michael@0: toolbarElement.collapsed = true; michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state because there's now just a collapsed toolbar."); michael@0: toolbarElement.collapsed = false; michael@0: ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's a non-collapsed toolbar again."); michael@0: yield endCustomizing(); michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state because the toolbar should have been removed."); michael@0: michael@0: newWindow = yield openAndLoadWindow({}, true); michael@0: ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar1"), michael@0: "Attribute should be gone in new window"); michael@0: yield promiseWindowClosed(newWindow); michael@0: michael@0: ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); michael@0: cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); michael@0: is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); michael@0: }); michael@0: michael@0: add_task(function resetShouldDealWithCustomToolbars() { michael@0: ok(gNavToolbox.toolbarset, "There should be a toolbarset"); michael@0: let toolbarID = "testAustralisCustomToolbar"; michael@0: gNavToolbox.appendCustomToolbar(toolbarID, ""); michael@0: let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); michael@0: let toolbarElement = document.getElementById(toolbarDOMID); michael@0: ok(toolbarElement, "There should be a toolbar"); michael@0: if (!toolbarElement) { michael@0: ok(false, "No toolbar created, bailing out of the test."); michael@0: return; michael@0: } michael@0: is(toolbarElement.nextSibling, gNavToolbox.toolbarset, michael@0: "Toolbar should have been inserted in toolbox, before toolbarset element"); michael@0: let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); michael@0: is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, michael@0: "CustomizableUI should know the area and think it's a toolbar"); michael@0: if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { michael@0: ok(false, "Toolbar not registered successfully, bailing out of the test."); michael@0: toolbarElement.remove(); michael@0: return; michael@0: } michael@0: ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); michael@0: CustomizableUI.addWidgetToArea("sync-button", toolbarDOMID, 0); michael@0: ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); michael@0: assertAreaPlacements(toolbarDOMID, ["sync-button"]); michael@0: michael@0: gNavToolbox.toolbarset.setAttribute("toolbar2", toolbarID + ":sync-button"); michael@0: document.persist(gNavToolbox.toolbarset.id, "toolbar2"); michael@0: michael@0: let newWindow = yield openAndLoadWindow({}, true); michael@0: is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar2"), michael@0: gNavToolbox.toolbarset.getAttribute("toolbar2"), michael@0: "Attribute should be the same in new window"); michael@0: yield promiseWindowClosed(newWindow); michael@0: michael@0: CustomizableUI.reset(); michael@0: michael@0: newWindow = yield openAndLoadWindow({}, true); michael@0: ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar2"), michael@0: "Attribute should be gone in new window"); michael@0: yield promiseWindowClosed(newWindow); michael@0: michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state after reset."); michael@0: let syncButton = document.getElementById("sync-button"); michael@0: ok(!syncButton, "Sync button shouldn't be in the document anymore."); michael@0: ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button should be in the palette"); michael@0: ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); michael@0: ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); michael@0: cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); michael@0: is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); michael@0: }); michael@0: michael@0: michael@0: add_task(function() { michael@0: let newWin = yield openAndLoadWindow({}, true); michael@0: ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar1"), "New window shouldn't have attribute toolbar1"); michael@0: ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar2"), "New window shouldn't have attribute toolbar2"); michael@0: yield promiseWindowClosed(newWin); michael@0: });