From 1c7f1420b78f37ec1619ab1552261e9ce3947a3b Mon Sep 17 00:00:00 2001 From: Diana Gage Date: Mon, 24 Jul 2017 11:19:52 -0700 Subject: Add FORM_DeleteSelectedText() and embedder tests. This method deletes the current text selection in a form text field or user-editable form combobox text field. If there is no selection, this method does nothing. BUG=chromium:59266 Change-Id: I3229ffad990c62beac1cf769cd366458b9ee5daa Reviewed-on: https://pdfium-review.googlesource.com/8370 Reviewed-by: Lei Zhang Commit-Queue: Diana Gage --- fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp') diff --git a/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp b/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp index 9ca994f2e1..3224284ee2 100644 --- a/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp +++ b/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp @@ -194,3 +194,75 @@ TEST_F(CPWLComboBoxEditEmbeddertest, GetSelectedTextFragmentsEditable) { GetCPWLComboBox()->SetEditSelection(49, 50); EXPECT_STREQ(L"r", GetCPWLComboBox()->GetSelectedText().c_str()); } + +TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEntireTextSelection) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); + for (int i = 0; i < 50; ++i) { + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0)); + } + + GetCPWLComboBox()->SetEditSelection(0, -1); + EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", + GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->DeleteSelectedText(); + EXPECT_TRUE(GetCPWLComboBox()->GetText().IsEmpty()); +} + +TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionMiddle) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); + for (int i = 0; i < 50; ++i) { + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0)); + } + + GetCPWLComboBox()->SetEditSelection(12, 23); + EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->DeleteSelectedText(); + EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr", + GetCPWLComboBox()->GetText().c_str()); +} + +TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionLeft) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); + for (int i = 0; i < 50; ++i) { + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0)); + } + + GetCPWLComboBox()->SetEditSelection(0, 5); + EXPECT_STREQ(L"ABCDE", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->DeleteSelectedText(); + EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", + GetCPWLComboBox()->GetText().c_str()); +} + +TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionRight) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); + for (int i = 0; i < 50; ++i) { + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0)); + } + + GetCPWLComboBox()->SetEditSelection(45, 50); + EXPECT_STREQ(L"nopqr", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->DeleteSelectedText(); + EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm", + GetCPWLComboBox()->GetText().c_str()); +} + +TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEmptyTextSelection) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); + for (int i = 0; i < 50; ++i) { + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0)); + } + + GetCPWLComboBox()->DeleteSelectedText(); + EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", + GetCPWLComboBox()->GetText().c_str()); +} -- cgit v1.2.3