editor/composer/test/test_async_UpdateCurrentDictionary.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/composer/test/test_async_UpdateCurrentDictionary.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=856270
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 856270 - Async UpdateCurrentDictionary</title>
    1.11 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=856270">Mozilla Bug 856270</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content">
    1.18 +<textarea id="editor" spellcheck="true"></textarea>
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="text/javascript;version=1.8">
    1.22 +
    1.23 +SimpleTest.waitForExplicitFinish();
    1.24 +addLoadEvent(start);
    1.25 +
    1.26 +function start() {
    1.27 +  Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
    1.28 +  var textarea = document.getElementById("editor");
    1.29 +  textarea.focus();
    1.30 +
    1.31 +  onSpellCheck(textarea, function () {
    1.32 +    var isc = textarea.editor.getInlineSpellChecker(false);
    1.33 +    ok(isc, "Inline spell checker should exist after focus and spell check");
    1.34 +    var sc = isc.spellChecker;
    1.35 +    isnot(sc.GetCurrentDictionary(), lang,
    1.36 +          "Current dictionary should not be set yet.");
    1.37 +
    1.38 +    // First, set the lang attribute on the textarea, call Update, and make
    1.39 +    // sure the spell checker's language was updated appropriately.
    1.40 +    var lang = "en-US";
    1.41 +    textarea.setAttribute("lang", lang);
    1.42 +    sc.UpdateCurrentDictionary(function () {
    1.43 +      is(sc.GetCurrentDictionary(), lang,
    1.44 +         "UpdateCurrentDictionary should set the current dictionary.");
    1.45 +
    1.46 +      // Second, make some Update calls, but then do a Set.  The Set should
    1.47 +      // effectively cancel the Updates, but the Updates' callbacks should be
    1.48 +      // called nonetheless.
    1.49 +      var numCalls = 3;
    1.50 +      for (var i = 0; i < numCalls; i++) {
    1.51 +        sc.UpdateCurrentDictionary(function () {
    1.52 +          is(sc.GetCurrentDictionary(), "",
    1.53 +             "No dictionary should be active after Update.");
    1.54 +          if (--numCalls == 0)
    1.55 +            SimpleTest.finish();
    1.56 +        });
    1.57 +      }
    1.58 +      try {
    1.59 +        sc.SetCurrentDictionary("testing-XX");
    1.60 +      }
    1.61 +      catch (err) {
    1.62 +        // Set throws NS_ERROR_NOT_AVAILABLE because "testing-XX" isn't really
    1.63 +        // an available dictionary.
    1.64 +      }
    1.65 +      is(sc.GetCurrentDictionary(), "",
    1.66 +         "No dictionary should be active after Set.");
    1.67 +    });
    1.68 +  });
    1.69 +}
    1.70 +
    1.71 +</script>
    1.72 +</pre>
    1.73 +</body>
    1.74 +</html>
    1.75 +

mercurial