browser/components/customizableui/test/browser_995164_registerArea_during_customize_mode.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 const TOOLBARID = "test-toolbar-added-during-customize-mode";
     9 add_task(function*() {
    10   yield startCustomizing();
    11   let toolbar = createToolbarWithPlacements(TOOLBARID, []);
    12   CustomizableUI.addWidgetToArea("sync-button", TOOLBARID);
    13   let syncButton = document.getElementById("sync-button");
    14   ok(syncButton, "Sync button should exist.");
    15   is(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should be a wrapper.");
    17   simulateItemDrag(syncButton, gNavToolbox.palette);
    18   ok(!CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved to the palette");
    19   ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button really is in palette.");
    21   simulateItemDrag(syncButton, toolbar);
    22   ok(CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved out of palette");
    23   is(CustomizableUI.getPlacementOfWidget("sync-button").area, TOOLBARID, "Button's back on toolbar");
    24   ok(toolbar.querySelector("#sync-button"), "Sync button really is on toolbar.");
    26   yield endCustomizing();
    27   isnot(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should not be a wrapper outside customize mode.");
    28   yield startCustomizing();
    30   is(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should be a wrapper back in customize mode.");
    32   simulateItemDrag(syncButton, gNavToolbox.palette);
    33   ok(!CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved to the palette");
    34   ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button really is in palette.");
    36   ok(!CustomizableUI.inDefaultState, "Not in default state while toolbar is not collapsed yet.");
    37   setToolbarVisibility(toolbar, false);
    38   ok(CustomizableUI.inDefaultState, "In default state while toolbar is collapsed.");
    40   setToolbarVisibility(toolbar, true);
    42   info("Check that removing the area registration from within customize mode works");
    43   CustomizableUI.unregisterArea(TOOLBARID);
    44   ok(CustomizableUI.inDefaultState, "Now that the toolbar is no longer registered, should be in default state.");
    45   ok(!(new Set(gCustomizeMode.areas)).has(toolbar), "Toolbar shouldn't be known to customize mode.");
    47   CustomizableUI.registerArea(TOOLBARID, {legacy: true, defaultPlacements: []});
    48   CustomizableUI.registerToolbarNode(toolbar, []);
    49   ok(!CustomizableUI.inDefaultState, "Now that the toolbar is registered again, should no longer be in default state.");
    50   ok((new Set(gCustomizeMode.areas)).has(toolbar), "Toolbar should be known to customize mode again.");
    52   simulateItemDrag(syncButton, toolbar);
    53   ok(CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved out of palette");
    54   is(CustomizableUI.getPlacementOfWidget("sync-button").area, TOOLBARID, "Button's back on toolbar");
    55   ok(toolbar.querySelector("#sync-button"), "Sync button really is on toolbar.");
    57   let otherWin = yield openAndLoadWindow({}, true);
    58   let otherTB = otherWin.document.createElementNS(kNSXUL, "toolbar");
    59   otherTB.id = TOOLBARID;
    60   otherTB.setAttribute("customizable", "true");
    61   let wasInformedCorrectlyOfAreaAppearing = false;
    62   let listener = {
    63     onAreaNodeRegistered: function(aArea, aNode) {
    64       if (aNode == otherTB) {
    65         wasInformedCorrectlyOfAreaAppearing = true;
    66       }
    67     }
    68   };
    69   CustomizableUI.addListener(listener);
    70   otherWin.gNavToolbox.appendChild(otherTB);
    71   ok(wasInformedCorrectlyOfAreaAppearing, "Should have been told area was registered.");
    72   CustomizableUI.removeListener(listener);
    74   ok(otherTB.querySelector("#sync-button"), "Sync button is on other toolbar, too.");
    76   simulateItemDrag(syncButton, gNavToolbox.palette);
    77   ok(!CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved to the palette");
    78   ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button really is in palette.");
    79   ok(!otherTB.querySelector("#sync-button"), "Sync button is in palette in other window, too.");
    81   simulateItemDrag(syncButton, toolbar);
    82   ok(CustomizableUI.getPlacementOfWidget("sync-button"), "Button moved out of palette");
    83   is(CustomizableUI.getPlacementOfWidget("sync-button").area, TOOLBARID, "Button's back on toolbar");
    84   ok(toolbar.querySelector("#sync-button"), "Sync button really is on toolbar.");
    85   ok(otherTB.querySelector("#sync-button"), "Sync button is on other toolbar, too.");
    87   let wasInformedCorrectlyOfAreaDisappearing = false;
    88   //XXXgijs So we could be using promiseWindowClosed here. However, after
    89   // repeated random oranges, I'm instead relying on onWindowClosed below to
    90   // fire appropriately - it is linked to an unload event as well, and so
    91   // reusing it prevents a potential race between unload handlers where the
    92   // one from promiseWindowClosed could fire before the onWindowClosed
    93   // (and therefore onAreaNodeRegistered) one, causing the test to fail.
    94   let windowCloseDeferred = Promise.defer();
    95   listener = {
    96     onAreaNodeUnregistered: function(aArea, aNode, aReason) {
    97       if (aArea == TOOLBARID) {
    98         is(aNode, otherTB, "Should be informed about other toolbar");
    99         is(aReason, CustomizableUI.REASON_WINDOW_CLOSED, "Reason should be correct.");
   100         wasInformedCorrectlyOfAreaDisappearing = (aReason === CustomizableUI.REASON_WINDOW_CLOSED);
   101       }
   102     },
   103     onWindowClosed: function(aWindow) {
   104       if (aWindow == otherWin) {
   105         windowCloseDeferred.resolve(aWindow);
   106       } else {
   107         info("Other window was closed!");
   108         info("Other window title: " + (aWindow.document && aWindow.document.title));
   109         info("Our window title: " + (otherWin.document && otherWin.document.title));
   110       }
   111     },
   112   };
   113   CustomizableUI.addListener(listener);
   114   otherWin.close();
   115   let windowClosed = yield windowCloseDeferred.promise;
   117   is(windowClosed, otherWin, "Window should have sent onWindowClosed notification.");
   118   ok(wasInformedCorrectlyOfAreaDisappearing, "Should be told about window closing.");
   119   // Closing the other window should not be counted against this window's customize mode:
   120   is(syncButton.parentNode.localName, "toolbarpaletteitem", "Sync button's parent node should still be a wrapper.");
   121   isnot(gCustomizeMode.areas.indexOf(toolbar), -1, "Toolbar should still be a customizable area for this customize mode instance.");
   123   yield gCustomizeMode.reset();
   125   yield endCustomizing();
   127   CustomizableUI.removeListener(listener);
   128   wasInformedCorrectlyOfAreaDisappearing = false;
   129   listener = {
   130     onAreaNodeUnregistered: function(aArea, aNode, aReason) {
   131       if (aArea == TOOLBARID) {
   132         is(aNode, toolbar, "Should be informed about this window's toolbar");
   133         is(aReason, CustomizableUI.REASON_AREA_UNREGISTERED, "Reason for final removal should be correct.");
   134         wasInformedCorrectlyOfAreaDisappearing = (aReason === CustomizableUI.REASON_AREA_UNREGISTERED);
   135       }
   136     },
   137   }
   138   CustomizableUI.addListener(listener);
   139   removeCustomToolbars();
   140   ok(wasInformedCorrectlyOfAreaDisappearing, "Should be told about area being unregistered.");
   141   CustomizableUI.removeListener(listener);
   142   ok(CustomizableUI.inDefaultState, "Should be fine after exiting customize mode.");
   143 });

mercurial