blob: f5151cc456846c4c02351818f1976fdd02e23493 [file] [log] [blame]
Tom Sepeza310e002015-02-27 13:03:07 -08001// Copyright 2015 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
Nicolas Pena742977f2017-04-13 15:28:20 -04005#include <memory>
6#include <string>
Diana Gagedce2d722017-06-20 11:17:11 -07007#include <vector>
Nicolas Pena742977f2017-04-13 15:28:20 -04008
Lei Zhang31f7e4b2017-08-26 01:34:42 -07009#include "core/fxcrt/fx_coordinates.h"
Diana Gagedce2d722017-06-20 11:17:11 -070010#include "core/fxcrt/fx_string.h"
Nicolas Pena742977f2017-04-13 15:28:20 -040011#include "core/fxcrt/fx_system.h"
12#include "public/cpp/fpdf_deleters.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080013#include "public/fpdf_formfill.h"
Diana Gagedce2d722017-06-20 11:17:11 -070014#include "public/fpdf_fwlevent.h"
Wei Li091f7a02015-11-09 12:09:55 -080015#include "testing/embedder_test.h"
16#include "testing/embedder_test_mock_delegate.h"
17#include "testing/embedder_test_timer_handling_delegate.h"
Tom Sepeza310e002015-02-27 13:03:07 -080018#include "testing/gmock/include/gmock/gmock.h"
19#include "testing/gtest/include/gtest/gtest.h"
20
21using testing::_;
Tom Sepeza310e002015-02-27 13:03:07 -080022
Lei Zhang839692f2017-08-25 23:23:57 -070023using FPDFFormFillEmbeddertest = EmbedderTest;
24
25// A base class for many related tests that involve clicking and typing into
26// form fields.
27class FPDFFormFillInteractiveEmbeddertest : public FPDFFormFillEmbeddertest {
Diana Gagedce2d722017-06-20 11:17:11 -070028 protected:
Lei Zhang839692f2017-08-25 23:23:57 -070029 FPDFFormFillInteractiveEmbeddertest() = default;
30 ~FPDFFormFillInteractiveEmbeddertest() override = default;
31
32 void SetUp() override {
33 FPDFFormFillEmbeddertest::SetUp();
34 ASSERT_TRUE(OpenDocument(GetDocumentName()));
35 page_ = LoadPage(0);
36 ASSERT_TRUE(page_);
37 FormSanityChecks();
Diana Gagef8c02762017-07-26 14:20:12 -070038 }
39
Lei Zhang839692f2017-08-25 23:23:57 -070040 void TearDown() override {
41 UnloadPage(page_);
42 FPDFFormFillEmbeddertest::TearDown();
43 }
44
45 // Returns the name of the PDF to use.
46 virtual const char* GetDocumentName() const = 0;
47
Lei Zhang7bec2ff2017-08-25 23:28:23 -070048 // Returns the type of field(s) in the PDF.
49 virtual int GetFormType() const = 0;
50
Lei Zhang839692f2017-08-25 23:23:57 -070051 // Optionally do some sanity check on the document after loading.
52 virtual void FormSanityChecks() {}
53
54 FPDF_PAGE page() { return page_; }
55
Lei Zhang31f7e4b2017-08-26 01:34:42 -070056 int GetFormTypeAtPoint(const CFX_PointF& point) {
57 return FPDFPage_HasFormFieldAtPoint(form_handle(), page_, point.x, point.y);
Lei Zhang839692f2017-08-25 23:23:57 -070058 }
59
Lei Zhang31f7e4b2017-08-26 01:34:42 -070060 void ClickOnFormFieldAtPoint(const CFX_PointF& point) {
61 // Click on the text field or combobox as specified by coordinates.
62 FORM_OnMouseMove(form_handle(), page_, 0, point.x, point.y);
63 FORM_OnLButtonDown(form_handle(), page_, 0, point.x, point.y);
64 FORM_OnLButtonUp(form_handle(), page_, 0, point.x, point.y);
65 }
66
67 void TypeTextIntoTextField(int num_chars, const CFX_PointF& point) {
68 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(point));
69 ClickOnFormFieldAtPoint(point);
Diana Gagedce2d722017-06-20 11:17:11 -070070
71 // Type text starting with 'A' to as many chars as specified by |num_chars|.
72 for (int i = 0; i < num_chars; ++i) {
Lei Zhang839692f2017-08-25 23:23:57 -070073 FORM_OnChar(form_handle(), page_, 'A' + i, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070074 }
75 }
76
Diana Gagecb50b5f2017-06-29 09:54:19 -070077 // Navigates to text field using the mouse and then selects text via the
Diana Gagedce2d722017-06-20 11:17:11 -070078 // shift and specfied left or right arrow key.
Lei Zhang839692f2017-08-25 23:23:57 -070079 void SelectTextWithKeyboard(int num_chars,
Diana Gagedce2d722017-06-20 11:17:11 -070080 int arrow_key,
Lei Zhang31f7e4b2017-08-26 01:34:42 -070081 const CFX_PointF& point) {
Diana Gagedce2d722017-06-20 11:17:11 -070082 // Navigate to starting position for selection.
Lei Zhang31f7e4b2017-08-26 01:34:42 -070083 ClickOnFormFieldAtPoint(point);
Diana Gagedce2d722017-06-20 11:17:11 -070084
85 // Hold down shift (and don't release until entire text is selected).
Lei Zhang839692f2017-08-25 23:23:57 -070086 FORM_OnKeyDown(form_handle(), page_, FWL_VKEY_Shift, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070087
88 // Select text char by char via left or right arrow key.
89 for (int i = 0; i < num_chars; ++i) {
Lei Zhang839692f2017-08-25 23:23:57 -070090 FORM_OnKeyDown(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
91 FORM_OnKeyUp(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
Diana Gagedce2d722017-06-20 11:17:11 -070092 }
Lei Zhang839692f2017-08-25 23:23:57 -070093 FORM_OnKeyUp(form_handle(), page_, FWL_VKEY_Shift, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070094 }
95
Diana Gagecb50b5f2017-06-29 09:54:19 -070096 // Uses the mouse to navigate to text field and select text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -070097 void SelectTextWithMouse(const CFX_PointF& start, const CFX_PointF& end) {
98 ASSERT(start.y == end.y);
99
Diana Gagedce2d722017-06-20 11:17:11 -0700100 // Navigate to starting position and click mouse.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700101 FORM_OnMouseMove(form_handle(), page_, 0, start.x, start.y);
102 FORM_OnLButtonDown(form_handle(), page_, 0, start.x, start.y);
Diana Gagedce2d722017-06-20 11:17:11 -0700103
104 // Hold down mouse until reach end of desired selection.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700105 FORM_OnMouseMove(form_handle(), page_, 0, end.x, end.y);
106 FORM_OnLButtonUp(form_handle(), page_, 0, end.x, end.y);
Diana Gagedce2d722017-06-20 11:17:11 -0700107 }
108
Ryan Harrison275e2602017-09-18 14:23:18 -0400109 void CheckSelection(const WideStringView& expected_string) {
Diana Gagedce2d722017-06-20 11:17:11 -0700110 // Calculate expected length for selected text.
111 int num_chars = expected_string.GetLength();
112
113 // Check actual selection against expected selection.
114 const unsigned long expected_length =
115 sizeof(unsigned short) * (num_chars + 1);
116 unsigned long sel_text_len =
Lei Zhang839692f2017-08-25 23:23:57 -0700117 FORM_GetSelectedText(form_handle(), page_, nullptr, 0);
Diana Gagedce2d722017-06-20 11:17:11 -0700118 ASSERT_EQ(expected_length, sel_text_len);
119
120 std::vector<unsigned short> buf(sel_text_len);
Lei Zhang839692f2017-08-25 23:23:57 -0700121 EXPECT_EQ(expected_length, FORM_GetSelectedText(form_handle(), page_,
Diana Gagedce2d722017-06-20 11:17:11 -0700122 buf.data(), sel_text_len));
123
Ryan Harrison275e2602017-09-18 14:23:18 -0400124 EXPECT_EQ(expected_string, WideString::FromUTF16LE(buf.data(), num_chars));
Diana Gagedce2d722017-06-20 11:17:11 -0700125 }
Diana Gagecb50b5f2017-06-29 09:54:19 -0700126
Lei Zhang839692f2017-08-25 23:23:57 -0700127 private:
128 FPDF_PAGE page_ = nullptr;
129};
130
131class FPDFFormFillTextFormEmbeddertest
132 : public FPDFFormFillInteractiveEmbeddertest {
133 protected:
134 FPDFFormFillTextFormEmbeddertest() = default;
135 ~FPDFFormFillTextFormEmbeddertest() override = default;
136
137 const char* GetDocumentName() const override {
138 // PDF with several form text fields:
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700139 // - "Text Box" - Regular text box with no special attributes.
Lei Zhang839692f2017-08-25 23:23:57 -0700140 // - "ReadOnly" - Ff: 1.
141 // - "CharLimit" - MaxLen: 10, V: Elephant.
142 return "text_form_multiple.pdf";
143 }
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700144
145 int GetFormType() const override { return FPDF_FORMFIELD_TEXTFIELD; }
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700146
147 void FormSanityChecks() override {
148 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(CharLimitFormBegin()));
149 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(CharLimitFormEnd()));
150 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(RegularFormBegin()));
151 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(RegularFormEnd()));
152 }
153
154 void SelectAllCharLimitFormTextWithMouse() {
155 SelectTextWithMouse(CharLimitFormEnd(), CharLimitFormBegin());
156 }
157
158 void SelectAllRegularFormTextWithMouse() {
159 SelectTextWithMouse(RegularFormEnd(), RegularFormBegin());
160 }
161
162 const CFX_PointF& CharLimitFormBegin() const {
163 static const CFX_PointF point = CharLimitFormAtX(kFormBeginX);
164 return point;
165 }
166
167 const CFX_PointF& CharLimitFormEnd() const {
168 static const CFX_PointF point = CharLimitFormAtX(kFormEndX);
169 return point;
170 }
171
172 const CFX_PointF& RegularFormBegin() const {
173 static const CFX_PointF point = RegularFormAtX(kFormBeginX);
174 return point;
175 }
176
177 const CFX_PointF& RegularFormEnd() const {
178 static const CFX_PointF point = RegularFormAtX(kFormEndX);
179 return point;
180 }
181
182 static CFX_PointF CharLimitFormAtX(float x) {
183 ASSERT(x >= kFormBeginX);
184 ASSERT(x <= kFormEndX);
185 return CFX_PointF(x, kCharLimitFormY);
186 }
187
188 static CFX_PointF RegularFormAtX(float x) {
189 ASSERT(x >= kFormBeginX);
190 ASSERT(x <= kFormEndX);
191 return CFX_PointF(x, kRegularFormY);
192 }
193
194 private:
195 static constexpr float kFormBeginX = 102.0;
196 static constexpr float kFormEndX = 195.0;
197 static constexpr float kCharLimitFormY = 60.0;
198 static constexpr float kRegularFormY = 115.0;
Lei Zhang839692f2017-08-25 23:23:57 -0700199};
200
201class FPDFFormFillComboBoxFormEmbeddertest
202 : public FPDFFormFillInteractiveEmbeddertest {
203 protected:
204 FPDFFormFillComboBoxFormEmbeddertest() = default;
205 ~FPDFFormFillComboBoxFormEmbeddertest() override = default;
206
207 const char* GetDocumentName() const override {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700208 // PDF with form comboboxes:
209 // - "Combo_Editable" - Ff: 393216, 3 options with pair values.
210 // - "Combo1" - Ff: 131072, 3 options with single values.
211 // - "Combo_ReadOnly" - Ff: 131073, 3 options with single values.
Lei Zhang839692f2017-08-25 23:23:57 -0700212 return "combobox_form.pdf";
213 }
214
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700215 int GetFormType() const override { return FPDF_FORMFIELD_COMBOBOX; }
216
Lei Zhang839692f2017-08-25 23:23:57 -0700217 void FormSanityChecks() override {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700218 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormBegin()));
219 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormEnd()));
220 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormDropDown()));
221 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormBegin()));
222 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormEnd()));
223 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormDropDown()));
Lei Zhang839692f2017-08-25 23:23:57 -0700224 }
225
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700226 void SelectEditableFormOption(int item_index) {
227 SelectOption(item_index, EditableFormDropDown());
228 }
229
230 void SelectNonEditableFormOption(int item_index) {
231 SelectOption(item_index, NonEditableFormDropDown());
232 }
233
234 void SelectAllEditableFormTextWithMouse() {
235 SelectTextWithMouse(EditableFormEnd(), EditableFormBegin());
236 }
237
238 const CFX_PointF& EditableFormBegin() const {
239 static const CFX_PointF point = EditableFormAtX(kFormBeginX);
240 return point;
241 }
242
243 const CFX_PointF& EditableFormEnd() const {
244 static const CFX_PointF point = EditableFormAtX(kFormEndX);
245 return point;
246 }
247
248 const CFX_PointF& EditableFormDropDown() const {
249 static const CFX_PointF point(kFormDropDownX, kEditableFormY);
250 return point;
251 }
252
253 const CFX_PointF& NonEditableFormBegin() const {
254 static const CFX_PointF point = NonEditableFormAtX(kFormBeginX);
255 return point;
256 }
257
258 const CFX_PointF& NonEditableFormEnd() const {
259 static const CFX_PointF point = NonEditableFormAtX(kFormEndX);
260 return point;
261 }
262
263 const CFX_PointF& NonEditableFormDropDown() const {
264 static const CFX_PointF point(kFormDropDownX, kNonEditableFormY);
265 return point;
266 }
267
268 static CFX_PointF EditableFormAtX(float x) {
269 ASSERT(x >= kFormBeginX);
270 ASSERT(x <= kFormEndX);
271 return CFX_PointF(x, kEditableFormY);
272 }
273
274 static CFX_PointF NonEditableFormAtX(float x) {
275 ASSERT(x >= kFormBeginX);
276 ASSERT(x <= kFormEndX);
277 return CFX_PointF(x, kNonEditableFormY);
278 }
279
280 private:
Diana Gagecb50b5f2017-06-29 09:54:19 -0700281 // Selects one of the pre-selected values from a combobox with three options.
282 // Options are specified by |item_index|, which is 0-based.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700283 void SelectOption(int item_index, const CFX_PointF& point) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700284 // Only relevant for comboboxes with three choices and the same dimensions
285 // as those in combobox_form.pdf.
286 ASSERT(item_index >= 0);
287 ASSERT(item_index < 3);
288
289 // Navigate to button for drop down and click mouse to reveal options.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700290 ClickOnFormFieldAtPoint(point);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700291
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700292 // Calculate to Y-coordinate of dropdown option to be selected.
Diana Gagecb50b5f2017-06-29 09:54:19 -0700293 constexpr double kChoiceHeight = 15;
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700294 CFX_PointF option_point = point;
295 option_point.y -= kChoiceHeight * (item_index + 1);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700296
297 // Navigate to option and click mouse to select it.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700298 ClickOnFormFieldAtPoint(option_point);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700299 }
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700300
301 static constexpr float kFormBeginX = 102.0;
302 static constexpr float kFormEndX = 183.0;
303 static constexpr float kFormDropDownX = 192.0;
304 static constexpr float kEditableFormY = 60.0;
305 static constexpr float kNonEditableFormY = 110.0;
Diana Gagedce2d722017-06-20 11:17:11 -0700306};
Tom Sepeza310e002015-02-27 13:03:07 -0800307
308TEST_F(FPDFFormFillEmbeddertest, FirstTest) {
309 EmbedderTestMockDelegate mock;
310 EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0);
311 EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700312 EXPECT_CALL(mock, SetTimer(_, _)).Times(0);
313 EXPECT_CALL(mock, KillTimer(_)).Times(0);
Tom Sepeza310e002015-02-27 13:03:07 -0800314 SetDelegate(&mock);
315
Wei Li091f7a02015-11-09 12:09:55 -0800316 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepeza310e002015-02-27 13:03:07 -0800317 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700318 EXPECT_TRUE(page);
Lei Zhangd27acae2015-05-15 15:36:02 -0700319 UnloadPage(page);
Tom Sepeza310e002015-02-27 13:03:07 -0800320}
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700321
322TEST_F(FPDFFormFillEmbeddertest, BUG_487928) {
323 EmbedderTestTimerHandlingDelegate delegate;
324 SetDelegate(&delegate);
325
Wei Li091f7a02015-11-09 12:09:55 -0800326 EXPECT_TRUE(OpenDocument("bug_487928.pdf"));
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700327 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700328 EXPECT_TRUE(page);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700329 DoOpenActions();
330 delegate.AdvanceTime(5000);
331 UnloadPage(page);
332}
Tom Sepez0b133982015-07-28 11:23:22 -0700333
Tom Sepez396e8722015-09-09 10:16:08 -0700334TEST_F(FPDFFormFillEmbeddertest, BUG_507316) {
335 EmbedderTestTimerHandlingDelegate delegate;
336 SetDelegate(&delegate);
337
Wei Li091f7a02015-11-09 12:09:55 -0800338 EXPECT_TRUE(OpenDocument("bug_507316.pdf"));
weili0dadcc62016-08-23 21:10:57 -0700339 FPDF_PAGE page = LoadPage(2);
tsepez8e120292016-08-03 14:03:35 -0700340 EXPECT_TRUE(page);
Tom Sepez396e8722015-09-09 10:16:08 -0700341 DoOpenActions();
342 delegate.AdvanceTime(4000);
343 UnloadPage(page);
344}
345
Tom Sepez0b133982015-07-28 11:23:22 -0700346TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
Wei Li091f7a02015-11-09 12:09:55 -0800347 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0b133982015-07-28 11:23:22 -0700348 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700349 EXPECT_TRUE(page);
Tom Sepez0b133982015-07-28 11:23:22 -0700350
351 // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES.
352 FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0);
353 FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0);
354
355 UnloadPage(page);
356}
Lei Zhang79e893a2015-11-04 16:02:47 -0800357
Tom Sepez4d071792016-02-04 16:53:26 -0800358#ifdef PDF_ENABLE_V8
Lei Zhang79e893a2015-11-04 16:02:47 -0800359TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
tsepez8e120292016-08-03 14:03:35 -0700360 // Test that timers fire once and intervals fire repeatedly.
Lei Zhang79e893a2015-11-04 16:02:47 -0800361 EmbedderTestTimerHandlingDelegate delegate;
362 SetDelegate(&delegate);
363
Wei Li091f7a02015-11-09 12:09:55 -0800364 EXPECT_TRUE(OpenDocument("bug_551248.pdf"));
Lei Zhang79e893a2015-11-04 16:02:47 -0800365 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700366 EXPECT_TRUE(page);
367 DoOpenActions();
368
369 const auto& alerts = delegate.GetAlerts();
370 EXPECT_EQ(0U, alerts.size());
371
372 delegate.AdvanceTime(1000);
373 EXPECT_EQ(0U, alerts.size()); // nothing fired.
374 delegate.AdvanceTime(1000);
375 EXPECT_EQ(1U, alerts.size()); // interval fired.
376 delegate.AdvanceTime(1000);
377 EXPECT_EQ(2U, alerts.size()); // timer fired.
378 delegate.AdvanceTime(1000);
379 EXPECT_EQ(3U, alerts.size()); // interval fired again.
380 delegate.AdvanceTime(1000);
381 EXPECT_EQ(3U, alerts.size()); // nothing fired.
382 delegate.AdvanceTime(1000);
383 EXPECT_EQ(4U, alerts.size()); // interval fired again.
384 delegate.AdvanceTime(1000);
385 EXPECT_EQ(4U, alerts.size()); // nothing fired.
386 UnloadPage(page);
387
388 ASSERT_EQ(4U, alerts.size()); // nothing else fired.
389
390 EXPECT_STREQ(L"interval fired", alerts[0].message.c_str());
391 EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
392 EXPECT_EQ(0, alerts[0].type);
393 EXPECT_EQ(0, alerts[0].icon);
394
395 EXPECT_STREQ(L"timer fired", alerts[1].message.c_str());
396 EXPECT_STREQ(L"Alert", alerts[1].title.c_str());
397 EXPECT_EQ(0, alerts[1].type);
398 EXPECT_EQ(0, alerts[1].icon);
399
400 EXPECT_STREQ(L"interval fired", alerts[2].message.c_str());
401 EXPECT_STREQ(L"Alert", alerts[2].title.c_str());
402 EXPECT_EQ(0, alerts[2].type);
403 EXPECT_EQ(0, alerts[2].icon);
404
405 EXPECT_STREQ(L"interval fired", alerts[3].message.c_str());
406 EXPECT_STREQ(L"Alert", alerts[3].title.c_str());
407 EXPECT_EQ(0, alerts[3].type);
408 EXPECT_EQ(0, alerts[3].icon);
409}
410
411TEST_F(FPDFFormFillEmbeddertest, BUG_620428) {
412 // Test that timers and intervals are cancelable.
413 EmbedderTestTimerHandlingDelegate delegate;
414 SetDelegate(&delegate);
415
416 EXPECT_TRUE(OpenDocument("bug_620428.pdf"));
417 FPDF_PAGE page = LoadPage(0);
418 EXPECT_TRUE(page);
Lei Zhang79e893a2015-11-04 16:02:47 -0800419 DoOpenActions();
420 delegate.AdvanceTime(5000);
421 UnloadPage(page);
422
423 const auto& alerts = delegate.GetAlerts();
tsepez0fa54b82016-08-04 12:07:28 -0700424 ASSERT_EQ(1U, alerts.size());
425 EXPECT_STREQ(L"done", alerts[0].message.c_str());
Lei Zhang79e893a2015-11-04 16:02:47 -0800426}
tsepez8e120292016-08-03 14:03:35 -0700427
tsepez32e693f2016-08-04 12:47:42 -0700428TEST_F(FPDFFormFillEmbeddertest, BUG_634394) {
429 // Cancel timer inside timer callback.
430 EmbedderTestTimerHandlingDelegate delegate;
431 SetDelegate(&delegate);
432
433 EXPECT_TRUE(OpenDocument("bug_634394.pdf"));
434 FPDF_PAGE page = LoadPage(0);
435 EXPECT_TRUE(page);
436 DoOpenActions();
437
438 // Timers fire at most once per AdvanceTime(), allow intervals
439 // to fire several times if possible.
440 delegate.AdvanceTime(1000);
441 delegate.AdvanceTime(1000);
442 delegate.AdvanceTime(1000);
443 delegate.AdvanceTime(1000);
444 delegate.AdvanceTime(1000);
445 UnloadPage(page);
446
447 const auto& alerts = delegate.GetAlerts();
448 EXPECT_EQ(2U, alerts.size());
449}
450
tsepez8ca63de2016-08-05 17:12:27 -0700451TEST_F(FPDFFormFillEmbeddertest, BUG_634716) {
452 EmbedderTestTimerHandlingDelegate delegate;
453 SetDelegate(&delegate);
454
455 EXPECT_TRUE(OpenDocument("bug_634716.pdf"));
456 FPDF_PAGE page = LoadPage(0);
457 EXPECT_TRUE(page);
458 DoOpenActions();
459
460 // Timers fire at most once per AdvanceTime(), allow intervals
461 // to fire several times if possible.
462 delegate.AdvanceTime(1000);
463 delegate.AdvanceTime(1000);
464 delegate.AdvanceTime(1000);
465 delegate.AdvanceTime(1000);
466 delegate.AdvanceTime(1000);
467 UnloadPage(page);
468
469 const auto& alerts = delegate.GetAlerts();
470 EXPECT_EQ(2U, alerts.size());
471}
472
tsepez6cf5eca2017-01-12 11:21:12 -0800473TEST_F(FPDFFormFillEmbeddertest, BUG_679649) {
474 EmbedderTestTimerHandlingDelegate delegate;
475 SetDelegate(&delegate);
476
477 EXPECT_TRUE(OpenDocument("bug_679649.pdf"));
478 FPDF_PAGE page = LoadPage(0);
479 EXPECT_TRUE(page);
480
481 delegate.SetFailNextTimer();
482 DoOpenActions();
483 delegate.AdvanceTime(2000);
484 UnloadPage(page);
485
486 const auto& alerts = delegate.GetAlerts();
487 EXPECT_EQ(0u, alerts.size());
488}
489
Tom Sepezfb7021c2017-05-31 10:29:25 -0700490TEST_F(FPDFFormFillEmbeddertest, BUG_707673) {
491 EmbedderTestTimerHandlingDelegate delegate;
492 SetDelegate(&delegate);
493
494 EXPECT_TRUE(OpenDocument("bug_707673.pdf"));
495 FPDF_PAGE page = LoadPage(0);
496 EXPECT_TRUE(page);
497
498 DoOpenActions();
499 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
500 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
501 delegate.AdvanceTime(1000);
502 UnloadPage(page);
503
504 const auto& alerts = delegate.GetAlerts();
505 EXPECT_EQ(0u, alerts.size());
506}
507
Tom Sepezb1f92052017-09-14 17:03:12 -0700508TEST_F(FPDFFormFillEmbeddertest, BUG_765384) {
509 EXPECT_TRUE(OpenDocument("bug_765384.pdf"));
510 FPDF_PAGE page = LoadPage(0);
511 EXPECT_TRUE(page);
512
513 DoOpenActions();
514 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
515 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
516 UnloadPage(page);
517}
518
Tom Sepez4d071792016-02-04 16:53:26 -0800519#endif // PDF_ENABLE_V8
Nicolas Pena742977f2017-04-13 15:28:20 -0400520
521TEST_F(FPDFFormFillEmbeddertest, FormText) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400522#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Nicolas Pena742977f2017-04-13 15:28:20 -0400523 const char md5_1[] = "5f11dbe575fe197a37c3fb422559f8ff";
524 const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d";
525 const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe";
526#else
Nicolas Pena00c3cfd2017-07-10 17:29:54 -0400527 const char md5_1[] = "a5e3ac74c2ee123ec6710e2f0ef8424a";
528 const char md5_2[] = "4526b09382e144d5506ad92149399de6";
529 const char md5_3[] = "80356067d860088864cf50ff85d8459e";
Nicolas Pena742977f2017-04-13 15:28:20 -0400530#endif
531 {
532 EXPECT_TRUE(OpenDocument("text_form.pdf"));
533 FPDF_PAGE page = LoadPage(0);
534 ASSERT_TRUE(page);
535 std::unique_ptr<void, FPDFBitmapDeleter> bitmap1(RenderPage(page));
536 CompareBitmap(bitmap1.get(), 300, 300, md5_1);
537
538 // Click on the textfield
539 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
540 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
541 FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
542 FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
543 FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
544
545 // Write "ABC"
546 FORM_OnChar(form_handle(), page, 65, 0);
547 FORM_OnChar(form_handle(), page, 66, 0);
548 FORM_OnChar(form_handle(), page, 67, 0);
549 std::unique_ptr<void, FPDFBitmapDeleter> bitmap2(RenderPage(page));
550 CompareBitmap(bitmap2.get(), 300, 300, md5_2);
551
552 // Take out focus by clicking out of the textfield
553 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
554 FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
555 FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
556 std::unique_ptr<void, FPDFBitmapDeleter> bitmap3(RenderPage(page));
557 CompareBitmap(bitmap3.get(), 300, 300, md5_3);
558
559 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
560
Nicolas Pena3ff54002017-07-05 11:55:35 -0400561 // Close page
Nicolas Pena742977f2017-04-13 15:28:20 -0400562 UnloadPage(page);
Nicolas Pena742977f2017-04-13 15:28:20 -0400563 }
564 // Check saved document
Nicolas Pena3ff54002017-07-05 11:55:35 -0400565 TestAndCloseSaved(300, 300, md5_3);
Nicolas Pena742977f2017-04-13 15:28:20 -0400566}
Diana Gagedce2d722017-06-20 11:17:11 -0700567
Lei Zhang839692f2017-08-25 23:23:57 -0700568TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) {
Diana Gagedce2d722017-06-20 11:17:11 -0700569 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700570 CheckSelection(L"");
Diana Gagedce2d722017-06-20 11:17:11 -0700571
572 // Test basic selection.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700573 TypeTextIntoTextField(3, RegularFormBegin());
574 SelectTextWithKeyboard(3, FWL_VKEY_Left, RegularFormAtX(123.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700575 CheckSelection(L"ABC");
Diana Gagedce2d722017-06-20 11:17:11 -0700576}
577
Lei Zhang839692f2017-08-25 23:23:57 -0700578TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicMouse) {
Diana Gagedce2d722017-06-20 11:17:11 -0700579 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700580 CheckSelection(L"");
Diana Gagedce2d722017-06-20 11:17:11 -0700581
582 // Test basic selection.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700583 TypeTextIntoTextField(3, RegularFormBegin());
584 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700585 CheckSelection(L"ABC");
Diana Gagedce2d722017-06-20 11:17:11 -0700586}
587
Lei Zhang839692f2017-08-25 23:23:57 -0700588TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsKeyBoard) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700589 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gagedce2d722017-06-20 11:17:11 -0700590
591 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700592 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700593 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700594
595 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700596 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700597 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700598
599 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700600 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(170.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700601 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700602
603 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700604 SelectTextWithKeyboard(6, FWL_VKEY_Right, RegularFormAtX(125.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700605 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700606
607 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700608 SelectTextWithKeyboard(1, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700609 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700610}
611
Lei Zhang839692f2017-08-25 23:23:57 -0700612TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsMouse) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700613 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gagedce2d722017-06-20 11:17:11 -0700614
615 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700616 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(106.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700617 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700618
619 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700620 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700621 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700622
623 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700624 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700625 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700626
627 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700628 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormAtX(170.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700629 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700630
631 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700632 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(186.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700633 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700634}
Diana Gagecb50b5f2017-06-29 09:54:19 -0700635
Lei Zhang839692f2017-08-25 23:23:57 -0700636TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
637 GetSelectedTextEmptyAndBasicNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700638 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700639 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700640
641 // Non-editable comboboxes don't allow selection with keyboard.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700642 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(142.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700643 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700644
645 // Select other another provided option.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700646 SelectNonEditableFormOption(0);
Lei Zhang839692f2017-08-25 23:23:57 -0700647 CheckSelection(L"Apple");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700648}
649
Lei Zhang839692f2017-08-25 23:23:57 -0700650TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700651 GetSelectedTextEmptyAndBasicEditableComboBoxKeyboard) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700652 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700653 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700654
655 // Test basic selection of text within user editable combobox using keyboard.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700656 TypeTextIntoTextField(3, EditableFormBegin());
657 SelectTextWithKeyboard(3, FWL_VKEY_Left, EditableFormAtX(128.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700658 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700659
660 // Select a provided option.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700661 SelectEditableFormOption(1);
Lei Zhang839692f2017-08-25 23:23:57 -0700662 CheckSelection(L"Bar");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700663}
664
Lei Zhang839692f2017-08-25 23:23:57 -0700665TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700666 GetSelectedTextEmptyAndBasicEditableComboBoxMouse) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700667 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700668 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700669
670 // Test basic selection of text within user editable combobox using mouse.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700671 TypeTextIntoTextField(3, EditableFormBegin());
672 SelectTextWithMouse(EditableFormAtX(128.0), EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700673 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700674
675 // Select a provided option.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700676 SelectEditableFormOption(2);
Lei Zhang839692f2017-08-25 23:23:57 -0700677 CheckSelection(L"Qux");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700678}
679
Lei Zhang839692f2017-08-25 23:23:57 -0700680TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
681 GetSelectedTextFragmentsNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700682 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700683 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(107.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700684 CheckSelection(L"B");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700685
686 // Test selecting entire string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700687 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700688 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700689
690 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700691 SelectTextWithMouse(NonEditableFormAtX(135.0), NonEditableFormAtX(117.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700692 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700693
694 // Test selecting middle section in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700695 SelectTextWithMouse(NonEditableFormAtX(117.0), NonEditableFormAtX(135.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700696 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700697
698 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700699 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormAtX(138.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700700 CheckSelection(L"a");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700701
702 // Select another option and then reset selection as first three chars.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700703 SelectNonEditableFormOption(2);
Lei Zhang839692f2017-08-25 23:23:57 -0700704 CheckSelection(L"Cherry");
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700705 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(122.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700706 CheckSelection(L"Che");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700707}
708
Lei Zhang839692f2017-08-25 23:23:57 -0700709TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700710 GetSelectedTextFragmentsEditableComboBoxKeyboard) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700711 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gagecb50b5f2017-06-29 09:54:19 -0700712
713 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700714 SelectTextWithKeyboard(1, FWL_VKEY_Right, EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700715 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700716
717 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700718 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700719 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700720
721 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700722 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(168.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700723 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700724
725 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700726 SelectTextWithKeyboard(5, FWL_VKEY_Right, EditableFormAtX(127.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700727 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700728
729 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700730 SelectTextWithKeyboard(1, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700731 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700732
733 // Select a provided option and then reset selection as first two chars.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700734 SelectEditableFormOption(0);
Lei Zhang839692f2017-08-25 23:23:57 -0700735 CheckSelection(L"Foo");
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700736 SelectTextWithKeyboard(2, FWL_VKEY_Right, EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700737 CheckSelection(L"Fo");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700738}
739
Lei Zhang839692f2017-08-25 23:23:57 -0700740TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700741 GetSelectedTextFragmentsEditableComboBoxMouse) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700742 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gagecb50b5f2017-06-29 09:54:19 -0700743
744 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700745 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(107.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700746 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700747
748 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700749 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700750 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700751
752 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700753 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700754 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700755
756 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700757 SelectTextWithMouse(EditableFormAtX(127.0), EditableFormAtX(168.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700758 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700759
760 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700761 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(174.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700762 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700763}
Diana Gage1c7f1422017-07-24 11:19:52 -0700764
Lei Zhang839692f2017-08-25 23:23:57 -0700765TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700766 // Select entire contents of text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700767 TypeTextIntoTextField(12, RegularFormBegin());
768 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700769 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700770
771 // Test deleting current text selection. Select what remains after deletion to
772 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700773 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -0700774
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700775 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700776 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700777}
778
Lei Zhang839692f2017-08-25 23:23:57 -0700779TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700780 // Select middle section of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700781 TypeTextIntoTextField(12, RegularFormBegin());
782 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700783 CheckSelection(L"DEFGHI");
Diana Gage1c7f1422017-07-24 11:19:52 -0700784
785 // Test deleting current text selection. Select what remains after deletion to
786 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700787 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700788 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700789 CheckSelection(L"ABCJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700790}
791
Lei Zhang839692f2017-08-25 23:23:57 -0700792TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700793 // Select first few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700794 TypeTextIntoTextField(12, RegularFormBegin());
795 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(132.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700796 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700797
798 // Test deleting current text selection. Select what remains after deletion to
799 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700800 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700801 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700802 CheckSelection(L"EFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700803}
804
Lei Zhang839692f2017-08-25 23:23:57 -0700805TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700806 // Select last few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700807 TypeTextIntoTextField(12, RegularFormBegin());
808 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(165.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700809 CheckSelection(L"IJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700810
811 // Test deleting current text selection. Select what remains after deletion to
812 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700813 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700814 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700815 CheckSelection(L"ABCDEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700816}
817
Lei Zhang839692f2017-08-25 23:23:57 -0700818TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteEmptyTextFieldSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700819 // Do not select text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700820 TypeTextIntoTextField(12, RegularFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700821 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700822
823 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700824 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700825 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700826 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700827}
828
Lei Zhang839692f2017-08-25 23:23:57 -0700829TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
830 DeleteEditableComboBoxEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700831 // Select entire contents of user-editable combobox text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700832 TypeTextIntoTextField(10, EditableFormBegin());
833 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700834 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700835
836 // Test deleting current text selection. Select what remains after deletion to
837 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700838 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700839 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700840 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700841}
842
Lei Zhang839692f2017-08-25 23:23:57 -0700843TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
844 DeleteEditableComboBoxSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700845 // Select middle section of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700846 TypeTextIntoTextField(10, EditableFormBegin());
847 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700848 CheckSelection(L"DEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700849
850 // Test deleting current text selection. Select what remains after deletion to
851 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700852 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700853 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700854 CheckSelection(L"ABCIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700855}
856
Lei Zhang839692f2017-08-25 23:23:57 -0700857TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
858 DeleteEditableComboBoxSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700859 // Select first few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700860 TypeTextIntoTextField(10, EditableFormBegin());
861 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(132.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700862 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700863
864 // Test deleting current text selection. Select what remains after deletion to
865 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700866 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700867 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700868 CheckSelection(L"EFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700869}
870
Lei Zhang839692f2017-08-25 23:23:57 -0700871TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
872 DeleteEditableComboBoxSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700873 // Select last few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700874 TypeTextIntoTextField(10, EditableFormBegin());
875 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(152.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700876 CheckSelection(L"GHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700877
878 // Test deleting current text selection. Select what remains after deletion to
879 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700880 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700881 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700882 CheckSelection(L"ABCDEF");
Diana Gage1c7f1422017-07-24 11:19:52 -0700883}
884
Lei Zhang839692f2017-08-25 23:23:57 -0700885TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
886 DeleteEmptyEditableComboBoxSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700887 // Do not select text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700888 TypeTextIntoTextField(10, EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700889 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700890
891 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700892 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700893 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700894 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700895}
Diana Gageab390972017-07-28 17:07:39 -0700896
Lei Zhang839692f2017-08-25 23:23:57 -0700897TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInEmptyTextField) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700898 ClickOnFormFieldAtPoint(RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700899
900 // Test inserting text into empty text field.
901 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
902 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700903 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700904
905 // Select entire contents of text field to check that insertion worked
906 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700907 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700908 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700909}
910
Lei Zhang839692f2017-08-25 23:23:57 -0700911TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700912 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700913
914 // Click on the leftmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700915 ClickOnFormFieldAtPoint(RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700916
917 // Test inserting text in front of existing text in text field.
918 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
919 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700920 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700921
922 // Select entire contents of text field to check that insertion worked
923 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700924 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700925 CheckSelection(L"HelloABCDEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700926}
927
Lei Zhang839692f2017-08-25 23:23:57 -0700928TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700929 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700930
931 // Click on the middle of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700932 ClickOnFormFieldAtPoint(RegularFormAtX(134.0));
Diana Gageab390972017-07-28 17:07:39 -0700933
934 // Test inserting text in the middle of existing text in text field.
935 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
936 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700937 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700938
939 // Select entire contents of text field to check that insertion worked
940 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700941 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700942 CheckSelection(L"ABCDHelloEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700943}
944
Lei Zhang839692f2017-08-25 23:23:57 -0700945TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700946 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700947
948 // Click on the rightmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700949 ClickOnFormFieldAtPoint(RegularFormAtX(166.0));
Diana Gageab390972017-07-28 17:07:39 -0700950
951 // Test inserting text behind existing text in text field.
952 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
953 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700954 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700955
956 // Select entire contents of text field to check that insertion worked
957 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700958 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700959 CheckSelection(L"ABCDEFGHHello");
Diana Gageab390972017-07-28 17:07:39 -0700960}
961
Lei Zhang839692f2017-08-25 23:23:57 -0700962TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700963 InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700964 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700965
966 // Select entire string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700967 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700968 CheckSelection(L"ABCDEFGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700969
970 // Test replacing text selection with text to be inserted.
971 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
972 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700973 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700974
975 // Select entire contents of text field to check that insertion worked
976 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700977 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700978 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700979}
980
Lei Zhang839692f2017-08-25 23:23:57 -0700981TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700982 InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700983 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700984
985 // Select left portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700986 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(148.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700987 CheckSelection(L"ABCDEF");
Diana Gageab390972017-07-28 17:07:39 -0700988
989 // Test replacing text selection with text to be inserted.
990 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
991 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700992 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700993
994 // Select entire contents of text field to check that insertion worked
995 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700996 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700997 CheckSelection(L"HelloGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700998}
999
Lei Zhang839692f2017-08-25 23:23:57 -07001000TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001001 InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001002 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001003
1004 // Select middle portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001005 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(171.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001006 CheckSelection(L"DEFGHI");
Diana Gageab390972017-07-28 17:07:39 -07001007
1008 // Test replacing text selection with text to be inserted.
1009 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1010 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001011 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001012
1013 // Select entire contents of text field to check that insertion worked
1014 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001015 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001016 CheckSelection(L"ABCHelloJKL");
Diana Gageab390972017-07-28 17:07:39 -07001017}
1018
Lei Zhang839692f2017-08-25 23:23:57 -07001019TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001020 InsertTextAndReplaceSelectionInPopulatedTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001021 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001022
1023 // Select right portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001024 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001025 CheckSelection(L"GHIJKL");
Diana Gageab390972017-07-28 17:07:39 -07001026
1027 // Test replacing text selection with text to be inserted.
1028 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1029 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001030 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001031
1032 // Select entire contents of text field to check that insertion worked
1033 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001034 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001035 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -07001036}
1037
Lei Zhang839692f2017-08-25 23:23:57 -07001038TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1039 InsertTextInEmptyEditableComboBox) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001040 ClickOnFormFieldAtPoint(EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001041
1042 // Test inserting text into empty user-editable combobox.
1043 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1044 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001045 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001046
1047 // Select entire contents of user-editable combobox text field to check that
1048 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001049 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001050 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -07001051}
1052
Lei Zhang839692f2017-08-25 23:23:57 -07001053TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1054 InsertTextInPopulatedEditableComboBoxLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001055 TypeTextIntoTextField(6, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001056
1057 // Click on the leftmost part of the user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001058 ClickOnFormFieldAtPoint(EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001059
1060 // Test inserting text in front of existing text in user-editable combobox.
1061 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1062 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001063 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001064
1065 // Select entire contents of user-editable combobox text field to check that
1066 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001067 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001068 CheckSelection(L"HelloABCDEF");
Diana Gageab390972017-07-28 17:07:39 -07001069}
1070
Lei Zhang839692f2017-08-25 23:23:57 -07001071TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1072 InsertTextInPopulatedEditableComboBoxMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001073 TypeTextIntoTextField(6, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001074
1075 // Click on the middle of the user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001076 ClickOnFormFieldAtPoint(EditableFormAtX(126.0));
Diana Gageab390972017-07-28 17:07:39 -07001077
1078 // Test inserting text in the middle of existing text in user-editable
1079 // combobox.
1080 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1081 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001082 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001083
1084 // Select entire contents of user-editable combobox text field to check that
1085 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001086 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001087 CheckSelection(L"ABCHelloDEF");
Diana Gageab390972017-07-28 17:07:39 -07001088}
1089
Lei Zhang839692f2017-08-25 23:23:57 -07001090TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1091 InsertTextInPopulatedEditableComboBoxRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001092 TypeTextIntoTextField(6, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001093
1094 // Click on the rightmost part of the user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001095 ClickOnFormFieldAtPoint(EditableFormEnd());
Diana Gageab390972017-07-28 17:07:39 -07001096
1097 // Test inserting text behind existing text in user-editable combobox.
1098 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1099 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001100 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001101
1102 // Select entire contents of user-editable combobox text field to check that
1103 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001104 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001105 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -07001106}
1107
Lei Zhang839692f2017-08-25 23:23:57 -07001108TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001109 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001110 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001111
1112 // Select entire string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001113 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001114 CheckSelection(L"ABCDEFGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001115
1116 // Test replacing text selection with text to be inserted.
1117 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1118 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001119 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001120
1121 // Select entire contents of user-editable combobox text field to check that
1122 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001123 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001124 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -07001125}
1126
Lei Zhang839692f2017-08-25 23:23:57 -07001127TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001128 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001129 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001130
1131 // Select left portion of string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001132 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(142.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001133 CheckSelection(L"ABCDE");
Diana Gageab390972017-07-28 17:07:39 -07001134
1135 // Test replacing text selection with text to be inserted.
1136 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1137 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001138 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001139
1140 // Select entire contents of user-editable combobox text field to check that
1141 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001142 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001143 CheckSelection(L"HelloFGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001144}
1145
Lei Zhang839692f2017-08-25 23:23:57 -07001146TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001147 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001148 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001149
1150 // Select middle portion of string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001151 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(167.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001152 CheckSelection(L"DEFGH");
Diana Gageab390972017-07-28 17:07:39 -07001153
1154 // Test replacing text selection with text to be inserted.
1155 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1156 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001157 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001158
1159 // Select entire contents of user-editable combobox text field to check that
1160 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001161 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001162 CheckSelection(L"ABCHelloIJ");
Diana Gageab390972017-07-28 17:07:39 -07001163}
1164
Lei Zhang839692f2017-08-25 23:23:57 -07001165TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001166 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001167 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001168
1169 // Select right portion of string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001170 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001171 CheckSelection(L"FGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001172
1173 // Test replacing text selection with text to be inserted.
1174 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1175 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001176 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001177
1178 // Select entire contents of user-editable combobox text field to check that
1179 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001180 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001181 CheckSelection(L"ABCDEHello");
Diana Gageab390972017-07-28 17:07:39 -07001182}
1183
Lei Zhang839692f2017-08-25 23:23:57 -07001184TEST_F(FPDFFormFillTextFormEmbeddertest,
1185 InsertTextInEmptyCharLimitTextFieldOverflow) {
Diana Gageab390972017-07-28 17:07:39 -07001186 // Click on the textfield.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001187 ClickOnFormFieldAtPoint(CharLimitFormEnd());
Diana Gageab390972017-07-28 17:07:39 -07001188
1189 // Delete pre-filled contents of text field with char limit.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001190 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001191 CheckSelection(L"Elephant");
1192 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001193
1194 // Test inserting text into now empty text field so text to be inserted
1195 // exceeds the char limit and is cut off.
1196 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1197 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001198 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001199
1200 // Select entire contents of text field to check that insertion worked
1201 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001202 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001203 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001204}
1205
Lei Zhang839692f2017-08-25 23:23:57 -07001206TEST_F(FPDFFormFillTextFormEmbeddertest,
1207 InsertTextInEmptyCharLimitTextFieldFit) {
Diana Gageab390972017-07-28 17:07:39 -07001208 // Click on the textfield.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001209 ClickOnFormFieldAtPoint(CharLimitFormEnd());
Diana Gageab390972017-07-28 17:07:39 -07001210
1211 // Delete pre-filled contents of text field with char limit.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001212 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001213 CheckSelection(L"Elephant");
1214 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001215
1216 // Test inserting text into now empty text field so text to be inserted
1217 // exceeds the char limit and is cut off.
1218 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1219 GetFPDFWideString(L"Zebra");
Lei Zhang839692f2017-08-25 23:23:57 -07001220 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001221
1222 // Select entire contents of text field to check that insertion worked
1223 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001224 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001225 CheckSelection(L"Zebra");
Diana Gageab390972017-07-28 17:07:39 -07001226}
1227
Lei Zhang839692f2017-08-25 23:23:57 -07001228TEST_F(FPDFFormFillTextFormEmbeddertest,
1229 InsertTextInPopulatedCharLimitTextFieldLeft) {
Diana Gageab390972017-07-28 17:07:39 -07001230 // Click on the leftmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001231 ClickOnFormFieldAtPoint(CharLimitFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001232
1233 // Test inserting text in front of existing text in text field.
1234 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1235 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001236 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001237
1238 // Select entire contents of text field to check that insertion worked
1239 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001240 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001241 CheckSelection(L"HiElephant");
Diana Gageab390972017-07-28 17:07:39 -07001242}
1243
Lei Zhang839692f2017-08-25 23:23:57 -07001244TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001245 InsertTextInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001246 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001247
1248 // Click on the middle of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001249 ClickOnFormFieldAtPoint(CharLimitFormAtX(134.0));
Diana Gageab390972017-07-28 17:07:39 -07001250
1251 // Test inserting text in the middle of existing text in text field.
1252 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1253 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001254 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001255
1256 // Select entire contents of text field to check that insertion worked
1257 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001258 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001259 CheckSelection(L"ElephHiant");
Diana Gageab390972017-07-28 17:07:39 -07001260}
1261
Lei Zhang839692f2017-08-25 23:23:57 -07001262TEST_F(FPDFFormFillTextFormEmbeddertest,
1263 InsertTextInPopulatedCharLimitTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001264 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001265
1266 // Click on the rightmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001267 ClickOnFormFieldAtPoint(CharLimitFormAtX(166.0));
Diana Gageab390972017-07-28 17:07:39 -07001268
1269 // Test inserting text behind existing text in text field.
1270 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1271 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001272 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001273
1274 // Select entire contents of text field to check that insertion worked
1275 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001276 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001277 CheckSelection(L"ElephantHi");
Diana Gageab390972017-07-28 17:07:39 -07001278}
1279
Lei Zhang839692f2017-08-25 23:23:57 -07001280TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001281 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001282 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001283
1284 // Select entire string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001285 SelectTextWithKeyboard(12, FWL_VKEY_Left, CharLimitFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001286 CheckSelection(L"Elephant");
Diana Gageab390972017-07-28 17:07:39 -07001287
1288 // Test replacing text selection with text to be inserted.
1289 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1290 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001291 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001292
1293 // Select entire contents of text field to check that insertion worked
1294 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001295 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001296 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001297}
1298
Lei Zhang839692f2017-08-25 23:23:57 -07001299TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001300 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001301 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001302
1303 // Select left portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001304 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(122.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001305 CheckSelection(L"Elep");
Diana Gageab390972017-07-28 17:07:39 -07001306
1307 // Test replacing text selection with text to be inserted.
1308 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1309 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001310 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001311
1312 // Select entire contents of text field to check that insertion worked
1313 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001314 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001315 CheckSelection(L"Hippophant");
Diana Gageab390972017-07-28 17:07:39 -07001316}
1317
Lei Zhang839692f2017-08-25 23:23:57 -07001318TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001319 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001320 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001321
1322 // Select middle portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001323 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(136.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001324 CheckSelection(L"epha");
Diana Gageab390972017-07-28 17:07:39 -07001325
1326 // Test replacing text selection with text to be inserted.
1327 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1328 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001329 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001330
1331 // Select entire contents of text field to check that insertion worked
1332 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001333 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001334 CheckSelection(L"ElHippopnt");
Diana Gageab390972017-07-28 17:07:39 -07001335}
1336
Lei Zhang839692f2017-08-25 23:23:57 -07001337TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001338 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001339 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001340
1341 // Select right portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001342 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(152.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001343 CheckSelection(L"hant");
Diana Gageab390972017-07-28 17:07:39 -07001344
1345 // Test replacing text selection with text to be inserted.
1346 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1347 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001348 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001349
1350 // Select entire contents of text field to check that insertion worked
1351 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001352 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001353 CheckSelection(L"ElepHippop");
Diana Gageab390972017-07-28 17:07:39 -07001354}