tor-browser

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

accesskey.js (1233B)


      1 /*
      2 * Function that sends an accesskey using the proper key combination depending on the browser and OS.
      3 *
      4 * This needs that the test imports the following scripts:
      5 *     <script src="/resources/testdriver.js"></script>
      6 *     <script src="/resources/testdriver-actions.js"></script>
      7 *     <script src="/resources/testdriver-vendor.js"></script>
      8 */
      9 function pressAccessKey(accessKey){
     10  let controlKey = '\uE009'; // left Control key
     11  let altKey = '\uE00A'; // left Alt key
     12  let optionKey = altKey;  // left Option key
     13  let shiftKey = '\uE008'; // left Shift key
     14  // There are differences in using accesskey across browsers and OS's.
     15  // See: // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey
     16  let isMacOSX = navigator.userAgent.indexOf("Mac") != -1;
     17  let osAccessKey = isMacOSX ? [controlKey, optionKey] : [shiftKey, altKey];
     18  let actions = new test_driver.Actions();
     19  // Press keys.
     20  for (let key of osAccessKey) {
     21    actions = actions.keyDown(key);
     22  }
     23  actions = actions
     24            .keyDown(accessKey)
     25            .addTick()
     26            .keyUp(accessKey);
     27  osAccessKey.reverse();
     28  for (let key of osAccessKey) {
     29    actions = actions.keyUp(key);
     30  }
     31  return actions.send();
     32 }