tor-browser

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

test_bug1837268.html (2433B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <title>Mozilla bug 1837268</title>
      5  <link rel=stylesheet href="/tests/SimpleTest/test.css">
      6  <script src="/tests/SimpleTest/EventUtils.js"></script>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <script src="/tests/editor/spellchecker/tests/spellcheck.js"></script>
      9 </head>
     10 <body>
     11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1837268">Mozilla Bug 1837268</a>
     12 <p id="display"></p>
     13 <div id="content" style="display: none;">
     14 
     15 </div>
     16 
     17 <div id="contenteditable" contenteditable=true>aabbcc</div>
     18 
     19 <script>
     20 const { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     21  "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     22 );
     23 
     24 SimpleTest.waitForExplicitFinish();
     25 
     26 function getEditor() {
     27  return SpecialPowers.wrap(window).docShell.editor;
     28 }
     29 
     30 SimpleTest.waitForFocus(async () => {
     31  let contenteditable = document.getElementById("contenteditable");
     32  contenteditable.addEventListener("beforeinput", (ev) => {
     33    ev.preventDefault();
     34    let text = contenteditable.textContent;
     35    const sel = window.getSelection();
     36    let offset = sel.anchorOffset;
     37    switch (ev.inputType) {
     38      case "insertText":
     39        text = text.substring(0, offset) + ev.data + text.substring(offset);
     40        offset += 1;
     41        break;
     42      case "deleteContentBackward":
     43        text = text.substring(0, offset - 1) + text.substring(offset);
     44        offset -= 1;
     45        break;
     46      default:
     47        return;
     48    }
     49    if (contenteditable.firstChild) {
     50      contenteditable.firstChild.nodeValue = text;
     51    } else {
     52      contenteditable.textContent = text;
     53    }
     54    sel.collapse(contenteditable.firstChild ?? contenteditable, offset);
     55  });
     56 
     57  let misspelledWords = [];
     58  misspelledWords.push("aabbc"); // One c removed.
     59 
     60  contenteditable.focus();
     61  window.getSelection().collapse(contenteditable.firstChild, contenteditable.firstChild.length);
     62 
     63  // Run spell checker
     64  await new Promise((resolve) => { maybeOnSpellCheck(contenteditable, resolve); });
     65 
     66  synthesizeKey("KEY_Backspace");
     67  synthesizeKey(" ");
     68 
     69  await new Promise((resolve) => { maybeOnSpellCheck(contenteditable, resolve); });
     70  let editor = getEditor();
     71  // isSpellingCheckOk is defined in spellcheck.js
     72  // eslint-disable-next-line no-undef
     73  ok(isSpellingCheckOk(editor, misspelledWords), "correct word is selected as misspelled");
     74 
     75  SimpleTest.finish();
     76 });
     77 </script>
     78 </body>
     79 </html>