Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 1 | // Copyright 2017 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Tom Sepez | d8ac668 | 2018-10-04 19:29:30 +0000 | [diff] [blame] | 5 | #include "fpdfsdk/pwl/cpwl_edit.h" |
| 6 | |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_annot.h" |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 8 | #include "fpdfsdk/cpdfsdk_annotiterator.h" |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 9 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 10 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
| 11 | #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" |
Lei Zhang | ac75664 | 2018-12-13 20:47:10 +0000 | [diff] [blame] | 12 | #include "public/fpdf_fwlevent.h" |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 13 | #include "testing/embedder_test.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 16 | class CPWLEditEmbedderTest : public EmbedderTest { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 17 | protected: |
| 18 | void SetUp() override { |
| 19 | EmbedderTest::SetUp(); |
| 20 | CreateAndInitializeFormPDF(); |
| 21 | } |
| 22 | |
| 23 | void TearDown() override { |
| 24 | UnloadPage(GetPage()); |
| 25 | EmbedderTest::TearDown(); |
| 26 | } |
| 27 | |
| 28 | void CreateAndInitializeFormPDF() { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 29 | EXPECT_TRUE(OpenDocument("text_form_multiple.pdf")); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 30 | m_page = LoadPage(0); |
| 31 | ASSERT_TRUE(m_page); |
| 32 | |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 33 | m_pFormFillEnv = |
| 34 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 35 | CPDFSDK_AnnotIterator iter(m_pFormFillEnv->GetPageView(0), |
| 36 | CPDF_Annot::Subtype::WIDGET); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 37 | // Normal text field. |
| 38 | m_pAnnot = iter.GetFirstAnnot(); |
| 39 | ASSERT_TRUE(m_pAnnot); |
| 40 | ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, m_pAnnot->GetAnnotSubtype()); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 41 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 42 | // Read-only text field. |
| 43 | CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnot); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 44 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 45 | // Pre-filled text field with char limit of 10. |
| 46 | m_pAnnotCharLimit = iter.GetNextAnnot(pAnnotReadOnly); |
| 47 | ASSERT_TRUE(m_pAnnotCharLimit); |
| 48 | ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, |
| 49 | m_pAnnotCharLimit->GetAnnotSubtype()); |
| 50 | CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot(); |
| 51 | ASSERT_EQ(m_pAnnotCharLimit, pLastAnnot); |
| 52 | } |
| 53 | |
| 54 | void FormFillerAndWindowSetup(CPDFSDK_Annot* pAnnotTextField) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 55 | CFFL_InteractiveFormFiller* pInteractiveFormFiller = |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 56 | m_pFormFillEnv->GetInteractiveFormFiller(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 57 | { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 58 | CPDFSDK_Annot::ObservedPtr pObserved(pAnnotTextField); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 59 | EXPECT_TRUE(pInteractiveFormFiller->OnSetFocus(&pObserved, 0)); |
| 60 | } |
| 61 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 62 | m_pFormFiller = |
| 63 | pInteractiveFormFiller->GetFormFiller(pAnnotTextField, false); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 64 | ASSERT_TRUE(m_pFormFiller); |
| 65 | |
| 66 | CPWL_Wnd* pWindow = |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 67 | m_pFormFiller->GetPDFWindow(m_pFormFillEnv->GetPageView(0), false); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 68 | ASSERT_TRUE(pWindow); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 69 | m_pEdit = static_cast<CPWL_Edit*>(pWindow); |
| 70 | } |
| 71 | |
Diana Gage | be38e16 | 2017-07-26 20:32:00 -0700 | [diff] [blame] | 72 | void TypeTextIntoTextField(int num_chars) { |
| 73 | // Type text starting with 'A' to as many chars as specified by |num_chars|. |
| 74 | for (int i = 0; i < num_chars; ++i) { |
| 75 | EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), i + 'A', 0)); |
| 76 | } |
| 77 | } |
| 78 | |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 79 | FPDF_PAGE GetPage() { return m_page; } |
| 80 | CPWL_Edit* GetCPWLEdit() { return m_pEdit; } |
| 81 | CFFL_FormFiller* GetCFFLFormFiller() { return m_pFormFiller; } |
| 82 | CPDFSDK_Annot* GetCPDFSDKAnnot() { return m_pAnnot; } |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 83 | CPDFSDK_Annot* GetCPDFSDKAnnotCharLimit() { return m_pAnnotCharLimit; } |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 84 | |
| 85 | private: |
| 86 | FPDF_PAGE m_page; |
| 87 | CPWL_Edit* m_pEdit; |
| 88 | CFFL_FormFiller* m_pFormFiller; |
| 89 | CPDFSDK_Annot* m_pAnnot; |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 90 | CPDFSDK_Annot* m_pAnnotCharLimit; |
| 91 | CPDFSDK_FormFillEnvironment* m_pFormFillEnv; |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 92 | }; |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 93 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 94 | TEST_F(CPWLEditEmbedderTest, TypeText) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 95 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 96 | EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty()); |
| 97 | EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'a', 0)); |
| 98 | EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'b', 0)); |
| 99 | EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'c', 0)); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 100 | |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 101 | EXPECT_STREQ(L"abc", GetCPWLEdit()->GetText().c_str()); |
| 102 | } |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 103 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 104 | TEST_F(CPWLEditEmbedderTest, GetSelectedTextEmptyAndBasic) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 105 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 106 | // Attempt to set selection before text has been typed to test that |
| 107 | // selection is identified as empty. |
| 108 | // |
| 109 | // Select from character index [0, 3) within form text field. |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 110 | GetCPWLEdit()->SetSelection(0, 3); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 111 | EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty()); |
| 112 | |
| 113 | EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'a', 0)); |
| 114 | EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'b', 0)); |
| 115 | EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'c', 0)); |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 116 | GetCPWLEdit()->SetSelection(0, 2); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 117 | |
| 118 | EXPECT_STREQ(L"ab", GetCPWLEdit()->GetSelectedText().c_str()); |
| 119 | } |
| 120 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 121 | TEST_F(CPWLEditEmbedderTest, GetSelectedTextFragments) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 122 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | be38e16 | 2017-07-26 20:32:00 -0700 | [diff] [blame] | 123 | TypeTextIntoTextField(50); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 124 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 125 | GetCPWLEdit()->SetSelection(0, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 126 | EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty()); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 127 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 128 | GetCPWLEdit()->SetSelection(0, 1); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 129 | EXPECT_STREQ(L"A", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 130 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 131 | GetCPWLEdit()->SetSelection(0, -1); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 132 | EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", |
| 133 | GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 134 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 135 | GetCPWLEdit()->SetSelection(-8, -1); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 136 | EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty()); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 137 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 138 | GetCPWLEdit()->SetSelection(23, 12); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 139 | EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 140 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 141 | GetCPWLEdit()->SetSelection(12, 23); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 142 | EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 143 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 144 | GetCPWLEdit()->SetSelection(49, 50); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 145 | EXPECT_STREQ(L"r", GetCPWLEdit()->GetSelectedText().c_str()); |
Diana Gage | a37f2f1 | 2017-07-25 17:39:50 -0700 | [diff] [blame] | 146 | |
| 147 | GetCPWLEdit()->SetSelection(49, 55); |
| 148 | EXPECT_STREQ(L"r", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | af680b1 | 2017-06-02 16:42:59 -0700 | [diff] [blame] | 149 | } |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 150 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 151 | TEST_F(CPWLEditEmbedderTest, DeleteEntireTextSelection) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 152 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | be38e16 | 2017-07-26 20:32:00 -0700 | [diff] [blame] | 153 | TypeTextIntoTextField(50); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 154 | |
| 155 | GetCPWLEdit()->SetSelection(0, -1); |
| 156 | EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", |
| 157 | GetCPWLEdit()->GetSelectedText().c_str()); |
| 158 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 159 | GetCPWLEdit()->ReplaceSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 160 | EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty()); |
| 161 | } |
| 162 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 163 | TEST_F(CPWLEditEmbedderTest, DeleteTextSelectionMiddle) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 164 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | be38e16 | 2017-07-26 20:32:00 -0700 | [diff] [blame] | 165 | TypeTextIntoTextField(50); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 166 | |
| 167 | GetCPWLEdit()->SetSelection(12, 23); |
| 168 | EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str()); |
| 169 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 170 | GetCPWLEdit()->ReplaceSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 171 | EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr", |
| 172 | GetCPWLEdit()->GetText().c_str()); |
| 173 | } |
| 174 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 175 | TEST_F(CPWLEditEmbedderTest, DeleteTextSelectionLeft) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 176 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | be38e16 | 2017-07-26 20:32:00 -0700 | [diff] [blame] | 177 | TypeTextIntoTextField(50); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 178 | |
| 179 | GetCPWLEdit()->SetSelection(0, 5); |
| 180 | EXPECT_STREQ(L"ABCDE", GetCPWLEdit()->GetSelectedText().c_str()); |
| 181 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 182 | GetCPWLEdit()->ReplaceSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 183 | EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", |
| 184 | GetCPWLEdit()->GetText().c_str()); |
| 185 | } |
| 186 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 187 | TEST_F(CPWLEditEmbedderTest, DeleteTextSelectionRight) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 188 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | be38e16 | 2017-07-26 20:32:00 -0700 | [diff] [blame] | 189 | TypeTextIntoTextField(50); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 190 | |
| 191 | GetCPWLEdit()->SetSelection(45, 50); |
| 192 | EXPECT_STREQ(L"nopqr", GetCPWLEdit()->GetSelectedText().c_str()); |
| 193 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 194 | GetCPWLEdit()->ReplaceSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 195 | EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm", |
| 196 | GetCPWLEdit()->GetText().c_str()); |
| 197 | } |
| 198 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 199 | TEST_F(CPWLEditEmbedderTest, DeleteEmptyTextSelection) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 200 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Diana Gage | be38e16 | 2017-07-26 20:32:00 -0700 | [diff] [blame] | 201 | TypeTextIntoTextField(50); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 202 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 203 | GetCPWLEdit()->ReplaceSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 204 | EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", |
| 205 | GetCPWLEdit()->GetText().c_str()); |
| 206 | } |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 207 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 208 | TEST_F(CPWLEditEmbedderTest, InsertTextInEmptyTextField) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 209 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 210 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 211 | EXPECT_STREQ(L"Hello", GetCPWLEdit()->GetText().c_str()); |
| 212 | } |
| 213 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 214 | TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedTextFieldLeft) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 215 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 216 | TypeTextIntoTextField(10); |
| 217 | |
| 218 | // Move cursor to beginning of text field. |
| 219 | EXPECT_TRUE( |
| 220 | GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnot(), FWL_VKEY_Home, 0)); |
| 221 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 222 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 223 | EXPECT_STREQ(L"HelloABCDEFGHIJ", GetCPWLEdit()->GetText().c_str()); |
| 224 | } |
| 225 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 226 | TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedTextFieldMiddle) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 227 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 228 | TypeTextIntoTextField(10); |
| 229 | |
| 230 | // Move cursor to middle of text field. |
| 231 | for (int i = 0; i < 5; ++i) { |
| 232 | EXPECT_TRUE( |
| 233 | GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnot(), FWL_VKEY_Left, 0)); |
| 234 | } |
| 235 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 236 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 237 | EXPECT_STREQ(L"ABCDEHelloFGHIJ", GetCPWLEdit()->GetText().c_str()); |
| 238 | } |
| 239 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 240 | TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedTextFieldRight) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 241 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 242 | TypeTextIntoTextField(10); |
| 243 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 244 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 245 | EXPECT_STREQ(L"ABCDEFGHIJHello", GetCPWLEdit()->GetText().c_str()); |
| 246 | } |
| 247 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 248 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 249 | InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) { |
| 250 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 251 | TypeTextIntoTextField(10); |
| 252 | |
| 253 | GetCPWLEdit()->SetSelection(0, -1); |
| 254 | EXPECT_STREQ(L"ABCDEFGHIJ", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 255 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 256 | EXPECT_STREQ(L"Hello", GetCPWLEdit()->GetText().c_str()); |
| 257 | } |
| 258 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 259 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 260 | InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) { |
| 261 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 262 | TypeTextIntoTextField(10); |
| 263 | |
| 264 | GetCPWLEdit()->SetSelection(0, 5); |
| 265 | EXPECT_STREQ(L"ABCDE", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 266 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 267 | EXPECT_STREQ(L"HelloFGHIJ", GetCPWLEdit()->GetText().c_str()); |
| 268 | } |
| 269 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 270 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 271 | InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) { |
| 272 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 273 | TypeTextIntoTextField(10); |
| 274 | |
| 275 | GetCPWLEdit()->SetSelection(2, 7); |
| 276 | EXPECT_STREQ(L"CDEFG", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 277 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 278 | EXPECT_STREQ(L"ABHelloHIJ", GetCPWLEdit()->GetText().c_str()); |
| 279 | } |
| 280 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 281 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 282 | InsertTextAndReplaceSelectionInPopulatedTextFieldRight) { |
| 283 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 284 | TypeTextIntoTextField(10); |
| 285 | |
| 286 | GetCPWLEdit()->SetSelection(5, 10); |
| 287 | EXPECT_STREQ(L"FGHIJ", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 288 | GetCPWLEdit()->ReplaceSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 289 | EXPECT_STREQ(L"ABCDEHello", GetCPWLEdit()->GetText().c_str()); |
| 290 | } |
| 291 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 292 | TEST_F(CPWLEditEmbedderTest, InsertTextInEmptyCharLimitTextFieldOverflow) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 293 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 294 | GetCPWLEdit()->SetSelection(0, -1); |
| 295 | EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 296 | GetCPWLEdit()->ReplaceSelection(L""); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 297 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 298 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 299 | EXPECT_STREQ(L"Hippopotam", GetCPWLEdit()->GetText().c_str()); |
| 300 | } |
| 301 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 302 | TEST_F(CPWLEditEmbedderTest, InsertTextInEmptyCharLimitTextFieldFit) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 303 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 304 | GetCPWLEdit()->SetSelection(0, -1); |
| 305 | EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 306 | GetCPWLEdit()->ReplaceSelection(L""); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 307 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 308 | GetCPWLEdit()->ReplaceSelection(L"Zebra"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 309 | EXPECT_STREQ(L"Zebra", GetCPWLEdit()->GetText().c_str()); |
| 310 | } |
| 311 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 312 | TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedCharLimitTextFieldLeft) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 313 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 314 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 315 | EXPECT_STREQ(L"HiElephant", GetCPWLEdit()->GetText().c_str()); |
| 316 | } |
| 317 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 318 | TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedCharLimitTextFieldMiddle) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 319 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 320 | // Move cursor to middle of text field. |
| 321 | for (int i = 0; i < 5; ++i) { |
| 322 | EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotCharLimit(), |
| 323 | FWL_VKEY_Right, 0)); |
| 324 | } |
| 325 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 326 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 327 | EXPECT_STREQ(L"ElephHiant", GetCPWLEdit()->GetText().c_str()); |
| 328 | } |
| 329 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 330 | TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedCharLimitTextFieldRight) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 331 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 332 | // Move cursor to end of text field. |
| 333 | EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotCharLimit(), |
| 334 | FWL_VKEY_End, 0)); |
| 335 | |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 336 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 337 | EXPECT_STREQ(L"ElephantHi", GetCPWLEdit()->GetText().c_str()); |
| 338 | } |
| 339 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 340 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 341 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) { |
| 342 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 343 | GetCPWLEdit()->SetSelection(0, -1); |
| 344 | EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 345 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 346 | EXPECT_STREQ(L"Hippopotam", GetCPWLEdit()->GetText().c_str()); |
| 347 | } |
| 348 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 349 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 350 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) { |
| 351 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 352 | GetCPWLEdit()->SetSelection(0, 4); |
| 353 | EXPECT_STREQ(L"Elep", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 354 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 355 | EXPECT_STREQ(L"Hippophant", GetCPWLEdit()->GetText().c_str()); |
| 356 | } |
| 357 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 358 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 359 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) { |
| 360 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 361 | GetCPWLEdit()->SetSelection(2, 6); |
| 362 | EXPECT_STREQ(L"epha", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 363 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 364 | EXPECT_STREQ(L"ElHippopnt", GetCPWLEdit()->GetText().c_str()); |
| 365 | } |
| 366 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 367 | TEST_F(CPWLEditEmbedderTest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 368 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) { |
| 369 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 370 | GetCPWLEdit()->SetSelection(4, 8); |
| 371 | EXPECT_STREQ(L"hant", GetCPWLEdit()->GetSelectedText().c_str()); |
Lei Zhang | 38adfc1 | 2017-08-25 22:05:18 -0700 | [diff] [blame] | 372 | GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 373 | EXPECT_STREQ(L"ElepHippop", GetCPWLEdit()->GetText().c_str()); |
| 374 | } |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 375 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 376 | TEST_F(CPWLEditEmbedderTest, SetTextWithEndCarriageFeed) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 377 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 378 | GetCPWLEdit()->SetText(L"Foo\r"); |
| 379 | EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str()); |
| 380 | } |
| 381 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 382 | TEST_F(CPWLEditEmbedderTest, SetTextWithEndNewline) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 383 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 384 | GetCPWLEdit()->SetText(L"Foo\n"); |
| 385 | EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str()); |
| 386 | } |
| 387 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 388 | TEST_F(CPWLEditEmbedderTest, SetTextWithEndCarriageFeedAndNewLine) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 389 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 390 | GetCPWLEdit()->SetText(L"Foo\r\n"); |
| 391 | EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str()); |
| 392 | } |
| 393 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 394 | TEST_F(CPWLEditEmbedderTest, SetTextWithEndNewLineAndCarriageFeed) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 395 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 396 | GetCPWLEdit()->SetText(L"Foo\n\r"); |
| 397 | EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str()); |
| 398 | } |
| 399 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 400 | TEST_F(CPWLEditEmbedderTest, SetTextWithBodyCarriageFeed) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 401 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 402 | GetCPWLEdit()->SetText(L"Foo\rBar"); |
| 403 | EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str()); |
| 404 | } |
| 405 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 406 | TEST_F(CPWLEditEmbedderTest, SetTextWithBodyNewline) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 407 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 408 | GetCPWLEdit()->SetText(L"Foo\nBar"); |
| 409 | EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str()); |
| 410 | } |
| 411 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 412 | TEST_F(CPWLEditEmbedderTest, SetTextWithBodyCarriageFeedAndNewLine) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 413 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 414 | GetCPWLEdit()->SetText(L"Foo\r\nBar"); |
| 415 | EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str()); |
| 416 | } |
| 417 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame^] | 418 | TEST_F(CPWLEditEmbedderTest, SetTextWithBodyNewLineAndCarriageFeed) { |
Ryan Harrison | f8763bb | 2017-08-31 14:22:39 -0400 | [diff] [blame] | 419 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 420 | GetCPWLEdit()->SetText(L"Foo\n\rBar"); |
| 421 | EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str()); |
| 422 | } |