browser/components/customizableui/test/browser_880164_customization_context_menus.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_880164_customization_context_menus.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,371 @@
     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 +const isOSX = (Services.appinfo.OS === "Darwin");
    1.11 +
    1.12 +// Right-click on the home button should
    1.13 +// show a context menu with options to move it.
    1.14 +add_task(function() {
    1.15 +  let contextMenu = document.getElementById("toolbar-context-menu");
    1.16 +  let shownPromise = popupShown(contextMenu);
    1.17 +  let homeButton = document.getElementById("home-button");
    1.18 +  EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2 });
    1.19 +  yield shownPromise;
    1.20 +
    1.21 +  let expectedEntries = [
    1.22 +    [".customize-context-moveToPanel", true],
    1.23 +    [".customize-context-removeFromToolbar", true],
    1.24 +    ["---"]
    1.25 +  ];
    1.26 +  if (!isOSX) {
    1.27 +    expectedEntries.push(["#toggle_toolbar-menubar", true]);
    1.28 +  }
    1.29 +  expectedEntries.push(
    1.30 +    ["#toggle_PersonalToolbar", true],
    1.31 +    ["---"],
    1.32 +    [".viewCustomizeToolbar", true]
    1.33 +  );
    1.34 +  checkContextMenu(contextMenu, expectedEntries);
    1.35 +
    1.36 +  let hiddenPromise = popupHidden(contextMenu);
    1.37 +  contextMenu.hidePopup();
    1.38 +  yield hiddenPromise;
    1.39 +});
    1.40 +
    1.41 +// Right-click on an empty bit of extra toolbar should
    1.42 +// show a context menu with moving options disabled,
    1.43 +// and a toggle option for the extra toolbar
    1.44 +add_task(function() {
    1.45 +  let contextMenu = document.getElementById("toolbar-context-menu");
    1.46 +  let shownPromise = popupShown(contextMenu);
    1.47 +  let toolbar = createToolbarWithPlacements("880164_empty_toolbar", []);
    1.48 +  toolbar.setAttribute("context", "toolbar-context-menu");
    1.49 +  toolbar.setAttribute("toolbarname", "Fancy Toolbar for Context Menu");
    1.50 +  EventUtils.synthesizeMouseAtCenter(toolbar, {type: "contextmenu", button: 2 });
    1.51 +  yield shownPromise;
    1.52 +
    1.53 +  let expectedEntries = [
    1.54 +    [".customize-context-moveToPanel", false],
    1.55 +    [".customize-context-removeFromToolbar", false],
    1.56 +    ["---"]
    1.57 +  ];
    1.58 +  if (!isOSX) {
    1.59 +    expectedEntries.push(["#toggle_toolbar-menubar", true]);
    1.60 +  }
    1.61 +  expectedEntries.push(
    1.62 +    ["#toggle_PersonalToolbar", true],
    1.63 +    ["#toggle_880164_empty_toolbar", true],
    1.64 +    ["---"],
    1.65 +    [".viewCustomizeToolbar", true]
    1.66 +  );
    1.67 +  checkContextMenu(contextMenu, expectedEntries);
    1.68 +
    1.69 +  let hiddenPromise = popupHidden(contextMenu);
    1.70 +  contextMenu.hidePopup();
    1.71 +  yield hiddenPromise;
    1.72 +  removeCustomToolbars();
    1.73 +});
    1.74 +
    1.75 +
    1.76 +// Right-click on the urlbar-container should
    1.77 +// show a context menu with disabled options to move it.
    1.78 +add_task(function() {
    1.79 +  let contextMenu = document.getElementById("toolbar-context-menu");
    1.80 +  let shownPromise = popupShown(contextMenu);
    1.81 +  let urlBarContainer = document.getElementById("urlbar-container");
    1.82 +  // Need to make sure not to click within an edit field.
    1.83 +  let urlbarRect = urlBarContainer.getBoundingClientRect();
    1.84 +  EventUtils.synthesizeMouse(urlBarContainer, 100, urlbarRect.height - 1, {type: "contextmenu", button: 2 });
    1.85 +  yield shownPromise;
    1.86 +
    1.87 +  let expectedEntries = [
    1.88 +    [".customize-context-moveToPanel", false],
    1.89 +    [".customize-context-removeFromToolbar", false],
    1.90 +    ["---"]
    1.91 +  ];
    1.92 +  if (!isOSX) {
    1.93 +    expectedEntries.push(["#toggle_toolbar-menubar", true]);
    1.94 +  }
    1.95 +  expectedEntries.push(
    1.96 +    ["#toggle_PersonalToolbar", true],
    1.97 +    ["---"],
    1.98 +    [".viewCustomizeToolbar", true]
    1.99 +  );
   1.100 +  checkContextMenu(contextMenu, expectedEntries);
   1.101 +
   1.102 +  let hiddenPromise = popupHidden(contextMenu);
   1.103 +  contextMenu.hidePopup();
   1.104 +  yield hiddenPromise;
   1.105 +});
   1.106 +
   1.107 +// Right-click on the searchbar and moving it to the menu
   1.108 +// and back should move the search-container instead.
   1.109 +add_task(function() {
   1.110 +  let searchbar = document.getElementById("searchbar");
   1.111 +  gCustomizeMode.addToPanel(searchbar);
   1.112 +  let placement = CustomizableUI.getPlacementOfWidget("search-container");
   1.113 +  is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
   1.114 +
   1.115 +  let shownPanelPromise = promisePanelShown(window);
   1.116 +  PanelUI.toggle({type: "command"});
   1.117 +  yield shownPanelPromise;
   1.118 +  let hiddenPanelPromise = promisePanelHidden(window);
   1.119 +  PanelUI.toggle({type: "command"});
   1.120 +  yield hiddenPanelPromise;
   1.121 +
   1.122 +  gCustomizeMode.addToToolbar(searchbar);
   1.123 +  placement = CustomizableUI.getPlacementOfWidget("search-container");
   1.124 +  is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
   1.125 +  gCustomizeMode.removeFromArea(searchbar);
   1.126 +  placement = CustomizableUI.getPlacementOfWidget("search-container");
   1.127 +  is(placement, null, "Should be in palette");
   1.128 +  CustomizableUI.reset();
   1.129 +  placement = CustomizableUI.getPlacementOfWidget("search-container");
   1.130 +  is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
   1.131 +});
   1.132 +
   1.133 +// Right-click on an item within the menu panel should
   1.134 +// show a context menu with options to move it.
   1.135 +add_task(function() {
   1.136 +  let shownPanelPromise = promisePanelShown(window);
   1.137 +  PanelUI.toggle({type: "command"});
   1.138 +  yield shownPanelPromise;
   1.139 +
   1.140 +  let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   1.141 +  let shownContextPromise = popupShown(contextMenu);
   1.142 +  let newWindowButton = document.getElementById("new-window-button");
   1.143 +  ok(newWindowButton, "new-window-button was found");
   1.144 +  EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
   1.145 +  yield shownContextPromise;
   1.146 +
   1.147 +  is(PanelUI.panel.state, "open", "The PanelUI should still be open.");
   1.148 +
   1.149 +  let expectedEntries = [
   1.150 +    [".customize-context-moveToToolbar", true],
   1.151 +    [".customize-context-removeFromPanel", true],
   1.152 +    ["---"],
   1.153 +    [".viewCustomizeToolbar", true]
   1.154 +  ];
   1.155 +  checkContextMenu(contextMenu, expectedEntries);
   1.156 +
   1.157 +  let hiddenContextPromise = popupHidden(contextMenu);
   1.158 +  contextMenu.hidePopup();
   1.159 +  yield hiddenContextPromise;
   1.160 +
   1.161 +  let hiddenPromise = promisePanelHidden(window);
   1.162 +  PanelUI.toggle({type: "command"});
   1.163 +  yield hiddenPromise;
   1.164 +});
   1.165 +
   1.166 +// Right-click on the home button while in customization mode
   1.167 +// should show a context menu with options to move it.
   1.168 +add_task(function() {
   1.169 +  yield startCustomizing();
   1.170 +  let contextMenu = document.getElementById("toolbar-context-menu");
   1.171 +  let shownPromise = popupShown(contextMenu);
   1.172 +  let homeButton = document.getElementById("wrapper-home-button");
   1.173 +  EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2});
   1.174 +  yield shownPromise;
   1.175 +
   1.176 +  let expectedEntries = [
   1.177 +    [".customize-context-moveToPanel", true],
   1.178 +    [".customize-context-removeFromToolbar", true],
   1.179 +    ["---"]
   1.180 +  ];
   1.181 +  if (!isOSX) {
   1.182 +    expectedEntries.push(["#toggle_toolbar-menubar", true]);
   1.183 +  }
   1.184 +  expectedEntries.push(
   1.185 +    ["#toggle_PersonalToolbar", true],
   1.186 +    ["---"],
   1.187 +    [".viewCustomizeToolbar", false]
   1.188 +  );
   1.189 +  checkContextMenu(contextMenu, expectedEntries);
   1.190 +
   1.191 +  let hiddenContextPromise = popupHidden(contextMenu);
   1.192 +  contextMenu.hidePopup();
   1.193 +  yield hiddenContextPromise;
   1.194 +});
   1.195 +
   1.196 +// Right-click on an item in the palette should
   1.197 +// show a context menu with options to move it.
   1.198 +add_task(function() {
   1.199 +  let contextMenu = document.getElementById("customizationPaletteItemContextMenu");
   1.200 +  let shownPromise = popupShown(contextMenu);
   1.201 +  let openFileButton = document.getElementById("wrapper-open-file-button");
   1.202 +  EventUtils.synthesizeMouse(openFileButton, 2, 2, {type: "contextmenu", button: 2});
   1.203 +  yield shownPromise;
   1.204 +
   1.205 +  let expectedEntries = [
   1.206 +    [".customize-context-addToToolbar", true],
   1.207 +    [".customize-context-addToPanel", true]
   1.208 +  ];
   1.209 +  checkContextMenu(contextMenu, expectedEntries);
   1.210 +
   1.211 +  let hiddenContextPromise = popupHidden(contextMenu);
   1.212 +  contextMenu.hidePopup();
   1.213 +  yield hiddenContextPromise;
   1.214 +});
   1.215 +
   1.216 +// Right-click on an item in the panel while in customization mode
   1.217 +// should show a context menu with options to move it.
   1.218 +add_task(function() {
   1.219 +  let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   1.220 +  let shownPromise = popupShown(contextMenu);
   1.221 +  let newWindowButton = document.getElementById("wrapper-new-window-button");
   1.222 +  EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
   1.223 +  yield shownPromise;
   1.224 +
   1.225 +  let expectedEntries = [
   1.226 +    [".customize-context-moveToToolbar", true],
   1.227 +    [".customize-context-removeFromPanel", true],
   1.228 +    ["---"],
   1.229 +    [".viewCustomizeToolbar", false]
   1.230 +  ];
   1.231 +  checkContextMenu(contextMenu, expectedEntries);
   1.232 +
   1.233 +  let hiddenContextPromise = popupHidden(contextMenu);
   1.234 +  contextMenu.hidePopup();
   1.235 +  yield hiddenContextPromise;
   1.236 +  yield endCustomizing();
   1.237 +});
   1.238 +
   1.239 +// Test the toolbarbutton panel context menu in customization mode
   1.240 +// without opening the panel before customization mode
   1.241 +add_task(function() {
   1.242 +  this.otherWin = yield openAndLoadWindow(null, true);
   1.243 +
   1.244 +  yield startCustomizing(this.otherWin);
   1.245 +
   1.246 +  let contextMenu = this.otherWin.document.getElementById("customizationPanelItemContextMenu");
   1.247 +  let shownPromise = popupShown(contextMenu);
   1.248 +  let newWindowButton = this.otherWin.document.getElementById("wrapper-new-window-button");
   1.249 +  EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}, this.otherWin);
   1.250 +  yield shownPromise;
   1.251 +
   1.252 +  let expectedEntries = [
   1.253 +    [".customize-context-moveToToolbar", true],
   1.254 +    [".customize-context-removeFromPanel", true],
   1.255 +    ["---"],
   1.256 +    [".viewCustomizeToolbar", false]
   1.257 +  ];
   1.258 +  checkContextMenu(contextMenu, expectedEntries, this.otherWin);
   1.259 +
   1.260 +  let hiddenContextPromise = popupHidden(contextMenu);
   1.261 +  contextMenu.hidePopup();
   1.262 +  yield hiddenContextPromise;
   1.263 +  yield endCustomizing(this.otherWin);
   1.264 +  yield promiseWindowClosed(this.otherWin);
   1.265 +  this.otherWin = null;
   1.266 +});
   1.267 +
   1.268 +// Bug 945191 - Combined buttons show wrong context menu options
   1.269 +// when they are in the toolbar.
   1.270 +add_task(function() {
   1.271 +  yield startCustomizing();
   1.272 +  let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   1.273 +  let shownPromise = popupShown(contextMenu);
   1.274 +  let zoomControls = document.getElementById("wrapper-zoom-controls");
   1.275 +  EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
   1.276 +  yield shownPromise;
   1.277 +  // Execute the command to move the item from the panel to the toolbar.
   1.278 +  contextMenu.childNodes[0].doCommand();
   1.279 +  let hiddenPromise = popupHidden(contextMenu);
   1.280 +  contextMenu.hidePopup();
   1.281 +  yield hiddenPromise;
   1.282 +  yield endCustomizing();
   1.283 +
   1.284 +  zoomControls = document.getElementById("zoom-controls");
   1.285 +  is(zoomControls.parentNode.id, "nav-bar-customization-target", "Zoom-controls should be on the nav-bar");
   1.286 +
   1.287 +  contextMenu = document.getElementById("toolbar-context-menu");
   1.288 +  shownPromise = popupShown(contextMenu);
   1.289 +  EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
   1.290 +  yield shownPromise;
   1.291 +
   1.292 +  let expectedEntries = [
   1.293 +    [".customize-context-moveToPanel", true],
   1.294 +    [".customize-context-removeFromToolbar", true],
   1.295 +    ["---"]
   1.296 +  ];
   1.297 +  if (!isOSX) {
   1.298 +    expectedEntries.push(["#toggle_toolbar-menubar", true]);
   1.299 +  }
   1.300 +  expectedEntries.push(
   1.301 +    ["#toggle_PersonalToolbar", true],
   1.302 +    ["---"],
   1.303 +    [".viewCustomizeToolbar", true]
   1.304 +  );
   1.305 +  checkContextMenu(contextMenu, expectedEntries);
   1.306 +
   1.307 +  hiddenPromise = popupHidden(contextMenu);
   1.308 +  contextMenu.hidePopup();
   1.309 +  yield hiddenPromise;
   1.310 +  yield resetCustomization();
   1.311 +});
   1.312 +
   1.313 +// Bug 947586 - After customization, panel items show wrong context menu options
   1.314 +add_task(function() {
   1.315 +  yield startCustomizing();
   1.316 +  yield endCustomizing();
   1.317 +
   1.318 +  yield PanelUI.show();
   1.319 +
   1.320 +  let contextMenu = document.getElementById("customizationPanelItemContextMenu");
   1.321 +  let shownContextPromise = popupShown(contextMenu);
   1.322 +  let newWindowButton = document.getElementById("new-window-button");
   1.323 +  ok(newWindowButton, "new-window-button was found");
   1.324 +  EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
   1.325 +  yield shownContextPromise;
   1.326 +
   1.327 +  is(PanelUI.panel.state, "open", "The PanelUI should still be open.");
   1.328 +
   1.329 +  let expectedEntries = [
   1.330 +    [".customize-context-moveToToolbar", true],
   1.331 +    [".customize-context-removeFromPanel", true],
   1.332 +    ["---"],
   1.333 +    [".viewCustomizeToolbar", true]
   1.334 +  ];
   1.335 +  checkContextMenu(contextMenu, expectedEntries);
   1.336 +
   1.337 +  let hiddenContextPromise = popupHidden(contextMenu);
   1.338 +  contextMenu.hidePopup();
   1.339 +  yield hiddenContextPromise;
   1.340 +
   1.341 +  let hiddenPromise = promisePanelHidden(window);
   1.342 +  PanelUI.hide();
   1.343 +  yield hiddenPromise;
   1.344 +});
   1.345 +
   1.346 +
   1.347 +// Bug 982027 - moving icon around removes custom context menu.
   1.348 +add_task(function() {
   1.349 +  let widgetId = "custom-context-menu-toolbarbutton";
   1.350 +  let expectedContext = "myfancycontext";
   1.351 +  let widget = createDummyXULButton(widgetId, "Test ctxt menu");
   1.352 +  widget.setAttribute("context", expectedContext);
   1.353 +  CustomizableUI.addWidgetToArea(widgetId, CustomizableUI.AREA_NAVBAR);
   1.354 +  is(widget.getAttribute("context"), expectedContext, "Should have context menu when added to the toolbar.");
   1.355 +
   1.356 +  yield startCustomizing();
   1.357 +  is(widget.getAttribute("context"), "", "Should not have own context menu in the toolbar now that we're customizing.");
   1.358 +  is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped when in toolbar.");
   1.359 +
   1.360 +  let panel = PanelUI.contents;
   1.361 +  simulateItemDrag(widget, panel);
   1.362 +  is(widget.getAttribute("context"), "", "Should not have own context menu when in the panel.");
   1.363 +  is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're in the panel.");
   1.364 +
   1.365 +  simulateItemDrag(widget, document.getElementById("nav-bar").customizationTarget);
   1.366 +  is(widget.getAttribute("context"), "", "Should not have own context menu when back in toolbar because we're still customizing.");
   1.367 +  is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're back in the toolbar.");
   1.368 +
   1.369 +  yield endCustomizing();
   1.370 +  is(widget.getAttribute("context"), expectedContext, "Should have context menu again now that we're out of customize mode.");
   1.371 +  CustomizableUI.removeWidgetFromArea(widgetId);
   1.372 +  widget.remove();
   1.373 +  ok(CustomizableUI.inDefaultState, "Should be in default state after removing button.");
   1.374 +});

mercurial