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 try |
| 9 { |
| 10 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", nul
l); |
| 11 } |
| 12 catch (e) |
| 13 { |
| 14 return; |
| 15 } |
| 16 |
7 let wnd = Utils.getChromeWindow(window); | 17 let wnd = Utils.getChromeWindow(window); |
8 let toolbox = wnd.document.getElementById("navigator-toolbox"); | |
9 if (!toolbox) | |
10 return; | |
11 | 18 |
12 module("Icon position", { | 19 module("Icon position", { |
13 setup: function() | 20 setup: function() |
14 { | 21 { |
15 this.oldPosition = toolbox.getAttribute("abp-iconposition"); | |
16 if (UI.isToolbarIconVisible(wnd)) | 22 if (UI.isToolbarIconVisible(wnd)) |
17 UI.toggleToolbarIcon(); | 23 UI.toggleToolbarIcon(); |
18 }, | 24 }, |
19 teardown: function() | 25 teardown: function() |
20 { | 26 { |
21 toolbox.setAttribute("abp-iconposition", this.oldPosition); | |
22 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition"); | |
23 UI.toggleToolbarIcon(); | 27 UI.toggleToolbarIcon(); |
24 UI.toggleToolbarIcon(); | 28 UI.toggleToolbarIcon(); |
25 } | 29 } |
26 }); | 30 }); |
27 | 31 |
28 test("Put icon before add-on bar close button", function() | 32 test("Put icon at default position", function() |
29 { | 33 { |
30 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,addonbar-closebut
ton"); | 34 UI.toggleToolbarIcon(); |
| 35 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 36 ok(placement, "Button is visible"); |
| 37 if (placement) |
| 38 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at the right
position"); |
31 | 39 |
32 UI.toggleToolbarIcon(); | 40 UI.toggleToolbarIcon(); |
33 let button = wnd.document.getElementById("abp-toolbarbutton"); | 41 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
34 ok(button, "Button added"); | 42 ok(!placement, "Button is invisible"); |
35 if (button) | |
36 { | |
37 ok(button.nextSibling, "Has next sibling"); | |
38 if (button.nextSibling) | |
39 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); | |
40 equal(button.parentNode.id, "addon-bar", "Parent ID"); | |
41 } | |
42 | 43 |
43 UI.toggleToolbarIcon(); | 44 UI.toggleToolbarIcon(); |
44 let button = wnd.document.getElementById("abp-toolbarbutton"); | 45 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
45 ok(!button, "Button removed"); | 46 ok(placement, "Button is visible"); |
| 47 if (placement) |
| 48 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at the right
position again"); |
| 49 }); |
| 50 |
| 51 test("Move icon into tabs bar and restore", function() |
| 52 { |
| 53 UI.toggleToolbarIcon(); |
| 54 |
| 55 CustomizableUI.addWidgetToArea("abp-toolbarbutton", CustomizableUI.AREA_TABS
TRIP); |
| 56 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 57 ok(placement, "Button is visible"); |
| 58 if (placement) |
| 59 equal(placement.area, CustomizableUI.AREA_TABSTRIP, "Button is in tabstrip
"); |
46 | 60 |
47 UI.toggleToolbarIcon(); | 61 UI.toggleToolbarIcon(); |
48 let button = wnd.document.getElementById("abp-toolbarbutton"); | 62 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
49 ok(button, "Button added"); | 63 ok(!placement, "Button is invisible"); |
50 if (button) | 64 |
51 { | 65 UI.toggleToolbarIcon(); |
52 ok(button.nextSibling, "Has next sibling"); | 66 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
53 if (button.nextSibling) | 67 ok(placement, "Button is visible"); |
54 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); | 68 if (placement) |
55 equal(button.parentNode.id, "addon-bar", "Parent ID"); | 69 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at default po
sition"); |
56 } | |
57 }); | 70 }); |
58 | 71 |
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 })(); | 72 })(); |
OLD | NEW |