tor-browser

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

eventOrder.html (2362B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>TestDriver actions: event order</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-actions.js"></script>
      8 <script src="/resources/testdriver-vendor.js"></script>
      9 
     10 <button id="a">Button a</button>
     11 <button id="b">Button b</button>
     12 <input id="text-input">
     13 
     14 <script>
     15 // Pointer 1 is added before Pointer 2 so it comes first in the list of sources
     16 // Therefore its actions happen first
     17 let events = [];
     18 
     19 promise_test(() => {
     20  Array.prototype.forEach.call(document.getElementsByTagName("button"),
     21                               (x) => x.addEventListener("mousedown", () => {events.push(x.id)}));
     22 
     23  let button_a = document.getElementById("a");
     24  let button_b = document.getElementById("b");
     25  return new test_driver.Actions()
     26    .addPointer("pointer1")
     27    .addPointer("pointer2")
     28    .pointerMove(0, 0, {origin: button_a, sourceName: "pointer1"})
     29    .pointerMove(0, 0, {origin: button_b, sourceName: "pointer2"})
     30    .pointerDown({sourceName: "pointer2"})
     31    .pointerDown({sourceName: "pointer1"})
     32    .pointerUp({sourceName: "pointer2"})
     33    .pointerUp({sourceName: "pointer1"})
     34    .send()
     35    .then(() => assert_array_equals(events, ["a", "b"]));
     36 });
     37 
     38 // This test uses a large number of keyboard sources to force race conditions
     39 // in implementations which incorrectly dispatch events. Despite belonging to
     40 // the same "tick," each action's initial event should be dispatched in series.
     41 promise_test(() => {
     42  const input = document.getElementById("text-input");
     43  const actions = new test_driver.Actions();
     44  const code_for_a = "a".charCodeAt(0);
     45  const keys = Array.from(Array(26))
     46    .map((_, index) => ({
     47      sourceName: "keyboard" + index,
     48      code: String.fromCharCode(code_for_a + index)
     49    }));
     50 
     51  keys.forEach(({sourceName}) => actions.addKeyboard(sourceName));
     52  keys.forEach(({code, sourceName}) => actions.keyDown(code, {sourceName}));
     53  keys.forEach(({code, sourceName}) => actions.keyUp(code,{sourceName}));
     54 
     55  return test_driver.click(input)
     56    .then(() => actions.send())
     57    .then(() => {
     58      assert_equals(input.value, "abcdefghijklmnopqrstuvwxyz");
     59    });
     60 }, "indivisible actions on the same track dispatch events in series");
     61 </script>