1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/customizableui/test/browser_975719_customtoolbars_behaviour.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +add_task(function customizeToolbarAndKeepIt() { 1.11 + ok(gNavToolbox.toolbarset, "There should be a toolbarset"); 1.12 + let toolbarID = "testAustralisCustomToolbar"; 1.13 + gNavToolbox.appendCustomToolbar(toolbarID, ""); 1.14 + let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); 1.15 + let toolbarElement = document.getElementById(toolbarDOMID); 1.16 + ok(toolbarElement, "There should be a toolbar"); 1.17 + if (!toolbarElement) { 1.18 + ok(false, "No toolbar created, bailing out of the test."); 1.19 + return; 1.20 + } 1.21 + is(toolbarElement.nextSibling, gNavToolbox.toolbarset, 1.22 + "Toolbar should have been inserted in toolbox, before toolbarset element"); 1.23 + let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); 1.24 + is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, 1.25 + "CustomizableUI should know the area and think it's a toolbar"); 1.26 + if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { 1.27 + ok(false, "Toolbar not registered successfully, bailing out of the test."); 1.28 + toolbarElement.remove(); 1.29 + return; 1.30 + } 1.31 + ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); 1.32 + CustomizableUI.addWidgetToArea("open-file-button", toolbarDOMID, 0); 1.33 + ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); 1.34 + assertAreaPlacements(toolbarDOMID, ["open-file-button"]); 1.35 + 1.36 + gNavToolbox.toolbarset.setAttribute("toolbar1", toolbarID + ":open-file-button"); 1.37 + document.persist(gNavToolbox.toolbarset.id, "toolbar1"); 1.38 + 1.39 + yield startCustomizing(); 1.40 + // First, exit customize mode without doing anything, and verify the toolbar doesn't get removed. 1.41 + yield endCustomizing(); 1.42 + ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state, the toolbar should still be there."); 1.43 + cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); 1.44 + is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, 1.45 + "CustomizableUI should still know the area and think it's a toolbar"); 1.46 + ok(toolbarElement.parentNode, "Toolbar should still be in the DOM."); 1.47 + ok(toolbarElement.hasChildNodes(), "Toolbar should still have items in it."); 1.48 + assertAreaPlacements(toolbarDOMID, ["open-file-button"]); 1.49 + 1.50 + let newWindow = yield openAndLoadWindow({}, true); 1.51 + is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar1"), 1.52 + gNavToolbox.toolbarset.getAttribute("toolbar1"), 1.53 + "Attribute should be the same in new window"); 1.54 + yield promiseWindowClosed(newWindow); 1.55 + 1.56 + // Then customize again, and this time empty out the toolbar and verify it *does* get removed. 1.57 + yield startCustomizing(); 1.58 + let openFileButton = document.getElementById("open-file-button"); 1.59 + let palette = document.getElementById("customization-palette"); 1.60 + simulateItemDrag(openFileButton, palette); 1.61 + ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's still a non-collapsed toolbar."); 1.62 + ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); 1.63 + 1.64 + toolbarElement.collapsed = true; 1.65 + ok(CustomizableUI.inDefaultState, "Should be in default state because there's now just a collapsed toolbar."); 1.66 + toolbarElement.collapsed = false; 1.67 + ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's a non-collapsed toolbar again."); 1.68 + yield endCustomizing(); 1.69 + ok(CustomizableUI.inDefaultState, "Should be in default state because the toolbar should have been removed."); 1.70 + 1.71 + newWindow = yield openAndLoadWindow({}, true); 1.72 + ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar1"), 1.73 + "Attribute should be gone in new window"); 1.74 + yield promiseWindowClosed(newWindow); 1.75 + 1.76 + ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); 1.77 + cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); 1.78 + is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); 1.79 +}); 1.80 + 1.81 +add_task(function resetShouldDealWithCustomToolbars() { 1.82 + ok(gNavToolbox.toolbarset, "There should be a toolbarset"); 1.83 + let toolbarID = "testAustralisCustomToolbar"; 1.84 + gNavToolbox.appendCustomToolbar(toolbarID, ""); 1.85 + let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); 1.86 + let toolbarElement = document.getElementById(toolbarDOMID); 1.87 + ok(toolbarElement, "There should be a toolbar"); 1.88 + if (!toolbarElement) { 1.89 + ok(false, "No toolbar created, bailing out of the test."); 1.90 + return; 1.91 + } 1.92 + is(toolbarElement.nextSibling, gNavToolbox.toolbarset, 1.93 + "Toolbar should have been inserted in toolbox, before toolbarset element"); 1.94 + let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); 1.95 + is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, 1.96 + "CustomizableUI should know the area and think it's a toolbar"); 1.97 + if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { 1.98 + ok(false, "Toolbar not registered successfully, bailing out of the test."); 1.99 + toolbarElement.remove(); 1.100 + return; 1.101 + } 1.102 + ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); 1.103 + CustomizableUI.addWidgetToArea("sync-button", toolbarDOMID, 0); 1.104 + ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); 1.105 + assertAreaPlacements(toolbarDOMID, ["sync-button"]); 1.106 + 1.107 + gNavToolbox.toolbarset.setAttribute("toolbar2", toolbarID + ":sync-button"); 1.108 + document.persist(gNavToolbox.toolbarset.id, "toolbar2"); 1.109 + 1.110 + let newWindow = yield openAndLoadWindow({}, true); 1.111 + is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar2"), 1.112 + gNavToolbox.toolbarset.getAttribute("toolbar2"), 1.113 + "Attribute should be the same in new window"); 1.114 + yield promiseWindowClosed(newWindow); 1.115 + 1.116 + CustomizableUI.reset(); 1.117 + 1.118 + newWindow = yield openAndLoadWindow({}, true); 1.119 + ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar2"), 1.120 + "Attribute should be gone in new window"); 1.121 + yield promiseWindowClosed(newWindow); 1.122 + 1.123 + ok(CustomizableUI.inDefaultState, "Should be in default state after reset."); 1.124 + let syncButton = document.getElementById("sync-button"); 1.125 + ok(!syncButton, "Sync button shouldn't be in the document anymore."); 1.126 + ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button should be in the palette"); 1.127 + ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); 1.128 + ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); 1.129 + cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); 1.130 + is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); 1.131 +}); 1.132 + 1.133 + 1.134 +add_task(function() { 1.135 + let newWin = yield openAndLoadWindow({}, true); 1.136 + ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar1"), "New window shouldn't have attribute toolbar1"); 1.137 + ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar2"), "New window shouldn't have attribute toolbar2"); 1.138 + yield promiseWindowClosed(newWin); 1.139 +});