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 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 158 | GetCPWLEdit()->ReplaceSelection(CFX_WideString()); |
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 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 169 | GetCPWLEdit()->ReplaceSelection(CFX_WideString()); |
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 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 181 | GetCPWLEdit()->ReplaceSelection(CFX_WideString()); |
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 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 193 | GetCPWLEdit()->ReplaceSelection(CFX_WideString()); |
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 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 202 | GetCPWLEdit()->ReplaceSelection(CFX_WideString()); |
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()); |
| 209 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 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 | |
| 221 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 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 | |
| 235 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 236 | EXPECT_STREQ(L"ABCDEHelloFGHIJ", GetCPWLEdit()->GetText().c_str()); |
| 237 | } |
| 238 | |
| 239 | TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedTextFieldRight) { |
| 240 | FormFillerAndWindowSetup(GetCPDFSDKAnnot()); |
| 241 | TypeTextIntoTextField(10); |
| 242 | |
| 243 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 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()); |
| 254 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 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()); |
| 265 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 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()); |
| 276 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 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()); |
| 287 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello")); |
| 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()); |
| 295 | GetCPWLEdit()->ReplaceSelection(CFX_WideString()); |
| 296 | |
| 297 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 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()); |
| 305 | GetCPWLEdit()->ReplaceSelection(CFX_WideString()); |
| 306 | |
| 307 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Zebra")); |
| 308 | EXPECT_STREQ(L"Zebra", GetCPWLEdit()->GetText().c_str()); |
| 309 | } |
| 310 | |
| 311 | TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedCharLimitTextFieldLeft) { |
| 312 | FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); |
| 313 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 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 | |
| 325 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 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 | |
| 335 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 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()); |
| 344 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 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()); |
| 353 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 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()); |
| 362 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 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()); |
| 371 | GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus")); |
| 372 | EXPECT_STREQ(L"ElepHippop", GetCPWLEdit()->GetText().c_str()); |
| 373 | } |