browser/components/customizableui/test/browser_880164_customization_context_menus.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 isOSX = (Services.appinfo.OS === "Darwin");
     9 // Right-click on the home button should
    10 // show a context menu with options to move it.
    11 add_task(function() {
    12   let contextMenu = document.getElementById("toolbar-context-menu");
    13   let shownPromise = popupShown(contextMenu);
    14   let homeButton = document.getElementById("home-button");
    15   EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2 });
    16   yield shownPromise;
    18   let expectedEntries = [
    19     [".customize-context-moveToPanel", true],
    20     [".customize-context-removeFromToolbar", true],
    21     ["---"]
    22   ];
    23   if (!isOSX) {
    24     expectedEntries.push(["#toggle_toolbar-menubar", true]);
    25   }
    26   expectedEntries.push(
    27     ["#toggle_PersonalToolbar", true],
    28     ["---"],
    29     [".viewCustomizeToolbar", true]
    30   );
    31   checkContextMenu(contextMenu, expectedEntries);
    33   let hiddenPromise = popupHidden(contextMenu);
    34   contextMenu.hidePopup();
    35   yield hiddenPromise;
    36 });
    38 // Right-click on an empty bit of extra toolbar should
    39 // show a context menu with moving options disabled,
    40 // and a toggle option for the extra toolbar
    41 add_task(function() {
    42   let contextMenu = document.getElementById("toolbar-context-menu");
    43   let shownPromise = popupShown(contextMenu);
    44   let toolbar = createToolbarWithPlacements("880164_empty_toolbar", []);
    45   toolbar.setAttribute("context", "toolbar-context-menu");
    46   toolbar.setAttribute("toolbarname", "Fancy Toolbar for Context Menu");
    47   EventUtils.synthesizeMouseAtCenter(toolbar, {type: "contextmenu", button: 2 });
    48   yield shownPromise;
    50   let expectedEntries = [
    51     [".customize-context-moveToPanel", false],
    52     [".customize-context-removeFromToolbar", false],
    53     ["---"]
    54   ];
    55   if (!isOSX) {
    56     expectedEntries.push(["#toggle_toolbar-menubar", true]);
    57   }
    58   expectedEntries.push(
    59     ["#toggle_PersonalToolbar", true],
    60     ["#toggle_880164_empty_toolbar", true],
    61     ["---"],
    62     [".viewCustomizeToolbar", true]
    63   );
    64   checkContextMenu(contextMenu, expectedEntries);
    66   let hiddenPromise = popupHidden(contextMenu);
    67   contextMenu.hidePopup();
    68   yield hiddenPromise;
    69   removeCustomToolbars();
    70 });
    73 // Right-click on the urlbar-container should
    74 // show a context menu with disabled options to move it.
    75 add_task(function() {
    76   let contextMenu = document.getElementById("toolbar-context-menu");
    77   let shownPromise = popupShown(contextMenu);
    78   let urlBarContainer = document.getElementById("urlbar-container");
    79   // Need to make sure not to click within an edit field.
    80   let urlbarRect = urlBarContainer.getBoundingClientRect();
    81   EventUtils.synthesizeMouse(urlBarContainer, 100, urlbarRect.height - 1, {type: "contextmenu", button: 2 });
    82   yield shownPromise;
    84   let expectedEntries = [
    85     [".customize-context-moveToPanel", false],
    86     [".customize-context-removeFromToolbar", false],
    87     ["---"]
    88   ];
    89   if (!isOSX) {
    90     expectedEntries.push(["#toggle_toolbar-menubar", true]);
    91   }
    92   expectedEntries.push(
    93     ["#toggle_PersonalToolbar", true],
    94     ["---"],
    95     [".viewCustomizeToolbar", true]
    96   );
    97   checkContextMenu(contextMenu, expectedEntries);
    99   let hiddenPromise = popupHidden(contextMenu);
   100   contextMenu.hidePopup();
   101   yield hiddenPromise;
   102 });
   104 // Right-click on the searchbar and moving it to the menu
   105 // and back should move the search-container instead.
   106 add_task(function() {
   107   let searchbar = document.getElementById("searchbar");
   108   gCustomizeMode.addToPanel(searchbar);
   109   let placement = CustomizableUI.getPlacementOfWidget("search-container");
   110   is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
   112   let shownPanelPromise = promisePanelShown(window);
   113   PanelUI.toggle({type: "command"});
   114   yield shownPanelPromise;
   115   let hiddenPanelPromise = promisePanelHidden(window);
   116   PanelUI.toggle({type: "command"});
   117   yield hiddenPanelPromise;
   119   gCustomizeMode.addToToolbar(searchbar);
   120   placement = CustomizableUI.getPlacementOfWidget("search-container");
   121   is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
   122   gCustomizeMode.removeFromArea(searchbar);
   123   placement = CustomizableUI.getPlacementOfWidget("search-container");
   124   is(placement, null, "Should be in palette");
   125   CustomizableUI.reset();
   126   placement = CustomizableUI.getPlacementOfWidget("search-container");
   127   is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
   128 });
   130 // Right-click on an item within the menu panel should
   131 // show a context menu with options to move it.
   132 add_task(function() {
   133   let shownPanelPromise = promisePanelShown(window);
   134   PanelUI.toggle({type: "command"});
   135   yield shownPanelPromise;
   137   let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   138   let shownContextPromise = popupShown(contextMenu);
   139   let newWindowButton = document.getElementById("new-window-button");
   140   ok(newWindowButton, "new-window-button was found");
   141   EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
   142   yield shownContextPromise;
   144   is(PanelUI.panel.state, "open", "The PanelUI should still be open.");
   146   let expectedEntries = [
   147     [".customize-context-moveToToolbar", true],
   148     [".customize-context-removeFromPanel", true],
   149     ["---"],
   150     [".viewCustomizeToolbar", true]
   151   ];
   152   checkContextMenu(contextMenu, expectedEntries);
   154   let hiddenContextPromise = popupHidden(contextMenu);
   155   contextMenu.hidePopup();
   156   yield hiddenContextPromise;
   158   let hiddenPromise = promisePanelHidden(window);
   159   PanelUI.toggle({type: "command"});
   160   yield hiddenPromise;
   161 });
   163 // Right-click on the home button while in customization mode
   164 // should show a context menu with options to move it.
   165 add_task(function() {
   166   yield startCustomizing();
   167   let contextMenu = document.getElementById("toolbar-context-menu");
   168   let shownPromise = popupShown(contextMenu);
   169   let homeButton = document.getElementById("wrapper-home-button");
   170   EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2});
   171   yield shownPromise;
   173   let expectedEntries = [
   174     [".customize-context-moveToPanel", true],
   175     [".customize-context-removeFromToolbar", true],
   176     ["---"]
   177   ];
   178   if (!isOSX) {
   179     expectedEntries.push(["#toggle_toolbar-menubar", true]);
   180   }
   181   expectedEntries.push(
   182     ["#toggle_PersonalToolbar", true],
   183     ["---"],
   184     [".viewCustomizeToolbar", false]
   185   );
   186   checkContextMenu(contextMenu, expectedEntries);
   188   let hiddenContextPromise = popupHidden(contextMenu);
   189   contextMenu.hidePopup();
   190   yield hiddenContextPromise;
   191 });
   193 // Right-click on an item in the palette should
   194 // show a context menu with options to move it.
   195 add_task(function() {
   196   let contextMenu = document.getElementById("customizationPaletteItemContextMenu");
   197   let shownPromise = popupShown(contextMenu);
   198   let openFileButton = document.getElementById("wrapper-open-file-button");
   199   EventUtils.synthesizeMouse(openFileButton, 2, 2, {type: "contextmenu", button: 2});
   200   yield shownPromise;
   202   let expectedEntries = [
   203     [".customize-context-addToToolbar", true],
   204     [".customize-context-addToPanel", true]
   205   ];
   206   checkContextMenu(contextMenu, expectedEntries);
   208   let hiddenContextPromise = popupHidden(contextMenu);
   209   contextMenu.hidePopup();
   210   yield hiddenContextPromise;
   211 });
   213 // Right-click on an item in the panel while in customization mode
   214 // should show a context menu with options to move it.
   215 add_task(function() {
   216   let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   217   let shownPromise = popupShown(contextMenu);
   218   let newWindowButton = document.getElementById("wrapper-new-window-button");
   219   EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
   220   yield shownPromise;
   222   let expectedEntries = [
   223     [".customize-context-moveToToolbar", true],
   224     [".customize-context-removeFromPanel", true],
   225     ["---"],
   226     [".viewCustomizeToolbar", false]
   227   ];
   228   checkContextMenu(contextMenu, expectedEntries);
   230   let hiddenContextPromise = popupHidden(contextMenu);
   231   contextMenu.hidePopup();
   232   yield hiddenContextPromise;
   233   yield endCustomizing();
   234 });
   236 // Test the toolbarbutton panel context menu in customization mode
   237 // without opening the panel before customization mode
   238 add_task(function() {
   239   this.otherWin = yield openAndLoadWindow(null, true);
   241   yield startCustomizing(this.otherWin);
   243   let contextMenu = this.otherWin.document.getElementById("customizationPanelItemContextMenu");
   244   let shownPromise = popupShown(contextMenu);
   245   let newWindowButton = this.otherWin.document.getElementById("wrapper-new-window-button");
   246   EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}, this.otherWin);
   247   yield shownPromise;
   249   let expectedEntries = [
   250     [".customize-context-moveToToolbar", true],
   251     [".customize-context-removeFromPanel", true],
   252     ["---"],
   253     [".viewCustomizeToolbar", false]
   254   ];
   255   checkContextMenu(contextMenu, expectedEntries, this.otherWin);
   257   let hiddenContextPromise = popupHidden(contextMenu);
   258   contextMenu.hidePopup();
   259   yield hiddenContextPromise;
   260   yield endCustomizing(this.otherWin);
   261   yield promiseWindowClosed(this.otherWin);
   262   this.otherWin = null;
   263 });
   265 // Bug 945191 - Combined buttons show wrong context menu options
   266 // when they are in the toolbar.
   267 add_task(function() {
   268   yield startCustomizing();
   269   let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   270   let shownPromise = popupShown(contextMenu);
   271   let zoomControls = document.getElementById("wrapper-zoom-controls");
   272   EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
   273   yield shownPromise;
   274   // Execute the command to move the item from the panel to the toolbar.
   275   contextMenu.childNodes[0].doCommand();
   276   let hiddenPromise = popupHidden(contextMenu);
   277   contextMenu.hidePopup();
   278   yield hiddenPromise;
   279   yield endCustomizing();
   281   zoomControls = document.getElementById("zoom-controls");
   282   is(zoomControls.parentNode.id, "nav-bar-customization-target", "Zoom-controls should be on the nav-bar");
   284   contextMenu = document.getElementById("toolbar-context-menu");
   285   shownPromise = popupShown(contextMenu);
   286   EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
   287   yield shownPromise;
   289   let expectedEntries = [
   290     [".customize-context-moveToPanel", true],
   291     [".customize-context-removeFromToolbar", true],
   292     ["---"]
   293   ];
   294   if (!isOSX) {
   295     expectedEntries.push(["#toggle_toolbar-menubar", true]);
   296   }
   297   expectedEntries.push(
   298     ["#toggle_PersonalToolbar", true],
   299     ["---"],
   300     [".viewCustomizeToolbar", true]
   301   );
   302   checkContextMenu(contextMenu, expectedEntries);
   304   hiddenPromise = popupHidden(contextMenu);
   305   contextMenu.hidePopup();
   306   yield hiddenPromise;
   307   yield resetCustomization();
   308 });
   310 // Bug 947586 - After customization, panel items show wrong context menu options
   311 add_task(function() {
   312   yield startCustomizing();
   313   yield endCustomizing();
   315   yield PanelUI.show();
   317   let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   318   let shownContextPromise = popupShown(contextMenu);
   319   let newWindowButton = document.getElementById("new-window-button");
   320   ok(newWindowButton, "new-window-button was found");
   321   EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
   322   yield shownContextPromise;
   324   is(PanelUI.panel.state, "open", "The PanelUI should still be open.");
   326   let expectedEntries = [
   327     [".customize-context-moveToToolbar", true],
   328     [".customize-context-removeFromPanel", true],
   329     ["---"],
   330     [".viewCustomizeToolbar", true]
   331   ];
   332   checkContextMenu(contextMenu, expectedEntries);
   334   let hiddenContextPromise = popupHidden(contextMenu);
   335   contextMenu.hidePopup();
   336   yield hiddenContextPromise;
   338   let hiddenPromise = promisePanelHidden(window);
   339   PanelUI.hide();
   340   yield hiddenPromise;
   341 });
   344 // Bug 982027 - moving icon around removes custom context menu.
   345 add_task(function() {
   346   let widgetId = "custom-context-menu-toolbarbutton";
   347   let expectedContext = "myfancycontext";
   348   let widget = createDummyXULButton(widgetId, "Test ctxt menu");
   349   widget.setAttribute("context", expectedContext);
   350   CustomizableUI.addWidgetToArea(widgetId, CustomizableUI.AREA_NAVBAR);
   351   is(widget.getAttribute("context"), expectedContext, "Should have context menu when added to the toolbar.");
   353   yield startCustomizing();
   354   is(widget.getAttribute("context"), "", "Should not have own context menu in the toolbar now that we're customizing.");
   355   is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped when in toolbar.");
   357   let panel = PanelUI.contents;
   358   simulateItemDrag(widget, panel);
   359   is(widget.getAttribute("context"), "", "Should not have own context menu when in the panel.");
   360   is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're in the panel.");
   362   simulateItemDrag(widget, document.getElementById("nav-bar").customizationTarget);
   363   is(widget.getAttribute("context"), "", "Should not have own context menu when back in toolbar because we're still customizing.");
   364   is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're back in the toolbar.");
   366   yield endCustomizing();
   367   is(widget.getAttribute("context"), expectedContext, "Should have context menu again now that we're out of customize mode.");
   368   CustomizableUI.removeWidgetFromArea(widgetId);
   369   widget.remove();
   370   ok(CustomizableUI.inDefaultState, "Should be in default state after removing button.");
   371 });

mercurial