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 "webkit/glue/webkit_glue.h" | 5 #include "webkit/glue/webkit_glue.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 | 926 |
927 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker | 927 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker |
928 // is used on Mac instead of SpellCheck::RequestTextChecking. | 928 // is used on Mac instead of SpellCheck::RequestTextChecking. |
929 | 929 |
930 // Make sure RequestTextChecking does not crash if input is empty. | 930 // Make sure RequestTextChecking does not crash if input is empty. |
931 TEST_F(SpellCheckTest, RequestSpellCheckWithEmptyString) { | 931 TEST_F(SpellCheckTest, RequestSpellCheckWithEmptyString) { |
932 MockTextCheckingCompletion completion; | 932 MockTextCheckingCompletion completion; |
933 | 933 |
934 spell_check()->RequestTextChecking(string16(), 0, &completion); | 934 spell_check()->RequestTextChecking(string16(), 0, &completion); |
935 | 935 |
936 MessageLoop::current()->RunAllPending(); | 936 MessageLoop::current()->RunUntilIdle(); |
937 | 937 |
938 EXPECT_EQ(completion.completion_count_, 1U); | 938 EXPECT_EQ(completion.completion_count_, 1U); |
939 } | 939 } |
940 | 940 |
941 // A simple test case having no misspellings. | 941 // A simple test case having no misspellings. |
942 TEST_F(SpellCheckTest, RequestSpellCheckWithoutMisspelling) { | 942 TEST_F(SpellCheckTest, RequestSpellCheckWithoutMisspelling) { |
943 MockTextCheckingCompletion completion; | 943 MockTextCheckingCompletion completion; |
944 | 944 |
945 const string16 text = ASCIIToUTF16("hello"); | 945 const string16 text = ASCIIToUTF16("hello"); |
946 spell_check()->RequestTextChecking(text, 0, &completion); | 946 spell_check()->RequestTextChecking(text, 0, &completion); |
947 | 947 |
948 MessageLoop::current()->RunAllPending(); | 948 MessageLoop::current()->RunUntilIdle(); |
949 | 949 |
950 EXPECT_EQ(completion.completion_count_, 1U); | 950 EXPECT_EQ(completion.completion_count_, 1U); |
951 } | 951 } |
952 | 952 |
953 // A simple test case having one misspelling. | 953 // A simple test case having one misspelling. |
954 TEST_F(SpellCheckTest, RequestSpellCheckWithSingleMisspelling) { | 954 TEST_F(SpellCheckTest, RequestSpellCheckWithSingleMisspelling) { |
955 MockTextCheckingCompletion completion; | 955 MockTextCheckingCompletion completion; |
956 | 956 |
957 const string16 text = ASCIIToUTF16("apple, zz"); | 957 const string16 text = ASCIIToUTF16("apple, zz"); |
958 spell_check()->RequestTextChecking(text, 0, &completion); | 958 spell_check()->RequestTextChecking(text, 0, &completion); |
959 | 959 |
960 MessageLoop::current()->RunAllPending(); | 960 MessageLoop::current()->RunUntilIdle(); |
961 | 961 |
962 EXPECT_EQ(completion.completion_count_, 1U); | 962 EXPECT_EQ(completion.completion_count_, 1U); |
963 EXPECT_EQ(completion.last_results_.size(), 1U); | 963 EXPECT_EQ(completion.last_results_.size(), 1U); |
964 EXPECT_EQ(completion.last_results_[0].location, 7); | 964 EXPECT_EQ(completion.last_results_[0].location, 7); |
965 EXPECT_EQ(completion.last_results_[0].length, 2); | 965 EXPECT_EQ(completion.last_results_[0].length, 2); |
966 } | 966 } |
967 | 967 |
968 // A simple test case having a few misspellings. | 968 // A simple test case having a few misspellings. |
969 TEST_F(SpellCheckTest, RequestSpellCheckWithMisspellings) { | 969 TEST_F(SpellCheckTest, RequestSpellCheckWithMisspellings) { |
970 MockTextCheckingCompletion completion; | 970 MockTextCheckingCompletion completion; |
971 | 971 |
972 const string16 text = ASCIIToUTF16("apple, zz, orange, zz"); | 972 const string16 text = ASCIIToUTF16("apple, zz, orange, zz"); |
973 spell_check()->RequestTextChecking(text, 0, &completion); | 973 spell_check()->RequestTextChecking(text, 0, &completion); |
974 | 974 |
975 MessageLoop::current()->RunAllPending(); | 975 MessageLoop::current()->RunUntilIdle(); |
976 | 976 |
977 EXPECT_EQ(completion.completion_count_, 1U); | 977 EXPECT_EQ(completion.completion_count_, 1U); |
978 EXPECT_EQ(completion.last_results_.size(), 2U); | 978 EXPECT_EQ(completion.last_results_.size(), 2U); |
979 EXPECT_EQ(completion.last_results_[0].location, 7); | 979 EXPECT_EQ(completion.last_results_[0].location, 7); |
980 EXPECT_EQ(completion.last_results_[0].length, 2); | 980 EXPECT_EQ(completion.last_results_[0].length, 2); |
981 EXPECT_EQ(completion.last_results_[1].location, 19); | 981 EXPECT_EQ(completion.last_results_[1].location, 19); |
982 EXPECT_EQ(completion.last_results_[1].length, 2); | 982 EXPECT_EQ(completion.last_results_[1].length, 2); |
983 } | 983 } |
984 | 984 |
985 // A test case that multiple requests comes at once. Make sure all | 985 // A test case that multiple requests comes at once. Make sure all |
986 // requests are processed. | 986 // requests are processed. |
987 TEST_F(SpellCheckTest, RequestSpellCheckWithMultipleRequests) { | 987 TEST_F(SpellCheckTest, RequestSpellCheckWithMultipleRequests) { |
988 MockTextCheckingCompletion completion[3]; | 988 MockTextCheckingCompletion completion[3]; |
989 | 989 |
990 const string16 text[3] = { | 990 const string16 text[3] = { |
991 ASCIIToUTF16("what, zz"), | 991 ASCIIToUTF16("what, zz"), |
992 ASCIIToUTF16("apple, zz"), | 992 ASCIIToUTF16("apple, zz"), |
993 ASCIIToUTF16("orange, zz") | 993 ASCIIToUTF16("orange, zz") |
994 }; | 994 }; |
995 | 995 |
996 for (int i = 0; i < 3; ++i) | 996 for (int i = 0; i < 3; ++i) |
997 spell_check()->RequestTextChecking(text[i], 0, &completion[i]); | 997 spell_check()->RequestTextChecking(text[i], 0, &completion[i]); |
998 | 998 |
999 MessageLoop::current()->RunAllPending(); | 999 MessageLoop::current()->RunUntilIdle(); |
1000 | 1000 |
1001 for (int i = 0; i < 3; ++i) { | 1001 for (int i = 0; i < 3; ++i) { |
1002 EXPECT_EQ(completion[i].completion_count_, 1U); | 1002 EXPECT_EQ(completion[i].completion_count_, 1U); |
1003 EXPECT_EQ(completion[i].last_results_.size(), 1U); | 1003 EXPECT_EQ(completion[i].last_results_.size(), 1U); |
1004 EXPECT_EQ(completion[i].last_results_[0].location, 6 + i); | 1004 EXPECT_EQ(completion[i].last_results_[0].location, 6 + i); |
1005 EXPECT_EQ(completion[i].last_results_[0].length, 2); | 1005 EXPECT_EQ(completion[i].last_results_[0].length, 2); |
1006 } | 1006 } |
1007 } | 1007 } |
1008 | 1008 |
1009 // A test case that spellchecking is requested before initializing. | 1009 // A test case that spellchecking is requested before initializing. |
1010 // In this case, we postpone to post a request. | 1010 // In this case, we postpone to post a request. |
1011 TEST_F(SpellCheckTest, RequestSpellCheckWithoutInitialization) { | 1011 TEST_F(SpellCheckTest, RequestSpellCheckWithoutInitialization) { |
1012 UninitializeSpellCheck(); | 1012 UninitializeSpellCheck(); |
1013 | 1013 |
1014 MockTextCheckingCompletion completion; | 1014 MockTextCheckingCompletion completion; |
1015 const string16 text = ASCIIToUTF16("zz"); | 1015 const string16 text = ASCIIToUTF16("zz"); |
1016 | 1016 |
1017 spell_check()->RequestTextChecking(text, 0, &completion); | 1017 spell_check()->RequestTextChecking(text, 0, &completion); |
1018 | 1018 |
1019 // The task will not be posted yet. | 1019 // The task will not be posted yet. |
1020 MessageLoop::current()->RunAllPending(); | 1020 MessageLoop::current()->RunUntilIdle(); |
1021 EXPECT_EQ(completion.completion_count_, 0U); | 1021 EXPECT_EQ(completion.completion_count_, 0U); |
1022 } | 1022 } |
1023 | 1023 |
1024 // Requests several spellchecking before initializing. Except the last one, | 1024 // Requests several spellchecking before initializing. Except the last one, |
1025 // posting requests is cancelled and text is rendered as correct one. | 1025 // posting requests is cancelled and text is rendered as correct one. |
1026 TEST_F(SpellCheckTest, RequestSpellCheckMultipleTimesWithoutInitialization) { | 1026 TEST_F(SpellCheckTest, RequestSpellCheckMultipleTimesWithoutInitialization) { |
1027 UninitializeSpellCheck(); | 1027 UninitializeSpellCheck(); |
1028 | 1028 |
1029 MockTextCheckingCompletion completion[3]; | 1029 MockTextCheckingCompletion completion[3]; |
1030 const string16 text[3] = { | 1030 const string16 text[3] = { |
1031 ASCIIToUTF16("what, zz"), | 1031 ASCIIToUTF16("what, zz"), |
1032 ASCIIToUTF16("apple, zz"), | 1032 ASCIIToUTF16("apple, zz"), |
1033 ASCIIToUTF16("orange, zz") | 1033 ASCIIToUTF16("orange, zz") |
1034 }; | 1034 }; |
1035 | 1035 |
1036 // Calls RequestTextchecking a few times. | 1036 // Calls RequestTextchecking a few times. |
1037 for (int i = 0; i < 3; ++i) | 1037 for (int i = 0; i < 3; ++i) |
1038 spell_check()->RequestTextChecking(text[i], 0, &completion[i]); | 1038 spell_check()->RequestTextChecking(text[i], 0, &completion[i]); |
1039 | 1039 |
1040 // The last task will be posted after initialization, however the other | 1040 // The last task will be posted after initialization, however the other |
1041 // requests should be pressed without spellchecking. | 1041 // requests should be pressed without spellchecking. |
1042 MessageLoop::current()->RunAllPending(); | 1042 MessageLoop::current()->RunUntilIdle(); |
1043 for (int i = 0; i < 2; ++i) | 1043 for (int i = 0; i < 2; ++i) |
1044 EXPECT_EQ(completion[i].completion_count_, 1U); | 1044 EXPECT_EQ(completion[i].completion_count_, 1U); |
1045 EXPECT_EQ(completion[2].completion_count_, 0U); | 1045 EXPECT_EQ(completion[2].completion_count_, 0U); |
1046 | 1046 |
1047 // Checks the last request is processed after initialization. | 1047 // Checks the last request is processed after initialization. |
1048 InitializeSpellCheck("en-US"); | 1048 InitializeSpellCheck("en-US"); |
1049 | 1049 |
1050 // Calls PostDelayedSpellCheckTask instead of OnInit here for simplicity. | 1050 // Calls PostDelayedSpellCheckTask instead of OnInit here for simplicity. |
1051 spell_check()->PostDelayedSpellCheckTask( | 1051 spell_check()->PostDelayedSpellCheckTask( |
1052 spell_check()->pending_request_param_.release()); | 1052 spell_check()->pending_request_param_.release()); |
1053 MessageLoop::current()->RunAllPending(); | 1053 MessageLoop::current()->RunUntilIdle(); |
1054 for (int i = 0; i < 3; ++i) | 1054 for (int i = 0; i < 3; ++i) |
1055 EXPECT_EQ(completion[i].completion_count_, 1U); | 1055 EXPECT_EQ(completion[i].completion_count_, 1U); |
1056 } | 1056 } |
1057 | 1057 |
1058 TEST_F(SpellCheckTest, CreateTextCheckingResults) { | 1058 TEST_F(SpellCheckTest, CreateTextCheckingResults) { |
1059 // Verify that the SpellCheck class keeps the spelling marker added to a | 1059 // Verify that the SpellCheck class keeps the spelling marker added to a |
1060 // misspelled word "zz". | 1060 // misspelled word "zz". |
1061 { | 1061 { |
1062 string16 text = ASCIIToUTF16("zz"); | 1062 string16 text = ASCIIToUTF16("zz"); |
1063 std::vector<SpellCheckResult> spellcheck_results; | 1063 std::vector<SpellCheckResult> spellcheck_results; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 int compare_result = | 1196 int compare_result = |
1197 suggestions.at(j).compare(ASCIIToUTF16(kTestCases[t].input)); | 1197 suggestions.at(j).compare(ASCIIToUTF16(kTestCases[t].input)); |
1198 EXPECT_FALSE(compare_result == 0) << kTestCases[t].input << | 1198 EXPECT_FALSE(compare_result == 0) << kTestCases[t].input << |
1199 " in " << kLocales[d]; | 1199 " in " << kLocales[d]; |
1200 } | 1200 } |
1201 } | 1201 } |
1202 } | 1202 } |
1203 } | 1203 } |
1204 | 1204 |
1205 #endif | 1205 #endif |
OLD | NEW |