editor/libeditor/text/tests/test_bug527935.html
author Masayuki Nakano <masayuki@d-toybox.com>
Sat, 15 Feb 2014 09:57:39 +0900
changeset 168896 e947cee33a9206310dc5ea57492a2f3fac4807ab
parent 131583 0b21e902f7a0ba74960e757379f18d4c90dcadba
permissions -rw-r--r--
Bug 969247 part.1 Remove or replace DOM_VK_ENTER and NS_VK_ENTER users r=smaug

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=527935
-->
<head>
  <title>Test for Bug 527935</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" 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=527935">Mozilla Bug 527935</a>
<p id="display"></p>
<div id="content">
  <iframe id="formTarget" name="formTarget"></iframe>
  <form action="data:text/html," target="formTarget">
    <input name="test" id="initValue"><input type="submit">
  </form>
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 527935 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
  var formTarget = document.getElementById("formTarget");
  var initValue = document.getElementById("initValue");

  formTarget.addEventListener("load", function() {
    var newInput = document.createElement("input");
    newInput.setAttribute("name", "test");
    document.body.appendChild(newInput);

    setTimeout(function() {
      var popupShown = false;
      function listener() {
        popupShown = true;
      }
      SpecialPowers.addAutoCompletePopupEventListener(window, "popupshowing", listener);

      var event = document.createEvent("KeyboardEvent");

      event.initKeyEvent("keypress", true, true, null, false, false,
                         false, false, 0, "f".charCodeAt(0));
      newInput.value = "";
      newInput.focus();
      newInput.dispatchEvent(event);

      hitEventLoop(function() {
        ok(!popupShown, "Popup must not be opened");
        SpecialPowers.removeAutoCompletePopupEventListener(window, "popupshowing", listener);
        SimpleTest.finish();
      }, 100);
    }, 0);
  }, false);

  initValue.focus();
  initValue.value = "foo";
  synthesizeKey("VK_RETURN", {});
});

function hitEventLoop(func, times) {
  if (times > 0) {
    setTimeout(hitEventLoop, 0, func, times - 1);
  } else {
    setTimeout(func, 0);
  }
}

</script>
</pre>
</body>
</html>