DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
<!DOCTYPE html>
<html>
<head>
  <title>Testing if AltGr keydown and keyup events are fired in web content on Windows</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script src="/tests/SimpleTest/NativeKeyCodes.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body>
<div id="display">
  <input id="input">
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>

<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();

function checkEvent(aEvent, aExpectedEvents, aDescription) {
  if (!aExpectedEvents.length) {
    ok(false, `${aDescription}: no more expected events ` +
              `(type: ${aEvent.type}, code: ${aEvent.code}, key: ${aEvent.key}, keyCode: ${aEvent.keyCode}`);
  }
  let expectedEvent = aExpectedEvents.shift();
  for (let property in expectedEvent) {
    is(aEvent[property], expectedEvent[property], `${aDescription}: ${property}`);
  }
}

async function runAltGrKeyTest() {
  return new Promise(resolve => {
    let target = document.getElementById("input");
    target.focus();

    let events = [
      { type: "keydown", code: "ControlLeft", key: "Control", keyCode: KeyboardEvent.DOM_VK_CONTROL },
      { type: "keydown", code: "AltRight", key: "AltGraph", keyCode: KeyboardEvent.DOM_VK_ALT },
      { type: "keyup", code: "ControlLeft", key: "Control", keyCode: KeyboardEvent.DOM_VK_CONTROL },
      { type: "keyup", code: "AltRight", key: "AltGraph", keyCode: KeyboardEvent.DOM_VK_ALT },
    ];
    function handleEvent(aEvent) {
      checkEvent(aEvent, events, "runAltGrKeyTest");
      if (aEvent.type === "keyup" && aEvent.code === "AltRight") {
        is(events.length, 0, "runAltGrKeyTest: all expected events are fired");
        SimpleTest.executeSoon(() => {
          target.removeEventListener("keydown", handleEvent);
          target.removeEventListener("keypress", handleEvent);
          target.removeEventListener("keyup", handleEvent);
          resolve();
        });
      }
    }
    target.addEventListener("keydown", handleEvent);
    target.addEventListener("keypress", handleEvent);
    target.addEventListener("keyup", handleEvent);

    synthesizeNativeKey(KEYBOARD_LAYOUT_SPANISH, WIN_VK_RMENU, {},
                        "", "");
  });
}

async function runEmulatingAltGrKeyTest() {
  return new Promise(resolve => {
    let target = document.getElementById("input");
    target.focus();

    let events = [
      { type: "keydown", code: "ControlLeft", key: "Control", keyCode: KeyboardEvent.DOM_VK_CONTROL },
      { type: "keydown", code: "AltLeft", key: "Alt", keyCode: KeyboardEvent.DOM_VK_ALT },
      { type: "keyup", code: "AltLeft", key: "Alt", keyCode: KeyboardEvent.DOM_VK_ALT },
      { type: "keyup", code: "ControlLeft", key: "Control", keyCode: KeyboardEvent.DOM_VK_CONTROL },
    ];
    function handleEvent(aEvent) {
      checkEvent(aEvent, events, "runEmulatingAltGrKeyTest");
      if (aEvent.type === "keyup" && aEvent.code === "ControlLeft") {
        is(events.length, 0, "runAltGrKeyTest: all expected events are fired");
        SimpleTest.executeSoon(() => {
          target.removeEventListener("keydown", handleEvent);
          target.removeEventListener("keypress", handleEvent);
          target.removeEventListener("keyup", handleEvent);
          resolve();
        });
      }
    }
    target.addEventListener("keydown", handleEvent);
    target.addEventListener("keypress", handleEvent);
    target.addEventListener("keyup", handleEvent);

    synthesizeNativeKey(KEYBOARD_LAYOUT_SPANISH, WIN_VK_LMENU, { ctrlKey: true },
                        "", "");
  });
}

async function runTests() {
  await runAltGrKeyTest();
  await runEmulatingAltGrKeyTest();
  SimpleTest.finish();
}

SimpleTest.waitForFocus(runTests);
</script>
</body>
</html>