summaryrefslogtreecommitdiffstats
path: root/dom/base/test/browser_form_validity_popup_submit.js
blob: 2cefbf9d98be9acac974ebb38792f22cee412e7c (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

"use strict";

async function promiseValidityPopupShown() {
  await BrowserTestUtils.waitForEvent(
    window,
    "popupshown",
    /* capture = */ false,
    event => event.target.id == "invalid-form-popup"
  );
  return document.getElementById("invalid-form-popup");
}

const HTML = `
  <form action="">
    <input name="text" type="text" placeholder="type here" autofocus required>
    <input id="submit" type="submit">
  </form>
`;

add_task(async function bug_1790128() {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: `data:text/html,${encodeURI(HTML)}`,
    },
    async function (aBrowser) {
      let promisePopupShown = promiseValidityPopupShown();
      await BrowserTestUtils.synthesizeMouseAtCenter("#submit", {}, aBrowser);
      let popup = await promisePopupShown;
      is(popup.state, "open", "Should be open");

      let promisePopupHidden = BrowserTestUtils.waitForEvent(
        popup,
        "popuphidden"
      );
      promisePopupShown = promiseValidityPopupShown();

      // This is written in a rather odd style because depending on whether
      // panel animations are enabled we might be able to show the popup again
      // after the first click or not. The point is that after one click the
      // popup should've hid at least once, and after two the popup should've
      // open again at least once.
      await BrowserTestUtils.synthesizeMouseAtCenter("#submit", {}, aBrowser);
      await promisePopupHidden;
      await BrowserTestUtils.synthesizeMouseAtCenter("#submit", {}, aBrowser);
      await promisePopupShown;
      ok(true, "Should've shown the popup again");
    }
  );
});