|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=856270 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 856270 - Async UpdateCurrentDictionary</title> |
|
8 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=856270">Mozilla Bug 856270</a> |
|
13 <p id="display"></p> |
|
14 <div id="content"> |
|
15 <textarea id="editor" spellcheck="true"></textarea> |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script class="testbody" type="text/javascript;version=1.8"> |
|
19 |
|
20 SimpleTest.waitForExplicitFinish(); |
|
21 addLoadEvent(start); |
|
22 |
|
23 function start() { |
|
24 Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm"); |
|
25 var textarea = document.getElementById("editor"); |
|
26 textarea.focus(); |
|
27 |
|
28 onSpellCheck(textarea, function () { |
|
29 var isc = textarea.editor.getInlineSpellChecker(false); |
|
30 ok(isc, "Inline spell checker should exist after focus and spell check"); |
|
31 var sc = isc.spellChecker; |
|
32 isnot(sc.GetCurrentDictionary(), lang, |
|
33 "Current dictionary should not be set yet."); |
|
34 |
|
35 // First, set the lang attribute on the textarea, call Update, and make |
|
36 // sure the spell checker's language was updated appropriately. |
|
37 var lang = "en-US"; |
|
38 textarea.setAttribute("lang", lang); |
|
39 sc.UpdateCurrentDictionary(function () { |
|
40 is(sc.GetCurrentDictionary(), lang, |
|
41 "UpdateCurrentDictionary should set the current dictionary."); |
|
42 |
|
43 // Second, make some Update calls, but then do a Set. The Set should |
|
44 // effectively cancel the Updates, but the Updates' callbacks should be |
|
45 // called nonetheless. |
|
46 var numCalls = 3; |
|
47 for (var i = 0; i < numCalls; i++) { |
|
48 sc.UpdateCurrentDictionary(function () { |
|
49 is(sc.GetCurrentDictionary(), "", |
|
50 "No dictionary should be active after Update."); |
|
51 if (--numCalls == 0) |
|
52 SimpleTest.finish(); |
|
53 }); |
|
54 } |
|
55 try { |
|
56 sc.SetCurrentDictionary("testing-XX"); |
|
57 } |
|
58 catch (err) { |
|
59 // Set throws NS_ERROR_NOT_AVAILABLE because "testing-XX" isn't really |
|
60 // an available dictionary. |
|
61 } |
|
62 is(sc.GetCurrentDictionary(), "", |
|
63 "No dictionary should be active after Set."); |
|
64 }); |
|
65 }); |
|
66 } |
|
67 |
|
68 </script> |
|
69 </pre> |
|
70 </body> |
|
71 </html> |
|
72 |