browser/components/customizableui/test/browser_890140_orphaned_placeholders.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_890140_orphaned_placeholders.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,167 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +requestLongerTimeout(2);
    1.11 +
    1.12 +// One orphaned item should have two placeholders next to it.
    1.13 +add_task(function() {
    1.14 +  yield startCustomizing();
    1.15 +  let btn = document.getElementById("open-file-button");
    1.16 +  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
    1.17 +  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    1.18 +
    1.19 +  if (isInWin8()) {
    1.20 +    CustomizableUI.removeWidgetFromArea("switch-to-metro-button");
    1.21 +    placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    1.22 +    ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
    1.23 +  } else {
    1.24 +    ok(CustomizableUI.inDefaultState, "Should be in default state.");
    1.25 +  }
    1.26 +
    1.27 +  assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
    1.28 +  is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders before exiting");
    1.29 +
    1.30 +  yield endCustomizing();
    1.31 +  yield startCustomizing();
    1.32 +  is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders after re-entering");
    1.33 +
    1.34 +  if (isInWin8()) {
    1.35 +    CustomizableUI.addWidgetToArea("switch-to-metro-button", CustomizableUI.AREA_PANEL);
    1.36 +  }
    1.37 +  ok(CustomizableUI.inDefaultState, "Should be in default state again.");
    1.38 +});
    1.39 +
    1.40 +// Two orphaned items should have one placeholder next to them (case 1).
    1.41 +add_task(function() {
    1.42 +  yield startCustomizing();
    1.43 +  let btn = document.getElementById("open-file-button");
    1.44 +  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
    1.45 +  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    1.46 +
    1.47 +  let placementsAfterAppend = placements;
    1.48 +
    1.49 +  if (!isInWin8()) {
    1.50 +    placementsAfterAppend = placements.concat(["open-file-button"]);
    1.51 +    simulateItemDrag(btn, panel);
    1.52 +  }
    1.53 +
    1.54 +  assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
    1.55 +  is(CustomizableUI.inDefaultState, isInWin8(), "Should only be in default state if on Win8");
    1.56 +  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
    1.57 +
    1.58 +  yield endCustomizing();
    1.59 +  yield startCustomizing();
    1.60 +  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
    1.61 +
    1.62 +  let palette = document.getElementById("customization-palette");
    1.63 +  simulateItemDrag(btn, palette);
    1.64 +
    1.65 +  if (!isInWin8()) {
    1.66 +    btn = document.getElementById("open-file-button");
    1.67 +    simulateItemDrag(btn, palette);
    1.68 +  }
    1.69 +  ok(CustomizableUI.inDefaultState, "Should be in default state again."); 
    1.70 +});
    1.71 +
    1.72 +// Two orphaned items should have one placeholder next to them (case 2).
    1.73 +add_task(function() {
    1.74 +  yield startCustomizing();
    1.75 +  let btn = document.getElementById("add-ons-button");
    1.76 +  let btn2 = document.getElementById("developer-button");
    1.77 +  let btn3 = document.getElementById("switch-to-metro-button");
    1.78 +  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
    1.79 +  let palette = document.getElementById("customization-palette");
    1.80 +  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    1.81 +
    1.82 +  let placementsAfterAppend = placements.filter(p => p != btn.id && p != btn2.id);
    1.83 +  simulateItemDrag(btn, palette);
    1.84 +  simulateItemDrag(btn2, palette);
    1.85 +
    1.86 +  if (isInWin8()) {
    1.87 +    placementsAfterAppend = placementsAfterAppend.filter(p => p != btn3.id);
    1.88 +    simulateItemDrag(btn3, palette);
    1.89 +  }
    1.90 +
    1.91 +  assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
    1.92 +  ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
    1.93 +  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
    1.94 +
    1.95 +  yield endCustomizing();
    1.96 +  yield startCustomizing();
    1.97 +  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
    1.98 +
    1.99 +  simulateItemDrag(btn, panel);
   1.100 +  simulateItemDrag(btn2, panel);
   1.101 +
   1.102 +  if (isInWin8()) {
   1.103 +    simulateItemDrag(btn3, panel);
   1.104 +  }
   1.105 +
   1.106 +  assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
   1.107 +  ok(CustomizableUI.inDefaultState, "Should be in default state again.");
   1.108 +});
   1.109 +
   1.110 +// A wide widget at the bottom of the panel should have three placeholders after it.
   1.111 +add_task(function() {
   1.112 +  yield startCustomizing();
   1.113 +  let btn = document.getElementById("edit-controls");
   1.114 +  let developerButton = document.getElementById("developer-button");
   1.115 +  let metroBtn = document.getElementById("switch-to-metro-button");
   1.116 +  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
   1.117 +  let palette = document.getElementById("customization-palette");
   1.118 +  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
   1.119 +
   1.120 +  placements.pop();
   1.121 +  simulateItemDrag(developerButton, palette);
   1.122 +  if (isInWin8()) {
   1.123 +    // Remove switch-to-metro-button
   1.124 +    placements.pop();
   1.125 +    simulateItemDrag(metroBtn, palette);
   1.126 +  }
   1.127 +
   1.128 +  let placementsAfterAppend = placements.concat([placements.shift()]);
   1.129 +  simulateItemDrag(btn, panel);
   1.130 +  assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
   1.131 +  ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
   1.132 +  is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders before exiting");
   1.133 +
   1.134 +  yield endCustomizing();
   1.135 +  yield startCustomizing();
   1.136 +  is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders after re-entering");
   1.137 +
   1.138 +  simulateItemDrag(developerButton, panel);
   1.139 +  if (isInWin8()) {
   1.140 +    simulateItemDrag(metroBtn, panel);
   1.141 +  }
   1.142 +  let zoomControls = document.getElementById("zoom-controls");
   1.143 +  simulateItemDrag(btn, zoomControls);
   1.144 +  ok(CustomizableUI.inDefaultState, "Should be in default state again.");
   1.145 +});
   1.146 +
   1.147 +// The default placements should have two placeholders at the bottom (or 1 in win8).
   1.148 +add_task(function() {
   1.149 +  yield startCustomizing();
   1.150 +  let numPlaceholders = isInWin8() ? 1 : 2;
   1.151 +  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
   1.152 +  ok(CustomizableUI.inDefaultState, "Should be in default state.");
   1.153 +  is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders before exiting");
   1.154 +
   1.155 +  yield endCustomizing();
   1.156 +  yield startCustomizing();
   1.157 +  is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders after re-entering");
   1.158 +
   1.159 +  ok(CustomizableUI.inDefaultState, "Should still be in default state.");
   1.160 +});
   1.161 +
   1.162 +add_task(function asyncCleanup() {
   1.163 +  yield endCustomizing();
   1.164 +  yield resetCustomization();
   1.165 +});
   1.166 +
   1.167 +function getVisiblePlaceholderCount(aPanel) {
   1.168 +  let visiblePlaceholders = aPanel.querySelectorAll(".panel-customization-placeholder:not([hidden=true])");
   1.169 +  return visiblePlaceholders.length;
   1.170 +}

mercurial