| 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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 testAutoResize(minAutoResize, maxAutoResize, pageWidth, pageHeight, | 744 testAutoResize(minAutoResize, maxAutoResize, pageWidth, pageHeight, |
| 745 expectedWidth, expectedHeight, NoHorizontalScrollbar, | 745 expectedWidth, expectedHeight, NoHorizontalScrollbar, |
| 746 NoVerticalScrollbar); | 746 NoVerticalScrollbar); |
| 747 } | 747 } |
| 748 | 748 |
| 749 void WebViewTest::testTextInputType(WebTextInputType expectedType, | 749 void WebViewTest::testTextInputType(WebTextInputType expectedType, |
| 750 const std::string& htmlFile) { | 750 const std::string& htmlFile) { |
| 751 URLTestHelpers::registerMockedURLFromBaseURL( | 751 URLTestHelpers::registerMockedURLFromBaseURL( |
| 752 WebString::fromUTF8(m_baseURL.c_str()), | 752 WebString::fromUTF8(m_baseURL.c_str()), |
| 753 WebString::fromUTF8(htmlFile.c_str())); | 753 WebString::fromUTF8(htmlFile.c_str())); |
| 754 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile); | 754 WebViewImpl* webView = |
| 755 EXPECT_EQ(WebTextInputTypeNone, webView->textInputType()); | 755 m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile); |
| 756 EXPECT_EQ(WebTextInputTypeNone, webView->textInputInfo().type); | 756 WebInputMethodControllerImpl* controller = |
| 757 webView->mainFrameImpl()->inputMethodController(); |
| 758 EXPECT_EQ(WebTextInputTypeNone, controller->textInputType()); |
| 759 EXPECT_EQ(WebTextInputTypeNone, controller->textInputInfo().type); |
| 757 webView->setInitialFocus(false); | 760 webView->setInitialFocus(false); |
| 758 EXPECT_EQ(expectedType, webView->textInputType()); | 761 EXPECT_EQ(expectedType, controller->textInputType()); |
| 759 EXPECT_EQ(expectedType, webView->textInputInfo().type); | 762 EXPECT_EQ(expectedType, controller->textInputInfo().type); |
| 760 webView->clearFocusedElement(); | 763 webView->clearFocusedElement(); |
| 761 EXPECT_EQ(WebTextInputTypeNone, webView->textInputType()); | 764 EXPECT_EQ(WebTextInputTypeNone, controller->textInputType()); |
| 762 EXPECT_EQ(WebTextInputTypeNone, webView->textInputInfo().type); | 765 EXPECT_EQ(WebTextInputTypeNone, controller->textInputInfo().type); |
| 763 } | 766 } |
| 764 | 767 |
| 765 TEST_P(WebViewTest, TextInputType) { | 768 TEST_P(WebViewTest, TextInputType) { |
| 766 testTextInputType(WebTextInputTypeText, "input_field_default.html"); | 769 testTextInputType(WebTextInputTypeText, "input_field_default.html"); |
| 767 testTextInputType(WebTextInputTypePassword, "input_field_password.html"); | 770 testTextInputType(WebTextInputTypePassword, "input_field_password.html"); |
| 768 testTextInputType(WebTextInputTypeEmail, "input_field_email.html"); | 771 testTextInputType(WebTextInputTypeEmail, "input_field_email.html"); |
| 769 testTextInputType(WebTextInputTypeSearch, "input_field_search.html"); | 772 testTextInputType(WebTextInputTypeSearch, "input_field_search.html"); |
| 770 testTextInputType(WebTextInputTypeNumber, "input_field_number.html"); | 773 testTextInputType(WebTextInputTypeNumber, "input_field_number.html"); |
| 771 testTextInputType(WebTextInputTypeTelephone, "input_field_tel.html"); | 774 testTextInputType(WebTextInputTypeTelephone, "input_field_tel.html"); |
| 772 testTextInputType(WebTextInputTypeURL, "input_field_url.html"); | 775 testTextInputType(WebTextInputTypeURL, "input_field_url.html"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 794 baseURL); | 797 baseURL); |
| 795 webViewImpl->setInitialFocus(false); | 798 webViewImpl->setInitialFocus(false); |
| 796 | 799 |
| 797 // Add id="foo" to <path>, thus triggering the condition described above. | 800 // Add id="foo" to <path>, thus triggering the condition described above. |
| 798 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); | 801 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
| 799 document->body() | 802 document->body() |
| 800 ->querySelector("path", ASSERT_NO_EXCEPTION) | 803 ->querySelector("path", ASSERT_NO_EXCEPTION) |
| 801 ->setIdAttribute("foo"); | 804 ->setIdAttribute("foo"); |
| 802 | 805 |
| 803 // This should not DCHECK. | 806 // This should not DCHECK. |
| 804 EXPECT_EQ(WebTextInputTypeText, webViewImpl->textInputInfo().type); | 807 EXPECT_EQ(WebTextInputTypeText, webViewImpl->mainFrameImpl() |
| 808 ->inputMethodController() |
| 809 ->textInputInfo() |
| 810 .type); |
| 805 } | 811 } |
| 806 | 812 |
| 807 void WebViewTest::testInputMode(WebTextInputMode expectedInputMode, | 813 void WebViewTest::testInputMode(WebTextInputMode expectedInputMode, |
| 808 const std::string& htmlFile) { | 814 const std::string& htmlFile) { |
| 809 URLTestHelpers::registerMockedURLFromBaseURL( | 815 URLTestHelpers::registerMockedURLFromBaseURL( |
| 810 WebString::fromUTF8(m_baseURL.c_str()), | 816 WebString::fromUTF8(m_baseURL.c_str()), |
| 811 WebString::fromUTF8(htmlFile.c_str())); | 817 WebString::fromUTF8(htmlFile.c_str())); |
| 812 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile); | 818 WebViewImpl* webViewImpl = |
| 813 webView->setInitialFocus(false); | 819 m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile); |
| 814 EXPECT_EQ(expectedInputMode, webView->textInputInfo().inputMode); | 820 webViewImpl->setInitialFocus(false); |
| 821 EXPECT_EQ(expectedInputMode, webViewImpl->mainFrameImpl() |
| 822 ->inputMethodController() |
| 823 ->textInputInfo() |
| 824 .inputMode); |
| 815 } | 825 } |
| 816 | 826 |
| 817 TEST_P(WebViewTest, InputMode) { | 827 TEST_P(WebViewTest, InputMode) { |
| 818 testInputMode(WebTextInputMode::kWebTextInputModeDefault, | 828 testInputMode(WebTextInputMode::kWebTextInputModeDefault, |
| 819 "input_mode_default.html"); | 829 "input_mode_default.html"); |
| 820 testInputMode(WebTextInputMode::kWebTextInputModeDefault, | 830 testInputMode(WebTextInputMode::kWebTextInputModeDefault, |
| 821 "input_mode_default_unknown.html"); | 831 "input_mode_default_unknown.html"); |
| 822 testInputMode(WebTextInputMode::kWebTextInputModeVerbatim, | 832 testInputMode(WebTextInputMode::kWebTextInputModeVerbatim, |
| 823 "input_mode_default_verbatim.html"); | 833 "input_mode_default_verbatim.html"); |
| 824 testInputMode(WebTextInputMode::kWebTextInputModeVerbatim, | 834 testInputMode(WebTextInputMode::kWebTextInputModeVerbatim, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 849 "input_mode_type_email.html"); | 859 "input_mode_type_email.html"); |
| 850 testInputMode(WebTextInputMode::kWebTextInputModeUrl, | 860 testInputMode(WebTextInputMode::kWebTextInputModeUrl, |
| 851 "input_mode_type_url.html"); | 861 "input_mode_type_url.html"); |
| 852 } | 862 } |
| 853 | 863 |
| 854 TEST_P(WebViewTest, TextInputInfoWithReplacedElements) { | 864 TEST_P(WebViewTest, TextInputInfoWithReplacedElements) { |
| 855 std::string url = m_baseURL + "div_with_image.html"; | 865 std::string url = m_baseURL + "div_with_image.html"; |
| 856 URLTestHelpers::registerMockedURLLoad(toKURL(url), "div_with_image.html"); | 866 URLTestHelpers::registerMockedURLLoad(toKURL(url), "div_with_image.html"); |
| 857 URLTestHelpers::registerMockedURLLoad(toKURL("http://www.test.com/foo.png"), | 867 URLTestHelpers::registerMockedURLLoad(toKURL("http://www.test.com/foo.png"), |
| 858 "white-1x1.png"); | 868 "white-1x1.png"); |
| 859 WebView* webView = m_webViewHelper.initializeAndLoad(url); | 869 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url); |
| 860 webView->setInitialFocus(false); | 870 webViewImpl->setInitialFocus(false); |
| 861 WebTextInputInfo info = webView->textInputInfo(); | 871 WebTextInputInfo info = |
| 872 webViewImpl->mainFrameImpl()->inputMethodController()->textInputInfo(); |
| 862 | 873 |
| 863 EXPECT_EQ("foo\xef\xbf\xbc", info.value.utf8()); | 874 EXPECT_EQ("foo\xef\xbf\xbc", info.value.utf8()); |
| 864 } | 875 } |
| 865 | 876 |
| 866 TEST_P(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) { | 877 TEST_P(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) { |
| 867 URLTestHelpers::registerMockedURLFromBaseURL( | 878 URLTestHelpers::registerMockedURLFromBaseURL( |
| 868 WebString::fromUTF8(m_baseURL.c_str()), | 879 WebString::fromUTF8(m_baseURL.c_str()), |
| 869 WebString::fromUTF8("input_field_populated.html")); | 880 WebString::fromUTF8("input_field_populated.html")); |
| 870 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 881 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 871 m_baseURL + "input_field_populated.html"); | 882 m_baseURL + "input_field_populated.html"); |
| 872 webView->setInitialFocus(false); | 883 webView->setInitialFocus(false); |
| 873 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 884 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 885 WebInputMethodControllerImpl* activeInputMethodController = |
| 886 frame->inputMethodController(); |
| 874 frame->setEditableSelectionOffsets(5, 13); | 887 frame->setEditableSelectionOffsets(5, 13); |
| 875 EXPECT_EQ("56789abc", frame->selectionAsText()); | 888 EXPECT_EQ("56789abc", frame->selectionAsText()); |
| 876 WebTextInputInfo info = webView->textInputInfo(); | 889 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 877 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); | 890 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); |
| 878 EXPECT_EQ(5, info.selectionStart); | 891 EXPECT_EQ(5, info.selectionStart); |
| 879 EXPECT_EQ(13, info.selectionEnd); | 892 EXPECT_EQ(13, info.selectionEnd); |
| 880 EXPECT_EQ(-1, info.compositionStart); | 893 EXPECT_EQ(-1, info.compositionStart); |
| 881 EXPECT_EQ(-1, info.compositionEnd); | 894 EXPECT_EQ(-1, info.compositionEnd); |
| 882 | 895 |
| 883 URLTestHelpers::registerMockedURLFromBaseURL( | 896 URLTestHelpers::registerMockedURLFromBaseURL( |
| 884 WebString::fromUTF8(m_baseURL.c_str()), | 897 WebString::fromUTF8(m_baseURL.c_str()), |
| 885 WebString::fromUTF8("content_editable_populated.html")); | 898 WebString::fromUTF8("content_editable_populated.html")); |
| 886 webView = m_webViewHelper.initializeAndLoad( | 899 webView = m_webViewHelper.initializeAndLoad( |
| 887 m_baseURL + "content_editable_populated.html"); | 900 m_baseURL + "content_editable_populated.html"); |
| 888 webView->setInitialFocus(false); | 901 webView->setInitialFocus(false); |
| 889 frame = webView->mainFrameImpl(); | 902 frame = webView->mainFrameImpl(); |
| 890 frame->setEditableSelectionOffsets(8, 19); | 903 frame->setEditableSelectionOffsets(8, 19); |
| 891 EXPECT_EQ("89abcdefghi", frame->selectionAsText()); | 904 EXPECT_EQ("89abcdefghi", frame->selectionAsText()); |
| 892 info = webView->textInputInfo(); | 905 info = activeInputMethodController->textInputInfo(); |
| 893 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); | 906 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); |
| 894 EXPECT_EQ(8, info.selectionStart); | 907 EXPECT_EQ(8, info.selectionStart); |
| 895 EXPECT_EQ(19, info.selectionEnd); | 908 EXPECT_EQ(19, info.selectionEnd); |
| 896 EXPECT_EQ(-1, info.compositionStart); | 909 EXPECT_EQ(-1, info.compositionStart); |
| 897 EXPECT_EQ(-1, info.compositionEnd); | 910 EXPECT_EQ(-1, info.compositionEnd); |
| 898 } | 911 } |
| 899 | 912 |
| 900 // Regression test for crbug.com/663645 | 913 // Regression test for crbug.com/663645 |
| 901 TEST_P(WebViewTest, FinishComposingTextDoesNotAssert) { | 914 TEST_P(WebViewTest, FinishComposingTextDoesNotAssert) { |
| 902 URLTestHelpers::registerMockedURLFromBaseURL( | 915 URLTestHelpers::registerMockedURLFromBaseURL( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 std::string compositionText("hello"); | 954 std::string compositionText("hello"); |
| 942 | 955 |
| 943 WebInputMethodController* activeInputMethodController = | 956 WebInputMethodController* activeInputMethodController = |
| 944 webView->mainFrameImpl() | 957 webView->mainFrameImpl() |
| 945 ->frameWidget() | 958 ->frameWidget() |
| 946 ->getActiveWebInputMethodController(); | 959 ->getActiveWebInputMethodController(); |
| 947 WebVector<WebCompositionUnderline> emptyUnderlines; | 960 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 948 activeInputMethodController->setComposition( | 961 activeInputMethodController->setComposition( |
| 949 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); | 962 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); |
| 950 | 963 |
| 951 WebTextInputInfo info = webView->textInputInfo(); | 964 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 952 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 965 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 953 EXPECT_EQ(3, info.selectionStart); | 966 EXPECT_EQ(3, info.selectionStart); |
| 954 EXPECT_EQ(3, info.selectionEnd); | 967 EXPECT_EQ(3, info.selectionEnd); |
| 955 EXPECT_EQ(0, info.compositionStart); | 968 EXPECT_EQ(0, info.compositionStart); |
| 956 EXPECT_EQ(5, info.compositionEnd); | 969 EXPECT_EQ(5, info.compositionEnd); |
| 957 | 970 |
| 958 activeInputMethodController->finishComposingText( | 971 activeInputMethodController->finishComposingText( |
| 959 WebInputMethodController::KeepSelection); | 972 WebInputMethodController::KeepSelection); |
| 960 info = webView->textInputInfo(); | 973 info = activeInputMethodController->textInputInfo(); |
| 961 EXPECT_EQ(3, info.selectionStart); | 974 EXPECT_EQ(3, info.selectionStart); |
| 962 EXPECT_EQ(3, info.selectionEnd); | 975 EXPECT_EQ(3, info.selectionEnd); |
| 963 EXPECT_EQ(-1, info.compositionStart); | 976 EXPECT_EQ(-1, info.compositionStart); |
| 964 EXPECT_EQ(-1, info.compositionEnd); | 977 EXPECT_EQ(-1, info.compositionEnd); |
| 965 | 978 |
| 966 activeInputMethodController->setComposition( | 979 activeInputMethodController->setComposition( |
| 967 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); | 980 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); |
| 968 info = webView->textInputInfo(); | 981 info = activeInputMethodController->textInputInfo(); |
| 969 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data())); | 982 EXPECT_EQ("helhellolo", std::string(info.value.utf8().data())); |
| 970 EXPECT_EQ(6, info.selectionStart); | 983 EXPECT_EQ(6, info.selectionStart); |
| 971 EXPECT_EQ(6, info.selectionEnd); | 984 EXPECT_EQ(6, info.selectionEnd); |
| 972 EXPECT_EQ(3, info.compositionStart); | 985 EXPECT_EQ(3, info.compositionStart); |
| 973 EXPECT_EQ(8, info.compositionEnd); | 986 EXPECT_EQ(8, info.compositionEnd); |
| 974 | 987 |
| 975 activeInputMethodController->finishComposingText( | 988 activeInputMethodController->finishComposingText( |
| 976 WebInputMethodController::DoNotKeepSelection); | 989 WebInputMethodController::DoNotKeepSelection); |
| 977 info = webView->textInputInfo(); | 990 info = activeInputMethodController->textInputInfo(); |
| 978 EXPECT_EQ(8, info.selectionStart); | 991 EXPECT_EQ(8, info.selectionStart); |
| 979 EXPECT_EQ(8, info.selectionEnd); | 992 EXPECT_EQ(8, info.selectionEnd); |
| 980 EXPECT_EQ(-1, info.compositionStart); | 993 EXPECT_EQ(-1, info.compositionStart); |
| 981 EXPECT_EQ(-1, info.compositionEnd); | 994 EXPECT_EQ(-1, info.compositionEnd); |
| 982 } | 995 } |
| 983 | 996 |
| 984 TEST_P(WebViewTest, SetCompositionForNewCaretPositions) { | 997 TEST_P(WebViewTest, SetCompositionForNewCaretPositions) { |
| 985 URLTestHelpers::registerMockedURLFromBaseURL( | 998 URLTestHelpers::registerMockedURLFromBaseURL( |
| 986 WebString::fromUTF8(m_baseURL.c_str()), | 999 WebString::fromUTF8(m_baseURL.c_str()), |
| 987 WebString::fromUTF8("input_field_populated.html")); | 1000 WebString::fromUTF8("input_field_populated.html")); |
| 988 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1001 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 989 m_baseURL + "input_field_populated.html"); | 1002 m_baseURL + "input_field_populated.html"); |
| 990 webView->setInitialFocus(false); | 1003 webView->setInitialFocus(false); |
| 991 WebInputMethodController* activeInputMethodController = | 1004 WebInputMethodController* activeInputMethodController = |
| 992 webView->mainFrameImpl() | 1005 webView->mainFrameImpl() |
| 993 ->frameWidget() | 1006 ->frameWidget() |
| 994 ->getActiveWebInputMethodController(); | 1007 ->getActiveWebInputMethodController(); |
| 995 | 1008 |
| 996 activeInputMethodController->commitText("hello", 0); | 1009 activeInputMethodController->commitText("hello", 0); |
| 997 activeInputMethodController->commitText("world", -5); | 1010 activeInputMethodController->commitText("world", -5); |
| 998 WebTextInputInfo info = webView->textInputInfo(); | 1011 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 999 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); | 1012 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); |
| 1000 EXPECT_EQ(5, info.selectionStart); | 1013 EXPECT_EQ(5, info.selectionStart); |
| 1001 EXPECT_EQ(5, info.selectionEnd); | 1014 EXPECT_EQ(5, info.selectionEnd); |
| 1002 EXPECT_EQ(-1, info.compositionStart); | 1015 EXPECT_EQ(-1, info.compositionStart); |
| 1003 EXPECT_EQ(-1, info.compositionEnd); | 1016 EXPECT_EQ(-1, info.compositionEnd); |
| 1004 | 1017 |
| 1005 WebVector<WebCompositionUnderline> emptyUnderlines; | 1018 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1006 // Set up a composition that needs to be committed. | 1019 // Set up a composition that needs to be committed. |
| 1007 std::string compositionText("ABC"); | 1020 std::string compositionText("ABC"); |
| 1008 | 1021 |
| 1009 // Caret is on the left of composing text. | 1022 // Caret is on the left of composing text. |
| 1010 activeInputMethodController->setComposition( | 1023 activeInputMethodController->setComposition( |
| 1011 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, 0); | 1024 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, 0); |
| 1012 info = webView->textInputInfo(); | 1025 info = activeInputMethodController->textInputInfo(); |
| 1013 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1026 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1014 EXPECT_EQ(5, info.selectionStart); | 1027 EXPECT_EQ(5, info.selectionStart); |
| 1015 EXPECT_EQ(5, info.selectionEnd); | 1028 EXPECT_EQ(5, info.selectionEnd); |
| 1016 EXPECT_EQ(5, info.compositionStart); | 1029 EXPECT_EQ(5, info.compositionStart); |
| 1017 EXPECT_EQ(8, info.compositionEnd); | 1030 EXPECT_EQ(8, info.compositionEnd); |
| 1018 | 1031 |
| 1019 // Caret is on the right of composing text. | 1032 // Caret is on the right of composing text. |
| 1020 activeInputMethodController->setComposition( | 1033 activeInputMethodController->setComposition( |
| 1021 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); | 1034 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 3, 3); |
| 1022 info = webView->textInputInfo(); | 1035 info = activeInputMethodController->textInputInfo(); |
| 1023 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1036 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1024 EXPECT_EQ(8, info.selectionStart); | 1037 EXPECT_EQ(8, info.selectionStart); |
| 1025 EXPECT_EQ(8, info.selectionEnd); | 1038 EXPECT_EQ(8, info.selectionEnd); |
| 1026 EXPECT_EQ(5, info.compositionStart); | 1039 EXPECT_EQ(5, info.compositionStart); |
| 1027 EXPECT_EQ(8, info.compositionEnd); | 1040 EXPECT_EQ(8, info.compositionEnd); |
| 1028 | 1041 |
| 1029 // Caret is between composing text and left boundary. | 1042 // Caret is between composing text and left boundary. |
| 1030 activeInputMethodController->setComposition( | 1043 activeInputMethodController->setComposition( |
| 1031 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -2, -2); | 1044 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -2, -2); |
| 1032 info = webView->textInputInfo(); | 1045 info = activeInputMethodController->textInputInfo(); |
| 1033 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1046 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1034 EXPECT_EQ(3, info.selectionStart); | 1047 EXPECT_EQ(3, info.selectionStart); |
| 1035 EXPECT_EQ(3, info.selectionEnd); | 1048 EXPECT_EQ(3, info.selectionEnd); |
| 1036 EXPECT_EQ(5, info.compositionStart); | 1049 EXPECT_EQ(5, info.compositionStart); |
| 1037 EXPECT_EQ(8, info.compositionEnd); | 1050 EXPECT_EQ(8, info.compositionEnd); |
| 1038 | 1051 |
| 1039 // Caret is between composing text and right boundary. | 1052 // Caret is between composing text and right boundary. |
| 1040 activeInputMethodController->setComposition( | 1053 activeInputMethodController->setComposition( |
| 1041 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 5, 5); | 1054 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 5, 5); |
| 1042 info = webView->textInputInfo(); | 1055 info = activeInputMethodController->textInputInfo(); |
| 1043 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1056 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1044 EXPECT_EQ(10, info.selectionStart); | 1057 EXPECT_EQ(10, info.selectionStart); |
| 1045 EXPECT_EQ(10, info.selectionEnd); | 1058 EXPECT_EQ(10, info.selectionEnd); |
| 1046 EXPECT_EQ(5, info.compositionStart); | 1059 EXPECT_EQ(5, info.compositionStart); |
| 1047 EXPECT_EQ(8, info.compositionEnd); | 1060 EXPECT_EQ(8, info.compositionEnd); |
| 1048 | 1061 |
| 1049 // Caret is on the left boundary. | 1062 // Caret is on the left boundary. |
| 1050 activeInputMethodController->setComposition( | 1063 activeInputMethodController->setComposition( |
| 1051 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -5, -5); | 1064 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -5, -5); |
| 1052 info = webView->textInputInfo(); | 1065 info = activeInputMethodController->textInputInfo(); |
| 1053 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1066 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1054 EXPECT_EQ(0, info.selectionStart); | 1067 EXPECT_EQ(0, info.selectionStart); |
| 1055 EXPECT_EQ(0, info.selectionEnd); | 1068 EXPECT_EQ(0, info.selectionEnd); |
| 1056 EXPECT_EQ(5, info.compositionStart); | 1069 EXPECT_EQ(5, info.compositionStart); |
| 1057 EXPECT_EQ(8, info.compositionEnd); | 1070 EXPECT_EQ(8, info.compositionEnd); |
| 1058 | 1071 |
| 1059 // Caret is on the right boundary. | 1072 // Caret is on the right boundary. |
| 1060 activeInputMethodController->setComposition( | 1073 activeInputMethodController->setComposition( |
| 1061 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 8, 8); | 1074 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 8, 8); |
| 1062 info = webView->textInputInfo(); | 1075 info = activeInputMethodController->textInputInfo(); |
| 1063 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1076 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1064 EXPECT_EQ(13, info.selectionStart); | 1077 EXPECT_EQ(13, info.selectionStart); |
| 1065 EXPECT_EQ(13, info.selectionEnd); | 1078 EXPECT_EQ(13, info.selectionEnd); |
| 1066 EXPECT_EQ(5, info.compositionStart); | 1079 EXPECT_EQ(5, info.compositionStart); |
| 1067 EXPECT_EQ(8, info.compositionEnd); | 1080 EXPECT_EQ(8, info.compositionEnd); |
| 1068 | 1081 |
| 1069 // Caret exceeds the left boundary. | 1082 // Caret exceeds the left boundary. |
| 1070 activeInputMethodController->setComposition( | 1083 activeInputMethodController->setComposition( |
| 1071 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -100, | 1084 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, -100, |
| 1072 -100); | 1085 -100); |
| 1073 info = webView->textInputInfo(); | 1086 info = activeInputMethodController->textInputInfo(); |
| 1074 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1087 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1075 EXPECT_EQ(0, info.selectionStart); | 1088 EXPECT_EQ(0, info.selectionStart); |
| 1076 EXPECT_EQ(0, info.selectionEnd); | 1089 EXPECT_EQ(0, info.selectionEnd); |
| 1077 EXPECT_EQ(5, info.compositionStart); | 1090 EXPECT_EQ(5, info.compositionStart); |
| 1078 EXPECT_EQ(8, info.compositionEnd); | 1091 EXPECT_EQ(8, info.compositionEnd); |
| 1079 | 1092 |
| 1080 // Caret exceeds the right boundary. | 1093 // Caret exceeds the right boundary. |
| 1081 activeInputMethodController->setComposition( | 1094 activeInputMethodController->setComposition( |
| 1082 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 100, 100); | 1095 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 100, 100); |
| 1083 info = webView->textInputInfo(); | 1096 info = activeInputMethodController->textInputInfo(); |
| 1084 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); | 1097 EXPECT_EQ("helloABCworld", std::string(info.value.utf8().data())); |
| 1085 EXPECT_EQ(13, info.selectionStart); | 1098 EXPECT_EQ(13, info.selectionStart); |
| 1086 EXPECT_EQ(13, info.selectionEnd); | 1099 EXPECT_EQ(13, info.selectionEnd); |
| 1087 EXPECT_EQ(5, info.compositionStart); | 1100 EXPECT_EQ(5, info.compositionStart); |
| 1088 EXPECT_EQ(8, info.compositionEnd); | 1101 EXPECT_EQ(8, info.compositionEnd); |
| 1089 } | 1102 } |
| 1090 | 1103 |
| 1091 TEST_P(WebViewTest, SetCompositionWithEmptyText) { | 1104 TEST_P(WebViewTest, SetCompositionWithEmptyText) { |
| 1092 URLTestHelpers::registerMockedURLFromBaseURL( | 1105 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1093 WebString::fromUTF8(m_baseURL.c_str()), | 1106 WebString::fromUTF8(m_baseURL.c_str()), |
| 1094 WebString::fromUTF8("input_field_populated.html")); | 1107 WebString::fromUTF8("input_field_populated.html")); |
| 1095 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1108 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1096 m_baseURL + "input_field_populated.html"); | 1109 m_baseURL + "input_field_populated.html"); |
| 1097 webView->setInitialFocus(false); | 1110 webView->setInitialFocus(false); |
| 1098 WebInputMethodController* activeInputMethodController = | 1111 WebInputMethodController* activeInputMethodController = |
| 1099 webView->mainFrameImpl() | 1112 webView->mainFrameImpl() |
| 1100 ->frameWidget() | 1113 ->frameWidget() |
| 1101 ->getActiveWebInputMethodController(); | 1114 ->getActiveWebInputMethodController(); |
| 1102 | 1115 |
| 1103 activeInputMethodController->commitText("hello", 0); | 1116 activeInputMethodController->commitText("hello", 0); |
| 1104 WebTextInputInfo info = webView->textInputInfo(); | 1117 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1105 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1118 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1106 EXPECT_EQ(5, info.selectionStart); | 1119 EXPECT_EQ(5, info.selectionStart); |
| 1107 EXPECT_EQ(5, info.selectionEnd); | 1120 EXPECT_EQ(5, info.selectionEnd); |
| 1108 EXPECT_EQ(-1, info.compositionStart); | 1121 EXPECT_EQ(-1, info.compositionStart); |
| 1109 EXPECT_EQ(-1, info.compositionEnd); | 1122 EXPECT_EQ(-1, info.compositionEnd); |
| 1110 | 1123 |
| 1111 WebVector<WebCompositionUnderline> emptyUnderlines; | 1124 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1112 | 1125 |
| 1113 activeInputMethodController->setComposition(WebString::fromUTF8(""), | 1126 activeInputMethodController->setComposition(WebString::fromUTF8(""), |
| 1114 emptyUnderlines, 0, 0); | 1127 emptyUnderlines, 0, 0); |
| 1115 info = webView->textInputInfo(); | 1128 info = activeInputMethodController->textInputInfo(); |
| 1116 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1129 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1117 EXPECT_EQ(5, info.selectionStart); | 1130 EXPECT_EQ(5, info.selectionStart); |
| 1118 EXPECT_EQ(5, info.selectionEnd); | 1131 EXPECT_EQ(5, info.selectionEnd); |
| 1119 EXPECT_EQ(-1, info.compositionStart); | 1132 EXPECT_EQ(-1, info.compositionStart); |
| 1120 EXPECT_EQ(-1, info.compositionEnd); | 1133 EXPECT_EQ(-1, info.compositionEnd); |
| 1121 | 1134 |
| 1122 activeInputMethodController->setComposition(WebString::fromUTF8(""), | 1135 activeInputMethodController->setComposition(WebString::fromUTF8(""), |
| 1123 emptyUnderlines, -2, -2); | 1136 emptyUnderlines, -2, -2); |
| 1124 info = webView->textInputInfo(); | 1137 info = activeInputMethodController->textInputInfo(); |
| 1125 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1138 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1126 EXPECT_EQ(3, info.selectionStart); | 1139 EXPECT_EQ(3, info.selectionStart); |
| 1127 EXPECT_EQ(3, info.selectionEnd); | 1140 EXPECT_EQ(3, info.selectionEnd); |
| 1128 EXPECT_EQ(-1, info.compositionStart); | 1141 EXPECT_EQ(-1, info.compositionStart); |
| 1129 EXPECT_EQ(-1, info.compositionEnd); | 1142 EXPECT_EQ(-1, info.compositionEnd); |
| 1130 } | 1143 } |
| 1131 | 1144 |
| 1132 TEST_P(WebViewTest, CommitTextForNewCaretPositions) { | 1145 TEST_P(WebViewTest, CommitTextForNewCaretPositions) { |
| 1133 URLTestHelpers::registerMockedURLFromBaseURL( | 1146 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1134 WebString::fromUTF8(m_baseURL.c_str()), | 1147 WebString::fromUTF8(m_baseURL.c_str()), |
| 1135 WebString::fromUTF8("input_field_populated.html")); | 1148 WebString::fromUTF8("input_field_populated.html")); |
| 1136 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1149 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1137 m_baseURL + "input_field_populated.html"); | 1150 m_baseURL + "input_field_populated.html"); |
| 1138 webView->setInitialFocus(false); | 1151 webView->setInitialFocus(false); |
| 1139 WebInputMethodController* activeInputMethodController = | 1152 WebInputMethodController* activeInputMethodController = |
| 1140 webView->mainFrameImpl() | 1153 webView->mainFrameImpl() |
| 1141 ->frameWidget() | 1154 ->frameWidget() |
| 1142 ->getActiveWebInputMethodController(); | 1155 ->getActiveWebInputMethodController(); |
| 1143 | 1156 |
| 1144 // Caret is on the left of composing text. | 1157 // Caret is on the left of composing text. |
| 1145 activeInputMethodController->commitText("ab", -2); | 1158 activeInputMethodController->commitText("ab", -2); |
| 1146 WebTextInputInfo info = webView->textInputInfo(); | 1159 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1147 EXPECT_EQ("ab", std::string(info.value.utf8().data())); | 1160 EXPECT_EQ("ab", std::string(info.value.utf8().data())); |
| 1148 EXPECT_EQ(0, info.selectionStart); | 1161 EXPECT_EQ(0, info.selectionStart); |
| 1149 EXPECT_EQ(0, info.selectionEnd); | 1162 EXPECT_EQ(0, info.selectionEnd); |
| 1150 EXPECT_EQ(-1, info.compositionStart); | 1163 EXPECT_EQ(-1, info.compositionStart); |
| 1151 EXPECT_EQ(-1, info.compositionEnd); | 1164 EXPECT_EQ(-1, info.compositionEnd); |
| 1152 | 1165 |
| 1153 // Caret is on the right of composing text. | 1166 // Caret is on the right of composing text. |
| 1154 activeInputMethodController->commitText("c", 1); | 1167 activeInputMethodController->commitText("c", 1); |
| 1155 info = webView->textInputInfo(); | 1168 info = activeInputMethodController->textInputInfo(); |
| 1156 EXPECT_EQ("cab", std::string(info.value.utf8().data())); | 1169 EXPECT_EQ("cab", std::string(info.value.utf8().data())); |
| 1157 EXPECT_EQ(2, info.selectionStart); | 1170 EXPECT_EQ(2, info.selectionStart); |
| 1158 EXPECT_EQ(2, info.selectionEnd); | 1171 EXPECT_EQ(2, info.selectionEnd); |
| 1159 EXPECT_EQ(-1, info.compositionStart); | 1172 EXPECT_EQ(-1, info.compositionStart); |
| 1160 EXPECT_EQ(-1, info.compositionEnd); | 1173 EXPECT_EQ(-1, info.compositionEnd); |
| 1161 | 1174 |
| 1162 // Caret is on the left boundary. | 1175 // Caret is on the left boundary. |
| 1163 activeInputMethodController->commitText("def", -5); | 1176 activeInputMethodController->commitText("def", -5); |
| 1164 info = webView->textInputInfo(); | 1177 info = activeInputMethodController->textInputInfo(); |
| 1165 EXPECT_EQ("cadefb", std::string(info.value.utf8().data())); | 1178 EXPECT_EQ("cadefb", std::string(info.value.utf8().data())); |
| 1166 EXPECT_EQ(0, info.selectionStart); | 1179 EXPECT_EQ(0, info.selectionStart); |
| 1167 EXPECT_EQ(0, info.selectionEnd); | 1180 EXPECT_EQ(0, info.selectionEnd); |
| 1168 EXPECT_EQ(-1, info.compositionStart); | 1181 EXPECT_EQ(-1, info.compositionStart); |
| 1169 EXPECT_EQ(-1, info.compositionEnd); | 1182 EXPECT_EQ(-1, info.compositionEnd); |
| 1170 | 1183 |
| 1171 // Caret is on the right boundary. | 1184 // Caret is on the right boundary. |
| 1172 activeInputMethodController->commitText("g", 6); | 1185 activeInputMethodController->commitText("g", 6); |
| 1173 info = webView->textInputInfo(); | 1186 info = activeInputMethodController->textInputInfo(); |
| 1174 EXPECT_EQ("gcadefb", std::string(info.value.utf8().data())); | 1187 EXPECT_EQ("gcadefb", std::string(info.value.utf8().data())); |
| 1175 EXPECT_EQ(7, info.selectionStart); | 1188 EXPECT_EQ(7, info.selectionStart); |
| 1176 EXPECT_EQ(7, info.selectionEnd); | 1189 EXPECT_EQ(7, info.selectionEnd); |
| 1177 EXPECT_EQ(-1, info.compositionStart); | 1190 EXPECT_EQ(-1, info.compositionStart); |
| 1178 EXPECT_EQ(-1, info.compositionEnd); | 1191 EXPECT_EQ(-1, info.compositionEnd); |
| 1179 | 1192 |
| 1180 // Caret exceeds the left boundary. | 1193 // Caret exceeds the left boundary. |
| 1181 activeInputMethodController->commitText("hi", -100); | 1194 activeInputMethodController->commitText("hi", -100); |
| 1182 info = webView->textInputInfo(); | 1195 info = activeInputMethodController->textInputInfo(); |
| 1183 EXPECT_EQ("gcadefbhi", std::string(info.value.utf8().data())); | 1196 EXPECT_EQ("gcadefbhi", std::string(info.value.utf8().data())); |
| 1184 EXPECT_EQ(0, info.selectionStart); | 1197 EXPECT_EQ(0, info.selectionStart); |
| 1185 EXPECT_EQ(0, info.selectionEnd); | 1198 EXPECT_EQ(0, info.selectionEnd); |
| 1186 EXPECT_EQ(-1, info.compositionStart); | 1199 EXPECT_EQ(-1, info.compositionStart); |
| 1187 EXPECT_EQ(-1, info.compositionEnd); | 1200 EXPECT_EQ(-1, info.compositionEnd); |
| 1188 | 1201 |
| 1189 // Caret exceeds the right boundary. | 1202 // Caret exceeds the right boundary. |
| 1190 activeInputMethodController->commitText("jk", 100); | 1203 activeInputMethodController->commitText("jk", 100); |
| 1191 info = webView->textInputInfo(); | 1204 info = activeInputMethodController->textInputInfo(); |
| 1192 EXPECT_EQ("jkgcadefbhi", std::string(info.value.utf8().data())); | 1205 EXPECT_EQ("jkgcadefbhi", std::string(info.value.utf8().data())); |
| 1193 EXPECT_EQ(11, info.selectionStart); | 1206 EXPECT_EQ(11, info.selectionStart); |
| 1194 EXPECT_EQ(11, info.selectionEnd); | 1207 EXPECT_EQ(11, info.selectionEnd); |
| 1195 EXPECT_EQ(-1, info.compositionStart); | 1208 EXPECT_EQ(-1, info.compositionStart); |
| 1196 EXPECT_EQ(-1, info.compositionEnd); | 1209 EXPECT_EQ(-1, info.compositionEnd); |
| 1197 } | 1210 } |
| 1198 | 1211 |
| 1199 TEST_P(WebViewTest, CommitTextWhileComposing) { | 1212 TEST_P(WebViewTest, CommitTextWhileComposing) { |
| 1200 URLTestHelpers::registerMockedURLFromBaseURL( | 1213 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1201 WebString::fromUTF8(m_baseURL.c_str()), | 1214 WebString::fromUTF8(m_baseURL.c_str()), |
| 1202 WebString::fromUTF8("input_field_populated.html")); | 1215 WebString::fromUTF8("input_field_populated.html")); |
| 1203 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1216 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1204 m_baseURL + "input_field_populated.html"); | 1217 m_baseURL + "input_field_populated.html"); |
| 1205 webView->setInitialFocus(false); | 1218 webView->setInitialFocus(false); |
| 1206 WebInputMethodController* activeInputMethodController = | 1219 WebInputMethodController* activeInputMethodController = |
| 1207 webView->mainFrameImpl() | 1220 webView->mainFrameImpl() |
| 1208 ->frameWidget() | 1221 ->frameWidget() |
| 1209 ->getActiveWebInputMethodController(); | 1222 ->getActiveWebInputMethodController(); |
| 1210 | 1223 |
| 1211 WebVector<WebCompositionUnderline> emptyUnderlines; | 1224 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1212 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), | 1225 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), |
| 1213 emptyUnderlines, 0, 0); | 1226 emptyUnderlines, 0, 0); |
| 1214 WebTextInputInfo info = webView->textInputInfo(); | 1227 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1215 EXPECT_EQ("abc", std::string(info.value.utf8().data())); | 1228 EXPECT_EQ("abc", std::string(info.value.utf8().data())); |
| 1216 EXPECT_EQ(0, info.selectionStart); | 1229 EXPECT_EQ(0, info.selectionStart); |
| 1217 EXPECT_EQ(0, info.selectionEnd); | 1230 EXPECT_EQ(0, info.selectionEnd); |
| 1218 EXPECT_EQ(0, info.compositionStart); | 1231 EXPECT_EQ(0, info.compositionStart); |
| 1219 EXPECT_EQ(3, info.compositionEnd); | 1232 EXPECT_EQ(3, info.compositionEnd); |
| 1220 | 1233 |
| 1221 // Deletes ongoing composition, inserts the specified text and moves the | 1234 // Deletes ongoing composition, inserts the specified text and moves the |
| 1222 // caret. | 1235 // caret. |
| 1223 activeInputMethodController->commitText("hello", -2); | 1236 activeInputMethodController->commitText("hello", -2); |
| 1224 info = webView->textInputInfo(); | 1237 info = activeInputMethodController->textInputInfo(); |
| 1225 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1238 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1226 EXPECT_EQ(3, info.selectionStart); | 1239 EXPECT_EQ(3, info.selectionStart); |
| 1227 EXPECT_EQ(3, info.selectionEnd); | 1240 EXPECT_EQ(3, info.selectionEnd); |
| 1228 EXPECT_EQ(-1, info.compositionStart); | 1241 EXPECT_EQ(-1, info.compositionStart); |
| 1229 EXPECT_EQ(-1, info.compositionEnd); | 1242 EXPECT_EQ(-1, info.compositionEnd); |
| 1230 | 1243 |
| 1231 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), | 1244 activeInputMethodController->setComposition(WebString::fromUTF8("abc"), |
| 1232 emptyUnderlines, 0, 0); | 1245 emptyUnderlines, 0, 0); |
| 1233 info = webView->textInputInfo(); | 1246 info = activeInputMethodController->textInputInfo(); |
| 1234 EXPECT_EQ("helabclo", std::string(info.value.utf8().data())); | 1247 EXPECT_EQ("helabclo", std::string(info.value.utf8().data())); |
| 1235 EXPECT_EQ(3, info.selectionStart); | 1248 EXPECT_EQ(3, info.selectionStart); |
| 1236 EXPECT_EQ(3, info.selectionEnd); | 1249 EXPECT_EQ(3, info.selectionEnd); |
| 1237 EXPECT_EQ(3, info.compositionStart); | 1250 EXPECT_EQ(3, info.compositionStart); |
| 1238 EXPECT_EQ(6, info.compositionEnd); | 1251 EXPECT_EQ(6, info.compositionEnd); |
| 1239 | 1252 |
| 1240 // Deletes ongoing composition and moves the caret. | 1253 // Deletes ongoing composition and moves the caret. |
| 1241 activeInputMethodController->commitText("", 2); | 1254 activeInputMethodController->commitText("", 2); |
| 1242 info = webView->textInputInfo(); | 1255 info = activeInputMethodController->textInputInfo(); |
| 1243 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1256 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1244 EXPECT_EQ(5, info.selectionStart); | 1257 EXPECT_EQ(5, info.selectionStart); |
| 1245 EXPECT_EQ(5, info.selectionEnd); | 1258 EXPECT_EQ(5, info.selectionEnd); |
| 1246 EXPECT_EQ(-1, info.compositionStart); | 1259 EXPECT_EQ(-1, info.compositionStart); |
| 1247 EXPECT_EQ(-1, info.compositionEnd); | 1260 EXPECT_EQ(-1, info.compositionEnd); |
| 1248 | 1261 |
| 1249 // Inserts the specified text and moves the caret. | 1262 // Inserts the specified text and moves the caret. |
| 1250 activeInputMethodController->commitText("world", -5); | 1263 activeInputMethodController->commitText("world", -5); |
| 1251 info = webView->textInputInfo(); | 1264 info = activeInputMethodController->textInputInfo(); |
| 1252 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); | 1265 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); |
| 1253 EXPECT_EQ(5, info.selectionStart); | 1266 EXPECT_EQ(5, info.selectionStart); |
| 1254 EXPECT_EQ(5, info.selectionEnd); | 1267 EXPECT_EQ(5, info.selectionEnd); |
| 1255 EXPECT_EQ(-1, info.compositionStart); | 1268 EXPECT_EQ(-1, info.compositionStart); |
| 1256 EXPECT_EQ(-1, info.compositionEnd); | 1269 EXPECT_EQ(-1, info.compositionEnd); |
| 1257 | 1270 |
| 1258 // Only moves the caret. | 1271 // Only moves the caret. |
| 1259 activeInputMethodController->commitText("", 5); | 1272 activeInputMethodController->commitText("", 5); |
| 1260 info = webView->textInputInfo(); | 1273 info = activeInputMethodController->textInputInfo(); |
| 1261 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); | 1274 EXPECT_EQ("helloworld", std::string(info.value.utf8().data())); |
| 1262 EXPECT_EQ(10, info.selectionStart); | 1275 EXPECT_EQ(10, info.selectionStart); |
| 1263 EXPECT_EQ(10, info.selectionEnd); | 1276 EXPECT_EQ(10, info.selectionEnd); |
| 1264 EXPECT_EQ(-1, info.compositionStart); | 1277 EXPECT_EQ(-1, info.compositionStart); |
| 1265 EXPECT_EQ(-1, info.compositionEnd); | 1278 EXPECT_EQ(-1, info.compositionEnd); |
| 1266 } | 1279 } |
| 1267 | 1280 |
| 1268 TEST_P(WebViewTest, FinishCompositionDoesNotRevealSelection) { | 1281 TEST_P(WebViewTest, FinishCompositionDoesNotRevealSelection) { |
| 1269 URLTestHelpers::registerMockedURLFromBaseURL( | 1282 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1270 WebString::fromUTF8(m_baseURL.c_str()), | 1283 WebString::fromUTF8(m_baseURL.c_str()), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1283 emptyUnderlines, 3, 3); | 1296 emptyUnderlines, 3, 3); |
| 1284 | 1297 |
| 1285 // Scroll the input field out of the viewport. | 1298 // Scroll the input field out of the viewport. |
| 1286 Element* element = static_cast<Element*>( | 1299 Element* element = static_cast<Element*>( |
| 1287 webView->mainFrame()->document().getElementById("btn")); | 1300 webView->mainFrame()->document().getElementById("btn")); |
| 1288 element->scrollIntoView(); | 1301 element->scrollIntoView(); |
| 1289 float offsetHeight = webView->mainFrame()->scrollOffset().height; | 1302 float offsetHeight = webView->mainFrame()->scrollOffset().height; |
| 1290 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); | 1303 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); |
| 1291 EXPECT_LT(0, offsetHeight); | 1304 EXPECT_LT(0, offsetHeight); |
| 1292 | 1305 |
| 1293 WebTextInputInfo info = webView->textInputInfo(); | 1306 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); |
| 1294 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 1307 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 1295 | 1308 |
| 1296 // Verify that the input field is not scrolled back into the viewport. | 1309 // Verify that the input field is not scrolled back into the viewport. |
| 1297 frame->frameWidget() | 1310 frame->frameWidget() |
| 1298 ->getActiveWebInputMethodController() | 1311 ->getActiveWebInputMethodController() |
| 1299 ->finishComposingText(WebInputMethodController::DoNotKeepSelection); | 1312 ->finishComposingText(WebInputMethodController::DoNotKeepSelection); |
| 1300 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); | 1313 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); |
| 1301 EXPECT_EQ(offsetHeight, webView->mainFrame()->scrollOffset().height); | 1314 EXPECT_EQ(offsetHeight, webView->mainFrame()->scrollOffset().height); |
| 1302 } | 1315 } |
| 1303 | 1316 |
| 1304 TEST_P(WebViewTest, InsertNewLinePlacementAfterFinishComposingText) { | 1317 TEST_P(WebViewTest, InsertNewLinePlacementAfterFinishComposingText) { |
| 1305 URLTestHelpers::registerMockedURLFromBaseURL( | 1318 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1306 WebString::fromUTF8(m_baseURL.c_str()), | 1319 WebString::fromUTF8(m_baseURL.c_str()), |
| 1307 WebString::fromUTF8("text_area_populated.html")); | 1320 WebString::fromUTF8("text_area_populated.html")); |
| 1308 WebViewImpl* webView = | 1321 WebViewImpl* webView = |
| 1309 m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_populated.html"); | 1322 m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_populated.html"); |
| 1310 webView->setInitialFocus(false); | 1323 webView->setInitialFocus(false); |
| 1311 | 1324 |
| 1312 WebVector<WebCompositionUnderline> emptyUnderlines; | 1325 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1313 | 1326 |
| 1314 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1327 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 1328 WebInputMethodController* activeInputMethodController = |
| 1329 frame->inputMethodController(); |
| 1315 frame->setEditableSelectionOffsets(4, 4); | 1330 frame->setEditableSelectionOffsets(4, 4); |
| 1316 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 1331 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 1317 | 1332 |
| 1318 WebTextInputInfo info = webView->textInputInfo(); | 1333 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1319 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", | 1334 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", |
| 1320 std::string(info.value.utf8().data())); | 1335 std::string(info.value.utf8().data())); |
| 1321 EXPECT_EQ(4, info.selectionStart); | 1336 EXPECT_EQ(4, info.selectionStart); |
| 1322 EXPECT_EQ(4, info.selectionEnd); | 1337 EXPECT_EQ(4, info.selectionEnd); |
| 1323 EXPECT_EQ(8, info.compositionStart); | 1338 EXPECT_EQ(8, info.compositionStart); |
| 1324 EXPECT_EQ(12, info.compositionEnd); | 1339 EXPECT_EQ(12, info.compositionEnd); |
| 1325 | 1340 |
| 1326 WebInputMethodController* activeInputMethodController = | |
| 1327 frame->frameWidget()->getActiveWebInputMethodController(); | |
| 1328 activeInputMethodController->finishComposingText( | 1341 activeInputMethodController->finishComposingText( |
| 1329 WebInputMethodController::KeepSelection); | 1342 WebInputMethodController::KeepSelection); |
| 1330 info = webView->textInputInfo(); | 1343 info = activeInputMethodController->textInputInfo(); |
| 1331 EXPECT_EQ(4, info.selectionStart); | 1344 EXPECT_EQ(4, info.selectionStart); |
| 1332 EXPECT_EQ(4, info.selectionEnd); | 1345 EXPECT_EQ(4, info.selectionEnd); |
| 1333 EXPECT_EQ(-1, info.compositionStart); | 1346 EXPECT_EQ(-1, info.compositionStart); |
| 1334 EXPECT_EQ(-1, info.compositionEnd); | 1347 EXPECT_EQ(-1, info.compositionEnd); |
| 1335 | 1348 |
| 1336 std::string compositionText("\n"); | 1349 std::string compositionText("\n"); |
| 1337 activeInputMethodController->commitText( | 1350 activeInputMethodController->commitText( |
| 1338 WebString::fromUTF8(compositionText.c_str()), 0); | 1351 WebString::fromUTF8(compositionText.c_str()), 0); |
| 1339 info = webView->textInputInfo(); | 1352 info = activeInputMethodController->textInputInfo(); |
| 1340 EXPECT_EQ(5, info.selectionStart); | 1353 EXPECT_EQ(5, info.selectionStart); |
| 1341 EXPECT_EQ(5, info.selectionEnd); | 1354 EXPECT_EQ(5, info.selectionEnd); |
| 1342 EXPECT_EQ(-1, info.compositionStart); | 1355 EXPECT_EQ(-1, info.compositionStart); |
| 1343 EXPECT_EQ(-1, info.compositionEnd); | 1356 EXPECT_EQ(-1, info.compositionEnd); |
| 1344 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", | 1357 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", |
| 1345 std::string(info.value.utf8().data())); | 1358 std::string(info.value.utf8().data())); |
| 1346 } | 1359 } |
| 1347 | 1360 |
| 1348 TEST_P(WebViewTest, ExtendSelectionAndDelete) { | 1361 TEST_P(WebViewTest, ExtendSelectionAndDelete) { |
| 1349 URLTestHelpers::registerMockedURLFromBaseURL( | 1362 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1350 WebString::fromUTF8(m_baseURL.c_str()), | 1363 WebString::fromUTF8(m_baseURL.c_str()), |
| 1351 WebString::fromUTF8("input_field_populated.html")); | 1364 WebString::fromUTF8("input_field_populated.html")); |
| 1352 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1365 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1353 m_baseURL + "input_field_populated.html"); | 1366 m_baseURL + "input_field_populated.html"); |
| 1354 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1367 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 1355 webView->setInitialFocus(false); | 1368 webView->setInitialFocus(false); |
| 1356 frame->setEditableSelectionOffsets(10, 10); | 1369 frame->setEditableSelectionOffsets(10, 10); |
| 1357 frame->extendSelectionAndDelete(5, 8); | 1370 frame->extendSelectionAndDelete(5, 8); |
| 1358 WebTextInputInfo info = webView->textInputInfo(); | 1371 WebInputMethodController* activeInputMethodController = |
| 1372 frame->inputMethodController(); |
| 1373 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1359 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 1374 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
| 1360 EXPECT_EQ(5, info.selectionStart); | 1375 EXPECT_EQ(5, info.selectionStart); |
| 1361 EXPECT_EQ(5, info.selectionEnd); | 1376 EXPECT_EQ(5, info.selectionEnd); |
| 1362 frame->extendSelectionAndDelete(10, 0); | 1377 frame->extendSelectionAndDelete(10, 0); |
| 1363 info = webView->textInputInfo(); | 1378 info = activeInputMethodController->textInputInfo(); |
| 1364 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 1379 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
| 1365 } | 1380 } |
| 1366 | 1381 |
| 1367 TEST_P(WebViewTest, DeleteSurroundingText) { | 1382 TEST_P(WebViewTest, DeleteSurroundingText) { |
| 1368 URLTestHelpers::registerMockedURLFromBaseURL( | 1383 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1369 WebString::fromUTF8(m_baseURL.c_str()), | 1384 WebString::fromUTF8(m_baseURL.c_str()), |
| 1370 WebString::fromUTF8("input_field_populated.html")); | 1385 WebString::fromUTF8("input_field_populated.html")); |
| 1371 WebView* webView = m_webViewHelper.initializeAndLoad( | 1386 WebView* webView = m_webViewHelper.initializeAndLoad( |
| 1372 m_baseURL + "input_field_populated.html"); | 1387 m_baseURL + "input_field_populated.html"); |
| 1373 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 1388 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 1389 WebInputMethodController* activeInputMethodController = |
| 1390 frame->inputMethodController(); |
| 1374 webView->setInitialFocus(false); | 1391 webView->setInitialFocus(false); |
| 1375 | 1392 |
| 1376 frame->setEditableSelectionOffsets(10, 10); | 1393 frame->setEditableSelectionOffsets(10, 10); |
| 1377 frame->deleteSurroundingText(5, 8); | 1394 frame->deleteSurroundingText(5, 8); |
| 1378 WebTextInputInfo info = webView->textInputInfo(); | 1395 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1379 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 1396 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
| 1380 EXPECT_EQ(5, info.selectionStart); | 1397 EXPECT_EQ(5, info.selectionStart); |
| 1381 EXPECT_EQ(5, info.selectionEnd); | 1398 EXPECT_EQ(5, info.selectionEnd); |
| 1382 | 1399 |
| 1383 frame->setEditableSelectionOffsets(5, 10); | 1400 frame->setEditableSelectionOffsets(5, 10); |
| 1384 frame->deleteSurroundingText(3, 5); | 1401 frame->deleteSurroundingText(3, 5); |
| 1385 info = webView->textInputInfo(); | 1402 info = activeInputMethodController->textInputInfo(); |
| 1386 EXPECT_EQ("01ijklmstuvwxyz", std::string(info.value.utf8().data())); | 1403 EXPECT_EQ("01ijklmstuvwxyz", std::string(info.value.utf8().data())); |
| 1387 EXPECT_EQ(2, info.selectionStart); | 1404 EXPECT_EQ(2, info.selectionStart); |
| 1388 EXPECT_EQ(7, info.selectionEnd); | 1405 EXPECT_EQ(7, info.selectionEnd); |
| 1389 | 1406 |
| 1390 frame->setEditableSelectionOffsets(5, 5); | 1407 frame->setEditableSelectionOffsets(5, 5); |
| 1391 frame->deleteSurroundingText(10, 0); | 1408 frame->deleteSurroundingText(10, 0); |
| 1392 info = webView->textInputInfo(); | 1409 info = activeInputMethodController->textInputInfo(); |
| 1393 EXPECT_EQ("lmstuvwxyz", std::string(info.value.utf8().data())); | 1410 EXPECT_EQ("lmstuvwxyz", std::string(info.value.utf8().data())); |
| 1394 EXPECT_EQ(0, info.selectionStart); | 1411 EXPECT_EQ(0, info.selectionStart); |
| 1395 EXPECT_EQ(0, info.selectionEnd); | 1412 EXPECT_EQ(0, info.selectionEnd); |
| 1396 | 1413 |
| 1397 frame->deleteSurroundingText(0, 20); | 1414 frame->deleteSurroundingText(0, 20); |
| 1398 info = webView->textInputInfo(); | 1415 info = activeInputMethodController->textInputInfo(); |
| 1399 EXPECT_EQ("", std::string(info.value.utf8().data())); | 1416 EXPECT_EQ("", std::string(info.value.utf8().data())); |
| 1400 EXPECT_EQ(0, info.selectionStart); | 1417 EXPECT_EQ(0, info.selectionStart); |
| 1401 EXPECT_EQ(0, info.selectionEnd); | 1418 EXPECT_EQ(0, info.selectionEnd); |
| 1402 | 1419 |
| 1403 frame->deleteSurroundingText(10, 10); | 1420 frame->deleteSurroundingText(10, 10); |
| 1404 info = webView->textInputInfo(); | 1421 info = activeInputMethodController->textInputInfo(); |
| 1405 EXPECT_EQ("", std::string(info.value.utf8().data())); | 1422 EXPECT_EQ("", std::string(info.value.utf8().data())); |
| 1406 EXPECT_EQ(0, info.selectionStart); | 1423 EXPECT_EQ(0, info.selectionStart); |
| 1407 EXPECT_EQ(0, info.selectionEnd); | 1424 EXPECT_EQ(0, info.selectionEnd); |
| 1408 } | 1425 } |
| 1409 | 1426 |
| 1410 TEST_P(WebViewTest, SetCompositionFromExistingText) { | 1427 TEST_P(WebViewTest, SetCompositionFromExistingText) { |
| 1411 URLTestHelpers::registerMockedURLFromBaseURL( | 1428 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1412 WebString::fromUTF8(m_baseURL.c_str()), | 1429 WebString::fromUTF8(m_baseURL.c_str()), |
| 1413 WebString::fromUTF8("input_field_populated.html")); | 1430 WebString::fromUTF8("input_field_populated.html")); |
| 1414 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 1431 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 1415 m_baseURL + "input_field_populated.html"); | 1432 m_baseURL + "input_field_populated.html"); |
| 1416 webView->setInitialFocus(false); | 1433 webView->setInitialFocus(false); |
| 1417 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 1434 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
| 1418 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 1435 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
| 1419 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1436 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 1437 WebInputMethodController* activeInputMethodController = |
| 1438 frame->inputMethodController(); |
| 1420 frame->setEditableSelectionOffsets(4, 10); | 1439 frame->setEditableSelectionOffsets(4, 10); |
| 1421 frame->setCompositionFromExistingText(8, 12, underlines); | 1440 frame->setCompositionFromExistingText(8, 12, underlines); |
| 1422 WebTextInputInfo info = webView->textInputInfo(); | 1441 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1423 EXPECT_EQ(4, info.selectionStart); | 1442 EXPECT_EQ(4, info.selectionStart); |
| 1424 EXPECT_EQ(10, info.selectionEnd); | 1443 EXPECT_EQ(10, info.selectionEnd); |
| 1425 EXPECT_EQ(8, info.compositionStart); | 1444 EXPECT_EQ(8, info.compositionStart); |
| 1426 EXPECT_EQ(12, info.compositionEnd); | 1445 EXPECT_EQ(12, info.compositionEnd); |
| 1427 WebVector<WebCompositionUnderline> emptyUnderlines; | 1446 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1428 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); | 1447 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); |
| 1429 info = webView->textInputInfo(); | 1448 info = activeInputMethodController->textInputInfo(); |
| 1430 EXPECT_EQ(4, info.selectionStart); | 1449 EXPECT_EQ(4, info.selectionStart); |
| 1431 EXPECT_EQ(10, info.selectionEnd); | 1450 EXPECT_EQ(10, info.selectionEnd); |
| 1432 EXPECT_EQ(-1, info.compositionStart); | 1451 EXPECT_EQ(-1, info.compositionStart); |
| 1433 EXPECT_EQ(-1, info.compositionEnd); | 1452 EXPECT_EQ(-1, info.compositionEnd); |
| 1434 } | 1453 } |
| 1435 | 1454 |
| 1436 TEST_P(WebViewTest, SetCompositionFromExistingTextInTextArea) { | 1455 TEST_P(WebViewTest, SetCompositionFromExistingTextInTextArea) { |
| 1437 URLTestHelpers::registerMockedURLFromBaseURL( | 1456 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1438 WebString::fromUTF8(m_baseURL.c_str()), | 1457 WebString::fromUTF8(m_baseURL.c_str()), |
| 1439 WebString::fromUTF8("text_area_populated.html")); | 1458 WebString::fromUTF8("text_area_populated.html")); |
| 1440 WebViewImpl* webView = | 1459 WebViewImpl* webView = |
| 1441 m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_populated.html"); | 1460 m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_populated.html"); |
| 1442 webView->setInitialFocus(false); | 1461 webView->setInitialFocus(false); |
| 1443 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 1462 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
| 1444 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 1463 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
| 1445 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1464 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 1446 WebInputMethodController* activeInputMethodController = | 1465 WebInputMethodController* activeInputMethodController = |
| 1447 frame->frameWidget()->getActiveWebInputMethodController(); | 1466 frame->frameWidget()->getActiveWebInputMethodController(); |
| 1448 frame->setEditableSelectionOffsets(27, 27); | 1467 frame->setEditableSelectionOffsets(27, 27); |
| 1449 std::string newLineText("\n"); | 1468 std::string newLineText("\n"); |
| 1450 activeInputMethodController->commitText( | 1469 activeInputMethodController->commitText( |
| 1451 WebString::fromUTF8(newLineText.c_str()), 0); | 1470 WebString::fromUTF8(newLineText.c_str()), 0); |
| 1452 WebTextInputInfo info = webView->textInputInfo(); | 1471 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1453 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", | 1472 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", |
| 1454 std::string(info.value.utf8().data())); | 1473 std::string(info.value.utf8().data())); |
| 1455 | 1474 |
| 1456 frame->setEditableSelectionOffsets(31, 31); | 1475 frame->setEditableSelectionOffsets(31, 31); |
| 1457 frame->setCompositionFromExistingText(30, 34, underlines); | 1476 frame->setCompositionFromExistingText(30, 34, underlines); |
| 1458 info = webView->textInputInfo(); | 1477 info = activeInputMethodController->textInputInfo(); |
| 1459 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", | 1478 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", |
| 1460 std::string(info.value.utf8().data())); | 1479 std::string(info.value.utf8().data())); |
| 1461 EXPECT_EQ(31, info.selectionStart); | 1480 EXPECT_EQ(31, info.selectionStart); |
| 1462 EXPECT_EQ(31, info.selectionEnd); | 1481 EXPECT_EQ(31, info.selectionEnd); |
| 1463 EXPECT_EQ(30, info.compositionStart); | 1482 EXPECT_EQ(30, info.compositionStart); |
| 1464 EXPECT_EQ(34, info.compositionEnd); | 1483 EXPECT_EQ(34, info.compositionEnd); |
| 1465 | 1484 |
| 1466 std::string compositionText("yolo"); | 1485 std::string compositionText("yolo"); |
| 1467 activeInputMethodController->commitText( | 1486 activeInputMethodController->commitText( |
| 1468 WebString::fromUTF8(compositionText.c_str()), 0); | 1487 WebString::fromUTF8(compositionText.c_str()), 0); |
| 1469 info = webView->textInputInfo(); | 1488 info = activeInputMethodController->textInputInfo(); |
| 1470 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", | 1489 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", |
| 1471 std::string(info.value.utf8().data())); | 1490 std::string(info.value.utf8().data())); |
| 1472 EXPECT_EQ(34, info.selectionStart); | 1491 EXPECT_EQ(34, info.selectionStart); |
| 1473 EXPECT_EQ(34, info.selectionEnd); | 1492 EXPECT_EQ(34, info.selectionEnd); |
| 1474 EXPECT_EQ(-1, info.compositionStart); | 1493 EXPECT_EQ(-1, info.compositionStart); |
| 1475 EXPECT_EQ(-1, info.compositionEnd); | 1494 EXPECT_EQ(-1, info.compositionEnd); |
| 1476 } | 1495 } |
| 1477 | 1496 |
| 1478 TEST_P(WebViewTest, SetCompositionFromExistingTextInRichText) { | 1497 TEST_P(WebViewTest, SetCompositionFromExistingTextInRichText) { |
| 1479 URLTestHelpers::registerMockedURLFromBaseURL( | 1498 URLTestHelpers::registerMockedURLFromBaseURL( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1506 WebInputMethodController* activeInputMethodController = | 1525 WebInputMethodController* activeInputMethodController = |
| 1507 webView->mainFrameImpl() | 1526 webView->mainFrameImpl() |
| 1508 ->frameWidget() | 1527 ->frameWidget() |
| 1509 ->getActiveWebInputMethodController(); | 1528 ->getActiveWebInputMethodController(); |
| 1510 activeInputMethodController->commitText( | 1529 activeInputMethodController->commitText( |
| 1511 WebString::fromUTF8(compositionTextFirst.c_str()), 0); | 1530 WebString::fromUTF8(compositionTextFirst.c_str()), 0); |
| 1512 activeInputMethodController->setComposition( | 1531 activeInputMethodController->setComposition( |
| 1513 WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, | 1532 WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, |
| 1514 5); | 1533 5); |
| 1515 | 1534 |
| 1516 WebTextInputInfo info = webView->textInputInfo(); | 1535 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 1517 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1536 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
| 1518 EXPECT_EQ(11, info.selectionStart); | 1537 EXPECT_EQ(11, info.selectionStart); |
| 1519 EXPECT_EQ(11, info.selectionEnd); | 1538 EXPECT_EQ(11, info.selectionEnd); |
| 1520 EXPECT_EQ(6, info.compositionStart); | 1539 EXPECT_EQ(6, info.compositionStart); |
| 1521 EXPECT_EQ(11, info.compositionEnd); | 1540 EXPECT_EQ(11, info.compositionEnd); |
| 1522 | 1541 |
| 1523 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 1542 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 1524 frame->setEditableSelectionOffsets(6, 6); | 1543 frame->setEditableSelectionOffsets(6, 6); |
| 1525 info = webView->textInputInfo(); | 1544 info = activeInputMethodController->textInputInfo(); |
| 1526 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1545 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
| 1527 EXPECT_EQ(6, info.selectionStart); | 1546 EXPECT_EQ(6, info.selectionStart); |
| 1528 EXPECT_EQ(6, info.selectionEnd); | 1547 EXPECT_EQ(6, info.selectionEnd); |
| 1529 EXPECT_EQ(6, info.compositionStart); | 1548 EXPECT_EQ(6, info.compositionStart); |
| 1530 EXPECT_EQ(11, info.compositionEnd); | 1549 EXPECT_EQ(11, info.compositionEnd); |
| 1531 | 1550 |
| 1532 frame->setEditableSelectionOffsets(8, 8); | 1551 frame->setEditableSelectionOffsets(8, 8); |
| 1533 info = webView->textInputInfo(); | 1552 info = activeInputMethodController->textInputInfo(); |
| 1534 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1553 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
| 1535 EXPECT_EQ(8, info.selectionStart); | 1554 EXPECT_EQ(8, info.selectionStart); |
| 1536 EXPECT_EQ(8, info.selectionEnd); | 1555 EXPECT_EQ(8, info.selectionEnd); |
| 1537 EXPECT_EQ(6, info.compositionStart); | 1556 EXPECT_EQ(6, info.compositionStart); |
| 1538 EXPECT_EQ(11, info.compositionEnd); | 1557 EXPECT_EQ(11, info.compositionEnd); |
| 1539 | 1558 |
| 1540 frame->setEditableSelectionOffsets(11, 11); | 1559 frame->setEditableSelectionOffsets(11, 11); |
| 1541 info = webView->textInputInfo(); | 1560 info = activeInputMethodController->textInputInfo(); |
| 1542 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1561 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
| 1543 EXPECT_EQ(11, info.selectionStart); | 1562 EXPECT_EQ(11, info.selectionStart); |
| 1544 EXPECT_EQ(11, info.selectionEnd); | 1563 EXPECT_EQ(11, info.selectionEnd); |
| 1545 EXPECT_EQ(6, info.compositionStart); | 1564 EXPECT_EQ(6, info.compositionStart); |
| 1546 EXPECT_EQ(11, info.compositionEnd); | 1565 EXPECT_EQ(11, info.compositionEnd); |
| 1547 | 1566 |
| 1548 frame->setEditableSelectionOffsets(6, 11); | 1567 frame->setEditableSelectionOffsets(6, 11); |
| 1549 info = webView->textInputInfo(); | 1568 info = activeInputMethodController->textInputInfo(); |
| 1550 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1569 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
| 1551 EXPECT_EQ(6, info.selectionStart); | 1570 EXPECT_EQ(6, info.selectionStart); |
| 1552 EXPECT_EQ(11, info.selectionEnd); | 1571 EXPECT_EQ(11, info.selectionEnd); |
| 1553 EXPECT_EQ(6, info.compositionStart); | 1572 EXPECT_EQ(6, info.compositionStart); |
| 1554 EXPECT_EQ(11, info.compositionEnd); | 1573 EXPECT_EQ(11, info.compositionEnd); |
| 1555 | 1574 |
| 1556 frame->setEditableSelectionOffsets(2, 2); | 1575 frame->setEditableSelectionOffsets(2, 2); |
| 1557 info = webView->textInputInfo(); | 1576 info = activeInputMethodController->textInputInfo(); |
| 1558 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 1577 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
| 1559 EXPECT_EQ(2, info.selectionStart); | 1578 EXPECT_EQ(2, info.selectionStart); |
| 1560 EXPECT_EQ(2, info.selectionEnd); | 1579 EXPECT_EQ(2, info.selectionEnd); |
| 1561 EXPECT_EQ(-1, info.compositionStart); | 1580 EXPECT_EQ(-1, info.compositionStart); |
| 1562 EXPECT_EQ(-1, info.compositionEnd); | 1581 EXPECT_EQ(-1, info.compositionEnd); |
| 1563 } | 1582 } |
| 1564 | 1583 |
| 1565 TEST_P(WebViewTest, IsSelectionAnchorFirst) { | 1584 TEST_P(WebViewTest, IsSelectionAnchorFirst) { |
| 1566 URLTestHelpers::registerMockedURLFromBaseURL( | 1585 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1567 WebString::fromUTF8(m_baseURL.c_str()), | 1586 WebString::fromUTF8(m_baseURL.c_str()), |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2699 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 2718 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 2700 m_baseURL + "input_field_populated.html"); | 2719 m_baseURL + "input_field_populated.html"); |
| 2701 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2720 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2702 frame->setAutofillClient(&client); | 2721 frame->setAutofillClient(&client); |
| 2703 webView->setInitialFocus(false); | 2722 webView->setInitialFocus(false); |
| 2704 | 2723 |
| 2705 // Set up a composition that needs to be committed. | 2724 // Set up a composition that needs to be committed. |
| 2706 WebVector<WebCompositionUnderline> emptyUnderlines; | 2725 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2707 frame->setEditableSelectionOffsets(4, 10); | 2726 frame->setEditableSelectionOffsets(4, 10); |
| 2708 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2727 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 2709 WebTextInputInfo info = webView->textInputInfo(); | 2728 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); |
| 2710 EXPECT_EQ(4, info.selectionStart); | 2729 EXPECT_EQ(4, info.selectionStart); |
| 2711 EXPECT_EQ(10, info.selectionEnd); | 2730 EXPECT_EQ(10, info.selectionEnd); |
| 2712 EXPECT_EQ(8, info.compositionStart); | 2731 EXPECT_EQ(8, info.compositionStart); |
| 2713 EXPECT_EQ(12, info.compositionEnd); | 2732 EXPECT_EQ(12, info.compositionEnd); |
| 2714 | 2733 |
| 2715 // Clear the focus and track that the subsequent composition commit does not | 2734 // Clear the focus and track that the subsequent composition commit does not |
| 2716 // trigger a text changed notification for autofill. | 2735 // trigger a text changed notification for autofill. |
| 2717 client.clearChangeCounts(); | 2736 client.clearChangeCounts(); |
| 2718 webView->setFocus(false); | 2737 webView->setFocus(false); |
| 2719 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 2738 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
| 2720 | 2739 |
| 2721 frame->setAutofillClient(0); | 2740 frame->setAutofillClient(0); |
| 2722 } | 2741 } |
| 2723 | 2742 |
| 2724 static void verifySelectionAndComposition(WebView* webView, | 2743 static void verifySelectionAndComposition(WebViewImpl* webView, |
| 2725 int selectionStart, | 2744 int selectionStart, |
| 2726 int selectionEnd, | 2745 int selectionEnd, |
| 2727 int compositionStart, | 2746 int compositionStart, |
| 2728 int compositionEnd, | 2747 int compositionEnd, |
| 2729 const char* failMessage) { | 2748 const char* failMessage) { |
| 2730 WebTextInputInfo info = webView->textInputInfo(); | 2749 WebTextInputInfo info = |
| 2750 webView->mainFrameImpl()->inputMethodController()->textInputInfo(); |
| 2731 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage; | 2751 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage; |
| 2732 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage; | 2752 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage; |
| 2733 EXPECT_EQ(compositionStart, info.compositionStart) << failMessage; | 2753 EXPECT_EQ(compositionStart, info.compositionStart) << failMessage; |
| 2734 EXPECT_EQ(compositionEnd, info.compositionEnd) << failMessage; | 2754 EXPECT_EQ(compositionEnd, info.compositionEnd) << failMessage; |
| 2735 } | 2755 } |
| 2736 | 2756 |
| 2737 TEST_P(WebViewTest, CompositionNotCancelledByBackspace) { | 2757 TEST_P(WebViewTest, CompositionNotCancelledByBackspace) { |
| 2738 URLTestHelpers::registerMockedURLFromBaseURL( | 2758 URLTestHelpers::registerMockedURLFromBaseURL( |
| 2739 WebString::fromUTF8(m_baseURL.c_str()), | 2759 WebString::fromUTF8(m_baseURL.c_str()), |
| 2740 WebString::fromUTF8("composition_not_cancelled_by_backspace.html")); | 2760 WebString::fromUTF8("composition_not_cancelled_by_backspace.html")); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2794 WebInputMethodController* activeInputMethodController = | 2814 WebInputMethodController* activeInputMethodController = |
| 2795 frame->frameWidget()->getActiveWebInputMethodController(); | 2815 frame->frameWidget()->getActiveWebInputMethodController(); |
| 2796 // Set up a composition that needs to be committed. | 2816 // Set up a composition that needs to be committed. |
| 2797 std::string compositionText("testingtext"); | 2817 std::string compositionText("testingtext"); |
| 2798 | 2818 |
| 2799 WebVector<WebCompositionUnderline> emptyUnderlines; | 2819 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2800 activeInputMethodController->setComposition( | 2820 activeInputMethodController->setComposition( |
| 2801 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, | 2821 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, |
| 2802 compositionText.length()); | 2822 compositionText.length()); |
| 2803 | 2823 |
| 2804 WebTextInputInfo info = webView->textInputInfo(); | 2824 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 2805 EXPECT_EQ(0, info.selectionStart); | 2825 EXPECT_EQ(0, info.selectionStart); |
| 2806 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); | 2826 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); |
| 2807 EXPECT_EQ(0, info.compositionStart); | 2827 EXPECT_EQ(0, info.compositionStart); |
| 2808 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); | 2828 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); |
| 2809 | 2829 |
| 2810 client.clearChangeCounts(); | 2830 client.clearChangeCounts(); |
| 2811 activeInputMethodController->finishComposingText( | 2831 activeInputMethodController->finishComposingText( |
| 2812 WebInputMethodController::KeepSelection); | 2832 WebInputMethodController::KeepSelection); |
| 2813 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 2833 EXPECT_EQ(0, client.textChangesWhileIgnored()); |
| 2814 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); | 2834 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2825 m_baseURL + "input_field_populated.html", true); | 2845 m_baseURL + "input_field_populated.html", true); |
| 2826 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2846 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2827 frame->setAutofillClient(&client); | 2847 frame->setAutofillClient(&client); |
| 2828 webView->setInitialFocus(false); | 2848 webView->setInitialFocus(false); |
| 2829 | 2849 |
| 2830 WebVector<WebCompositionUnderline> emptyUnderlines; | 2850 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2831 | 2851 |
| 2832 client.clearChangeCounts(); | 2852 client.clearChangeCounts(); |
| 2833 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2853 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 2834 | 2854 |
| 2835 WebTextInputInfo info = webView->textInputInfo(); | 2855 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); |
| 2836 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", | 2856 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", |
| 2837 std::string(info.value.utf8().data())); | 2857 std::string(info.value.utf8().data())); |
| 2838 EXPECT_EQ(8, info.compositionStart); | 2858 EXPECT_EQ(8, info.compositionStart); |
| 2839 EXPECT_EQ(12, info.compositionEnd); | 2859 EXPECT_EQ(12, info.compositionEnd); |
| 2840 | 2860 |
| 2841 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 2861 EXPECT_EQ(0, client.textChangesWhileIgnored()); |
| 2842 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 2862 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
| 2843 | 2863 |
| 2844 WebDocument document = webView->mainFrame()->document(); | 2864 WebDocument document = webView->mainFrame()->document(); |
| 2845 EXPECT_EQ(WebString::fromUTF8("none"), | 2865 EXPECT_EQ(WebString::fromUTF8("none"), |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3491 }; | 3511 }; |
| 3492 | 3512 |
| 3493 // This test verifies the text input flags are correctly exposed to script. | 3513 // This test verifies the text input flags are correctly exposed to script. |
| 3494 TEST_P(WebViewTest, TextInputFlags) { | 3514 TEST_P(WebViewTest, TextInputFlags) { |
| 3495 std::string url = m_baseURL + "text_input_flags.html"; | 3515 std::string url = m_baseURL + "text_input_flags.html"; |
| 3496 URLTestHelpers::registerMockedURLLoad(toKURL(url), "text_input_flags.html"); | 3516 URLTestHelpers::registerMockedURLLoad(toKURL(url), "text_input_flags.html"); |
| 3497 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true); | 3517 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true); |
| 3498 webViewImpl->setInitialFocus(false); | 3518 webViewImpl->setInitialFocus(false); |
| 3499 | 3519 |
| 3500 WebLocalFrameImpl* frame = webViewImpl->mainFrameImpl(); | 3520 WebLocalFrameImpl* frame = webViewImpl->mainFrameImpl(); |
| 3521 WebInputMethodControllerImpl* activeInputMethodController = |
| 3522 frame->inputMethodController(); |
| 3501 Document* document = frame->frame()->document(); | 3523 Document* document = frame->frame()->document(); |
| 3502 | 3524 |
| 3503 // (A) <input> | 3525 // (A) <input> |
| 3504 // (A.1) Verifies autocorrect/autocomplete/spellcheck flags are Off and | 3526 // (A.1) Verifies autocorrect/autocomplete/spellcheck flags are Off and |
| 3505 // autocapitalize is set to none. | 3527 // autocapitalize is set to none. |
| 3506 HTMLInputElement* inputElement = | 3528 HTMLInputElement* inputElement = |
| 3507 toHTMLInputElement(document->getElementById("input")); | 3529 toHTMLInputElement(document->getElementById("input")); |
| 3508 document->setFocusedElement( | 3530 document->setFocusedElement( |
| 3509 inputElement, | 3531 inputElement, |
| 3510 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 3532 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 3511 webViewImpl->setFocus(true); | 3533 webViewImpl->setFocus(true); |
| 3512 WebTextInputInfo info1 = webViewImpl->textInputInfo(); | 3534 WebTextInputInfo info1 = activeInputMethodController->textInputInfo(); |
| 3513 EXPECT_EQ(WebTextInputFlagAutocompleteOff | WebTextInputFlagAutocorrectOff | | 3535 EXPECT_EQ(WebTextInputFlagAutocompleteOff | WebTextInputFlagAutocorrectOff | |
| 3514 WebTextInputFlagSpellcheckOff | | 3536 WebTextInputFlagSpellcheckOff | |
| 3515 WebTextInputFlagAutocapitalizeNone, | 3537 WebTextInputFlagAutocapitalizeNone, |
| 3516 info1.flags); | 3538 info1.flags); |
| 3517 | 3539 |
| 3518 // (A.2) Verifies autocorrect/autocomplete/spellcheck flags are On and | 3540 // (A.2) Verifies autocorrect/autocomplete/spellcheck flags are On and |
| 3519 // autocapitalize is set to sentences. | 3541 // autocapitalize is set to sentences. |
| 3520 inputElement = toHTMLInputElement(document->getElementById("input2")); | 3542 inputElement = toHTMLInputElement(document->getElementById("input2")); |
| 3521 document->setFocusedElement( | 3543 document->setFocusedElement( |
| 3522 inputElement, | 3544 inputElement, |
| 3523 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 3545 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 3524 webViewImpl->setFocus(true); | 3546 webViewImpl->setFocus(true); |
| 3525 WebTextInputInfo info2 = webViewImpl->textInputInfo(); | 3547 WebTextInputInfo info2 = activeInputMethodController->textInputInfo(); |
| 3526 EXPECT_EQ(WebTextInputFlagAutocompleteOn | WebTextInputFlagAutocorrectOn | | 3548 EXPECT_EQ(WebTextInputFlagAutocompleteOn | WebTextInputFlagAutocorrectOn | |
| 3527 WebTextInputFlagSpellcheckOn | | 3549 WebTextInputFlagSpellcheckOn | |
| 3528 WebTextInputFlagAutocapitalizeSentences, | 3550 WebTextInputFlagAutocapitalizeSentences, |
| 3529 info2.flags); | 3551 info2.flags); |
| 3530 | 3552 |
| 3531 // (B) <textarea> Verifies the default text input flags are | 3553 // (B) <textarea> Verifies the default text input flags are |
| 3532 // WebTextInputFlagAutocapitalizeSentences. | 3554 // WebTextInputFlagAutocapitalizeSentences. |
| 3533 HTMLTextAreaElement* textAreaElement = | 3555 HTMLTextAreaElement* textAreaElement = |
| 3534 toHTMLTextAreaElement(document->getElementById("textarea")); | 3556 toHTMLTextAreaElement(document->getElementById("textarea")); |
| 3535 document->setFocusedElement( | 3557 document->setFocusedElement( |
| 3536 textAreaElement, | 3558 textAreaElement, |
| 3537 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 3559 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 3538 webViewImpl->setFocus(true); | 3560 webViewImpl->setFocus(true); |
| 3539 WebTextInputInfo info3 = webViewImpl->textInputInfo(); | 3561 WebTextInputInfo info3 = activeInputMethodController->textInputInfo(); |
| 3540 EXPECT_EQ(WebTextInputFlagAutocapitalizeSentences, info3.flags); | 3562 EXPECT_EQ(WebTextInputFlagAutocapitalizeSentences, info3.flags); |
| 3541 | 3563 |
| 3542 // (C) Verifies the WebTextInputInfo's don't equal. | 3564 // (C) Verifies the WebTextInputInfo's don't equal. |
| 3543 EXPECT_FALSE(info1.equals(info2)); | 3565 EXPECT_FALSE(info1.equals(info2)); |
| 3544 EXPECT_FALSE(info2.equals(info3)); | 3566 EXPECT_FALSE(info2.equals(info3)); |
| 3545 | 3567 |
| 3546 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. | 3568 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. |
| 3547 m_webViewHelper.reset(); | 3569 m_webViewHelper.reset(); |
| 3548 } | 3570 } |
| 3549 | 3571 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3573 toHTMLInputElement(document->getElementById("input")); | 3595 toHTMLInputElement(document->getElementById("input")); |
| 3574 document->setFocusedElement( | 3596 document->setFocusedElement( |
| 3575 inputElement, | 3597 inputElement, |
| 3576 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 3598 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 3577 webViewImpl->setFocus(true); | 3599 webViewImpl->setFocus(true); |
| 3578 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(inputElement)); | 3600 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(inputElement)); |
| 3579 | 3601 |
| 3580 // Emulate value change from script. | 3602 // Emulate value change from script. |
| 3581 inputElement->setValue("testA"); | 3603 inputElement->setValue("testA"); |
| 3582 EXPECT_TRUE(client.textIsUpdated()); | 3604 EXPECT_TRUE(client.textIsUpdated()); |
| 3583 WebTextInputInfo info = webViewImpl->textInputInfo(); | 3605 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 3584 EXPECT_EQ("testA", std::string(info.value.utf8().data())); | 3606 EXPECT_EQ("testA", std::string(info.value.utf8().data())); |
| 3585 | 3607 |
| 3586 // (A.2) Focused and user input modifies value. | 3608 // (A.2) Focused and user input modifies value. |
| 3587 client.reset(); | 3609 client.reset(); |
| 3588 EXPECT_FALSE(client.textIsUpdated()); | 3610 EXPECT_FALSE(client.textIsUpdated()); |
| 3589 | 3611 |
| 3590 WebVector<WebCompositionUnderline> emptyUnderlines; | 3612 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 3591 activeInputMethodController->setComposition(WebString::fromUTF8("2"), | 3613 activeInputMethodController->setComposition(WebString::fromUTF8("2"), |
| 3592 emptyUnderlines, 1, 1); | 3614 emptyUnderlines, 1, 1); |
| 3593 activeInputMethodController->finishComposingText( | 3615 activeInputMethodController->finishComposingText( |
| 3594 WebInputMethodController::KeepSelection); | 3616 WebInputMethodController::KeepSelection); |
| 3595 EXPECT_FALSE(client.textIsUpdated()); | 3617 EXPECT_FALSE(client.textIsUpdated()); |
| 3596 info = webViewImpl->textInputInfo(); | 3618 info = activeInputMethodController->textInputInfo(); |
| 3597 EXPECT_EQ("testA2", std::string(info.value.utf8().data())); | 3619 EXPECT_EQ("testA2", std::string(info.value.utf8().data())); |
| 3598 | 3620 |
| 3599 // (A.3) Unfocused and value is changed by script. | 3621 // (A.3) Unfocused and value is changed by script. |
| 3600 client.reset(); | 3622 client.reset(); |
| 3601 EXPECT_FALSE(client.textIsUpdated()); | 3623 EXPECT_FALSE(client.textIsUpdated()); |
| 3602 document->clearFocusedElement(); | 3624 document->clearFocusedElement(); |
| 3603 webViewImpl->setFocus(false); | 3625 webViewImpl->setFocus(false); |
| 3604 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement)); | 3626 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement)); |
| 3605 inputElement->setValue("testA3"); | 3627 inputElement->setValue("testA3"); |
| 3606 EXPECT_FALSE(client.textIsUpdated()); | 3628 EXPECT_FALSE(client.textIsUpdated()); |
| 3607 | 3629 |
| 3608 // (B) <textarea> | 3630 // (B) <textarea> |
| 3609 // (B.1) Focused and value is changed by script. | 3631 // (B.1) Focused and value is changed by script. |
| 3610 client.reset(); | 3632 client.reset(); |
| 3611 EXPECT_FALSE(client.textIsUpdated()); | 3633 EXPECT_FALSE(client.textIsUpdated()); |
| 3612 HTMLTextAreaElement* textAreaElement = | 3634 HTMLTextAreaElement* textAreaElement = |
| 3613 toHTMLTextAreaElement(document->getElementById("textarea")); | 3635 toHTMLTextAreaElement(document->getElementById("textarea")); |
| 3614 document->setFocusedElement( | 3636 document->setFocusedElement( |
| 3615 textAreaElement, | 3637 textAreaElement, |
| 3616 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 3638 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 3617 webViewImpl->setFocus(true); | 3639 webViewImpl->setFocus(true); |
| 3618 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement)); | 3640 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement)); |
| 3619 textAreaElement->setValue("testB"); | 3641 textAreaElement->setValue("testB"); |
| 3620 EXPECT_TRUE(client.textIsUpdated()); | 3642 EXPECT_TRUE(client.textIsUpdated()); |
| 3621 info = webViewImpl->textInputInfo(); | 3643 info = activeInputMethodController->textInputInfo(); |
| 3622 EXPECT_EQ("testB", std::string(info.value.utf8().data())); | 3644 EXPECT_EQ("testB", std::string(info.value.utf8().data())); |
| 3623 | 3645 |
| 3624 // (B.2) Focused and user input modifies value. | 3646 // (B.2) Focused and user input modifies value. |
| 3625 client.reset(); | 3647 client.reset(); |
| 3626 EXPECT_FALSE(client.textIsUpdated()); | 3648 EXPECT_FALSE(client.textIsUpdated()); |
| 3627 activeInputMethodController->setComposition(WebString::fromUTF8("2"), | 3649 activeInputMethodController->setComposition(WebString::fromUTF8("2"), |
| 3628 emptyUnderlines, 1, 1); | 3650 emptyUnderlines, 1, 1); |
| 3629 activeInputMethodController->finishComposingText( | 3651 activeInputMethodController->finishComposingText( |
| 3630 WebInputMethodController::KeepSelection); | 3652 WebInputMethodController::KeepSelection); |
| 3631 info = webViewImpl->textInputInfo(); | 3653 info = activeInputMethodController->textInputInfo(); |
| 3632 EXPECT_EQ("testB2", std::string(info.value.utf8().data())); | 3654 EXPECT_EQ("testB2", std::string(info.value.utf8().data())); |
| 3633 | 3655 |
| 3634 // (B.3) Unfocused and value is changed by script. | 3656 // (B.3) Unfocused and value is changed by script. |
| 3635 client.reset(); | 3657 client.reset(); |
| 3636 EXPECT_FALSE(client.textIsUpdated()); | 3658 EXPECT_FALSE(client.textIsUpdated()); |
| 3637 document->clearFocusedElement(); | 3659 document->clearFocusedElement(); |
| 3638 webViewImpl->setFocus(false); | 3660 webViewImpl->setFocus(false); |
| 3639 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement)); | 3661 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement)); |
| 3640 inputElement->setValue("testB3"); | 3662 inputElement->setValue("testB3"); |
| 3641 EXPECT_FALSE(client.textIsUpdated()); | 3663 EXPECT_FALSE(client.textIsUpdated()); |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4349 .translate(50, 55) | 4371 .translate(50, 55) |
| 4350 .scale(1. / 2.f); | 4372 .scale(1. / 2.f); |
| 4351 EXPECT_EQ(expectedMatrix, | 4373 EXPECT_EQ(expectedMatrix, |
| 4352 webViewImpl->getDeviceEmulationTransformForTesting()); | 4374 webViewImpl->getDeviceEmulationTransformForTesting()); |
| 4353 // visibleContentRect doesn't change. | 4375 // visibleContentRect doesn't change. |
| 4354 EXPECT_EQ(IntRect(50, 55, 50, 75), | 4376 EXPECT_EQ(IntRect(50, 55, 50, 75), |
| 4355 *devToolsEmulator->visibleContentRectForPainting()); | 4377 *devToolsEmulator->visibleContentRectForPainting()); |
| 4356 } | 4378 } |
| 4357 | 4379 |
| 4358 } // namespace blink | 4380 } // namespace blink |
| OLD | NEW |