tor-browser

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

test_bug1368544.html (3401B)


      1 <!DOCTYPE html>
      2 <!--
      3 https://bugzilla.mozilla.org/show_bug.cgi=id=1368544
      4 -->
      5 <html>
      6 <head>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <script src="/tests/SimpleTest/EventUtils.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1368544">Mozilla Bug 1368544</a>
     13 <div id="display"></div>
     14 <textarea id=textarea></textarea>
     15 <pre id="test">
     16 </pre>
     17 
     18 <script class="testbody">
     19 function hasEmptyTextNode(div) {
     20  return div.firstChild.nodeType === Node.TEXT_NODE && div.firstChild.length === 0;
     21 }
     22 
     23 SimpleTest.waitForExplicitFinish();
     24 SimpleTest.waitForFocus(() => {
     25  let textarea = document.getElementById("textarea");
     26  let editor = SpecialPowers.wrap(textarea).editor;
     27 
     28  let spellChecker = SpecialPowers.Cu.createSpellChecker();
     29  spellChecker.InitSpellChecker(editor, false);
     30 
     31  textarea.focus();
     32 
     33  const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     34    "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     35  );
     36  onSpellCheck(textarea, () => {
     37    spellChecker.UpdateCurrentDictionary(() => {
     38      textarea.value = "ABC";
     39      ok(editor.rootElement.hasChildNodes(),
     40         "editor of textarea has child nodes");
     41      sendString("D");
     42      is(textarea.value, "ABCD", "D is last character");
     43      ok(editor.rootElement.hasChildNodes(),
     44         "editor of textarea has child nodes");
     45      textarea.value = "";
     46      ok(editor.rootElement.hasChildNodes(),
     47         "editor of textarea has child node even if value is empty");
     48 
     49      sendString("AAA");
     50      synthesizeKey("KEY_Backspace", {repeat: 3});
     51      is(textarea.value, "", "value is empty");
     52      ok(editor.rootElement.hasChildNodes(),
     53         "editor of textarea has child node even if value is empty");
     54 
     55      textarea.value = "ABC";
     56      SpecialPowers.wrap(textarea).setUserInput("");
     57      is(textarea.value, "",
     58         "textarea should become empty when setUserInput() is called with empty string");
     59      ok(hasEmptyTextNode(editor.rootElement),
     60            "editor of textarea should only have an empty text node when user input emulation set the value to empty");
     61      todo(editor.rootElement.childNodes.length === 1, "editor of textarea should only have a single child");
     62      if (editor.rootElement.childNodes.length > 1) {
     63        is(editor.rootElement.childNodes.length, 2, "There should be only one additional <br> node");
     64        is(editor.rootElement.lastChild.tagName.toLowerCase(), "br", "The node should be a <br> element node");
     65        ok(!SpecialPowers.wrap(editor.rootElement.lastChild).isPaddingForEmptyEditor,
     66            "The <br> should not be a padding <br> element");
     67      }
     68      textarea.value = "ABC";
     69      synthesizeKey("KEY_Enter", {repeat: 2});
     70      textarea.value = "";
     71      ok(editor.rootElement.hasChildNodes(),
     72         "editor of textarea has child node even if value is empty");
     73 
     74      sendString("AAA");
     75      is(textarea.value, "AAA", "value is AAA");
     76      textarea.addEventListener("keyup", (e) => {
     77        if (e.key == "Enter") {
     78          textarea.value = "";
     79          ok(editor.rootElement.hasChildNodes(),
     80             "editor of textarea has child node even if value is empty");
     81          SimpleTest.finish();
     82        }
     83      });
     84 
     85      synthesizeKey("KEY_Enter");
     86    });
     87 });
     88 });
     89 </script>
     90 </body>
     91 </html>