author Ehsan Akhgari <ehsan@mozilla.com>
Mon, 18 Aug 2014 20:59:37 -0400
changeset 221858 8f48ab6499cfa2f071d8bb3c550884e94dbc7803
parent 136998 editor/libeditor/text/tests/test_bug471722.html@23850987c825d2e48be20e0e5f7bac22357af1f9
child 475179 7c9969cf727a3885d25453de55101f56134a4a49
permissions -rw-r--r--
Bug 1055286 - Flatten editor/libeditor/text to editor/libeditor; r=poiru

<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

  <title>Test for Bug 471722</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>  

<body onload="doTest();">
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=471722">Mozilla Bug 471722</a>
  <p id="display"></p>
  <div id="content" style="display: none">

  <pre id="test">
    <script type="application/javascript">

      /** Test for Bug 471722 **/

      function doTest() {
        var t1 = $("t1");
        var editor = null;

        if (t1 instanceof SpecialPowers.Ci.nsIDOMNSEditableElement)
          editor = SpecialPowers.wrap(t1).editor;
        ok(editor, "able to get editor for the element");

        try {

          // Cut the initial text in the textbox
          ok(editor.canCut(), "can cut text");
          is(t1.value, "", "initial text was removed");
          // So now we will have emptied the textfield
          // and the editor will have created a bogus node
          // Check the transaction is in the undo stack...
          var t1Enabled = {};
          var t1CanUndo = {};
          editor.canUndo(t1Enabled, t1CanUndo);
          ok(t1CanUndo.value, "undo is enabled");

          // Undo the cut
          is(t1.value, "minefield", "text reinserted");

          // So now, the cut should be in the redo stack,
          // so executing the redo will clear the text once again
          // and reinsert the bogus node that was removed after undo.
          // This will require the editor to figure out that we have a
          // bogus node again...
          var t1CanRedo = {};
          editor.canRedo(t1Enabled, t1CanRedo);
          ok(t1CanRedo.value, "redo is enabled");

          // Did the editor notice a bogus node reappeared?
          is(t1.value, "", "editor found bogus node");
       } catch (e) {
         ok(false, "test failed with error "+e);

  <input type="text" value="minefield" id="t1" />