michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR); michael@0: let overflowList = document.getElementById(navbar.getAttribute("overflowtarget")); michael@0: michael@0: const kTestBtn1 = "test-addWidgetToArea-overflow"; michael@0: const kTestBtn2 = "test-removeWidgetFromArea-overflow"; michael@0: const kTestBtn3 = "test-createWidget-overflow"; michael@0: const kHomeBtn = "home-button"; michael@0: const kDownloadsBtn = "downloads-button"; michael@0: const kSearchBox = "search-container"; michael@0: const kStarBtn = "bookmarks-menu-button"; michael@0: michael@0: let originalWindowWidth; michael@0: michael@0: // Adding a widget should add it next to the widget it's being inserted next to. michael@0: add_task(function() { michael@0: originalWindowWidth = window.outerWidth; michael@0: createDummyXULButton(kTestBtn1, "Test"); michael@0: ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar."); michael@0: ok(CustomizableUI.inDefaultState, "Should start in default state."); michael@0: michael@0: window.resizeTo(400, window.outerHeight); michael@0: yield waitForCondition(() => navbar.hasAttribute("overflowing")); michael@0: ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar."); michael@0: ok(!navbar.querySelector("#" + kHomeBtn), "Home button should no longer be in the navbar"); michael@0: let homeBtnNode = overflowList.querySelector("#" + kHomeBtn); michael@0: ok(homeBtnNode, "Home button should be overflowing"); michael@0: ok(homeBtnNode && homeBtnNode.getAttribute("overflowedItem") == "true", "Home button should have overflowedItem attribute"); michael@0: michael@0: let placementOfHomeButton = CustomizableUI.getWidgetIdsInArea(navbar.id).indexOf(kHomeBtn); michael@0: CustomizableUI.addWidgetToArea(kTestBtn1, navbar.id, placementOfHomeButton); michael@0: ok(!navbar.querySelector("#" + kTestBtn1), "New button should not be in the navbar"); michael@0: let newButtonNode = overflowList.querySelector("#" + kTestBtn1); michael@0: ok(newButtonNode, "New button should be overflowing"); michael@0: ok(newButtonNode && newButtonNode.getAttribute("overflowedItem") == "true", "New button should have overflowedItem attribute"); michael@0: let nextEl = newButtonNode && newButtonNode.nextSibling; michael@0: is(nextEl && nextEl.id, kHomeBtn, "Test button should be next to home button."); michael@0: michael@0: window.resizeTo(originalWindowWidth, window.outerHeight); michael@0: yield waitForCondition(() => !navbar.hasAttribute("overflowing")); michael@0: ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar."); michael@0: ok(navbar.querySelector("#" + kHomeBtn), "Home button should be in the navbar"); michael@0: ok(homeBtnNode && (homeBtnNode.getAttribute("overflowedItem") != "true"), "Home button should no longer have overflowedItem attribute"); michael@0: ok(!overflowList.querySelector("#" + kHomeBtn), "Home button should no longer be overflowing"); michael@0: ok(navbar.querySelector("#" + kTestBtn1), "Test button should be in the navbar"); michael@0: ok(!overflowList.querySelector("#" + kTestBtn1), "Test button should no longer be overflowing"); michael@0: ok(newButtonNode && (newButtonNode.getAttribute("overflowedItem") != "true"), "New button should no longer have overflowedItem attribute"); michael@0: let el = document.getElementById(kTestBtn1); michael@0: if (el) { michael@0: CustomizableUI.removeWidgetFromArea(kTestBtn1); michael@0: el.remove(); michael@0: } michael@0: window.resizeTo(originalWindowWidth, window.outerHeight); michael@0: }); michael@0: michael@0: // Removing a widget should remove it from the overflow list if that is where it is, and update it accordingly. michael@0: add_task(function() { michael@0: createDummyXULButton(kTestBtn2, "Test"); michael@0: ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar."); michael@0: ok(CustomizableUI.inDefaultState, "Should start in default state."); michael@0: CustomizableUI.addWidgetToArea(kTestBtn2, navbar.id); michael@0: ok(!navbar.hasAttribute("overflowing"), "Should still have a non-overflowing toolbar."); michael@0: michael@0: window.resizeTo(400, window.outerHeight); michael@0: yield waitForCondition(() => navbar.hasAttribute("overflowing")); michael@0: ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar."); michael@0: ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar"); michael@0: ok(overflowList.querySelector("#" + kTestBtn2), "Test button should be overflowing"); michael@0: michael@0: CustomizableUI.removeWidgetFromArea(kTestBtn2); michael@0: michael@0: ok(!overflowList.querySelector("#" + kTestBtn2), "Test button should not be overflowing."); michael@0: ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar"); michael@0: ok(gNavToolbox.palette.querySelector("#" + kTestBtn2), "Test button should be in the palette"); michael@0: michael@0: window.resizeTo(originalWindowWidth, window.outerHeight); michael@0: yield waitForCondition(() => !navbar.hasAttribute("overflowing")); michael@0: ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar."); michael@0: let el = document.getElementById(kTestBtn2); michael@0: if (el) { michael@0: CustomizableUI.removeWidgetFromArea(kTestBtn2); michael@0: el.remove(); michael@0: } michael@0: window.resizeTo(originalWindowWidth, window.outerHeight); michael@0: }); michael@0: michael@0: // Constructing a widget while overflown should set the right class on it. michael@0: add_task(function() { michael@0: originalWindowWidth = window.outerWidth; michael@0: ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar."); michael@0: ok(CustomizableUI.inDefaultState, "Should start in default state."); michael@0: michael@0: window.resizeTo(400, window.outerHeight); michael@0: yield waitForCondition(() => navbar.hasAttribute("overflowing")); michael@0: ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar."); michael@0: ok(!navbar.querySelector("#" + kHomeBtn), "Home button should no longer be in the navbar"); michael@0: let homeBtnNode = overflowList.querySelector("#" + kHomeBtn); michael@0: ok(homeBtnNode, "Home button should be overflowing"); michael@0: ok(homeBtnNode && homeBtnNode.getAttribute("overflowedItem") == "true", "Home button should have overflowedItem class"); michael@0: michael@0: let testBtnSpec = {id: kTestBtn3, label: "Overflowable widget test", defaultArea: "nav-bar"}; michael@0: CustomizableUI.createWidget(testBtnSpec); michael@0: let testNode = overflowList.querySelector("#" + kTestBtn3); michael@0: ok(testNode, "Test button should be overflowing"); michael@0: ok(testNode && testNode.getAttribute("overflowedItem") == "true", "Test button should have overflowedItem class"); michael@0: michael@0: CustomizableUI.destroyWidget(kTestBtn3); michael@0: testNode = document.getElementById(kTestBtn3); michael@0: ok(!testNode, "Test button should be gone"); michael@0: michael@0: CustomizableUI.createWidget(testBtnSpec); michael@0: testNode = overflowList.querySelector("#" + kTestBtn3); michael@0: ok(testNode, "Test button should be overflowing"); michael@0: ok(testNode && testNode.getAttribute("overflowedItem") == "true", "Test button should have overflowedItem class"); michael@0: michael@0: CustomizableUI.removeWidgetFromArea(kTestBtn3); michael@0: testNode = document.getElementById(kTestBtn3); michael@0: ok(!testNode, "Test button should be gone"); michael@0: CustomizableUI.destroyWidget(kTestBtn3); michael@0: window.resizeTo(originalWindowWidth, window.outerHeight); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: window.resizeTo(originalWindowWidth, window.outerHeight); michael@0: yield resetCustomization(); michael@0: });