summaryrefslogtreecommitdiffstats
path: root/browser/components/uitour/test/browser_UITour_panel_close_annotation.js
blob: cff446573e5eac9054ec3b84fc551b98c99d5dbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that annotations disappear when their target is hidden.
 */

"use strict";

var gTestTab;
var gContentAPI;
var gContentWindow;
var highlight = document.getElementById("UITourHighlight");
var tooltip = document.getElementById("UITourTooltip");

function test() {
  registerCleanupFunction(() => {
    // Close the find bar in case it's open in the remaining tab
    gBrowser.getFindBar(gBrowser.selectedTab).close();
  });
  UITourTest();
}

var tests = [
  function test_highlight_move_outside_panel(done) {
    gContentAPI.showInfo("urlbar", "test title", "test text");
    gContentAPI.showHighlight("customize");
    waitForElementToBeVisible(highlight, function checkPanelIsOpen() {
      isnot(PanelUI.panel.state, "closed", "Panel should have opened");

      // Move the highlight outside which should close the app menu.
      gContentAPI.showHighlight("appMenu");
      waitForPopupAtAnchor(highlight.parentElement, document.getElementById("PanelUI-button"), () => {
        isnot(PanelUI.panel.state, "open",
              "Panel should have closed after the highlight moved elsewhere.");
        ok(tooltip.state == "showing" || tooltip.state == "open", "The info panel should have remained open");
        done();
      }, "Highlight should move to the appMenu button and still be visible");
    }, "Highlight should be shown after showHighlight() for fixed panel items");
  },

  function test_highlight_panel_hideMenu(done) {
    gContentAPI.showHighlight("customize");
    gContentAPI.showInfo("search", "test title", "test text");
    waitForElementToBeVisible(highlight, function checkPanelIsOpen() {
      isnot(PanelUI.panel.state, "closed", "Panel should have opened");

      // Close the app menu and make sure the highlight also disappeared.
      gContentAPI.hideMenu("appMenu");
      waitForElementToBeHidden(highlight, function checkPanelIsClosed() {
        isnot(PanelUI.panel.state, "open",
              "Panel still should have closed");
        ok(tooltip.state == "showing" || tooltip.state == "open", "The info panel should have remained open");
        done();
      }, "Highlight should have disappeared when panel closed");
    }, "Highlight should be shown after showHighlight() for fixed panel items");
  },

  function test_highlight_panel_click_find(done) {
    gContentAPI.showHighlight("help");
    gContentAPI.showInfo("searchIcon", "test title", "test text");
    waitForElementToBeVisible(highlight, function checkPanelIsOpen() {
      isnot(PanelUI.panel.state, "closed", "Panel should have opened");

      // Click the find button which should close the panel.
      let findButton = document.getElementById("find-button");
      EventUtils.synthesizeMouseAtCenter(findButton, {});
      waitForElementToBeHidden(highlight, function checkPanelIsClosed() {
        isnot(PanelUI.panel.state, "open",
              "Panel should have closed when the find bar opened");
        ok(tooltip.state == "showing" || tooltip.state == "open", "The info panel should have remained open");
        done();
      }, "Highlight should have disappeared when panel closed");
    }, "Highlight should be shown after showHighlight() for fixed panel items");
  },

  function test_highlight_info_panel_click_find(done) {
    gContentAPI.showHighlight("help");
    gContentAPI.showInfo("customize", "customize me!", "awesome!");
    waitForElementToBeVisible(highlight, function checkPanelIsOpen() {
      isnot(PanelUI.panel.state, "closed", "Panel should have opened");

      // Click the find button which should close the panel.
      let findButton = document.getElementById("find-button");
      EventUtils.synthesizeMouseAtCenter(findButton, {});
      waitForElementToBeHidden(highlight, function checkPanelIsClosed() {
        isnot(PanelUI.panel.state, "open",
              "Panel should have closed when the find bar opened");
        waitForElementToBeHidden(tooltip, function checkTooltipIsClosed() {
          isnot(tooltip.state, "open", "The info panel should have closed too");
          done();
        }, "Tooltip should hide with the menu");
      }, "Highlight should have disappeared when panel closed");
    }, "Highlight should be shown after showHighlight() for fixed panel items");
  },

  function test_highlight_panel_open_subview(done) {
    gContentAPI.showHighlight("customize");
    gContentAPI.showInfo("backForward", "test title", "test text");
    waitForElementToBeVisible(highlight, function checkPanelIsOpen() {
      isnot(PanelUI.panel.state, "closed", "Panel should have opened");

      // Click the help button which should open the subview in the panel menu.
      let helpButton = document.getElementById("PanelUI-help");
      EventUtils.synthesizeMouseAtCenter(helpButton, {});
      waitForElementToBeHidden(highlight, function highlightHidden() {
        is(PanelUI.panel.state, "open",
           "Panel should have stayed open when the subview opened");
        ok(tooltip.state == "showing" || tooltip.state == "open", "The info panel should have remained open");
        PanelUI.hide();
        done();
      }, "Highlight should have disappeared when the subview opened");
    }, "Highlight should be shown after showHighlight() for fixed panel items");
  },

  function test_info_panel_open_subview(done) {
    gContentAPI.showHighlight("urlbar");
    gContentAPI.showInfo("customize", "customize me!", "Open a subview");
    waitForElementToBeVisible(tooltip, function checkPanelIsOpen() {
      isnot(PanelUI.panel.state, "closed", "Panel should have opened");

      // Click the help button which should open the subview in the panel menu.
      let helpButton = document.getElementById("PanelUI-help");
      EventUtils.synthesizeMouseAtCenter(helpButton, {});
      waitForElementToBeHidden(tooltip, function tooltipHidden() {
        is(PanelUI.panel.state, "open",
           "Panel should have stayed open when the subview opened");
        is(highlight.parentElement.state, "open", "The highlight should have remained open");
        PanelUI.hide();
        done();
      }, "Tooltip should have disappeared when the subview opened");
    }, "Highlight should be shown after showHighlight() for fixed panel items");
  },

  function test_info_move_outside_panel(done) {
    gContentAPI.showInfo("addons", "test title", "test text");
    gContentAPI.showHighlight("urlbar");
    let addonsButton = document.getElementById("add-ons-button");
    waitForPopupAtAnchor(tooltip, addonsButton, function checkPanelIsOpen() {
      isnot(PanelUI.panel.state, "closed", "Panel should have opened");

      // Move the info panel outside which should close the app menu.
      gContentAPI.showInfo("appMenu", "Cool menu button", "It's three lines");
      waitForPopupAtAnchor(tooltip, document.getElementById("PanelUI-button"), () => {
        isnot(PanelUI.panel.state, "open",
              "Menu should have closed after the highlight moved elsewhere.");
        is(highlight.parentElement.state, "open", "The highlight should have remained visible");
        done();
      }, "Tooltip should move to the appMenu button and still be visible");
    }, "Tooltip should be shown after showInfo() for a panel item");
  },

];