browser/components/customizableui/test/browser_914138_widget_API_overflowable_toolbar.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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 let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
michael@0 8 let overflowList = document.getElementById(navbar.getAttribute("overflowtarget"));
michael@0 9
michael@0 10 const kTestBtn1 = "test-addWidgetToArea-overflow";
michael@0 11 const kTestBtn2 = "test-removeWidgetFromArea-overflow";
michael@0 12 const kTestBtn3 = "test-createWidget-overflow";
michael@0 13 const kHomeBtn = "home-button";
michael@0 14 const kDownloadsBtn = "downloads-button";
michael@0 15 const kSearchBox = "search-container";
michael@0 16 const kStarBtn = "bookmarks-menu-button";
michael@0 17
michael@0 18 let originalWindowWidth;
michael@0 19
michael@0 20 // Adding a widget should add it next to the widget it's being inserted next to.
michael@0 21 add_task(function() {
michael@0 22 originalWindowWidth = window.outerWidth;
michael@0 23 createDummyXULButton(kTestBtn1, "Test");
michael@0 24 ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
michael@0 25 ok(CustomizableUI.inDefaultState, "Should start in default state.");
michael@0 26
michael@0 27 window.resizeTo(400, window.outerHeight);
michael@0 28 yield waitForCondition(() => navbar.hasAttribute("overflowing"));
michael@0 29 ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
michael@0 30 ok(!navbar.querySelector("#" + kHomeBtn), "Home button should no longer be in the navbar");
michael@0 31 let homeBtnNode = overflowList.querySelector("#" + kHomeBtn);
michael@0 32 ok(homeBtnNode, "Home button should be overflowing");
michael@0 33 ok(homeBtnNode && homeBtnNode.getAttribute("overflowedItem") == "true", "Home button should have overflowedItem attribute");
michael@0 34
michael@0 35 let placementOfHomeButton = CustomizableUI.getWidgetIdsInArea(navbar.id).indexOf(kHomeBtn);
michael@0 36 CustomizableUI.addWidgetToArea(kTestBtn1, navbar.id, placementOfHomeButton);
michael@0 37 ok(!navbar.querySelector("#" + kTestBtn1), "New button should not be in the navbar");
michael@0 38 let newButtonNode = overflowList.querySelector("#" + kTestBtn1);
michael@0 39 ok(newButtonNode, "New button should be overflowing");
michael@0 40 ok(newButtonNode && newButtonNode.getAttribute("overflowedItem") == "true", "New button should have overflowedItem attribute");
michael@0 41 let nextEl = newButtonNode && newButtonNode.nextSibling;
michael@0 42 is(nextEl && nextEl.id, kHomeBtn, "Test button should be next to home button.");
michael@0 43
michael@0 44 window.resizeTo(originalWindowWidth, window.outerHeight);
michael@0 45 yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
michael@0 46 ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
michael@0 47 ok(navbar.querySelector("#" + kHomeBtn), "Home button should be in the navbar");
michael@0 48 ok(homeBtnNode && (homeBtnNode.getAttribute("overflowedItem") != "true"), "Home button should no longer have overflowedItem attribute");
michael@0 49 ok(!overflowList.querySelector("#" + kHomeBtn), "Home button should no longer be overflowing");
michael@0 50 ok(navbar.querySelector("#" + kTestBtn1), "Test button should be in the navbar");
michael@0 51 ok(!overflowList.querySelector("#" + kTestBtn1), "Test button should no longer be overflowing");
michael@0 52 ok(newButtonNode && (newButtonNode.getAttribute("overflowedItem") != "true"), "New button should no longer have overflowedItem attribute");
michael@0 53 let el = document.getElementById(kTestBtn1);
michael@0 54 if (el) {
michael@0 55 CustomizableUI.removeWidgetFromArea(kTestBtn1);
michael@0 56 el.remove();
michael@0 57 }
michael@0 58 window.resizeTo(originalWindowWidth, window.outerHeight);
michael@0 59 });
michael@0 60
michael@0 61 // Removing a widget should remove it from the overflow list if that is where it is, and update it accordingly.
michael@0 62 add_task(function() {
michael@0 63 createDummyXULButton(kTestBtn2, "Test");
michael@0 64 ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
michael@0 65 ok(CustomizableUI.inDefaultState, "Should start in default state.");
michael@0 66 CustomizableUI.addWidgetToArea(kTestBtn2, navbar.id);
michael@0 67 ok(!navbar.hasAttribute("overflowing"), "Should still have a non-overflowing toolbar.");
michael@0 68
michael@0 69 window.resizeTo(400, window.outerHeight);
michael@0 70 yield waitForCondition(() => navbar.hasAttribute("overflowing"));
michael@0 71 ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
michael@0 72 ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar");
michael@0 73 ok(overflowList.querySelector("#" + kTestBtn2), "Test button should be overflowing");
michael@0 74
michael@0 75 CustomizableUI.removeWidgetFromArea(kTestBtn2);
michael@0 76
michael@0 77 ok(!overflowList.querySelector("#" + kTestBtn2), "Test button should not be overflowing.");
michael@0 78 ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar");
michael@0 79 ok(gNavToolbox.palette.querySelector("#" + kTestBtn2), "Test button should be in the palette");
michael@0 80
michael@0 81 window.resizeTo(originalWindowWidth, window.outerHeight);
michael@0 82 yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
michael@0 83 ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
michael@0 84 let el = document.getElementById(kTestBtn2);
michael@0 85 if (el) {
michael@0 86 CustomizableUI.removeWidgetFromArea(kTestBtn2);
michael@0 87 el.remove();
michael@0 88 }
michael@0 89 window.resizeTo(originalWindowWidth, window.outerHeight);
michael@0 90 });
michael@0 91
michael@0 92 // Constructing a widget while overflown should set the right class on it.
michael@0 93 add_task(function() {
michael@0 94 originalWindowWidth = window.outerWidth;
michael@0 95 ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
michael@0 96 ok(CustomizableUI.inDefaultState, "Should start in default state.");
michael@0 97
michael@0 98 window.resizeTo(400, window.outerHeight);
michael@0 99 yield waitForCondition(() => navbar.hasAttribute("overflowing"));
michael@0 100 ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
michael@0 101 ok(!navbar.querySelector("#" + kHomeBtn), "Home button should no longer be in the navbar");
michael@0 102 let homeBtnNode = overflowList.querySelector("#" + kHomeBtn);
michael@0 103 ok(homeBtnNode, "Home button should be overflowing");
michael@0 104 ok(homeBtnNode && homeBtnNode.getAttribute("overflowedItem") == "true", "Home button should have overflowedItem class");
michael@0 105
michael@0 106 let testBtnSpec = {id: kTestBtn3, label: "Overflowable widget test", defaultArea: "nav-bar"};
michael@0 107 CustomizableUI.createWidget(testBtnSpec);
michael@0 108 let testNode = overflowList.querySelector("#" + kTestBtn3);
michael@0 109 ok(testNode, "Test button should be overflowing");
michael@0 110 ok(testNode && testNode.getAttribute("overflowedItem") == "true", "Test button should have overflowedItem class");
michael@0 111
michael@0 112 CustomizableUI.destroyWidget(kTestBtn3);
michael@0 113 testNode = document.getElementById(kTestBtn3);
michael@0 114 ok(!testNode, "Test button should be gone");
michael@0 115
michael@0 116 CustomizableUI.createWidget(testBtnSpec);
michael@0 117 testNode = overflowList.querySelector("#" + kTestBtn3);
michael@0 118 ok(testNode, "Test button should be overflowing");
michael@0 119 ok(testNode && testNode.getAttribute("overflowedItem") == "true", "Test button should have overflowedItem class");
michael@0 120
michael@0 121 CustomizableUI.removeWidgetFromArea(kTestBtn3);
michael@0 122 testNode = document.getElementById(kTestBtn3);
michael@0 123 ok(!testNode, "Test button should be gone");
michael@0 124 CustomizableUI.destroyWidget(kTestBtn3);
michael@0 125 window.resizeTo(originalWindowWidth, window.outerHeight);
michael@0 126 });
michael@0 127
michael@0 128 add_task(function asyncCleanup() {
michael@0 129 window.resizeTo(originalWindowWidth, window.outerHeight);
michael@0 130 yield resetCustomization();
michael@0 131 });

mercurial