Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const kToolbarId = "test-registerToolbarNode-toolbar";
8 const kButtonId = "test-registerToolbarNode-button";
9 registerCleanupFunction(cleanup);
11 // Registering a toolbar with defaultset attribute should work
12 add_task(function() {
13 ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
14 let btn = createDummyXULButton(kButtonId);
15 let toolbar = document.createElement("toolbar");
16 toolbar.id = kToolbarId;
17 toolbar.setAttribute("customizable", true);
18 toolbar.setAttribute("defaultset", kButtonId);
19 gNavToolbox.appendChild(toolbar);
20 ok(CustomizableUI.areas.indexOf(kToolbarId) != -1,
21 "Toolbar should have been registered automatically.");
22 is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR,
23 "Area should be registered as toolbar");
24 assertAreaPlacements(kToolbarId, [kButtonId]);
25 ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible.");
26 CustomizableUI.unregisterArea(kToolbarId, true);
27 toolbar.remove();
28 ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
29 btn.remove();
30 });
32 // Registering a toolbar without a defaultset attribute should
33 // wait for the registerArea call
34 add_task(function() {
35 ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
36 let btn = createDummyXULButton(kButtonId);
37 let toolbar = document.createElement("toolbar");
38 toolbar.id = kToolbarId;
39 toolbar.setAttribute("customizable", true);
40 gNavToolbox.appendChild(toolbar);
41 ok(CustomizableUI.areas.indexOf(kToolbarId) == -1,
42 "Toolbar should not yet have been registered automatically.");
43 CustomizableUI.registerArea(kToolbarId, {defaultPlacements: [kButtonId]});
44 ok(CustomizableUI.areas.indexOf(kToolbarId) != -1,
45 "Toolbar should have been registered now.");
46 is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR,
47 "Area should be registered as toolbar");
48 assertAreaPlacements(kToolbarId, [kButtonId]);
49 ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible.");
50 CustomizableUI.unregisterArea(kToolbarId, true);
51 toolbar.remove();
52 ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
53 btn.remove();
54 });
56 add_task(function asyncCleanup() {
57 yield resetCustomization();
58 });
60 function cleanup() {
61 let toolbar = document.getElementById(kToolbarId);
62 if (toolbar) {
63 toolbar.remove();
64 }
65 let btn = document.getElementById(kButtonId) ||
66 gNavToolbox.querySelector("#" + kButtonId);
67 if (btn) {
68 btn.remove();
69 }
70 }