tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_form_validity_popup_submit.js (1893B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 "use strict";
      7 
      8 async function promiseValidityPopupShown() {
      9  await BrowserTestUtils.waitForEvent(
     10    window,
     11    "popupshown",
     12    /* capture = */ false,
     13    event => event.target.id == "invalid-form-popup"
     14  );
     15  return document.getElementById("invalid-form-popup");
     16 }
     17 
     18 const HTML = `
     19  <form action="">
     20    <input name="text" type="text" placeholder="type here" autofocus required>
     21    <input id="submit" type="submit">
     22  </form>
     23 `;
     24 
     25 add_setup(async function () {
     26  await SpecialPowers.pushPrefEnv({
     27    set: [["test.wait300msAfterTabSwitch", true]],
     28  });
     29 });
     30 
     31 add_task(async function bug_1790128() {
     32  await BrowserTestUtils.withNewTab(
     33    {
     34      gBrowser,
     35      url: `data:text/html,${encodeURI(HTML)}`,
     36    },
     37    async function (aBrowser) {
     38      let promisePopupShown = promiseValidityPopupShown();
     39      await BrowserTestUtils.synthesizeMouseAtCenter("#submit", {}, aBrowser);
     40      let popup = await promisePopupShown;
     41      is(popup.state, "open", "Should be open");
     42 
     43      let promisePopupHidden = BrowserTestUtils.waitForEvent(
     44        popup,
     45        "popuphidden"
     46      );
     47      promisePopupShown = promiseValidityPopupShown();
     48 
     49      // This is written in a rather odd style because depending on whether
     50      // panel animations are enabled we might be able to show the popup again
     51      // after the first click or not. The point is that after one click the
     52      // popup should've hid at least once, and after two the popup should've
     53      // open again at least once.
     54      await BrowserTestUtils.synthesizeMouseAtCenter("#submit", {}, aBrowser);
     55      await promisePopupHidden;
     56      await BrowserTestUtils.synthesizeMouseAtCenter("#submit", {}, aBrowser);
     57      await promisePopupShown;
     58      ok(true, "Should've shown the popup again");
     59    }
     60  );
     61 });