browser/components/customizableui/test/browser_940307_panel_click_closure_handling.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 let button, menuButton;
     8 /* Clicking a button should close the panel */
     9 add_task(function() {
    10   button = document.createElement("toolbarbutton");
    11   button.id = "browser_940307_button";
    12   button.setAttribute("label", "Button");
    13   PanelUI.contents.appendChild(button);
    14   yield PanelUI.show();
    15   let hiddenAgain = promisePanelHidden(window);
    16   EventUtils.synthesizeMouseAtCenter(button, {});
    17   yield hiddenAgain;
    18   button.remove();
    19 });
    21 /* Clicking a menu button should close the panel, opening the popup shouldn't.  */
    22 add_task(function() {
    23   menuButton = document.createElement("toolbarbutton");
    24   menuButton.setAttribute("type", "menu-button");
    25   menuButton.id = "browser_940307_menubutton";
    26   menuButton.setAttribute("label", "Menu button");
    28   let menuPopup = document.createElement("menupopup");
    29   menuPopup.id = "browser_940307_menupopup";
    31   let menuItem = document.createElement("menuitem");
    32   menuItem.setAttribute("label", "Menu item");
    33   menuItem.id = "browser_940307_menuitem";
    35   menuPopup.appendChild(menuItem);
    36   menuButton.appendChild(menuPopup);
    37   PanelUI.contents.appendChild(menuButton);
    39   yield PanelUI.show();
    40   let hiddenAgain = promisePanelHidden(window);
    41   let innerButton = document.getAnonymousElementByAttribute(menuButton, "anonid", "button");
    42   EventUtils.synthesizeMouseAtCenter(innerButton, {});
    43   yield hiddenAgain;
    45   // Now click the dropmarker to show the menu
    46   yield PanelUI.show();
    47   hiddenAgain = promisePanelHidden(window);
    48   let menuShown = promisePanelElementShown(window, menuPopup);
    49   let dropmarker = document.getAnonymousElementByAttribute(menuButton, "type", "menu-button");
    50   EventUtils.synthesizeMouseAtCenter(dropmarker, {});
    51   yield menuShown;
    52   // Panel should stay open:
    53   ok(isPanelUIOpen(), "Panel should still be open");
    54   let menuHidden = promisePanelElementHidden(window, menuPopup);
    55   // Then click the menu item to close all the things
    56   EventUtils.synthesizeMouseAtCenter(menuItem, {});
    57   yield menuHidden;
    58   yield hiddenAgain;
    59   menuButton.remove();
    60 });
    62 add_task(function() {
    63   let searchbar = document.getElementById("searchbar");
    64   gCustomizeMode.addToPanel(searchbar);
    65   let placement = CustomizableUI.getPlacementOfWidget("search-container");
    66   is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
    67   yield PanelUI.show();
    68   yield waitForCondition(() => "value" in searchbar && searchbar.value === "");
    70   searchbar.value = "foo";
    71   searchbar.focus();
    72   // Reaching into this context menu is pretty evil, but hey... it's a test.
    73   let textbox = document.getAnonymousElementByAttribute(searchbar.textbox, "anonid", "textbox-input-box");
    74   let contextmenu = document.getAnonymousElementByAttribute(textbox, "anonid", "input-box-contextmenu");
    75   let contextMenuShown = promisePanelElementShown(window, contextmenu);
    76   EventUtils.synthesizeMouseAtCenter(searchbar, {type: "contextmenu", button: 2});
    77   yield contextMenuShown;
    79   ok(isPanelUIOpen(), "Panel should still be open");
    81   let selectAll = contextmenu.querySelector("[cmd='cmd_selectAll']");
    82   let contextMenuHidden = promisePanelElementHidden(window, contextmenu);
    83   EventUtils.synthesizeMouseAtCenter(selectAll, {});
    84   yield contextMenuHidden;
    86   ok(isPanelUIOpen(), "Panel should still be open");
    88   let hiddenPanelPromise = promisePanelHidden(window);
    89   EventUtils.synthesizeKey("VK_ESCAPE", {});
    90   yield hiddenPanelPromise;
    91   ok(!isPanelUIOpen(), "Panel should no longer be open");
    92 });
    94 registerCleanupFunction(function() {
    95   if (button && button.parentNode) {
    96     button.remove();
    97   }
    98   if (menuButton && menuButton.parentNode) {
    99     menuButton.remove();
   100   }
   101   // Sadly this isn't task.jsm-enabled, so we can't wait for this to happen. But we should
   102   // definitely close it here and hope it won't interfere with other tests.
   103   // Of course, all the tests are meant to do this themselves, but if they fail...
   104   if (isPanelUIOpen()) {
   105     PanelUI.hide();
   106   }
   107 });

mercurial