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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 WebTextInputInfo info = webView->textInputInfo(); | 789 WebTextInputInfo info = webView->textInputInfo(); |
790 | 790 |
791 EXPECT_EQ("foo\xef\xbf\xbc", info.value.utf8()); | 791 EXPECT_EQ("foo\xef\xbf\xbc", info.value.utf8()); |
792 } | 792 } |
793 | 793 |
794 TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) | 794 TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) |
795 { | 795 { |
796 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 796 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
797 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); | 797 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); |
798 webView->setInitialFocus(false); | 798 webView->setInitialFocus(false); |
| 799 webView->setEditableSelectionOffsets(5, 13); |
799 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 800 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
800 frame->setEditableSelectionOffsets(5, 13); | |
801 EXPECT_EQ("56789abc", frame->selectionAsText()); | 801 EXPECT_EQ("56789abc", frame->selectionAsText()); |
802 WebTextInputInfo info = webView->textInputInfo(); | 802 WebTextInputInfo info = webView->textInputInfo(); |
803 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); | 803 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); |
804 EXPECT_EQ(5, info.selectionStart); | 804 EXPECT_EQ(5, info.selectionStart); |
805 EXPECT_EQ(13, info.selectionEnd); | 805 EXPECT_EQ(13, info.selectionEnd); |
806 EXPECT_EQ(-1, info.compositionStart); | 806 EXPECT_EQ(-1, info.compositionStart); |
807 EXPECT_EQ(-1, info.compositionEnd); | 807 EXPECT_EQ(-1, info.compositionEnd); |
808 | 808 |
809 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_editable_populated.html")); | 809 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_editable_populated.html")); |
810 webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_editable_po
pulated.html"); | 810 webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_editable_po
pulated.html"); |
811 webView->setInitialFocus(false); | 811 webView->setInitialFocus(false); |
| 812 webView->setEditableSelectionOffsets(8, 19); |
812 frame = webView->mainFrameImpl(); | 813 frame = webView->mainFrameImpl(); |
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, ConfirmCompositionCursorPositionChange) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 } | 893 } |
894 | 894 |
895 TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition) | 895 TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition) |
896 { | 896 { |
897 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); | 897 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"); | 898 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_a
rea_populated.html"); |
899 webView->setInitialFocus(false); | 899 webView->setInitialFocus(false); |
900 | 900 |
901 WebVector<WebCompositionUnderline> emptyUnderlines; | 901 WebVector<WebCompositionUnderline> emptyUnderlines; |
902 | 902 |
903 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 903 webView->setEditableSelectionOffsets(4, 4); |
904 frame->setEditableSelectionOffsets(4, 4); | 904 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); |
905 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | |
906 | 905 |
907 WebTextInputInfo info = webView->textInputInfo(); | 906 WebTextInputInfo info = webView->textInputInfo(); |
908 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); | 907 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); |
909 EXPECT_EQ(4, info.selectionStart); | 908 EXPECT_EQ(4, info.selectionStart); |
910 EXPECT_EQ(4, info.selectionEnd); | 909 EXPECT_EQ(4, info.selectionEnd); |
911 EXPECT_EQ(8, info.compositionStart); | 910 EXPECT_EQ(8, info.compositionStart); |
912 EXPECT_EQ(12, info.compositionEnd); | 911 EXPECT_EQ(12, info.compositionEnd); |
913 | 912 |
914 webView->confirmComposition(WebWidget::KeepSelection); | 913 webView->confirmComposition(WebWidget::KeepSelection); |
915 info = webView->textInputInfo(); | 914 info = webView->textInputInfo(); |
916 EXPECT_EQ(4, info.selectionStart); | 915 EXPECT_EQ(4, info.selectionStart); |
917 EXPECT_EQ(4, info.selectionEnd); | 916 EXPECT_EQ(4, info.selectionEnd); |
918 EXPECT_EQ(-1, info.compositionStart); | 917 EXPECT_EQ(-1, info.compositionStart); |
919 EXPECT_EQ(-1, info.compositionEnd); | 918 EXPECT_EQ(-1, info.compositionEnd); |
920 | 919 |
921 std::string compositionText("\n"); | 920 std::string compositionText("\n"); |
922 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); | 921 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); |
923 info = webView->textInputInfo(); | 922 info = webView->textInputInfo(); |
924 EXPECT_EQ(5, info.selectionStart); | 923 EXPECT_EQ(5, info.selectionStart); |
925 EXPECT_EQ(5, info.selectionEnd); | 924 EXPECT_EQ(5, info.selectionEnd); |
926 EXPECT_EQ(-1, info.compositionStart); | 925 EXPECT_EQ(-1, info.compositionStart); |
927 EXPECT_EQ(-1, info.compositionEnd); | 926 EXPECT_EQ(-1, info.compositionEnd); |
928 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.u
tf8().data())); | 927 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.u
tf8().data())); |
929 } | 928 } |
930 | 929 |
931 TEST_F(WebViewTest, ExtendSelectionAndDelete) | 930 TEST_F(WebViewTest, ExtendSelectionAndDelete) |
932 { | 931 { |
933 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 932 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
934 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); | 933 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); |
935 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | |
936 webView->setInitialFocus(false); | 934 webView->setInitialFocus(false); |
937 frame->setEditableSelectionOffsets(10, 10); | 935 webView->setEditableSelectionOffsets(10, 10); |
938 frame->extendSelectionAndDelete(5, 8); | 936 webView->extendSelectionAndDelete(5, 8); |
939 WebTextInputInfo info = webView->textInputInfo(); | 937 WebTextInputInfo info = webView->textInputInfo(); |
940 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 938 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
941 EXPECT_EQ(5, info.selectionStart); | 939 EXPECT_EQ(5, info.selectionStart); |
942 EXPECT_EQ(5, info.selectionEnd); | 940 EXPECT_EQ(5, info.selectionEnd); |
943 frame->extendSelectionAndDelete(10, 0); | 941 webView->extendSelectionAndDelete(10, 0); |
944 info = webView->textInputInfo(); | 942 info = webView->textInputInfo(); |
945 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 943 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
946 } | 944 } |
947 | 945 |
948 TEST_F(WebViewTest, SetCompositionFromExistingText) | 946 TEST_F(WebViewTest, SetCompositionFromExistingText) |
949 { | 947 { |
950 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 948 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
951 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); | 949 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); |
952 webView->setInitialFocus(false); | 950 webView->setInitialFocus(false); |
953 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 951 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
954 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 952 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
955 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 953 webView->setEditableSelectionOffsets(4, 10); |
956 frame->setEditableSelectionOffsets(4, 10); | 954 webView->setCompositionFromExistingText(8, 12, underlines); |
957 frame->setCompositionFromExistingText(8, 12, underlines); | |
958 WebTextInputInfo info = webView->textInputInfo(); | 955 WebTextInputInfo info = webView->textInputInfo(); |
959 EXPECT_EQ(4, info.selectionStart); | 956 EXPECT_EQ(4, info.selectionStart); |
960 EXPECT_EQ(10, info.selectionEnd); | 957 EXPECT_EQ(10, info.selectionEnd); |
961 EXPECT_EQ(8, info.compositionStart); | 958 EXPECT_EQ(8, info.compositionStart); |
962 EXPECT_EQ(12, info.compositionEnd); | 959 EXPECT_EQ(12, info.compositionEnd); |
963 WebVector<WebCompositionUnderline> emptyUnderlines; | 960 WebVector<WebCompositionUnderline> emptyUnderlines; |
964 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); | 961 webView->setCompositionFromExistingText(0, 0, emptyUnderlines); |
965 info = webView->textInputInfo(); | 962 info = webView->textInputInfo(); |
966 EXPECT_EQ(4, info.selectionStart); | 963 EXPECT_EQ(4, info.selectionStart); |
967 EXPECT_EQ(10, info.selectionEnd); | 964 EXPECT_EQ(10, info.selectionEnd); |
968 EXPECT_EQ(-1, info.compositionStart); | 965 EXPECT_EQ(-1, info.compositionStart); |
969 EXPECT_EQ(-1, info.compositionEnd); | 966 EXPECT_EQ(-1, info.compositionEnd); |
970 } | 967 } |
971 | 968 |
972 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea) | 969 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea) |
973 { | 970 { |
974 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); | 971 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"); | 972 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_a
rea_populated.html"); |
976 webView->setInitialFocus(false); | 973 webView->setInitialFocus(false); |
977 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 974 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
978 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 975 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
979 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 976 webView->setEditableSelectionOffsets(27, 27); |
980 frame->setEditableSelectionOffsets(27, 27); | |
981 std::string newLineText("\n"); | 977 std::string newLineText("\n"); |
982 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); | 978 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); |
983 WebTextInputInfo info = webView->textInputInfo(); | 979 WebTextInputInfo info = webView->textInputInfo(); |
984 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); | 980 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); |
985 | 981 |
986 frame->setEditableSelectionOffsets(31, 31); | 982 webView->setEditableSelectionOffsets(31, 31); |
987 frame->setCompositionFromExistingText(30, 34, underlines); | 983 webView->setCompositionFromExistingText(30, 34, underlines); |
988 info = webView->textInputInfo(); | 984 info = webView->textInputInfo(); |
989 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); | 985 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); |
990 EXPECT_EQ(31, info.selectionStart); | 986 EXPECT_EQ(31, info.selectionStart); |
991 EXPECT_EQ(31, info.selectionEnd); | 987 EXPECT_EQ(31, info.selectionEnd); |
992 EXPECT_EQ(30, info.compositionStart); | 988 EXPECT_EQ(30, info.compositionStart); |
993 EXPECT_EQ(34, info.compositionEnd); | 989 EXPECT_EQ(34, info.compositionEnd); |
994 | 990 |
995 std::string compositionText("yolo"); | 991 std::string compositionText("yolo"); |
996 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); | 992 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); |
997 info = webView->textInputInfo(); | 993 info = webView->textInputInfo(); |
998 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u
tf8().data())); | 994 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u
tf8().data())); |
999 EXPECT_EQ(34, info.selectionStart); | 995 EXPECT_EQ(34, info.selectionStart); |
1000 EXPECT_EQ(34, info.selectionEnd); | 996 EXPECT_EQ(34, info.selectionEnd); |
1001 EXPECT_EQ(-1, info.compositionStart); | 997 EXPECT_EQ(-1, info.compositionStart); |
1002 EXPECT_EQ(-1, info.compositionEnd); | 998 EXPECT_EQ(-1, info.compositionEnd); |
1003 } | 999 } |
1004 | 1000 |
1005 TEST_F(WebViewTest, SetCompositionFromExistingTextInRichText) | 1001 TEST_F(WebViewTest, SetCompositionFromExistingTextInRichText) |
1006 { | 1002 { |
1007 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_editable_rich_text.html")); | 1003 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_editable_rich_text.html")); |
1008 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "conten
t_editable_rich_text.html"); | 1004 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "conten
t_editable_rich_text.html"); |
1009 webView->setInitialFocus(false); | 1005 webView->setInitialFocus(false); |
1010 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 1006 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
1011 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 1007 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
1012 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1008 webView->setEditableSelectionOffsets(1, 1); |
1013 frame->setEditableSelectionOffsets(1, 1); | |
1014 WebDocument document = webView->mainFrame()->document(); | 1009 WebDocument document = webView->mainFrame()->document(); |
1015 EXPECT_FALSE(document.getElementById("bold").isNull()); | 1010 EXPECT_FALSE(document.getElementById("bold").isNull()); |
1016 frame->setCompositionFromExistingText(0, 4, underlines); | 1011 webView->setCompositionFromExistingText(0, 4, underlines); |
1017 EXPECT_FALSE(document.getElementById("bold").isNull()); | 1012 EXPECT_FALSE(document.getElementById("bold").isNull()); |
1018 } | 1013 } |
1019 | 1014 |
1020 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) | 1015 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) |
1021 { | 1016 { |
1022 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1017 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"); | 1018 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); |
1024 webView->setInitialFocus(false); | 1019 webView->setInitialFocus(false); |
1025 | 1020 |
1026 std::string compositionTextFirst("hello "); | 1021 std::string compositionTextFirst("hello "); |
1027 std::string compositionTextSecond("world"); | 1022 std::string compositionTextSecond("world"); |
1028 WebVector<WebCompositionUnderline> emptyUnderlines; | 1023 WebVector<WebCompositionUnderline> emptyUnderlines; |
1029 | 1024 |
1030 webView->confirmComposition(WebString::fromUTF8(compositionTextFirst.c_str()
)); | 1025 webView->confirmComposition(WebString::fromUTF8(compositionTextFirst.c_str()
)); |
1031 webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()),
emptyUnderlines, 5, 5); | 1026 webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()),
emptyUnderlines, 5, 5); |
1032 | 1027 |
1033 WebTextInputInfo info = webView->textInputInfo(); | 1028 WebTextInputInfo info = webView->textInputInfo(); |
1034 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1029 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
1035 EXPECT_EQ(11, info.selectionStart); | 1030 EXPECT_EQ(11, info.selectionStart); |
1036 EXPECT_EQ(11, info.selectionEnd); | 1031 EXPECT_EQ(11, info.selectionEnd); |
1037 EXPECT_EQ(6, info.compositionStart); | 1032 EXPECT_EQ(6, info.compositionStart); |
1038 EXPECT_EQ(11, info.compositionEnd); | 1033 EXPECT_EQ(11, info.compositionEnd); |
1039 | 1034 |
1040 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1035 webView->setEditableSelectionOffsets(6, 6); |
1041 frame->setEditableSelectionOffsets(6, 6); | |
1042 info = webView->textInputInfo(); | 1036 info = webView->textInputInfo(); |
1043 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1037 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
1044 EXPECT_EQ(6, info.selectionStart); | 1038 EXPECT_EQ(6, info.selectionStart); |
1045 EXPECT_EQ(6, info.selectionEnd); | 1039 EXPECT_EQ(6, info.selectionEnd); |
1046 EXPECT_EQ(6, info.compositionStart); | 1040 EXPECT_EQ(6, info.compositionStart); |
1047 EXPECT_EQ(11, info.compositionEnd); | 1041 EXPECT_EQ(11, info.compositionEnd); |
1048 | 1042 |
1049 frame->setEditableSelectionOffsets(8, 8); | 1043 webView->setEditableSelectionOffsets(8, 8); |
1050 info = webView->textInputInfo(); | 1044 info = webView->textInputInfo(); |
1051 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1045 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
1052 EXPECT_EQ(8, info.selectionStart); | 1046 EXPECT_EQ(8, info.selectionStart); |
1053 EXPECT_EQ(8, info.selectionEnd); | 1047 EXPECT_EQ(8, info.selectionEnd); |
1054 EXPECT_EQ(6, info.compositionStart); | 1048 EXPECT_EQ(6, info.compositionStart); |
1055 EXPECT_EQ(11, info.compositionEnd); | 1049 EXPECT_EQ(11, info.compositionEnd); |
1056 | 1050 |
1057 frame->setEditableSelectionOffsets(11, 11); | 1051 webView->setEditableSelectionOffsets(11, 11); |
1058 info = webView->textInputInfo(); | 1052 info = webView->textInputInfo(); |
1059 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1053 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
1060 EXPECT_EQ(11, info.selectionStart); | 1054 EXPECT_EQ(11, info.selectionStart); |
1061 EXPECT_EQ(11, info.selectionEnd); | 1055 EXPECT_EQ(11, info.selectionEnd); |
1062 EXPECT_EQ(6, info.compositionStart); | 1056 EXPECT_EQ(6, info.compositionStart); |
1063 EXPECT_EQ(11, info.compositionEnd); | 1057 EXPECT_EQ(11, info.compositionEnd); |
1064 | 1058 |
1065 frame->setEditableSelectionOffsets(6, 11); | 1059 webView->setEditableSelectionOffsets(6, 11); |
1066 info = webView->textInputInfo(); | 1060 info = webView->textInputInfo(); |
1067 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1061 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
1068 EXPECT_EQ(6, info.selectionStart); | 1062 EXPECT_EQ(6, info.selectionStart); |
1069 EXPECT_EQ(11, info.selectionEnd); | 1063 EXPECT_EQ(11, info.selectionEnd); |
1070 EXPECT_EQ(6, info.compositionStart); | 1064 EXPECT_EQ(6, info.compositionStart); |
1071 EXPECT_EQ(11, info.compositionEnd); | 1065 EXPECT_EQ(11, info.compositionEnd); |
1072 | 1066 |
1073 frame->setEditableSelectionOffsets(2, 2); | 1067 webView->setEditableSelectionOffsets(2, 2); |
1074 info = webView->textInputInfo(); | 1068 info = webView->textInputInfo(); |
1075 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1069 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
1076 EXPECT_EQ(2, info.selectionStart); | 1070 EXPECT_EQ(2, info.selectionStart); |
1077 EXPECT_EQ(2, info.selectionEnd); | 1071 EXPECT_EQ(2, info.selectionEnd); |
1078 EXPECT_EQ(-1, info.compositionStart); | 1072 EXPECT_EQ(-1, info.compositionStart); |
1079 EXPECT_EQ(-1, info.compositionEnd); | 1073 EXPECT_EQ(-1, info.compositionEnd); |
1080 } | 1074 } |
1081 | 1075 |
1082 TEST_F(WebViewTest, IsSelectionAnchorFirst) | 1076 TEST_F(WebViewTest, IsSelectionAnchorFirst) |
1083 { | 1077 { |
1084 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1078 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
1085 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); | 1079 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); |
1086 WebLocalFrame* frame = webView->mainFrameImpl(); | |
1087 | 1080 |
1088 webView->setInitialFocus(false); | 1081 webView->setInitialFocus(false); |
1089 frame->setEditableSelectionOffsets(4, 10); | 1082 webView->setEditableSelectionOffsets(4, 10); |
1090 EXPECT_TRUE(webView->isSelectionAnchorFirst()); | 1083 EXPECT_TRUE(webView->isSelectionAnchorFirst()); |
1091 WebRect anchor; | 1084 WebRect anchor; |
1092 WebRect focus; | 1085 WebRect focus; |
1093 webView->selectionBounds(anchor, focus); | 1086 webView->selectionBounds(anchor, focus); |
| 1087 WebLocalFrame* frame = webView->mainFrameImpl(); |
1094 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y))
; | 1088 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y))
; |
1095 EXPECT_FALSE(webView->isSelectionAnchorFirst()); | 1089 EXPECT_FALSE(webView->isSelectionAnchorFirst()); |
1096 } | 1090 } |
1097 | 1091 |
1098 TEST_F(WebViewTest, ExitingDeviceEmulationResetsPageScale) | 1092 TEST_F(WebViewTest, ExitingDeviceEmulationResetsPageScale) |
1099 { | 1093 { |
1100 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); | 1094 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
1101 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); | 1095 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
1102 webViewImpl->resize(WebSize(200, 300)); | 1096 webViewImpl->resize(WebSize(200, 300)); |
1103 | 1097 |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2023 { | 2017 { |
2024 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 2018 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
2025 MockAutofillClient client; | 2019 MockAutofillClient client; |
2026 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); | 2020 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html"); |
2027 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2021 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
2028 frame->setAutofillClient(&client); | 2022 frame->setAutofillClient(&client); |
2029 webView->setInitialFocus(false); | 2023 webView->setInitialFocus(false); |
2030 | 2024 |
2031 // Set up a composition that needs to be committed. | 2025 // Set up a composition that needs to be committed. |
2032 WebVector<WebCompositionUnderline> emptyUnderlines; | 2026 WebVector<WebCompositionUnderline> emptyUnderlines; |
2033 frame->setEditableSelectionOffsets(4, 10); | 2027 webView->setEditableSelectionOffsets(4, 10); |
2034 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2028 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); |
2035 WebTextInputInfo info = webView->textInputInfo(); | 2029 WebTextInputInfo info = webView->textInputInfo(); |
2036 EXPECT_EQ(4, info.selectionStart); | 2030 EXPECT_EQ(4, info.selectionStart); |
2037 EXPECT_EQ(10, info.selectionEnd); | 2031 EXPECT_EQ(10, info.selectionEnd); |
2038 EXPECT_EQ(8, info.compositionStart); | 2032 EXPECT_EQ(8, info.compositionStart); |
2039 EXPECT_EQ(12, info.compositionEnd); | 2033 EXPECT_EQ(12, info.compositionEnd); |
2040 | 2034 |
2041 // Clear the focus and track that the subsequent composition commit does not
trigger a | 2035 // Clear the focus and track that the subsequent composition commit does not
trigger a |
2042 // text changed notification for autofill. | 2036 // text changed notification for autofill. |
2043 client.clearChangeCounts(); | 2037 client.clearChangeCounts(); |
2044 webView->setFocus(false); | 2038 webView->setFocus(false); |
(...skipping 17 matching lines...) Expand all Loading... |
2062 MockAutofillClient client; | 2056 MockAutofillClient client; |
2063 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "compos
ition_not_cancelled_by_backspace.html"); | 2057 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "compos
ition_not_cancelled_by_backspace.html"); |
2064 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2058 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
2065 frame->setAutofillClient(&client); | 2059 frame->setAutofillClient(&client); |
2066 webView->setInitialFocus(false); | 2060 webView->setInitialFocus(false); |
2067 | 2061 |
2068 // Test both input elements. | 2062 // Test both input elements. |
2069 for (int i = 0; i < 2; ++i) { | 2063 for (int i = 0; i < 2; ++i) { |
2070 // Select composition and do sanity check. | 2064 // Select composition and do sanity check. |
2071 WebVector<WebCompositionUnderline> emptyUnderlines; | 2065 WebVector<WebCompositionUnderline> emptyUnderlines; |
2072 frame->setEditableSelectionOffsets(6, 6); | 2066 webView->setEditableSelectionOffsets(6, 6); |
2073 EXPECT_TRUE(webView->setComposition("fghij", emptyUnderlines, 0, 5)); | 2067 EXPECT_TRUE(webView->setComposition("fghij", emptyUnderlines, 0, 5)); |
2074 frame->setEditableSelectionOffsets(11, 11); | 2068 webView->setEditableSelectionOffsets(11, 11); |
2075 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case"); | 2069 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case"); |
2076 | 2070 |
2077 // Press Backspace and verify composition didn't get cancelled. This is
to verify the fix | 2071 // Press Backspace and verify composition didn't get cancelled. This is
to verify the fix |
2078 // for crbug.com/429916. | 2072 // for crbug.com/429916. |
2079 WebKeyboardEvent keyEvent; | 2073 WebKeyboardEvent keyEvent; |
2080 keyEvent.domKey = Platform::current()->domKeyEnumFromString("\b"); | 2074 keyEvent.domKey = Platform::current()->domKeyEnumFromString("\b"); |
2081 keyEvent.windowsKeyCode = VKEY_BACK; | 2075 keyEvent.windowsKeyCode = VKEY_BACK; |
2082 keyEvent.type = WebInputEvent::RawKeyDown; | 2076 keyEvent.type = WebInputEvent::RawKeyDown; |
2083 webView->handleInputEvent(keyEvent); | 2077 webView->handleInputEvent(keyEvent); |
2084 | 2078 |
2085 frame->setEditableSelectionOffsets(6, 6); | 2079 webView->setEditableSelectionOffsets(6, 6); |
2086 EXPECT_TRUE(webView->setComposition("fghi", emptyUnderlines, 0, 4)); | 2080 EXPECT_TRUE(webView->setComposition("fghi", emptyUnderlines, 0, 4)); |
2087 frame->setEditableSelectionOffsets(10, 10); | 2081 webView->setEditableSelectionOffsets(10, 10); |
2088 verifySelectionAndComposition(webView, 10, 10, 6, 10, "after pressing Ba
ckspace"); | 2082 verifySelectionAndComposition(webView, 10, 10, 6, 10, "after pressing Ba
ckspace"); |
2089 | 2083 |
2090 keyEvent.type = WebInputEvent::KeyUp; | 2084 keyEvent.type = WebInputEvent::KeyUp; |
2091 webView->handleInputEvent(keyEvent); | 2085 webView->handleInputEvent(keyEvent); |
2092 | 2086 |
2093 webView->advanceFocus(false); | 2087 webView->advanceFocus(false); |
2094 } | 2088 } |
2095 | 2089 |
2096 frame->setAutofillClient(0); | 2090 frame->setAutofillClient(0); |
2097 } | 2091 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 2124 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
2131 MockAutofillClient client; | 2125 MockAutofillClient client; |
2132 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html", true); | 2126 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_
field_populated.html", true); |
2133 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2127 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
2134 frame->setAutofillClient(&client); | 2128 frame->setAutofillClient(&client); |
2135 webView->setInitialFocus(false); | 2129 webView->setInitialFocus(false); |
2136 | 2130 |
2137 WebVector<WebCompositionUnderline> emptyUnderlines; | 2131 WebVector<WebCompositionUnderline> emptyUnderlines; |
2138 | 2132 |
2139 client.clearChangeCounts(); | 2133 client.clearChangeCounts(); |
2140 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2134 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); |
2141 | 2135 |
2142 WebTextInputInfo info = webView->textInputInfo(); | 2136 WebTextInputInfo info = webView->textInputInfo(); |
2143 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); | 2137 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); |
2144 EXPECT_EQ(8, info.compositionStart); | 2138 EXPECT_EQ(8, info.compositionStart); |
2145 EXPECT_EQ(12, info.compositionEnd); | 2139 EXPECT_EQ(12, info.compositionEnd); |
2146 | 2140 |
2147 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 2141 EXPECT_EQ(0, client.textChangesWhileIgnored()); |
2148 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 2142 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
2149 | 2143 |
2150 WebDocument document = webView->mainFrame()->document(); | 2144 WebDocument document = webView->mainFrame()->document(); |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3364 EXPECT_TRUE(webView->page()->defersLoading()); | 3358 EXPECT_TRUE(webView->page()->defersLoading()); |
3365 } | 3359 } |
3366 | 3360 |
3367 EXPECT_TRUE(webView->page()->defersLoading()); | 3361 EXPECT_TRUE(webView->page()->defersLoading()); |
3368 } | 3362 } |
3369 | 3363 |
3370 EXPECT_FALSE(webView->page()->defersLoading()); | 3364 EXPECT_FALSE(webView->page()->defersLoading()); |
3371 } | 3365 } |
3372 | 3366 |
3373 } // namespace blink | 3367 } // namespace blink |
OLD | NEW |