tor-browser

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

browser_selectpopup_user_input.js (2953B)


      1 const PAGE = `
      2 <!doctype html>
      3 <select>
      4  <option>ABC</option>
      5  <option>DEFG</option>
      6 </select>
      7 `;
      8 
      9 function promiseChangeHandlingUserInput(browser) {
     10  return SpecialPowers.spawn(browser, [], async function () {
     11    content.document.clearUserGestureActivation();
     12    let element = content.document.querySelector("select");
     13    let reply = {};
     14    function getUserInputState() {
     15      return {
     16        isHandlingUserInput: content.window.windowUtils.isHandlingUserInput,
     17        hasValidTransientUserGestureActivation:
     18          content.document.hasValidTransientUserGestureActivation,
     19      };
     20    }
     21    reply.before = getUserInputState();
     22    await ContentTaskUtils.waitForEvent(element, "change", false, () => {
     23      reply.during = getUserInputState();
     24      return true;
     25    });
     26    await new Promise(r => content.window.setTimeout(r));
     27    reply.after = getUserInputState();
     28    return reply;
     29  });
     30 }
     31 
     32 async function testHandlingUserInputOnChange(aTriggerFn) {
     33  const url = "data:text/html," + encodeURI(PAGE);
     34  return BrowserTestUtils.withNewTab(
     35    {
     36      gBrowser,
     37      url,
     38    },
     39    async function (browser) {
     40      let popup = await openSelectPopup("click");
     41      let userInputOnChange = promiseChangeHandlingUserInput(browser);
     42      await aTriggerFn(popup);
     43      let userInput = await userInputOnChange;
     44      ok(
     45        !userInput.before.isHandlingUserInput,
     46        "Shouldn't be handling user input before test"
     47      );
     48      ok(
     49        !userInput.before.hasValidTransientUserGestureActivation,
     50        "transient activation should be cleared before test"
     51      );
     52      ok(
     53        userInput.during.hasValidTransientUserGestureActivation,
     54        "should provide transient activation during event"
     55      );
     56      ok(
     57        userInput.during.isHandlingUserInput,
     58        "isHandlingUserInput should be true during event"
     59      );
     60      ok(
     61        userInput.after.hasValidTransientUserGestureActivation,
     62        "should provide transient activation after event"
     63      );
     64      ok(
     65        !userInput.after.isHandlingUserInput,
     66        "isHandlingUserInput should be false after event"
     67      );
     68    }
     69  );
     70 }
     71 
     72 add_setup(async function () {
     73  await SpecialPowers.pushPrefEnv({
     74    set: [["test.wait300msAfterTabSwitch", true]],
     75  });
     76 });
     77 
     78 // This test checks if the change/click event is considered as user input event.
     79 add_task(async function test_handling_user_input_key() {
     80  return testHandlingUserInputOnChange(async function () {
     81    EventUtils.synthesizeKey("KEY_ArrowDown");
     82    await hideSelectPopup();
     83  });
     84 });
     85 
     86 add_task(async function test_handling_user_input_click() {
     87  return testHandlingUserInputOnChange(async function (popup) {
     88    EventUtils.synthesizeMouseAtCenter(popup.lastElementChild, {});
     89  });
     90 });
     91 
     92 add_task(async function test_handling_user_input_click() {
     93  return testHandlingUserInputOnChange(async function (popup) {
     94    EventUtils.synthesizeMouseAtCenter(popup.lastElementChild, {});
     95  });
     96 });