summaryrefslogtreecommitdiff
path: root/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
diff options
context:
space:
mode:
authorDiana Gage <drgage@google.com>2017-07-28 17:07:39 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-07-31 21:43:06 +0000
commitab3909796cf2e9fa192040bcd7cb9da7bb3328a5 (patch)
treec4b3d336aa8d3539794ec0a9740cb9d78a7b0af8 /fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
parent47c9e6d1a151c7c8b0649712a91e04f12177b7b9 (diff)
downloadpdfium-ab3909796cf2e9fa192040bcd7cb9da7bb3328a5.tar.xz
Add FORM_ReplaceSelection() and embedder tests.
This method replaces the selected text in a user-editable form text area with another text string (which can be empty or non-empty). If there is no selected text, FORM_ReplaceSelection() will append the replacement text after the current caret position. BUG=chromium:59266 Change-Id: I76448ef757d107888c33ebd5656457ebac93b952 Reviewed-on: https://pdfium-review.googlesource.com/8812 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Diana Gage <drgage@google.com>
Diffstat (limited to 'fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp')
-rw-r--r--fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp97
1 files changed, 92 insertions, 5 deletions
diff --git a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
index 30fe32bc53..308ee4ac40 100644
--- a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
@@ -211,7 +211,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEntireTextSelection) {
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_TRUE(GetCPWLComboBox()->GetText().IsEmpty());
}
@@ -222,7 +222,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionMiddle) {
GetCPWLComboBox()->SetEditSelection(12, 23);
EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetText().c_str());
}
@@ -234,7 +234,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionLeft) {
GetCPWLComboBox()->SetEditSelection(0, 5);
EXPECT_STREQ(L"ABCDE", GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetText().c_str());
}
@@ -246,7 +246,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionRight) {
GetCPWLComboBox()->SetEditSelection(45, 50);
EXPECT_STREQ(L"nopqr", GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm",
GetCPWLComboBox()->GetText().c_str());
}
@@ -255,7 +255,94 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEmptyTextSelection) {
FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
TypeTextIntoTextField(50);
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetText().c_str());
}
+
+TEST_F(CPWLComboBoxEditEmbeddertest, InsertTextInEmptyEditableComboBox) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"Hello", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextInPopulatedEditableComboBoxLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ // Move cursor to beginning of user-editable combobox text field.
+ EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotUserEditable(),
+ FWL_VKEY_Home, 0));
+
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"HelloABCDEFGHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextInPopulatedEditableComboBoxMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ // Move cursor to middle of user-editable combobox text field.
+ for (int i = 0; i < 5; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotUserEditable(),
+ FWL_VKEY_Left, 0));
+ }
+
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEHelloFGHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextInPopulatedEditableComboBoxRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEFGHIJHello", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(0, -1);
+ EXPECT_STREQ(L"ABCDEFGHIJ", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"Hello", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(0, 5);
+ EXPECT_STREQ(L"ABCDE", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"HelloFGHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(2, 7);
+ EXPECT_STREQ(L"CDEFG", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABHelloHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(5, 10);
+ EXPECT_STREQ(L"FGHIJ", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEHello", GetCPWLComboBox()->GetText().c_str());
+}