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

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

Issue 1325563002: Avoid style clobbering in setCompositionFromExistingText. (2nd land) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Delete CompositionUnderlinesRangeFilter (it's now dead code) Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
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"
37 #include "core/frame/EventHandlerRegistry.h" 38 #include "core/frame/EventHandlerRegistry.h"
38 #include "core/frame/FrameHost.h" 39 #include "core/frame/FrameHost.h"
39 #include "core/frame/FrameView.h" 40 #include "core/frame/FrameView.h"
40 #include "core/frame/LocalFrame.h" 41 #include "core/frame/LocalFrame.h"
41 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
42 #include "core/frame/VisualViewport.h" 43 #include "core/frame/VisualViewport.h"
43 #include "core/html/HTMLDocument.h" 44 #include "core/html/HTMLDocument.h"
44 #include "core/html/HTMLIFrameElement.h" 45 #include "core/html/HTMLIFrameElement.h"
45 #include "core/html/HTMLInputElement.h" 46 #include "core/html/HTMLInputElement.h"
46 #include "core/html/HTMLTextAreaElement.h" 47 #include "core/html/HTMLTextAreaElement.h"
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 TEST_F(WebViewTest, SetCompositionFromExistingText) 985 TEST_F(WebViewTest, SetCompositionFromExistingText)
985 { 986 {
986 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 987 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
987 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 988 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
988 webView->setInitialFocus(false); 989 webView->setInitialFocus(false);
989 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); 990 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
990 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); 991 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
991 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 992 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
992 frame->setEditableSelectionOffsets(4, 10); 993 frame->setEditableSelectionOffsets(4, 10);
993 frame->setCompositionFromExistingText(8, 12, underlines); 994 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);
997 WebTextInputInfo info = webView->textInputInfo(); 995 WebTextInputInfo info = webView->textInputInfo();
998 EXPECT_EQ(4, info.selectionStart); 996 EXPECT_EQ(4, info.selectionStart);
999 EXPECT_EQ(10, info.selectionEnd); 997 EXPECT_EQ(10, info.selectionEnd);
1000 EXPECT_EQ(8, info.compositionStart); 998 EXPECT_EQ(8, info.compositionStart);
1001 EXPECT_EQ(12, info.compositionEnd); 999 EXPECT_EQ(12, info.compositionEnd);
1002 WebVector<WebCompositionUnderline> emptyUnderlines; 1000 WebVector<WebCompositionUnderline> emptyUnderlines;
1003 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); 1001 frame->setCompositionFromExistingText(0, 0, emptyUnderlines);
1004 info = webView->textInputInfo(); 1002 info = webView->textInputInfo();
1005 EXPECT_EQ(4, info.selectionStart); 1003 EXPECT_EQ(4, info.selectionStart);
1006 EXPECT_EQ(10, info.selectionEnd); 1004 EXPECT_EQ(10, info.selectionEnd);
(...skipping 10 matching lines...) Expand all
1017 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); 1015 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
1018 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 1016 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1019 frame->setEditableSelectionOffsets(27, 27); 1017 frame->setEditableSelectionOffsets(27, 27);
1020 std::string newLineText("\n"); 1018 std::string newLineText("\n");
1021 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); 1019 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str()));
1022 WebTextInputInfo info = webView->textInputInfo(); 1020 WebTextInputInfo info = webView->textInputInfo();
1023 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data())); 1021 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data()));
1024 1022
1025 frame->setEditableSelectionOffsets(31, 31); 1023 frame->setEditableSelectionOffsets(31, 31);
1026 frame->setCompositionFromExistingText(30, 34, underlines); 1024 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);
1030 info = webView->textInputInfo(); 1025 info = webView->textInputInfo();
1031 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data())); 1026 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data()));
1032 EXPECT_EQ(31, info.selectionStart); 1027 EXPECT_EQ(31, info.selectionStart);
1033 EXPECT_EQ(31, info.selectionEnd); 1028 EXPECT_EQ(31, info.selectionEnd);
1034 EXPECT_EQ(30, info.compositionStart); 1029 EXPECT_EQ(30, info.compositionStart);
1035 EXPECT_EQ(34, info.compositionEnd); 1030 EXPECT_EQ(34, info.compositionEnd);
1036 1031
1037 std::string compositionText("yolo"); 1032 std::string compositionText("yolo");
1038 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); 1033 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str()));
1039 info = webView->textInputInfo(); 1034 info = webView->textInputInfo();
1040 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data())); 1035 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data()));
1041 EXPECT_EQ(34, info.selectionStart); 1036 EXPECT_EQ(34, info.selectionStart);
1042 EXPECT_EQ(34, info.selectionEnd); 1037 EXPECT_EQ(34, info.selectionEnd);
1043 EXPECT_EQ(-1, info.compositionStart); 1038 EXPECT_EQ(-1, info.compositionStart);
1044 EXPECT_EQ(-1, info.compositionEnd); 1039 EXPECT_EQ(-1, info.compositionEnd);
1045 } 1040 }
1046 1041
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
1047 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) 1057 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
1048 { 1058 {
1049 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 1059 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1050 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 1060 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
1051 webView->setInitialFocus(false); 1061 webView->setInitialFocus(false);
1052 1062
1053 std::string compositionTextFirst("hello "); 1063 std::string compositionTextFirst("hello ");
1054 std::string compositionTextSecond("world"); 1064 std::string compositionTextSecond("world");
1055 WebVector<WebCompositionUnderline> emptyUnderlines; 1065 WebVector<WebCompositionUnderline> emptyUnderlines;
1056 1066
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 WebTextInputInfo info = webView->textInputInfo(); 1675 WebTextInputInfo info = webView->textInputInfo();
1666 EXPECT_EQ(4, info.selectionStart); 1676 EXPECT_EQ(4, info.selectionStart);
1667 EXPECT_EQ(10, info.selectionEnd); 1677 EXPECT_EQ(10, info.selectionEnd);
1668 EXPECT_EQ(8, info.compositionStart); 1678 EXPECT_EQ(8, info.compositionStart);
1669 EXPECT_EQ(12, info.compositionEnd); 1679 EXPECT_EQ(12, info.compositionEnd);
1670 1680
1671 // Clear the focus and track that the subsequent composition commit does not trigger a 1681 // Clear the focus and track that the subsequent composition commit does not trigger a
1672 // text changed notification for autofill. 1682 // text changed notification for autofill.
1673 client.clearChangeCounts(); 1683 client.clearChangeCounts();
1674 webView->setFocus(false); 1684 webView->setFocus(false);
1675 EXPECT_EQ(1, client.textChangesWhileIgnored());
1676 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); 1685 EXPECT_EQ(0, client.textChangesWhileNotIgnored());
1677 1686
1678 frame->setAutofillClient(0); 1687 frame->setAutofillClient(0);
1679 } 1688 }
1680 1689
1681 static void verifySelectionAndComposition(WebView* webView, int selectionStart, int selectionEnd, int compositionStart, int compositionEnd, const char* failMess age) 1690 static void verifySelectionAndComposition(WebView* webView, int selectionStart, int selectionEnd, int compositionStart, int compositionEnd, const char* failMess age)
1682 { 1691 {
1683 WebTextInputInfo info = webView->textInputInfo(); 1692 WebTextInputInfo info = webView->textInputInfo();
1684 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage; 1693 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage;
1685 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage; 1694 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage;
(...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after
3045 for (size_t i = 0; i < renders.size(); ++i) { 3054 for (size_t i = 0; i < renders.size(); ++i) {
3046 double docStartTime = frame->domWindow()->document()->loader()->timing() .monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0; 3055 double docStartTime = frame->domWindow()->document()->loader()->timing() .monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0;
3047 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime()); 3056 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime());
3048 double docFinishTime = frame->domWindow()->document()->loader()->timing( ).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0; 3057 double docFinishTime = frame->domWindow()->document()->loader()->timing( ).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0;
3049 double docDuration = docFinishTime - docStartTime; 3058 double docDuration = docFinishTime - docStartTime;
3050 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration()); 3059 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration());
3051 } 3060 }
3052 } 3061 }
3053 3062
3054 } // namespace blink 3063 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698