1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const kToolbarName = "test-insertNodeInWindow-placements-toolbar";
const kTestWidgetPrefix = "test-widget-for-insertNodeInWindow-placements-";
/*
Tries to replicate the situation of having a placement list like this:
exists-1,trying-to-insert-this,doesn't-exist,exists-2
*/
add_task(function*() {
let testWidgetExists = [true, false, false, true];
let widgetIds = [];
for (let i = 0; i < testWidgetExists.length; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
if (testWidgetExists[i]) {
let spec = {id: id, type: "button", removable: true, label: "test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
}
}
let toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds);
assertAreaPlacements(kToolbarName, widgetIds);
let btnId = kTestWidgetPrefix + 1;
let btn = createDummyXULButton(btnId, "test");
CustomizableUI.ensureWidgetPlacedInWindow(btnId, window);
is(btn.parentNode.id, kToolbarName, "New XUL widget should be placed inside new toolbar");
is(btn.previousSibling.id, toolbarNode.firstChild.id,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
btn.remove();
removeCustomToolbars();
yield resetCustomization();
});
/*
Tests nodes get placed inside the toolbar's overflow as expected. Replicates a
situation similar to:
exists-1,exists-2,overflow-1,trying-to-insert-this,overflow-2
*/
add_task(function*() {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
let widgetIds = [];
for (let i = 0; i < 5; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
let spec = {id: id, type: "button", removable: true, label: "insertNodeInWindow test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
CustomizableUI.addWidgetToArea(id, "nav-bar");
}
for (let id of widgetIds) {
document.getElementById(id).style.minWidth = "200px";
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
let testWidgetId = kTestWidgetPrefix + 3;
CustomizableUI.destroyWidget(testWidgetId);
let btn = createDummyXULButton(testWidgetId, "test");
CustomizableUI.ensureWidgetPlacedInWindow(testWidgetId, window);
is(btn.parentNode.id, navbar.overflowable._list.id, "New XUL widget should be placed inside overflow of toolbar");
is(btn.previousSibling.id, kTestWidgetPrefix + 2,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
is(btn.nextSibling.id, kTestWidgetPrefix + 4,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
window.resizeTo(originalWindowWidth, window.outerHeight);
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
CustomizableUI.removeWidgetFromArea(btn.id, kToolbarName);
btn.remove();
yield resetCustomization();
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
});
/*
Tests nodes get placed inside the toolbar's overflow as expected. Replicates a
placements situation similar to:
exists-1,exists-2,overflow-1,doesn't-exist,trying-to-insert-this,overflow-2
*/
add_task(function*() {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
let widgetIds = [];
for (let i = 0; i < 5; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
let spec = {id: id, type: "button", removable: true, label: "insertNodeInWindow test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
CustomizableUI.addWidgetToArea(id, "nav-bar");
}
for (let id of widgetIds) {
document.getElementById(id).style.minWidth = "200px";
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
let testWidgetId = kTestWidgetPrefix + 3;
CustomizableUI.destroyWidget(kTestWidgetPrefix + 2);
CustomizableUI.destroyWidget(testWidgetId);
let btn = createDummyXULButton(testWidgetId, "test");
CustomizableUI.ensureWidgetPlacedInWindow(testWidgetId, window);
is(btn.parentNode.id, navbar.overflowable._list.id, "New XUL widget should be placed inside overflow of toolbar");
is(btn.previousSibling.id, kTestWidgetPrefix + 1,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
is(btn.nextSibling.id, kTestWidgetPrefix + 4,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
window.resizeTo(originalWindowWidth, window.outerHeight);
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
CustomizableUI.removeWidgetFromArea(btn.id, kToolbarName);
btn.remove();
yield resetCustomization();
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
});
/*
Tests nodes get placed inside the toolbar's overflow as expected. Replicates a
placements situation similar to:
exists-1,exists-2,overflow-1,doesn't-exist,trying-to-insert-this,doesn't-exist
*/
add_task(function*() {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
let widgetIds = [];
for (let i = 0; i < 5; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
let spec = {id: id, type: "button", removable: true, label: "insertNodeInWindow test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
CustomizableUI.addWidgetToArea(id, "nav-bar");
}
for (let id of widgetIds) {
document.getElementById(id).style.minWidth = "200px";
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
let testWidgetId = kTestWidgetPrefix + 3;
CustomizableUI.destroyWidget(kTestWidgetPrefix + 2);
CustomizableUI.destroyWidget(testWidgetId);
CustomizableUI.destroyWidget(kTestWidgetPrefix + 4);
let btn = createDummyXULButton(testWidgetId, "test");
CustomizableUI.ensureWidgetPlacedInWindow(testWidgetId, window);
is(btn.parentNode.id, navbar.overflowable._list.id, "New XUL widget should be placed inside overflow of toolbar");
is(btn.previousSibling.id, kTestWidgetPrefix + 1,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
is(btn.nextSibling, null,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
window.resizeTo(originalWindowWidth, window.outerHeight);
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
CustomizableUI.removeWidgetFromArea(btn.id, kToolbarName);
btn.remove();
yield resetCustomization();
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
});
/*
Tests nodes get placed inside the toolbar's overflow as expected. Replicates a
placements situation similar to:
exists-1,exists-2,overflow-1,can't-overflow,trying-to-insert-this,overflow-2
*/
add_task(function*() {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
let widgetIds = [];
for (let i = 5; i >= 0; i--) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
let spec = {id: id, type: "button", removable: true, label: "insertNodeInWindow test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
CustomizableUI.addWidgetToArea(id, "nav-bar", 0);
}
for (let i = 10; i < 15; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
let spec = {id: id, type: "button", removable: true, label: "insertNodeInWindow test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
CustomizableUI.addWidgetToArea(id, "nav-bar");
}
for (let id of widgetIds) {
document.getElementById(id).style.minWidth = "200px";
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
// Find last widget that doesn't allow overflowing
let nonOverflowing = navbar.customizationTarget.lastChild;
is(nonOverflowing.getAttribute("overflows"), "false", "Last child is expected to not allow overflowing");
isnot(nonOverflowing.getAttribute("skipintoolbarset"), "true", "Last child is expected to not be skipintoolbarset");
let testWidgetId = kTestWidgetPrefix + 10;
CustomizableUI.destroyWidget(testWidgetId);
let btn = createDummyXULButton(testWidgetId, "test");
CustomizableUI.ensureWidgetPlacedInWindow(testWidgetId, window);
is(btn.parentNode.id, navbar.overflowable._list.id, "New XUL widget should be placed inside overflow of toolbar");
is(btn.nextSibling.id, kTestWidgetPrefix + 11,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
window.resizeTo(originalWindowWidth, window.outerHeight);
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
CustomizableUI.removeWidgetFromArea(btn.id, kToolbarName);
btn.remove();
yield resetCustomization();
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
});
/*
Tests nodes get placed inside the toolbar's overflow as expected. Replicates a
placements situation similar to:
exists-1,exists-2,overflow-1,trying-to-insert-this,can't-overflow,overflow-2
*/
add_task(function*() {
let widgetIds = [];
let missingId = 2;
let nonOverflowableId = 3;
for (let i = 0; i < 5; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
if (i != missingId) {
// Setting min-width to make the overflow state not depend on styling of the button and/or
// screen width
let spec = {id: id, type: "button", removable: true, label: "test", tooltiptext: "" + i,
onCreated: function(node) {
node.style.minWidth = "200px";
if (id == (kTestWidgetPrefix + nonOverflowableId)) {
node.setAttribute("overflows", false);
}
}};
info("Creating: " + id);
CustomizableUI.createWidget(spec);
}
}
let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds);
assertAreaPlacements(kToolbarName, widgetIds);
ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
let btnId = kTestWidgetPrefix + missingId;
let btn = createDummyXULButton(btnId, "test");
CustomizableUI.ensureWidgetPlacedInWindow(btnId, window);
is(btn.parentNode.id, kToolbarName + "-overflow-list", "New XUL widget should be placed inside new toolbar's overflow");
is(btn.previousSibling.id, kTestWidgetPrefix + 1,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
is(btn.nextSibling.id, kTestWidgetPrefix + 4,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
window.resizeTo(originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !toolbarNode.hasAttribute("overflowing"));
btn.remove();
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
removeCustomToolbars();
yield resetCustomization();
});
/*
Tests nodes do *not* get placed in the toolbar's overflow. Replicates a
plcements situation similar to:
exists-1,trying-to-insert-this,exists-2,overflowed-1
*/
add_task(function*() {
let widgetIds = [];
let missingId = 1;
for (let i = 0; i < 5; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
if (i != missingId) {
// Setting min-width to make the overflow state not depend on styling of the button and/or
// screen width
let spec = {id: id, type: "button", removable: true, label: "test", tooltiptext: "" + i,
onCreated: function(node) { node.style.minWidth = "100px"; }};
info("Creating: " + id);
CustomizableUI.createWidget(spec);
}
}
let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds);
assertAreaPlacements(kToolbarName, widgetIds);
ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
let btnId = kTestWidgetPrefix + missingId;
let btn = createDummyXULButton(btnId, "test");
CustomizableUI.ensureWidgetPlacedInWindow(btnId, window);
is(btn.parentNode.id, kToolbarName + "-target", "New XUL widget should be placed inside new toolbar");
window.resizeTo(originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !toolbarNode.hasAttribute("overflowing"));
btn.remove();
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
removeCustomToolbars();
yield resetCustomization();
});
/*
Tests inserting a node onto the end of an overflowing toolbar *doesn't* put it in
the overflow list when the widget disallows overflowing. ie:
exists-1,exists-2,overflows-1,trying-to-insert-this
Where trying-to-insert-this has overflows=false
*/
add_task(function*() {
let widgetIds = [];
let missingId = 3;
for (let i = 0; i < 5; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
if (i != missingId) {
// Setting min-width to make the overflow state not depend on styling of the button and/or
// screen width
let spec = {id: id, type: "button", removable: true, label: "test", tooltiptext: "" + i,
onCreated: function(node) { node.style.minWidth = "200px"; }};
info("Creating: " + id);
CustomizableUI.createWidget(spec);
}
}
let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds);
assertAreaPlacements(kToolbarName, widgetIds);
ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
let btnId = kTestWidgetPrefix + missingId;
let btn = createDummyXULButton(btnId, "test");
btn.setAttribute("overflows", false);
CustomizableUI.ensureWidgetPlacedInWindow(btnId, window);
is(btn.parentNode.id, kToolbarName + "-target", "New XUL widget should be placed inside new toolbar");
is(btn.nextSibling, null,
"insertNodeInWindow should have placed new XUL widget in correct place in DOM according to placements");
window.resizeTo(originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !toolbarNode.hasAttribute("overflowing"));
btn.remove();
widgetIds.forEach(id => CustomizableUI.destroyWidget(id));
removeCustomToolbars();
yield resetCustomization();
});
add_task(function* asyncCleanUp() {
yield resetCustomization();
});
|