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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 "use strict";
     7 requestLongerTimeout(2);
     9 // One orphaned item should have two placeholders next to it.
    10 add_task(function() {
    11   yield startCustomizing();
    12   let btn = document.getElementById("open-file-button");
    13   let panel = document.getElementById(CustomizableUI.AREA_PANEL);
    14   let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    16   if (isInWin8()) {
    17     CustomizableUI.removeWidgetFromArea("switch-to-metro-button");
    18     placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    19     ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
    20   } else {
    21     ok(CustomizableUI.inDefaultState, "Should be in default state.");
    22   }
    24   assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
    25   is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders before exiting");
    27   yield endCustomizing();
    28   yield startCustomizing();
    29   is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders after re-entering");
    31   if (isInWin8()) {
    32     CustomizableUI.addWidgetToArea("switch-to-metro-button", CustomizableUI.AREA_PANEL);
    33   }
    34   ok(CustomizableUI.inDefaultState, "Should be in default state again.");
    35 });
    37 // Two orphaned items should have one placeholder next to them (case 1).
    38 add_task(function() {
    39   yield startCustomizing();
    40   let btn = document.getElementById("open-file-button");
    41   let panel = document.getElementById(CustomizableUI.AREA_PANEL);
    42   let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    44   let placementsAfterAppend = placements;
    46   if (!isInWin8()) {
    47     placementsAfterAppend = placements.concat(["open-file-button"]);
    48     simulateItemDrag(btn, panel);
    49   }
    51   assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
    52   is(CustomizableUI.inDefaultState, isInWin8(), "Should only be in default state if on Win8");
    53   is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
    55   yield endCustomizing();
    56   yield startCustomizing();
    57   is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
    59   let palette = document.getElementById("customization-palette");
    60   simulateItemDrag(btn, palette);
    62   if (!isInWin8()) {
    63     btn = document.getElementById("open-file-button");
    64     simulateItemDrag(btn, palette);
    65   }
    66   ok(CustomizableUI.inDefaultState, "Should be in default state again."); 
    67 });
    69 // Two orphaned items should have one placeholder next to them (case 2).
    70 add_task(function() {
    71   yield startCustomizing();
    72   let btn = document.getElementById("add-ons-button");
    73   let btn2 = document.getElementById("developer-button");
    74   let btn3 = document.getElementById("switch-to-metro-button");
    75   let panel = document.getElementById(CustomizableUI.AREA_PANEL);
    76   let palette = document.getElementById("customization-palette");
    77   let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
    79   let placementsAfterAppend = placements.filter(p => p != btn.id && p != btn2.id);
    80   simulateItemDrag(btn, palette);
    81   simulateItemDrag(btn2, palette);
    83   if (isInWin8()) {
    84     placementsAfterAppend = placementsAfterAppend.filter(p => p != btn3.id);
    85     simulateItemDrag(btn3, palette);
    86   }
    88   assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
    89   ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
    90   is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
    92   yield endCustomizing();
    93   yield startCustomizing();
    94   is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
    96   simulateItemDrag(btn, panel);
    97   simulateItemDrag(btn2, panel);
    99   if (isInWin8()) {
   100     simulateItemDrag(btn3, panel);
   101   }
   103   assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
   104   ok(CustomizableUI.inDefaultState, "Should be in default state again.");
   105 });
   107 // A wide widget at the bottom of the panel should have three placeholders after it.
   108 add_task(function() {
   109   yield startCustomizing();
   110   let btn = document.getElementById("edit-controls");
   111   let developerButton = document.getElementById("developer-button");
   112   let metroBtn = document.getElementById("switch-to-metro-button");
   113   let panel = document.getElementById(CustomizableUI.AREA_PANEL);
   114   let palette = document.getElementById("customization-palette");
   115   let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
   117   placements.pop();
   118   simulateItemDrag(developerButton, palette);
   119   if (isInWin8()) {
   120     // Remove switch-to-metro-button
   121     placements.pop();
   122     simulateItemDrag(metroBtn, palette);
   123   }
   125   let placementsAfterAppend = placements.concat([placements.shift()]);
   126   simulateItemDrag(btn, panel);
   127   assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
   128   ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
   129   is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders before exiting");
   131   yield endCustomizing();
   132   yield startCustomizing();
   133   is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders after re-entering");
   135   simulateItemDrag(developerButton, panel);
   136   if (isInWin8()) {
   137     simulateItemDrag(metroBtn, panel);
   138   }
   139   let zoomControls = document.getElementById("zoom-controls");
   140   simulateItemDrag(btn, zoomControls);
   141   ok(CustomizableUI.inDefaultState, "Should be in default state again.");
   142 });
   144 // The default placements should have two placeholders at the bottom (or 1 in win8).
   145 add_task(function() {
   146   yield startCustomizing();
   147   let numPlaceholders = isInWin8() ? 1 : 2;
   148   let panel = document.getElementById(CustomizableUI.AREA_PANEL);
   149   ok(CustomizableUI.inDefaultState, "Should be in default state.");
   150   is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders before exiting");
   152   yield endCustomizing();
   153   yield startCustomizing();
   154   is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders after re-entering");
   156   ok(CustomizableUI.inDefaultState, "Should still be in default state.");
   157 });
   159 add_task(function asyncCleanup() {
   160   yield endCustomizing();
   161   yield resetCustomization();
   162 });
   164 function getVisiblePlaceholderCount(aPanel) {
   165   let visiblePlaceholders = aPanel.querySelectorAll(".panel-customization-placeholder:not([hidden=true])");
   166   return visiblePlaceholders.length;
   167 }

mercurial