dom/events/test/test_use_split_keypress_event_model_on_old_Office_Online_Server.html
author Masayuki Nakano <masayuki@d-toybox.com>
Thu, 23 May 2019 22:00:58 +0000
changeset 536570 b9d57ba2bf45a07a5348473a354931c49b580e3f
permissions -rw-r--r--
Bug 1545410 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Office Online Server r=smaug a=jcristau Similar to bug 1514940, we need to use "split model" keypres events on Office Online Server since they can be installed into user own servers. Microsoft said it's safe to check whether there is an element whose id is "WACViewPanel_EditingElement": https://bugzilla.mozilla.org/show_bug.cgi?id=1545410#c17 Additionally, they'll add new class to the element after fixing the bug in their side: https://bugzilla.mozilla.org/show_bug.cgi?id=1545410#c17 https://bugzilla.mozilla.org/show_bug.cgi?id=1545410#c20 Differential Revision: https://phabricator.services.mozilla.com/D32287

<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1545410
-->
<head>
  <meta charset="utf-8">
  <title>Testing whether "keypress" event model is forcibly split model if the document is old Office Online Server instance</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1545410">Bug 1545410</a>
<p id="display"></p>
<pre id="test"></pre>
<input id="input">
<iframe id="iframe" srcdoc='<html><body><div id="WACViewPanel_EditingElement" spellcheck="false" class="FireFox usehover WACEditing EditMode EditingSurfaceBody" style="overflow: visible; visibility: visible;" contenteditable="true"></div></body></html>'></iframe>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async function doTests() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["dom.keyboardevent.keypress.set_keycode_and_charcode_to_same_value", true],
    ],
  });

  let iframe = document.getElementById("iframe");
  iframe.contentDocument.body.firstChild.focus();
  let keypressEvent;
  iframe.contentDocument.body.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
  synthesizeKey("a", {}, iframe.contentWindow);
  is(keypressEvent.keyCode, 0,
     "keyCode value of 'a' should be 0");
  is(keypressEvent.charCode, "a".charCodeAt(0),
     "charCode value of 'a' should be 'a'");

  iframe.contentDocument.body.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
  synthesizeKey("KEY_Enter", {}, iframe.contentWindow);
  is(keypressEvent.keyCode, KeyboardEvent.DOM_VK_RETURN,
     "keyCode value of 'Enter' should be DOM_VK_RETURN");
  is(keypressEvent.charCode, 0,
     "charCode value of 'Enter' should be 0");

  let input = document.getElementById("input");
  input.focus();
  input.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
  synthesizeKey("a", {});
  is(keypressEvent.keyCode, "a".charCodeAt(0),
     "keyCode value of 'a' in the parent document should be 'a'");
  is(keypressEvent.charCode, "a".charCodeAt(0),
     "charCode value of 'a' in the parent document should be 'a'");

  input.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
  synthesizeKey("KEY_Enter");
  is(keypressEvent.keyCode, KeyboardEvent.DOM_VK_RETURN,
     "keyCode value of 'Enter' in the parent document should be DOM_VK_RETURN");
  is(keypressEvent.charCode, KeyboardEvent.DOM_VK_RETURN,
     "charCode value of 'Enter' in the parent document should be DOM_VK_RETURN");

  SimpleTest.finish();
});
</script>
</body>
</html>