tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_UITour_panel_close_annotation.js (7564B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Tests that annotations disappear when their target is hidden.
      6 */
      7 
      8 "use strict";
      9 
     10 var gTestTab;
     11 var gContentAPI;
     12 var highlight = UITour.getHighlightContainerAndMaybeCreate(document);
     13 var tooltip = UITour.getTooltipAndMaybeCreate(document);
     14 
     15 function test() {
     16  registerCleanupFunction(() => {
     17    // Close the find bar in case it's open in the remaining tab
     18    let findBar = gBrowser.getCachedFindBar(gBrowser.selectedTab);
     19    if (findBar) {
     20      findBar.close();
     21    }
     22  });
     23  UITourTest();
     24 }
     25 
     26 var tests = [
     27  function test_highlight_move_outside_panel(done) {
     28    gContentAPI.showInfo("urlbar", "test title", "test text");
     29    gContentAPI.showHighlight("addons");
     30    waitForElementToBeVisible(
     31      highlight,
     32      function checkPanelIsOpen() {
     33        isnot(PanelUI.panel.state, "closed", "Panel should have opened");
     34 
     35        // Move the highlight outside which should close the app menu.
     36        gContentAPI.showHighlight("appMenu");
     37        waitForPopupAtAnchor(
     38          highlight.parentElement,
     39          document.getElementById("PanelUI-button"),
     40          () => {
     41            isnot(
     42              PanelUI.panel.state,
     43              "open",
     44              "Panel should have closed after the highlight moved elsewhere."
     45            );
     46            ok(
     47              tooltip.state == "showing" || tooltip.state == "open",
     48              "The info panel should have remained open"
     49            );
     50            done();
     51          },
     52          "Highlight should move to the appMenu button and still be visible"
     53        );
     54      },
     55      "Highlight should be shown after showHighlight() for fixed panel items"
     56    );
     57  },
     58 
     59  function test_highlight_panel_hideMenu(done) {
     60    gContentAPI.showHighlight("addons");
     61    gContentAPI.showInfo("search", "test title", "test text");
     62    waitForElementToBeVisible(
     63      highlight,
     64      function checkPanelIsOpen() {
     65        isnot(PanelUI.panel.state, "closed", "Panel should have opened");
     66 
     67        // Close the app menu and make sure the highlight also disappeared.
     68        gContentAPI.hideMenu("appMenu");
     69        waitForElementToBeHidden(
     70          highlight,
     71          function checkPanelIsClosed() {
     72            isnot(
     73              PanelUI.panel.state,
     74              "open",
     75              "Panel still should have closed"
     76            );
     77            ok(
     78              tooltip.state == "showing" || tooltip.state == "open",
     79              "The info panel should have remained open"
     80            );
     81            done();
     82          },
     83          "Highlight should have disappeared when panel closed"
     84        );
     85      },
     86      "Highlight should be shown after showHighlight() for fixed panel items"
     87    );
     88  },
     89 
     90  function test_highlight_panel_click_find(done) {
     91    gContentAPI.showHighlight("help");
     92    gContentAPI.showInfo("searchIcon", "test title", "test text");
     93    waitForElementToBeVisible(
     94      highlight,
     95      function checkPanelIsOpen() {
     96        isnot(PanelUI.panel.state, "closed", "Panel should have opened");
     97 
     98        // Click the find button which should close the panel.
     99        let findButton = document.getElementById("find-button");
    100        EventUtils.synthesizeMouseAtCenter(findButton, {});
    101        waitForElementToBeHidden(
    102          highlight,
    103          function checkPanelIsClosed() {
    104            isnot(
    105              PanelUI.panel.state,
    106              "open",
    107              "Panel should have closed when the find bar opened"
    108            );
    109            ok(
    110              tooltip.state == "showing" || tooltip.state == "open",
    111              "The info panel should have remained open"
    112            );
    113            done();
    114          },
    115          "Highlight should have disappeared when panel closed"
    116        );
    117      },
    118      "Highlight should be shown after showHighlight() for fixed panel items"
    119    );
    120  },
    121 
    122  function test_highlight_info_panel_click_find(done) {
    123    gContentAPI.showHighlight("help");
    124    gContentAPI.showInfo("addons", "Add addons!", "awesome!");
    125    waitForElementToBeVisible(
    126      highlight,
    127      function checkPanelIsOpen() {
    128        isnot(PanelUI.panel.state, "closed", "Panel should have opened");
    129 
    130        // Click the find button which should close the panel.
    131        let findButton = document.getElementById("find-button");
    132        EventUtils.synthesizeMouseAtCenter(findButton, {});
    133        waitForElementToBeHidden(
    134          highlight,
    135          function checkPanelIsClosed() {
    136            isnot(
    137              PanelUI.panel.state,
    138              "open",
    139              "Panel should have closed when the find bar opened"
    140            );
    141            waitForElementToBeHidden(
    142              tooltip,
    143              function checkTooltipIsClosed() {
    144                isnot(
    145                  tooltip.state,
    146                  "open",
    147                  "The info panel should have closed too"
    148                );
    149                done();
    150              },
    151              "Tooltip should hide with the menu"
    152            );
    153          },
    154          "Highlight should have disappeared when panel closed"
    155        );
    156      },
    157      "Highlight should be shown after showHighlight() for fixed panel items"
    158    );
    159  },
    160 
    161  function test_highlight_panel_open_subview(done) {
    162    gContentAPI.showHighlight("addons");
    163    gContentAPI.showInfo("backForward", "test title", "test text");
    164    waitForElementToBeVisible(
    165      highlight,
    166      function checkPanelIsOpen() {
    167        isnot(PanelUI.panel.state, "closed", "Panel should have opened");
    168 
    169        // Click the help button which should open the subview in the panel menu.
    170        let helpButton = document.getElementById("PanelUI-help");
    171        EventUtils.synthesizeMouseAtCenter(helpButton, {});
    172        waitForElementToBeHidden(
    173          highlight,
    174          function highlightHidden() {
    175            is(
    176              PanelUI.panel.state,
    177              "open",
    178              "Panel should have stayed open when the subview opened"
    179            );
    180            ok(
    181              tooltip.state == "showing" || tooltip.state == "open",
    182              "The info panel should have remained open"
    183            );
    184            PanelUI.hide();
    185            done();
    186          },
    187          "Highlight should have disappeared when the subview opened"
    188        );
    189      },
    190      "Highlight should be shown after showHighlight() for fixed panel items"
    191    );
    192  },
    193 
    194  function test_info_panel_open_subview(done) {
    195    gContentAPI.showHighlight("urlbar");
    196    gContentAPI.showInfo("addons", "Add addons!", "Open a subview");
    197    waitForElementToBeVisible(
    198      tooltip,
    199      function checkPanelIsOpen() {
    200        isnot(PanelUI.panel.state, "closed", "Panel should have opened");
    201 
    202        // Click the help button which should open the subview in the panel menu.
    203        let helpButton = document.getElementById("PanelUI-help");
    204        EventUtils.synthesizeMouseAtCenter(helpButton, {});
    205        waitForElementToBeHidden(
    206          tooltip,
    207          function tooltipHidden() {
    208            is(
    209              PanelUI.panel.state,
    210              "open",
    211              "Panel should have stayed open when the subview opened"
    212            );
    213            is(
    214              highlight.parentElement.state,
    215              "open",
    216              "The highlight should have remained open"
    217            );
    218            PanelUI.hide();
    219            done();
    220          },
    221          "Tooltip should have disappeared when the subview opened"
    222        );
    223      },
    224      "Highlight should be shown after showHighlight() for fixed panel items"
    225    );
    226  },
    227 ];