tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_texteditor_textnode.html (1423B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Test for Bug 1713334</title>
      4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      5 <script src="/tests/SimpleTest/EventUtils.js"></script>
      6 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
      7 <input id="input">
      8 <textarea id="textarea"></textarea>
      9 <script>
     10 "use strict";
     11 
     12 function assertChild(div, content) {
     13  const name = div.parentElement.localName;
     14  is(div.firstChild.nodeType, Node.TEXT_NODE, `<${name}>: The first node of the root element must be a text node`);
     15  is(div.firstChild.textContent, content, `<${name}>: The content of the text node is wrong`);
     16 }
     17 
     18 function test(element) {
     19  element.focus();
     20 
     21  const { rootElement } = SpecialPowers.wrap(element).editor;
     22  assertChild(rootElement, "");
     23 
     24  element.value = "";
     25  assertChild(rootElement, "");
     26 
     27  element.value = "foo"
     28  assertChild(rootElement, "foo");
     29 
     30  element.value = "";
     31  assertChild(rootElement, "");
     32 
     33  element.value = "foo";
     34  const selection =
     35    SpecialPowers.wrap(element).
     36    editor.
     37    selectionController.getSelection(
     38      SpecialPowers.Ci.nsISelectionController.SELECTION_NORMAL
     39    );
     40  selection.setBaseAndExtent(rootElement, 0, rootElement, 1);
     41  document.execCommand("delete");
     42  assertChild(rootElement, "");
     43 }
     44 
     45 SimpleTest.waitForExplicitFinish();
     46 SimpleTest.waitForFocus(() => {
     47  test(document.all.input);
     48  test(document.all.textarea);
     49 
     50  SimpleTest.finish();
     51 });
     52 </script>