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