tor-browser

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

browser_selectpopup_showPicker.js (1684B)


      1 const PAGE = `
      2 <!doctype html>
      3 <select>
      4  <option>ABC</option>
      5  <option>DEFG</option>
      6 </select>
      7 `;
      8 
      9 add_setup(async function () {
     10  await SpecialPowers.pushPrefEnv({
     11    set: [["test.wait300msAfterTabSwitch", true]],
     12  });
     13 });
     14 
     15 add_task(async function test_showPicker() {
     16  const url = "data:text/html," + encodeURI(PAGE);
     17  await BrowserTestUtils.withNewTab(
     18    {
     19      gBrowser,
     20      url,
     21    },
     22    async function (browser) {
     23      let popupShownPromise = BrowserTestUtils.waitForSelectPopupShown(window);
     24 
     25      await SpecialPowers.spawn(browser, [], async function () {
     26        content.document.notifyUserGestureActivation();
     27        content.document.querySelector("select").showPicker();
     28      });
     29 
     30      let selectPopup = await popupShownPromise;
     31      is(
     32        selectPopup.state,
     33        "open",
     34        "select popup is open after calling showPicker"
     35      );
     36    }
     37  );
     38 });
     39 
     40 add_task(async function test_showPicker_alreadyOpen() {
     41  const url = "data:text/html," + encodeURI(PAGE);
     42  await BrowserTestUtils.withNewTab(
     43    {
     44      gBrowser,
     45      url,
     46    },
     47    async function (browser) {
     48      let selectPopup = await openSelectPopup("click");
     49 
     50      await SpecialPowers.spawn(browser, [], async function () {
     51        content.document.notifyUserGestureActivation();
     52        content.document.querySelector("select").showPicker();
     53      });
     54 
     55      // Wait some time for potential (unwanted) closing.
     56      // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     57      await new Promise(resolve => setTimeout(resolve, 100));
     58 
     59      is(
     60        selectPopup.state,
     61        "open",
     62        "select popup is still open after calling showPicker"
     63      );
     64    }
     65  );
     66 });