blob: 93350874dcbc77524a46d234c88ee5c164174ef5 [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
Lei Zhang839692f2017-08-25 23:23:57 -0700109 void CheckSelection(const CFX_WideStringC& 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
124 EXPECT_EQ(expected_string,
125 CFX_WideString::FromUTF16LE(buf.data(), num_chars));
126 }
Diana Gagecb50b5f2017-06-29 09:54:19 -0700127
Lei Zhang839692f2017-08-25 23:23:57 -0700128 private:
129 FPDF_PAGE page_ = nullptr;
130};
131
132class FPDFFormFillTextFormEmbeddertest
133 : public FPDFFormFillInteractiveEmbeddertest {
134 protected:
135 FPDFFormFillTextFormEmbeddertest() = default;
136 ~FPDFFormFillTextFormEmbeddertest() override = default;
137
138 const char* GetDocumentName() const override {
139 // PDF with several form text fields:
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700140 // - "Text Box" - Regular text box with no special attributes.
Lei Zhang839692f2017-08-25 23:23:57 -0700141 // - "ReadOnly" - Ff: 1.
142 // - "CharLimit" - MaxLen: 10, V: Elephant.
143 return "text_form_multiple.pdf";
144 }
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700145
146 int GetFormType() const override { return FPDF_FORMFIELD_TEXTFIELD; }
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700147
148 void FormSanityChecks() override {
149 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(CharLimitFormBegin()));
150 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(CharLimitFormEnd()));
151 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(RegularFormBegin()));
152 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(RegularFormEnd()));
153 }
154
155 void SelectAllCharLimitFormTextWithMouse() {
156 SelectTextWithMouse(CharLimitFormEnd(), CharLimitFormBegin());
157 }
158
159 void SelectAllRegularFormTextWithMouse() {
160 SelectTextWithMouse(RegularFormEnd(), RegularFormBegin());
161 }
162
163 const CFX_PointF& CharLimitFormBegin() const {
164 static const CFX_PointF point = CharLimitFormAtX(kFormBeginX);
165 return point;
166 }
167
168 const CFX_PointF& CharLimitFormEnd() const {
169 static const CFX_PointF point = CharLimitFormAtX(kFormEndX);
170 return point;
171 }
172
173 const CFX_PointF& RegularFormBegin() const {
174 static const CFX_PointF point = RegularFormAtX(kFormBeginX);
175 return point;
176 }
177
178 const CFX_PointF& RegularFormEnd() const {
179 static const CFX_PointF point = RegularFormAtX(kFormEndX);
180 return point;
181 }
182
183 static CFX_PointF CharLimitFormAtX(float x) {
184 ASSERT(x >= kFormBeginX);
185 ASSERT(x <= kFormEndX);
186 return CFX_PointF(x, kCharLimitFormY);
187 }
188
189 static CFX_PointF RegularFormAtX(float x) {
190 ASSERT(x >= kFormBeginX);
191 ASSERT(x <= kFormEndX);
192 return CFX_PointF(x, kRegularFormY);
193 }
194
195 private:
196 static constexpr float kFormBeginX = 102.0;
197 static constexpr float kFormEndX = 195.0;
198 static constexpr float kCharLimitFormY = 60.0;
199 static constexpr float kRegularFormY = 115.0;
Lei Zhang839692f2017-08-25 23:23:57 -0700200};
201
202class FPDFFormFillComboBoxFormEmbeddertest
203 : public FPDFFormFillInteractiveEmbeddertest {
204 protected:
205 FPDFFormFillComboBoxFormEmbeddertest() = default;
206 ~FPDFFormFillComboBoxFormEmbeddertest() override = default;
207
208 const char* GetDocumentName() const override {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700209 // PDF with form comboboxes:
210 // - "Combo_Editable" - Ff: 393216, 3 options with pair values.
211 // - "Combo1" - Ff: 131072, 3 options with single values.
212 // - "Combo_ReadOnly" - Ff: 131073, 3 options with single values.
Lei Zhang839692f2017-08-25 23:23:57 -0700213 return "combobox_form.pdf";
214 }
215
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700216 int GetFormType() const override { return FPDF_FORMFIELD_COMBOBOX; }
217
Lei Zhang839692f2017-08-25 23:23:57 -0700218 void FormSanityChecks() override {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700219 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormBegin()));
220 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormEnd()));
221 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormDropDown()));
222 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormBegin()));
223 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormEnd()));
224 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormDropDown()));
Lei Zhang839692f2017-08-25 23:23:57 -0700225 }
226
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700227 void SelectEditableFormOption(int item_index) {
228 SelectOption(item_index, EditableFormDropDown());
229 }
230
231 void SelectNonEditableFormOption(int item_index) {
232 SelectOption(item_index, NonEditableFormDropDown());
233 }
234
235 void SelectAllEditableFormTextWithMouse() {
236 SelectTextWithMouse(EditableFormEnd(), EditableFormBegin());
237 }
238
239 const CFX_PointF& EditableFormBegin() const {
240 static const CFX_PointF point = EditableFormAtX(kFormBeginX);
241 return point;
242 }
243
244 const CFX_PointF& EditableFormEnd() const {
245 static const CFX_PointF point = EditableFormAtX(kFormEndX);
246 return point;
247 }
248
249 const CFX_PointF& EditableFormDropDown() const {
250 static const CFX_PointF point(kFormDropDownX, kEditableFormY);
251 return point;
252 }
253
254 const CFX_PointF& NonEditableFormBegin() const {
255 static const CFX_PointF point = NonEditableFormAtX(kFormBeginX);
256 return point;
257 }
258
259 const CFX_PointF& NonEditableFormEnd() const {
260 static const CFX_PointF point = NonEditableFormAtX(kFormEndX);
261 return point;
262 }
263
264 const CFX_PointF& NonEditableFormDropDown() const {
265 static const CFX_PointF point(kFormDropDownX, kNonEditableFormY);
266 return point;
267 }
268
269 static CFX_PointF EditableFormAtX(float x) {
270 ASSERT(x >= kFormBeginX);
271 ASSERT(x <= kFormEndX);
272 return CFX_PointF(x, kEditableFormY);
273 }
274
275 static CFX_PointF NonEditableFormAtX(float x) {
276 ASSERT(x >= kFormBeginX);
277 ASSERT(x <= kFormEndX);
278 return CFX_PointF(x, kNonEditableFormY);
279 }
280
281 private:
Diana Gagecb50b5f2017-06-29 09:54:19 -0700282 // Selects one of the pre-selected values from a combobox with three options.
283 // Options are specified by |item_index|, which is 0-based.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700284 void SelectOption(int item_index, const CFX_PointF& point) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700285 // Only relevant for comboboxes with three choices and the same dimensions
286 // as those in combobox_form.pdf.
287 ASSERT(item_index >= 0);
288 ASSERT(item_index < 3);
289
290 // Navigate to button for drop down and click mouse to reveal options.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700291 ClickOnFormFieldAtPoint(point);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700292
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700293 // Calculate to Y-coordinate of dropdown option to be selected.
Diana Gagecb50b5f2017-06-29 09:54:19 -0700294 constexpr double kChoiceHeight = 15;
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700295 CFX_PointF option_point = point;
296 option_point.y -= kChoiceHeight * (item_index + 1);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700297
298 // Navigate to option and click mouse to select it.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700299 ClickOnFormFieldAtPoint(option_point);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700300 }
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700301
302 static constexpr float kFormBeginX = 102.0;
303 static constexpr float kFormEndX = 183.0;
304 static constexpr float kFormDropDownX = 192.0;
305 static constexpr float kEditableFormY = 60.0;
306 static constexpr float kNonEditableFormY = 110.0;
Diana Gagedce2d722017-06-20 11:17:11 -0700307};
Tom Sepeza310e002015-02-27 13:03:07 -0800308
309TEST_F(FPDFFormFillEmbeddertest, FirstTest) {
310 EmbedderTestMockDelegate mock;
311 EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0);
312 EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700313 EXPECT_CALL(mock, SetTimer(_, _)).Times(0);
314 EXPECT_CALL(mock, KillTimer(_)).Times(0);
Tom Sepeza310e002015-02-27 13:03:07 -0800315 SetDelegate(&mock);
316
Wei Li091f7a02015-11-09 12:09:55 -0800317 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepeza310e002015-02-27 13:03:07 -0800318 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700319 EXPECT_TRUE(page);
Lei Zhangd27acae2015-05-15 15:36:02 -0700320 UnloadPage(page);
Tom Sepeza310e002015-02-27 13:03:07 -0800321}
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700322
323TEST_F(FPDFFormFillEmbeddertest, BUG_487928) {
324 EmbedderTestTimerHandlingDelegate delegate;
325 SetDelegate(&delegate);
326
Wei Li091f7a02015-11-09 12:09:55 -0800327 EXPECT_TRUE(OpenDocument("bug_487928.pdf"));
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700328 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700329 EXPECT_TRUE(page);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700330 DoOpenActions();
331 delegate.AdvanceTime(5000);
332 UnloadPage(page);
333}
Tom Sepez0b133982015-07-28 11:23:22 -0700334
Tom Sepez396e8722015-09-09 10:16:08 -0700335TEST_F(FPDFFormFillEmbeddertest, BUG_507316) {
336 EmbedderTestTimerHandlingDelegate delegate;
337 SetDelegate(&delegate);
338
Wei Li091f7a02015-11-09 12:09:55 -0800339 EXPECT_TRUE(OpenDocument("bug_507316.pdf"));
weili0dadcc62016-08-23 21:10:57 -0700340 FPDF_PAGE page = LoadPage(2);
tsepez8e120292016-08-03 14:03:35 -0700341 EXPECT_TRUE(page);
Tom Sepez396e8722015-09-09 10:16:08 -0700342 DoOpenActions();
343 delegate.AdvanceTime(4000);
344 UnloadPage(page);
345}
346
Tom Sepez0b133982015-07-28 11:23:22 -0700347TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
Wei Li091f7a02015-11-09 12:09:55 -0800348 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0b133982015-07-28 11:23:22 -0700349 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700350 EXPECT_TRUE(page);
Tom Sepez0b133982015-07-28 11:23:22 -0700351
352 // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES.
353 FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0);
354 FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0);
355
356 UnloadPage(page);
357}
Lei Zhang79e893a2015-11-04 16:02:47 -0800358
Tom Sepez4d071792016-02-04 16:53:26 -0800359#ifdef PDF_ENABLE_V8
Lei Zhang79e893a2015-11-04 16:02:47 -0800360TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
tsepez8e120292016-08-03 14:03:35 -0700361 // Test that timers fire once and intervals fire repeatedly.
Lei Zhang79e893a2015-11-04 16:02:47 -0800362 EmbedderTestTimerHandlingDelegate delegate;
363 SetDelegate(&delegate);
364
Wei Li091f7a02015-11-09 12:09:55 -0800365 EXPECT_TRUE(OpenDocument("bug_551248.pdf"));
Lei Zhang79e893a2015-11-04 16:02:47 -0800366 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700367 EXPECT_TRUE(page);
368 DoOpenActions();
369
370 const auto& alerts = delegate.GetAlerts();
371 EXPECT_EQ(0U, alerts.size());
372
373 delegate.AdvanceTime(1000);
374 EXPECT_EQ(0U, alerts.size()); // nothing fired.
375 delegate.AdvanceTime(1000);
376 EXPECT_EQ(1U, alerts.size()); // interval fired.
377 delegate.AdvanceTime(1000);
378 EXPECT_EQ(2U, alerts.size()); // timer fired.
379 delegate.AdvanceTime(1000);
380 EXPECT_EQ(3U, alerts.size()); // interval fired again.
381 delegate.AdvanceTime(1000);
382 EXPECT_EQ(3U, alerts.size()); // nothing fired.
383 delegate.AdvanceTime(1000);
384 EXPECT_EQ(4U, alerts.size()); // interval fired again.
385 delegate.AdvanceTime(1000);
386 EXPECT_EQ(4U, alerts.size()); // nothing fired.
387 UnloadPage(page);
388
389 ASSERT_EQ(4U, alerts.size()); // nothing else fired.
390
391 EXPECT_STREQ(L"interval fired", alerts[0].message.c_str());
392 EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
393 EXPECT_EQ(0, alerts[0].type);
394 EXPECT_EQ(0, alerts[0].icon);
395
396 EXPECT_STREQ(L"timer fired", alerts[1].message.c_str());
397 EXPECT_STREQ(L"Alert", alerts[1].title.c_str());
398 EXPECT_EQ(0, alerts[1].type);
399 EXPECT_EQ(0, alerts[1].icon);
400
401 EXPECT_STREQ(L"interval fired", alerts[2].message.c_str());
402 EXPECT_STREQ(L"Alert", alerts[2].title.c_str());
403 EXPECT_EQ(0, alerts[2].type);
404 EXPECT_EQ(0, alerts[2].icon);
405
406 EXPECT_STREQ(L"interval fired", alerts[3].message.c_str());
407 EXPECT_STREQ(L"Alert", alerts[3].title.c_str());
408 EXPECT_EQ(0, alerts[3].type);
409 EXPECT_EQ(0, alerts[3].icon);
410}
411
412TEST_F(FPDFFormFillEmbeddertest, BUG_620428) {
413 // Test that timers and intervals are cancelable.
414 EmbedderTestTimerHandlingDelegate delegate;
415 SetDelegate(&delegate);
416
417 EXPECT_TRUE(OpenDocument("bug_620428.pdf"));
418 FPDF_PAGE page = LoadPage(0);
419 EXPECT_TRUE(page);
Lei Zhang79e893a2015-11-04 16:02:47 -0800420 DoOpenActions();
421 delegate.AdvanceTime(5000);
422 UnloadPage(page);
423
424 const auto& alerts = delegate.GetAlerts();
tsepez0fa54b82016-08-04 12:07:28 -0700425 ASSERT_EQ(1U, alerts.size());
426 EXPECT_STREQ(L"done", alerts[0].message.c_str());
Lei Zhang79e893a2015-11-04 16:02:47 -0800427}
tsepez8e120292016-08-03 14:03:35 -0700428
tsepez32e693f2016-08-04 12:47:42 -0700429TEST_F(FPDFFormFillEmbeddertest, BUG_634394) {
430 // Cancel timer inside timer callback.
431 EmbedderTestTimerHandlingDelegate delegate;
432 SetDelegate(&delegate);
433
434 EXPECT_TRUE(OpenDocument("bug_634394.pdf"));
435 FPDF_PAGE page = LoadPage(0);
436 EXPECT_TRUE(page);
437 DoOpenActions();
438
439 // Timers fire at most once per AdvanceTime(), allow intervals
440 // to fire several times if possible.
441 delegate.AdvanceTime(1000);
442 delegate.AdvanceTime(1000);
443 delegate.AdvanceTime(1000);
444 delegate.AdvanceTime(1000);
445 delegate.AdvanceTime(1000);
446 UnloadPage(page);
447
448 const auto& alerts = delegate.GetAlerts();
449 EXPECT_EQ(2U, alerts.size());
450}
451
tsepez8ca63de2016-08-05 17:12:27 -0700452TEST_F(FPDFFormFillEmbeddertest, BUG_634716) {
453 EmbedderTestTimerHandlingDelegate delegate;
454 SetDelegate(&delegate);
455
456 EXPECT_TRUE(OpenDocument("bug_634716.pdf"));
457 FPDF_PAGE page = LoadPage(0);
458 EXPECT_TRUE(page);
459 DoOpenActions();
460
461 // Timers fire at most once per AdvanceTime(), allow intervals
462 // to fire several times if possible.
463 delegate.AdvanceTime(1000);
464 delegate.AdvanceTime(1000);
465 delegate.AdvanceTime(1000);
466 delegate.AdvanceTime(1000);
467 delegate.AdvanceTime(1000);
468 UnloadPage(page);
469
470 const auto& alerts = delegate.GetAlerts();
471 EXPECT_EQ(2U, alerts.size());
472}
473
tsepez6cf5eca2017-01-12 11:21:12 -0800474TEST_F(FPDFFormFillEmbeddertest, BUG_679649) {
475 EmbedderTestTimerHandlingDelegate delegate;
476 SetDelegate(&delegate);
477
478 EXPECT_TRUE(OpenDocument("bug_679649.pdf"));
479 FPDF_PAGE page = LoadPage(0);
480 EXPECT_TRUE(page);
481
482 delegate.SetFailNextTimer();
483 DoOpenActions();
484 delegate.AdvanceTime(2000);
485 UnloadPage(page);
486
487 const auto& alerts = delegate.GetAlerts();
488 EXPECT_EQ(0u, alerts.size());
489}
490
Tom Sepezfb7021c2017-05-31 10:29:25 -0700491TEST_F(FPDFFormFillEmbeddertest, BUG_707673) {
492 EmbedderTestTimerHandlingDelegate delegate;
493 SetDelegate(&delegate);
494
495 EXPECT_TRUE(OpenDocument("bug_707673.pdf"));
496 FPDF_PAGE page = LoadPage(0);
497 EXPECT_TRUE(page);
498
499 DoOpenActions();
500 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
501 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
502 delegate.AdvanceTime(1000);
503 UnloadPage(page);
504
505 const auto& alerts = delegate.GetAlerts();
506 EXPECT_EQ(0u, alerts.size());
507}
508
Tom Sepez4d071792016-02-04 16:53:26 -0800509#endif // PDF_ENABLE_V8
Nicolas Pena742977f2017-04-13 15:28:20 -0400510
511TEST_F(FPDFFormFillEmbeddertest, FormText) {
512#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
513 const char md5_1[] = "5f11dbe575fe197a37c3fb422559f8ff";
514 const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d";
515 const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe";
516#else
Nicolas Pena00c3cfd2017-07-10 17:29:54 -0400517 const char md5_1[] = "a5e3ac74c2ee123ec6710e2f0ef8424a";
518 const char md5_2[] = "4526b09382e144d5506ad92149399de6";
519 const char md5_3[] = "80356067d860088864cf50ff85d8459e";
Nicolas Pena742977f2017-04-13 15:28:20 -0400520#endif
521 {
522 EXPECT_TRUE(OpenDocument("text_form.pdf"));
523 FPDF_PAGE page = LoadPage(0);
524 ASSERT_TRUE(page);
525 std::unique_ptr<void, FPDFBitmapDeleter> bitmap1(RenderPage(page));
526 CompareBitmap(bitmap1.get(), 300, 300, md5_1);
527
528 // Click on the textfield
529 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
530 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
531 FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
532 FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
533 FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
534
535 // Write "ABC"
536 FORM_OnChar(form_handle(), page, 65, 0);
537 FORM_OnChar(form_handle(), page, 66, 0);
538 FORM_OnChar(form_handle(), page, 67, 0);
539 std::unique_ptr<void, FPDFBitmapDeleter> bitmap2(RenderPage(page));
540 CompareBitmap(bitmap2.get(), 300, 300, md5_2);
541
542 // Take out focus by clicking out of the textfield
543 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
544 FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
545 FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
546 std::unique_ptr<void, FPDFBitmapDeleter> bitmap3(RenderPage(page));
547 CompareBitmap(bitmap3.get(), 300, 300, md5_3);
548
549 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
550
Nicolas Pena3ff54002017-07-05 11:55:35 -0400551 // Close page
Nicolas Pena742977f2017-04-13 15:28:20 -0400552 UnloadPage(page);
Nicolas Pena742977f2017-04-13 15:28:20 -0400553 }
554 // Check saved document
Nicolas Pena3ff54002017-07-05 11:55:35 -0400555 TestAndCloseSaved(300, 300, md5_3);
Nicolas Pena742977f2017-04-13 15:28:20 -0400556}
Diana Gagedce2d722017-06-20 11:17:11 -0700557
Lei Zhang839692f2017-08-25 23:23:57 -0700558TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) {
Diana Gagedce2d722017-06-20 11:17:11 -0700559 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700560 CheckSelection(L"");
Diana Gagedce2d722017-06-20 11:17:11 -0700561
562 // Test basic selection.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700563 TypeTextIntoTextField(3, RegularFormBegin());
564 SelectTextWithKeyboard(3, FWL_VKEY_Left, RegularFormAtX(123.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700565 CheckSelection(L"ABC");
Diana Gagedce2d722017-06-20 11:17:11 -0700566}
567
Lei Zhang839692f2017-08-25 23:23:57 -0700568TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicMouse) {
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 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormBegin());
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, GetSelectedTextFragmentsKeyBoard) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700579 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gagedce2d722017-06-20 11:17:11 -0700580
581 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700582 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700583 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700584
585 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700586 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700587 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700588
589 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700590 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(170.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700591 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700592
593 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700594 SelectTextWithKeyboard(6, FWL_VKEY_Right, RegularFormAtX(125.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700595 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700596
597 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700598 SelectTextWithKeyboard(1, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700599 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700600}
601
Lei Zhang839692f2017-08-25 23:23:57 -0700602TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsMouse) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700603 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gagedce2d722017-06-20 11:17:11 -0700604
605 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700606 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(106.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700607 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700608
609 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700610 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700611 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700612
613 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700614 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700615 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700616
617 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700618 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormAtX(170.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700619 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700620
621 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700622 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(186.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700623 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700624}
Diana Gagecb50b5f2017-06-29 09:54:19 -0700625
Lei Zhang839692f2017-08-25 23:23:57 -0700626TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
627 GetSelectedTextEmptyAndBasicNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700628 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700629 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700630
631 // Non-editable comboboxes don't allow selection with keyboard.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700632 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(142.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700633 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700634
635 // Select other another provided option.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700636 SelectNonEditableFormOption(0);
Lei Zhang839692f2017-08-25 23:23:57 -0700637 CheckSelection(L"Apple");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700638}
639
Lei Zhang839692f2017-08-25 23:23:57 -0700640TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700641 GetSelectedTextEmptyAndBasicEditableComboBoxKeyboard) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700642 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700643 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700644
645 // Test basic selection of text within user editable combobox using keyboard.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700646 TypeTextIntoTextField(3, EditableFormBegin());
647 SelectTextWithKeyboard(3, FWL_VKEY_Left, EditableFormAtX(128.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700648 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700649
650 // Select a provided option.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700651 SelectEditableFormOption(1);
Lei Zhang839692f2017-08-25 23:23:57 -0700652 CheckSelection(L"Bar");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700653}
654
Lei Zhang839692f2017-08-25 23:23:57 -0700655TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700656 GetSelectedTextEmptyAndBasicEditableComboBoxMouse) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700657 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700658 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700659
660 // Test basic selection of text within user editable combobox using mouse.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700661 TypeTextIntoTextField(3, EditableFormBegin());
662 SelectTextWithMouse(EditableFormAtX(128.0), EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700663 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700664
665 // Select a provided option.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700666 SelectEditableFormOption(2);
Lei Zhang839692f2017-08-25 23:23:57 -0700667 CheckSelection(L"Qux");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700668}
669
Lei Zhang839692f2017-08-25 23:23:57 -0700670TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
671 GetSelectedTextFragmentsNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700672 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700673 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(107.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700674 CheckSelection(L"B");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700675
676 // Test selecting entire string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700677 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700678 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700679
680 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700681 SelectTextWithMouse(NonEditableFormAtX(135.0), NonEditableFormAtX(117.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700682 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700683
684 // Test selecting middle section in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700685 SelectTextWithMouse(NonEditableFormAtX(117.0), NonEditableFormAtX(135.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700686 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700687
688 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700689 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormAtX(138.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700690 CheckSelection(L"a");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700691
692 // Select another option and then reset selection as first three chars.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700693 SelectNonEditableFormOption(2);
Lei Zhang839692f2017-08-25 23:23:57 -0700694 CheckSelection(L"Cherry");
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700695 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(122.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700696 CheckSelection(L"Che");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700697}
698
Lei Zhang839692f2017-08-25 23:23:57 -0700699TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700700 GetSelectedTextFragmentsEditableComboBoxKeyboard) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700701 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gagecb50b5f2017-06-29 09:54:19 -0700702
703 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700704 SelectTextWithKeyboard(1, FWL_VKEY_Right, EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700705 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700706
707 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700708 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700709 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700710
711 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700712 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(168.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700713 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700714
715 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700716 SelectTextWithKeyboard(5, FWL_VKEY_Right, EditableFormAtX(127.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700717 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700718
719 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700720 SelectTextWithKeyboard(1, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700721 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700722
723 // Select a provided option and then reset selection as first two chars.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700724 SelectEditableFormOption(0);
Lei Zhang839692f2017-08-25 23:23:57 -0700725 CheckSelection(L"Foo");
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700726 SelectTextWithKeyboard(2, FWL_VKEY_Right, EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700727 CheckSelection(L"Fo");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700728}
729
Lei Zhang839692f2017-08-25 23:23:57 -0700730TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700731 GetSelectedTextFragmentsEditableComboBoxMouse) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700732 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gagecb50b5f2017-06-29 09:54:19 -0700733
734 // Test selecting first character in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700735 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(107.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700736 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700737
738 // Test selecting entire long string in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700739 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700740 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700741
742 // Test selecting middle section in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700743 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700744 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700745
746 // Test selecting middle selection in forward direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700747 SelectTextWithMouse(EditableFormAtX(127.0), EditableFormAtX(168.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700748 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700749
750 // Test selecting last character in backwards direction.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700751 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(174.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700752 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700753}
Diana Gage1c7f1422017-07-24 11:19:52 -0700754
Lei Zhang839692f2017-08-25 23:23:57 -0700755TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700756 // Select entire contents of text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700757 TypeTextIntoTextField(12, RegularFormBegin());
758 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700759 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700760
761 // Test deleting current text selection. Select what remains after deletion to
762 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700763 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -0700764
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700765 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700766 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700767}
768
Lei Zhang839692f2017-08-25 23:23:57 -0700769TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700770 // Select middle section of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700771 TypeTextIntoTextField(12, RegularFormBegin());
772 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700773 CheckSelection(L"DEFGHI");
Diana Gage1c7f1422017-07-24 11:19:52 -0700774
775 // Test deleting current text selection. Select what remains after deletion to
776 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700777 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700778 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700779 CheckSelection(L"ABCJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700780}
781
Lei Zhang839692f2017-08-25 23:23:57 -0700782TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700783 // Select first few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700784 TypeTextIntoTextField(12, RegularFormBegin());
785 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(132.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700786 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700787
788 // Test deleting current text selection. Select what remains after deletion to
789 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700790 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700791 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700792 CheckSelection(L"EFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700793}
794
Lei Zhang839692f2017-08-25 23:23:57 -0700795TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700796 // Select last few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700797 TypeTextIntoTextField(12, RegularFormBegin());
798 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(165.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700799 CheckSelection(L"IJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700800
801 // Test deleting current text selection. Select what remains after deletion to
802 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700803 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700804 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700805 CheckSelection(L"ABCDEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700806}
807
Lei Zhang839692f2017-08-25 23:23:57 -0700808TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteEmptyTextFieldSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700809 // Do not select text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700810 TypeTextIntoTextField(12, RegularFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700811 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700812
813 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700814 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700815 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700816 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700817}
818
Lei Zhang839692f2017-08-25 23:23:57 -0700819TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
820 DeleteEditableComboBoxEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700821 // Select entire contents of user-editable combobox text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700822 TypeTextIntoTextField(10, EditableFormBegin());
823 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700824 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700825
826 // Test deleting current text selection. Select what remains after deletion to
827 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700828 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700829 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700830 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700831}
832
Lei Zhang839692f2017-08-25 23:23:57 -0700833TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
834 DeleteEditableComboBoxSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700835 // Select middle section of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700836 TypeTextIntoTextField(10, EditableFormBegin());
837 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700838 CheckSelection(L"DEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700839
840 // Test deleting current text selection. Select what remains after deletion to
841 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700842 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700843 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700844 CheckSelection(L"ABCIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700845}
846
Lei Zhang839692f2017-08-25 23:23:57 -0700847TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
848 DeleteEditableComboBoxSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700849 // Select first few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700850 TypeTextIntoTextField(10, EditableFormBegin());
851 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(132.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700852 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700853
854 // Test deleting current text selection. Select what remains after deletion to
855 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700856 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700857 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700858 CheckSelection(L"EFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700859}
860
Lei Zhang839692f2017-08-25 23:23:57 -0700861TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
862 DeleteEditableComboBoxSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700863 // Select last few characters of text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700864 TypeTextIntoTextField(10, EditableFormBegin());
865 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(152.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700866 CheckSelection(L"GHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700867
868 // Test deleting current text selection. Select what remains after deletion to
869 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700870 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700871 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700872 CheckSelection(L"ABCDEF");
Diana Gage1c7f1422017-07-24 11:19:52 -0700873}
874
Lei Zhang839692f2017-08-25 23:23:57 -0700875TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
876 DeleteEmptyEditableComboBoxSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700877 // Do not select text.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700878 TypeTextIntoTextField(10, EditableFormBegin());
Lei Zhang839692f2017-08-25 23:23:57 -0700879 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700880
881 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700882 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700883 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700884 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700885}
Diana Gageab390972017-07-28 17:07:39 -0700886
Lei Zhang839692f2017-08-25 23:23:57 -0700887TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInEmptyTextField) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700888 ClickOnFormFieldAtPoint(RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700889
890 // Test inserting text into empty text field.
891 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
892 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700893 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700894
895 // Select entire contents of text field to check that insertion worked
896 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700897 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700898 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700899}
900
Lei Zhang839692f2017-08-25 23:23:57 -0700901TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700902 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700903
904 // Click on the leftmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700905 ClickOnFormFieldAtPoint(RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700906
907 // Test inserting text in front of existing text in text field.
908 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
909 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700910 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700911
912 // Select entire contents of text field to check that insertion worked
913 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700914 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700915 CheckSelection(L"HelloABCDEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700916}
917
Lei Zhang839692f2017-08-25 23:23:57 -0700918TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700919 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700920
921 // Click on the middle of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700922 ClickOnFormFieldAtPoint(RegularFormAtX(134.0));
Diana Gageab390972017-07-28 17:07:39 -0700923
924 // Test inserting text in the middle of existing text in text field.
925 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
926 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700927 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700928
929 // Select entire contents of text field to check that insertion worked
930 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700931 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700932 CheckSelection(L"ABCDHelloEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700933}
934
Lei Zhang839692f2017-08-25 23:23:57 -0700935TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700936 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700937
938 // Click on the rightmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700939 ClickOnFormFieldAtPoint(RegularFormAtX(166.0));
Diana Gageab390972017-07-28 17:07:39 -0700940
941 // Test inserting text behind existing text in text field.
942 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
943 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700944 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700945
946 // Select entire contents of text field to check that insertion worked
947 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700948 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700949 CheckSelection(L"ABCDEFGHHello");
Diana Gageab390972017-07-28 17:07:39 -0700950}
951
Lei Zhang839692f2017-08-25 23:23:57 -0700952TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700953 InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700954 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700955
956 // Select entire string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700957 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -0700958 CheckSelection(L"ABCDEFGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700959
960 // Test replacing text selection with text to be inserted.
961 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
962 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700963 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700964
965 // Select entire contents of text field to check that insertion worked
966 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700967 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700968 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700969}
970
Lei Zhang839692f2017-08-25 23:23:57 -0700971TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700972 InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700973 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700974
975 // Select left portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700976 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(148.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700977 CheckSelection(L"ABCDEF");
Diana Gageab390972017-07-28 17:07:39 -0700978
979 // Test replacing text selection with text to be inserted.
980 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
981 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700982 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700983
984 // Select entire contents of text field to check that insertion worked
985 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700986 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -0700987 CheckSelection(L"HelloGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700988}
989
Lei Zhang839692f2017-08-25 23:23:57 -0700990TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700991 InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700992 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -0700993
994 // Select middle portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -0700995 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(171.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700996 CheckSelection(L"DEFGHI");
Diana Gageab390972017-07-28 17:07:39 -0700997
998 // Test replacing text selection with text to be inserted.
999 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1000 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001001 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001002
1003 // Select entire contents of text field to check that insertion worked
1004 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001005 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001006 CheckSelection(L"ABCHelloJKL");
Diana Gageab390972017-07-28 17:07:39 -07001007}
1008
Lei Zhang839692f2017-08-25 23:23:57 -07001009TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001010 InsertTextAndReplaceSelectionInPopulatedTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001011 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001012
1013 // Select right portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001014 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001015 CheckSelection(L"GHIJKL");
Diana Gageab390972017-07-28 17:07:39 -07001016
1017 // Test replacing text selection with text to be inserted.
1018 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1019 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001020 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001021
1022 // Select entire contents of text field to check that insertion worked
1023 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001024 SelectAllRegularFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001025 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -07001026}
1027
Lei Zhang839692f2017-08-25 23:23:57 -07001028TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1029 InsertTextInEmptyEditableComboBox) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001030 ClickOnFormFieldAtPoint(EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001031
1032 // Test inserting text into empty user-editable combobox.
1033 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1034 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001035 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001036
1037 // Select entire contents of user-editable combobox text field to check that
1038 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001039 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001040 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -07001041}
1042
Lei Zhang839692f2017-08-25 23:23:57 -07001043TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1044 InsertTextInPopulatedEditableComboBoxLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001045 TypeTextIntoTextField(6, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001046
1047 // Click on the leftmost part of the user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001048 ClickOnFormFieldAtPoint(EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001049
1050 // Test inserting text in front of existing text in user-editable combobox.
1051 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1052 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001053 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001054
1055 // Select entire contents of user-editable combobox text field to check that
1056 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001057 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001058 CheckSelection(L"HelloABCDEF");
Diana Gageab390972017-07-28 17:07:39 -07001059}
1060
Lei Zhang839692f2017-08-25 23:23:57 -07001061TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1062 InsertTextInPopulatedEditableComboBoxMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001063 TypeTextIntoTextField(6, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001064
1065 // Click on the middle of the user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001066 ClickOnFormFieldAtPoint(EditableFormAtX(126.0));
Diana Gageab390972017-07-28 17:07:39 -07001067
1068 // Test inserting text in the middle of existing text in user-editable
1069 // combobox.
1070 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1071 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001072 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001073
1074 // Select entire contents of user-editable combobox text field to check that
1075 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001076 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001077 CheckSelection(L"ABCHelloDEF");
Diana Gageab390972017-07-28 17:07:39 -07001078}
1079
Lei Zhang839692f2017-08-25 23:23:57 -07001080TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
1081 InsertTextInPopulatedEditableComboBoxRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001082 TypeTextIntoTextField(6, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001083
1084 // Click on the rightmost part of the user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001085 ClickOnFormFieldAtPoint(EditableFormEnd());
Diana Gageab390972017-07-28 17:07:39 -07001086
1087 // Test inserting text behind existing text in user-editable combobox.
1088 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1089 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001090 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001091
1092 // Select entire contents of user-editable combobox text field to check that
1093 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001094 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001095 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -07001096}
1097
Lei Zhang839692f2017-08-25 23:23:57 -07001098TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001099 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001100 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001101
1102 // Select entire string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001103 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001104 CheckSelection(L"ABCDEFGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001105
1106 // Test replacing text selection with text to be inserted.
1107 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1108 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001109 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001110
1111 // Select entire contents of user-editable combobox text field to check that
1112 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001113 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001114 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -07001115}
1116
Lei Zhang839692f2017-08-25 23:23:57 -07001117TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001118 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001119 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001120
1121 // Select left portion of string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001122 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(142.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001123 CheckSelection(L"ABCDE");
Diana Gageab390972017-07-28 17:07:39 -07001124
1125 // Test replacing text selection with text to be inserted.
1126 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1127 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001128 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001129
1130 // Select entire contents of user-editable combobox text field to check that
1131 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001132 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001133 CheckSelection(L"HelloFGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001134}
1135
Lei Zhang839692f2017-08-25 23:23:57 -07001136TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001137 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001138 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001139
1140 // Select middle portion of string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001141 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(167.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001142 CheckSelection(L"DEFGH");
Diana Gageab390972017-07-28 17:07:39 -07001143
1144 // Test replacing text selection with text to be inserted.
1145 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1146 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001147 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001148
1149 // Select entire contents of user-editable combobox text field to check that
1150 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001151 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001152 CheckSelection(L"ABCHelloIJ");
Diana Gageab390972017-07-28 17:07:39 -07001153}
1154
Lei Zhang839692f2017-08-25 23:23:57 -07001155TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001156 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001157 TypeTextIntoTextField(10, EditableFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001158
1159 // Select right portion of string in user-editable combobox.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001160 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001161 CheckSelection(L"FGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001162
1163 // Test replacing text selection with text to be inserted.
1164 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1165 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001166 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001167
1168 // Select entire contents of user-editable combobox text field to check that
1169 // insertion worked as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001170 SelectAllEditableFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001171 CheckSelection(L"ABCDEHello");
Diana Gageab390972017-07-28 17:07:39 -07001172}
1173
Lei Zhang839692f2017-08-25 23:23:57 -07001174TEST_F(FPDFFormFillTextFormEmbeddertest,
1175 InsertTextInEmptyCharLimitTextFieldOverflow) {
Diana Gageab390972017-07-28 17:07:39 -07001176 // Click on the textfield.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001177 ClickOnFormFieldAtPoint(CharLimitFormEnd());
Diana Gageab390972017-07-28 17:07:39 -07001178
1179 // Delete pre-filled contents of text field with char limit.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001180 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001181 CheckSelection(L"Elephant");
1182 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001183
1184 // Test inserting text into now empty text field so text to be inserted
1185 // exceeds the char limit and is cut off.
1186 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1187 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001188 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001189
1190 // Select entire contents of text field to check that insertion worked
1191 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001192 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001193 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001194}
1195
Lei Zhang839692f2017-08-25 23:23:57 -07001196TEST_F(FPDFFormFillTextFormEmbeddertest,
1197 InsertTextInEmptyCharLimitTextFieldFit) {
Diana Gageab390972017-07-28 17:07:39 -07001198 // Click on the textfield.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001199 ClickOnFormFieldAtPoint(CharLimitFormEnd());
Diana Gageab390972017-07-28 17:07:39 -07001200
1201 // Delete pre-filled contents of text field with char limit.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001202 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001203 CheckSelection(L"Elephant");
1204 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001205
1206 // Test inserting text into now empty text field so text to be inserted
1207 // exceeds the char limit and is cut off.
1208 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1209 GetFPDFWideString(L"Zebra");
Lei Zhang839692f2017-08-25 23:23:57 -07001210 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001211
1212 // Select entire contents of text field to check that insertion worked
1213 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001214 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001215 CheckSelection(L"Zebra");
Diana Gageab390972017-07-28 17:07:39 -07001216}
1217
Lei Zhang839692f2017-08-25 23:23:57 -07001218TEST_F(FPDFFormFillTextFormEmbeddertest,
1219 InsertTextInPopulatedCharLimitTextFieldLeft) {
Diana Gageab390972017-07-28 17:07:39 -07001220 // Click on the leftmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001221 ClickOnFormFieldAtPoint(CharLimitFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001222
1223 // Test inserting text in front of existing text in text field.
1224 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1225 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001226 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001227
1228 // Select entire contents of text field to check that insertion worked
1229 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001230 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001231 CheckSelection(L"HiElephant");
Diana Gageab390972017-07-28 17:07:39 -07001232}
1233
Lei Zhang839692f2017-08-25 23:23:57 -07001234TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001235 InsertTextInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001236 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001237
1238 // Click on the middle of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001239 ClickOnFormFieldAtPoint(CharLimitFormAtX(134.0));
Diana Gageab390972017-07-28 17:07:39 -07001240
1241 // Test inserting text in the middle of existing text in text field.
1242 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1243 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001244 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001245
1246 // Select entire contents of text field to check that insertion worked
1247 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001248 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001249 CheckSelection(L"ElephHiant");
Diana Gageab390972017-07-28 17:07:39 -07001250}
1251
Lei Zhang839692f2017-08-25 23:23:57 -07001252TEST_F(FPDFFormFillTextFormEmbeddertest,
1253 InsertTextInPopulatedCharLimitTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001254 TypeTextIntoTextField(8, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001255
1256 // Click on the rightmost part of the text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001257 ClickOnFormFieldAtPoint(CharLimitFormAtX(166.0));
Diana Gageab390972017-07-28 17:07:39 -07001258
1259 // Test inserting text behind existing text in text field.
1260 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1261 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001262 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001263
1264 // Select entire contents of text field to check that insertion worked
1265 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001266 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001267 CheckSelection(L"ElephantHi");
Diana Gageab390972017-07-28 17:07:39 -07001268}
1269
Lei Zhang839692f2017-08-25 23:23:57 -07001270TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001271 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001272 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001273
1274 // Select entire string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001275 SelectTextWithKeyboard(12, FWL_VKEY_Left, CharLimitFormEnd());
Lei Zhang839692f2017-08-25 23:23:57 -07001276 CheckSelection(L"Elephant");
Diana Gageab390972017-07-28 17:07:39 -07001277
1278 // Test replacing text selection with text to be inserted.
1279 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1280 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001281 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001282
1283 // Select entire contents of text field to check that insertion worked
1284 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001285 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001286 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001287}
1288
Lei Zhang839692f2017-08-25 23:23:57 -07001289TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001290 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001291 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001292
1293 // Select left portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001294 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(122.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001295 CheckSelection(L"Elep");
Diana Gageab390972017-07-28 17:07:39 -07001296
1297 // Test replacing text selection with text to be inserted.
1298 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1299 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001300 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001301
1302 // Select entire contents of text field to check that insertion worked
1303 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001304 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001305 CheckSelection(L"Hippophant");
Diana Gageab390972017-07-28 17:07:39 -07001306}
1307
Lei Zhang839692f2017-08-25 23:23:57 -07001308TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001309 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001310 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001311
1312 // Select middle portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001313 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(136.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001314 CheckSelection(L"epha");
Diana Gageab390972017-07-28 17:07:39 -07001315
1316 // Test replacing text selection with text to be inserted.
1317 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1318 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001319 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001320
1321 // Select entire contents of text field to check that insertion worked
1322 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001323 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001324 CheckSelection(L"ElHippopnt");
Diana Gageab390972017-07-28 17:07:39 -07001325}
1326
Lei Zhang839692f2017-08-25 23:23:57 -07001327TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001328 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) {
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001329 TypeTextIntoTextField(12, RegularFormBegin());
Diana Gageab390972017-07-28 17:07:39 -07001330
1331 // Select right portion of string in text field.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001332 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(152.0));
Lei Zhang839692f2017-08-25 23:23:57 -07001333 CheckSelection(L"hant");
Diana Gageab390972017-07-28 17:07:39 -07001334
1335 // Test replacing text selection with text to be inserted.
1336 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1337 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001338 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001339
1340 // Select entire contents of text field to check that insertion worked
1341 // as expected.
Lei Zhang31f7e4b2017-08-26 01:34:42 -07001342 SelectAllCharLimitFormTextWithMouse();
Lei Zhang839692f2017-08-25 23:23:57 -07001343 CheckSelection(L"ElepHippop");
Diana Gageab390972017-07-28 17:07:39 -07001344}