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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "public/web/WebView.h" | 32 #include "public/web/WebView.h" |
33 | 33 |
34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
35 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
36 #include "core/editing/FrameSelection.h" | 36 #include "core/editing/FrameSelection.h" |
37 #include "core/editing/markers/DocumentMarkerController.h" | |
38 #include "core/frame/EventHandlerRegistry.h" | 37 #include "core/frame/EventHandlerRegistry.h" |
39 #include "core/frame/FrameHost.h" | 38 #include "core/frame/FrameHost.h" |
40 #include "core/frame/FrameView.h" | 39 #include "core/frame/FrameView.h" |
41 #include "core/frame/LocalFrame.h" | 40 #include "core/frame/LocalFrame.h" |
42 #include "core/frame/Settings.h" | 41 #include "core/frame/Settings.h" |
43 #include "core/frame/VisualViewport.h" | 42 #include "core/frame/VisualViewport.h" |
44 #include "core/html/HTMLDocument.h" | 43 #include "core/html/HTMLDocument.h" |
45 #include "core/html/HTMLIFrameElement.h" | 44 #include "core/html/HTMLIFrameElement.h" |
46 #include "core/html/HTMLInputElement.h" | 45 #include "core/html/HTMLInputElement.h" |
47 #include "core/html/HTMLTextAreaElement.h" | 46 #include "core/html/HTMLTextAreaElement.h" |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 TEST_F(WebViewTest, SetCompositionFromExistingText) | 984 TEST_F(WebViewTest, SetCompositionFromExistingText) |
986 { | 985 { |
987 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 986 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
988 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); | 987 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
989 webView->setInitialFocus(false); | 988 webView->setInitialFocus(false); |
990 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 989 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
991 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 990 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
992 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 991 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
993 frame->setEditableSelectionOffsets(4, 10); | 992 frame->setEditableSelectionOffsets(4, 10); |
994 frame->setCompositionFromExistingText(8, 12, underlines); | 993 frame->setCompositionFromExistingText(8, 12, underlines); |
| 994 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); |
| 995 EXPECT_EQ(8u, underlineResults[0].startOffset); |
| 996 EXPECT_EQ(12u, underlineResults[0].endOffset); |
995 WebTextInputInfo info = webView->textInputInfo(); | 997 WebTextInputInfo info = webView->textInputInfo(); |
996 EXPECT_EQ(4, info.selectionStart); | 998 EXPECT_EQ(4, info.selectionStart); |
997 EXPECT_EQ(10, info.selectionEnd); | 999 EXPECT_EQ(10, info.selectionEnd); |
998 EXPECT_EQ(8, info.compositionStart); | 1000 EXPECT_EQ(8, info.compositionStart); |
999 EXPECT_EQ(12, info.compositionEnd); | 1001 EXPECT_EQ(12, info.compositionEnd); |
1000 WebVector<WebCompositionUnderline> emptyUnderlines; | 1002 WebVector<WebCompositionUnderline> emptyUnderlines; |
1001 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); | 1003 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); |
1002 info = webView->textInputInfo(); | 1004 info = webView->textInputInfo(); |
1003 EXPECT_EQ(4, info.selectionStart); | 1005 EXPECT_EQ(4, info.selectionStart); |
1004 EXPECT_EQ(10, info.selectionEnd); | 1006 EXPECT_EQ(10, info.selectionEnd); |
(...skipping 10 matching lines...) Expand all Loading... |
1015 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | 1017 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
1016 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 1018 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
1017 frame->setEditableSelectionOffsets(27, 27); | 1019 frame->setEditableSelectionOffsets(27, 27); |
1018 std::string newLineText("\n"); | 1020 std::string newLineText("\n"); |
1019 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); | 1021 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); |
1020 WebTextInputInfo info = webView->textInputInfo(); | 1022 WebTextInputInfo info = webView->textInputInfo(); |
1021 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); | 1023 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); |
1022 | 1024 |
1023 frame->setEditableSelectionOffsets(31, 31); | 1025 frame->setEditableSelectionOffsets(31, 31); |
1024 frame->setCompositionFromExistingText(30, 34, underlines); | 1026 frame->setCompositionFromExistingText(30, 34, underlines); |
| 1027 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); |
| 1028 EXPECT_EQ(2u, underlineResults[0].startOffset); |
| 1029 EXPECT_EQ(6u, underlineResults[0].endOffset); |
1025 info = webView->textInputInfo(); | 1030 info = webView->textInputInfo(); |
1026 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); | 1031 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); |
1027 EXPECT_EQ(31, info.selectionStart); | 1032 EXPECT_EQ(31, info.selectionStart); |
1028 EXPECT_EQ(31, info.selectionEnd); | 1033 EXPECT_EQ(31, info.selectionEnd); |
1029 EXPECT_EQ(30, info.compositionStart); | 1034 EXPECT_EQ(30, info.compositionStart); |
1030 EXPECT_EQ(34, info.compositionEnd); | 1035 EXPECT_EQ(34, info.compositionEnd); |
1031 | 1036 |
1032 std::string compositionText("yolo"); | 1037 std::string compositionText("yolo"); |
1033 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); | 1038 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); |
1034 info = webView->textInputInfo(); | 1039 info = webView->textInputInfo(); |
1035 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u
tf8().data())); | 1040 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u
tf8().data())); |
1036 EXPECT_EQ(34, info.selectionStart); | 1041 EXPECT_EQ(34, info.selectionStart); |
1037 EXPECT_EQ(34, info.selectionEnd); | 1042 EXPECT_EQ(34, info.selectionEnd); |
1038 EXPECT_EQ(-1, info.compositionStart); | 1043 EXPECT_EQ(-1, info.compositionStart); |
1039 EXPECT_EQ(-1, info.compositionEnd); | 1044 EXPECT_EQ(-1, info.compositionEnd); |
1040 } | 1045 } |
1041 | 1046 |
1042 TEST_F(WebViewTest, SetCompositionFromExistingTextInRichText) | |
1043 { | |
1044 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_editable_rich_text.html")); | |
1045 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_ed
itable_rich_text.html"); | |
1046 webView->setInitialFocus(false); | |
1047 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | |
1048 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); | |
1049 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | |
1050 frame->setEditableSelectionOffsets(1, 1); | |
1051 WebDocument document = webView->mainFrame()->document(); | |
1052 EXPECT_FALSE(document.getElementById("bold").isNull()); | |
1053 frame->setCompositionFromExistingText(0, 4, underlines); | |
1054 EXPECT_FALSE(document.getElementById("bold").isNull()); | |
1055 } | |
1056 | |
1057 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) | 1047 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) |
1058 { | 1048 { |
1059 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1049 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
1060 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); | 1050 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
1061 webView->setInitialFocus(false); | 1051 webView->setInitialFocus(false); |
1062 | 1052 |
1063 std::string compositionTextFirst("hello "); | 1053 std::string compositionTextFirst("hello "); |
1064 std::string compositionTextSecond("world"); | 1054 std::string compositionTextSecond("world"); |
1065 WebVector<WebCompositionUnderline> emptyUnderlines; | 1055 WebVector<WebCompositionUnderline> emptyUnderlines; |
1066 | 1056 |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 WebTextInputInfo info = webView->textInputInfo(); | 1665 WebTextInputInfo info = webView->textInputInfo(); |
1676 EXPECT_EQ(4, info.selectionStart); | 1666 EXPECT_EQ(4, info.selectionStart); |
1677 EXPECT_EQ(10, info.selectionEnd); | 1667 EXPECT_EQ(10, info.selectionEnd); |
1678 EXPECT_EQ(8, info.compositionStart); | 1668 EXPECT_EQ(8, info.compositionStart); |
1679 EXPECT_EQ(12, info.compositionEnd); | 1669 EXPECT_EQ(12, info.compositionEnd); |
1680 | 1670 |
1681 // Clear the focus and track that the subsequent composition commit does not
trigger a | 1671 // Clear the focus and track that the subsequent composition commit does not
trigger a |
1682 // text changed notification for autofill. | 1672 // text changed notification for autofill. |
1683 client.clearChangeCounts(); | 1673 client.clearChangeCounts(); |
1684 webView->setFocus(false); | 1674 webView->setFocus(false); |
| 1675 EXPECT_EQ(1, client.textChangesWhileIgnored()); |
1685 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 1676 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
1686 | 1677 |
1687 frame->setAutofillClient(0); | 1678 frame->setAutofillClient(0); |
1688 } | 1679 } |
1689 | 1680 |
1690 static void verifySelectionAndComposition(WebView* webView, int selectionStart,
int selectionEnd, int compositionStart, int compositionEnd, const char* failMess
age) | 1681 static void verifySelectionAndComposition(WebView* webView, int selectionStart,
int selectionEnd, int compositionStart, int compositionEnd, const char* failMess
age) |
1691 { | 1682 { |
1692 WebTextInputInfo info = webView->textInputInfo(); | 1683 WebTextInputInfo info = webView->textInputInfo(); |
1693 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage; | 1684 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage; |
1694 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage; | 1685 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage; |
(...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3054 for (size_t i = 0; i < renders.size(); ++i) { | 3045 for (size_t i = 0; i < renders.size(); ++i) { |
3055 double docStartTime = frame->domWindow()->document()->loader()->timing()
.monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0; | 3046 double docStartTime = frame->domWindow()->document()->loader()->timing()
.monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0; |
3056 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime()); | 3047 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime()); |
3057 double docFinishTime = frame->domWindow()->document()->loader()->timing(
).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0; | 3048 double docFinishTime = frame->domWindow()->document()->loader()->timing(
).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0; |
3058 double docDuration = docFinishTime - docStartTime; | 3049 double docDuration = docFinishTime - docStartTime; |
3059 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration()); | 3050 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration()); |
3060 } | 3051 } |
3061 } | 3052 } |
3062 | 3053 |
3063 } // namespace blink | 3054 } // namespace blink |
OLD | NEW |