tor-browser

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

test_bug678842.html (3695B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=678842
      5 -->
      6 <head>
      7  <title>Test for Bug 678842</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=678842">Mozilla Bug 678842</a>
     13 <p id="display"></p>
     14 <iframe id="content"></iframe>
     15 
     16 </div>
     17 <pre id="test">
     18 <script class="testbody" type="text/javascript">
     19 
     20 /** Test for Bug 678842 */
     21 SimpleTest.waitForExplicitFinish();
     22 var content = document.getElementById("content");
     23 // load a subframe containing an editor with a defined unknown lang. At first
     24 // load, it will set dictionary to en-US. At second load, it will return current
     25 // dictionary. So, we can check, dictionary is correctly remembered between
     26 // loads.
     27 
     28 var firstLoad = true;
     29 var script;
     30 
     31 var loadListener = async function(evt) {
     32  if (firstLoad) {
     33    script = SpecialPowers.loadChromeScript(function() {
     34      /* eslint-env mozilla/chrome-script */
     35      // eslint-disable-next-line mozilla/use-services
     36      var dir = Cc["@mozilla.org/file/directory_service;1"]
     37                  .getService(Ci.nsIProperties)
     38                  .get("CurWorkD", Ci.nsIFile);
     39      dir.append("tests");
     40      dir.append("editor");
     41      dir.append("spellchecker");
     42      dir.append("tests");
     43 
     44      var hunspell = Cc["@mozilla.org/spellchecker/engine;1"]
     45                       .getService(Ci.mozISpellCheckingEngine);
     46 
     47      // Install en-GB dictionary.
     48      let en_GB = dir.clone();
     49      en_GB.append("en-GB");
     50      hunspell.addDirectory(en_GB);
     51 
     52      addMessageListener("en_GB-exists", () => en_GB.exists());
     53      addMessageListener("destroy", () => hunspell.removeDirectory(en_GB));
     54    });
     55    is(await script.sendQuery("en_GB-exists"), true,
     56       "true expected (en-GB directory should exist)");
     57  }
     58 
     59  var doc = evt.target.contentDocument;
     60  var elem = doc.getElementById("textarea");
     61  var editor = SpecialPowers.wrap(elem).editor;
     62  editor.setSpellcheckUserOverride(true);
     63  var inlineSpellChecker = editor.getInlineSpellChecker(true);
     64 
     65  const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     66    "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     67  );
     68  onSpellCheck(elem, async function() {
     69    let spellchecker = inlineSpellChecker.spellChecker;
     70    let currentDictionaries = spellchecker.getCurrentDictionaries();
     71    is(currentDictionaries.length, 1, "expected one dictionary");
     72    let currentDictionary = currentDictionaries[0];
     73 
     74    if (firstLoad) {
     75      firstLoad = false;
     76 
     77       // First time around, the dictionary defaults to the locale.
     78      is(currentDictionary, "en-US", "unexpected lang " + currentDictionary + " instead of en-US");
     79 
     80      // Select en-GB.
     81      spellchecker.setCurrentDictionaries(["en-GB"]).then(() => {
     82        content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug678842_subframe.html?firstload=false";
     83      });
     84    } else {
     85      is(currentDictionary, "en-GB", "unexpected lang " + currentDictionary + " instead of en-GB");
     86      content.removeEventListener("load", loadListener);
     87 
     88      // Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
     89      await script.sendQuery("destroy");
     90 
     91      // This will clear the content preferences and reset "spellchecker.dictionary".
     92      spellchecker.setCurrentDictionaries([]).then( () => {
     93        SimpleTest.finish();
     94      });
     95    }
     96  });
     97 };
     98 
     99 content.addEventListener("load", loadListener);
    100 
    101 content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug678842_subframe.html?firstload=true";
    102 
    103 </script>
    104 </pre>
    105 </body>
    106 </html>