summaryrefslogtreecommitdiffstats
path: root/chrome/browser/spellchecker_platform_engine_unittest.cc
blob: 060a0a51e17b3f1595d805af819e8920618d7700 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/utf_string_conversions.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "testing/gtest/include/gtest/gtest.h"

#if defined(OS_MACOSX)
#define MAYBE_IgnoreWords_EN_US IgnoreWords_EN_US
#define MAYBE_SpellCheckSuggestions_EN_US SpellCheckSuggestions_EN_US
#else
#define MAYBE_IgnoreWords_EN_US DISABLED_IgnoreWords_EN_US
#define MAYBE_SpellCheckSuggestions_EN_US DISABLED_SpellCheckSuggestions_EN_US
#endif

// Tests that words are properly ignored. Currently only enabled on OS X as it
// is the only platform to support ignoring words. Note that in this test, we
// supply a non-zero doc_tag, in order to test that ignored words are matched to
// the correct document.
TEST(PlatformSpellCheckTest, MAYBE_IgnoreWords_EN_US) {
  static const struct {
    // A misspelled word.
    const char* input;
    bool input_result;
  } kTestCases[] = {
    {"teh"},
    {"morblier"},
    {"watre"},
    {"noooen"},
  };

  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
    string16 word(UTF8ToUTF16(kTestCases[i].input));
    std::vector<string16> suggestions;
    size_t input_length = 0;
    if (kTestCases[i].input != NULL) {
      input_length = word.length();
    }

    int doc_tag = SpellCheckerPlatform::GetDocumentTag();
    bool result = SpellCheckerPlatform::CheckSpelling(word, doc_tag);

    // The word should show up as misspelled.
    EXPECT_EQ(kTestCases[i].input_result, result);

    // Ignore the word.
    SpellCheckerPlatform::IgnoreWord(word);

    // Spellcheck again.
    result = SpellCheckerPlatform::CheckSpelling(word, doc_tag);

    // The word should now show up as correctly spelled.
    EXPECT_EQ(!(kTestCases[i].input_result), result);

    // Close the docuemnt. Any words that we had previously ignored should no
    // longer be ignored and thus should show up as misspelled.
    SpellCheckerPlatform::CloseDocumentWithTag(doc_tag);

    // Spellcheck one more time.
    result = SpellCheckerPlatform::CheckSpelling(word, doc_tag);

    // The word should now show be spelled wrong again
    EXPECT_EQ(kTestCases[i].input_result, result);
  }
}  // Test IgnoreWords_EN_US

TEST(PlatformSpellCheckTest, MAYBE_SpellCheckSuggestions_EN_US) {
  static const struct {
    // A string to be tested.
    const wchar_t* input;

    // A suggested word that should occur.
    const wchar_t* suggested_word;
  } kTestCases[] = {    // A valid English word with a preceding whitespace
    // We need to have separate test cases here, since hunspell and the OS X
    // spellchecking service occasionally differ on what they consider a valid
    // suggestion for a given word, although these lists could likely be
    // integrated somewhat. The test cases for non-Mac are in
    // chrome/renderer/spellcheck_unittest.cc
    // These words come from the wikipedia page of the most commonly
    // misspelled words in english.
    // (http://en.wikipedia.org/wiki/Commonly_misspelled_words).
    // However, 10.6 loads multiple dictionaries and enables many non-English
    // dictionaries by default. As a result, we have removed from the list any
    // word that is marked as correct because it is correct in another
    // language.
    {L"absense", L"absence"},
    {L"acceptible", L"acceptable"},
    {L"accidentaly", L"accidentally"},
    {L"acheive", L"achieve"},
    {L"acknowlege", L"acknowledge"},
    {L"acquaintence", L"acquaintance"},
    {L"aquire", L"acquire"},
    {L"aquit", L"acquit"},
    {L"acrage", L"acreage"},
    {L"adultary", L"adultery"},
    {L"advertize", L"advertise"},
    {L"adviseable", L"advisable"},
    {L"alchohol", L"alcohol"},
    {L"alege", L"allege"},
    {L"allegaince", L"allegiance"},
    {L"allmost", L"almost"},
    // Ideally, this test should pass. It works in firefox, but not in hunspell
    // or OS X.
    // {L"alot", L"a lot"},
    {L"amatuer", L"amateur"},
    {L"ammend", L"amend"},
    {L"amung", L"among"},
    {L"anually", L"annually"},
    {L"apparant", L"apparent"},
    {L"artic", L"arctic"},
    {L"arguement", L"argument"},
    {L"athiest", L"atheist"},
    {L"athelete", L"athlete"},
    {L"avrage", L"average"},
    {L"awfull", L"awful"},
    {L"ballance", L"balance"},
    {L"basicly", L"basically"},
    {L"becuase", L"because"},
    {L"becomeing", L"becoming"},
    {L"befor", L"before"},
    {L"begining", L"beginning"},
    {L"beleive", L"believe"},
    {L"bellweather", L"bellwether"},
    {L"benifit", L"benefit"},
    {L"bouy", L"buoy"},
    {L"briliant", L"brilliant"},
    {L"burgler", L"burglar"},
    {L"camoflage", L"camouflage"},
    {L"carefull", L"careful"},
    {L"Carribean", L"Caribbean"},
    {L"catagory", L"category"},
    {L"cauhgt", L"caught"},
    {L"cieling", L"ceiling"},
    {L"cemetary", L"cemetery"},
    {L"certin", L"certain"},
    {L"changable", L"changeable"},
    {L"cheif", L"chief"},
    {L"citezen", L"citizen"},
    {L"collaegue", L"colleague"},
    {L"colum", L"column"},
    {L"comming", L"coming"},
    {L"commited", L"committed"},
    {L"compitition", L"competition"},
    {L"conceed", L"concede"},
    {L"congradulate", L"congratulate"},
    {L"consciencious", L"conscientious"},
    {L"concious", L"conscious"},
    {L"concensus", L"consensus"},
    {L"contraversy", L"controversy"},
    {L"conveniance", L"convenience"},
    {L"critecize", L"criticize"},
    {L"dacquiri", L"daiquiri"},
    {L"decieve", L"deceive"},
    {L"dicide", L"decide"},
    {L"definate", L"definite"},
    {L"definitly", L"definitely"},
    {L"desparate", L"desperate"},
    {L"develope", L"develop"},
    {L"diffrence", L"difference"},
    {L"disapear", L"disappear"},
    {L"disapoint", L"disappoint"},
    {L"disasterous", L"disastrous"},
    {L"disipline", L"discipline"},
    {L"drunkeness", L"drunkenness"},
    {L"dumbell", L"dumbbell"},
    {L"easely", L"easily"},
    {L"eigth", L"eight"},
    {L"embarass", L"embarrass"},
    {L"enviroment", L"environment"},
    {L"equiped", L"equipped"},
    {L"equiptment", L"equipment"},
    {L"exagerate", L"exaggerate"},
    {L"exellent", L"excellent"},
    {L"exsept", L"except"},
    {L"exercize", L"exercise"},
    {L"exilerate", L"exhilarate"},
    {L"existance", L"existence"},
    {L"experiance", L"experience"},
    {L"experament", L"experiment"},
    {L"explaination", L"explanation"},
    {L"facinating", L"fascinating"},
    {L"firey", L"fiery"},
    {L"finaly", L"finally"},
    {L"flourescent", L"fluorescent"},
    {L"foriegn", L"foreign"},
    {L"fourty", L"forty"},
    {L"foreward", L"forward"},
    {L"freind", L"friend"},
    {L"fundemental", L"fundamental"},
    {L"guage", L"gauge"},
    {L"generaly", L"generally"},
    {L"goverment", L"government"},
    {L"gratefull", L"grateful"},
    {L"garantee", L"guarantee"},
    {L"guidence", L"guidance"},
    {L"happyness", L"happiness"},
    {L"harrass", L"harass"},
    {L"heighth", L"height"},
    {L"heirarchy", L"hierarchy"},
    {L"humerous", L"humorous"},
    {L"hygene", L"hygiene"},
    {L"hipocrit", L"hypocrite"},
    {L"idenity", L"identity"},
    {L"ignorence", L"ignorance"},
    {L"imaginery", L"imaginary"},
    {L"immitate", L"imitate"},
    {L"immitation", L"imitation"},
    {L"imediately", L"immediately"},
    {L"incidently", L"incidentally"},
    {L"independant", L"independent"},
    {L"indispensible", L"indispensable"},
    {L"innoculate", L"inoculate"},
    {L"inteligence", L"intelligence"},
    {L"intresting", L"interesting"},
    {L"interuption", L"interruption"},
    {L"irrelevent", L"irrelevant"},
    {L"irritible", L"irritable"},
    {L"jellous", L"jealous"},
    {L"knowlege", L"knowledge"},
    {L"labratory", L"laboratory"},
    {L"lenght", L"length"},
    {L"liason", L"liaison"},
    {L"libary", L"library"},
    {L"lisence", L"license"},
    {L"lonelyness", L"loneliness"},
    {L"lieing", L"lying"},
    {L"maintenence", L"maintenance"},
    {L"manuever", L"maneuver"},
    {L"marrige", L"marriage"},
    {L"mathmatics", L"mathematics"},
    {L"medcine", L"medicine"},
    {L"miniture", L"miniature"},
    {L"minite", L"minute"},
    {L"mischevous", L"mischievous"},
    {L"mispell", L"misspell"},
    // Maybe this one should pass, as it works in hunspell, but not in firefox.
    // {L"misterius", L"mysterious"},
    {L"naturaly", L"naturally"},
    {L"neccessary", L"necessary"},
    {L"neice", L"niece"},
    {L"nieghbor", L"neighbor"},
    {L"nieghbour", L"neighbor"},
    {L"niether", L"neither"},
    {L"noticable", L"noticeable"},
    {L"occassion", L"occasion"},
    {L"occasionaly", L"occasionally"},
    {L"occurrance", L"occurrence"},
    {L"occured", L"occurred"},
    {L"ommision", L"omission"},
    {L"oppurtunity", L"opportunity"},
    {L"outragous", L"outrageous"},
    {L"parrallel", L"parallel"},
    {L"parliment", L"parliament"},
    {L"particurly", L"particularly"},
    {L"passtime", L"pastime"},
    {L"peculier", L"peculiar"},
    {L"percieve", L"perceive"},
    {L"pernament", L"permanent"},
    {L"perseverence", L"perseverance"},
    {L"personaly", L"personally"},
    {L"persaude", L"persuade"},
    {L"pichure", L"picture"},
    {L"peice", L"piece"},
    {L"plagerize", L"plagiarize"},
    {L"playright", L"playwright"},
    {L"plesant", L"pleasant"},
    {L"pollitical", L"political"},
    {L"posession", L"possession"},
    {L"potatos", L"potatoes"},
    {L"practicle", L"practical"},
    {L"preceed", L"precede"},
    {L"predjudice", L"prejudice"},
    {L"presance", L"presence"},
    {L"privelege", L"privilege"},
    // This one should probably work. It does in FF and Hunspell.
    // {L"probly", L"probably"},
    {L"proffesional", L"professional"},
    {L"promiss", L"promise"},
    {L"pronounciation", L"pronunciation"},
    {L"prufe", L"proof"},
    {L"psycology", L"psychology"},
    {L"publically", L"publicly"},
    {L"quanity", L"quantity"},
    {L"quarentine", L"quarantine"},
    {L"questionaire", L"questionnaire"},
    {L"readible", L"readable"},
    {L"realy", L"really"},
    {L"recieve", L"receive"},
    {L"reciept", L"receipt"},
    {L"reconize", L"recognize"},
    {L"recomend", L"recommend"},
    {L"refered", L"referred"},
    {L"referance", L"reference"},
    {L"relevent", L"relevant"},
    {L"religous", L"religious"},
    {L"repitition", L"repetition"},
    {L"restarant", L"restaurant"},
    {L"rythm", L"rhythm"},
    {L"rediculous", L"ridiculous"},
    {L"sacrefice", L"sacrifice"},
    {L"saftey", L"safety"},
    {L"sissors", L"scissors"},
    {L"secratary", L"secretary"},
    {L"seperate", L"separate"},
    {L"sargent", L"sergeant"},
    {L"shineing", L"shining"},
    {L"similer", L"similar"},
    {L"sinceerly", L"sincerely"},
    {L"speach", L"speech"},
    {L"stoping", L"stopping"},
    {L"strenght", L"strength"},
    {L"succesful", L"successful"},
    {L"supercede", L"supersede"},
    {L"surelly", L"surely"},
    {L"suprise", L"surprise"},
    {L"temperture", L"temperature"},
    {L"temprary", L"temporary"},
    {L"tommorrow", L"tomorrow"},
    {L"tounge", L"tongue"},
    {L"truely", L"truly"},
    {L"twelth", L"twelfth"},
    {L"tyrany", L"tyranny"},
    {L"underate", L"underrate"},
    {L"untill", L"until"},
    {L"unuseual", L"unusual"},
    {L"upholstry", L"upholstery"},
    {L"usible", L"usable"},
    {L"useing", L"using"},
    {L"usualy", L"usually"},
    {L"vaccuum", L"vacuum"},
    {L"vegatarian", L"vegetarian"},
    {L"vehical", L"vehicle"},
    {L"visious", L"vicious"},
    {L"villege", L"village"},
    {L"wierd", L"weird"},
    {L"wellcome", L"welcome"},
    {L"wellfare", L"welfare"},
    {L"wilfull", L"willful"},
    {L"withold", L"withhold"},
    {L"writting", L"writing"},
  };

  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
    std::vector<string16> suggestions;
    size_t input_length = 0;
    if (kTestCases[i].input != NULL) {
      input_length = wcslen(kTestCases[i].input);
    }
    bool result = SpellCheckerPlatform::CheckSpelling(
        WideToUTF16(kTestCases[i].input), 0);
    EXPECT_FALSE(result);

    SpellCheckerPlatform::FillSuggestionList(WideToUTF16(kTestCases[i].input),
                                             &suggestions);

    // Check if the suggested words occur.
    bool suggested_word_is_present = false;
    for (int j = 0; j < static_cast<int>(suggestions.size()); j++) {
      if (suggestions.at(j).compare(WideToUTF16(kTestCases[i].suggested_word))
          == 0) {
        suggested_word_is_present = true;
        break;
      }
    }

    EXPECT_TRUE(suggested_word_is_present);
  }
}