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

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

Issue 1999423002: tyrbot test for commitText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SetHasCompositionTextToTrue Created 4 years, 3 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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 frame->setEditableSelectionOffsets(8, 19); 813 frame->setEditableSelectionOffsets(8, 19);
814 EXPECT_EQ("89abcdefghi", frame->selectionAsText()); 814 EXPECT_EQ("89abcdefghi", frame->selectionAsText());
815 info = webView->textInputInfo(); 815 info = webView->textInputInfo();
816 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); 816 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value);
817 EXPECT_EQ(8, info.selectionStart); 817 EXPECT_EQ(8, info.selectionStart);
818 EXPECT_EQ(19, info.selectionEnd); 818 EXPECT_EQ(19, info.selectionEnd);
819 EXPECT_EQ(-1, info.compositionStart); 819 EXPECT_EQ(-1, info.compositionStart);
820 EXPECT_EQ(-1, info.compositionEnd); 820 EXPECT_EQ(-1, info.compositionEnd);
821 } 821 }
822 822
823 TEST_F(WebViewTest, ConfirmCompositionCursorPositionChange) 823 TEST_F(WebViewTest, FinishComposingTextCursorPositionChange)
824 { 824 {
825 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 825 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
826 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 826 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
827 webView->setInitialFocus(false); 827 webView->setInitialFocus(false);
828 828
829 // Set up a composition that needs to be committed. 829 // Set up a composition that needs to be committed.
830 std::string compositionText("hello"); 830 std::string compositionText("hello");
831 831
832 WebVector<WebCompositionUnderline> emptyUnderlines; 832 WebVector<WebCompositionUnderline> emptyUnderlines;
833 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 3, 3); 833 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 3, 3);
834 834
835 WebTextInputInfo info = webView->textInputInfo(); 835 WebTextInputInfo info = webView->textInputInfo();
836 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 836 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
837 EXPECT_EQ(3, info.selectionStart); 837 EXPECT_EQ(3, info.selectionStart);
838 EXPECT_EQ(3, info.selectionEnd); 838 EXPECT_EQ(3, info.selectionEnd);
839 EXPECT_EQ(0, info.compositionStart); 839 EXPECT_EQ(0, info.compositionStart);
840 EXPECT_EQ(5, info.compositionEnd); 840 EXPECT_EQ(5, info.compositionEnd);
841 841
842 webView->confirmComposition(WebWidget::KeepSelection); 842 webView->finishComposingText(WebWidget::KeepSelection);
843 info = webView->textInputInfo(); 843 info = webView->textInputInfo();
844 EXPECT_EQ(3, info.selectionStart); 844 EXPECT_EQ(3, info.selectionStart);
845 EXPECT_EQ(3, info.selectionEnd); 845 EXPECT_EQ(3, info.selectionEnd);
846 EXPECT_EQ(-1, info.compositionStart); 846 EXPECT_EQ(-1, info.compositionStart);
847 EXPECT_EQ(-1, info.compositionEnd); 847 EXPECT_EQ(-1, info.compositionEnd);
848 848
849 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 3, 3); 849 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 3, 3);
850 info = webView->textInputInfo(); 850 info = webView->textInputInfo();
851 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data())); 851 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data()));
852 EXPECT_EQ(6, info.selectionStart); 852 EXPECT_EQ(6, info.selectionStart);
853 EXPECT_EQ(6, info.selectionEnd); 853 EXPECT_EQ(6, info.selectionEnd);
854 EXPECT_EQ(3, info.compositionStart); 854 EXPECT_EQ(3, info.compositionStart);
855 EXPECT_EQ(8, info.compositionEnd); 855 EXPECT_EQ(8, info.compositionEnd);
856 856
857 webView->confirmComposition(WebWidget::DoNotKeepSelection); 857 webView->finishComposingText(WebWidget::DoNotKeepSelection);
858 info = webView->textInputInfo(); 858 info = webView->textInputInfo();
859 EXPECT_EQ(8, info.selectionStart); 859 EXPECT_EQ(8, info.selectionStart);
860 EXPECT_EQ(8, info.selectionEnd); 860 EXPECT_EQ(8, info.selectionEnd);
861 EXPECT_EQ(-1, info.compositionStart); 861 EXPECT_EQ(-1, info.compositionStart);
862 EXPECT_EQ(-1, info.compositionEnd); 862 EXPECT_EQ(-1, info.compositionEnd);
863 } 863 }
864 864
865 TEST_F(WebViewTest, SetCompositionForNewCaretPositions)
866 {
867 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
868 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
869 webView->setInitialFocus(false);
870
871 webView->commitText("hello", 0);
872 webView->commitText("world", -5);
873 WebTextInputInfo info = webView->textInputInfo();
874 EXPECT_EQ("helloworld", std::string(info.value.utf8().data()));
875 EXPECT_EQ(5, info.selectionStart);
876 EXPECT_EQ(5, info.selectionEnd);
877 EXPECT_EQ(-1, info.compositionStart);
878 EXPECT_EQ(-1, info.compositionEnd);
879
880 WebVector<WebCompositionUnderline> emptyUnderlines;
881 // Set up a composition that needs to be committed.
882 std::string compositionText("ABC");
883
884 // Caret is on the left of composing text.
885 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 0, 0);
886 info = webView->textInputInfo();
887 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
888 EXPECT_EQ(5, info.selectionStart);
889 EXPECT_EQ(5, info.selectionEnd);
890 EXPECT_EQ(5, info.compositionStart);
891 EXPECT_EQ(8, info.compositionEnd);
892
893 // Caret is on the right of composing text.
894 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 3, 3);
895 info = webView->textInputInfo();
896 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
897 EXPECT_EQ(8, info.selectionStart);
898 EXPECT_EQ(8, info.selectionEnd);
899 EXPECT_EQ(5, info.compositionStart);
900 EXPECT_EQ(8, info.compositionEnd);
901
902 // Caret is between composing text and left boundary.
903 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, -2, -2);
904 info = webView->textInputInfo();
905 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
906 EXPECT_EQ(3, info.selectionStart);
907 EXPECT_EQ(3, info.selectionEnd);
908 EXPECT_EQ(5, info.compositionStart);
909 EXPECT_EQ(8, info.compositionEnd);
910
911 // Caret is between composing text and right boundary.
912 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 5, 5);
913 info = webView->textInputInfo();
914 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
915 EXPECT_EQ(10, info.selectionStart);
916 EXPECT_EQ(10, info.selectionEnd);
917 EXPECT_EQ(5, info.compositionStart);
918 EXPECT_EQ(8, info.compositionEnd);
919
920 // Caret is on the left boundary.
921 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, -5, -5);
922 info = webView->textInputInfo();
923 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
924 EXPECT_EQ(0, info.selectionStart);
925 EXPECT_EQ(0, info.selectionEnd);
926 EXPECT_EQ(5, info.compositionStart);
927 EXPECT_EQ(8, info.compositionEnd);
928
929 // Caret is on the right boundary.
930 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 8, 8);
931 info = webView->textInputInfo();
932 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
933 EXPECT_EQ(13, info.selectionStart);
934 EXPECT_EQ(13, info.selectionEnd);
935 EXPECT_EQ(5, info.compositionStart);
936 EXPECT_EQ(8, info.compositionEnd);
937
938 // Caret exceeds the left boundary.
939 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, -100, -100);
940 info = webView->textInputInfo();
941 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
942 EXPECT_EQ(0, info.selectionStart);
943 EXPECT_EQ(0, info.selectionEnd);
944 EXPECT_EQ(5, info.compositionStart);
945 EXPECT_EQ(8, info.compositionEnd);
946
947 // Caret exceeds the right boundary.
948 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 100, 100);
949 info = webView->textInputInfo();
950 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data()));
951 EXPECT_EQ(13, info.selectionStart);
952 EXPECT_EQ(13, info.selectionEnd);
953 EXPECT_EQ(5, info.compositionStart);
954 EXPECT_EQ(8, info.compositionEnd);
955 }
956
957 TEST_F(WebViewTest, SetCompositionWithEmptyText)
958 {
959 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
960 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
961 webView->setInitialFocus(false);
962
963 webView->commitText("hello", 0);
964 WebTextInputInfo info = webView->textInputInfo();
965 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
966 EXPECT_EQ(5, info.selectionStart);
967 EXPECT_EQ(5, info.selectionEnd);
968 EXPECT_EQ(-1, info.compositionStart);
969 EXPECT_EQ(-1, info.compositionEnd);
970
971 WebVector<WebCompositionUnderline> emptyUnderlines;
972
973 webView->setComposition(WebString::fromUTF8(""), emptyUnderlines, 0, 0);
974 info = webView->textInputInfo();
975 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
976 EXPECT_EQ(5, info.selectionStart);
977 EXPECT_EQ(5, info.selectionEnd);
978 EXPECT_EQ(-1, info.compositionStart);
979 EXPECT_EQ(-1, info.compositionEnd);
980
981 webView->setComposition(WebString::fromUTF8(""), emptyUnderlines, -2, -2);
982 info = webView->textInputInfo();
983 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
984 EXPECT_EQ(3, info.selectionStart);
985 EXPECT_EQ(3, info.selectionEnd);
986 EXPECT_EQ(-1, info.compositionStart);
987 EXPECT_EQ(-1, info.compositionEnd);
988 }
989
990 TEST_F(WebViewTest, CommitTextForNewCaretPositions)
991 {
992 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
993 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
994 webView->setInitialFocus(false);
995
996 // Caret is on the left of composing text.
997 webView->commitText("ab", -2);
998 WebTextInputInfo info = webView->textInputInfo();
999 EXPECT_EQ("ab", std::string(info.value.utf8().data()));
1000 EXPECT_EQ(0, info.selectionStart);
1001 EXPECT_EQ(0, info.selectionEnd);
1002 EXPECT_EQ(-1, info.compositionStart);
1003 EXPECT_EQ(-1, info.compositionEnd);
1004
1005 // Caret is on the right of composing text.
1006 webView->commitText("c", 1);
1007 info = webView->textInputInfo();
1008 EXPECT_EQ("cab", std::string(info.value.utf8().data()));
1009 EXPECT_EQ(2, info.selectionStart);
1010 EXPECT_EQ(2, info.selectionEnd);
1011 EXPECT_EQ(-1, info.compositionStart);
1012 EXPECT_EQ(-1, info.compositionEnd);
1013
1014 // Caret is on the left boundary.
1015 webView->commitText("def", -5);
1016 info = webView->textInputInfo();
1017 EXPECT_EQ("cadefb", std::string(info.value.utf8().data()));
1018 EXPECT_EQ(0, info.selectionStart);
1019 EXPECT_EQ(0, info.selectionEnd);
1020 EXPECT_EQ(-1, info.compositionStart);
1021 EXPECT_EQ(-1, info.compositionEnd);
1022
1023 // Caret is on the right boundary.
1024 webView->commitText("g", 6);
1025 info = webView->textInputInfo();
1026 EXPECT_EQ("gcadefb", std::string(info.value.utf8().data()));
1027 EXPECT_EQ(7, info.selectionStart);
1028 EXPECT_EQ(7, info.selectionEnd);
1029 EXPECT_EQ(-1, info.compositionStart);
1030 EXPECT_EQ(-1, info.compositionEnd);
1031
1032 // Caret exceeds the left boundary.
1033 webView->commitText("hi", -100);
1034 info = webView->textInputInfo();
1035 EXPECT_EQ("gcadefbhi", std::string(info.value.utf8().data()));
1036 EXPECT_EQ(0, info.selectionStart);
1037 EXPECT_EQ(0, info.selectionEnd);
1038 EXPECT_EQ(-1, info.compositionStart);
1039 EXPECT_EQ(-1, info.compositionEnd);
1040
1041 // Caret exceeds the right boundary.
1042 webView->commitText("jk", 100);
1043 info = webView->textInputInfo();
1044 EXPECT_EQ("jkgcadefbhi", std::string(info.value.utf8().data()));
1045 EXPECT_EQ(11, info.selectionStart);
1046 EXPECT_EQ(11, info.selectionEnd);
1047 EXPECT_EQ(-1, info.compositionStart);
1048 EXPECT_EQ(-1, info.compositionEnd);
1049 }
1050
1051 TEST_F(WebViewTest, CommitTextWhileComposing)
1052 {
1053 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1054 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
1055 webView->setInitialFocus(false);
1056
1057 WebVector<WebCompositionUnderline> emptyUnderlines;
1058 webView->setComposition(WebString::fromUTF8("abc"), emptyUnderlines, 0, 0);
1059 WebTextInputInfo info = webView->textInputInfo();
1060 EXPECT_EQ("abc", std::string(info.value.utf8().data()));
1061 EXPECT_EQ(0, info.selectionStart);
1062 EXPECT_EQ(0, info.selectionEnd);
1063 EXPECT_EQ(0, info.compositionStart);
1064 EXPECT_EQ(3, info.compositionEnd);
1065
1066 // Deletes ongoing composition, inserts the specified text and moves the
1067 // caret.
1068 webView->commitText("hello", -2);
1069 info = webView->textInputInfo();
1070 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
1071 EXPECT_EQ(3, info.selectionStart);
1072 EXPECT_EQ(3, info.selectionEnd);
1073 EXPECT_EQ(-1, info.compositionStart);
1074 EXPECT_EQ(-1, info.compositionEnd);
1075
1076 webView->setComposition(WebString::fromUTF8("abc"), emptyUnderlines, 0, 0);
1077 info = webView->textInputInfo();
1078 EXPECT_EQ("helabclo", std::string(info.value.utf8().data()));
1079 EXPECT_EQ(3, info.selectionStart);
1080 EXPECT_EQ(3, info.selectionEnd);
1081 EXPECT_EQ(3, info.compositionStart);
1082 EXPECT_EQ(6, info.compositionEnd);
1083
1084 // Deletes ongoing composition and moves the caret.
1085 webView->commitText("", 2);
1086 info = webView->textInputInfo();
1087 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
1088 EXPECT_EQ(5, info.selectionStart);
1089 EXPECT_EQ(5, info.selectionEnd);
1090 EXPECT_EQ(-1, info.compositionStart);
1091 EXPECT_EQ(-1, info.compositionEnd);
1092
1093 // Inserts the specified text and moves the caret.
1094 webView->commitText("world", -5);
1095 info = webView->textInputInfo();
1096 EXPECT_EQ("helloworld", std::string(info.value.utf8().data()));
1097 EXPECT_EQ(5, info.selectionStart);
1098 EXPECT_EQ(5, info.selectionEnd);
1099 EXPECT_EQ(-1, info.compositionStart);
1100 EXPECT_EQ(-1, info.compositionEnd);
1101
1102 // Only moves the caret.
1103 webView->commitText("", 5);
1104 info = webView->textInputInfo();
1105 EXPECT_EQ("helloworld", std::string(info.value.utf8().data()));
1106 EXPECT_EQ(10, info.selectionStart);
1107 EXPECT_EQ(10, info.selectionEnd);
1108 EXPECT_EQ(-1, info.compositionStart);
1109 EXPECT_EQ(-1, info.compositionEnd);
1110 }
1111
865 TEST_F(WebViewTest, FinishCompositionDoesNotRevealSelection) 1112 TEST_F(WebViewTest, FinishCompositionDoesNotRevealSelection)
866 { 1113 {
867 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form_with_input.html")); 1114 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form_with_input.html"));
868 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form_w ith_input.html"); 1115 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form_w ith_input.html");
869 webView->resize(WebSize(800, 600)); 1116 webView->resize(WebSize(800, 600));
870 webView->setInitialFocus(false); 1117 webView->setInitialFocus(false);
871 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); 1118 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width);
872 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().height); 1119 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().height);
873 1120
874 // Set up a composition from existing text that needs to be committed. 1121 // Set up a composition from existing text that needs to be committed.
875 Vector<CompositionUnderline> emptyUnderlines; 1122 Vector<CompositionUnderline> emptyUnderlines;
876 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 1123 WebLocalFrameImpl* frame = webView->mainFrameImpl();
877 frame->frame()->inputMethodController().setCompositionFromExistingText(empty Underlines, 3, 3); 1124 frame->frame()->inputMethodController().setCompositionFromExistingText(empty Underlines, 3, 3);
878 1125
879 // Scroll the input field out of the viewport. 1126 // Scroll the input field out of the viewport.
880 Element* element = static_cast<Element*>(webView->mainFrame()->document().ge tElementById("btn")); 1127 Element* element = static_cast<Element*>(webView->mainFrame()->document().ge tElementById("btn"));
881 element->scrollIntoView(); 1128 element->scrollIntoView();
882 float offsetHeight = webView->mainFrame()->scrollOffset().height; 1129 float offsetHeight = webView->mainFrame()->scrollOffset().height;
883 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); 1130 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width);
884 EXPECT_LT(0, offsetHeight); 1131 EXPECT_LT(0, offsetHeight);
885 1132
886 WebTextInputInfo info = webView->textInputInfo(); 1133 WebTextInputInfo info = webView->textInputInfo();
887 EXPECT_EQ("hello", std::string(info.value.utf8().data())); 1134 EXPECT_EQ("hello", std::string(info.value.utf8().data()));
888 1135
889 // Verify that the input field is not scrolled back into the viewport. 1136 // Verify that the input field is not scrolled back into the viewport.
890 webView->confirmComposition(WebWidget::DoNotKeepSelection); 1137 webView->finishComposingText(WebWidget::DoNotKeepSelection);
891 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); 1138 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width);
892 EXPECT_EQ(offsetHeight, webView->mainFrame()->scrollOffset().height); 1139 EXPECT_EQ(offsetHeight, webView->mainFrame()->scrollOffset().height);
893 } 1140 }
894 1141
895 TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition) 1142 TEST_F(WebViewTest, InsertNewLinePlacementAfterFinishComposingText)
896 { 1143 {
897 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("text_area_populated.html")); 1144 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("text_area_populated.html"));
898 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_a rea_populated.html"); 1145 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_a rea_populated.html");
899 webView->setInitialFocus(false); 1146 webView->setInitialFocus(false);
900 1147
901 WebVector<WebCompositionUnderline> emptyUnderlines; 1148 WebVector<WebCompositionUnderline> emptyUnderlines;
902 1149
903 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 1150 WebLocalFrameImpl* frame = webView->mainFrameImpl();
904 frame->setEditableSelectionOffsets(4, 4); 1151 frame->setEditableSelectionOffsets(4, 4);
905 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); 1152 frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
906 1153
907 WebTextInputInfo info = webView->textInputInfo(); 1154 WebTextInputInfo info = webView->textInputInfo();
908 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf 8().data())); 1155 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf 8().data()));
909 EXPECT_EQ(4, info.selectionStart); 1156 EXPECT_EQ(4, info.selectionStart);
910 EXPECT_EQ(4, info.selectionEnd); 1157 EXPECT_EQ(4, info.selectionEnd);
911 EXPECT_EQ(8, info.compositionStart); 1158 EXPECT_EQ(8, info.compositionStart);
912 EXPECT_EQ(12, info.compositionEnd); 1159 EXPECT_EQ(12, info.compositionEnd);
913 1160
914 webView->confirmComposition(WebWidget::KeepSelection); 1161 webView->finishComposingText(WebWidget::KeepSelection);
915 info = webView->textInputInfo(); 1162 info = webView->textInputInfo();
916 EXPECT_EQ(4, info.selectionStart); 1163 EXPECT_EQ(4, info.selectionStart);
917 EXPECT_EQ(4, info.selectionEnd); 1164 EXPECT_EQ(4, info.selectionEnd);
918 EXPECT_EQ(-1, info.compositionStart); 1165 EXPECT_EQ(-1, info.compositionStart);
919 EXPECT_EQ(-1, info.compositionEnd); 1166 EXPECT_EQ(-1, info.compositionEnd);
920 1167
921 std::string compositionText("\n"); 1168 std::string compositionText("\n");
922 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); 1169 webView->commitText(WebString::fromUTF8(compositionText.c_str()), 0);
923 info = webView->textInputInfo(); 1170 info = webView->textInputInfo();
924 EXPECT_EQ(5, info.selectionStart); 1171 EXPECT_EQ(5, info.selectionStart);
925 EXPECT_EQ(5, info.selectionEnd); 1172 EXPECT_EQ(5, info.selectionEnd);
926 EXPECT_EQ(-1, info.compositionStart); 1173 EXPECT_EQ(-1, info.compositionStart);
927 EXPECT_EQ(-1, info.compositionEnd); 1174 EXPECT_EQ(-1, info.compositionEnd);
928 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.u tf8().data())); 1175 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.u tf8().data()));
929 } 1176 }
930 1177
931 TEST_F(WebViewTest, ExtendSelectionAndDelete) 1178 TEST_F(WebViewTest, ExtendSelectionAndDelete)
932 { 1179 {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea) 1219 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea)
973 { 1220 {
974 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("text_area_populated.html")); 1221 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("text_area_populated.html"));
975 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_a rea_populated.html"); 1222 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_a rea_populated.html");
976 webView->setInitialFocus(false); 1223 webView->setInitialFocus(false);
977 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); 1224 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
978 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); 1225 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
979 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 1226 WebLocalFrameImpl* frame = webView->mainFrameImpl();
980 frame->setEditableSelectionOffsets(27, 27); 1227 frame->setEditableSelectionOffsets(27, 27);
981 std::string newLineText("\n"); 1228 std::string newLineText("\n");
982 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); 1229 webView->commitText(WebString::fromUTF8(newLineText.c_str()), 0);
983 WebTextInputInfo info = webView->textInputInfo(); 1230 WebTextInputInfo info = webView->textInputInfo();
984 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data())); 1231 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data()));
985 1232
986 frame->setEditableSelectionOffsets(31, 31); 1233 frame->setEditableSelectionOffsets(31, 31);
987 frame->setCompositionFromExistingText(30, 34, underlines); 1234 frame->setCompositionFromExistingText(30, 34, underlines);
988 info = webView->textInputInfo(); 1235 info = webView->textInputInfo();
989 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data())); 1236 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data()));
990 EXPECT_EQ(31, info.selectionStart); 1237 EXPECT_EQ(31, info.selectionStart);
991 EXPECT_EQ(31, info.selectionEnd); 1238 EXPECT_EQ(31, info.selectionEnd);
992 EXPECT_EQ(30, info.compositionStart); 1239 EXPECT_EQ(30, info.compositionStart);
993 EXPECT_EQ(34, info.compositionEnd); 1240 EXPECT_EQ(34, info.compositionEnd);
994 1241
995 std::string compositionText("yolo"); 1242 std::string compositionText("yolo");
996 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); 1243 webView->commitText(WebString::fromUTF8(compositionText.c_str()), 0);
997 info = webView->textInputInfo(); 1244 info = webView->textInputInfo();
998 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data())); 1245 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data()));
999 EXPECT_EQ(34, info.selectionStart); 1246 EXPECT_EQ(34, info.selectionStart);
1000 EXPECT_EQ(34, info.selectionEnd); 1247 EXPECT_EQ(34, info.selectionEnd);
1001 EXPECT_EQ(-1, info.compositionStart); 1248 EXPECT_EQ(-1, info.compositionStart);
1002 EXPECT_EQ(-1, info.compositionEnd); 1249 EXPECT_EQ(-1, info.compositionEnd);
1003 } 1250 }
1004 1251
1005 TEST_F(WebViewTest, SetCompositionFromExistingTextInRichText) 1252 TEST_F(WebViewTest, SetCompositionFromExistingTextInRichText)
1006 { 1253 {
(...skipping 13 matching lines...) Expand all
1020 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) 1267 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
1021 { 1268 {
1022 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 1269 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1023 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_ field_populated.html"); 1270 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_ field_populated.html");
1024 webView->setInitialFocus(false); 1271 webView->setInitialFocus(false);
1025 1272
1026 std::string compositionTextFirst("hello "); 1273 std::string compositionTextFirst("hello ");
1027 std::string compositionTextSecond("world"); 1274 std::string compositionTextSecond("world");
1028 WebVector<WebCompositionUnderline> emptyUnderlines; 1275 WebVector<WebCompositionUnderline> emptyUnderlines;
1029 1276
1030 webView->confirmComposition(WebString::fromUTF8(compositionTextFirst.c_str() )); 1277 webView->commitText(WebString::fromUTF8(compositionTextFirst.c_str()), 0);
1031 webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, 5); 1278 webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, 5);
1032 1279
1033 WebTextInputInfo info = webView->textInputInfo(); 1280 WebTextInputInfo info = webView->textInputInfo();
1034 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); 1281 EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
1035 EXPECT_EQ(11, info.selectionStart); 1282 EXPECT_EQ(11, info.selectionStart);
1036 EXPECT_EQ(11, info.selectionEnd); 1283 EXPECT_EQ(11, info.selectionEnd);
1037 EXPECT_EQ(6, info.compositionStart); 1284 EXPECT_EQ(6, info.compositionStart);
1038 EXPECT_EQ(11, info.compositionEnd); 1285 EXPECT_EQ(11, info.compositionEnd);
1039 1286
1040 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 1287 WebLocalFrameImpl* frame = webView->mainFrameImpl();
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 2336
2090 keyEvent.type = WebInputEvent::KeyUp; 2337 keyEvent.type = WebInputEvent::KeyUp;
2091 webView->handleInputEvent(keyEvent); 2338 webView->handleInputEvent(keyEvent);
2092 2339
2093 webView->advanceFocus(false); 2340 webView->advanceFocus(false);
2094 } 2341 }
2095 2342
2096 frame->setAutofillClient(0); 2343 frame->setAutofillClient(0);
2097 } 2344 }
2098 2345
2099 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) 2346 TEST_F(WebViewTest, FinishComposingTextTriggersAutofillTextChange)
2100 { 2347 {
2101 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 2348 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
2102 MockAutofillClient client; 2349 MockAutofillClient client;
2103 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_ field_populated.html"); 2350 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_ field_populated.html");
2104 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 2351 WebLocalFrameImpl* frame = webView->mainFrameImpl();
2105 frame->setAutofillClient(&client); 2352 frame->setAutofillClient(&client);
2106 webView->setInitialFocus(false); 2353 webView->setInitialFocus(false);
2107 2354
2108 // Set up a composition that needs to be committed. 2355 // Set up a composition that needs to be committed.
2109 std::string compositionText("testingtext"); 2356 std::string compositionText("testingtext");
2110 2357
2111 WebVector<WebCompositionUnderline> emptyUnderlines; 2358 WebVector<WebCompositionUnderline> emptyUnderlines;
2112 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 0, compositionText.length()); 2359 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 0, compositionText.length());
2113 2360
2114 WebTextInputInfo info = webView->textInputInfo(); 2361 WebTextInputInfo info = webView->textInputInfo();
2115 EXPECT_EQ(0, info.selectionStart); 2362 EXPECT_EQ(0, info.selectionStart);
2116 EXPECT_EQ((int) compositionText.length(), info.selectionEnd); 2363 EXPECT_EQ((int) compositionText.length(), info.selectionEnd);
2117 EXPECT_EQ(0, info.compositionStart); 2364 EXPECT_EQ(0, info.compositionStart);
2118 EXPECT_EQ((int) compositionText.length(), info.compositionEnd); 2365 EXPECT_EQ((int) compositionText.length(), info.compositionEnd);
2119 2366
2120 client.clearChangeCounts(); 2367 client.clearChangeCounts();
2121 webView->confirmComposition(); 2368 webView->finishComposingText(WebWidget::KeepSelection);
2122 EXPECT_EQ(0, client.textChangesWhileIgnored()); 2369 EXPECT_EQ(0, client.textChangesWhileIgnored());
2123 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); 2370 EXPECT_EQ(1, client.textChangesWhileNotIgnored());
2124 2371
2125 frame->setAutofillClient(0); 2372 frame->setAutofillClient(0);
2126 } 2373 }
2127 2374
2128 TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) 2375 TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange)
2129 { 2376 {
2130 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 2377 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
2131 MockAutofillClient client; 2378 MockAutofillClient client;
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 EXPECT_TRUE(client.textIsUpdated()); 3062 EXPECT_TRUE(client.textIsUpdated());
2816 WebTextInputInfo info = webViewImpl->textInputInfo(); 3063 WebTextInputInfo info = webViewImpl->textInputInfo();
2817 EXPECT_EQ("testA", std::string(info.value.utf8().data())); 3064 EXPECT_EQ("testA", std::string(info.value.utf8().data()));
2818 3065
2819 // (A.2) Focused and user input modifies value. 3066 // (A.2) Focused and user input modifies value.
2820 client.reset(); 3067 client.reset();
2821 EXPECT_FALSE(client.textIsUpdated()); 3068 EXPECT_FALSE(client.textIsUpdated());
2822 3069
2823 WebVector<WebCompositionUnderline> emptyUnderlines; 3070 WebVector<WebCompositionUnderline> emptyUnderlines;
2824 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ; 3071 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ;
2825 webViewImpl->confirmComposition(WebWidget::KeepSelection); 3072 webViewImpl->finishComposingText(WebWidget::KeepSelection);
2826 EXPECT_FALSE(client.textIsUpdated()); 3073 EXPECT_FALSE(client.textIsUpdated());
2827 info = webViewImpl->textInputInfo(); 3074 info = webViewImpl->textInputInfo();
2828 EXPECT_EQ("testA2", std::string(info.value.utf8().data())); 3075 EXPECT_EQ("testA2", std::string(info.value.utf8().data()));
2829 3076
2830 // (A.3) Unfocused and value is changed by script. 3077 // (A.3) Unfocused and value is changed by script.
2831 client.reset(); 3078 client.reset();
2832 EXPECT_FALSE(client.textIsUpdated()); 3079 EXPECT_FALSE(client.textIsUpdated());
2833 document->clearFocusedElement(); 3080 document->clearFocusedElement();
2834 webViewImpl->setFocus(false); 3081 webViewImpl->setFocus(false);
2835 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement)); 3082 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement));
(...skipping 10 matching lines...) Expand all
2846 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement) ); 3093 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement) );
2847 textAreaElement->setValue("testB"); 3094 textAreaElement->setValue("testB");
2848 EXPECT_TRUE(client.textIsUpdated()); 3095 EXPECT_TRUE(client.textIsUpdated());
2849 info = webViewImpl->textInputInfo(); 3096 info = webViewImpl->textInputInfo();
2850 EXPECT_EQ("testB", std::string(info.value.utf8().data())); 3097 EXPECT_EQ("testB", std::string(info.value.utf8().data()));
2851 3098
2852 // (B.2) Focused and user input modifies value. 3099 // (B.2) Focused and user input modifies value.
2853 client.reset(); 3100 client.reset();
2854 EXPECT_FALSE(client.textIsUpdated()); 3101 EXPECT_FALSE(client.textIsUpdated());
2855 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ; 3102 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ;
2856 webViewImpl->confirmComposition(WebWidget::KeepSelection); 3103 webViewImpl->finishComposingText(WebWidget::KeepSelection);
2857 info = webViewImpl->textInputInfo(); 3104 info = webViewImpl->textInputInfo();
2858 EXPECT_EQ("testB2", std::string(info.value.utf8().data())); 3105 EXPECT_EQ("testB2", std::string(info.value.utf8().data()));
2859 3106
2860 // (B.3) Unfocused and value is changed by script. 3107 // (B.3) Unfocused and value is changed by script.
2861 client.reset(); 3108 client.reset();
2862 EXPECT_FALSE(client.textIsUpdated()); 3109 EXPECT_FALSE(client.textIsUpdated());
2863 document->clearFocusedElement(); 3110 document->clearFocusedElement();
2864 webViewImpl->setFocus(false); 3111 webViewImpl->setFocus(false);
2865 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement) ); 3112 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement) );
2866 inputElement->setValue("testB3"); 3113 inputElement->setValue("testB3");
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 3534
3288 TEST_F(WebViewTest, PasswordFieldEditingIsUserGesture) 3535 TEST_F(WebViewTest, PasswordFieldEditingIsUserGesture)
3289 { 3536 {
3290 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_password.html")); 3537 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_password.html"));
3291 MockAutofillClient client; 3538 MockAutofillClient client;
3292 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_ field_password.html", true); 3539 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_ field_password.html", true);
3293 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 3540 WebLocalFrameImpl* frame = webView->mainFrameImpl();
3294 frame->setAutofillClient(&client); 3541 frame->setAutofillClient(&client);
3295 webView->setInitialFocus(false); 3542 webView->setInitialFocus(false);
3296 3543
3297 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel lo").c_str()))); 3544 EXPECT_TRUE(webView->commitText(WebString::fromUTF8(std::string("hello").c_s tr()), 0));
3298 EXPECT_EQ(1, client.textChangesFromUserGesture()); 3545 EXPECT_EQ(1, client.textChangesFromUserGesture());
3299 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); 3546 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
3300 frame->setAutofillClient(0); 3547 frame->setAutofillClient(0);
3301 } 3548 }
3302 3549
3303 // Verify that a WebView created with a ScopedPageLoadDeferrer already on the 3550 // Verify that a WebView created with a ScopedPageLoadDeferrer already on the
3304 // stack defers its loads. 3551 // stack defers its loads.
3305 TEST_F(WebViewTest, CreatedDuringLoadDeferral) 3552 TEST_F(WebViewTest, CreatedDuringLoadDeferral)
3306 { 3553 {
3307 { 3554 {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3365 EXPECT_TRUE(webView->page()->defersLoading()); 3612 EXPECT_TRUE(webView->page()->defersLoading());
3366 } 3613 }
3367 3614
3368 EXPECT_TRUE(webView->page()->defersLoading()); 3615 EXPECT_TRUE(webView->page()->defersLoading());
3369 } 3616 }
3370 3617
3371 EXPECT_FALSE(webView->page()->defersLoading()); 3618 EXPECT_FALSE(webView->page()->defersLoading());
3372 } 3619 }
3373 3620
3374 } // namespace blink 3621 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/public/web/WebLocalFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698