tor-browser

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

test_bug717433.html (3830B)


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