editor/libeditor/tests/test_bug569988.html
author Ehsan Akhgari <ehsan@mozilla.com>
Mon, 18 Aug 2014 20:59:37 -0400
changeset 221858 8f48ab6499cfa2f071d8bb3c550884e94dbc7803
parent 163310 editor/libeditor/text/tests/test_bug569988.html@0ed8e884d35242b595a5f1b1196dea5f7eaa9918
child 363445 fe1a0812871c3e44645180330534a4292a56ebae
permissions -rw-r--r--
Bug 1055286 - Flatten editor/libeditor/text to editor/libeditor; r=poiru

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=569988
-->
<head>
  <title>Test for Bug 569988</title>
 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=569988">Mozilla Bug 569988</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 569988 **/

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);

var gPromptInput = null;

function runTest()
{
  var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"].
             getService(SpecialPowers.Ci.nsIObserverService);

  os.addObserver(onPromptLoad, "common-dialog-loaded", false);
  os.addObserver(onPromptLoad, "tabmodal-dialog-loaded", false);

  info("opening prompt...");
  prompt("summary", "text");
  info("prompt is closed");

  os.removeObserver(onPromptLoad, "tabmodal-dialog-loaded");
  os.removeObserver(onPromptLoad, "common-dialog-loaded");
  SimpleTest.finish();
}

function onPromptLoad(subject, topic, data)
{
  ok(true, "onPromptLoad is called");
  gPromptInput = subject.Dialog.ui.loginTextbox;
  gPromptInput.addEventListener("focus", onPromptFocus, false);
  // shift focus to ensure it fires.
  subject.Dialog.ui.button0.focus();
  gPromptInput.focus();
}

function onPromptFocus() {
  ok(true, "onPromptFocus is called");
  gPromptInput.removeEventListener("focus", onPromptFocus, false);

  var listener = {
    handleEvent: function _hv(aEvent)
    {
      var isPrevented = aEvent.defaultPrevented;
      ok(!isPrevented, "ESC key event is prevented by editor");
      SpecialPowers.removeSystemEventListener(gPromptInput, "keypress",
                                              listener, false);
    }
  };
  SpecialPowers.addSystemEventListener(gPromptInput, "keypress", listener,
                                       false);
  info("sending key");
  synthesizeKey("VK_ESCAPE", { }, gPromptInput.ownerDocument.defaultView);
}

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