summaryrefslogtreecommitdiffstats
path: root/editor/spellchecker/tests/test_async_UpdateCurrentDictionary.html
blob: d586eef72154ebe79c2b27cf05138b52298494da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=856270
-->
<head>
  <title>Test for Bug 856270 - Async UpdateCurrentDictionary</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=856270">Mozilla Bug 856270</a>
<p id="display"></p>
<div id="content">
<textarea id="editor" spellcheck="true"></textarea>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();
addLoadEvent(start);

function start() {
  var textarea = document.getElementById("editor");
  textarea.focus();

  const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
    "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
  )
  onSpellCheck(textarea, function() {
    var isc = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(false);
    ok(isc, "Inline spell checker should exist after focus and spell check");
    var sc = isc.spellChecker;

    sc.setCurrentDictionaries(["testing-XX"]).then(() => {
      is(true, false, "Setting a non-existent dictionary should fail");
    }, () => {
      let currentDictionaries = sc.getCurrentDictionaries();

      is(currentDictionaries.length, 0, "expected no dictionaries");
      // First, set the lang attribute on the textarea, call Update, and make
      // sure the spell checker's language was updated appropriately.
      var lang = "en-US";
      textarea.setAttribute("lang", lang);
      sc.UpdateCurrentDictionary(function() {
        currentDictionaries = sc.getCurrentDictionaries();
        is(currentDictionaries.length, 1, "expected one dictionary");
        is(sc.getCurrentDictionaries()[0], lang,
          "UpdateCurrentDictionary should set the current dictionary.");
        sc.setCurrentDictionaries([]).then(() => {
          SimpleTest.finish();
        });
      });
    });
  });
}
</script>
</pre>
</body>
</html>