summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/forms/head.js
blob: 1629c6a57c90a3d289292448a829e995e353376a (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
async function openSelectPopup(
  mode = "key",
  selector = "select",
  win = window
) {
  info("Opening select popup");
  let popupShownPromise = BrowserTestUtils.waitForSelectPopupShown(win);
  if (mode == "click" || mode == "mousedown") {
    let mousePromise;
    if (mode == "click") {
      mousePromise = BrowserTestUtils.synthesizeMouseAtCenter(
        selector,
        {},
        win.gBrowser.selectedBrowser
      );
    } else {
      mousePromise = BrowserTestUtils.synthesizeMouse(
        selector,
        5,
        5,
        { type: "mousedown" },
        win.gBrowser.selectedBrowser
      );
    }
    await mousePromise;
  } else {
    EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true }, win);
  }
  return popupShownPromise;
}

function hideSelectPopup(mode = "enter", win = window) {
  let browser = win.gBrowser.selectedBrowser;
  let selectClosedPromise = SpecialPowers.spawn(browser, [], async function () {
    let { SelectContentHelper } = ChromeUtils.importESModule(
      "resource://gre/actors/SelectChild.sys.mjs"
    );
    return ContentTaskUtils.waitForCondition(() => !SelectContentHelper.open);
  });

  if (mode == "escape") {
    EventUtils.synthesizeKey("KEY_Escape", {}, win);
  } else if (mode == "enter") {
    EventUtils.synthesizeKey("KEY_Enter", {}, win);
  } else if (mode == "click") {
    let popup = win.document.getElementById("ContentSelectDropdown").menupopup;
    EventUtils.synthesizeMouseAtCenter(popup.lastElementChild, {}, win);
  }

  return selectClosedPromise;
}