browser/components/customizableui/test/browser_890140_orphaned_placeholders.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 requestLongerTimeout(2);
michael@0 8
michael@0 9 // One orphaned item should have two placeholders next to it.
michael@0 10 add_task(function() {
michael@0 11 yield startCustomizing();
michael@0 12 let btn = document.getElementById("open-file-button");
michael@0 13 let panel = document.getElementById(CustomizableUI.AREA_PANEL);
michael@0 14 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
michael@0 15
michael@0 16 if (isInWin8()) {
michael@0 17 CustomizableUI.removeWidgetFromArea("switch-to-metro-button");
michael@0 18 placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
michael@0 19 ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
michael@0 20 } else {
michael@0 21 ok(CustomizableUI.inDefaultState, "Should be in default state.");
michael@0 22 }
michael@0 23
michael@0 24 assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
michael@0 25 is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders before exiting");
michael@0 26
michael@0 27 yield endCustomizing();
michael@0 28 yield startCustomizing();
michael@0 29 is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders after re-entering");
michael@0 30
michael@0 31 if (isInWin8()) {
michael@0 32 CustomizableUI.addWidgetToArea("switch-to-metro-button", CustomizableUI.AREA_PANEL);
michael@0 33 }
michael@0 34 ok(CustomizableUI.inDefaultState, "Should be in default state again.");
michael@0 35 });
michael@0 36
michael@0 37 // Two orphaned items should have one placeholder next to them (case 1).
michael@0 38 add_task(function() {
michael@0 39 yield startCustomizing();
michael@0 40 let btn = document.getElementById("open-file-button");
michael@0 41 let panel = document.getElementById(CustomizableUI.AREA_PANEL);
michael@0 42 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
michael@0 43
michael@0 44 let placementsAfterAppend = placements;
michael@0 45
michael@0 46 if (!isInWin8()) {
michael@0 47 placementsAfterAppend = placements.concat(["open-file-button"]);
michael@0 48 simulateItemDrag(btn, panel);
michael@0 49 }
michael@0 50
michael@0 51 assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
michael@0 52 is(CustomizableUI.inDefaultState, isInWin8(), "Should only be in default state if on Win8");
michael@0 53 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
michael@0 54
michael@0 55 yield endCustomizing();
michael@0 56 yield startCustomizing();
michael@0 57 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
michael@0 58
michael@0 59 let palette = document.getElementById("customization-palette");
michael@0 60 simulateItemDrag(btn, palette);
michael@0 61
michael@0 62 if (!isInWin8()) {
michael@0 63 btn = document.getElementById("open-file-button");
michael@0 64 simulateItemDrag(btn, palette);
michael@0 65 }
michael@0 66 ok(CustomizableUI.inDefaultState, "Should be in default state again.");
michael@0 67 });
michael@0 68
michael@0 69 // Two orphaned items should have one placeholder next to them (case 2).
michael@0 70 add_task(function() {
michael@0 71 yield startCustomizing();
michael@0 72 let btn = document.getElementById("add-ons-button");
michael@0 73 let btn2 = document.getElementById("developer-button");
michael@0 74 let btn3 = document.getElementById("switch-to-metro-button");
michael@0 75 let panel = document.getElementById(CustomizableUI.AREA_PANEL);
michael@0 76 let palette = document.getElementById("customization-palette");
michael@0 77 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
michael@0 78
michael@0 79 let placementsAfterAppend = placements.filter(p => p != btn.id && p != btn2.id);
michael@0 80 simulateItemDrag(btn, palette);
michael@0 81 simulateItemDrag(btn2, palette);
michael@0 82
michael@0 83 if (isInWin8()) {
michael@0 84 placementsAfterAppend = placementsAfterAppend.filter(p => p != btn3.id);
michael@0 85 simulateItemDrag(btn3, palette);
michael@0 86 }
michael@0 87
michael@0 88 assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
michael@0 89 ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
michael@0 90 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
michael@0 91
michael@0 92 yield endCustomizing();
michael@0 93 yield startCustomizing();
michael@0 94 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
michael@0 95
michael@0 96 simulateItemDrag(btn, panel);
michael@0 97 simulateItemDrag(btn2, panel);
michael@0 98
michael@0 99 if (isInWin8()) {
michael@0 100 simulateItemDrag(btn3, panel);
michael@0 101 }
michael@0 102
michael@0 103 assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
michael@0 104 ok(CustomizableUI.inDefaultState, "Should be in default state again.");
michael@0 105 });
michael@0 106
michael@0 107 // A wide widget at the bottom of the panel should have three placeholders after it.
michael@0 108 add_task(function() {
michael@0 109 yield startCustomizing();
michael@0 110 let btn = document.getElementById("edit-controls");
michael@0 111 let developerButton = document.getElementById("developer-button");
michael@0 112 let metroBtn = document.getElementById("switch-to-metro-button");
michael@0 113 let panel = document.getElementById(CustomizableUI.AREA_PANEL);
michael@0 114 let palette = document.getElementById("customization-palette");
michael@0 115 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
michael@0 116
michael@0 117 placements.pop();
michael@0 118 simulateItemDrag(developerButton, palette);
michael@0 119 if (isInWin8()) {
michael@0 120 // Remove switch-to-metro-button
michael@0 121 placements.pop();
michael@0 122 simulateItemDrag(metroBtn, palette);
michael@0 123 }
michael@0 124
michael@0 125 let placementsAfterAppend = placements.concat([placements.shift()]);
michael@0 126 simulateItemDrag(btn, panel);
michael@0 127 assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
michael@0 128 ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
michael@0 129 is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders before exiting");
michael@0 130
michael@0 131 yield endCustomizing();
michael@0 132 yield startCustomizing();
michael@0 133 is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders after re-entering");
michael@0 134
michael@0 135 simulateItemDrag(developerButton, panel);
michael@0 136 if (isInWin8()) {
michael@0 137 simulateItemDrag(metroBtn, panel);
michael@0 138 }
michael@0 139 let zoomControls = document.getElementById("zoom-controls");
michael@0 140 simulateItemDrag(btn, zoomControls);
michael@0 141 ok(CustomizableUI.inDefaultState, "Should be in default state again.");
michael@0 142 });
michael@0 143
michael@0 144 // The default placements should have two placeholders at the bottom (or 1 in win8).
michael@0 145 add_task(function() {
michael@0 146 yield startCustomizing();
michael@0 147 let numPlaceholders = isInWin8() ? 1 : 2;
michael@0 148 let panel = document.getElementById(CustomizableUI.AREA_PANEL);
michael@0 149 ok(CustomizableUI.inDefaultState, "Should be in default state.");
michael@0 150 is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders before exiting");
michael@0 151
michael@0 152 yield endCustomizing();
michael@0 153 yield startCustomizing();
michael@0 154 is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders after re-entering");
michael@0 155
michael@0 156 ok(CustomizableUI.inDefaultState, "Should still be in default state.");
michael@0 157 });
michael@0 158
michael@0 159 add_task(function asyncCleanup() {
michael@0 160 yield endCustomizing();
michael@0 161 yield resetCustomization();
michael@0 162 });
michael@0 163
michael@0 164 function getVisiblePlaceholderCount(aPanel) {
michael@0 165 let visiblePlaceholders = aPanel.querySelectorAll(".panel-customization-placeholder:not([hidden=true])");
michael@0 166 return visiblePlaceholders.length;
michael@0 167 }

mercurial