summaryrefslogtreecommitdiffstats
path: root/toolkit/components/tooltiptext/tests/browser_shadow_dom_tooltip.js
blob: 50386e07e28866b07830a0bcc6368a4365b94def (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
154
155
156
157
158
159
160
161
162
163
164
165
166
/* eslint-disable mozilla/no-arbitrary-setTimeout */

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({ set: [["ui.tooltipDelay", 0]] });
});

add_task(async function test_title_in_shadow_dom() {
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);

  info("Moving mouse out of the way.");
  await EventUtils.synthesizeAndWaitNativeMouseMove(
    tab.linkedBrowser,
    300,
    300
  );

  info("creating host");
  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
    let doc = content.document;
    let host = doc.createElement("div");
    doc.body.appendChild(host);
    host.setAttribute("style", "position: absolute; top: 0; left: 0;");
    var sr = host.attachShadow({ mode: "closed" });
    sr.innerHTML =
      "<div title='shadow' style='width: 200px; height: 200px;'>shadow</div>";
  });

  let awaitTooltipOpen = new Promise(resolve => {
    let tooltipId = Services.appinfo.browserTabsRemoteAutostart
      ? "remoteBrowserTooltip"
      : "aHTMLTooltip";
    let tooltip = document.getElementById(tooltipId);
    tooltip.addEventListener(
      "popupshown",
      function (event) {
        resolve(event.target);
      },
      { once: true }
    );
  });
  info("Initial mouse move");
  await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 50, 5);
  info("Waiting");
  await new Promise(resolve => setTimeout(resolve, 400));
  info("Second mouse move");
  await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 70, 5);
  info("Waiting for tooltip to open");
  let tooltip = await awaitTooltipOpen;

  is(
    tooltip.getAttribute("label"),
    "shadow",
    "tooltip label should match expectation"
  );

  info("Closing tab");
  BrowserTestUtils.removeTab(tab);
});

add_task(async function test_title_in_light_dom() {
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);

  info("Moving mouse out of the way.");
  await EventUtils.synthesizeAndWaitNativeMouseMove(
    tab.linkedBrowser,
    300,
    300
  );

  info("creating host");
  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
    let doc = content.document;
    let host = doc.createElement("div");
    host.title = "light";
    doc.body.appendChild(host);
    host.setAttribute("style", "position: absolute; top: 0; left: 0;");
    var sr = host.attachShadow({ mode: "closed" });
    sr.innerHTML = "<div style='width: 200px; height: 200px;'>shadow</div>";
  });

  let awaitTooltipOpen = new Promise(resolve => {
    let tooltipId = Services.appinfo.browserTabsRemoteAutostart
      ? "remoteBrowserTooltip"
      : "aHTMLTooltip";
    let tooltip = document.getElementById(tooltipId);
    tooltip.addEventListener(
      "popupshown",
      function (event) {
        resolve(event.target);
      },
      { once: true }
    );
  });
  info("Initial mouse move");
  await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 50, 5);
  info("Waiting");
  await new Promise(resolve => setTimeout(resolve, 400));
  info("Second mouse move");
  await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 70, 5);
  info("Waiting for tooltip to open");
  let tooltip = await awaitTooltipOpen;

  is(
    tooltip.getAttribute("label"),
    "light",
    "tooltip label should match expectation"
  );

  info("Closing tab");
  BrowserTestUtils.removeTab(tab);
});

add_task(async function test_title_through_slot() {
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);

  info("Moving mouse out of the way.");
  await EventUtils.synthesizeAndWaitNativeMouseMove(
    tab.linkedBrowser,
    300,
    300
  );

  info("creating host");
  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
    let doc = content.document;
    let host = doc.createElement("div");
    host.title = "light";
    host.innerHTML = "<div style='width: 200px; height: 200px;'>light</div>";
    doc.body.appendChild(host);
    host.setAttribute("style", "position: absolute; top: 0; left: 0;");
    var sr = host.attachShadow({ mode: "closed" });
    sr.innerHTML =
      "<div title='shadow' style='width: 200px; height: 200px;'><slot></slot></div>";
  });

  let awaitTooltipOpen = new Promise(resolve => {
    let tooltipId = Services.appinfo.browserTabsRemoteAutostart
      ? "remoteBrowserTooltip"
      : "aHTMLTooltip";
    let tooltip = document.getElementById(tooltipId);
    tooltip.addEventListener(
      "popupshown",
      function (event) {
        resolve(event.target);
      },
      { once: true }
    );
  });
  info("Initial mouse move");
  await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 50, 5);
  info("Waiting");
  await new Promise(resolve => setTimeout(resolve, 400));
  info("Second mouse move");
  await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 70, 5);
  info("Waiting for tooltip to open");
  let tooltip = await awaitTooltipOpen;

  is(
    tooltip.getAttribute("label"),
    "shadow",
    "tooltip label should match expectation"
  );

  info("Closing tab");
  BrowserTestUtils.removeTab(tab);
});