widget/tests/test_AltGr_key_events_in_web_content_on_windows.html
author Jan de Mooij <jdemooij@mozilla.com>
Sat, 12 Jan 2019 10:50:04 +0000
changeset 453631 cfa1c48c717048f00eb4811b5719cd716eb1e5b3
parent 424489 c0cd065ee5c8832f6962d09805541ecad1d5398e
child 469640 c9c0c6f2eed54a187e124942e53c3660b4cf17d8
permissions -rw-r--r--
Bug 1518753 part 5 - Stop using JSProtoKey for initial shapes. r=tcampbell I added this optimization in bug 1299107 to share more shapes across compartments. Unfortunately this doesn't play well with same-compartment realms (ICs can misbehave) because it relies on compartments being isolated from each other. I think we should remove this optimization: * Fixing the IC issue is impossible without deoptimizing everything. * I added it mainly for chrome globals. The shared-JSM-global work has eliminated the need for this there. * Same-compartment realms win memory back by eliminating CCWs etc. * It's quite a lot of complicated code. Differential Revision: https://phabricator.services.mozilla.com/D16170

<!DOCTYPE html>
<html>
<head>
  <title>Testing if AltGr keydown and keyup events are fired in web content on Windows</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" 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>