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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2674253004: [refactor] Remove WebWidget::applyReplacementRange (Closed)
Patch Set: more refactoring Created 3 years, 10 months 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 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 927
928 WebInputMethodController* activeInputMethodController = 928 WebInputMethodController* activeInputMethodController =
929 webView->mainFrameImpl() 929 webView->mainFrameImpl()
930 ->frameWidget() 930 ->frameWidget()
931 ->getActiveWebInputMethodController(); 931 ->getActiveWebInputMethodController();
932 932
933 // The test requires non-empty composition. 933 // The test requires non-empty composition.
934 std::string compositionText("hello"); 934 std::string compositionText("hello");
935 WebVector<WebCompositionUnderline> emptyUnderlines; 935 WebVector<WebCompositionUnderline> emptyUnderlines;
936 activeInputMethodController->setComposition( 936 activeInputMethodController->setComposition(
937 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 5, 5); 937 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
938 5, 5);
938 939
939 // Do arbitrary change to make layout dirty. 940 // Do arbitrary change to make layout dirty.
940 Document& document = *webView->mainFrameImpl()->frame()->document(); 941 Document& document = *webView->mainFrameImpl()->frame()->document();
941 Element* br = document.createElement("br"); 942 Element* br = document.createElement("br");
942 document.body()->appendChild(br); 943 document.body()->appendChild(br);
943 944
944 // Should not hit assertion when calling 945 // Should not hit assertion when calling
945 // WebInputMethodController::finishComposingText with non-empty composition 946 // WebInputMethodController::finishComposingText with non-empty composition
946 // and dirty layout. 947 // and dirty layout.
947 activeInputMethodController->finishComposingText( 948 activeInputMethodController->finishComposingText(
(...skipping 10 matching lines...) Expand all
958 959
959 // Set up a composition that needs to be committed. 960 // Set up a composition that needs to be committed.
960 std::string compositionText("hello"); 961 std::string compositionText("hello");
961 962
962 WebInputMethodController* activeInputMethodController = 963 WebInputMethodController* activeInputMethodController =
963 webView->mainFrameImpl() 964 webView->mainFrameImpl()
964 ->frameWidget() 965 ->frameWidget()
965 ->getActiveWebInputMethodController(); 966 ->getActiveWebInputMethodController();
966 WebVector<WebCompositionUnderline> emptyUnderlines; 967 WebVector<WebCompositionUnderline> emptyUnderlines;
967 activeInputMethodController->setComposition( 968 activeInputMethodController->setComposition(
968 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); 969 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
970 3, 3);
969 971
970 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 972 WebTextInputInfo info = activeInputMethodController->textInputInfo();
971 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 973 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
972 EXPECT_EQ(3, info.selectionStart); 974 EXPECT_EQ(3, info.selectionStart);
973 EXPECT_EQ(3, info.selectionEnd); 975 EXPECT_EQ(3, info.selectionEnd);
974 EXPECT_EQ(0, info.compositionStart); 976 EXPECT_EQ(0, info.compositionStart);
975 EXPECT_EQ(5, info.compositionEnd); 977 EXPECT_EQ(5, info.compositionEnd);
976 978
977 activeInputMethodController->finishComposingText( 979 activeInputMethodController->finishComposingText(
978 WebInputMethodController::KeepSelection); 980 WebInputMethodController::KeepSelection);
979 info = activeInputMethodController->textInputInfo(); 981 info = activeInputMethodController->textInputInfo();
980 EXPECT_EQ(3, info.selectionStart); 982 EXPECT_EQ(3, info.selectionStart);
981 EXPECT_EQ(3, info.selectionEnd); 983 EXPECT_EQ(3, info.selectionEnd);
982 EXPECT_EQ(-1, info.compositionStart); 984 EXPECT_EQ(-1, info.compositionStart);
983 EXPECT_EQ(-1, info.compositionEnd); 985 EXPECT_EQ(-1, info.compositionEnd);
984 986
985 activeInputMethodController->setComposition( 987 activeInputMethodController->setComposition(
986 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); 988 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
989 3, 3);
987 info = activeInputMethodController->textInputInfo(); 990 info = activeInputMethodController->textInputInfo();
988 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data())); 991 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data()));
989 EXPECT_EQ(6, info.selectionStart); 992 EXPECT_EQ(6, info.selectionStart);
990 EXPECT_EQ(6, info.selectionEnd); 993 EXPECT_EQ(6, info.selectionEnd);
991 EXPECT_EQ(3, info.compositionStart); 994 EXPECT_EQ(3, info.compositionStart);
992 EXPECT_EQ(8, info.compositionEnd); 995 EXPECT_EQ(8, info.compositionEnd);
993 996
994 activeInputMethodController->finishComposingText( 997 activeInputMethodController->finishComposingText(
995 WebInputMethodController::DoNotKeepSelection); 998 WebInputMethodController::DoNotKeepSelection);
996 info = activeInputMethodController->textInputInfo(); 999 info = activeInputMethodController->textInputInfo();
(...skipping 10 matching lines...) Expand all
1007 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 1010 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
1008 m_baseURL + "input_field_populated.html"); 1011 m_baseURL + "input_field_populated.html");
1009 webView->setInitialFocus(false); 1012 webView->setInitialFocus(false);
1010 WebInputMethodController* activeInputMethodController = 1013 WebInputMethodController* activeInputMethodController =
1011 webView->mainFrameImpl() 1014 webView->mainFrameImpl()
1012 ->frameWidget() 1015 ->frameWidget()
1013 ->getActiveWebInputMethodController(); 1016 ->getActiveWebInputMethodController();
1014 1017
1015 WebVector<WebCompositionUnderline> emptyUnderlines; 1018 WebVector<WebCompositionUnderline> emptyUnderlines;
1016 1019
1017 activeInputMethodController->commitText("hello", emptyUnderlines, 0); 1020 activeInputMethodController->commitText("hello", emptyUnderlines, WebRange(),
1018 activeInputMethodController->commitText("world", emptyUnderlines, -5); 1021 0);
1022 activeInputMethodController->commitText("world", emptyUnderlines, WebRange(),
1023 -5);
1019 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 1024 WebTextInputInfo info = activeInputMethodController->textInputInfo();
1020 1025
1021 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); 1026 EXPECT_EQ("helloworld", std::string(info.value.utf8().data()));
1022 EXPECT_EQ(5, info.selectionStart); 1027 EXPECT_EQ(5, info.selectionStart);
1023 EXPECT_EQ(5, info.selectionEnd); 1028 EXPECT_EQ(5, info.selectionEnd);
1024 EXPECT_EQ(-1, info.compositionStart); 1029 EXPECT_EQ(-1, info.compositionStart);
1025 EXPECT_EQ(-1, info.compositionEnd); 1030 EXPECT_EQ(-1, info.compositionEnd);
1026 1031
1027 // Set up a composition that needs to be committed. 1032 // Set up a composition that needs to be committed.
1028 std::string compositionText("ABC"); 1033 std::string compositionText("ABC");
1029 1034
1030 // Caret is on the left of composing text. 1035 // Caret is on the left of composing text.
1031 activeInputMethodController->setComposition( 1036 activeInputMethodController->setComposition(
1032 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, 0); 1037 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1038 0, 0);
1033 info = activeInputMethodController->textInputInfo(); 1039 info = activeInputMethodController->textInputInfo();
1034 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1040 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1035 EXPECT_EQ(5, info.selectionStart); 1041 EXPECT_EQ(5, info.selectionStart);
1036 EXPECT_EQ(5, info.selectionEnd); 1042 EXPECT_EQ(5, info.selectionEnd);
1037 EXPECT_EQ(5, info.compositionStart); 1043 EXPECT_EQ(5, info.compositionStart);
1038 EXPECT_EQ(8, info.compositionEnd); 1044 EXPECT_EQ(8, info.compositionEnd);
1039 1045
1040 // Caret is on the right of composing text. 1046 // Caret is on the right of composing text.
1041 activeInputMethodController->setComposition( 1047 activeInputMethodController->setComposition(
1042 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); 1048 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1049 3, 3);
1043 info = activeInputMethodController->textInputInfo(); 1050 info = activeInputMethodController->textInputInfo();
1044 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1051 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1045 EXPECT_EQ(8, info.selectionStart); 1052 EXPECT_EQ(8, info.selectionStart);
1046 EXPECT_EQ(8, info.selectionEnd); 1053 EXPECT_EQ(8, info.selectionEnd);
1047 EXPECT_EQ(5, info.compositionStart); 1054 EXPECT_EQ(5, info.compositionStart);
1048 EXPECT_EQ(8, info.compositionEnd); 1055 EXPECT_EQ(8, info.compositionEnd);
1049 1056
1050 // Caret is between composing text and left boundary. 1057 // Caret is between composing text and left boundary.
1051 activeInputMethodController->setComposition( 1058 activeInputMethodController->setComposition(
1052 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -2, -2); 1059 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1060 -2, -2);
1053 info = activeInputMethodController->textInputInfo(); 1061 info = activeInputMethodController->textInputInfo();
1054 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1062 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1055 EXPECT_EQ(3, info.selectionStart); 1063 EXPECT_EQ(3, info.selectionStart);
1056 EXPECT_EQ(3, info.selectionEnd); 1064 EXPECT_EQ(3, info.selectionEnd);
1057 EXPECT_EQ(5, info.compositionStart); 1065 EXPECT_EQ(5, info.compositionStart);
1058 EXPECT_EQ(8, info.compositionEnd); 1066 EXPECT_EQ(8, info.compositionEnd);
1059 1067
1060 // Caret is between composing text and right boundary. 1068 // Caret is between composing text and right boundary.
1061 activeInputMethodController->setComposition( 1069 activeInputMethodController->setComposition(
1062 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 5, 5); 1070 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1071 5, 5);
1063 info = activeInputMethodController->textInputInfo(); 1072 info = activeInputMethodController->textInputInfo();
1064 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1073 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1065 EXPECT_EQ(10, info.selectionStart); 1074 EXPECT_EQ(10, info.selectionStart);
1066 EXPECT_EQ(10, info.selectionEnd); 1075 EXPECT_EQ(10, info.selectionEnd);
1067 EXPECT_EQ(5, info.compositionStart); 1076 EXPECT_EQ(5, info.compositionStart);
1068 EXPECT_EQ(8, info.compositionEnd); 1077 EXPECT_EQ(8, info.compositionEnd);
1069 1078
1070 // Caret is on the left boundary. 1079 // Caret is on the left boundary.
1071 activeInputMethodController->setComposition( 1080 activeInputMethodController->setComposition(
1072 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -5, -5); 1081 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1082 -5, -5);
1073 info = activeInputMethodController->textInputInfo(); 1083 info = activeInputMethodController->textInputInfo();
1074 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1084 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1075 EXPECT_EQ(0, info.selectionStart); 1085 EXPECT_EQ(0, info.selectionStart);
1076 EXPECT_EQ(0, info.selectionEnd); 1086 EXPECT_EQ(0, info.selectionEnd);
1077 EXPECT_EQ(5, info.compositionStart); 1087 EXPECT_EQ(5, info.compositionStart);
1078 EXPECT_EQ(8, info.compositionEnd); 1088 EXPECT_EQ(8, info.compositionEnd);
1079 1089
1080 // Caret is on the right boundary. 1090 // Caret is on the right boundary.
1081 activeInputMethodController->setComposition( 1091 activeInputMethodController->setComposition(
1082 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 8, 8); 1092 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1093 8, 8);
1083 info = activeInputMethodController->textInputInfo(); 1094 info = activeInputMethodController->textInputInfo();
1084 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1095 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1085 EXPECT_EQ(13, info.selectionStart); 1096 EXPECT_EQ(13, info.selectionStart);
1086 EXPECT_EQ(13, info.selectionEnd); 1097 EXPECT_EQ(13, info.selectionEnd);
1087 EXPECT_EQ(5, info.compositionStart); 1098 EXPECT_EQ(5, info.compositionStart);
1088 EXPECT_EQ(8, info.compositionEnd); 1099 EXPECT_EQ(8, info.compositionEnd);
1089 1100
1090 // Caret exceeds the left boundary. 1101 // Caret exceeds the left boundary.
1091 activeInputMethodController->setComposition( 1102 activeInputMethodController->setComposition(
1092 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -100, 1103 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1093 -100); 1104 -100, -100);
1094 info = activeInputMethodController->textInputInfo(); 1105 info = activeInputMethodController->textInputInfo();
1095 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1106 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1096 EXPECT_EQ(0, info.selectionStart); 1107 EXPECT_EQ(0, info.selectionStart);
1097 EXPECT_EQ(0, info.selectionEnd); 1108 EXPECT_EQ(0, info.selectionEnd);
1098 EXPECT_EQ(5, info.compositionStart); 1109 EXPECT_EQ(5, info.compositionStart);
1099 EXPECT_EQ(8, info.compositionEnd); 1110 EXPECT_EQ(8, info.compositionEnd);
1100 1111
1101 // Caret exceeds the right boundary. 1112 // Caret exceeds the right boundary.
1102 activeInputMethodController->setComposition( 1113 activeInputMethodController->setComposition(
1103 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 100, 100); 1114 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1115 100, 100);
1104 info = activeInputMethodController->textInputInfo(); 1116 info = activeInputMethodController->textInputInfo();
1105 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); 1117 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
1106 EXPECT_EQ(13, info.selectionStart); 1118 EXPECT_EQ(13, info.selectionStart);
1107 EXPECT_EQ(13, info.selectionEnd); 1119 EXPECT_EQ(13, info.selectionEnd);
1108 EXPECT_EQ(5, info.compositionStart); 1120 EXPECT_EQ(5, info.compositionStart);
1109 EXPECT_EQ(8, info.compositionEnd); 1121 EXPECT_EQ(8, info.compositionEnd);
1110 } 1122 }
1111 1123
1112 TEST_P(WebViewTest, SetCompositionWithEmptyText) { 1124 TEST_P(WebViewTest, SetCompositionWithEmptyText) {
1113 URLTestHelpers::registerMockedURLFromBaseURL( 1125 URLTestHelpers::registerMockedURLFromBaseURL(
1114 WebString::fromUTF8(m_baseURL.c_str()), 1126 WebString::fromUTF8(m_baseURL.c_str()),
1115 WebString::fromUTF8("input_field_populated.html")); 1127 WebString::fromUTF8("input_field_populated.html"));
1116 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 1128 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
1117 m_baseURL + "input_field_populated.html"); 1129 m_baseURL + "input_field_populated.html");
1118 webView->setInitialFocus(false); 1130 webView->setInitialFocus(false);
1119 WebInputMethodController* activeInputMethodController = 1131 WebInputMethodController* activeInputMethodController =
1120 webView->mainFrameImpl() 1132 webView->mainFrameImpl()
1121 ->frameWidget() 1133 ->frameWidget()
1122 ->getActiveWebInputMethodController(); 1134 ->getActiveWebInputMethodController();
1123 1135
1124 WebVector<WebCompositionUnderline> emptyUnderlines; 1136 WebVector<WebCompositionUnderline> emptyUnderlines;
1125 1137
1126 activeInputMethodController->commitText("hello", emptyUnderlines, 0); 1138 activeInputMethodController->commitText("hello", emptyUnderlines, WebRange(),
1139 0);
1127 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 1140 WebTextInputInfo info = activeInputMethodController->textInputInfo();
1128 1141
1129 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 1142 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
1130 EXPECT_EQ(5, info.selectionStart); 1143 EXPECT_EQ(5, info.selectionStart);
1131 EXPECT_EQ(5, info.selectionEnd); 1144 EXPECT_EQ(5, info.selectionEnd);
1132 EXPECT_EQ(-1, info.compositionStart); 1145 EXPECT_EQ(-1, info.compositionStart);
1133 EXPECT_EQ(-1, info.compositionEnd); 1146 EXPECT_EQ(-1, info.compositionEnd);
1134 1147
1135 activeInputMethodController->setComposition(WebString::fromUTF8(""), 1148 activeInputMethodController->setComposition(
1136 emptyUnderlines, 0, 0); 1149 WebString::fromUTF8(""), emptyUnderlines, WebRange(), 0, 0);
1137 info = activeInputMethodController->textInputInfo(); 1150 info = activeInputMethodController->textInputInfo();
1138 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 1151 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
1139 EXPECT_EQ(5, info.selectionStart); 1152 EXPECT_EQ(5, info.selectionStart);
1140 EXPECT_EQ(5, info.selectionEnd); 1153 EXPECT_EQ(5, info.selectionEnd);
1141 EXPECT_EQ(-1, info.compositionStart); 1154 EXPECT_EQ(-1, info.compositionStart);
1142 EXPECT_EQ(-1, info.compositionEnd); 1155 EXPECT_EQ(-1, info.compositionEnd);
1143 1156
1144 activeInputMethodController->setComposition(WebString::fromUTF8(""), 1157 activeInputMethodController->setComposition(
1145 emptyUnderlines, -2, -2); 1158 WebString::fromUTF8(""), emptyUnderlines, WebRange(), -2, -2);
1146 info = activeInputMethodController->textInputInfo(); 1159 info = activeInputMethodController->textInputInfo();
1147 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 1160 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
1148 EXPECT_EQ(3, info.selectionStart); 1161 EXPECT_EQ(3, info.selectionStart);
1149 EXPECT_EQ(3, info.selectionEnd); 1162 EXPECT_EQ(3, info.selectionEnd);
1150 EXPECT_EQ(-1, info.compositionStart); 1163 EXPECT_EQ(-1, info.compositionStart);
1151 EXPECT_EQ(-1, info.compositionEnd); 1164 EXPECT_EQ(-1, info.compositionEnd);
1152 } 1165 }
1153 1166
1154 TEST_P(WebViewTest, CommitTextForNewCaretPositions) { 1167 TEST_P(WebViewTest, CommitTextForNewCaretPositions) {
1155 URLTestHelpers::registerMockedURLFromBaseURL( 1168 URLTestHelpers::registerMockedURLFromBaseURL(
1156 WebString::fromUTF8(m_baseURL.c_str()), 1169 WebString::fromUTF8(m_baseURL.c_str()),
1157 WebString::fromUTF8("input_field_populated.html")); 1170 WebString::fromUTF8("input_field_populated.html"));
1158 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 1171 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
1159 m_baseURL + "input_field_populated.html"); 1172 m_baseURL + "input_field_populated.html");
1160 webView->setInitialFocus(false); 1173 webView->setInitialFocus(false);
1161 WebInputMethodController* activeInputMethodController = 1174 WebInputMethodController* activeInputMethodController =
1162 webView->mainFrameImpl() 1175 webView->mainFrameImpl()
1163 ->frameWidget() 1176 ->frameWidget()
1164 ->getActiveWebInputMethodController(); 1177 ->getActiveWebInputMethodController();
1165 1178
1166 WebVector<WebCompositionUnderline> emptyUnderlines; 1179 WebVector<WebCompositionUnderline> emptyUnderlines;
1167 1180
1168 // Caret is on the left of composing text. 1181 // Caret is on the left of composing text.
1169 activeInputMethodController->commitText("ab", emptyUnderlines, -2); 1182 activeInputMethodController->commitText("ab", emptyUnderlines, WebRange(),
1183 -2);
1170 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 1184 WebTextInputInfo info = activeInputMethodController->textInputInfo();
1171 EXPECT_EQ("ab", std::string(info.value.utf8().data())); 1185 EXPECT_EQ("ab", std::string(info.value.utf8().data()));
1172 EXPECT_EQ(0, info.selectionStart); 1186 EXPECT_EQ(0, info.selectionStart);
1173 EXPECT_EQ(0, info.selectionEnd); 1187 EXPECT_EQ(0, info.selectionEnd);
1174 EXPECT_EQ(-1, info.compositionStart); 1188 EXPECT_EQ(-1, info.compositionStart);
1175 EXPECT_EQ(-1, info.compositionEnd); 1189 EXPECT_EQ(-1, info.compositionEnd);
1176 1190
1177 // Caret is on the right of composing text. 1191 // Caret is on the right of composing text.
1178 activeInputMethodController->commitText("c", emptyUnderlines, 1); 1192 activeInputMethodController->commitText("c", emptyUnderlines, WebRange(), 1);
1179 info = activeInputMethodController->textInputInfo(); 1193 info = activeInputMethodController->textInputInfo();
1180 EXPECT_EQ("cab", std::string(info.value.utf8().data())); 1194 EXPECT_EQ("cab", std::string(info.value.utf8().data()));
1181 EXPECT_EQ(2, info.selectionStart); 1195 EXPECT_EQ(2, info.selectionStart);
1182 EXPECT_EQ(2, info.selectionEnd); 1196 EXPECT_EQ(2, info.selectionEnd);
1183 EXPECT_EQ(-1, info.compositionStart); 1197 EXPECT_EQ(-1, info.compositionStart);
1184 EXPECT_EQ(-1, info.compositionEnd); 1198 EXPECT_EQ(-1, info.compositionEnd);
1185 1199
1186 // Caret is on the left boundary. 1200 // Caret is on the left boundary.
1187 activeInputMethodController->commitText("def", emptyUnderlines, -5); 1201 activeInputMethodController->commitText("def", emptyUnderlines, WebRange(),
1202 -5);
1188 info = activeInputMethodController->textInputInfo(); 1203 info = activeInputMethodController->textInputInfo();
1189 EXPECT_EQ("cadefb", std::string(info.value.utf8().data())); 1204 EXPECT_EQ("cadefb", std::string(info.value.utf8().data()));
1190 EXPECT_EQ(0, info.selectionStart); 1205 EXPECT_EQ(0, info.selectionStart);
1191 EXPECT_EQ(0, info.selectionEnd); 1206 EXPECT_EQ(0, info.selectionEnd);
1192 EXPECT_EQ(-1, info.compositionStart); 1207 EXPECT_EQ(-1, info.compositionStart);
1193 EXPECT_EQ(-1, info.compositionEnd); 1208 EXPECT_EQ(-1, info.compositionEnd);
1194 1209
1195 // Caret is on the right boundary. 1210 // Caret is on the right boundary.
1196 activeInputMethodController->commitText("g", emptyUnderlines, 6); 1211 activeInputMethodController->commitText("g", emptyUnderlines, WebRange(), 6);
1197 info = activeInputMethodController->textInputInfo(); 1212 info = activeInputMethodController->textInputInfo();
1198 EXPECT_EQ("gcadefb", std::string(info.value.utf8().data())); 1213 EXPECT_EQ("gcadefb", std::string(info.value.utf8().data()));
1199 EXPECT_EQ(7, info.selectionStart); 1214 EXPECT_EQ(7, info.selectionStart);
1200 EXPECT_EQ(7, info.selectionEnd); 1215 EXPECT_EQ(7, info.selectionEnd);
1201 EXPECT_EQ(-1, info.compositionStart); 1216 EXPECT_EQ(-1, info.compositionStart);
1202 EXPECT_EQ(-1, info.compositionEnd); 1217 EXPECT_EQ(-1, info.compositionEnd);
1203 1218
1204 // Caret exceeds the left boundary. 1219 // Caret exceeds the left boundary.
1205 activeInputMethodController->commitText("hi", emptyUnderlines, -100); 1220 activeInputMethodController->commitText("hi", emptyUnderlines, WebRange(),
1221 -100);
1206 info = activeInputMethodController->textInputInfo(); 1222 info = activeInputMethodController->textInputInfo();
1207 EXPECT_EQ("gcadefbhi", std::string(info.value.utf8().data())); 1223 EXPECT_EQ("gcadefbhi", std::string(info.value.utf8().data()));
1208 EXPECT_EQ(0, info.selectionStart); 1224 EXPECT_EQ(0, info.selectionStart);
1209 EXPECT_EQ(0, info.selectionEnd); 1225 EXPECT_EQ(0, info.selectionEnd);
1210 EXPECT_EQ(-1, info.compositionStart); 1226 EXPECT_EQ(-1, info.compositionStart);
1211 EXPECT_EQ(-1, info.compositionEnd); 1227 EXPECT_EQ(-1, info.compositionEnd);
1212 1228
1213 // Caret exceeds the right boundary. 1229 // Caret exceeds the right boundary.
1214 activeInputMethodController->commitText("jk", emptyUnderlines, 100); 1230 activeInputMethodController->commitText("jk", emptyUnderlines, WebRange(),
1231 100);
1215 info = activeInputMethodController->textInputInfo(); 1232 info = activeInputMethodController->textInputInfo();
1216 EXPECT_EQ("jkgcadefbhi", std::string(info.value.utf8().data())); 1233 EXPECT_EQ("jkgcadefbhi", std::string(info.value.utf8().data()));
1217 EXPECT_EQ(11, info.selectionStart); 1234 EXPECT_EQ(11, info.selectionStart);
1218 EXPECT_EQ(11, info.selectionEnd); 1235 EXPECT_EQ(11, info.selectionEnd);
1219 EXPECT_EQ(-1, info.compositionStart); 1236 EXPECT_EQ(-1, info.compositionStart);
1220 EXPECT_EQ(-1, info.compositionEnd); 1237 EXPECT_EQ(-1, info.compositionEnd);
1221 } 1238 }
1222 1239
1223 TEST_P(WebViewTest, CommitTextWhileComposing) { 1240 TEST_P(WebViewTest, CommitTextWhileComposing) {
1224 URLTestHelpers::registerMockedURLFromBaseURL( 1241 URLTestHelpers::registerMockedURLFromBaseURL(
1225 WebString::fromUTF8(m_baseURL.c_str()), 1242 WebString::fromUTF8(m_baseURL.c_str()),
1226 WebString::fromUTF8("input_field_populated.html")); 1243 WebString::fromUTF8("input_field_populated.html"));
1227 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 1244 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
1228 m_baseURL + "input_field_populated.html"); 1245 m_baseURL + "input_field_populated.html");
1229 webView->setInitialFocus(false); 1246 webView->setInitialFocus(false);
1230 WebInputMethodController* activeInputMethodController = 1247 WebInputMethodController* activeInputMethodController =
1231 webView->mainFrameImpl() 1248 webView->mainFrameImpl()
1232 ->frameWidget() 1249 ->frameWidget()
1233 ->getActiveWebInputMethodController(); 1250 ->getActiveWebInputMethodController();
1234 1251
1235 WebVector<WebCompositionUnderline> emptyUnderlines; 1252 WebVector<WebCompositionUnderline> emptyUnderlines;
1236 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), 1253 activeInputMethodController->setComposition(
1237 emptyUnderlines, 0, 0); 1254 WebString::fromUTF8("abc"), emptyUnderlines, WebRange(), 0, 0);
1238 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 1255 WebTextInputInfo info = activeInputMethodController->textInputInfo();
1239 EXPECT_EQ("abc", std::string(info.value.utf8().data())); 1256 EXPECT_EQ("abc", std::string(info.value.utf8().data()));
1240 EXPECT_EQ(0, info.selectionStart); 1257 EXPECT_EQ(0, info.selectionStart);
1241 EXPECT_EQ(0, info.selectionEnd); 1258 EXPECT_EQ(0, info.selectionEnd);
1242 EXPECT_EQ(0, info.compositionStart); 1259 EXPECT_EQ(0, info.compositionStart);
1243 EXPECT_EQ(3, info.compositionEnd); 1260 EXPECT_EQ(3, info.compositionEnd);
1244 1261
1245 // Deletes ongoing composition, inserts the specified text and moves the 1262 // Deletes ongoing composition, inserts the specified text and moves the
1246 // caret. 1263 // caret.
1247 activeInputMethodController->commitText("hello", emptyUnderlines, -2); 1264 activeInputMethodController->commitText("hello", emptyUnderlines, WebRange(),
1265 -2);
1248 info = activeInputMethodController->textInputInfo(); 1266 info = activeInputMethodController->textInputInfo();
1249 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 1267 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
1250 EXPECT_EQ(3, info.selectionStart); 1268 EXPECT_EQ(3, info.selectionStart);
1251 EXPECT_EQ(3, info.selectionEnd); 1269 EXPECT_EQ(3, info.selectionEnd);
1252 EXPECT_EQ(-1, info.compositionStart); 1270 EXPECT_EQ(-1, info.compositionStart);
1253 EXPECT_EQ(-1, info.compositionEnd); 1271 EXPECT_EQ(-1, info.compositionEnd);
1254 1272
1255 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), 1273 activeInputMethodController->setComposition(
1256 emptyUnderlines, 0, 0); 1274 WebString::fromUTF8("abc"), emptyUnderlines, WebRange(), 0, 0);
1257 info = activeInputMethodController->textInputInfo(); 1275 info = activeInputMethodController->textInputInfo();
1258 EXPECT_EQ("helabclo", std::string(info.value.utf8().data())); 1276 EXPECT_EQ("helabclo", std::string(info.value.utf8().data()));
1259 EXPECT_EQ(3, info.selectionStart); 1277 EXPECT_EQ(3, info.selectionStart);
1260 EXPECT_EQ(3, info.selectionEnd); 1278 EXPECT_EQ(3, info.selectionEnd);
1261 EXPECT_EQ(3, info.compositionStart); 1279 EXPECT_EQ(3, info.compositionStart);
1262 EXPECT_EQ(6, info.compositionEnd); 1280 EXPECT_EQ(6, info.compositionEnd);
1263 1281
1264 // Deletes ongoing composition and moves the caret. 1282 // Deletes ongoing composition and moves the caret.
1265 activeInputMethodController->commitText("", emptyUnderlines, 2); 1283 activeInputMethodController->commitText("", emptyUnderlines, WebRange(), 2);
1266 info = activeInputMethodController->textInputInfo(); 1284 info = activeInputMethodController->textInputInfo();
1267 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 1285 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
1268 EXPECT_EQ(5, info.selectionStart); 1286 EXPECT_EQ(5, info.selectionStart);
1269 EXPECT_EQ(5, info.selectionEnd); 1287 EXPECT_EQ(5, info.selectionEnd);
1270 EXPECT_EQ(-1, info.compositionStart); 1288 EXPECT_EQ(-1, info.compositionStart);
1271 EXPECT_EQ(-1, info.compositionEnd); 1289 EXPECT_EQ(-1, info.compositionEnd);
1272 1290
1273 // Inserts the specified text and moves the caret. 1291 // Inserts the specified text and moves the caret.
1274 activeInputMethodController->commitText("world", emptyUnderlines, -5); 1292 activeInputMethodController->commitText("world", emptyUnderlines, WebRange(),
1293 -5);
1275 info = activeInputMethodController->textInputInfo(); 1294 info = activeInputMethodController->textInputInfo();
1276 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); 1295 EXPECT_EQ("helloworld", std::string(info.value.utf8().data()));
1277 EXPECT_EQ(5, info.selectionStart); 1296 EXPECT_EQ(5, info.selectionStart);
1278 EXPECT_EQ(5, info.selectionEnd); 1297 EXPECT_EQ(5, info.selectionEnd);
1279 EXPECT_EQ(-1, info.compositionStart); 1298 EXPECT_EQ(-1, info.compositionStart);
1280 EXPECT_EQ(-1, info.compositionEnd); 1299 EXPECT_EQ(-1, info.compositionEnd);
1281 1300
1282 // Only moves the caret. 1301 // Only moves the caret.
1283 activeInputMethodController->commitText("", emptyUnderlines, 5); 1302 activeInputMethodController->commitText("", emptyUnderlines, WebRange(), 5);
1284 info = activeInputMethodController->textInputInfo(); 1303 info = activeInputMethodController->textInputInfo();
1285 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); 1304 EXPECT_EQ("helloworld", std::string(info.value.utf8().data()));
1286 EXPECT_EQ(10, info.selectionStart); 1305 EXPECT_EQ(10, info.selectionStart);
1287 EXPECT_EQ(10, info.selectionEnd); 1306 EXPECT_EQ(10, info.selectionEnd);
1288 EXPECT_EQ(-1, info.compositionStart); 1307 EXPECT_EQ(-1, info.compositionStart);
1289 EXPECT_EQ(-1, info.compositionEnd); 1308 EXPECT_EQ(-1, info.compositionEnd);
1290 } 1309 }
1291 1310
1292 TEST_P(WebViewTest, FinishCompositionDoesNotRevealSelection) { 1311 TEST_P(WebViewTest, FinishCompositionDoesNotRevealSelection) {
1293 URLTestHelpers::registerMockedURLFromBaseURL( 1312 URLTestHelpers::registerMockedURLFromBaseURL(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 activeInputMethodController->finishComposingText( 1371 activeInputMethodController->finishComposingText(
1353 WebInputMethodController::KeepSelection); 1372 WebInputMethodController::KeepSelection);
1354 info = activeInputMethodController->textInputInfo(); 1373 info = activeInputMethodController->textInputInfo();
1355 EXPECT_EQ(4, info.selectionStart); 1374 EXPECT_EQ(4, info.selectionStart);
1356 EXPECT_EQ(4, info.selectionEnd); 1375 EXPECT_EQ(4, info.selectionEnd);
1357 EXPECT_EQ(-1, info.compositionStart); 1376 EXPECT_EQ(-1, info.compositionStart);
1358 EXPECT_EQ(-1, info.compositionEnd); 1377 EXPECT_EQ(-1, info.compositionEnd);
1359 1378
1360 std::string compositionText("\n"); 1379 std::string compositionText("\n");
1361 activeInputMethodController->commitText( 1380 activeInputMethodController->commitText(
1362 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0); 1381 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1382 0);
1363 info = activeInputMethodController->textInputInfo(); 1383 info = activeInputMethodController->textInputInfo();
1364 EXPECT_EQ(5, info.selectionStart); 1384 EXPECT_EQ(5, info.selectionStart);
1365 EXPECT_EQ(5, info.selectionEnd); 1385 EXPECT_EQ(5, info.selectionEnd);
1366 EXPECT_EQ(-1, info.compositionStart); 1386 EXPECT_EQ(-1, info.compositionStart);
1367 EXPECT_EQ(-1, info.compositionEnd); 1387 EXPECT_EQ(-1, info.compositionEnd);
1368 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", 1388 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz",
1369 std::string(info.value.utf8().data())); 1389 std::string(info.value.utf8().data()));
1370 } 1390 }
1371 1391
1372 TEST_P(WebViewTest, ExtendSelectionAndDelete) { 1392 TEST_P(WebViewTest, ExtendSelectionAndDelete) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 webView->setInitialFocus(false); 1492 webView->setInitialFocus(false);
1473 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); 1493 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
1474 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); 1494 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
1475 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 1495 WebLocalFrameImpl* frame = webView->mainFrameImpl();
1476 WebInputMethodController* activeInputMethodController = 1496 WebInputMethodController* activeInputMethodController =
1477 frame->frameWidget()->getActiveWebInputMethodController(); 1497 frame->frameWidget()->getActiveWebInputMethodController();
1478 frame->setEditableSelectionOffsets(27, 27); 1498 frame->setEditableSelectionOffsets(27, 27);
1479 std::string newLineText("\n"); 1499 std::string newLineText("\n");
1480 WebVector<WebCompositionUnderline> emptyUnderlines; 1500 WebVector<WebCompositionUnderline> emptyUnderlines;
1481 activeInputMethodController->commitText( 1501 activeInputMethodController->commitText(
1482 WebString::fromUTF8(newLineText.c_str()), emptyUnderlines, 0); 1502 WebString::fromUTF8(newLineText.c_str()), emptyUnderlines, WebRange(), 0);
1483 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 1503 WebTextInputInfo info = activeInputMethodController->textInputInfo();
1484 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", 1504 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz",
1485 std::string(info.value.utf8().data())); 1505 std::string(info.value.utf8().data()));
1486 1506
1487 frame->setEditableSelectionOffsets(31, 31); 1507 frame->setEditableSelectionOffsets(31, 31);
1488 frame->setCompositionFromExistingText(30, 34, underlines); 1508 frame->setCompositionFromExistingText(30, 34, underlines);
1489 info = activeInputMethodController->textInputInfo(); 1509 info = activeInputMethodController->textInputInfo();
1490 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", 1510 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz",
1491 std::string(info.value.utf8().data())); 1511 std::string(info.value.utf8().data()));
1492 EXPECT_EQ(31, info.selectionStart); 1512 EXPECT_EQ(31, info.selectionStart);
1493 EXPECT_EQ(31, info.selectionEnd); 1513 EXPECT_EQ(31, info.selectionEnd);
1494 EXPECT_EQ(30, info.compositionStart); 1514 EXPECT_EQ(30, info.compositionStart);
1495 EXPECT_EQ(34, info.compositionEnd); 1515 EXPECT_EQ(34, info.compositionEnd);
1496 1516
1497 std::string compositionText("yolo"); 1517 std::string compositionText("yolo");
1498 activeInputMethodController->commitText( 1518 activeInputMethodController->commitText(
1499 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0); 1519 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
1520 0);
1500 info = activeInputMethodController->textInputInfo(); 1521 info = activeInputMethodController->textInputInfo();
1501 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", 1522 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz",
1502 std::string(info.value.utf8().data())); 1523 std::string(info.value.utf8().data()));
1503 EXPECT_EQ(34, info.selectionStart); 1524 EXPECT_EQ(34, info.selectionStart);
1504 EXPECT_EQ(34, info.selectionEnd); 1525 EXPECT_EQ(34, info.selectionEnd);
1505 EXPECT_EQ(-1, info.compositionStart); 1526 EXPECT_EQ(-1, info.compositionStart);
1506 EXPECT_EQ(-1, info.compositionEnd); 1527 EXPECT_EQ(-1, info.compositionEnd);
1507 } 1528 }
1508 1529
1509 TEST_P(WebViewTest, SetCompositionFromExistingTextInRichText) { 1530 TEST_P(WebViewTest, SetCompositionFromExistingTextInRichText) {
(...skipping 22 matching lines...) Expand all
1532 webView->setInitialFocus(false); 1553 webView->setInitialFocus(false);
1533 1554
1534 std::string compositionTextFirst("hello "); 1555 std::string compositionTextFirst("hello ");
1535 std::string compositionTextSecond("world"); 1556 std::string compositionTextSecond("world");
1536 WebVector<WebCompositionUnderline> emptyUnderlines; 1557 WebVector<WebCompositionUnderline> emptyUnderlines;
1537 WebInputMethodController* activeInputMethodController = 1558 WebInputMethodController* activeInputMethodController =
1538 webView->mainFrameImpl() 1559 webView->mainFrameImpl()
1539 ->frameWidget() 1560 ->frameWidget()
1540 ->getActiveWebInputMethodController(); 1561 ->getActiveWebInputMethodController();
1541 activeInputMethodController->commitText( 1562 activeInputMethodController->commitText(
1542 WebString::fromUTF8(compositionTextFirst.c_str()), emptyUnderlines, 0); 1563 WebString::fromUTF8(compositionTextFirst.c_str()), emptyUnderlines,
1564 WebRange(), 0);
1543 activeInputMethodController->setComposition( 1565 activeInputMethodController->setComposition(
1544 WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, 1566 WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines,
1545 5); 1567 WebRange(), 5, 5);
1546 1568
1547 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 1569 WebTextInputInfo info = activeInputMethodController->textInputInfo();
1548 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); 1570 EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
1549 EXPECT_EQ(11, info.selectionStart); 1571 EXPECT_EQ(11, info.selectionStart);
1550 EXPECT_EQ(11, info.selectionEnd); 1572 EXPECT_EQ(11, info.selectionEnd);
1551 EXPECT_EQ(6, info.compositionStart); 1573 EXPECT_EQ(6, info.compositionStart);
1552 EXPECT_EQ(11, info.compositionEnd); 1574 EXPECT_EQ(11, info.compositionEnd);
1553 1575
1554 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 1576 WebLocalFrameImpl* frame = webView->mainFrameImpl();
1555 frame->setEditableSelectionOffsets(6, 6); 1577 frame->setEditableSelectionOffsets(6, 6);
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
2801 webView->setInitialFocus(false); 2823 webView->setInitialFocus(false);
2802 2824
2803 // Test both input elements. 2825 // Test both input elements.
2804 for (int i = 0; i < 2; ++i) { 2826 for (int i = 0; i < 2; ++i) {
2805 // Select composition and do sanity check. 2827 // Select composition and do sanity check.
2806 WebVector<WebCompositionUnderline> emptyUnderlines; 2828 WebVector<WebCompositionUnderline> emptyUnderlines;
2807 frame->setEditableSelectionOffsets(6, 6); 2829 frame->setEditableSelectionOffsets(6, 6);
2808 WebInputMethodController* activeInputMethodController = 2830 WebInputMethodController* activeInputMethodController =
2809 frame->frameWidget()->getActiveWebInputMethodController(); 2831 frame->frameWidget()->getActiveWebInputMethodController();
2810 EXPECT_TRUE(activeInputMethodController->setComposition( 2832 EXPECT_TRUE(activeInputMethodController->setComposition(
2811 "fghij", emptyUnderlines, 0, 5)); 2833 "fghij", emptyUnderlines, WebRange(), 0, 5));
2812 frame->setEditableSelectionOffsets(11, 11); 2834 frame->setEditableSelectionOffsets(11, 11);
2813 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case"); 2835 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case");
2814 2836
2815 // Press Backspace and verify composition didn't get cancelled. This is to 2837 // Press Backspace and verify composition didn't get cancelled. This is to
2816 // verify the fix for crbug.com/429916. 2838 // verify the fix for crbug.com/429916.
2817 WebKeyboardEvent keyEvent(WebInputEvent::RawKeyDown, 2839 WebKeyboardEvent keyEvent(WebInputEvent::RawKeyDown,
2818 WebInputEvent::NoModifiers, 2840 WebInputEvent::NoModifiers,
2819 WebInputEvent::TimeStampForTesting); 2841 WebInputEvent::TimeStampForTesting);
2820 keyEvent.domKey = Platform::current()->domKeyEnumFromString("\b"); 2842 keyEvent.domKey = Platform::current()->domKeyEnumFromString("\b");
2821 keyEvent.windowsKeyCode = VKEY_BACK; 2843 keyEvent.windowsKeyCode = VKEY_BACK;
2822 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); 2844 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent));
2823 2845
2824 frame->setEditableSelectionOffsets(6, 6); 2846 frame->setEditableSelectionOffsets(6, 6);
2825 EXPECT_TRUE(activeInputMethodController->setComposition( 2847 EXPECT_TRUE(activeInputMethodController->setComposition(
2826 "fghi", emptyUnderlines, 0, 4)); 2848 "fghi", emptyUnderlines, WebRange(), 0, 4));
2827 frame->setEditableSelectionOffsets(10, 10); 2849 frame->setEditableSelectionOffsets(10, 10);
2828 verifySelectionAndComposition(webView, 10, 10, 6, 10, 2850 verifySelectionAndComposition(webView, 10, 10, 6, 10,
2829 "after pressing Backspace"); 2851 "after pressing Backspace");
2830 2852
2831 keyEvent.setType(WebInputEvent::KeyUp); 2853 keyEvent.setType(WebInputEvent::KeyUp);
2832 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); 2854 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent));
2833 2855
2834 webView->advanceFocus(false); 2856 webView->advanceFocus(false);
2835 } 2857 }
2836 2858
(...skipping 10 matching lines...) Expand all
2847 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 2869 WebLocalFrameImpl* frame = webView->mainFrameImpl();
2848 frame->setAutofillClient(&client); 2870 frame->setAutofillClient(&client);
2849 webView->setInitialFocus(false); 2871 webView->setInitialFocus(false);
2850 WebInputMethodController* activeInputMethodController = 2872 WebInputMethodController* activeInputMethodController =
2851 frame->frameWidget()->getActiveWebInputMethodController(); 2873 frame->frameWidget()->getActiveWebInputMethodController();
2852 // Set up a composition that needs to be committed. 2874 // Set up a composition that needs to be committed.
2853 std::string compositionText("testingtext"); 2875 std::string compositionText("testingtext");
2854 2876
2855 WebVector<WebCompositionUnderline> emptyUnderlines; 2877 WebVector<WebCompositionUnderline> emptyUnderlines;
2856 activeInputMethodController->setComposition( 2878 activeInputMethodController->setComposition(
2857 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, 2879 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(),
2858 compositionText.length()); 2880 0, compositionText.length());
2859 2881
2860 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 2882 WebTextInputInfo info = activeInputMethodController->textInputInfo();
2861 EXPECT_EQ(0, info.selectionStart); 2883 EXPECT_EQ(0, info.selectionStart);
2862 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); 2884 EXPECT_EQ((int)compositionText.length(), info.selectionEnd);
2863 EXPECT_EQ(0, info.compositionStart); 2885 EXPECT_EQ(0, info.compositionStart);
2864 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); 2886 EXPECT_EQ((int)compositionText.length(), info.compositionEnd);
2865 2887
2866 client.clearChangeCounts(); 2888 client.clearChangeCounts();
2867 activeInputMethodController->finishComposingText( 2889 activeInputMethodController->finishComposingText(
2868 WebInputMethodController::KeepSelection); 2890 WebInputMethodController::KeepSelection);
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
3670 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 3692 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
3671 m_baseURL + "input_field_populated.html"); 3693 m_baseURL + "input_field_populated.html");
3672 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 3694 WebLocalFrameImpl* frame = webView->mainFrameImpl();
3673 MockAutofillClient client; 3695 MockAutofillClient client;
3674 frame->setAutofillClient(&client); 3696 frame->setAutofillClient(&client);
3675 webView->setInitialFocus(false); 3697 webView->setInitialFocus(false);
3676 3698
3677 EXPECT_TRUE( 3699 EXPECT_TRUE(
3678 frame->frameWidget()->getActiveWebInputMethodController()->setComposition( 3700 frame->frameWidget()->getActiveWebInputMethodController()->setComposition(
3679 WebString::fromUTF8(std::string("hello").c_str()), 3701 WebString::fromUTF8(std::string("hello").c_str()),
3680 WebVector<WebCompositionUnderline>(), 3, 3)); 3702 WebVector<WebCompositionUnderline>(), WebRange(), 3, 3));
3681 EXPECT_EQ(1, client.textChangesFromUserGesture()); 3703 EXPECT_EQ(1, client.textChangesFromUserGesture());
3682 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); 3704 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
3683 EXPECT_TRUE(frame->hasMarkedText()); 3705 EXPECT_TRUE(frame->hasMarkedText());
3684 3706
3685 frame->setAutofillClient(0); 3707 frame->setAutofillClient(0);
3686 } 3708 }
3687 3709
3688 TEST_P(WebViewTest, CompareSelectAllToContentAsText) { 3710 TEST_P(WebViewTest, CompareSelectAllToContentAsText) {
3689 URLTestHelpers::registerMockedURLFromBaseURL( 3711 URLTestHelpers::registerMockedURLFromBaseURL(
3690 WebString::fromUTF8(m_baseURL.c_str()), 3712 WebString::fromUTF8(m_baseURL.c_str()),
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
4073 m_baseURL + "input_field_password.html", true); 4095 m_baseURL + "input_field_password.html", true);
4074 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 4096 WebLocalFrameImpl* frame = webView->mainFrameImpl();
4075 frame->setAutofillClient(&client); 4097 frame->setAutofillClient(&client);
4076 webView->setInitialFocus(false); 4098 webView->setInitialFocus(false);
4077 4099
4078 WebVector<WebCompositionUnderline> emptyUnderlines; 4100 WebVector<WebCompositionUnderline> emptyUnderlines;
4079 4101
4080 EXPECT_TRUE( 4102 EXPECT_TRUE(
4081 frame->frameWidget()->getActiveWebInputMethodController()->commitText( 4103 frame->frameWidget()->getActiveWebInputMethodController()->commitText(
4082 WebString::fromUTF8(std::string("hello").c_str()), emptyUnderlines, 4104 WebString::fromUTF8(std::string("hello").c_str()), emptyUnderlines,
4083 0)); 4105 WebRange(), 0));
4084 EXPECT_EQ(1, client.textChangesFromUserGesture()); 4106 EXPECT_EQ(1, client.textChangesFromUserGesture());
4085 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); 4107 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
4086 frame->setAutofillClient(0); 4108 frame->setAutofillClient(0);
4087 } 4109 }
4088 4110
4089 // Verify that a WebView created with a ScopedPageSuspender already on the 4111 // Verify that a WebView created with a ScopedPageSuspender already on the
4090 // stack defers its loads. 4112 // stack defers its loads.
4091 TEST_P(WebViewTest, CreatedDuringPageSuspension) { 4113 TEST_P(WebViewTest, CreatedDuringPageSuspension) {
4092 { 4114 {
4093 WebViewImpl* webView = m_webViewHelper.initialize(); 4115 WebViewImpl* webView = m_webViewHelper.initialize();
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
4374 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); 4396 EXPECT_EQ(expectedWidth, vwElement->offsetWidth());
4375 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); 4397 EXPECT_EQ(expectedHeight, vwElement->offsetHeight());
4376 4398
4377 webView->resize(WebSize(800, 600)); 4399 webView->resize(WebSize(800, 600));
4378 frame->printEnd(); 4400 frame->printEnd();
4379 4401
4380 EXPECT_EQ(800, vwElement->offsetWidth()); 4402 EXPECT_EQ(800, vwElement->offsetWidth());
4381 } 4403 }
4382 4404
4383 } // namespace blink 4405 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698