OLD | NEW |
1 (function() | 1 (function() |
2 { | 2 { |
3 let {application} = require("info"); | 3 let {application} = require("info"); |
4 if (application != "firefox") | 4 if (application != "firefox") |
5 return; | 5 return; |
6 | 6 |
| 7 let CustomizableUI = null; |
| 8 let usingShim = false; |
| 9 try |
| 10 { |
| 11 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", nul
l); |
| 12 } |
| 13 catch (e) |
| 14 { |
| 15 usingShim = true; |
| 16 // No built-in CustomizableUI API, use our own implementation. |
| 17 ({CustomizableUI}) = require("customizableUI"); |
| 18 } |
| 19 |
7 let wnd = Utils.getChromeWindow(window); | 20 let wnd = Utils.getChromeWindow(window); |
8 let toolbox = wnd.document.getElementById("navigator-toolbox"); | 21 let defaultParent = require("appSupport").defaultToolbarPosition.parent; |
9 if (!toolbox) | 22 |
10 return; | 23 let toolbox; |
| 24 if (usingShim) |
| 25 { |
| 26 let toolbar = wnd.document.getElementById(defaultParent); |
| 27 if (!toolbar) |
| 28 return; |
| 29 toolbox = toolbar.toolbox; |
| 30 } |
11 | 31 |
12 module("Icon position", { | 32 module("Icon position", { |
13 setup: function() | 33 setup: function() |
14 { | 34 { |
15 this.oldPosition = toolbox.getAttribute("abp-iconposition"); | 35 // Force default position |
| 36 if (usingShim) |
| 37 toolbox.removeAttribute("abp-iconposition"); |
| 38 |
16 if (UI.isToolbarIconVisible(wnd)) | 39 if (UI.isToolbarIconVisible(wnd)) |
17 UI.toggleToolbarIcon(); | 40 UI.toggleToolbarIcon(); |
18 }, | 41 }, |
19 teardown: function() | 42 teardown: function() |
20 { | 43 { |
21 toolbox.setAttribute("abp-iconposition", this.oldPosition); | |
22 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition"); | |
23 UI.toggleToolbarIcon(); | 44 UI.toggleToolbarIcon(); |
24 UI.toggleToolbarIcon(); | 45 UI.toggleToolbarIcon(); |
25 } | 46 } |
26 }); | 47 }); |
27 | 48 |
28 test("Put icon before add-on bar close button", function() | 49 test("Put icon at default position", function() |
29 { | 50 { |
30 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,addonbar-closebut
ton"); | 51 UI.toggleToolbarIcon(); |
| 52 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 53 ok(placement, "Button is visible"); |
| 54 if (placement) |
| 55 equal(placement.area, defaultParent, "Button is at the right position"); |
31 | 56 |
32 UI.toggleToolbarIcon(); | 57 UI.toggleToolbarIcon(); |
33 let button = wnd.document.getElementById("abp-toolbarbutton"); | 58 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
34 ok(button, "Button added"); | 59 ok(!placement, "Button is invisible"); |
35 if (button) | 60 |
36 { | 61 UI.toggleToolbarIcon(); |
37 ok(button.nextSibling, "Has next sibling"); | 62 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
38 if (button.nextSibling) | 63 ok(placement, "Button is visible"); |
39 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); | 64 if (placement) |
40 equal(button.parentNode.id, "addon-bar", "Parent ID"); | 65 equal(placement.area, defaultParent, "Button is at the right position agai
n"); |
| 66 }); |
| 67 |
| 68 test("Move icon into tabs bar and restore", function() |
| 69 { |
| 70 // The shim doesn't have proper support for addToWidgetArea |
| 71 if (usingShim) { |
| 72 ok(true, "Can't test"); |
| 73 return; |
41 } | 74 } |
42 | 75 |
43 UI.toggleToolbarIcon(); | 76 UI.toggleToolbarIcon(); |
44 let button = wnd.document.getElementById("abp-toolbarbutton"); | 77 |
45 ok(!button, "Button removed"); | 78 CustomizableUI.addWidgetToArea("abp-toolbarbutton", CustomizableUI.AREA_TABS
TRIP); |
| 79 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 80 ok(placement, "Button is visible"); |
| 81 if (placement) |
| 82 equal(placement.area, CustomizableUI.AREA_TABSTRIP, "Button is in tabstrip
"); |
46 | 83 |
47 UI.toggleToolbarIcon(); | 84 UI.toggleToolbarIcon(); |
48 let button = wnd.document.getElementById("abp-toolbarbutton"); | 85 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
49 ok(button, "Button added"); | 86 ok(!placement, "Button is invisible"); |
50 if (button) | 87 |
51 { | 88 UI.toggleToolbarIcon(); |
52 ok(button.nextSibling, "Has next sibling"); | 89 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
53 if (button.nextSibling) | 90 ok(placement, "Button is visible"); |
54 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); | 91 if (placement) |
55 equal(button.parentNode.id, "addon-bar", "Parent ID"); | 92 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at default po
sition"); |
56 } | |
57 }); | 93 }); |
58 | 94 |
59 test("Put icon at the end of the add-on bar", function() | |
60 { | |
61 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,"); | |
62 | |
63 UI.toggleToolbarIcon(); | |
64 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
65 ok(button, "Button added"); | |
66 if (button) | |
67 { | |
68 ok(!button.nextSibling, "No next sibling"); | |
69 equal(button.parentNode.id, "addon-bar", "Parent ID"); | |
70 } | |
71 | |
72 UI.toggleToolbarIcon(); | |
73 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
74 ok(!button, "Button removed"); | |
75 | |
76 UI.toggleToolbarIcon(); | |
77 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
78 ok(button, "Button added"); | |
79 if (button) | |
80 { | |
81 ok(!button.nextSibling, "No next sibling"); | |
82 equal(button.parentNode.id, "addon-bar", "Parent ID"); | |
83 } | |
84 }); | |
85 | |
86 test("Put icon into navigation toolbar", function() | |
87 { | |
88 toolbox.setAttribute("abp-iconposition", "hidden,nav-bar,home-button"); | |
89 | |
90 UI.toggleToolbarIcon(); | |
91 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
92 ok(button, "Button added"); | |
93 if (button) | |
94 { | |
95 ok(button.nextSibling, "Has next sibling"); | |
96 if (button.nextSibling) | |
97 equal(button.nextSibling.id, "home-button", "Next sibling ID"); | |
98 equal(button.parentNode.id, "nav-bar", "Parent ID"); | |
99 } | |
100 | |
101 UI.toggleToolbarIcon(); | |
102 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
103 ok(!button, "Button removed"); | |
104 | |
105 UI.toggleToolbarIcon(); | |
106 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
107 ok(button, "Button added"); | |
108 if (button) | |
109 { | |
110 ok(button.nextSibling, "Has next sibling"); | |
111 if (button.nextSibling) | |
112 equal(button.nextSibling.id, "home-button", "Next sibling ID"); | |
113 equal(button.parentNode.id, "nav-bar", "Parent ID"); | |
114 } | |
115 }); | |
116 | |
117 test("Put icon before an invalid element", function() | |
118 { | |
119 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,navigator-toolbox
"); | |
120 | |
121 UI.toggleToolbarIcon(); | |
122 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
123 ok(button, "Button added"); | |
124 if (button) | |
125 { | |
126 ok(!button.nextSibling, "No next sibling"); | |
127 equal(button.parentNode.id, "addon-bar", "Parent ID"); | |
128 } | |
129 equal(toolbox.getAttribute("abp-iconposition"), "visible,addon-bar,", "New s
aved position"); | |
130 }); | |
131 | |
132 test("Put icon before an unknown element", function() | |
133 { | |
134 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,foobarelement"); | |
135 | |
136 UI.toggleToolbarIcon(); | |
137 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
138 ok(button, "Button added"); | |
139 if (button) | |
140 { | |
141 ok(!button.nextSibling, "No next sibling"); | |
142 equal(button.parentNode.id, "addon-bar", "Parent ID"); | |
143 } | |
144 equal(toolbox.getAttribute("abp-iconposition"), "visible,addon-bar,", "New s
aved position"); | |
145 }); | |
146 | |
147 test("Default icon position", function() | |
148 { | |
149 toolbox.removeAttribute("abp-iconposition"); | |
150 | |
151 UI.toggleToolbarIcon(); | |
152 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
153 ok(button, "Button added"); | |
154 if (button) | |
155 { | |
156 ok(button.nextSibling, "Has next sibling"); | |
157 if (button.nextSibling) | |
158 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); | |
159 equal(button.parentNode.id, "addon-bar", "Parent ID"); | |
160 } | |
161 }); | |
162 | |
163 test("Recover legacy position", function() | |
164 { | |
165 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,"); | |
166 UI.toggleToolbarIcon(); | |
167 let icon = wnd.document.getElementById("abp-toolbarbutton"); | |
168 UI.toggleToolbarIcon(); | |
169 | |
170 toolbox.removeAttribute("abp-iconposition"); | |
171 let addonBar = wnd.document.getElementById("addon-bar"); | |
172 let currentset = addonBar.getAttribute("currentset"); | |
173 currentset = currentset.replace(/,abp-toolbarbutton/g, ""); | |
174 currentset = currentset.replace(/abp-toolbarbutton,/g, ""); | |
175 addonBar.setAttribute("currentset", currentset); | |
176 | |
177 let navBar = wnd.document.getElementById("nav-bar"); | |
178 currentset = navBar.getAttribute("currentset"); | |
179 currentset = currentset.replace(/,abp-toolbarbutton/g, ""); | |
180 currentset = currentset.replace(/abp-toolbarbutton,/g, ""); | |
181 currentset = currentset.replace(/,home-button/, ",abp-toolbarbutton,home-but
ton"); | |
182 navBar.setAttribute("currentset", currentset); | |
183 | |
184 UI.restoreToolbarIcon(toolbox, icon); | |
185 | |
186 let button = wnd.document.getElementById("abp-toolbarbutton"); | |
187 ok(button, "Button added"); | |
188 if (button) | |
189 { | |
190 ok(button.nextSibling, "Has next sibling"); | |
191 if (button.nextSibling) | |
192 equal(button.nextSibling.id, "home-button", "Next sibling ID"); | |
193 equal(button.parentNode.id, "nav-bar", "Parent ID"); | |
194 } | |
195 }); | |
196 })(); | 95 })(); |
OLD | NEW |