editor/libeditor/text/tests/test_bug569988.html
author Justin Dolske <dolske@mozilla.com>
Fri, 19 Nov 2010 15:15:27 -0800
changeset 57928 bbc4273845eb1bd1c7133a5416ec0fb1450e9213
parent 44170 38c6287d66820f1121925cf6ef694f53e0d8133c
child 71620 47c73a8334bb6b4bc059fcd6e8bbf6ac8d2a4cb1
permissions -rw-r--r--
Bug 613403 - Fix existing tests to work with tab-modal prompt changes. r=ehsan, a=testsonly

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=569988
-->
<head>
  <title>Test for Bug 569988</title>
  <script type="application/javascript" src="/MochiKit/packed.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/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=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()
{
  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

  var os = Components.classes["@mozilla.org/observer-service;1"].
             getService(Components.interfaces.nsIObserverService);

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

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

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

function onPromptLoad(subject, topic, data)
{
  ok(true, "onPromptLoad is called");
  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  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");
  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  gPromptInput.removeEventListener("focus", onPromptFocus, false);

  var systemGroup =
    Components.classes["@mozilla.org/eventlistenerservice;1"].
      getService(Components.interfaces.nsIEventListenerService).
      systemEventGroup;
  gPromptInput.QueryInterface(Components.interfaces.nsIDOM3EventTarget);
  var listener = {
    handleEvent: function _hv(aEvent)
    {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
      var isPrevented = aEvent.getPreventDefault();
      ok(!isPrevented, "ESC key event is prevented by editor");
      gPromptInput.removeGroupedEventListener("keypress", listener, false,
                                              systemGroup);
      SimpleTest.finish();
    }
  };
  gPromptInput.addGroupedEventListener("keypress", listener, false,
                                       systemGroup);
  ok(true, "sending key");
  synthesizeKey("VK_ESCAPE", { }, gPromptInput.ownerDocument.defaultView);
}

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