tor-browser

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

pending-input-utils.js (2232B)


      1 // Dispatches the given sequence of actions and verifies isInputPending state
      2 // after dispatch according to expectations. Returns when all dispatched input
      3 // has been handled.
      4 const pendingActionTest = async (label, target, actionCallback, expectations) => {
      5  promise_test(async () => {
      6    // Give focus to the page first, before running the test.
      7    await new test_driver.Actions()
      8      .pointerMove(0, 0)
      9      .pointerDown()
     10      .pointerUp()
     11      .send();
     12 
     13    // Register a handler to fetch the result of isInputPending from the target
     14    // window.
     15    const resultPromise = new Promise(res => {
     16      window.addEventListener('message', function handler(e) {
     17        if (e.data === 'check-input') return;
     18        res(e.data);
     19        window.removeEventListener('message', handler);
     20      });
     21    });
     22 
     23    // Signal to the target window to monitor isInputPending.
     24    target.postMessage('check-input', '*');
     25 
     26    const actions = actionCallback();
     27    const actionsPromise = actions.send();
     28 
     29    const {discrete, continuous} = await resultPromise;
     30 
     31    assert_equals(discrete, expectations.discrete, 'detected discrete input');
     32    assert_equals(continuous, expectations.continuous, 'detected continuous input');
     33 
     34    await actionsPromise;
     35  }, label);
     36 }
     37 
     38 const PendingInputUtils = {
     39  testDetectNoPendingInput(target, actionCallback, label) {
     40    pendingActionTest(label, target, actionCallback, {
     41      discrete: false,
     42      continuous: false,
     43    });
     44  },
     45 
     46  testDetectDiscretePendingInput(target, actionCallback, label) {
     47    pendingActionTest(label, target, actionCallback, {
     48      discrete: true,
     49      continuous: true,
     50    });
     51  },
     52 
     53  testDetectContinuousPendingInput(target, actionCallback, label) {
     54    pendingActionTest(label, target, actionCallback, {
     55      discrete: false,
     56      continuous: true,
     57    });
     58  },
     59 
     60  // Simulates a pointer event at the given coordinates, and tests that the
     61  // given target window cannot access it. Intended for cross-origin compliance
     62  // tests.
     63  testCannotAccessPendingInputAt(target, x, y, label) {
     64    PendingInputUtils.testDetectNoPendingInput(target, () => {
     65      return new test_driver.Actions().pointerMove(x, y).pointerDown().pointerUp();
     66    }, label);
     67  },
     68 }