browser/components/customizableui/test/browser_976792_insertNodeInWindow.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial