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: requestLongerTimeout(2); michael@0: michael@0: // One orphaned item should have two placeholders next to it. michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: let btn = document.getElementById("open-file-button"); michael@0: let panel = document.getElementById(CustomizableUI.AREA_PANEL); michael@0: let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); michael@0: michael@0: if (isInWin8()) { michael@0: CustomizableUI.removeWidgetFromArea("switch-to-metro-button"); michael@0: placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); michael@0: ok(!CustomizableUI.inDefaultState, "Should no longer be in default state."); michael@0: } else { michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state."); michael@0: } michael@0: michael@0: assertAreaPlacements(CustomizableUI.AREA_PANEL, placements); michael@0: is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders before exiting"); michael@0: michael@0: yield endCustomizing(); michael@0: yield startCustomizing(); michael@0: is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders after re-entering"); michael@0: michael@0: if (isInWin8()) { michael@0: CustomizableUI.addWidgetToArea("switch-to-metro-button", CustomizableUI.AREA_PANEL); michael@0: } michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state again."); michael@0: }); michael@0: michael@0: // Two orphaned items should have one placeholder next to them (case 1). michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: let btn = document.getElementById("open-file-button"); michael@0: let panel = document.getElementById(CustomizableUI.AREA_PANEL); michael@0: let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); michael@0: michael@0: let placementsAfterAppend = placements; michael@0: michael@0: if (!isInWin8()) { michael@0: placementsAfterAppend = placements.concat(["open-file-button"]); michael@0: simulateItemDrag(btn, panel); michael@0: } michael@0: michael@0: assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend); michael@0: is(CustomizableUI.inDefaultState, isInWin8(), "Should only be in default state if on Win8"); michael@0: is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting"); michael@0: michael@0: yield endCustomizing(); michael@0: yield startCustomizing(); michael@0: is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering"); michael@0: michael@0: let palette = document.getElementById("customization-palette"); michael@0: simulateItemDrag(btn, palette); michael@0: michael@0: if (!isInWin8()) { michael@0: btn = document.getElementById("open-file-button"); michael@0: simulateItemDrag(btn, palette); michael@0: } michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state again."); michael@0: }); michael@0: michael@0: // Two orphaned items should have one placeholder next to them (case 2). michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: let btn = document.getElementById("add-ons-button"); michael@0: let btn2 = document.getElementById("developer-button"); michael@0: let btn3 = document.getElementById("switch-to-metro-button"); michael@0: let panel = document.getElementById(CustomizableUI.AREA_PANEL); michael@0: let palette = document.getElementById("customization-palette"); michael@0: let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); michael@0: michael@0: let placementsAfterAppend = placements.filter(p => p != btn.id && p != btn2.id); michael@0: simulateItemDrag(btn, palette); michael@0: simulateItemDrag(btn2, palette); michael@0: michael@0: if (isInWin8()) { michael@0: placementsAfterAppend = placementsAfterAppend.filter(p => p != btn3.id); michael@0: simulateItemDrag(btn3, palette); michael@0: } michael@0: michael@0: assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend); michael@0: ok(!CustomizableUI.inDefaultState, "Should no longer be in default state."); michael@0: is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting"); michael@0: michael@0: yield endCustomizing(); michael@0: yield startCustomizing(); michael@0: is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering"); michael@0: michael@0: simulateItemDrag(btn, panel); michael@0: simulateItemDrag(btn2, panel); michael@0: michael@0: if (isInWin8()) { michael@0: simulateItemDrag(btn3, panel); michael@0: } michael@0: michael@0: assertAreaPlacements(CustomizableUI.AREA_PANEL, placements); michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state again."); michael@0: }); michael@0: michael@0: // A wide widget at the bottom of the panel should have three placeholders after it. michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: let btn = document.getElementById("edit-controls"); michael@0: let developerButton = document.getElementById("developer-button"); michael@0: let metroBtn = document.getElementById("switch-to-metro-button"); michael@0: let panel = document.getElementById(CustomizableUI.AREA_PANEL); michael@0: let palette = document.getElementById("customization-palette"); michael@0: let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); michael@0: michael@0: placements.pop(); michael@0: simulateItemDrag(developerButton, palette); michael@0: if (isInWin8()) { michael@0: // Remove switch-to-metro-button michael@0: placements.pop(); michael@0: simulateItemDrag(metroBtn, palette); michael@0: } michael@0: michael@0: let placementsAfterAppend = placements.concat([placements.shift()]); michael@0: simulateItemDrag(btn, panel); michael@0: assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend); michael@0: ok(!CustomizableUI.inDefaultState, "Should no longer be in default state."); michael@0: is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders before exiting"); michael@0: michael@0: yield endCustomizing(); michael@0: yield startCustomizing(); michael@0: is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders after re-entering"); michael@0: michael@0: simulateItemDrag(developerButton, panel); michael@0: if (isInWin8()) { michael@0: simulateItemDrag(metroBtn, panel); michael@0: } michael@0: let zoomControls = document.getElementById("zoom-controls"); michael@0: simulateItemDrag(btn, zoomControls); michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state again."); michael@0: }); michael@0: michael@0: // The default placements should have two placeholders at the bottom (or 1 in win8). michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: let numPlaceholders = isInWin8() ? 1 : 2; michael@0: let panel = document.getElementById(CustomizableUI.AREA_PANEL); michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state."); michael@0: is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders before exiting"); michael@0: michael@0: yield endCustomizing(); michael@0: yield startCustomizing(); michael@0: is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders after re-entering"); michael@0: michael@0: ok(CustomizableUI.inDefaultState, "Should still be in default state."); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: yield endCustomizing(); michael@0: yield resetCustomization(); michael@0: }); michael@0: michael@0: function getVisiblePlaceholderCount(aPanel) { michael@0: let visiblePlaceholders = aPanel.querySelectorAll(".panel-customization-placeholder:not([hidden=true])"); michael@0: return visiblePlaceholders.length; michael@0: }