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

Side by Side Diff: chrome/browser/spellchecker/spellchecker_mac_unittest.cc

Issue 8890022: Remove Hunspell on OS X - step 2 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rename unit tests Created 9 years 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" 7 #include "chrome/browser/spellchecker/spellchecker_mac.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 // Tests that words are properly ignored. Currently only enabled on OS X as it 10 // Tests that words are properly ignored. Currently only enabled on OS X as it
11 // is the only platform to support ignoring words. Note that in this test, we 11 // is the only platform to support ignoring words. Note that in this test, we
12 // supply a non-zero doc_tag, in order to test that ignored words are matched to 12 // supply a non-zero doc_tag, in order to test that ignored words are matched to
13 // the correct document. 13 // the correct document.
14 TEST(PlatformSpellCheckTest, IgnoreWords_EN_US) { 14 TEST(SpellCheckerMacTest, IgnoreWords_EN_US) {
15 const char* kTestCases[] = { 15 const char* kTestCases[] = {
16 "teh", 16 "teh",
17 "morblier", 17 "morblier",
18 "watre", 18 "watre",
19 "noooen", 19 "noooen",
20 }; 20 };
21 21
22 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 22 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
23 const string16 word(ASCIIToUTF16(kTestCases[i])); 23 const string16 word(ASCIIToUTF16(kTestCases[i]));
24 const int doc_tag = SpellCheckerPlatform::GetDocumentTag(); 24 const int doc_tag = SpellCheckerMac::GetDocumentTag();
25 25
26 // The word should show up as misspelled. 26 // The word should show up as misspelled.
27 EXPECT_FALSE(SpellCheckerPlatform::CheckSpelling(word, doc_tag)) << word; 27 EXPECT_FALSE(SpellCheckerMac::CheckSpelling(word, doc_tag)) << word;
28 28
29 // Ignore the word. 29 // Ignore the word.
30 SpellCheckerPlatform::IgnoreWord(word); 30 SpellCheckerMac::IgnoreWord(word);
31 31
32 // The word should now show up as correctly spelled. 32 // The word should now show up as correctly spelled.
33 EXPECT_TRUE(SpellCheckerPlatform::CheckSpelling(word, doc_tag)) << word; 33 EXPECT_TRUE(SpellCheckerMac::CheckSpelling(word, doc_tag)) << word;
34 34
35 // Close the docuemnt. Any words that we had previously ignored should no 35 // Close the docuemnt. Any words that we had previously ignored should no
36 // longer be ignored and thus should show up as misspelled. 36 // longer be ignored and thus should show up as misspelled.
37 SpellCheckerPlatform::CloseDocumentWithTag(doc_tag); 37 SpellCheckerMac::CloseDocumentWithTag(doc_tag);
38 38
39 // The word should now show be spelled wrong again 39 // The word should now show be spelled wrong again
40 EXPECT_FALSE(SpellCheckerPlatform::CheckSpelling(word, doc_tag)) << word; 40 EXPECT_FALSE(SpellCheckerMac::CheckSpelling(word, doc_tag)) << word;
41 } 41 }
42 } // Test IgnoreWords_EN_US 42 } // Test IgnoreWords_EN_US
43 43
44 TEST(PlatformSpellCheckTest, SpellCheckSuggestions_EN_US) { 44 TEST(SpellCheckerMacTest, SpellCheckSuggestions_EN_US) {
45 static const struct { 45 static const struct {
46 const char* input; // A string to be tested. 46 const char* input; // A string to be tested.
47 const char* suggested_word; // A suggested word that should occur. 47 const char* suggested_word; // A suggested word that should occur.
48 } kTestCases[] = { 48 } kTestCases[] = {
49 // We need to have separate test cases here, since hunspell and the OS X 49 // We need to have separate test cases here, since hunspell and the OS X
50 // spellchecking service occasionally differ on what they consider a valid 50 // spellchecking service occasionally differ on what they consider a valid
51 // suggestion for a given word, although these lists could likely be 51 // suggestion for a given word, although these lists could likely be
52 // integrated somewhat. The test cases for non-Mac are in 52 // integrated somewhat. The test cases for non-Mac are in
53 // chrome/renderer/spellcheck_unittest.cc 53 // chrome/renderer/spellcheck_unittest.cc
54 // These words come from the wikipedia page of the most commonly 54 // These words come from the wikipedia page of the most commonly
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 {"wierd", "weird"}, 309 {"wierd", "weird"},
310 {"wellcome", "welcome"}, 310 {"wellcome", "welcome"},
311 {"wellfare", "welfare"}, 311 {"wellfare", "welfare"},
312 {"wilfull", "willful"}, 312 {"wilfull", "willful"},
313 {"withold", "withhold"}, 313 {"withold", "withhold"},
314 {"writting", "writing"}, 314 {"writting", "writing"},
315 }; 315 };
316 316
317 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 317 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
318 const string16 word(ASCIIToUTF16(kTestCases[i].input)); 318 const string16 word(ASCIIToUTF16(kTestCases[i].input));
319 EXPECT_FALSE(SpellCheckerPlatform::CheckSpelling(word, 0)) << word; 319 EXPECT_FALSE(SpellCheckerMac::CheckSpelling(word, 0)) << word;
320 320
321 // Check if the suggested words occur. 321 // Check if the suggested words occur.
322 std::vector<string16> suggestions; 322 std::vector<string16> suggestions;
323 SpellCheckerPlatform::FillSuggestionList(word, &suggestions); 323 SpellCheckerMac::FillSuggestionList(word, &suggestions);
324 bool suggested_word_is_present = false; 324 bool suggested_word_is_present = false;
325 const string16 suggested_word(ASCIIToUTF16(kTestCases[i].suggested_word)); 325 const string16 suggested_word(ASCIIToUTF16(kTestCases[i].suggested_word));
326 for (size_t j = 0; j < suggestions.size(); j++) { 326 for (size_t j = 0; j < suggestions.size(); j++) {
327 if (suggestions[j].compare(suggested_word) == 0) { 327 if (suggestions[j].compare(suggested_word) == 0) {
328 suggested_word_is_present = true; 328 suggested_word_is_present = true;
329 break; 329 break;
330 } 330 }
331 } 331 }
332 EXPECT_TRUE(suggested_word_is_present) << suggested_word; 332 EXPECT_TRUE(suggested_word_is_present) << suggested_word;
333 } 333 }
334 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698