|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 |
|
4 <window title="Add and remove dictionaries test" |
|
5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
6 onload="RunTest();"> |
|
7 |
|
8 <script type="application/javascript" |
|
9 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
10 |
|
11 <script type="application/javascript"> |
|
12 <![CDATA[ |
|
13 SimpleTest.waitForExplicitFinish(); |
|
14 |
|
15 function getMisspelledWords(editor) { |
|
16 return editor.selectionController.getSelection(Components.interfaces.nsISelectionController.SELECTION_SPELLCHECK).toString(); |
|
17 } |
|
18 |
|
19 function getDictionaryList(editor) { |
|
20 var spellchecker = editor.getInlineSpellChecker(true).spellChecker; |
|
21 var o1 = {}; |
|
22 spellchecker.GetDictionaryList(o1, {}); |
|
23 return o1.value; |
|
24 } |
|
25 |
|
26 function getCurrentDictionary(editor) { |
|
27 var spellchecker = editor.getInlineSpellChecker(true).spellChecker; |
|
28 return spellchecker.GetCurrentDictionary(); |
|
29 } |
|
30 |
|
31 function setCurrentDictionary(editor, dictionary) { |
|
32 var spellchecker = editor.getInlineSpellChecker(true).spellChecker; |
|
33 spellchecker.SetCurrentDictionary(dictionary); |
|
34 } |
|
35 |
|
36 function RunTest() { |
|
37 var textbox = document.getElementById('textbox'); |
|
38 textbox.focus(); |
|
39 var editor = textbox.editor; |
|
40 |
|
41 var dir = Components.classes["@mozilla.org/file/directory_service;1"]. |
|
42 getService(Components.interfaces.nsIProperties). |
|
43 get("CurWorkD", Components.interfaces.nsIFile); |
|
44 dir.append("chrome"); |
|
45 dir.append("extensions"); |
|
46 dir.append("spellcheck"); |
|
47 dir.append("tests"); |
|
48 dir.append("chrome"); |
|
49 |
|
50 var hunspell = Components |
|
51 .classes["@mozilla.org/spellchecker/engine;1"] |
|
52 .getService(Components.interfaces.mozISpellCheckingEngine); |
|
53 |
|
54 // install base dictionary |
|
55 var base = dir.clone(); |
|
56 base.append("base"); |
|
57 ok(base.exists()); |
|
58 hunspell.addDirectory(base); |
|
59 |
|
60 // install map dictionary |
|
61 var map = dir.clone(); |
|
62 map.append("map"); |
|
63 ok(map.exists()); |
|
64 hunspell.addDirectory(map); |
|
65 |
|
66 Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm"); |
|
67 onSpellCheck(textbox, function () { |
|
68 |
|
69 // test that base and map dictionaries are available |
|
70 var dicts = getDictionaryList(editor); |
|
71 isnot(dicts.indexOf("base_utf"), -1, "base is available"); |
|
72 isnot(dicts.indexOf("maputf"), -1, "map is available"); |
|
73 |
|
74 // select base dictionary |
|
75 setCurrentDictionary(editor, "base_utf"); |
|
76 |
|
77 onSpellCheck(textbox, function () { |
|
78 // test that base dictionary is in use |
|
79 is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings"); |
|
80 is(getCurrentDictionary(editor), "base_utf", "current dictionary"); |
|
81 |
|
82 // select map dictionary |
|
83 setCurrentDictionary(editor, "maputf"); |
|
84 |
|
85 onSpellCheck(textbox, function () { |
|
86 // test that map dictionary is in use |
|
87 is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings"); |
|
88 is(getCurrentDictionary(editor), "maputf", "current dictionary"); |
|
89 |
|
90 // uninstall map dictionary |
|
91 hunspell.removeDirectory(map); |
|
92 |
|
93 onSpellCheck(textbox, function () { |
|
94 // test that map dictionary is not in use |
|
95 isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings"); |
|
96 isnot(getCurrentDictionary(editor), "maputf", "current dictionary"); |
|
97 |
|
98 // test that base dictionary is available and map dictionary is unavailable |
|
99 var dicts = getDictionaryList(editor); |
|
100 isnot(dicts.indexOf("base_utf"), -1, "base is available"); |
|
101 is(dicts.indexOf("maputf"), -1, "map is unavailable"); |
|
102 |
|
103 // uninstall base dictionary |
|
104 hunspell.removeDirectory(base); |
|
105 |
|
106 onSpellCheck(textbox, function () { |
|
107 SimpleTest.finish(); |
|
108 }); |
|
109 }); |
|
110 }); |
|
111 }); |
|
112 }); |
|
113 } |
|
114 ]]> |
|
115 </script> |
|
116 <textbox id="textbox" spellcheck="true" value="created imply Frühstück tomorrow qwertyu"/> |
|
117 </window> |