summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/forms/browser_selectpopup_showPicker.js
blob: 9c978cb41154c554bdd9972589c802381bd1c8c6 (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
const PAGE = `
<!doctype html>
<select>
  <option>ABC</option>
  <option>DEFG</option>
</select>
`;

add_task(async function test_showPicker() {
  const url = "data:text/html," + encodeURI(PAGE);
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url,
    },
    async function (browser) {
      let popupShownPromise = BrowserTestUtils.waitForSelectPopupShown(window);

      await SpecialPowers.spawn(browser, [], async function () {
        content.document.notifyUserGestureActivation();
        content.document.querySelector("select").showPicker();
      });

      let selectPopup = await popupShownPromise;
      is(
        selectPopup.state,
        "open",
        "select popup is open after calling showPicker"
      );
    }
  );
});

add_task(async function test_showPicker_alreadyOpen() {
  const url = "data:text/html," + encodeURI(PAGE);
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url,
    },
    async function (browser) {
      let selectPopup = await openSelectPopup("click");

      await SpecialPowers.spawn(browser, [], async function () {
        content.document.notifyUserGestureActivation();
        content.document.querySelector("select").showPicker();
      });

      // Wait some time for potential (unwanted) closing.
      // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
      await new Promise(resolve => setTimeout(resolve, 100));

      is(
        selectPopup.state,
        "open",
        "select popup is still open after calling showPicker"
      );
    }
  );
});