tor-browser

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

test_bug1204147.html (4476B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1204147
      5 -->
      6 <head>
      7  <title>Test for Bug 1204147</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=1204147">Mozilla Bug 1204147</a>
     13 <p id="display"></p>
     14 <iframe id="content"></iframe>
     15 </div>
     16 
     17 <pre id="test">
     18 <script class="testbody" type="text/javascript">
     19 
     20 /** Test for Bug 1204147 */
     21 SimpleTest.waitForExplicitFinish();
     22 var content = document.getElementById("content");
     23 // Load a subframe containing an editor with using "en-GB". At first
     24 // load, it will set the dictionary to "en-GB". The bug was that a content preference
     25 // was also created. At second load, we check the dictionary for another element,
     26 // one that should use "en-US". With the bug corrected, we get "en-US", before
     27 // we got "en-GB" from the content preference.
     28 
     29 var firstLoad = true;
     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      let 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;
     62  if (firstLoad) {
     63    elem = doc.getElementById("en-GB");
     64  } else {
     65    elem = doc.getElementById("en-US");
     66  }
     67 
     68  var editor = SpecialPowers.wrap(elem).editor;
     69  editor.setSpellcheckUserOverride(true);
     70  var inlineSpellChecker = editor.getInlineSpellChecker(true);
     71 
     72  const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     73    "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     74  );
     75  onSpellCheck(elem, async function() {
     76    let spellchecker = inlineSpellChecker.spellChecker;
     77    let currentDictionaries = spellchecker.getCurrentDictionaries();
     78    is(currentDictionaries.length, 1, "expected one dictionary");
     79    let currentDictionary = currentDictionaries[0];
     80    if (firstLoad) {
     81      firstLoad = false;
     82 
     83       // First time around, the element's language should be used.
     84      is(currentDictionary, "en-GB", "unexpected lang " + currentDictionary + " instead of en-GB");
     85 
     86      // Note that on second load, we load a different page, which does NOT have the trouble-causing
     87      // contenteditable in it. Sadly, loading the same page with the trouble-maker in it
     88      // doesn't allow the retrieval of the spell check dictionary used for the element,
     89      // because the trouble-maker causes the 'global' spell check dictionary to be set to "en-GB"
     90      // (since it picks the first one from the list) before we have the chance to retrieve
     91      // the dictionary for the element (which happens asynchonously after the spell check has completed).
     92      content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1204147_subframe2.html?firstload=false";
     93    } else {
     94      // Second time around, the element should default to en-US.
     95      // Without the fix, the first run sets the content preference to en-GB for the whole site.
     96      is(currentDictionary, "en-US", "unexpected lang " + currentDictionary + " instead of en-US");
     97      content.removeEventListener("load", loadListener);
     98 
     99      // Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
    100      await script.sendQuery("destroy");
    101 
    102      // Reset the preference, so the last value we set doesn't collide with the next test.
    103      SimpleTest.finish();
    104    }
    105  });
    106 };
    107 
    108 content.addEventListener("load", loadListener);
    109 
    110 content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1204147_subframe.html?firstload=true";
    111 
    112 </script>
    113 </pre>
    114 </body>
    115 </html>