editor/libeditor/base/tests/test_bug646194.xul
author Blake Kaplan <mrbkap@gmail.com>
Tue, 03 Sep 2013 15:01:00 -0400
changeset 110284 54dde77e836c60cf478cb330c966b0f91272f55c
parent 75084 67f6f1908b0f4cb8c00d3de763787fdb8fe8eeeb
permissions -rw-r--r--
Bug 860123 - Use the right window's selection in some tests. r=ehsan, a=bajaj

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin"
                 type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=646194
-->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="Mozilla Bug 646194" onload="runTest();">
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=646194"
     target="_blank">Mozilla Bug 646194</a>
  <p/>
  <iframe id="i" src="data:text/html,&lt;div contenteditable=true id=t&gt;test me now&lt;/div&gt;"/>
  <p/>
  <pre id="test">
  </pre>
  </body>
  <script class="testbody" type="application/javascript">
  <![CDATA[

function runTest() {
  function doCommand(aCmd) {
    var controller = top.document.commandDispatcher
                     .getControllerForCommand(aCmd);
    ok((controller && controller.isCommandEnabled(aCmd)), "command available");
    controller.doCommand(aCmd);
  }

  var i = document.getElementById("i");
  i.focus();
  var win = i.contentWindow;
  var doc = i.contentDocument;
  var t = doc.getElementById("t");
  t.focus();
  // put the caret at the end
  win.getSelection().collapse(t.firstChild, 11);

  // Simulate pression Option+Delete on Mac
  // We do things this way because not every platform can invoke this
  // command using the available key bindings.
  doCommand("cmd_wordPrevious");
  doCommand("cmd_wordPrevious");
  doCommand("cmd_deleteWordBackward");
  doCommand("cmd_deleteWordBackward");

  // If we reach here, we haven't crashed.  Phew!
  // But let's check the value too, now that we're here.
  is(t.textContent, "me now", "The command has worked correctly");

  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>