| OLD | NEW |
| 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 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 | 914 |
| 915 WebInputMethodController* activeInputMethodController = | 915 WebInputMethodController* activeInputMethodController = |
| 916 webView->mainFrameImpl() | 916 webView->mainFrameImpl() |
| 917 ->frameWidget() | 917 ->frameWidget() |
| 918 ->getActiveWebInputMethodController(); | 918 ->getActiveWebInputMethodController(); |
| 919 | 919 |
| 920 // The test requires non-empty composition. | 920 // The test requires non-empty composition. |
| 921 std::string compositionText("hello"); | 921 std::string compositionText("hello"); |
| 922 WebVector<WebCompositionUnderline> emptyUnderlines; | 922 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 923 activeInputMethodController->setComposition( | 923 activeInputMethodController->setComposition( |
| 924 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 5, 5); | 924 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 925 5, 5); |
| 925 | 926 |
| 926 // Do arbitrary change to make layout dirty. | 927 // Do arbitrary change to make layout dirty. |
| 927 Document& document = *webView->mainFrameImpl()->frame()->document(); | 928 Document& document = *webView->mainFrameImpl()->frame()->document(); |
| 928 Element* br = document.createElement("br"); | 929 Element* br = document.createElement("br"); |
| 929 document.body()->appendChild(br); | 930 document.body()->appendChild(br); |
| 930 | 931 |
| 931 // Should not hit assertion when calling | 932 // Should not hit assertion when calling |
| 932 // WebInputMethodController::finishComposingText with non-empty composition | 933 // WebInputMethodController::finishComposingText with non-empty composition |
| 933 // and dirty layout. | 934 // and dirty layout. |
| 934 activeInputMethodController->finishComposingText( | 935 activeInputMethodController->finishComposingText( |
| 935 WebInputMethodController::KeepSelection); | 936 WebInputMethodController::KeepSelection); |
| 936 } | 937 } |
| 937 | 938 |
| 938 TEST_P(WebViewTest, FinishComposingTextCursorPositionChange) { | 939 TEST_P(WebViewTest, FinishComposingTextCursorPositionChange) { |
| 939 registerMockedHttpURLLoad("input_field_populated.html"); | 940 registerMockedHttpURLLoad("input_field_populated.html"); |
| 940 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 941 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 941 m_baseURL + "input_field_populated.html"); | 942 m_baseURL + "input_field_populated.html"); |
| 942 webView->setInitialFocus(false); | 943 webView->setInitialFocus(false); |
| 943 | 944 |
| 944 // Set up a composition that needs to be committed. | 945 // Set up a composition that needs to be committed. |
| 945 std::string compositionText("hello"); | 946 std::string compositionText("hello"); |
| 946 | 947 |
| 947 WebInputMethodController* activeInputMethodController = | 948 WebInputMethodController* activeInputMethodController = |
| 948 webView->mainFrameImpl() | 949 webView->mainFrameImpl() |
| 949 ->frameWidget() | 950 ->frameWidget() |
| 950 ->getActiveWebInputMethodController(); | 951 ->getActiveWebInputMethodController(); |
| 951 WebVector<WebCompositionUnderline> emptyUnderlines; | 952 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 952 activeInputMethodController->setComposition( | 953 activeInputMethodController->setComposition( |
| 953 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); | 954 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 955 3, 3); |
| 954 | 956 |
| 955 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 957 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 956 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 958 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 957 EXPECT_EQ(3, info.selectionStart); | 959 EXPECT_EQ(3, info.selectionStart); |
| 958 EXPECT_EQ(3, info.selectionEnd); | 960 EXPECT_EQ(3, info.selectionEnd); |
| 959 EXPECT_EQ(0, info.compositionStart); | 961 EXPECT_EQ(0, info.compositionStart); |
| 960 EXPECT_EQ(5, info.compositionEnd); | 962 EXPECT_EQ(5, info.compositionEnd); |
| 961 | 963 |
| 962 activeInputMethodController->finishComposingText( | 964 activeInputMethodController->finishComposingText( |
| 963 WebInputMethodController::KeepSelection); | 965 WebInputMethodController::KeepSelection); |
| 964 info = activeInputMethodController->textInputInfo(); | 966 info = activeInputMethodController->textInputInfo(); |
| 965 EXPECT_EQ(3, info.selectionStart); | 967 EXPECT_EQ(3, info.selectionStart); |
| 966 EXPECT_EQ(3, info.selectionEnd); | 968 EXPECT_EQ(3, info.selectionEnd); |
| 967 EXPECT_EQ(-1, info.compositionStart); | 969 EXPECT_EQ(-1, info.compositionStart); |
| 968 EXPECT_EQ(-1, info.compositionEnd); | 970 EXPECT_EQ(-1, info.compositionEnd); |
| 969 | 971 |
| 970 activeInputMethodController->setComposition( | 972 activeInputMethodController->setComposition( |
| 971 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); | 973 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 974 3, 3); |
| 972 info = activeInputMethodController->textInputInfo(); | 975 info = activeInputMethodController->textInputInfo(); |
| 973 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data())); | 976 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data())); |
| 974 EXPECT_EQ(6, info.selectionStart); | 977 EXPECT_EQ(6, info.selectionStart); |
| 975 EXPECT_EQ(6, info.selectionEnd); | 978 EXPECT_EQ(6, info.selectionEnd); |
| 976 EXPECT_EQ(3, info.compositionStart); | 979 EXPECT_EQ(3, info.compositionStart); |
| 977 EXPECT_EQ(8, info.compositionEnd); | 980 EXPECT_EQ(8, info.compositionEnd); |
| 978 | 981 |
| 979 activeInputMethodController->finishComposingText( | 982 activeInputMethodController->finishComposingText( |
| 980 WebInputMethodController::DoNotKeepSelection); | 983 WebInputMethodController::DoNotKeepSelection); |
| 981 info = activeInputMethodController->textInputInfo(); | 984 info = activeInputMethodController->textInputInfo(); |
| 982 EXPECT_EQ(8, info.selectionStart); | 985 EXPECT_EQ(8, info.selectionStart); |
| 983 EXPECT_EQ(8, info.selectionEnd); | 986 EXPECT_EQ(8, info.selectionEnd); |
| 984 EXPECT_EQ(-1, info.compositionStart); | 987 EXPECT_EQ(-1, info.compositionStart); |
| 985 EXPECT_EQ(-1, info.compositionEnd); | 988 EXPECT_EQ(-1, info.compositionEnd); |
| 986 } | 989 } |
| 987 | 990 |
| 988 TEST_P(WebViewTest, SetCompositionForNewCaretPositions) { | 991 TEST_P(WebViewTest, SetCompositionForNewCaretPositions) { |
| 989 registerMockedHttpURLLoad("input_field_populated.html"); | 992 registerMockedHttpURLLoad("input_field_populated.html"); |
| 990 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 993 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 991 m_baseURL + "input_field_populated.html"); | 994 m_baseURL + "input_field_populated.html"); |
| 992 webView->setInitialFocus(false); | 995 webView->setInitialFocus(false); |
| 993 WebInputMethodController* activeInputMethodController = | 996 WebInputMethodController* activeInputMethodController = |
| 994 webView->mainFrameImpl() | 997 webView->mainFrameImpl() |
| 995 ->frameWidget() | 998 ->frameWidget() |
| 996 ->getActiveWebInputMethodController(); | 999 ->getActiveWebInputMethodController(); |
| 997 | 1000 |
| 998 WebVector<WebCompositionUnderline> emptyUnderlines; | 1001 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 999 | 1002 |
| 1000 activeInputMethodController->commitText("hello", emptyUnderlines, 0); | 1003 activeInputMethodController->commitText("hello", emptyUnderlines, WebRange(), |
| 1001 activeInputMethodController->commitText("world", emptyUnderlines, -5); | 1004 0); |
| 1005 activeInputMethodController->commitText("world", emptyUnderlines, WebRange(), |
| 1006 -5); |
| 1002 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 1007 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1003 | 1008 |
| 1004 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); | 1009 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); |
| 1005 EXPECT_EQ(5, info.selectionStart); | 1010 EXPECT_EQ(5, info.selectionStart); |
| 1006 EXPECT_EQ(5, info.selectionEnd); | 1011 EXPECT_EQ(5, info.selectionEnd); |
| 1007 EXPECT_EQ(-1, info.compositionStart); | 1012 EXPECT_EQ(-1, info.compositionStart); |
| 1008 EXPECT_EQ(-1, info.compositionEnd); | 1013 EXPECT_EQ(-1, info.compositionEnd); |
| 1009 | 1014 |
| 1010 // Set up a composition that needs to be committed. | 1015 // Set up a composition that needs to be committed. |
| 1011 std::string compositionText("ABC"); | 1016 std::string compositionText("ABC"); |
| 1012 | 1017 |
| 1013 // Caret is on the left of composing text. | 1018 // Caret is on the left of composing text. |
| 1014 activeInputMethodController->setComposition( | 1019 activeInputMethodController->setComposition( |
| 1015 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, 0); | 1020 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1021 0, 0); |
| 1016 info = activeInputMethodController->textInputInfo(); | 1022 info = activeInputMethodController->textInputInfo(); |
| 1017 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1023 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1018 EXPECT_EQ(5, info.selectionStart); | 1024 EXPECT_EQ(5, info.selectionStart); |
| 1019 EXPECT_EQ(5, info.selectionEnd); | 1025 EXPECT_EQ(5, info.selectionEnd); |
| 1020 EXPECT_EQ(5, info.compositionStart); | 1026 EXPECT_EQ(5, info.compositionStart); |
| 1021 EXPECT_EQ(8, info.compositionEnd); | 1027 EXPECT_EQ(8, info.compositionEnd); |
| 1022 | 1028 |
| 1023 // Caret is on the right of composing text. | 1029 // Caret is on the right of composing text. |
| 1024 activeInputMethodController->setComposition( | 1030 activeInputMethodController->setComposition( |
| 1025 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); | 1031 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1032 3, 3); |
| 1026 info = activeInputMethodController->textInputInfo(); | 1033 info = activeInputMethodController->textInputInfo(); |
| 1027 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1034 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1028 EXPECT_EQ(8, info.selectionStart); | 1035 EXPECT_EQ(8, info.selectionStart); |
| 1029 EXPECT_EQ(8, info.selectionEnd); | 1036 EXPECT_EQ(8, info.selectionEnd); |
| 1030 EXPECT_EQ(5, info.compositionStart); | 1037 EXPECT_EQ(5, info.compositionStart); |
| 1031 EXPECT_EQ(8, info.compositionEnd); | 1038 EXPECT_EQ(8, info.compositionEnd); |
| 1032 | 1039 |
| 1033 // Caret is between composing text and left boundary. | 1040 // Caret is between composing text and left boundary. |
| 1034 activeInputMethodController->setComposition( | 1041 activeInputMethodController->setComposition( |
| 1035 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -2, -2); | 1042 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1043 -2, -2); |
| 1036 info = activeInputMethodController->textInputInfo(); | 1044 info = activeInputMethodController->textInputInfo(); |
| 1037 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1045 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1038 EXPECT_EQ(3, info.selectionStart); | 1046 EXPECT_EQ(3, info.selectionStart); |
| 1039 EXPECT_EQ(3, info.selectionEnd); | 1047 EXPECT_EQ(3, info.selectionEnd); |
| 1040 EXPECT_EQ(5, info.compositionStart); | 1048 EXPECT_EQ(5, info.compositionStart); |
| 1041 EXPECT_EQ(8, info.compositionEnd); | 1049 EXPECT_EQ(8, info.compositionEnd); |
| 1042 | 1050 |
| 1043 // Caret is between composing text and right boundary. | 1051 // Caret is between composing text and right boundary. |
| 1044 activeInputMethodController->setComposition( | 1052 activeInputMethodController->setComposition( |
| 1045 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 5, 5); | 1053 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1054 5, 5); |
| 1046 info = activeInputMethodController->textInputInfo(); | 1055 info = activeInputMethodController->textInputInfo(); |
| 1047 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1056 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1048 EXPECT_EQ(10, info.selectionStart); | 1057 EXPECT_EQ(10, info.selectionStart); |
| 1049 EXPECT_EQ(10, info.selectionEnd); | 1058 EXPECT_EQ(10, info.selectionEnd); |
| 1050 EXPECT_EQ(5, info.compositionStart); | 1059 EXPECT_EQ(5, info.compositionStart); |
| 1051 EXPECT_EQ(8, info.compositionEnd); | 1060 EXPECT_EQ(8, info.compositionEnd); |
| 1052 | 1061 |
| 1053 // Caret is on the left boundary. | 1062 // Caret is on the left boundary. |
| 1054 activeInputMethodController->setComposition( | 1063 activeInputMethodController->setComposition( |
| 1055 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -5, -5); | 1064 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1065 -5, -5); |
| 1056 info = activeInputMethodController->textInputInfo(); | 1066 info = activeInputMethodController->textInputInfo(); |
| 1057 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1067 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1058 EXPECT_EQ(0, info.selectionStart); | 1068 EXPECT_EQ(0, info.selectionStart); |
| 1059 EXPECT_EQ(0, info.selectionEnd); | 1069 EXPECT_EQ(0, info.selectionEnd); |
| 1060 EXPECT_EQ(5, info.compositionStart); | 1070 EXPECT_EQ(5, info.compositionStart); |
| 1061 EXPECT_EQ(8, info.compositionEnd); | 1071 EXPECT_EQ(8, info.compositionEnd); |
| 1062 | 1072 |
| 1063 // Caret is on the right boundary. | 1073 // Caret is on the right boundary. |
| 1064 activeInputMethodController->setComposition( | 1074 activeInputMethodController->setComposition( |
| 1065 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 8, 8); | 1075 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1076 8, 8); |
| 1066 info = activeInputMethodController->textInputInfo(); | 1077 info = activeInputMethodController->textInputInfo(); |
| 1067 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1078 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1068 EXPECT_EQ(13, info.selectionStart); | 1079 EXPECT_EQ(13, info.selectionStart); |
| 1069 EXPECT_EQ(13, info.selectionEnd); | 1080 EXPECT_EQ(13, info.selectionEnd); |
| 1070 EXPECT_EQ(5, info.compositionStart); | 1081 EXPECT_EQ(5, info.compositionStart); |
| 1071 EXPECT_EQ(8, info.compositionEnd); | 1082 EXPECT_EQ(8, info.compositionEnd); |
| 1072 | 1083 |
| 1073 // Caret exceeds the left boundary. | 1084 // Caret exceeds the left boundary. |
| 1074 activeInputMethodController->setComposition( | 1085 activeInputMethodController->setComposition( |
| 1075 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -100, | 1086 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1076 -100); | 1087 -100, -100); |
| 1077 info = activeInputMethodController->textInputInfo(); | 1088 info = activeInputMethodController->textInputInfo(); |
| 1078 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1089 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1079 EXPECT_EQ(0, info.selectionStart); | 1090 EXPECT_EQ(0, info.selectionStart); |
| 1080 EXPECT_EQ(0, info.selectionEnd); | 1091 EXPECT_EQ(0, info.selectionEnd); |
| 1081 EXPECT_EQ(5, info.compositionStart); | 1092 EXPECT_EQ(5, info.compositionStart); |
| 1082 EXPECT_EQ(8, info.compositionEnd); | 1093 EXPECT_EQ(8, info.compositionEnd); |
| 1083 | 1094 |
| 1084 // Caret exceeds the right boundary. | 1095 // Caret exceeds the right boundary. |
| 1085 activeInputMethodController->setComposition( | 1096 activeInputMethodController->setComposition( |
| 1086 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 100, 100); | 1097 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1098 100, 100); |
| 1087 info = activeInputMethodController->textInputInfo(); | 1099 info = activeInputMethodController->textInputInfo(); |
| 1088 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1100 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1089 EXPECT_EQ(13, info.selectionStart); | 1101 EXPECT_EQ(13, info.selectionStart); |
| 1090 EXPECT_EQ(13, info.selectionEnd); | 1102 EXPECT_EQ(13, info.selectionEnd); |
| 1091 EXPECT_EQ(5, info.compositionStart); | 1103 EXPECT_EQ(5, info.compositionStart); |
| 1092 EXPECT_EQ(8, info.compositionEnd); | 1104 EXPECT_EQ(8, info.compositionEnd); |
| 1093 } | 1105 } |
| 1094 | 1106 |
| 1095 TEST_P(WebViewTest, SetCompositionWithEmptyText) { | 1107 TEST_P(WebViewTest, SetCompositionWithEmptyText) { |
| 1096 registerMockedHttpURLLoad("input_field_populated.html"); | 1108 registerMockedHttpURLLoad("input_field_populated.html"); |
| 1097 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1109 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1098 m_baseURL + "input_field_populated.html"); | 1110 m_baseURL + "input_field_populated.html"); |
| 1099 webView->setInitialFocus(false); | 1111 webView->setInitialFocus(false); |
| 1100 WebInputMethodController* activeInputMethodController = | 1112 WebInputMethodController* activeInputMethodController = |
| 1101 webView->mainFrameImpl() | 1113 webView->mainFrameImpl() |
| 1102 ->frameWidget() | 1114 ->frameWidget() |
| 1103 ->getActiveWebInputMethodController(); | 1115 ->getActiveWebInputMethodController(); |
| 1104 | 1116 |
| 1105 WebVector<WebCompositionUnderline> emptyUnderlines; | 1117 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1106 | 1118 |
| 1107 activeInputMethodController->commitText("hello", emptyUnderlines, 0); | 1119 activeInputMethodController->commitText("hello", emptyUnderlines, WebRange(), |
| 1120 0); |
| 1108 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 1121 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1109 | 1122 |
| 1110 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1123 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1111 EXPECT_EQ(5, info.selectionStart); | 1124 EXPECT_EQ(5, info.selectionStart); |
| 1112 EXPECT_EQ(5, info.selectionEnd); | 1125 EXPECT_EQ(5, info.selectionEnd); |
| 1113 EXPECT_EQ(-1, info.compositionStart); | 1126 EXPECT_EQ(-1, info.compositionStart); |
| 1114 EXPECT_EQ(-1, info.compositionEnd); | 1127 EXPECT_EQ(-1, info.compositionEnd); |
| 1115 | 1128 |
| 1116 activeInputMethodController->setComposition(WebString::fromUTF8(""), | 1129 activeInputMethodController->setComposition( |
| 1117 emptyUnderlines, 0, 0); | 1130 WebString::fromUTF8(""), emptyUnderlines, WebRange(), 0, 0); |
| 1118 info = activeInputMethodController->textInputInfo(); | 1131 info = activeInputMethodController->textInputInfo(); |
| 1119 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1132 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1120 EXPECT_EQ(5, info.selectionStart); | 1133 EXPECT_EQ(5, info.selectionStart); |
| 1121 EXPECT_EQ(5, info.selectionEnd); | 1134 EXPECT_EQ(5, info.selectionEnd); |
| 1122 EXPECT_EQ(-1, info.compositionStart); | 1135 EXPECT_EQ(-1, info.compositionStart); |
| 1123 EXPECT_EQ(-1, info.compositionEnd); | 1136 EXPECT_EQ(-1, info.compositionEnd); |
| 1124 | 1137 |
| 1125 activeInputMethodController->setComposition(WebString::fromUTF8(""), | 1138 activeInputMethodController->setComposition( |
| 1126 emptyUnderlines, -2, -2); | 1139 WebString::fromUTF8(""), emptyUnderlines, WebRange(), -2, -2); |
| 1127 info = activeInputMethodController->textInputInfo(); | 1140 info = activeInputMethodController->textInputInfo(); |
| 1128 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1141 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1129 EXPECT_EQ(3, info.selectionStart); | 1142 EXPECT_EQ(3, info.selectionStart); |
| 1130 EXPECT_EQ(3, info.selectionEnd); | 1143 EXPECT_EQ(3, info.selectionEnd); |
| 1131 EXPECT_EQ(-1, info.compositionStart); | 1144 EXPECT_EQ(-1, info.compositionStart); |
| 1132 EXPECT_EQ(-1, info.compositionEnd); | 1145 EXPECT_EQ(-1, info.compositionEnd); |
| 1133 } | 1146 } |
| 1134 | 1147 |
| 1135 TEST_P(WebViewTest, CommitTextForNewCaretPositions) { | 1148 TEST_P(WebViewTest, CommitTextForNewCaretPositions) { |
| 1136 registerMockedHttpURLLoad("input_field_populated.html"); | 1149 registerMockedHttpURLLoad("input_field_populated.html"); |
| 1137 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1150 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1138 m_baseURL + "input_field_populated.html"); | 1151 m_baseURL + "input_field_populated.html"); |
| 1139 webView->setInitialFocus(false); | 1152 webView->setInitialFocus(false); |
| 1140 WebInputMethodController* activeInputMethodController = | 1153 WebInputMethodController* activeInputMethodController = |
| 1141 webView->mainFrameImpl() | 1154 webView->mainFrameImpl() |
| 1142 ->frameWidget() | 1155 ->frameWidget() |
| 1143 ->getActiveWebInputMethodController(); | 1156 ->getActiveWebInputMethodController(); |
| 1144 | 1157 |
| 1145 WebVector<WebCompositionUnderline> emptyUnderlines; | 1158 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1146 | 1159 |
| 1147 // Caret is on the left of composing text. | 1160 // Caret is on the left of composing text. |
| 1148 activeInputMethodController->commitText("ab", emptyUnderlines, -2); | 1161 activeInputMethodController->commitText("ab", emptyUnderlines, WebRange(), |
| 1162 -2); |
| 1149 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 1163 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1150 EXPECT_EQ("ab", std::string(info.value.utf8().data())); | 1164 EXPECT_EQ("ab", std::string(info.value.utf8().data())); |
| 1151 EXPECT_EQ(0, info.selectionStart); | 1165 EXPECT_EQ(0, info.selectionStart); |
| 1152 EXPECT_EQ(0, info.selectionEnd); | 1166 EXPECT_EQ(0, info.selectionEnd); |
| 1153 EXPECT_EQ(-1, info.compositionStart); | 1167 EXPECT_EQ(-1, info.compositionStart); |
| 1154 EXPECT_EQ(-1, info.compositionEnd); | 1168 EXPECT_EQ(-1, info.compositionEnd); |
| 1155 | 1169 |
| 1156 // Caret is on the right of composing text. | 1170 // Caret is on the right of composing text. |
| 1157 activeInputMethodController->commitText("c", emptyUnderlines, 1); | 1171 activeInputMethodController->commitText("c", emptyUnderlines, WebRange(), 1); |
| 1158 info = activeInputMethodController->textInputInfo(); | 1172 info = activeInputMethodController->textInputInfo(); |
| 1159 EXPECT_EQ("cab", std::string(info.value.utf8().data())); | 1173 EXPECT_EQ("cab", std::string(info.value.utf8().data())); |
| 1160 EXPECT_EQ(2, info.selectionStart); | 1174 EXPECT_EQ(2, info.selectionStart); |
| 1161 EXPECT_EQ(2, info.selectionEnd); | 1175 EXPECT_EQ(2, info.selectionEnd); |
| 1162 EXPECT_EQ(-1, info.compositionStart); | 1176 EXPECT_EQ(-1, info.compositionStart); |
| 1163 EXPECT_EQ(-1, info.compositionEnd); | 1177 EXPECT_EQ(-1, info.compositionEnd); |
| 1164 | 1178 |
| 1165 // Caret is on the left boundary. | 1179 // Caret is on the left boundary. |
| 1166 activeInputMethodController->commitText("def", emptyUnderlines, -5); | 1180 activeInputMethodController->commitText("def", emptyUnderlines, WebRange(), |
| 1181 -5); |
| 1167 info = activeInputMethodController->textInputInfo(); | 1182 info = activeInputMethodController->textInputInfo(); |
| 1168 EXPECT_EQ("cadefb", std::string(info.value.utf8().data())); | 1183 EXPECT_EQ("cadefb", std::string(info.value.utf8().data())); |
| 1169 EXPECT_EQ(0, info.selectionStart); | 1184 EXPECT_EQ(0, info.selectionStart); |
| 1170 EXPECT_EQ(0, info.selectionEnd); | 1185 EXPECT_EQ(0, info.selectionEnd); |
| 1171 EXPECT_EQ(-1, info.compositionStart); | 1186 EXPECT_EQ(-1, info.compositionStart); |
| 1172 EXPECT_EQ(-1, info.compositionEnd); | 1187 EXPECT_EQ(-1, info.compositionEnd); |
| 1173 | 1188 |
| 1174 // Caret is on the right boundary. | 1189 // Caret is on the right boundary. |
| 1175 activeInputMethodController->commitText("g", emptyUnderlines, 6); | 1190 activeInputMethodController->commitText("g", emptyUnderlines, WebRange(), 6); |
| 1176 info = activeInputMethodController->textInputInfo(); | 1191 info = activeInputMethodController->textInputInfo(); |
| 1177 EXPECT_EQ("gcadefb", std::string(info.value.utf8().data())); | 1192 EXPECT_EQ("gcadefb", std::string(info.value.utf8().data())); |
| 1178 EXPECT_EQ(7, info.selectionStart); | 1193 EXPECT_EQ(7, info.selectionStart); |
| 1179 EXPECT_EQ(7, info.selectionEnd); | 1194 EXPECT_EQ(7, info.selectionEnd); |
| 1180 EXPECT_EQ(-1, info.compositionStart); | 1195 EXPECT_EQ(-1, info.compositionStart); |
| 1181 EXPECT_EQ(-1, info.compositionEnd); | 1196 EXPECT_EQ(-1, info.compositionEnd); |
| 1182 | 1197 |
| 1183 // Caret exceeds the left boundary. | 1198 // Caret exceeds the left boundary. |
| 1184 activeInputMethodController->commitText("hi", emptyUnderlines, -100); | 1199 activeInputMethodController->commitText("hi", emptyUnderlines, WebRange(), |
| 1200 -100); |
| 1185 info = activeInputMethodController->textInputInfo(); | 1201 info = activeInputMethodController->textInputInfo(); |
| 1186 EXPECT_EQ("gcadefbhi", std::string(info.value.utf8().data())); | 1202 EXPECT_EQ("gcadefbhi", std::string(info.value.utf8().data())); |
| 1187 EXPECT_EQ(0, info.selectionStart); | 1203 EXPECT_EQ(0, info.selectionStart); |
| 1188 EXPECT_EQ(0, info.selectionEnd); | 1204 EXPECT_EQ(0, info.selectionEnd); |
| 1189 EXPECT_EQ(-1, info.compositionStart); | 1205 EXPECT_EQ(-1, info.compositionStart); |
| 1190 EXPECT_EQ(-1, info.compositionEnd); | 1206 EXPECT_EQ(-1, info.compositionEnd); |
| 1191 | 1207 |
| 1192 // Caret exceeds the right boundary. | 1208 // Caret exceeds the right boundary. |
| 1193 activeInputMethodController->commitText("jk", emptyUnderlines, 100); | 1209 activeInputMethodController->commitText("jk", emptyUnderlines, WebRange(), |
| 1210 100); |
| 1194 info = activeInputMethodController->textInputInfo(); | 1211 info = activeInputMethodController->textInputInfo(); |
| 1195 EXPECT_EQ("jkgcadefbhi", std::string(info.value.utf8().data())); | 1212 EXPECT_EQ("jkgcadefbhi", std::string(info.value.utf8().data())); |
| 1196 EXPECT_EQ(11, info.selectionStart); | 1213 EXPECT_EQ(11, info.selectionStart); |
| 1197 EXPECT_EQ(11, info.selectionEnd); | 1214 EXPECT_EQ(11, info.selectionEnd); |
| 1198 EXPECT_EQ(-1, info.compositionStart); | 1215 EXPECT_EQ(-1, info.compositionStart); |
| 1199 EXPECT_EQ(-1, info.compositionEnd); | 1216 EXPECT_EQ(-1, info.compositionEnd); |
| 1200 } | 1217 } |
| 1201 | 1218 |
| 1202 TEST_P(WebViewTest, CommitTextWhileComposing) { | 1219 TEST_P(WebViewTest, CommitTextWhileComposing) { |
| 1203 registerMockedHttpURLLoad("input_field_populated.html"); | 1220 registerMockedHttpURLLoad("input_field_populated.html"); |
| 1204 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1221 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1205 m_baseURL + "input_field_populated.html"); | 1222 m_baseURL + "input_field_populated.html"); |
| 1206 webView->setInitialFocus(false); | 1223 webView->setInitialFocus(false); |
| 1207 WebInputMethodController* activeInputMethodController = | 1224 WebInputMethodController* activeInputMethodController = |
| 1208 webView->mainFrameImpl() | 1225 webView->mainFrameImpl() |
| 1209 ->frameWidget() | 1226 ->frameWidget() |
| 1210 ->getActiveWebInputMethodController(); | 1227 ->getActiveWebInputMethodController(); |
| 1211 | 1228 |
| 1212 WebVector<WebCompositionUnderline> emptyUnderlines; | 1229 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1213 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), | 1230 activeInputMethodController->setComposition( |
| 1214 emptyUnderlines, 0, 0); | 1231 WebString::fromUTF8("abc"), emptyUnderlines, WebRange(), 0, 0); |
| 1215 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 1232 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1216 EXPECT_EQ("abc", std::string(info.value.utf8().data())); | 1233 EXPECT_EQ("abc", std::string(info.value.utf8().data())); |
| 1217 EXPECT_EQ(0, info.selectionStart); | 1234 EXPECT_EQ(0, info.selectionStart); |
| 1218 EXPECT_EQ(0, info.selectionEnd); | 1235 EXPECT_EQ(0, info.selectionEnd); |
| 1219 EXPECT_EQ(0, info.compositionStart); | 1236 EXPECT_EQ(0, info.compositionStart); |
| 1220 EXPECT_EQ(3, info.compositionEnd); | 1237 EXPECT_EQ(3, info.compositionEnd); |
| 1221 | 1238 |
| 1222 // Deletes ongoing composition, inserts the specified text and moves the | 1239 // Deletes ongoing composition, inserts the specified text and moves the |
| 1223 // caret. | 1240 // caret. |
| 1224 activeInputMethodController->commitText("hello", emptyUnderlines, -2); | 1241 activeInputMethodController->commitText("hello", emptyUnderlines, WebRange(), |
| 1242 -2); |
| 1225 info = activeInputMethodController->textInputInfo(); | 1243 info = activeInputMethodController->textInputInfo(); |
| 1226 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1244 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1227 EXPECT_EQ(3, info.selectionStart); | 1245 EXPECT_EQ(3, info.selectionStart); |
| 1228 EXPECT_EQ(3, info.selectionEnd); | 1246 EXPECT_EQ(3, info.selectionEnd); |
| 1229 EXPECT_EQ(-1, info.compositionStart); | 1247 EXPECT_EQ(-1, info.compositionStart); |
| 1230 EXPECT_EQ(-1, info.compositionEnd); | 1248 EXPECT_EQ(-1, info.compositionEnd); |
| 1231 | 1249 |
| 1232 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), | 1250 activeInputMethodController->setComposition( |
| 1233 emptyUnderlines, 0, 0); | 1251 WebString::fromUTF8("abc"), emptyUnderlines, WebRange(), 0, 0); |
| 1234 info = activeInputMethodController->textInputInfo(); | 1252 info = activeInputMethodController->textInputInfo(); |
| 1235 EXPECT_EQ("helabclo", std::string(info.value.utf8().data())); | 1253 EXPECT_EQ("helabclo", std::string(info.value.utf8().data())); |
| 1236 EXPECT_EQ(3, info.selectionStart); | 1254 EXPECT_EQ(3, info.selectionStart); |
| 1237 EXPECT_EQ(3, info.selectionEnd); | 1255 EXPECT_EQ(3, info.selectionEnd); |
| 1238 EXPECT_EQ(3, info.compositionStart); | 1256 EXPECT_EQ(3, info.compositionStart); |
| 1239 EXPECT_EQ(6, info.compositionEnd); | 1257 EXPECT_EQ(6, info.compositionEnd); |
| 1240 | 1258 |
| 1241 // Deletes ongoing composition and moves the caret. | 1259 // Deletes ongoing composition and moves the caret. |
| 1242 activeInputMethodController->commitText("", emptyUnderlines, 2); | 1260 activeInputMethodController->commitText("", emptyUnderlines, WebRange(), 2); |
| 1243 info = activeInputMethodController->textInputInfo(); | 1261 info = activeInputMethodController->textInputInfo(); |
| 1244 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1262 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1245 EXPECT_EQ(5, info.selectionStart); | 1263 EXPECT_EQ(5, info.selectionStart); |
| 1246 EXPECT_EQ(5, info.selectionEnd); | 1264 EXPECT_EQ(5, info.selectionEnd); |
| 1247 EXPECT_EQ(-1, info.compositionStart); | 1265 EXPECT_EQ(-1, info.compositionStart); |
| 1248 EXPECT_EQ(-1, info.compositionEnd); | 1266 EXPECT_EQ(-1, info.compositionEnd); |
| 1249 | 1267 |
| 1250 // Inserts the specified text and moves the caret. | 1268 // Inserts the specified text and moves the caret. |
| 1251 activeInputMethodController->commitText("world", emptyUnderlines, -5); | 1269 activeInputMethodController->commitText("world", emptyUnderlines, WebRange(), |
| 1270 -5); |
| 1252 info = activeInputMethodController->textInputInfo(); | 1271 info = activeInputMethodController->textInputInfo(); |
| 1253 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); | 1272 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); |
| 1254 EXPECT_EQ(5, info.selectionStart); | 1273 EXPECT_EQ(5, info.selectionStart); |
| 1255 EXPECT_EQ(5, info.selectionEnd); | 1274 EXPECT_EQ(5, info.selectionEnd); |
| 1256 EXPECT_EQ(-1, info.compositionStart); | 1275 EXPECT_EQ(-1, info.compositionStart); |
| 1257 EXPECT_EQ(-1, info.compositionEnd); | 1276 EXPECT_EQ(-1, info.compositionEnd); |
| 1258 | 1277 |
| 1259 // Only moves the caret. | 1278 // Only moves the caret. |
| 1260 activeInputMethodController->commitText("", emptyUnderlines, 5); | 1279 activeInputMethodController->commitText("", emptyUnderlines, WebRange(), 5); |
| 1261 info = activeInputMethodController->textInputInfo(); | 1280 info = activeInputMethodController->textInputInfo(); |
| 1262 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); | 1281 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); |
| 1263 EXPECT_EQ(10, info.selectionStart); | 1282 EXPECT_EQ(10, info.selectionStart); |
| 1264 EXPECT_EQ(10, info.selectionEnd); | 1283 EXPECT_EQ(10, info.selectionEnd); |
| 1265 EXPECT_EQ(-1, info.compositionStart); | 1284 EXPECT_EQ(-1, info.compositionStart); |
| 1266 EXPECT_EQ(-1, info.compositionEnd); | 1285 EXPECT_EQ(-1, info.compositionEnd); |
| 1267 } | 1286 } |
| 1268 | 1287 |
| 1269 TEST_P(WebViewTest, FinishCompositionDoesNotRevealSelection) { | 1288 TEST_P(WebViewTest, FinishCompositionDoesNotRevealSelection) { |
| 1270 registerMockedHttpURLLoad("form_with_input.html"); | 1289 registerMockedHttpURLLoad("form_with_input.html"); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 activeInputMethodController->finishComposingText( | 1344 activeInputMethodController->finishComposingText( |
| 1326 WebInputMethodController::KeepSelection); | 1345 WebInputMethodController::KeepSelection); |
| 1327 info = activeInputMethodController->textInputInfo(); | 1346 info = activeInputMethodController->textInputInfo(); |
| 1328 EXPECT_EQ(4, info.selectionStart); | 1347 EXPECT_EQ(4, info.selectionStart); |
| 1329 EXPECT_EQ(4, info.selectionEnd); | 1348 EXPECT_EQ(4, info.selectionEnd); |
| 1330 EXPECT_EQ(-1, info.compositionStart); | 1349 EXPECT_EQ(-1, info.compositionStart); |
| 1331 EXPECT_EQ(-1, info.compositionEnd); | 1350 EXPECT_EQ(-1, info.compositionEnd); |
| 1332 | 1351 |
| 1333 std::string compositionText("\n"); | 1352 std::string compositionText("\n"); |
| 1334 activeInputMethodController->commitText( | 1353 activeInputMethodController->commitText( |
| 1335 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0); | 1354 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1355 0); |
| 1336 info = activeInputMethodController->textInputInfo(); | 1356 info = activeInputMethodController->textInputInfo(); |
| 1337 EXPECT_EQ(5, info.selectionStart); | 1357 EXPECT_EQ(5, info.selectionStart); |
| 1338 EXPECT_EQ(5, info.selectionEnd); | 1358 EXPECT_EQ(5, info.selectionEnd); |
| 1339 EXPECT_EQ(-1, info.compositionStart); | 1359 EXPECT_EQ(-1, info.compositionStart); |
| 1340 EXPECT_EQ(-1, info.compositionEnd); | 1360 EXPECT_EQ(-1, info.compositionEnd); |
| 1341 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", | 1361 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", |
| 1342 std::string(info.value.utf8().data())); | 1362 std::string(info.value.utf8().data())); |
| 1343 } | 1363 } |
| 1344 | 1364 |
| 1345 TEST_P(WebViewTest, ExtendSelectionAndDelete) { | 1365 TEST_P(WebViewTest, ExtendSelectionAndDelete) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 webView->setInitialFocus(false); | 1457 webView->setInitialFocus(false); |
| 1438 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 1458 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
| 1439 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 1459 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
| 1440 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1460 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 1441 WebInputMethodController* activeInputMethodController = | 1461 WebInputMethodController* activeInputMethodController = |
| 1442 frame->frameWidget()->getActiveWebInputMethodController(); | 1462 frame->frameWidget()->getActiveWebInputMethodController(); |
| 1443 frame->setEditableSelectionOffsets(27, 27); | 1463 frame->setEditableSelectionOffsets(27, 27); |
| 1444 std::string newLineText("\n"); | 1464 std::string newLineText("\n"); |
| 1445 WebVector<WebCompositionUnderline> emptyUnderlines; | 1465 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1446 activeInputMethodController->commitText( | 1466 activeInputMethodController->commitText( |
| 1447 WebString::fromUTF8(newLineText.c_str()), emptyUnderlines, 0); | 1467 WebString::fromUTF8(newLineText.c_str()), emptyUnderlines, WebRange(), 0); |
| 1448 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 1468 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1449 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", | 1469 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", |
| 1450 std::string(info.value.utf8().data())); | 1470 std::string(info.value.utf8().data())); |
| 1451 | 1471 |
| 1452 frame->setEditableSelectionOffsets(31, 31); | 1472 frame->setEditableSelectionOffsets(31, 31); |
| 1453 frame->setCompositionFromExistingText(30, 34, underlines); | 1473 frame->setCompositionFromExistingText(30, 34, underlines); |
| 1454 info = activeInputMethodController->textInputInfo(); | 1474 info = activeInputMethodController->textInputInfo(); |
| 1455 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", | 1475 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", |
| 1456 std::string(info.value.utf8().data())); | 1476 std::string(info.value.utf8().data())); |
| 1457 EXPECT_EQ(31, info.selectionStart); | 1477 EXPECT_EQ(31, info.selectionStart); |
| 1458 EXPECT_EQ(31, info.selectionEnd); | 1478 EXPECT_EQ(31, info.selectionEnd); |
| 1459 EXPECT_EQ(30, info.compositionStart); | 1479 EXPECT_EQ(30, info.compositionStart); |
| 1460 EXPECT_EQ(34, info.compositionEnd); | 1480 EXPECT_EQ(34, info.compositionEnd); |
| 1461 | 1481 |
| 1462 std::string compositionText("yolo"); | 1482 std::string compositionText("yolo"); |
| 1463 activeInputMethodController->commitText( | 1483 activeInputMethodController->commitText( |
| 1464 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0); | 1484 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 1485 0); |
| 1465 info = activeInputMethodController->textInputInfo(); | 1486 info = activeInputMethodController->textInputInfo(); |
| 1466 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", | 1487 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", |
| 1467 std::string(info.value.utf8().data())); | 1488 std::string(info.value.utf8().data())); |
| 1468 EXPECT_EQ(34, info.selectionStart); | 1489 EXPECT_EQ(34, info.selectionStart); |
| 1469 EXPECT_EQ(34, info.selectionEnd); | 1490 EXPECT_EQ(34, info.selectionEnd); |
| 1470 EXPECT_EQ(-1, info.compositionStart); | 1491 EXPECT_EQ(-1, info.compositionStart); |
| 1471 EXPECT_EQ(-1, info.compositionEnd); | 1492 EXPECT_EQ(-1, info.compositionEnd); |
| 1472 } | 1493 } |
| 1473 | 1494 |
| 1474 TEST_P(WebViewTest, SetCompositionFromExistingTextInRichText) { | 1495 TEST_P(WebViewTest, SetCompositionFromExistingTextInRichText) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1493 webView->setInitialFocus(false); | 1514 webView->setInitialFocus(false); |
| 1494 | 1515 |
| 1495 std::string compositionTextFirst("hello "); | 1516 std::string compositionTextFirst("hello "); |
| 1496 std::string compositionTextSecond("world"); | 1517 std::string compositionTextSecond("world"); |
| 1497 WebVector<WebCompositionUnderline> emptyUnderlines; | 1518 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1498 WebInputMethodController* activeInputMethodController = | 1519 WebInputMethodController* activeInputMethodController = |
| 1499 webView->mainFrameImpl() | 1520 webView->mainFrameImpl() |
| 1500 ->frameWidget() | 1521 ->frameWidget() |
| 1501 ->getActiveWebInputMethodController(); | 1522 ->getActiveWebInputMethodController(); |
| 1502 activeInputMethodController->commitText( | 1523 activeInputMethodController->commitText( |
| 1503 WebString::fromUTF8(compositionTextFirst.c_str()), emptyUnderlines, 0); | 1524 WebString::fromUTF8(compositionTextFirst.c_str()), emptyUnderlines, |
| 1525 WebRange(), 0); |
| 1504 activeInputMethodController->setComposition( | 1526 activeInputMethodController->setComposition( |
| 1505 WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, | 1527 WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, |
| 1506 5); | 1528 WebRange(), 5, 5); |
| 1507 | 1529 |
| 1508 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 1530 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1509 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1531 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
| 1510 EXPECT_EQ(11, info.selectionStart); | 1532 EXPECT_EQ(11, info.selectionStart); |
| 1511 EXPECT_EQ(11, info.selectionEnd); | 1533 EXPECT_EQ(11, info.selectionEnd); |
| 1512 EXPECT_EQ(6, info.compositionStart); | 1534 EXPECT_EQ(6, info.compositionStart); |
| 1513 EXPECT_EQ(11, info.compositionEnd); | 1535 EXPECT_EQ(11, info.compositionEnd); |
| 1514 | 1536 |
| 1515 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1537 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 1516 frame->setEditableSelectionOffsets(6, 6); | 1538 frame->setEditableSelectionOffsets(6, 6); |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2355 runPendingTasks(); | 2377 runPendingTasks(); |
| 2356 | 2378 |
| 2357 WebString target = WebString::fromUTF8("target"); | 2379 WebString target = WebString::fromUTF8("target"); |
| 2358 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2380 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2359 WebInputMethodController* activeInputMethodController = | 2381 WebInputMethodController* activeInputMethodController = |
| 2360 frame->frameWidget()->getActiveWebInputMethodController(); | 2382 frame->frameWidget()->getActiveWebInputMethodController(); |
| 2361 EXPECT_TRUE(tapElementById(WebInputEvent::GestureTap, target)); | 2383 EXPECT_TRUE(tapElementById(WebInputEvent::GestureTap, target)); |
| 2362 WebVector<WebCompositionUnderline> emptyUnderlines; | 2384 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2363 frame->setEditableSelectionOffsets(8, 8); | 2385 frame->setEditableSelectionOffsets(8, 8); |
| 2364 EXPECT_TRUE(activeInputMethodController->setComposition( | 2386 EXPECT_TRUE(activeInputMethodController->setComposition( |
| 2365 "12345", emptyUnderlines, 8, 13)); | 2387 "12345", emptyUnderlines, WebRange(), 8, 13)); |
| 2366 EXPECT_TRUE(frame->frame()->inputMethodController().hasComposition()); | 2388 EXPECT_TRUE(frame->frame()->inputMethodController().hasComposition()); |
| 2367 EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data())); | 2389 EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data())); |
| 2368 EXPECT_FALSE(frame->frame()->selection().isHandleVisible()); | 2390 EXPECT_FALSE(frame->frame()->selection().isHandleVisible()); |
| 2369 EXPECT_TRUE(frame->frame()->inputMethodController().hasComposition()); | 2391 EXPECT_TRUE(frame->frame()->inputMethodController().hasComposition()); |
| 2370 | 2392 |
| 2371 EXPECT_TRUE(tapElementById(WebInputEvent::GestureLongPress, target)); | 2393 EXPECT_TRUE(tapElementById(WebInputEvent::GestureLongPress, target)); |
| 2372 EXPECT_EQ("testword12345", | 2394 EXPECT_EQ("testword12345", |
| 2373 std::string(frame->selectionAsText().utf8().data())); | 2395 std::string(frame->selectionAsText().utf8().data())); |
| 2374 EXPECT_TRUE(frame->frame()->selection().isHandleVisible()); | 2396 EXPECT_TRUE(frame->frame()->selection().isHandleVisible()); |
| 2375 EXPECT_TRUE(frame->frame()->inputMethodController().hasComposition()); | 2397 EXPECT_TRUE(frame->frame()->inputMethodController().hasComposition()); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2726 webView->setInitialFocus(false); | 2748 webView->setInitialFocus(false); |
| 2727 | 2749 |
| 2728 // Test both input elements. | 2750 // Test both input elements. |
| 2729 for (int i = 0; i < 2; ++i) { | 2751 for (int i = 0; i < 2; ++i) { |
| 2730 // Select composition and do sanity check. | 2752 // Select composition and do sanity check. |
| 2731 WebVector<WebCompositionUnderline> emptyUnderlines; | 2753 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2732 frame->setEditableSelectionOffsets(6, 6); | 2754 frame->setEditableSelectionOffsets(6, 6); |
| 2733 WebInputMethodController* activeInputMethodController = | 2755 WebInputMethodController* activeInputMethodController = |
| 2734 frame->frameWidget()->getActiveWebInputMethodController(); | 2756 frame->frameWidget()->getActiveWebInputMethodController(); |
| 2735 EXPECT_TRUE(activeInputMethodController->setComposition( | 2757 EXPECT_TRUE(activeInputMethodController->setComposition( |
| 2736 "fghij", emptyUnderlines, 0, 5)); | 2758 "fghij", emptyUnderlines, WebRange(), 0, 5)); |
| 2737 frame->setEditableSelectionOffsets(11, 11); | 2759 frame->setEditableSelectionOffsets(11, 11); |
| 2738 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case"); | 2760 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case"); |
| 2739 | 2761 |
| 2740 // Press Backspace and verify composition didn't get cancelled. This is to | 2762 // Press Backspace and verify composition didn't get cancelled. This is to |
| 2741 // verify the fix for crbug.com/429916. | 2763 // verify the fix for crbug.com/429916. |
| 2742 WebKeyboardEvent keyEvent(WebInputEvent::RawKeyDown, | 2764 WebKeyboardEvent keyEvent(WebInputEvent::RawKeyDown, |
| 2743 WebInputEvent::NoModifiers, | 2765 WebInputEvent::NoModifiers, |
| 2744 WebInputEvent::TimeStampForTesting); | 2766 WebInputEvent::TimeStampForTesting); |
| 2745 keyEvent.domKey = Platform::current()->domKeyEnumFromString("\b"); | 2767 keyEvent.domKey = Platform::current()->domKeyEnumFromString("\b"); |
| 2746 keyEvent.windowsKeyCode = VKEY_BACK; | 2768 keyEvent.windowsKeyCode = VKEY_BACK; |
| 2747 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); | 2769 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); |
| 2748 | 2770 |
| 2749 frame->setEditableSelectionOffsets(6, 6); | 2771 frame->setEditableSelectionOffsets(6, 6); |
| 2750 EXPECT_TRUE(activeInputMethodController->setComposition( | 2772 EXPECT_TRUE(activeInputMethodController->setComposition( |
| 2751 "fghi", emptyUnderlines, 0, 4)); | 2773 "fghi", emptyUnderlines, WebRange(), 0, 4)); |
| 2752 frame->setEditableSelectionOffsets(10, 10); | 2774 frame->setEditableSelectionOffsets(10, 10); |
| 2753 verifySelectionAndComposition(webView, 10, 10, 6, 10, | 2775 verifySelectionAndComposition(webView, 10, 10, 6, 10, |
| 2754 "after pressing Backspace"); | 2776 "after pressing Backspace"); |
| 2755 | 2777 |
| 2756 keyEvent.setType(WebInputEvent::KeyUp); | 2778 keyEvent.setType(WebInputEvent::KeyUp); |
| 2757 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); | 2779 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); |
| 2758 | 2780 |
| 2759 webView->advanceFocus(false); | 2781 webView->advanceFocus(false); |
| 2760 } | 2782 } |
| 2761 | 2783 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2775 HTMLFormControlElement* form = | 2797 HTMLFormControlElement* form = |
| 2776 toHTMLFormControlElement(document.getElementById("sample")); | 2798 toHTMLFormControlElement(document.getElementById("sample")); |
| 2777 | 2799 |
| 2778 WebInputMethodController* activeInputMethodController = | 2800 WebInputMethodController* activeInputMethodController = |
| 2779 frame->frameWidget()->getActiveWebInputMethodController(); | 2801 frame->frameWidget()->getActiveWebInputMethodController(); |
| 2780 // Set up a composition that needs to be committed. | 2802 // Set up a composition that needs to be committed. |
| 2781 std::string compositionText("testingtext"); | 2803 std::string compositionText("testingtext"); |
| 2782 | 2804 |
| 2783 WebVector<WebCompositionUnderline> emptyUnderlines; | 2805 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2784 activeInputMethodController->setComposition( | 2806 activeInputMethodController->setComposition( |
| 2785 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, | 2807 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, WebRange(), |
| 2786 compositionText.length()); | 2808 0, compositionText.length()); |
| 2787 | 2809 |
| 2788 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 2810 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 2789 EXPECT_EQ(0, info.selectionStart); | 2811 EXPECT_EQ(0, info.selectionStart); |
| 2790 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); | 2812 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); |
| 2791 EXPECT_EQ(0, info.compositionStart); | 2813 EXPECT_EQ(0, info.compositionStart); |
| 2792 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); | 2814 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); |
| 2793 | 2815 |
| 2794 form->setAutofilled(true); | 2816 form->setAutofilled(true); |
| 2795 client.clearChangeCounts(); | 2817 client.clearChangeCounts(); |
| 2796 | 2818 |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3556 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 3578 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 3557 m_baseURL + "input_field_populated.html"); | 3579 m_baseURL + "input_field_populated.html"); |
| 3558 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 3580 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 3559 MockAutofillClient client; | 3581 MockAutofillClient client; |
| 3560 frame->setAutofillClient(&client); | 3582 frame->setAutofillClient(&client); |
| 3561 webView->setInitialFocus(false); | 3583 webView->setInitialFocus(false); |
| 3562 | 3584 |
| 3563 EXPECT_TRUE( | 3585 EXPECT_TRUE( |
| 3564 frame->frameWidget()->getActiveWebInputMethodController()->setComposition( | 3586 frame->frameWidget()->getActiveWebInputMethodController()->setComposition( |
| 3565 WebString::fromUTF8(std::string("hello").c_str()), | 3587 WebString::fromUTF8(std::string("hello").c_str()), |
| 3566 WebVector<WebCompositionUnderline>(), 3, 3)); | 3588 WebVector<WebCompositionUnderline>(), WebRange(), 3, 3)); |
| 3567 EXPECT_EQ(1, client.textChangesFromUserGesture()); | 3589 EXPECT_EQ(1, client.textChangesFromUserGesture()); |
| 3568 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | 3590 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); |
| 3569 EXPECT_TRUE(frame->hasMarkedText()); | 3591 EXPECT_TRUE(frame->hasMarkedText()); |
| 3570 | 3592 |
| 3571 frame->setAutofillClient(0); | 3593 frame->setAutofillClient(0); |
| 3572 } | 3594 } |
| 3573 | 3595 |
| 3574 TEST_P(WebViewTest, CompareSelectAllToContentAsText) { | 3596 TEST_P(WebViewTest, CompareSelectAllToContentAsText) { |
| 3575 registerMockedHttpURLLoad("longpress_selection.html"); | 3597 registerMockedHttpURLLoad("longpress_selection.html"); |
| 3576 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 3598 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3968 m_baseURL + "input_field_password.html", true); | 3990 m_baseURL + "input_field_password.html", true); |
| 3969 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 3991 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 3970 frame->setAutofillClient(&client); | 3992 frame->setAutofillClient(&client); |
| 3971 webView->setInitialFocus(false); | 3993 webView->setInitialFocus(false); |
| 3972 | 3994 |
| 3973 WebVector<WebCompositionUnderline> emptyUnderlines; | 3995 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 3974 | 3996 |
| 3975 EXPECT_TRUE( | 3997 EXPECT_TRUE( |
| 3976 frame->frameWidget()->getActiveWebInputMethodController()->commitText( | 3998 frame->frameWidget()->getActiveWebInputMethodController()->commitText( |
| 3977 WebString::fromUTF8(std::string("hello").c_str()), emptyUnderlines, | 3999 WebString::fromUTF8(std::string("hello").c_str()), emptyUnderlines, |
| 3978 0)); | 4000 WebRange(), 0)); |
| 3979 EXPECT_EQ(1, client.textChangesFromUserGesture()); | 4001 EXPECT_EQ(1, client.textChangesFromUserGesture()); |
| 3980 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | 4002 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); |
| 3981 frame->setAutofillClient(0); | 4003 frame->setAutofillClient(0); |
| 3982 } | 4004 } |
| 3983 | 4005 |
| 3984 // Verify that a WebView created with a ScopedPageSuspender already on the | 4006 // Verify that a WebView created with a ScopedPageSuspender already on the |
| 3985 // stack defers its loads. | 4007 // stack defers its loads. |
| 3986 TEST_P(WebViewTest, CreatedDuringPageSuspension) { | 4008 TEST_P(WebViewTest, CreatedDuringPageSuspension) { |
| 3987 { | 4009 { |
| 3988 WebViewImpl* webView = m_webViewHelper.initialize(); | 4010 WebViewImpl* webView = m_webViewHelper.initialize(); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4263 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); | 4285 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); |
| 4264 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); | 4286 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); |
| 4265 | 4287 |
| 4266 webView->resize(WebSize(800, 600)); | 4288 webView->resize(WebSize(800, 600)); |
| 4267 frame->printEnd(); | 4289 frame->printEnd(); |
| 4268 | 4290 |
| 4269 EXPECT_EQ(800, vwElement->offsetWidth()); | 4291 EXPECT_EQ(800, vwElement->offsetWidth()); |
| 4270 } | 4292 } |
| 4271 | 4293 |
| 4272 } // namespace blink | 4294 } // namespace blink |
| OLD | NEW |