browser/components/customizableui/test/browser_940307_panel_click_closure_handling.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_940307_panel_click_closure_handling.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     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 +let button, menuButton;
    1.11 +/* Clicking a button should close the panel */
    1.12 +add_task(function() {
    1.13 +  button = document.createElement("toolbarbutton");
    1.14 +  button.id = "browser_940307_button";
    1.15 +  button.setAttribute("label", "Button");
    1.16 +  PanelUI.contents.appendChild(button);
    1.17 +  yield PanelUI.show();
    1.18 +  let hiddenAgain = promisePanelHidden(window);
    1.19 +  EventUtils.synthesizeMouseAtCenter(button, {});
    1.20 +  yield hiddenAgain;
    1.21 +  button.remove();
    1.22 +});
    1.23 +
    1.24 +/* Clicking a menu button should close the panel, opening the popup shouldn't.  */
    1.25 +add_task(function() {
    1.26 +  menuButton = document.createElement("toolbarbutton");
    1.27 +  menuButton.setAttribute("type", "menu-button");
    1.28 +  menuButton.id = "browser_940307_menubutton";
    1.29 +  menuButton.setAttribute("label", "Menu button");
    1.30 +
    1.31 +  let menuPopup = document.createElement("menupopup");
    1.32 +  menuPopup.id = "browser_940307_menupopup";
    1.33 +
    1.34 +  let menuItem = document.createElement("menuitem");
    1.35 +  menuItem.setAttribute("label", "Menu item");
    1.36 +  menuItem.id = "browser_940307_menuitem";
    1.37 +
    1.38 +  menuPopup.appendChild(menuItem);
    1.39 +  menuButton.appendChild(menuPopup);
    1.40 +  PanelUI.contents.appendChild(menuButton);
    1.41 +
    1.42 +  yield PanelUI.show();
    1.43 +  let hiddenAgain = promisePanelHidden(window);
    1.44 +  let innerButton = document.getAnonymousElementByAttribute(menuButton, "anonid", "button");
    1.45 +  EventUtils.synthesizeMouseAtCenter(innerButton, {});
    1.46 +  yield hiddenAgain;
    1.47 +
    1.48 +  // Now click the dropmarker to show the menu
    1.49 +  yield PanelUI.show();
    1.50 +  hiddenAgain = promisePanelHidden(window);
    1.51 +  let menuShown = promisePanelElementShown(window, menuPopup);
    1.52 +  let dropmarker = document.getAnonymousElementByAttribute(menuButton, "type", "menu-button");
    1.53 +  EventUtils.synthesizeMouseAtCenter(dropmarker, {});
    1.54 +  yield menuShown;
    1.55 +  // Panel should stay open:
    1.56 +  ok(isPanelUIOpen(), "Panel should still be open");
    1.57 +  let menuHidden = promisePanelElementHidden(window, menuPopup);
    1.58 +  // Then click the menu item to close all the things
    1.59 +  EventUtils.synthesizeMouseAtCenter(menuItem, {});
    1.60 +  yield menuHidden;
    1.61 +  yield hiddenAgain;
    1.62 +  menuButton.remove();
    1.63 +});
    1.64 +
    1.65 +add_task(function() {
    1.66 +  let searchbar = document.getElementById("searchbar");
    1.67 +  gCustomizeMode.addToPanel(searchbar);
    1.68 +  let placement = CustomizableUI.getPlacementOfWidget("search-container");
    1.69 +  is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
    1.70 +  yield PanelUI.show();
    1.71 +  yield waitForCondition(() => "value" in searchbar && searchbar.value === "");
    1.72 +
    1.73 +  searchbar.value = "foo";
    1.74 +  searchbar.focus();
    1.75 +  // Reaching into this context menu is pretty evil, but hey... it's a test.
    1.76 +  let textbox = document.getAnonymousElementByAttribute(searchbar.textbox, "anonid", "textbox-input-box");
    1.77 +  let contextmenu = document.getAnonymousElementByAttribute(textbox, "anonid", "input-box-contextmenu");
    1.78 +  let contextMenuShown = promisePanelElementShown(window, contextmenu);
    1.79 +  EventUtils.synthesizeMouseAtCenter(searchbar, {type: "contextmenu", button: 2});
    1.80 +  yield contextMenuShown;
    1.81 +
    1.82 +  ok(isPanelUIOpen(), "Panel should still be open");
    1.83 +
    1.84 +  let selectAll = contextmenu.querySelector("[cmd='cmd_selectAll']");
    1.85 +  let contextMenuHidden = promisePanelElementHidden(window, contextmenu);
    1.86 +  EventUtils.synthesizeMouseAtCenter(selectAll, {});
    1.87 +  yield contextMenuHidden;
    1.88 +
    1.89 +  ok(isPanelUIOpen(), "Panel should still be open");
    1.90 +
    1.91 +  let hiddenPanelPromise = promisePanelHidden(window);
    1.92 +  EventUtils.synthesizeKey("VK_ESCAPE", {});
    1.93 +  yield hiddenPanelPromise;
    1.94 +  ok(!isPanelUIOpen(), "Panel should no longer be open");
    1.95 +});
    1.96 +
    1.97 +registerCleanupFunction(function() {
    1.98 +  if (button && button.parentNode) {
    1.99 +    button.remove();
   1.100 +  }
   1.101 +  if (menuButton && menuButton.parentNode) {
   1.102 +    menuButton.remove();
   1.103 +  }
   1.104 +  // Sadly this isn't task.jsm-enabled, so we can't wait for this to happen. But we should
   1.105 +  // definitely close it here and hope it won't interfere with other tests.
   1.106 +  // Of course, all the tests are meant to do this themselves, but if they fail...
   1.107 +  if (isPanelUIOpen()) {
   1.108 +    PanelUI.hide();
   1.109 +  }
   1.110 +});
   1.111 +

mercurial