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 kToolbarId = "test-registerToolbarNode-toolbar"; |
michael@0 | 8 | const kButtonId = "test-registerToolbarNode-button"; |
michael@0 | 9 | registerCleanupFunction(cleanup); |
michael@0 | 10 | |
michael@0 | 11 | // Registering a toolbar with defaultset attribute should work |
michael@0 | 12 | add_task(function() { |
michael@0 | 13 | ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); |
michael@0 | 14 | let btn = createDummyXULButton(kButtonId); |
michael@0 | 15 | let toolbar = document.createElement("toolbar"); |
michael@0 | 16 | toolbar.id = kToolbarId; |
michael@0 | 17 | toolbar.setAttribute("customizable", true); |
michael@0 | 18 | toolbar.setAttribute("defaultset", kButtonId); |
michael@0 | 19 | gNavToolbox.appendChild(toolbar); |
michael@0 | 20 | ok(CustomizableUI.areas.indexOf(kToolbarId) != -1, |
michael@0 | 21 | "Toolbar should have been registered automatically."); |
michael@0 | 22 | is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR, |
michael@0 | 23 | "Area should be registered as toolbar"); |
michael@0 | 24 | assertAreaPlacements(kToolbarId, [kButtonId]); |
michael@0 | 25 | ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible."); |
michael@0 | 26 | CustomizableUI.unregisterArea(kToolbarId, true); |
michael@0 | 27 | toolbar.remove(); |
michael@0 | 28 | ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); |
michael@0 | 29 | btn.remove(); |
michael@0 | 30 | }); |
michael@0 | 31 | |
michael@0 | 32 | // Registering a toolbar without a defaultset attribute should |
michael@0 | 33 | // wait for the registerArea call |
michael@0 | 34 | add_task(function() { |
michael@0 | 35 | ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); |
michael@0 | 36 | let btn = createDummyXULButton(kButtonId); |
michael@0 | 37 | let toolbar = document.createElement("toolbar"); |
michael@0 | 38 | toolbar.id = kToolbarId; |
michael@0 | 39 | toolbar.setAttribute("customizable", true); |
michael@0 | 40 | gNavToolbox.appendChild(toolbar); |
michael@0 | 41 | ok(CustomizableUI.areas.indexOf(kToolbarId) == -1, |
michael@0 | 42 | "Toolbar should not yet have been registered automatically."); |
michael@0 | 43 | CustomizableUI.registerArea(kToolbarId, {defaultPlacements: [kButtonId]}); |
michael@0 | 44 | ok(CustomizableUI.areas.indexOf(kToolbarId) != -1, |
michael@0 | 45 | "Toolbar should have been registered now."); |
michael@0 | 46 | is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR, |
michael@0 | 47 | "Area should be registered as toolbar"); |
michael@0 | 48 | assertAreaPlacements(kToolbarId, [kButtonId]); |
michael@0 | 49 | ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible."); |
michael@0 | 50 | CustomizableUI.unregisterArea(kToolbarId, true); |
michael@0 | 51 | toolbar.remove(); |
michael@0 | 52 | ok(CustomizableUI.inDefaultState, "Everything should be in its default state."); |
michael@0 | 53 | btn.remove(); |
michael@0 | 54 | }); |
michael@0 | 55 | |
michael@0 | 56 | add_task(function asyncCleanup() { |
michael@0 | 57 | yield resetCustomization(); |
michael@0 | 58 | }); |
michael@0 | 59 | |
michael@0 | 60 | function cleanup() { |
michael@0 | 61 | let toolbar = document.getElementById(kToolbarId); |
michael@0 | 62 | if (toolbar) { |
michael@0 | 63 | toolbar.remove(); |
michael@0 | 64 | } |
michael@0 | 65 | let btn = document.getElementById(kButtonId) || |
michael@0 | 66 | gNavToolbox.querySelector("#" + kButtonId); |
michael@0 | 67 | if (btn) { |
michael@0 | 68 | btn.remove(); |
michael@0 | 69 | } |
michael@0 | 70 | } |