tor-browser

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

test_spellcheck_after_pressing_navigation_key.html (2552B)


      1 <!doctype html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1729653
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1729653</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <script src="/tests/SimpleTest/EventUtils.js"></script>
     11  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
     12 </head>
     13 <body>
     14 <textarea rows="20" cols="50">That undfgdfg seems OK.</textarea>
     15 <script>
     16 let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     17  "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     18 );
     19 
     20 function waitForTick() {
     21  return new Promise(resolve => SimpleTest.executeSoon(resolve));
     22 }
     23 
     24 function waitForOnSpellCheck(aTextArea) {
     25  info("Waiting for onSpellCheck...");
     26  return new Promise(resolve => maybeOnSpellCheck(aTextArea, resolve));
     27 }
     28 
     29 /** Test for Bug 1729653 */
     30 SimpleTest.waitForExplicitFinish();
     31 SimpleTest.waitForFocus(async () => {
     32  const textarea = document.querySelector("textarea");
     33  textarea.focus();
     34  textarea.selectionStart = textarea.selectionEnd = "That undfgdfg".length;
     35  const editor = SpecialPowers.wrap(textarea).editor;
     36  const nsISelectionController = SpecialPowers.Ci.nsISelectionController;
     37  const selection = editor.selectionController.getSelection(nsISelectionController.SELECTION_SPELLCHECK);
     38  const spellChecker = SpecialPowers.Cu.createSpellChecker();
     39  spellChecker.InitSpellChecker(editor, false);
     40  info("Waiting for current dictionary update...");
     41  await new Promise(resolve => spellChecker.UpdateCurrentDictionary(resolve));
     42  if (selection.rangeCount === 0) {
     43    await waitForOnSpellCheck(textarea);
     44  }
     45  if (selection.rangeCount == 1) {
     46    is(
     47      selection.getRangeAt(0).toString(),
     48      "undfgdfg",
     49      "\"undfgdfg\" should be marked as misspelled word at start"
     50    );
     51  } else {
     52    is(selection.rangeCount, 1, "We should have a misspelled word at start");
     53  }
     54  synthesizeKey(" ");
     55  synthesizeKey("KEY_Backspace");
     56  textarea.addEventListener("keydown", event => {
     57    event.stopImmediatePropagation();  // This shouldn't block spellchecker to handle it.
     58  }, {once: true});
     59  synthesizeKey("KEY_End");
     60  await waitForTick();
     61  if (selection.rangeCount === 0) {
     62    await waitForOnSpellCheck(textarea);
     63  }
     64  if (selection.rangeCount == 1) {
     65    is(
     66      selection.getRangeAt(0).toString(),
     67      "undfgdfg",
     68      "\"undfgdfg\" should be marked as misspelled word at end"
     69    );
     70  } else {
     71    is(selection.rangeCount, 1, "We should have a misspelled word at end");
     72  }
     73  SimpleTest.finish();
     74 });
     75 </script>
     76 </body>
     77 </html>