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

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: Release Range on document detach and remove selectionStart/End 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
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/content_editable_rich_text.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17 matching lines...) Expand all
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 "bindings/core/v8/V8Document.h" 34 #include "bindings/core/v8/V8Document.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/Element.h" 36 #include "core/dom/Element.h"
37 #include "core/editing/FrameSelection.h" 37 #include "core/editing/FrameSelection.h"
38 #include "core/editing/markers/DocumentMarkerController.h"
38 #include "core/frame/EventHandlerRegistry.h" 39 #include "core/frame/EventHandlerRegistry.h"
39 #include "core/frame/FrameHost.h" 40 #include "core/frame/FrameHost.h"
40 #include "core/frame/FrameView.h" 41 #include "core/frame/FrameView.h"
41 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
42 #include "core/frame/Settings.h" 43 #include "core/frame/Settings.h"
43 #include "core/frame/VisualViewport.h" 44 #include "core/frame/VisualViewport.h"
44 #include "core/html/HTMLDocument.h" 45 #include "core/html/HTMLDocument.h"
45 #include "core/html/HTMLIFrameElement.h" 46 #include "core/html/HTMLIFrameElement.h"
46 #include "core/html/HTMLInputElement.h" 47 #include "core/html/HTMLInputElement.h"
47 #include "core/html/HTMLTextAreaElement.h" 48 #include "core/html/HTMLTextAreaElement.h"
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 TEST_F(WebViewTest, SetCompositionFromExistingText) 986 TEST_F(WebViewTest, SetCompositionFromExistingText)
986 { 987 {
987 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 988 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"); 989 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
989 webView->setInitialFocus(false); 990 webView->setInitialFocus(false);
990 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); 991 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
991 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); 992 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
992 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 993 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
993 frame->setEditableSelectionOffsets(4, 10); 994 frame->setEditableSelectionOffsets(4, 10);
994 frame->setCompositionFromExistingText(8, 12, underlines); 995 frame->setCompositionFromExistingText(8, 12, underlines);
995 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView) ->compositionUnderlines();
996 EXPECT_EQ(8u, underlineResults[0].startOffset);
997 EXPECT_EQ(12u, underlineResults[0].endOffset);
998 WebTextInputInfo info = webView->textInputInfo(); 996 WebTextInputInfo info = webView->textInputInfo();
999 EXPECT_EQ(4, info.selectionStart); 997 EXPECT_EQ(4, info.selectionStart);
1000 EXPECT_EQ(10, info.selectionEnd); 998 EXPECT_EQ(10, info.selectionEnd);
1001 EXPECT_EQ(8, info.compositionStart); 999 EXPECT_EQ(8, info.compositionStart);
1002 EXPECT_EQ(12, info.compositionEnd); 1000 EXPECT_EQ(12, info.compositionEnd);
1003 WebVector<WebCompositionUnderline> emptyUnderlines; 1001 WebVector<WebCompositionUnderline> emptyUnderlines;
1004 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); 1002 frame->setCompositionFromExistingText(0, 0, emptyUnderlines);
1005 info = webView->textInputInfo(); 1003 info = webView->textInputInfo();
1006 EXPECT_EQ(4, info.selectionStart); 1004 EXPECT_EQ(4, info.selectionStart);
1007 EXPECT_EQ(10, info.selectionEnd); 1005 EXPECT_EQ(10, info.selectionEnd);
(...skipping 10 matching lines...) Expand all
1018 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); 1016 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
1019 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 1017 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1020 frame->setEditableSelectionOffsets(27, 27); 1018 frame->setEditableSelectionOffsets(27, 27);
1021 std::string newLineText("\n"); 1019 std::string newLineText("\n");
1022 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); 1020 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str()));
1023 WebTextInputInfo info = webView->textInputInfo(); 1021 WebTextInputInfo info = webView->textInputInfo();
1024 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data())); 1022 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data()));
1025 1023
1026 frame->setEditableSelectionOffsets(31, 31); 1024 frame->setEditableSelectionOffsets(31, 31);
1027 frame->setCompositionFromExistingText(30, 34, underlines); 1025 frame->setCompositionFromExistingText(30, 34, underlines);
1028 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView) ->compositionUnderlines();
1029 EXPECT_EQ(2u, underlineResults[0].startOffset);
1030 EXPECT_EQ(6u, underlineResults[0].endOffset);
1031 info = webView->textInputInfo(); 1026 info = webView->textInputInfo();
1032 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data())); 1027 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u tf8().data()));
1033 EXPECT_EQ(31, info.selectionStart); 1028 EXPECT_EQ(31, info.selectionStart);
1034 EXPECT_EQ(31, info.selectionEnd); 1029 EXPECT_EQ(31, info.selectionEnd);
1035 EXPECT_EQ(30, info.compositionStart); 1030 EXPECT_EQ(30, info.compositionStart);
1036 EXPECT_EQ(34, info.compositionEnd); 1031 EXPECT_EQ(34, info.compositionEnd);
1037 1032
1038 std::string compositionText("yolo"); 1033 std::string compositionText("yolo");
1039 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); 1034 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str()));
1040 info = webView->textInputInfo(); 1035 info = webView->textInputInfo();
1041 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data())); 1036 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data()));
1042 EXPECT_EQ(34, info.selectionStart); 1037 EXPECT_EQ(34, info.selectionStart);
1043 EXPECT_EQ(34, info.selectionEnd); 1038 EXPECT_EQ(34, info.selectionEnd);
1044 EXPECT_EQ(-1, info.compositionStart); 1039 EXPECT_EQ(-1, info.compositionStart);
1045 EXPECT_EQ(-1, info.compositionEnd); 1040 EXPECT_EQ(-1, info.compositionEnd);
1046 } 1041 }
1047 1042
1043 TEST_F(WebViewTest, SetCompositionFromExistingTextInRichText)
1044 {
1045 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("content_editable_rich_text.html"));
1046 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_ed itable_rich_text.html");
1047 webView->setInitialFocus(false);
1048 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
1049 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
1050 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1051 frame->setEditableSelectionOffsets(1, 1);
1052 WebDocument document = webView->mainFrame()->document();
1053 EXPECT_FALSE(document.getElementById("bold").isNull());
1054 frame->setCompositionFromExistingText(0, 4, underlines);
1055 EXPECT_FALSE(document.getElementById("bold").isNull());
1056 }
1057
1048 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) 1058 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
1049 { 1059 {
1050 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 1060 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1051 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 1061 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
1052 webView->setInitialFocus(false); 1062 webView->setInitialFocus(false);
1053 1063
1054 std::string compositionTextFirst("hello "); 1064 std::string compositionTextFirst("hello ");
1055 std::string compositionTextSecond("world"); 1065 std::string compositionTextSecond("world");
1056 WebVector<WebCompositionUnderline> emptyUnderlines; 1066 WebVector<WebCompositionUnderline> emptyUnderlines;
1057 1067
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 WebTextInputInfo info = webView->textInputInfo(); 1676 WebTextInputInfo info = webView->textInputInfo();
1667 EXPECT_EQ(4, info.selectionStart); 1677 EXPECT_EQ(4, info.selectionStart);
1668 EXPECT_EQ(10, info.selectionEnd); 1678 EXPECT_EQ(10, info.selectionEnd);
1669 EXPECT_EQ(8, info.compositionStart); 1679 EXPECT_EQ(8, info.compositionStart);
1670 EXPECT_EQ(12, info.compositionEnd); 1680 EXPECT_EQ(12, info.compositionEnd);
1671 1681
1672 // Clear the focus and track that the subsequent composition commit does not trigger a 1682 // Clear the focus and track that the subsequent composition commit does not trigger a
1673 // text changed notification for autofill. 1683 // text changed notification for autofill.
1674 client.clearChangeCounts(); 1684 client.clearChangeCounts();
1675 webView->setFocus(false); 1685 webView->setFocus(false);
1676 EXPECT_EQ(1, client.textChangesWhileIgnored());
1677 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); 1686 EXPECT_EQ(0, client.textChangesWhileNotIgnored());
1678 1687
1679 frame->setAutofillClient(0); 1688 frame->setAutofillClient(0);
1680 } 1689 }
1681 1690
1682 static void verifySelectionAndComposition(WebView* webView, int selectionStart, int selectionEnd, int compositionStart, int compositionEnd, const char* failMess age) 1691 static void verifySelectionAndComposition(WebView* webView, int selectionStart, int selectionEnd, int compositionStart, int compositionEnd, const char* failMess age)
1683 { 1692 {
1684 WebTextInputInfo info = webView->textInputInfo(); 1693 WebTextInputInfo info = webView->textInputInfo();
1685 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage; 1694 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage;
1686 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage; 1695 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage;
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
3061 WebFrame* frame = mainWebView.webView()->mainFrame(); 3070 WebFrame* frame = mainWebView.webView()->mainFrame();
3062 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3071 v8::HandleScope scope(v8::Isolate::GetCurrent());
3063 v8::Local<v8::Value> v8Value = frame->executeScriptAndReturnValue(WebScriptS ource("var win = window.open('javascript:false'); win.document")); 3072 v8::Local<v8::Value> v8Value = frame->executeScriptAndReturnValue(WebScriptS ource("var win = window.open('javascript:false'); win.document"));
3064 ASSERT_TRUE(v8Value->IsObject()); 3073 ASSERT_TRUE(v8Value->IsObject());
3065 Document* document = V8Document::toImplWithTypeCheck(v8::Isolate::GetCurrent (), v8Value); 3074 Document* document = V8Document::toImplWithTypeCheck(v8::Isolate::GetCurrent (), v8Value);
3066 ASSERT_TRUE(document); 3075 ASSERT_TRUE(document);
3067 EXPECT_FALSE(document->frame()->isLoading()); 3076 EXPECT_FALSE(document->frame()->isLoading());
3068 } 3077 }
3069 3078
3070 } // namespace blink 3079 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/content_editable_rich_text.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698