tor-browser

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

test_bug697981.html (4964B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=697981
      5 -->
      6 <head>
      7  <title>Test for Bug 697981</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=697981">Mozilla Bug 697981</a>
     13 <p id="display"></p>
     14 </div>
     15 
     16 <textarea id="de-DE" lang="de-DE" onfocus="deFocus()">German heute ist ein guter Tag</textarea>
     17 <textarea id="en-US" lang="en-US" onfocus="enFocus()">Nogoodword today is a nice day</textarea>
     18 
     19 <pre id="test">
     20 <script class="testbody" type="text/javascript">
     21 
     22 function getMisspelledWords(editor) {
     23  return editor.selectionController.getSelection(SpecialPowers.Ci.nsISelectionController.SELECTION_SPELLCHECK).toString();
     24 }
     25 
     26 var elem_de;
     27 var editor_de;
     28 var script;
     29 
     30 var { maybeOnSpellCheck, onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     31  "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     32 );
     33 
     34 /** Test for Bug 697981 */
     35 SimpleTest.waitForExplicitFinish();
     36 SimpleTest.waitForFocus(async function() {
     37  script = SpecialPowers.loadChromeScript(function() {
     38    /* eslint-env mozilla/chrome-script */
     39    // eslint-disable-next-line mozilla/use-services
     40    var dir = Cc["@mozilla.org/file/directory_service;1"]
     41                .getService(Ci.nsIProperties)
     42                .get("CurWorkD", Ci.nsIFile);
     43    dir.append("tests");
     44    dir.append("editor");
     45    dir.append("spellchecker");
     46    dir.append("tests");
     47 
     48    var hunspell = Cc["@mozilla.org/spellchecker/engine;1"]
     49                     .getService(Ci.mozISpellCheckingEngine);
     50 
     51    // Install de-DE dictionary.
     52    var de_DE = dir.clone();
     53    de_DE.append("de-DE");
     54    hunspell.addDirectory(de_DE);
     55 
     56    addMessageListener("de_DE-exists", () => de_DE.exists());
     57    addMessageListener("destroy", () => hunspell.removeDirectory(de_DE));
     58  });
     59  is(await script.sendQuery("de_DE-exists"), true,
     60     "true expected (de_DE directory should exist)");
     61 
     62  document.getElementById("de-DE").focus();
     63 });
     64 
     65 function deFocus() {
     66  elem_de = document.getElementById("de-DE");
     67  editor_de = SpecialPowers.wrap(elem_de).editor;
     68  editor_de.setSpellcheckUserOverride(true);
     69  var inlineSpellChecker = editor_de.getInlineSpellChecker(true);
     70 
     71  maybeOnSpellCheck(elem_de, function() {
     72    var spellchecker = inlineSpellChecker.spellChecker;
     73    try {
     74      var currentDictionaries = spellchecker.getCurrentDictionaries();
     75    } catch (e) {}
     76 
     77    // Check that the German dictionary is loaded and that the spell check has worked.
     78    is(currentDictionaries.length, 1, "expected one dictionary");
     79    is(currentDictionaries[0], "de-DE", "expected de-DE");
     80    is(getMisspelledWords(editor_de), "German", "one misspelled word expected: German");
     81 
     82    // Now focus the other textarea, which requires English spelling.
     83    document.getElementById("en-US").focus();
     84  });
     85 }
     86 
     87 function enFocus() {
     88  var elem_en = document.getElementById("en-US");
     89  var editor_en = SpecialPowers.wrap(elem_en).editor;
     90  editor_en.setSpellcheckUserOverride(true);
     91  var inlineSpellChecker = editor_en.getInlineSpellChecker(true);
     92 
     93  onSpellCheck(elem_en, async function() {
     94    let spellchecker = inlineSpellChecker.spellChecker;
     95    let currentDictionaries = spellchecker.getCurrentDictionaries();
     96 
     97    // Check that the English dictionary is loaded and that the spell check has worked.
     98    is(currentDictionaries.length, 1, "expected one dictionary");
     99    is(currentDictionaries[0], "en-US", "expected en-US");
    100    is(getMisspelledWords(editor_en), "Nogoodword", "one misspelled word expected: Nogoodword");
    101 
    102    // So far all was boring. The important thing is whether the spell check result
    103    // in the de-DE editor is still the same. After losing focus, no spell check
    104    // updates should take place there.
    105    is(getMisspelledWords(editor_de), "German", "one misspelled word expected: German");
    106 
    107    // Remove the fake de_DE dictionary again.
    108    await script.sendQuery("destroy");
    109 
    110    // Focus again, so the spelling gets updated, but before we need to kill the focus handler.
    111    elem_de.onfocus = null;
    112    elem_de.blur();
    113    elem_de.focus();
    114 
    115    // After removal, the de_DE editor should refresh the spelling with en-US.
    116    maybeOnSpellCheck(elem_de, function() {
    117      spellchecker = inlineSpellChecker.spellChecker;
    118      try {
    119        currentDictionaries = spellchecker.getCurrentDictionaries();
    120      } catch (e) {}
    121 
    122      // Check that the default English dictionary is loaded and that the spell check has worked.
    123      is(currentDictionaries.length, 1, "expected one dictionary");
    124      is(currentDictionaries[0], "en-US", "expected en-US");
    125      // eslint-disable-next-line no-useless-concat
    126      is(getMisspelledWords(editor_de), "heute" + "ist" + "ein" + "guter",
    127         "some misspelled words expected: heute ist ein guter");
    128 
    129      SimpleTest.finish();
    130    });
    131  });
    132 }
    133 
    134 </script>
    135 </pre>
    136 </body>
    137 </html>