summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_UrlbarInput_tooltip.js
blob: 5ecb5e7a90d4fcf0dfdc8e570e02dac3b93f986f (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

function synthesizeMouseOver(element) {
  info("synthesize mouseover");
  let promise = BrowserTestUtils.waitForEvent(element, "mouseover");
  EventUtils.synthesizeMouseAtCenter(document.documentElement, {
    type: "mouseout",
  });
  EventUtils.synthesizeMouseAtCenter(element, { type: "mouseover" });
  EventUtils.synthesizeMouseAtCenter(element, { type: "mousemove" });
  return promise;
}

function synthesizeMouseOut(element) {
  info("synthesize mouseout");
  let promise = BrowserTestUtils.waitForEvent(element, "mouseout");
  EventUtils.synthesizeMouseAtCenter(element, { type: "mouseover" });
  EventUtils.synthesizeMouseAtCenter(element, { type: "mouseout" });
  EventUtils.synthesizeMouseAtCenter(document.documentElement, {
    type: "mousemove",
  });
  return promise;
}

async function expectTooltip(text) {
  if (!gURLBar._overflowing && !gURLBar._inOverflow) {
    info("waiting for overflow event");
    await BrowserTestUtils.waitForEvent(gURLBar.inputField, "overflow");
  }

  let tooltip = document.getElementById("aHTMLTooltip");
  let element = gURLBar.inputField;

  let popupShownPromise = BrowserTestUtils.waitForEvent(tooltip, "popupshown");
  await synthesizeMouseOver(element);
  info("awaiting for tooltip popup");
  await popupShownPromise;

  is(element.getAttribute("title"), text, "title attribute has expected text");
  is(tooltip.textContent, text, "tooltip shows expected text");

  await synthesizeMouseOut(element);
}

async function expectNoTooltip() {
  if (gURLBar._overflowing || gURLBar._inOverflow) {
    info("waiting for underflow event");
    await BrowserTestUtils.waitForEvent(gURLBar.inputField, "underflow");
  }

  let element = gURLBar.inputField;
  await synthesizeMouseOver(element);

  is(element.getAttribute("title"), null, "title attribute shouldn't be set");

  await synthesizeMouseOut(element);
}

add_task(async function () {
  window.windowUtils.disableNonTestMouseEvents(true);
  registerCleanupFunction(() => {
    window.windowUtils.disableNonTestMouseEvents(false);
  });

  // Ensure the URL bar is neither focused nor hovered before we start.
  gBrowser.selectedBrowser.focus();
  await synthesizeMouseOut(gURLBar.inputField);

  gURLBar.value = "short string";
  await expectNoTooltip();

  let longURL = "http://longurl.com/" + "foobar/".repeat(30);
  gURLBar.value = longURL;
  is(
    gURLBar.inputField.value,
    longURL.replace(/^http:\/\//, ""),
    "Urlbar value has http:// stripped"
  );
  await expectTooltip(longURL);
});