tor-browser

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

test_bug1402822.html (4144B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1402822
      5 -->
      6 <head>
      7  <title>Test for Bug 1402822</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1402822">Mozilla Bug 1402822</a>
     14 <p id="display"></p>
     15 </div>
     16 
     17 <textarea id="editor">heute ist ein guter Tag - today is a good day</textarea>
     18 
     19 <pre id="test">
     20 <script class="testbody" type="text/javascript">
     21 
     22 const Ci = SpecialPowers.Ci;
     23 
     24 let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     25  "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     26 );
     27 
     28 function getMisspelledWords(editor) {
     29  return editor.selectionController.getSelection(Ci.nsISelectionController.SELECTION_SPELLCHECK).toString();
     30 }
     31 
     32 /** Test for Bug 1402822 */
     33 SimpleTest.waitForExplicitFinish();
     34 addLoadEvent(start);
     35 async function start() {
     36  let script = SpecialPowers.loadChromeScript(() => {
     37    /* eslint-env mozilla/chrome-script */
     38    // eslint-disable-next-line mozilla/use-services
     39    let dir = Cc["@mozilla.org/file/directory_service;1"]
     40                .getService(Ci.nsIProperties)
     41                .get("CurWorkD", Ci.nsIFile);
     42    dir.append("tests");
     43    dir.append("editor");
     44    dir.append("spellchecker");
     45    dir.append("tests");
     46 
     47    let hunspell = Cc["@mozilla.org/spellchecker/engine;1"]
     48                     .getService(Ci.mozISpellCheckingEngine);
     49 
     50    // Install de-DE dictionary.
     51    let de_DE = dir.clone();
     52    de_DE.append("de-DE");
     53    hunspell.addDirectory(de_DE);
     54 
     55    addMessageListener("destroy", () => hunspell.removeDirectory(de_DE));
     56    addMessageListener("de_DE-exists", () => de_DE.exists());
     57  });
     58  is(await script.sendQuery("de_DE-exists"), true,
     59     "true expected (de_DE directory should exist)");
     60 
     61  let textarea = document.getElementById("editor");
     62  let editor = SpecialPowers.wrap(textarea).editor;
     63  textarea.focus();
     64 
     65  maybeOnSpellCheck(textarea, () => {
     66    let isc = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(false);
     67    ok(isc, "Inline spell checker should exist after focus and spell check");
     68    let spellchecker = isc.spellChecker;
     69 
     70    spellchecker.setCurrentDictionaries(["en-US"]).then(() => {
     71      let currentDictionaries = spellchecker.getCurrentDictionaries();
     72 
     73      is(currentDictionaries.length, 1, "expected one dictionary");
     74      is(currentDictionaries[0], "en-US", "expected en-US");
     75      is(getMisspelledWords(editor), "heuteisteinguter", "some misspelled words expected: heuteisteinguter");
     76      spellchecker.setCurrentDictionaries(["en-US", "de-DE"]).then(() => {
     77        textarea.blur();
     78        textarea.focus();
     79        maybeOnSpellCheck(textarea, () => {
     80          currentDictionaries = spellchecker.getCurrentDictionaries();
     81 
     82          is(currentDictionaries.length, 2, "expected two dictionaries");
     83          is(currentDictionaries[0], "en-US", "expected en-US");
     84          is(currentDictionaries[1], "de-DE", "expected de-DE");
     85          is(getMisspelledWords(editor), "", "No misspelled words expected");
     86 
     87          spellchecker.setCurrentDictionaries(["de-DE"]).then(() => {
     88            textarea.blur();
     89            textarea.focus();
     90            maybeOnSpellCheck(textarea, async function() {
     91              currentDictionaries = spellchecker.getCurrentDictionaries();
     92 
     93              is(currentDictionaries.length, 1, "expected one dictionary");
     94              is(currentDictionaries[0], "de-DE", "expected de-DE");
     95              is(getMisspelledWords(editor), "todayisagoodday", "some misspelled words expected: todayisagoodday");
     96 
     97              // Remove the fake de_DE dictionary again.
     98              await script.sendQuery("destroy");
     99 
    100              // This will clear the content preferences and reset "spellchecker.dictionary".
    101              spellchecker.setCurrentDictionaries([]).then(() => {
    102                SimpleTest.finish();
    103              });
    104            });
    105          });
    106        });
    107      });
    108    });
    109  });
    110 }
    111 </script>
    112 </pre>
    113 </body>
    114 </html>