OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 SpellCheck* spell_check() { return spell_check_.get(); } | 78 SpellCheck* spell_check() { return spell_check_.get(); } |
79 | 79 |
80 bool CheckSpelling(const std::string& word, int tag) { | 80 bool CheckSpelling(const std::string& word, int tag) { |
81 return spell_check_->spellcheck_.platform_spelling_engine_->CheckSpelling( | 81 return spell_check_->spellcheck_.platform_spelling_engine_->CheckSpelling( |
82 ASCIIToUTF16(word), tag); | 82 ASCIIToUTF16(word), tag); |
83 } | 83 } |
84 | 84 |
85 #if !defined(OS_MACOSX) | 85 #if !defined(OS_MACOSX) |
86 protected: | 86 protected: |
87 void TestSpellCheckParagraph( | 87 void TestSpellCheckParagraph( |
88 const string16& input, | 88 const base::string16& input, |
89 const std::vector<SpellCheckResult>& expected) { | 89 const std::vector<SpellCheckResult>& expected) { |
90 blink::WebVector<blink::WebTextCheckingResult> results; | 90 blink::WebVector<blink::WebTextCheckingResult> results; |
91 spell_check()->SpellCheckParagraph(input, | 91 spell_check()->SpellCheckParagraph(input, |
92 &results); | 92 &results); |
93 | 93 |
94 EXPECT_EQ(results.size(), expected.size()); | 94 EXPECT_EQ(results.size(), expected.size()); |
95 size_t size = std::min(results.size(), expected.size()); | 95 size_t size = std::min(results.size(), expected.size()); |
96 for (size_t j = 0; j < size; ++j) { | 96 for (size_t j = 0; j < size; ++j) { |
97 EXPECT_EQ(results[j].decoration, blink::WebTextDecorationTypeSpelling); | 97 EXPECT_EQ(results[j].decoration, blink::WebTextDecorationTypeSpelling); |
98 EXPECT_EQ(results[j].location, expected[j].location); | 98 EXPECT_EQ(results[j].location, expected[j].location); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 {L"jum", false, 0, 0, L"jump"}, | 424 {L"jum", false, 0, 0, L"jump"}, |
425 {L"jum", false, 0, 0, L"hum"}, | 425 {L"jum", false, 0, 0, L"hum"}, |
426 {L"jum", false, 0, 0, L"sum"}, | 426 {L"jum", false, 0, 0, L"sum"}, |
427 {L"jum", false, 0, 0, L"um"}, | 427 {L"jum", false, 0, 0, L"um"}, |
428 // A regression test for Issue 36523. | 428 // A regression test for Issue 36523. |
429 {L"privliged", false, 0, 0, L"privileged"}, | 429 {L"privliged", false, 0, 0, L"privileged"}, |
430 // TODO (Sidchat): add many more examples. | 430 // TODO (Sidchat): add many more examples. |
431 }; | 431 }; |
432 | 432 |
433 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 433 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
434 std::vector<string16> suggestions; | 434 std::vector<base::string16> suggestions; |
435 size_t input_length = 0; | 435 size_t input_length = 0; |
436 if (kTestCases[i].input != NULL) { | 436 if (kTestCases[i].input != NULL) { |
437 input_length = wcslen(kTestCases[i].input); | 437 input_length = wcslen(kTestCases[i].input); |
438 } | 438 } |
439 int misspelling_start; | 439 int misspelling_start; |
440 int misspelling_length; | 440 int misspelling_length; |
441 bool result = spell_check()->SpellCheckWord( | 441 bool result = spell_check()->SpellCheckWord( |
442 WideToUTF16(kTestCases[i].input).c_str(), | 442 WideToUTF16(kTestCases[i].input).c_str(), |
443 static_cast<int>(input_length), | 443 static_cast<int>(input_length), |
444 0, | 444 0, |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 {"teh", "the"}, | 834 {"teh", "the"}, |
835 {"moer", "more"}, | 835 {"moer", "more"}, |
836 {"watre", "water"}, | 836 {"watre", "water"}, |
837 {"noen", ""}, | 837 {"noen", ""}, |
838 {"what", ""}, | 838 {"what", ""}, |
839 }; | 839 }; |
840 | 840 |
841 EnableAutoCorrect(true); | 841 EnableAutoCorrect(true); |
842 | 842 |
843 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 843 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
844 string16 misspelled_word(UTF8ToUTF16(kTestCases[i].input)); | 844 base::string16 misspelled_word(UTF8ToUTF16(kTestCases[i].input)); |
845 string16 expected_autocorrect_word( | 845 base::string16 expected_autocorrect_word( |
846 UTF8ToUTF16(kTestCases[i].expected_result)); | 846 UTF8ToUTF16(kTestCases[i].expected_result)); |
847 string16 autocorrect_word = spell_check()->GetAutoCorrectionWord( | 847 base::string16 autocorrect_word = spell_check()->GetAutoCorrectionWord( |
848 misspelled_word, 0); | 848 misspelled_word, 0); |
849 | 849 |
850 // Check for spelling. | 850 // Check for spelling. |
851 EXPECT_EQ(expected_autocorrect_word, autocorrect_word); | 851 EXPECT_EQ(expected_autocorrect_word, autocorrect_word); |
852 } | 852 } |
853 } | 853 } |
854 | 854 |
855 // Verify that our SpellCheck::SpellCheckWord() returns false when it checks | 855 // Verify that our SpellCheck::SpellCheckWord() returns false when it checks |
856 // misspelled words. | 856 // misspelled words. |
857 TEST_F(SpellCheckTest, MisspelledWords) { | 857 TEST_F(SpellCheckTest, MisspelledWords) { |
(...skipping 20 matching lines...) Expand all Loading... |
878 }, { | 878 }, { |
879 // A misspelled word for Russian | 879 // A misspelled word for Russian |
880 "ru-RU", | 880 "ru-RU", |
881 L"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430", | 881 L"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430", |
882 }, | 882 }, |
883 }; | 883 }; |
884 | 884 |
885 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 885 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
886 ReinitializeSpellCheck(kTestCases[i].language); | 886 ReinitializeSpellCheck(kTestCases[i].language); |
887 | 887 |
888 string16 word(WideToUTF16(kTestCases[i].input)); | 888 base::string16 word(WideToUTF16(kTestCases[i].input)); |
889 int word_length = static_cast<int>(word.length()); | 889 int word_length = static_cast<int>(word.length()); |
890 int misspelling_start = 0; | 890 int misspelling_start = 0; |
891 int misspelling_length = 0; | 891 int misspelling_length = 0; |
892 bool result = spell_check()->SpellCheckWord(word.c_str(), | 892 bool result = spell_check()->SpellCheckWord(word.c_str(), |
893 word_length, | 893 word_length, |
894 0, | 894 0, |
895 &misspelling_start, | 895 &misspelling_start, |
896 &misspelling_length, | 896 &misspelling_length, |
897 NULL); | 897 NULL); |
898 EXPECT_FALSE(result); | 898 EXPECT_FALSE(result); |
899 EXPECT_EQ(0, misspelling_start); | 899 EXPECT_EQ(0, misspelling_start); |
900 EXPECT_EQ(word_length, misspelling_length); | 900 EXPECT_EQ(word_length, misspelling_length); |
901 } | 901 } |
902 } | 902 } |
903 | 903 |
904 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac, | 904 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac, |
905 // we skip these SpellCheckParagraph tests on Mac. | 905 // we skip these SpellCheckParagraph tests on Mac. |
906 #if !defined(OS_MACOSX) | 906 #if !defined(OS_MACOSX) |
907 | 907 |
908 // Make sure SpellCheckParagraph does not crash if the input is empty. | 908 // Make sure SpellCheckParagraph does not crash if the input is empty. |
909 TEST_F(SpellCheckTest, SpellCheckParagraphEmptyParagraph) { | 909 TEST_F(SpellCheckTest, SpellCheckParagraphEmptyParagraph) { |
910 std::vector<SpellCheckResult> expected; | 910 std::vector<SpellCheckResult> expected; |
911 TestSpellCheckParagraph(UTF8ToUTF16(""), expected); | 911 TestSpellCheckParagraph(UTF8ToUTF16(""), expected); |
912 } | 912 } |
913 | 913 |
914 // A simple test case having no misspellings. | 914 // A simple test case having no misspellings. |
915 TEST_F(SpellCheckTest, SpellCheckParagraphNoMisspellings) { | 915 TEST_F(SpellCheckTest, SpellCheckParagraphNoMisspellings) { |
916 const string16 text = UTF8ToUTF16("apple"); | 916 const base::string16 text = UTF8ToUTF16("apple"); |
917 std::vector<SpellCheckResult> expected; | 917 std::vector<SpellCheckResult> expected; |
918 TestSpellCheckParagraph(text, expected); | 918 TestSpellCheckParagraph(text, expected); |
919 } | 919 } |
920 | 920 |
921 // A simple test case having one misspelling. | 921 // A simple test case having one misspelling. |
922 TEST_F(SpellCheckTest, SpellCheckParagraphSingleMisspellings) { | 922 TEST_F(SpellCheckTest, SpellCheckParagraphSingleMisspellings) { |
923 const string16 text = UTF8ToUTF16("zz"); | 923 const base::string16 text = UTF8ToUTF16("zz"); |
924 std::vector<SpellCheckResult> expected; | 924 std::vector<SpellCheckResult> expected; |
925 expected.push_back(SpellCheckResult( | 925 expected.push_back(SpellCheckResult( |
926 SpellCheckResult::SPELLING, 0, 2)); | 926 SpellCheckResult::SPELLING, 0, 2)); |
927 | 927 |
928 TestSpellCheckParagraph(text, expected); | 928 TestSpellCheckParagraph(text, expected); |
929 } | 929 } |
930 | 930 |
931 // A simple test case having multiple misspellings. | 931 // A simple test case having multiple misspellings. |
932 TEST_F(SpellCheckTest, SpellCheckParagraphMultipleMisspellings) { | 932 TEST_F(SpellCheckTest, SpellCheckParagraphMultipleMisspellings) { |
933 const string16 text = UTF8ToUTF16("zz, zz"); | 933 const base::string16 text = UTF8ToUTF16("zz, zz"); |
934 std::vector<SpellCheckResult> expected; | 934 std::vector<SpellCheckResult> expected; |
935 expected.push_back(SpellCheckResult( | 935 expected.push_back(SpellCheckResult( |
936 SpellCheckResult::SPELLING, 0, 2)); | 936 SpellCheckResult::SPELLING, 0, 2)); |
937 expected.push_back(SpellCheckResult( | 937 expected.push_back(SpellCheckResult( |
938 SpellCheckResult::SPELLING, 4, 2)); | 938 SpellCheckResult::SPELLING, 4, 2)); |
939 | 939 |
940 TestSpellCheckParagraph(text, expected); | 940 TestSpellCheckParagraph(text, expected); |
941 } | 941 } |
942 | 942 |
943 // Make sure a relatively long (correct) sentence can be spellchecked. | 943 // Make sure a relatively long (correct) sentence can be spellchecked. |
944 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentence) { | 944 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentence) { |
945 std::vector<SpellCheckResult> expected; | 945 std::vector<SpellCheckResult> expected; |
946 // The text is taken from US constitution preamble. | 946 // The text is taken from US constitution preamble. |
947 const string16 text = UTF8ToUTF16( | 947 const base::string16 text = UTF8ToUTF16( |
948 "We the people of the United States, in order to form a more perfect " | 948 "We the people of the United States, in order to form a more perfect " |
949 "union, establish justice, insure domestic tranquility, provide for " | 949 "union, establish justice, insure domestic tranquility, provide for " |
950 "the common defense, promote the general welfare, and secure the " | 950 "the common defense, promote the general welfare, and secure the " |
951 "blessings of liberty to ourselves and our posterity, do ordain and " | 951 "blessings of liberty to ourselves and our posterity, do ordain and " |
952 "establish this Constitution for the United States of America."); | 952 "establish this Constitution for the United States of America."); |
953 | 953 |
954 TestSpellCheckParagraph(text, expected); | 954 TestSpellCheckParagraph(text, expected); |
955 } | 955 } |
956 | 956 |
957 // Make sure all misspellings can be found in a relatively long sentence. | 957 // Make sure all misspellings can be found in a relatively long sentence. |
958 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentenceMultipleMisspellings) { | 958 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentenceMultipleMisspellings) { |
959 std::vector<SpellCheckResult> expected; | 959 std::vector<SpellCheckResult> expected; |
960 | 960 |
961 // All 'the' are converted to 'hte' in US consitition preamble. | 961 // All 'the' are converted to 'hte' in US consitition preamble. |
962 const string16 text = UTF8ToUTF16( | 962 const base::string16 text = UTF8ToUTF16( |
963 "We hte people of hte United States, in order to form a more perfect " | 963 "We hte people of hte United States, in order to form a more perfect " |
964 "union, establish justice, insure domestic tranquility, provide for " | 964 "union, establish justice, insure domestic tranquility, provide for " |
965 "hte common defense, promote hte general welfare, and secure hte " | 965 "hte common defense, promote hte general welfare, and secure hte " |
966 "blessings of liberty to ourselves and our posterity, do ordain and " | 966 "blessings of liberty to ourselves and our posterity, do ordain and " |
967 "establish this Constitution for hte United States of America."); | 967 "establish this Constitution for hte United States of America."); |
968 | 968 |
969 expected.push_back(SpellCheckResult( | 969 expected.push_back(SpellCheckResult( |
970 SpellCheckResult::SPELLING, 3, 3)); | 970 SpellCheckResult::SPELLING, 3, 3)); |
971 expected.push_back(SpellCheckResult( | 971 expected.push_back(SpellCheckResult( |
972 SpellCheckResult::SPELLING, 17, 3)); | 972 SpellCheckResult::SPELLING, 17, 3)); |
973 expected.push_back(SpellCheckResult( | 973 expected.push_back(SpellCheckResult( |
974 SpellCheckResult::SPELLING, 135, 3)); | 974 SpellCheckResult::SPELLING, 135, 3)); |
975 expected.push_back(SpellCheckResult( | 975 expected.push_back(SpellCheckResult( |
976 SpellCheckResult::SPELLING, 163, 3)); | 976 SpellCheckResult::SPELLING, 163, 3)); |
977 expected.push_back(SpellCheckResult( | 977 expected.push_back(SpellCheckResult( |
978 SpellCheckResult::SPELLING, 195, 3)); | 978 SpellCheckResult::SPELLING, 195, 3)); |
979 expected.push_back(SpellCheckResult( | 979 expected.push_back(SpellCheckResult( |
980 SpellCheckResult::SPELLING, 298, 3)); | 980 SpellCheckResult::SPELLING, 298, 3)); |
981 | 981 |
982 TestSpellCheckParagraph(text, expected); | 982 TestSpellCheckParagraph(text, expected); |
983 } | 983 } |
984 | 984 |
985 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker | 985 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker |
986 // is used on Mac instead of SpellCheck::RequestTextChecking. | 986 // is used on Mac instead of SpellCheck::RequestTextChecking. |
987 | 987 |
988 // Make sure RequestTextChecking does not crash if input is empty. | 988 // Make sure RequestTextChecking does not crash if input is empty. |
989 TEST_F(SpellCheckTest, RequestSpellCheckWithEmptyString) { | 989 TEST_F(SpellCheckTest, RequestSpellCheckWithEmptyString) { |
990 MockTextCheckingCompletion completion; | 990 MockTextCheckingCompletion completion; |
991 | 991 |
992 spell_check()->RequestTextChecking(string16(), &completion); | 992 spell_check()->RequestTextChecking(base::string16(), &completion); |
993 | 993 |
994 base::MessageLoop::current()->RunUntilIdle(); | 994 base::MessageLoop::current()->RunUntilIdle(); |
995 | 995 |
996 EXPECT_EQ(completion.completion_count_, 1U); | 996 EXPECT_EQ(completion.completion_count_, 1U); |
997 } | 997 } |
998 | 998 |
999 // A simple test case having no misspellings. | 999 // A simple test case having no misspellings. |
1000 TEST_F(SpellCheckTest, RequestSpellCheckWithoutMisspelling) { | 1000 TEST_F(SpellCheckTest, RequestSpellCheckWithoutMisspelling) { |
1001 MockTextCheckingCompletion completion; | 1001 MockTextCheckingCompletion completion; |
1002 | 1002 |
1003 const string16 text = ASCIIToUTF16("hello"); | 1003 const base::string16 text = ASCIIToUTF16("hello"); |
1004 spell_check()->RequestTextChecking(text, &completion); | 1004 spell_check()->RequestTextChecking(text, &completion); |
1005 | 1005 |
1006 base::MessageLoop::current()->RunUntilIdle(); | 1006 base::MessageLoop::current()->RunUntilIdle(); |
1007 | 1007 |
1008 EXPECT_EQ(completion.completion_count_, 1U); | 1008 EXPECT_EQ(completion.completion_count_, 1U); |
1009 } | 1009 } |
1010 | 1010 |
1011 // A simple test case having one misspelling. | 1011 // A simple test case having one misspelling. |
1012 TEST_F(SpellCheckTest, RequestSpellCheckWithSingleMisspelling) { | 1012 TEST_F(SpellCheckTest, RequestSpellCheckWithSingleMisspelling) { |
1013 MockTextCheckingCompletion completion; | 1013 MockTextCheckingCompletion completion; |
1014 | 1014 |
1015 const string16 text = ASCIIToUTF16("apple, zz"); | 1015 const base::string16 text = ASCIIToUTF16("apple, zz"); |
1016 spell_check()->RequestTextChecking(text, &completion); | 1016 spell_check()->RequestTextChecking(text, &completion); |
1017 | 1017 |
1018 base::MessageLoop::current()->RunUntilIdle(); | 1018 base::MessageLoop::current()->RunUntilIdle(); |
1019 | 1019 |
1020 EXPECT_EQ(completion.completion_count_, 1U); | 1020 EXPECT_EQ(completion.completion_count_, 1U); |
1021 EXPECT_EQ(completion.last_results_.size(), 1U); | 1021 EXPECT_EQ(completion.last_results_.size(), 1U); |
1022 EXPECT_EQ(completion.last_results_[0].location, 7); | 1022 EXPECT_EQ(completion.last_results_[0].location, 7); |
1023 EXPECT_EQ(completion.last_results_[0].length, 2); | 1023 EXPECT_EQ(completion.last_results_[0].length, 2); |
1024 } | 1024 } |
1025 | 1025 |
1026 // A simple test case having a few misspellings. | 1026 // A simple test case having a few misspellings. |
1027 TEST_F(SpellCheckTest, RequestSpellCheckWithMisspellings) { | 1027 TEST_F(SpellCheckTest, RequestSpellCheckWithMisspellings) { |
1028 MockTextCheckingCompletion completion; | 1028 MockTextCheckingCompletion completion; |
1029 | 1029 |
1030 const string16 text = ASCIIToUTF16("apple, zz, orange, zz"); | 1030 const base::string16 text = ASCIIToUTF16("apple, zz, orange, zz"); |
1031 spell_check()->RequestTextChecking(text, &completion); | 1031 spell_check()->RequestTextChecking(text, &completion); |
1032 | 1032 |
1033 base::MessageLoop::current()->RunUntilIdle(); | 1033 base::MessageLoop::current()->RunUntilIdle(); |
1034 | 1034 |
1035 EXPECT_EQ(completion.completion_count_, 1U); | 1035 EXPECT_EQ(completion.completion_count_, 1U); |
1036 EXPECT_EQ(completion.last_results_.size(), 2U); | 1036 EXPECT_EQ(completion.last_results_.size(), 2U); |
1037 EXPECT_EQ(completion.last_results_[0].location, 7); | 1037 EXPECT_EQ(completion.last_results_[0].location, 7); |
1038 EXPECT_EQ(completion.last_results_[0].length, 2); | 1038 EXPECT_EQ(completion.last_results_[0].length, 2); |
1039 EXPECT_EQ(completion.last_results_[1].location, 19); | 1039 EXPECT_EQ(completion.last_results_[1].location, 19); |
1040 EXPECT_EQ(completion.last_results_[1].length, 2); | 1040 EXPECT_EQ(completion.last_results_[1].length, 2); |
1041 } | 1041 } |
1042 | 1042 |
1043 // A test case that multiple requests comes at once. Make sure all | 1043 // A test case that multiple requests comes at once. Make sure all |
1044 // requests are processed. | 1044 // requests are processed. |
1045 TEST_F(SpellCheckTest, RequestSpellCheckWithMultipleRequests) { | 1045 TEST_F(SpellCheckTest, RequestSpellCheckWithMultipleRequests) { |
1046 MockTextCheckingCompletion completion[3]; | 1046 MockTextCheckingCompletion completion[3]; |
1047 | 1047 |
1048 const string16 text[3] = { | 1048 const base::string16 text[3] = { |
1049 ASCIIToUTF16("what, zz"), | 1049 ASCIIToUTF16("what, zz"), |
1050 ASCIIToUTF16("apple, zz"), | 1050 ASCIIToUTF16("apple, zz"), |
1051 ASCIIToUTF16("orange, zz") | 1051 ASCIIToUTF16("orange, zz") |
1052 }; | 1052 }; |
1053 | 1053 |
1054 for (int i = 0; i < 3; ++i) | 1054 for (int i = 0; i < 3; ++i) |
1055 spell_check()->RequestTextChecking(text[i], &completion[i]); | 1055 spell_check()->RequestTextChecking(text[i], &completion[i]); |
1056 | 1056 |
1057 base::MessageLoop::current()->RunUntilIdle(); | 1057 base::MessageLoop::current()->RunUntilIdle(); |
1058 | 1058 |
1059 for (int i = 0; i < 3; ++i) { | 1059 for (int i = 0; i < 3; ++i) { |
1060 EXPECT_EQ(completion[i].completion_count_, 1U); | 1060 EXPECT_EQ(completion[i].completion_count_, 1U); |
1061 EXPECT_EQ(completion[i].last_results_.size(), 1U); | 1061 EXPECT_EQ(completion[i].last_results_.size(), 1U); |
1062 EXPECT_EQ(completion[i].last_results_[0].location, 6 + i); | 1062 EXPECT_EQ(completion[i].last_results_[0].location, 6 + i); |
1063 EXPECT_EQ(completion[i].last_results_[0].length, 2); | 1063 EXPECT_EQ(completion[i].last_results_[0].length, 2); |
1064 } | 1064 } |
1065 } | 1065 } |
1066 | 1066 |
1067 // A test case that spellchecking is requested before initializing. | 1067 // A test case that spellchecking is requested before initializing. |
1068 // In this case, we postpone to post a request. | 1068 // In this case, we postpone to post a request. |
1069 TEST_F(SpellCheckTest, RequestSpellCheckWithoutInitialization) { | 1069 TEST_F(SpellCheckTest, RequestSpellCheckWithoutInitialization) { |
1070 UninitializeSpellCheck(); | 1070 UninitializeSpellCheck(); |
1071 | 1071 |
1072 MockTextCheckingCompletion completion; | 1072 MockTextCheckingCompletion completion; |
1073 const string16 text = ASCIIToUTF16("zz"); | 1073 const base::string16 text = ASCIIToUTF16("zz"); |
1074 | 1074 |
1075 spell_check()->RequestTextChecking(text, &completion); | 1075 spell_check()->RequestTextChecking(text, &completion); |
1076 | 1076 |
1077 // The task will not be posted yet. | 1077 // The task will not be posted yet. |
1078 base::MessageLoop::current()->RunUntilIdle(); | 1078 base::MessageLoop::current()->RunUntilIdle(); |
1079 EXPECT_EQ(completion.completion_count_, 0U); | 1079 EXPECT_EQ(completion.completion_count_, 0U); |
1080 } | 1080 } |
1081 | 1081 |
1082 // Requests several spellchecking before initializing. Except the last one, | 1082 // Requests several spellchecking before initializing. Except the last one, |
1083 // posting requests is cancelled and text is rendered as correct one. | 1083 // posting requests is cancelled and text is rendered as correct one. |
1084 TEST_F(SpellCheckTest, RequestSpellCheckMultipleTimesWithoutInitialization) { | 1084 TEST_F(SpellCheckTest, RequestSpellCheckMultipleTimesWithoutInitialization) { |
1085 UninitializeSpellCheck(); | 1085 UninitializeSpellCheck(); |
1086 | 1086 |
1087 MockTextCheckingCompletion completion[3]; | 1087 MockTextCheckingCompletion completion[3]; |
1088 const string16 text[3] = { | 1088 const base::string16 text[3] = { |
1089 ASCIIToUTF16("what, zz"), | 1089 ASCIIToUTF16("what, zz"), |
1090 ASCIIToUTF16("apple, zz"), | 1090 ASCIIToUTF16("apple, zz"), |
1091 ASCIIToUTF16("orange, zz") | 1091 ASCIIToUTF16("orange, zz") |
1092 }; | 1092 }; |
1093 | 1093 |
1094 // Calls RequestTextchecking a few times. | 1094 // Calls RequestTextchecking a few times. |
1095 for (int i = 0; i < 3; ++i) | 1095 for (int i = 0; i < 3; ++i) |
1096 spell_check()->RequestTextChecking(text[i], &completion[i]); | 1096 spell_check()->RequestTextChecking(text[i], &completion[i]); |
1097 | 1097 |
1098 // The last task will be posted after initialization, however the other | 1098 // The last task will be posted after initialization, however the other |
(...skipping 11 matching lines...) Expand all Loading... |
1110 spell_check()->pending_request_param_.release()); | 1110 spell_check()->pending_request_param_.release()); |
1111 base::MessageLoop::current()->RunUntilIdle(); | 1111 base::MessageLoop::current()->RunUntilIdle(); |
1112 for (int i = 0; i < 3; ++i) | 1112 for (int i = 0; i < 3; ++i) |
1113 EXPECT_EQ(completion[i].completion_count_, 1U); | 1113 EXPECT_EQ(completion[i].completion_count_, 1U); |
1114 } | 1114 } |
1115 | 1115 |
1116 TEST_F(SpellCheckTest, CreateTextCheckingResults) { | 1116 TEST_F(SpellCheckTest, CreateTextCheckingResults) { |
1117 // Verify that the SpellCheck class keeps the spelling marker added to a | 1117 // Verify that the SpellCheck class keeps the spelling marker added to a |
1118 // misspelled word "zz". | 1118 // misspelled word "zz". |
1119 { | 1119 { |
1120 string16 text = ASCIIToUTF16("zz"); | 1120 base::string16 text = ASCIIToUTF16("zz"); |
1121 std::vector<SpellCheckResult> spellcheck_results; | 1121 std::vector<SpellCheckResult> spellcheck_results; |
1122 spellcheck_results.push_back(SpellCheckResult( | 1122 spellcheck_results.push_back(SpellCheckResult( |
1123 SpellCheckResult::SPELLING, 0, 2, string16())); | 1123 SpellCheckResult::SPELLING, 0, 2, base::string16())); |
1124 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1124 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
1125 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, | 1125 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
1126 0, | 1126 0, |
1127 text, | 1127 text, |
1128 spellcheck_results, | 1128 spellcheck_results, |
1129 &textcheck_results); | 1129 &textcheck_results); |
1130 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1130 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); |
1131 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, | 1131 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, |
1132 textcheck_results[0].decoration); | 1132 textcheck_results[0].decoration); |
1133 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1133 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
1134 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1134 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
1135 } | 1135 } |
1136 | 1136 |
1137 // Verify that the SpellCheck class replaces the spelling marker added to a | 1137 // Verify that the SpellCheck class replaces the spelling marker added to a |
1138 // contextually-misspelled word "bean" with a grammar marker. | 1138 // contextually-misspelled word "bean" with a grammar marker. |
1139 { | 1139 { |
1140 string16 text = ASCIIToUTF16("I have bean to USA."); | 1140 base::string16 text = ASCIIToUTF16("I have bean to USA."); |
1141 std::vector<SpellCheckResult> spellcheck_results; | 1141 std::vector<SpellCheckResult> spellcheck_results; |
1142 spellcheck_results.push_back(SpellCheckResult( | 1142 spellcheck_results.push_back(SpellCheckResult( |
1143 SpellCheckResult::SPELLING, 7, 4, string16())); | 1143 SpellCheckResult::SPELLING, 7, 4, base::string16())); |
1144 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1144 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
1145 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, | 1145 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
1146 0, | 1146 0, |
1147 text, | 1147 text, |
1148 spellcheck_results, | 1148 spellcheck_results, |
1149 &textcheck_results); | 1149 &textcheck_results); |
1150 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1150 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); |
1151 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, | 1151 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, |
1152 textcheck_results[0].decoration); | 1152 textcheck_results[0].decoration); |
1153 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1153 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 ASCIIToUTF16(kTestCases[i].suggestion).c_str(), | 1247 ASCIIToUTF16(kTestCases[i].suggestion).c_str(), |
1248 static_cast<int>(suggestion_length), | 1248 static_cast<int>(suggestion_length), |
1249 0, | 1249 0, |
1250 &misspelling_start, | 1250 &misspelling_start, |
1251 &misspelling_length, NULL); | 1251 &misspelling_length, NULL); |
1252 | 1252 |
1253 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].suggestion << | 1253 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].suggestion << |
1254 " in " << kTestCases[i].locale; | 1254 " in " << kTestCases[i].locale; |
1255 | 1255 |
1256 // Now verify that this test case does not show up as a suggestion. | 1256 // Now verify that this test case does not show up as a suggestion. |
1257 std::vector<string16> suggestions; | 1257 std::vector<base::string16> suggestions; |
1258 size_t input_length = 0; | 1258 size_t input_length = 0; |
1259 if (kTestCases[i].input != NULL) | 1259 if (kTestCases[i].input != NULL) |
1260 input_length = strlen(kTestCases[i].input); | 1260 input_length = strlen(kTestCases[i].input); |
1261 result = spell_check()->SpellCheckWord( | 1261 result = spell_check()->SpellCheckWord( |
1262 ASCIIToUTF16(kTestCases[i].input).c_str(), | 1262 ASCIIToUTF16(kTestCases[i].input).c_str(), |
1263 static_cast<int>(input_length), | 1263 static_cast<int>(input_length), |
1264 0, | 1264 0, |
1265 &misspelling_start, | 1265 &misspelling_start, |
1266 &misspelling_length, | 1266 &misspelling_length, |
1267 &suggestions); | 1267 &suggestions); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 const char* misspelled; | 1340 const char* misspelled; |
1341 const char* suggestion; | 1341 const char* suggestion; |
1342 } kTestCases[] = { | 1342 } kTestCases[] = { |
1343 { "hellllo", "hello" }, | 1343 { "hellllo", "hello" }, |
1344 { "accidently", "accidentally" } | 1344 { "accidently", "accidentally" } |
1345 }; | 1345 }; |
1346 | 1346 |
1347 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 1347 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
1348 int misspelling_start = 0; | 1348 int misspelling_start = 0; |
1349 int misspelling_length = 0; | 1349 int misspelling_length = 0; |
1350 std::vector<string16> suggestions; | 1350 std::vector<base::string16> suggestions; |
1351 EXPECT_FALSE(spell_check()->SpellCheckWord( | 1351 EXPECT_FALSE(spell_check()->SpellCheckWord( |
1352 ASCIIToUTF16(kTestCases[i].misspelled).c_str(), | 1352 ASCIIToUTF16(kTestCases[i].misspelled).c_str(), |
1353 strlen(kTestCases[i].misspelled), | 1353 strlen(kTestCases[i].misspelled), |
1354 0, | 1354 0, |
1355 &misspelling_start, | 1355 &misspelling_start, |
1356 &misspelling_length, | 1356 &misspelling_length, |
1357 &suggestions)); | 1357 &suggestions)); |
1358 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); | 1358 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); |
1359 if (suggestions.size() > 0) | 1359 if (suggestions.size() > 0) |
1360 EXPECT_EQ(suggestions[0], ASCIIToUTF16(kTestCases[i].suggestion)); | 1360 EXPECT_EQ(suggestions[0], ASCIIToUTF16(kTestCases[i].suggestion)); |
1361 } | 1361 } |
1362 } | 1362 } |
OLD | NEW |