blob: b3f0d5dc0ebd454369ecc3dcb695dbb3554e2112 [file] [log] [blame]
Lei Zhangaf680b12017-06-02 16:42:59 -07001// 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 Sinclairc411eb92017-07-25 09:39:30 -040010#include "fpdfsdk/pwl/cpwl_wnd.h"
Lei Zhangaf680b12017-06-02 16:42:59 -070011#include "testing/embedder_test.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
Diana Gagedce2d722017-06-20 11:17:11 -070014class 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 Gageab390972017-07-28 17:07:39 -070027 EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
Diana Gagedce2d722017-06-20 11:17:11 -070028 m_page = LoadPage(0);
29 ASSERT_TRUE(m_page);
30
Diana Gageab390972017-07-28 17:07:39 -070031 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 Gagedce2d722017-06-20 11:17:11 -070038
Diana Gageab390972017-07-28 17:07:39 -070039 // Read-only text field.
40 CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnot);
Diana Gagedce2d722017-06-20 11:17:11 -070041
Diana Gageab390972017-07-28 17:07:39 -070042 // 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 Gagedce2d722017-06-20 11:17:11 -070052 CFFL_InteractiveFormFiller* pInteractiveFormFiller =
Diana Gageab390972017-07-28 17:07:39 -070053 m_pFormFillEnv->GetInteractiveFormFiller();
Diana Gagedce2d722017-06-20 11:17:11 -070054 {
Diana Gageab390972017-07-28 17:07:39 -070055 CPDFSDK_Annot::ObservedPtr pObserved(pAnnotTextField);
Diana Gagedce2d722017-06-20 11:17:11 -070056 EXPECT_TRUE(pInteractiveFormFiller->OnSetFocus(&pObserved, 0));
57 }
58
Diana Gageab390972017-07-28 17:07:39 -070059 m_pFormFiller =
60 pInteractiveFormFiller->GetFormFiller(pAnnotTextField, false);
Diana Gagedce2d722017-06-20 11:17:11 -070061 ASSERT_TRUE(m_pFormFiller);
62
63 CPWL_Wnd* pWindow =
Diana Gageab390972017-07-28 17:07:39 -070064 m_pFormFiller->GetPDFWindow(m_pFormFillEnv->GetPageView(0), false);
Diana Gagedce2d722017-06-20 11:17:11 -070065 ASSERT_TRUE(pWindow);
66 ASSERT_EQ(PWL_CLASSNAME_EDIT, pWindow->GetClassName());
67
68 m_pEdit = static_cast<CPWL_Edit*>(pWindow);
69 }
70
Diana Gagebe38e162017-07-26 20:32:00 -070071 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 Gagedce2d722017-06-20 11:17:11 -070078 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 Gageab390972017-07-28 17:07:39 -070082 CPDFSDK_Annot* GetCPDFSDKAnnotCharLimit() { return m_pAnnotCharLimit; }
Diana Gagedce2d722017-06-20 11:17:11 -070083
84 private:
85 FPDF_PAGE m_page;
86 CPWL_Edit* m_pEdit;
87 CFFL_FormFiller* m_pFormFiller;
88 CPDFSDK_Annot* m_pAnnot;
Diana Gageab390972017-07-28 17:07:39 -070089 CPDFSDK_Annot* m_pAnnotCharLimit;
90 CPDFSDK_FormFillEnvironment* m_pFormFillEnv;
Diana Gagedce2d722017-06-20 11:17:11 -070091};
Lei Zhangaf680b12017-06-02 16:42:59 -070092
93TEST_F(CPWLEditEmbeddertest, TypeText) {
Diana Gageab390972017-07-28 17:07:39 -070094 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagedce2d722017-06-20 11:17:11 -070095 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 Zhangaf680b12017-06-02 16:42:59 -070099
Diana Gagedce2d722017-06-20 11:17:11 -0700100 EXPECT_STREQ(L"abc", GetCPWLEdit()->GetText().c_str());
101}
Lei Zhangaf680b12017-06-02 16:42:59 -0700102
Diana Gagedce2d722017-06-20 11:17:11 -0700103TEST_F(CPWLEditEmbeddertest, GetSelectedTextEmptyAndBasic) {
Diana Gageab390972017-07-28 17:07:39 -0700104 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagedce2d722017-06-20 11:17:11 -0700105 // 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 Gage4d02e902017-07-20 17:20:31 -0700109 GetCPWLEdit()->SetSelection(0, 3);
Diana Gagedce2d722017-06-20 11:17:11 -0700110 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 Gage4d02e902017-07-20 17:20:31 -0700115 GetCPWLEdit()->SetSelection(0, 2);
Diana Gagedce2d722017-06-20 11:17:11 -0700116
117 EXPECT_STREQ(L"ab", GetCPWLEdit()->GetSelectedText().c_str());
118}
119
120TEST_F(CPWLEditEmbeddertest, GetSelectedTextFragments) {
Diana Gageab390972017-07-28 17:07:39 -0700121 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagebe38e162017-07-26 20:32:00 -0700122 TypeTextIntoTextField(50);
Lei Zhangaf680b12017-06-02 16:42:59 -0700123
Diana Gage4d02e902017-07-20 17:20:31 -0700124 GetCPWLEdit()->SetSelection(0, 0);
Diana Gagedce2d722017-06-20 11:17:11 -0700125 EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty());
Lei Zhangaf680b12017-06-02 16:42:59 -0700126
Diana Gage4d02e902017-07-20 17:20:31 -0700127 GetCPWLEdit()->SetSelection(0, 1);
Diana Gagedce2d722017-06-20 11:17:11 -0700128 EXPECT_STREQ(L"A", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhangaf680b12017-06-02 16:42:59 -0700129
Diana Gage4d02e902017-07-20 17:20:31 -0700130 GetCPWLEdit()->SetSelection(0, -1);
Diana Gagedce2d722017-06-20 11:17:11 -0700131 EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
132 GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhangaf680b12017-06-02 16:42:59 -0700133
Diana Gage4d02e902017-07-20 17:20:31 -0700134 GetCPWLEdit()->SetSelection(-8, -1);
Diana Gagedce2d722017-06-20 11:17:11 -0700135 EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty());
Lei Zhangaf680b12017-06-02 16:42:59 -0700136
Diana Gage4d02e902017-07-20 17:20:31 -0700137 GetCPWLEdit()->SetSelection(23, 12);
Diana Gagedce2d722017-06-20 11:17:11 -0700138 EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhangaf680b12017-06-02 16:42:59 -0700139
Diana Gage4d02e902017-07-20 17:20:31 -0700140 GetCPWLEdit()->SetSelection(12, 23);
Diana Gagedce2d722017-06-20 11:17:11 -0700141 EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhangaf680b12017-06-02 16:42:59 -0700142
Diana Gage4d02e902017-07-20 17:20:31 -0700143 GetCPWLEdit()->SetSelection(49, 50);
Diana Gagedce2d722017-06-20 11:17:11 -0700144 EXPECT_STREQ(L"r", GetCPWLEdit()->GetSelectedText().c_str());
Diana Gagea37f2f12017-07-25 17:39:50 -0700145
146 GetCPWLEdit()->SetSelection(49, 55);
147 EXPECT_STREQ(L"r", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhangaf680b12017-06-02 16:42:59 -0700148}
Diana Gage1c7f1422017-07-24 11:19:52 -0700149
150TEST_F(CPWLEditEmbeddertest, DeleteEntireTextSelection) {
Diana Gageab390972017-07-28 17:07:39 -0700151 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagebe38e162017-07-26 20:32:00 -0700152 TypeTextIntoTextField(50);
Diana Gage1c7f1422017-07-24 11:19:52 -0700153
154 GetCPWLEdit()->SetSelection(0, -1);
155 EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
156 GetCPWLEdit()->GetSelectedText().c_str());
157
Lei Zhang38adfc12017-08-25 22:05:18 -0700158 GetCPWLEdit()->ReplaceSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700159 EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty());
160}
161
162TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionMiddle) {
Diana Gageab390972017-07-28 17:07:39 -0700163 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagebe38e162017-07-26 20:32:00 -0700164 TypeTextIntoTextField(50);
Diana Gage1c7f1422017-07-24 11:19:52 -0700165
166 GetCPWLEdit()->SetSelection(12, 23);
167 EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str());
168
Lei Zhang38adfc12017-08-25 22:05:18 -0700169 GetCPWLEdit()->ReplaceSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700170 EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr",
171 GetCPWLEdit()->GetText().c_str());
172}
173
174TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionLeft) {
Diana Gageab390972017-07-28 17:07:39 -0700175 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagebe38e162017-07-26 20:32:00 -0700176 TypeTextIntoTextField(50);
Diana Gage1c7f1422017-07-24 11:19:52 -0700177
178 GetCPWLEdit()->SetSelection(0, 5);
179 EXPECT_STREQ(L"ABCDE", GetCPWLEdit()->GetSelectedText().c_str());
180
Lei Zhang38adfc12017-08-25 22:05:18 -0700181 GetCPWLEdit()->ReplaceSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700182 EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
183 GetCPWLEdit()->GetText().c_str());
184}
185
186TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionRight) {
Diana Gageab390972017-07-28 17:07:39 -0700187 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagebe38e162017-07-26 20:32:00 -0700188 TypeTextIntoTextField(50);
Diana Gage1c7f1422017-07-24 11:19:52 -0700189
190 GetCPWLEdit()->SetSelection(45, 50);
191 EXPECT_STREQ(L"nopqr", GetCPWLEdit()->GetSelectedText().c_str());
192
Lei Zhang38adfc12017-08-25 22:05:18 -0700193 GetCPWLEdit()->ReplaceSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700194 EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm",
195 GetCPWLEdit()->GetText().c_str());
196}
197
198TEST_F(CPWLEditEmbeddertest, DeleteEmptyTextSelection) {
Diana Gageab390972017-07-28 17:07:39 -0700199 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Diana Gagebe38e162017-07-26 20:32:00 -0700200 TypeTextIntoTextField(50);
Diana Gage1c7f1422017-07-24 11:19:52 -0700201
Lei Zhang38adfc12017-08-25 22:05:18 -0700202 GetCPWLEdit()->ReplaceSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700203 EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
204 GetCPWLEdit()->GetText().c_str());
205}
Diana Gageab390972017-07-28 17:07:39 -0700206
207TEST_F(CPWLEditEmbeddertest, InsertTextInEmptyTextField) {
208 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
Lei Zhang38adfc12017-08-25 22:05:18 -0700209 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700210 EXPECT_STREQ(L"Hello", GetCPWLEdit()->GetText().c_str());
211}
212
213TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700221 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700222 EXPECT_STREQ(L"HelloABCDEFGHIJ", GetCPWLEdit()->GetText().c_str());
223}
224
225TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700235 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700236 EXPECT_STREQ(L"ABCDEHelloFGHIJ", GetCPWLEdit()->GetText().c_str());
237}
238
239TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedTextFieldRight) {
240 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
241 TypeTextIntoTextField(10);
242
Lei Zhang38adfc12017-08-25 22:05:18 -0700243 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700244 EXPECT_STREQ(L"ABCDEFGHIJHello", GetCPWLEdit()->GetText().c_str());
245}
246
247TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700254 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700255 EXPECT_STREQ(L"Hello", GetCPWLEdit()->GetText().c_str());
256}
257
258TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700265 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700266 EXPECT_STREQ(L"HelloFGHIJ", GetCPWLEdit()->GetText().c_str());
267}
268
269TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700276 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700277 EXPECT_STREQ(L"ABHelloHIJ", GetCPWLEdit()->GetText().c_str());
278}
279
280TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700287 GetCPWLEdit()->ReplaceSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700288 EXPECT_STREQ(L"ABCDEHello", GetCPWLEdit()->GetText().c_str());
289}
290
291TEST_F(CPWLEditEmbeddertest, InsertTextInEmptyCharLimitTextFieldOverflow) {
292 FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
293 GetCPWLEdit()->SetSelection(0, -1);
294 EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhang38adfc12017-08-25 22:05:18 -0700295 GetCPWLEdit()->ReplaceSelection(L"");
Diana Gageab390972017-07-28 17:07:39 -0700296
Lei Zhang38adfc12017-08-25 22:05:18 -0700297 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700298 EXPECT_STREQ(L"Hippopotam", GetCPWLEdit()->GetText().c_str());
299}
300
301TEST_F(CPWLEditEmbeddertest, InsertTextInEmptyCharLimitTextFieldFit) {
302 FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
303 GetCPWLEdit()->SetSelection(0, -1);
304 EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhang38adfc12017-08-25 22:05:18 -0700305 GetCPWLEdit()->ReplaceSelection(L"");
Diana Gageab390972017-07-28 17:07:39 -0700306
Lei Zhang38adfc12017-08-25 22:05:18 -0700307 GetCPWLEdit()->ReplaceSelection(L"Zebra");
Diana Gageab390972017-07-28 17:07:39 -0700308 EXPECT_STREQ(L"Zebra", GetCPWLEdit()->GetText().c_str());
309}
310
311TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedCharLimitTextFieldLeft) {
312 FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
Lei Zhang38adfc12017-08-25 22:05:18 -0700313 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700314 EXPECT_STREQ(L"HiElephant", GetCPWLEdit()->GetText().c_str());
315}
316
317TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700325 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700326 EXPECT_STREQ(L"ElephHiant", GetCPWLEdit()->GetText().c_str());
327}
328
329TEST_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 Zhang38adfc12017-08-25 22:05:18 -0700335 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700336 EXPECT_STREQ(L"ElephantHi", GetCPWLEdit()->GetText().c_str());
337}
338
339TEST_F(CPWLEditEmbeddertest,
340 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) {
341 FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
342 GetCPWLEdit()->SetSelection(0, -1);
343 EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhang38adfc12017-08-25 22:05:18 -0700344 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700345 EXPECT_STREQ(L"Hippopotam", GetCPWLEdit()->GetText().c_str());
346}
347
348TEST_F(CPWLEditEmbeddertest,
349 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) {
350 FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
351 GetCPWLEdit()->SetSelection(0, 4);
352 EXPECT_STREQ(L"Elep", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhang38adfc12017-08-25 22:05:18 -0700353 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700354 EXPECT_STREQ(L"Hippophant", GetCPWLEdit()->GetText().c_str());
355}
356
357TEST_F(CPWLEditEmbeddertest,
358 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) {
359 FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
360 GetCPWLEdit()->SetSelection(2, 6);
361 EXPECT_STREQ(L"epha", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhang38adfc12017-08-25 22:05:18 -0700362 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700363 EXPECT_STREQ(L"ElHippopnt", GetCPWLEdit()->GetText().c_str());
364}
365
366TEST_F(CPWLEditEmbeddertest,
367 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) {
368 FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
369 GetCPWLEdit()->SetSelection(4, 8);
370 EXPECT_STREQ(L"hant", GetCPWLEdit()->GetSelectedText().c_str());
Lei Zhang38adfc12017-08-25 22:05:18 -0700371 GetCPWLEdit()->ReplaceSelection(L"Hippopotamus");
Diana Gageab390972017-07-28 17:07:39 -0700372 EXPECT_STREQ(L"ElepHippop", GetCPWLEdit()->GetText().c_str());
373}
Ryan Harrisonf8763bb2017-08-31 14:22:39 -0400374
375TEST_F(CPWLEditEmbeddertest, SetTextWithEndCarriageFeed) {
376 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
377 GetCPWLEdit()->SetText(L"Foo\r");
378 EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str());
379}
380
381TEST_F(CPWLEditEmbeddertest, SetTextWithEndNewline) {
382 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
383 GetCPWLEdit()->SetText(L"Foo\n");
384 EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str());
385}
386
387TEST_F(CPWLEditEmbeddertest, SetTextWithEndCarriageFeedAndNewLine) {
388 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
389 GetCPWLEdit()->SetText(L"Foo\r\n");
390 EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str());
391}
392
393TEST_F(CPWLEditEmbeddertest, SetTextWithEndNewLineAndCarriageFeed) {
394 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
395 GetCPWLEdit()->SetText(L"Foo\n\r");
396 EXPECT_STREQ(L"Foo", GetCPWLEdit()->GetText().c_str());
397}
398
399TEST_F(CPWLEditEmbeddertest, SetTextWithBodyCarriageFeed) {
400 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
401 GetCPWLEdit()->SetText(L"Foo\rBar");
402 EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str());
403}
404
405TEST_F(CPWLEditEmbeddertest, SetTextWithBodyNewline) {
406 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
407 GetCPWLEdit()->SetText(L"Foo\nBar");
408 EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str());
409}
410
411TEST_F(CPWLEditEmbeddertest, SetTextWithBodyCarriageFeedAndNewLine) {
412 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
413 GetCPWLEdit()->SetText(L"Foo\r\nBar");
414 EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str());
415}
416
417TEST_F(CPWLEditEmbeddertest, SetTextWithBodyNewLineAndCarriageFeed) {
418 FormFillerAndWindowSetup(GetCPDFSDKAnnot());
419 GetCPWLEdit()->SetText(L"Foo\n\rBar");
420 EXPECT_STREQ(L"FooBar", GetCPWLEdit()->GetText().c_str());
421}