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

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

Issue 23848007: Fixing the bounds check in cancelCompositionIfSelectionIsInvalid. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adding a test Created 7 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/core/editing/InputMethodController.cpp ('k') | no next file » | 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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); 676 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str()));
677 info = webView->textInputInfo(); 677 info = webView->textInputInfo();
678 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data())); 678 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u tf8().data()));
679 EXPECT_EQ(34, info.selectionStart); 679 EXPECT_EQ(34, info.selectionStart);
680 EXPECT_EQ(34, info.selectionEnd); 680 EXPECT_EQ(34, info.selectionEnd);
681 EXPECT_EQ(-1, info.compositionStart); 681 EXPECT_EQ(-1, info.compositionStart);
682 EXPECT_EQ(-1, info.compositionEnd); 682 EXPECT_EQ(-1, info.compositionEnd);
683 webView->close(); 683 webView->close();
684 } 684 }
685 685
686 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
687 {
688 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
689 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input _field_populated.html");
690 webView->setInitialFocus(false);
691
692 std::string compositionTextFirst("hello ");
693 std::string compositionTextSecond("world");
694 WebVector<WebCompositionUnderline> emptyUnderlines;
695
696 webView->confirmComposition(WebString::fromUTF8(compositionTextFirst.c_str() ));
697 webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, 5);
698
699 WebTextInputInfo info = webView->textInputInfo();
700 EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
701 EXPECT_EQ(11, info.selectionStart);
702 EXPECT_EQ(11, info.selectionEnd);
703 EXPECT_EQ(6, info.compositionStart);
704 EXPECT_EQ(11, info.compositionEnd);
705
706 webView->setEditableSelectionOffsets(6, 6);
707 info = webView->textInputInfo();
708 EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
709 EXPECT_EQ(6, info.selectionStart);
710 EXPECT_EQ(6, info.selectionEnd);
711 EXPECT_EQ(6, info.compositionStart);
712 EXPECT_EQ(11, info.compositionEnd);
713
714 webView->setEditableSelectionOffsets(8, 8);
715 info = webView->textInputInfo();
716 EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
717 EXPECT_EQ(8, info.selectionStart);
718 EXPECT_EQ(8, info.selectionEnd);
719 EXPECT_EQ(6, info.compositionStart);
720 EXPECT_EQ(11, info.compositionEnd);
721
722 webView->setEditableSelectionOffsets(2, 2);
yosin_UTC9 2013/09/06 01:17:55 Please add test case for moving selection offset t
aurimas (slooooooooow) 2013/09/06 01:25:35 Done.
723 info = webView->textInputInfo();
724 EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
725 EXPECT_EQ(2, info.selectionStart);
726 EXPECT_EQ(2, info.selectionEnd);
727 EXPECT_EQ(-1, info.compositionStart);
728 EXPECT_EQ(-1, info.compositionEnd);
729 webView->close();
730 }
731
686 TEST_F(WebViewTest, IsSelectionAnchorFirst) 732 TEST_F(WebViewTest, IsSelectionAnchorFirst)
687 { 733 {
688 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 734 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
689 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input _field_populated.html"); 735 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input _field_populated.html");
690 WebFrame* frame = webView->mainFrame(); 736 WebFrame* frame = webView->mainFrame();
691 737
692 webView->setInitialFocus(false); 738 webView->setInitialFocus(false);
693 webView->setEditableSelectionOffsets(4, 10); 739 webView->setEditableSelectionOffsets(4, 10);
694 EXPECT_TRUE(webView->isSelectionAnchorFirst()); 740 EXPECT_TRUE(webView->isSelectionAnchorFirst());
695 WebRect anchor; 741 WebRect anchor;
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 WebHelperPluginImpl* helperPlugin = webViewImpl->createHelperPlugin("dummy-p lugin-type", frame->document()); 1191 WebHelperPluginImpl* helperPlugin = webViewImpl->createHelperPlugin("dummy-p lugin-type", frame->document());
1146 EXPECT_TRUE(helperPlugin); 1192 EXPECT_TRUE(helperPlugin);
1147 EXPECT_EQ(0, helperPlugin->getPlugin()); // Invalid plugin type means no plu gin. 1193 EXPECT_EQ(0, helperPlugin->getPlugin()); // Invalid plugin type means no plu gin.
1148 1194
1149 webViewImpl->closeHelperPluginSoon(helperPlugin); 1195 webViewImpl->closeHelperPluginSoon(helperPlugin);
1150 1196
1151 webViewImpl->close(); 1197 webViewImpl->close();
1152 } 1198 }
1153 1199
1154 } 1200 }
OLDNEW
« no previous file with comments | « Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698