layout/base/tests/bug989012-3.html
author Makoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 08 Jan 2019 16:50:14 +0900
changeset 510115 a6cc9b822c1c1051961f8a293bc3e0331b8739d6
parent 456830 50d6fe2d0bca50837dd34eb4a79957885c55bffc
child 528457 c9c0c6f2eed54a187e124942e53c3660b4cf17d8
permissions -rw-r--r--
Bug 1450055 - Part 3. Update mochitests since focus event listener is system group. r=masayuki The focus event listener in editor is system group, so synthesizeKey and/or synthesizeMouse doesn't work on focus event since editor doesn't initialize selection yet. So use setTimeout to work synthesizeKey and etc well. Differential Revision: https://phabricator.services.mozilla.com/D15926

<html class="reftest-wait">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    <style>
      img {
        border: solid 1px red;
        mid-width: 1em;
        display: inline-block;
      }
    </style>
  </head>
  <body onload="start()">
    <div onfocus="setTimeout(done, 0)" contenteditable>foo<img>bar</div>
    <script>
      var div = document.querySelector("div");
      function start() {
        div.focus();
      }
      function done() {
        var sel = getSelection();
        sel.collapse(div, 0);
        // Press Right four times to set the caret right before "bar"
        for (var i = 0; i < 4; ++i) {
          synthesizeKey("KEY_ArrowRight");
        }
        document.documentElement.removeAttribute("class");
      }
    </script>
  </body>
</html>