|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 let tempElements = []; |
|
8 |
|
9 function insertTempItemsIntoMenu(parentMenu) { |
|
10 // Last element is null to insert at the end: |
|
11 let beforeEls = [parentMenu.firstChild, parentMenu.lastChild, null]; |
|
12 for (let i = 0; i < beforeEls.length; i++) { |
|
13 let sep = document.createElement("menuseparator"); |
|
14 tempElements.push(sep); |
|
15 parentMenu.insertBefore(sep, beforeEls[i]); |
|
16 let menu = document.createElement("menu"); |
|
17 tempElements.push(menu); |
|
18 parentMenu.insertBefore(menu, beforeEls[i]); |
|
19 // And another separator for good measure: |
|
20 sep = document.createElement("menuseparator"); |
|
21 tempElements.push(sep); |
|
22 parentMenu.insertBefore(sep, beforeEls[i]); |
|
23 } |
|
24 } |
|
25 |
|
26 function checkSeparatorInsertion(menuId, buttonId, subviewId) { |
|
27 return function() { |
|
28 info("Checking for duplicate separators in " + buttonId + " widget"); |
|
29 let menu = document.getElementById(menuId); |
|
30 insertTempItemsIntoMenu(menu); |
|
31 |
|
32 let placement = CustomizableUI.getPlacementOfWidget(buttonId); |
|
33 let changedPlacement = false; |
|
34 if (!placement || placement.area != CustomizableUI.AREA_PANEL) { |
|
35 CustomizableUI.addWidgetToArea(buttonId, CustomizableUI.AREA_PANEL); |
|
36 changedPlacement = true; |
|
37 } |
|
38 yield PanelUI.show(); |
|
39 |
|
40 let button = document.getElementById(buttonId); |
|
41 button.click(); |
|
42 |
|
43 yield waitForCondition(() => !PanelUI.multiView.hasAttribute("transitioning")); |
|
44 let subview = document.getElementById(subviewId); |
|
45 ok(subview.firstChild, "Subview should have a kid"); |
|
46 is(subview.firstChild.localName, "toolbarbutton", "There should be no separators to start with"); |
|
47 |
|
48 for (let kid of subview.children) { |
|
49 if (kid.localName == "menuseparator") { |
|
50 ok(kid.previousSibling && kid.previousSibling.localName != "menuseparator", |
|
51 "Separators should never have another separator next to them, and should never be the first node."); |
|
52 } |
|
53 } |
|
54 |
|
55 let panelHiddenPromise = promisePanelHidden(window); |
|
56 PanelUI.hide(); |
|
57 yield panelHiddenPromise; |
|
58 |
|
59 if (changedPlacement) { |
|
60 CustomizableUI.reset(); |
|
61 } |
|
62 }; |
|
63 } |
|
64 |
|
65 add_task(checkSeparatorInsertion("menuWebDeveloperPopup", "developer-button", "PanelUI-developerItems")); |
|
66 add_task(checkSeparatorInsertion("viewSidebarMenu", "sidebar-button", "PanelUI-sidebarItems")); |
|
67 |
|
68 registerCleanupFunction(function() { |
|
69 for (let el of tempElements) { |
|
70 el.remove(); |
|
71 } |
|
72 tempElements = null; |
|
73 }); |