Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: chrome/browser/spellchecker_platform_engine_unittest.cc

Issue 395007: Move Mac to using renderer spellchecker. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: ui test fix Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/spellchecker_platform_engine.h ('k') | chrome/browser/spellchecker_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/string_util.h"
6 #include "chrome/browser/spellchecker_platform_engine.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 #if defined(OS_MACOSX)
10 #define MAYBE_IgnoreWords_EN_US IgnoreWords_EN_US
11 #else
12 #define MAYBE_IgnoreWords_EN_US DISABLED_IgnoreWords_EN_US
13 #endif
14
15 // Tests that words are properly ignored. Currently only enabled on OS X as it
16 // is the only platform to support ignoring words. Note that in this test, we
17 // supply a non-zero doc_tag, in order to test that ignored words are matched to
18 // the correct document.
19 TEST(PlatformSpellCheckTest, MAYBE_IgnoreWords_EN_US) {
20 static const struct {
21 // A misspelled word.
22 const char* input;
23 bool input_result;
24 } kTestCases[] = {
25 {"teh"},
26 {"moer"},
27 {"watre"},
28 {"noen"},
29 };
30
31 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
32 string16 word(UTF8ToUTF16(kTestCases[i].input));
33 std::vector<string16> suggestions;
34 size_t input_length = 0;
35 if (kTestCases[i].input != NULL) {
36 input_length = word.length();
37 }
38
39 int doc_tag = SpellCheckerPlatform::GetDocumentTag();
40 bool result = SpellCheckerPlatform::CheckSpelling(word, doc_tag);
41
42 // The word should show up as misspelled.
43 EXPECT_EQ(kTestCases[i].input_result, result);
44
45 // Ignore the word.
46 SpellCheckerPlatform::IgnoreWord(word);
47
48 // Spellcheck again.
49 result = SpellCheckerPlatform::CheckSpelling(word, doc_tag);
50
51 // The word should now show up as correctly spelled.
52 EXPECT_EQ(!(kTestCases[i].input_result), result);
53
54 // Close the docuemnt. Any words that we had previously ignored should no
55 // longer be ignored and thus should show up as misspelled.
56 SpellCheckerPlatform::CloseDocumentWithTag(doc_tag);
57
58 // Spellcheck one more time.
59 result = SpellCheckerPlatform::CheckSpelling(word, doc_tag);
60
61 // The word should now show be spelled wrong again
62 EXPECT_EQ(kTestCases[i].input_result, result);
63 }
64 } // Test IgnoreWords_EN_US
65
66 #if defined(OS_MACOSX)
67 TEST(PlatformSpellCheckTest, SpellCheckSuggestions_EN_US) {
68 static const struct {
69 // A string to be tested.
70 const wchar_t* input;
71
72 // A suggested word that should occur.
73 const wchar_t* suggested_word;
74 } kTestCases[] = { // A valid English word with a preceding whitespace
75 // We need to have separate test cases here, since hunspell and the OS X
76 // spellchecking service occasionally differ on what they consider a valid
77 // suggestion for a given word, although these lists could likely be
78 // integrated somewhat. The test cases for non-Mac are in
79 // chrome/renderer/spellcheck_unittest.cc
80 // These words come from the wikipedia page of the most commonly
81 // misspelled words in english.
82 // (http://en.wikipedia.org/wiki/Commonly_misspelled_words).
83 {L"absense", L"absence"},
84 {L"acceptible", L"acceptable"},
85 {L"accidentaly", L"accidentally"},
86 {L"accomodate", L"accommodate"},
87 {L"acheive", L"achieve"},
88 {L"acknowlege", L"acknowledge"},
89 {L"acquaintence", L"acquaintance"},
90 {L"aquire", L"acquire"},
91 {L"aquit", L"acquit"},
92 {L"acrage", L"acreage"},
93 {L"adress", L"address"},
94 {L"adultary", L"adultery"},
95 {L"advertize", L"advertise"},
96 {L"adviseable", L"advisable"},
97 {L"agression", L"aggression"},
98 {L"alchohol", L"alcohol"},
99 {L"alege", L"allege"},
100 {L"allegaince", L"allegiance"},
101 {L"allmost", L"almost"},
102 // Ideally, this test should pass. It works in firefox, but not in hunspell
103 // or OS X.
104 // {L"alot", L"a lot"},
105 {L"amatuer", L"amateur"},
106 {L"ammend", L"amend"},
107 {L"amung", L"among"},
108 {L"anually", L"annually"},
109 {L"apparant", L"apparent"},
110 {L"artic", L"arctic"},
111 {L"arguement", L"argument"},
112 {L"athiest", L"atheist"},
113 {L"athelete", L"athlete"},
114 {L"avrage", L"average"},
115 {L"awfull", L"awful"},
116 {L"ballance", L"balance"},
117 {L"basicly", L"basically"},
118 {L"becuase", L"because"},
119 {L"becomeing", L"becoming"},
120 {L"befor", L"before"},
121 {L"begining", L"beginning"},
122 {L"beleive", L"believe"},
123 {L"bellweather", L"bellwether"},
124 {L"benifit", L"benefit"},
125 {L"bouy", L"buoy"},
126 {L"briliant", L"brilliant"},
127 {L"burgler", L"burglar"},
128 {L"camoflage", L"camouflage"},
129 {L"carrer", L"career"},
130 {L"carefull", L"careful"},
131 {L"Carribean", L"Caribbean"},
132 {L"catagory", L"category"},
133 {L"cauhgt", L"caught"},
134 {L"cieling", L"ceiling"},
135 {L"cemetary", L"cemetery"},
136 {L"certin", L"certain"},
137 {L"changable", L"changeable"},
138 {L"cheif", L"chief"},
139 {L"citezen", L"citizen"},
140 {L"collaegue", L"colleague"},
141 {L"colum", L"column"},
142 {L"comming", L"coming"},
143 {L"commited", L"committed"},
144 {L"compitition", L"competition"},
145 {L"conceed", L"concede"},
146 {L"congradulate", L"congratulate"},
147 {L"consciencious", L"conscientious"},
148 {L"concious", L"conscious"},
149 {L"concensus", L"consensus"},
150 {L"contraversy", L"controversy"},
151 {L"conveniance", L"convenience"},
152 {L"critecize", L"criticize"},
153 {L"dacquiri", L"daiquiri"},
154 {L"decieve", L"deceive"},
155 {L"dicide", L"decide"},
156 {L"definate", L"definite"},
157 {L"definitly", L"definitely"},
158 {L"deposite", L"deposit"},
159 {L"desparate", L"desperate"},
160 {L"develope", L"develop"},
161 {L"diffrence", L"difference"},
162 {L"dilema", L"dilemma"},
163 {L"disapear", L"disappear"},
164 {L"disapoint", L"disappoint"},
165 {L"disasterous", L"disastrous"},
166 {L"disipline", L"discipline"},
167 {L"drunkeness", L"drunkenness"},
168 {L"dumbell", L"dumbbell"},
169 {L"durring", L"during"},
170 {L"easely", L"easily"},
171 {L"eigth", L"eight"},
172 {L"embarass", L"embarrass"},
173 {L"enviroment", L"environment"},
174 {L"equiped", L"equipped"},
175 {L"equiptment", L"equipment"},
176 {L"exagerate", L"exaggerate"},
177 {L"excede", L"exceed"},
178 {L"exellent", L"excellent"},
179 {L"exsept", L"except"},
180 {L"exercize", L"exercise"},
181 {L"exilerate", L"exhilarate"},
182 {L"existance", L"existence"},
183 {L"experiance", L"experience"},
184 {L"experament", L"experiment"},
185 {L"explaination", L"explanation"},
186 {L"extreem", L"extreme"},
187 {L"familier", L"familiar"},
188 {L"facinating", L"fascinating"},
189 {L"firey", L"fiery"},
190 {L"finaly", L"finally"},
191 {L"flourescent", L"fluorescent"},
192 {L"foriegn", L"foreign"},
193 {L"fourty", L"forty"},
194 {L"foreward", L"forward"},
195 {L"freind", L"friend"},
196 {L"fullfil", L"fulfill"},
197 {L"fundemental", L"fundamental"},
198 {L"guage", L"gauge"},
199 {L"generaly", L"generally"},
200 {L"goverment", L"government"},
201 {L"grammer", L"grammar"},
202 {L"gratefull", L"grateful"},
203 {L"garantee", L"guarantee"},
204 {L"guidence", L"guidance"},
205 {L"happyness", L"happiness"},
206 {L"harrass", L"harass"},
207 {L"heighth", L"height"},
208 {L"heirarchy", L"hierarchy"},
209 {L"humerous", L"humorous"},
210 {L"hygene", L"hygiene"},
211 {L"hipocrit", L"hypocrite"},
212 {L"idenity", L"identity"},
213 {L"ignorence", L"ignorance"},
214 {L"imaginery", L"imaginary"},
215 {L"immitate", L"imitate"},
216 {L"immitation", L"imitation"},
217 {L"imediately", L"immediately"},
218 {L"incidently", L"incidentally"},
219 {L"independant", L"independent"},
220 {L"indispensible", L"indispensable"},
221 {L"innoculate", L"inoculate"},
222 {L"inteligence", L"intelligence"},
223 {L"intresting", L"interesting"},
224 {L"interuption", L"interruption"},
225 {L"irrelevent", L"irrelevant"},
226 {L"irritible", L"irritable"},
227 {L"iland", L"island"},
228 {L"jellous", L"jealous"},
229 {L"knowlege", L"knowledge"},
230 {L"labratory", L"laboratory"},
231 {L"liesure", L"leisure"},
232 {L"lenght", L"length"},
233 {L"liason", L"liaison"},
234 {L"libary", L"library"},
235 {L"lisence", L"license"},
236 {L"lonelyness", L"loneliness"},
237 {L"lieing", L"lying"},
238 {L"maintenence", L"maintenance"},
239 {L"manuever", L"maneuver"},
240 {L"marrige", L"marriage"},
241 {L"mathmatics", L"mathematics"},
242 {L"medcine", L"medicine"},
243 {L"medeval", L"medieval"},
244 {L"momento", L"memento"},
245 {L"millenium", L"millennium"},
246 {L"miniture", L"miniature"},
247 {L"minite", L"minute"},
248 {L"mischevous", L"mischievous"},
249 {L"mispell", L"misspell"},
250 // Maybe this one should pass, as it works in hunspell, but not in firefox.
251 // {L"misterius", L"mysterious"},
252 {L"naturaly", L"naturally"},
253 {L"neccessary", L"necessary"},
254 {L"neice", L"niece"},
255 {L"nieghbor", L"neighbor"},
256 {L"nieghbour", L"neighbor"},
257 {L"niether", L"neither"},
258 {L"noticable", L"noticeable"},
259 {L"occassion", L"occasion"},
260 {L"occasionaly", L"occasionally"},
261 {L"occurrance", L"occurrence"},
262 {L"occured", L"occurred"},
263 {L"oficial", L"official"},
264 {L"offen", L"often"},
265 {L"ommision", L"omission"},
266 {L"oprate", L"operate"},
267 {L"oppurtunity", L"opportunity"},
268 {L"orignal", L"original"},
269 {L"outragous", L"outrageous"},
270 {L"parrallel", L"parallel"},
271 {L"parliment", L"parliament"},
272 {L"particurly", L"particularly"},
273 {L"passtime", L"pastime"},
274 {L"peculier", L"peculiar"},
275 {L"percieve", L"perceive"},
276 {L"pernament", L"permanent"},
277 {L"perseverence", L"perseverance"},
278 {L"personaly", L"personally"},
279 {L"personell", L"personnel"},
280 {L"persaude", L"persuade"},
281 {L"pichure", L"picture"},
282 {L"peice", L"piece"},
283 {L"plagerize", L"plagiarize"},
284 {L"playright", L"playwright"},
285 {L"plesant", L"pleasant"},
286 {L"pollitical", L"political"},
287 {L"posession", L"possession"},
288 {L"potatos", L"potatoes"},
289 {L"practicle", L"practical"},
290 {L"preceed", L"precede"},
291 {L"predjudice", L"prejudice"},
292 {L"presance", L"presence"},
293 {L"privelege", L"privilege"},
294 // This one should probably work. It does in FF and Hunspell.
295 // {L"probly", L"probably"},
296 {L"proffesional", L"professional"},
297 {L"professer", L"professor"},
298 {L"promiss", L"promise"},
299 {L"pronounciation", L"pronunciation"},
300 {L"prufe", L"proof"},
301 {L"psycology", L"psychology"},
302 {L"publically", L"publicly"},
303 {L"quanity", L"quantity"},
304 {L"quarentine", L"quarantine"},
305 {L"questionaire", L"questionnaire"},
306 {L"readible", L"readable"},
307 {L"realy", L"really"},
308 {L"recieve", L"receive"},
309 {L"reciept", L"receipt"},
310 {L"reconize", L"recognize"},
311 {L"recomend", L"recommend"},
312 {L"refered", L"referred"},
313 {L"referance", L"reference"},
314 {L"relevent", L"relevant"},
315 {L"religous", L"religious"},
316 {L"repitition", L"repetition"},
317 {L"restarant", L"restaurant"},
318 {L"rythm", L"rhythm"},
319 {L"rediculous", L"ridiculous"},
320 {L"sacrefice", L"sacrifice"},
321 {L"saftey", L"safety"},
322 {L"sissors", L"scissors"},
323 {L"secratary", L"secretary"},
324 {L"sieze", L"seize"},
325 {L"seperate", L"separate"},
326 {L"sargent", L"sergeant"},
327 {L"shineing", L"shining"},
328 {L"similer", L"similar"},
329 {L"sinceerly", L"sincerely"},
330 {L"speach", L"speech"},
331 {L"stoping", L"stopping"},
332 {L"strenght", L"strength"},
333 {L"succede", L"succeed"},
334 {L"succesful", L"successful"},
335 {L"supercede", L"supersede"},
336 {L"surelly", L"surely"},
337 {L"suprise", L"surprise"},
338 {L"temperture", L"temperature"},
339 {L"temprary", L"temporary"},
340 {L"tomatos", L"tomatoes"},
341 {L"tommorrow", L"tomorrow"},
342 {L"tounge", L"tongue"},
343 {L"truely", L"truly"},
344 {L"twelth", L"twelfth"},
345 {L"tyrany", L"tyranny"},
346 {L"underate", L"underrate"},
347 {L"untill", L"until"},
348 {L"unuseual", L"unusual"},
349 {L"upholstry", L"upholstery"},
350 {L"usible", L"usable"},
351 {L"useing", L"using"},
352 {L"usualy", L"usually"},
353 {L"vaccuum", L"vacuum"},
354 {L"vegatarian", L"vegetarian"},
355 {L"vehical", L"vehicle"},
356 {L"visious", L"vicious"},
357 {L"villege", L"village"},
358 {L"wierd", L"weird"},
359 {L"wellcome", L"welcome"},
360 {L"wellfare", L"welfare"},
361 {L"wilfull", L"willful"},
362 {L"withold", L"withhold"},
363 {L"writting", L"writing"},
364 };
365
366 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
367 std::vector<string16> suggestions;
368 size_t input_length = 0;
369 if (kTestCases[i].input != NULL) {
370 input_length = wcslen(kTestCases[i].input);
371 }
372 bool result = SpellCheckerPlatform::CheckSpelling(
373 WideToUTF16(kTestCases[i].input), 0);
374 EXPECT_FALSE(result);
375
376 SpellCheckerPlatform::FillSuggestionList(WideToUTF16(kTestCases[i].input),
377 &suggestions);
378
379 // Check if the suggested words occur.
380 bool suggested_word_is_present = false;
381 for (int j=0; j < static_cast<int>(suggestions.size()); j++) {
382 if (suggestions.at(j).compare(WideToUTF16(kTestCases[i].suggested_word))
383 == 0) {
384 suggested_word_is_present = true;
385 break;
386 }
387 }
388
389 EXPECT_TRUE(suggested_word_is_present);
390 }
391 }
392
393 #endif // defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker_platform_engine.h ('k') | chrome/browser/spellchecker_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698