blob: e5f517f6735bfd25d6eac5b09576576d08de0ccd [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
Diana Gagedce2d722017-06-20 11:17:11 -07009#include "core/fxcrt/fx_string.h"
Nicolas Pena742977f2017-04-13 15:28:20 -040010#include "core/fxcrt/fx_system.h"
11#include "public/cpp/fpdf_deleters.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080012#include "public/fpdf_formfill.h"
Diana Gagedce2d722017-06-20 11:17:11 -070013#include "public/fpdf_fwlevent.h"
Wei Li091f7a02015-11-09 12:09:55 -080014#include "testing/embedder_test.h"
15#include "testing/embedder_test_mock_delegate.h"
16#include "testing/embedder_test_timer_handling_delegate.h"
Tom Sepeza310e002015-02-27 13:03:07 -080017#include "testing/gmock/include/gmock/gmock.h"
18#include "testing/gtest/include/gtest/gtest.h"
19
20using testing::_;
Tom Sepeza310e002015-02-27 13:03:07 -080021
Lei Zhang839692f2017-08-25 23:23:57 -070022using FPDFFormFillEmbeddertest = EmbedderTest;
23
24// A base class for many related tests that involve clicking and typing into
25// form fields.
26class FPDFFormFillInteractiveEmbeddertest : public FPDFFormFillEmbeddertest {
Diana Gagedce2d722017-06-20 11:17:11 -070027 protected:
Lei Zhang839692f2017-08-25 23:23:57 -070028 FPDFFormFillInteractiveEmbeddertest() = default;
29 ~FPDFFormFillInteractiveEmbeddertest() override = default;
30
31 void SetUp() override {
32 FPDFFormFillEmbeddertest::SetUp();
33 ASSERT_TRUE(OpenDocument(GetDocumentName()));
34 page_ = LoadPage(0);
35 ASSERT_TRUE(page_);
36 FormSanityChecks();
Diana Gagef8c02762017-07-26 14:20:12 -070037 }
38
Lei Zhang839692f2017-08-25 23:23:57 -070039 void TearDown() override {
40 UnloadPage(page_);
41 FPDFFormFillEmbeddertest::TearDown();
42 }
43
44 // Returns the name of the PDF to use.
45 virtual const char* GetDocumentName() const = 0;
46
Lei Zhang7bec2ff2017-08-25 23:28:23 -070047 // Returns the type of field(s) in the PDF.
48 virtual int GetFormType() const = 0;
49
Lei Zhang839692f2017-08-25 23:23:57 -070050 // Optionally do some sanity check on the document after loading.
51 virtual void FormSanityChecks() {}
52
53 FPDF_PAGE page() { return page_; }
54
55 void ClickOnFormFieldAtPoint(double x, double y) {
56 // Click on the text field or combobox as specified by coordinates.
57 FORM_OnMouseMove(form_handle(), page_, 0, x, y);
58 FORM_OnLButtonDown(form_handle(), page_, 0, x, y);
59 FORM_OnLButtonUp(form_handle(), page_, 0, x, y);
60 }
61
Lei Zhang7bec2ff2017-08-25 23:28:23 -070062 void TypeTextIntoTextField(int num_chars, double x, double y) {
63 EXPECT_EQ(GetFormType(),
Lei Zhang839692f2017-08-25 23:23:57 -070064 FPDFPage_HasFormFieldAtPoint(form_handle(), page_, x, y));
65 ClickOnFormFieldAtPoint(x, y);
Diana Gagedce2d722017-06-20 11:17:11 -070066
67 // Type text starting with 'A' to as many chars as specified by |num_chars|.
68 for (int i = 0; i < num_chars; ++i) {
Lei Zhang839692f2017-08-25 23:23:57 -070069 FORM_OnChar(form_handle(), page_, 'A' + i, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070070 }
71 }
72
Diana Gagecb50b5f2017-06-29 09:54:19 -070073 // Navigates to text field using the mouse and then selects text via the
Diana Gagedce2d722017-06-20 11:17:11 -070074 // shift and specfied left or right arrow key.
Lei Zhang839692f2017-08-25 23:23:57 -070075 void SelectTextWithKeyboard(int num_chars,
Diana Gagedce2d722017-06-20 11:17:11 -070076 int arrow_key,
77 double x,
78 double y) {
79 // Navigate to starting position for selection.
Lei Zhang839692f2017-08-25 23:23:57 -070080 ClickOnFormFieldAtPoint(x, y);
Diana Gagedce2d722017-06-20 11:17:11 -070081
82 // Hold down shift (and don't release until entire text is selected).
Lei Zhang839692f2017-08-25 23:23:57 -070083 FORM_OnKeyDown(form_handle(), page_, FWL_VKEY_Shift, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070084
85 // Select text char by char via left or right arrow key.
86 for (int i = 0; i < num_chars; ++i) {
Lei Zhang839692f2017-08-25 23:23:57 -070087 FORM_OnKeyDown(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
88 FORM_OnKeyUp(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
Diana Gagedce2d722017-06-20 11:17:11 -070089 }
Lei Zhang839692f2017-08-25 23:23:57 -070090 FORM_OnKeyUp(form_handle(), page_, FWL_VKEY_Shift, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070091 }
92
Diana Gagecb50b5f2017-06-29 09:54:19 -070093 // Uses the mouse to navigate to text field and select text.
Lei Zhang839692f2017-08-25 23:23:57 -070094 void SelectTextWithMouse(double start_x, double end_x, double y) {
Diana Gagedce2d722017-06-20 11:17:11 -070095 // Navigate to starting position and click mouse.
Lei Zhang839692f2017-08-25 23:23:57 -070096 FORM_OnMouseMove(form_handle(), page_, 0, start_x, y);
97 FORM_OnLButtonDown(form_handle(), page_, 0, start_x, y);
Diana Gagedce2d722017-06-20 11:17:11 -070098
99 // Hold down mouse until reach end of desired selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700100 FORM_OnMouseMove(form_handle(), page_, 0, end_x, y);
101 FORM_OnLButtonUp(form_handle(), page_, 0, end_x, y);
Diana Gagedce2d722017-06-20 11:17:11 -0700102 }
103
Lei Zhang839692f2017-08-25 23:23:57 -0700104 void CheckSelection(const CFX_WideStringC& expected_string) {
Diana Gagedce2d722017-06-20 11:17:11 -0700105 // Calculate expected length for selected text.
106 int num_chars = expected_string.GetLength();
107
108 // Check actual selection against expected selection.
109 const unsigned long expected_length =
110 sizeof(unsigned short) * (num_chars + 1);
111 unsigned long sel_text_len =
Lei Zhang839692f2017-08-25 23:23:57 -0700112 FORM_GetSelectedText(form_handle(), page_, nullptr, 0);
Diana Gagedce2d722017-06-20 11:17:11 -0700113 ASSERT_EQ(expected_length, sel_text_len);
114
115 std::vector<unsigned short> buf(sel_text_len);
Lei Zhang839692f2017-08-25 23:23:57 -0700116 EXPECT_EQ(expected_length, FORM_GetSelectedText(form_handle(), page_,
Diana Gagedce2d722017-06-20 11:17:11 -0700117 buf.data(), sel_text_len));
118
119 EXPECT_EQ(expected_string,
120 CFX_WideString::FromUTF16LE(buf.data(), num_chars));
121 }
Diana Gagecb50b5f2017-06-29 09:54:19 -0700122
Lei Zhang839692f2017-08-25 23:23:57 -0700123 private:
124 FPDF_PAGE page_ = nullptr;
125};
126
127class FPDFFormFillTextFormEmbeddertest
128 : public FPDFFormFillInteractiveEmbeddertest {
129 protected:
130 FPDFFormFillTextFormEmbeddertest() = default;
131 ~FPDFFormFillTextFormEmbeddertest() override = default;
132
133 const char* GetDocumentName() const override {
134 // PDF with several form text fields:
135 // - "Text Box" - No special attributes.
136 // - "ReadOnly" - Ff: 1.
137 // - "CharLimit" - MaxLen: 10, V: Elephant.
138 return "text_form_multiple.pdf";
139 }
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700140
141 int GetFormType() const override { return FPDF_FORMFIELD_TEXTFIELD; }
Lei Zhang839692f2017-08-25 23:23:57 -0700142};
143
144class FPDFFormFillComboBoxFormEmbeddertest
145 : public FPDFFormFillInteractiveEmbeddertest {
146 protected:
147 FPDFFormFillComboBoxFormEmbeddertest() = default;
148 ~FPDFFormFillComboBoxFormEmbeddertest() override = default;
149
150 const char* GetDocumentName() const override {
151 // PDF with form comboboxes.
152 return "combobox_form.pdf";
153 }
154
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700155 int GetFormType() const override { return FPDF_FORMFIELD_COMBOBOX; }
156
Lei Zhang839692f2017-08-25 23:23:57 -0700157 void FormSanityChecks() override {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700158 EXPECT_EQ(GetFormType(), FPDFPage_HasFormFieldAtPoint(form_handle(), page(),
159 102.0, 113.0));
Lei Zhang839692f2017-08-25 23:23:57 -0700160 }
161
Diana Gagecb50b5f2017-06-29 09:54:19 -0700162 // Selects one of the pre-selected values from a combobox with three options.
163 // Options are specified by |item_index|, which is 0-based.
Lei Zhang839692f2017-08-25 23:23:57 -0700164 void SelectOption(int32_t item_index, double x, double y) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700165 // Only relevant for comboboxes with three choices and the same dimensions
166 // as those in combobox_form.pdf.
167 ASSERT(item_index >= 0);
168 ASSERT(item_index < 3);
169
170 // Navigate to button for drop down and click mouse to reveal options.
Lei Zhang839692f2017-08-25 23:23:57 -0700171 ClickOnFormFieldAtPoint(x, y);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700172
173 // Y coordinate of dropdown option to be selected.
174 constexpr double kChoiceHeight = 15;
175 double option_y = y - kChoiceHeight * (item_index + 1);
176
177 // Navigate to option and click mouse to select it.
Lei Zhang839692f2017-08-25 23:23:57 -0700178 ClickOnFormFieldAtPoint(x, option_y);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700179 }
Diana Gagedce2d722017-06-20 11:17:11 -0700180};
Tom Sepeza310e002015-02-27 13:03:07 -0800181
182TEST_F(FPDFFormFillEmbeddertest, FirstTest) {
183 EmbedderTestMockDelegate mock;
184 EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0);
185 EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700186 EXPECT_CALL(mock, SetTimer(_, _)).Times(0);
187 EXPECT_CALL(mock, KillTimer(_)).Times(0);
Tom Sepeza310e002015-02-27 13:03:07 -0800188 SetDelegate(&mock);
189
Wei Li091f7a02015-11-09 12:09:55 -0800190 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepeza310e002015-02-27 13:03:07 -0800191 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700192 EXPECT_TRUE(page);
Lei Zhangd27acae2015-05-15 15:36:02 -0700193 UnloadPage(page);
Tom Sepeza310e002015-02-27 13:03:07 -0800194}
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700195
196TEST_F(FPDFFormFillEmbeddertest, BUG_487928) {
197 EmbedderTestTimerHandlingDelegate delegate;
198 SetDelegate(&delegate);
199
Wei Li091f7a02015-11-09 12:09:55 -0800200 EXPECT_TRUE(OpenDocument("bug_487928.pdf"));
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700201 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700202 EXPECT_TRUE(page);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700203 DoOpenActions();
204 delegate.AdvanceTime(5000);
205 UnloadPage(page);
206}
Tom Sepez0b133982015-07-28 11:23:22 -0700207
Tom Sepez396e8722015-09-09 10:16:08 -0700208TEST_F(FPDFFormFillEmbeddertest, BUG_507316) {
209 EmbedderTestTimerHandlingDelegate delegate;
210 SetDelegate(&delegate);
211
Wei Li091f7a02015-11-09 12:09:55 -0800212 EXPECT_TRUE(OpenDocument("bug_507316.pdf"));
weili0dadcc62016-08-23 21:10:57 -0700213 FPDF_PAGE page = LoadPage(2);
tsepez8e120292016-08-03 14:03:35 -0700214 EXPECT_TRUE(page);
Tom Sepez396e8722015-09-09 10:16:08 -0700215 DoOpenActions();
216 delegate.AdvanceTime(4000);
217 UnloadPage(page);
218}
219
Tom Sepez0b133982015-07-28 11:23:22 -0700220TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
Wei Li091f7a02015-11-09 12:09:55 -0800221 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0b133982015-07-28 11:23:22 -0700222 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700223 EXPECT_TRUE(page);
Tom Sepez0b133982015-07-28 11:23:22 -0700224
225 // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES.
226 FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0);
227 FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0);
228
229 UnloadPage(page);
230}
Lei Zhang79e893a2015-11-04 16:02:47 -0800231
Tom Sepez4d071792016-02-04 16:53:26 -0800232#ifdef PDF_ENABLE_V8
Lei Zhang79e893a2015-11-04 16:02:47 -0800233TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
tsepez8e120292016-08-03 14:03:35 -0700234 // Test that timers fire once and intervals fire repeatedly.
Lei Zhang79e893a2015-11-04 16:02:47 -0800235 EmbedderTestTimerHandlingDelegate delegate;
236 SetDelegate(&delegate);
237
Wei Li091f7a02015-11-09 12:09:55 -0800238 EXPECT_TRUE(OpenDocument("bug_551248.pdf"));
Lei Zhang79e893a2015-11-04 16:02:47 -0800239 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700240 EXPECT_TRUE(page);
241 DoOpenActions();
242
243 const auto& alerts = delegate.GetAlerts();
244 EXPECT_EQ(0U, alerts.size());
245
246 delegate.AdvanceTime(1000);
247 EXPECT_EQ(0U, alerts.size()); // nothing fired.
248 delegate.AdvanceTime(1000);
249 EXPECT_EQ(1U, alerts.size()); // interval fired.
250 delegate.AdvanceTime(1000);
251 EXPECT_EQ(2U, alerts.size()); // timer fired.
252 delegate.AdvanceTime(1000);
253 EXPECT_EQ(3U, alerts.size()); // interval fired again.
254 delegate.AdvanceTime(1000);
255 EXPECT_EQ(3U, alerts.size()); // nothing fired.
256 delegate.AdvanceTime(1000);
257 EXPECT_EQ(4U, alerts.size()); // interval fired again.
258 delegate.AdvanceTime(1000);
259 EXPECT_EQ(4U, alerts.size()); // nothing fired.
260 UnloadPage(page);
261
262 ASSERT_EQ(4U, alerts.size()); // nothing else fired.
263
264 EXPECT_STREQ(L"interval fired", alerts[0].message.c_str());
265 EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
266 EXPECT_EQ(0, alerts[0].type);
267 EXPECT_EQ(0, alerts[0].icon);
268
269 EXPECT_STREQ(L"timer fired", alerts[1].message.c_str());
270 EXPECT_STREQ(L"Alert", alerts[1].title.c_str());
271 EXPECT_EQ(0, alerts[1].type);
272 EXPECT_EQ(0, alerts[1].icon);
273
274 EXPECT_STREQ(L"interval fired", alerts[2].message.c_str());
275 EXPECT_STREQ(L"Alert", alerts[2].title.c_str());
276 EXPECT_EQ(0, alerts[2].type);
277 EXPECT_EQ(0, alerts[2].icon);
278
279 EXPECT_STREQ(L"interval fired", alerts[3].message.c_str());
280 EXPECT_STREQ(L"Alert", alerts[3].title.c_str());
281 EXPECT_EQ(0, alerts[3].type);
282 EXPECT_EQ(0, alerts[3].icon);
283}
284
285TEST_F(FPDFFormFillEmbeddertest, BUG_620428) {
286 // Test that timers and intervals are cancelable.
287 EmbedderTestTimerHandlingDelegate delegate;
288 SetDelegate(&delegate);
289
290 EXPECT_TRUE(OpenDocument("bug_620428.pdf"));
291 FPDF_PAGE page = LoadPage(0);
292 EXPECT_TRUE(page);
Lei Zhang79e893a2015-11-04 16:02:47 -0800293 DoOpenActions();
294 delegate.AdvanceTime(5000);
295 UnloadPage(page);
296
297 const auto& alerts = delegate.GetAlerts();
tsepez0fa54b82016-08-04 12:07:28 -0700298 ASSERT_EQ(1U, alerts.size());
299 EXPECT_STREQ(L"done", alerts[0].message.c_str());
Lei Zhang79e893a2015-11-04 16:02:47 -0800300}
tsepez8e120292016-08-03 14:03:35 -0700301
tsepez32e693f2016-08-04 12:47:42 -0700302TEST_F(FPDFFormFillEmbeddertest, BUG_634394) {
303 // Cancel timer inside timer callback.
304 EmbedderTestTimerHandlingDelegate delegate;
305 SetDelegate(&delegate);
306
307 EXPECT_TRUE(OpenDocument("bug_634394.pdf"));
308 FPDF_PAGE page = LoadPage(0);
309 EXPECT_TRUE(page);
310 DoOpenActions();
311
312 // Timers fire at most once per AdvanceTime(), allow intervals
313 // to fire several times if possible.
314 delegate.AdvanceTime(1000);
315 delegate.AdvanceTime(1000);
316 delegate.AdvanceTime(1000);
317 delegate.AdvanceTime(1000);
318 delegate.AdvanceTime(1000);
319 UnloadPage(page);
320
321 const auto& alerts = delegate.GetAlerts();
322 EXPECT_EQ(2U, alerts.size());
323}
324
tsepez8ca63de2016-08-05 17:12:27 -0700325TEST_F(FPDFFormFillEmbeddertest, BUG_634716) {
326 EmbedderTestTimerHandlingDelegate delegate;
327 SetDelegate(&delegate);
328
329 EXPECT_TRUE(OpenDocument("bug_634716.pdf"));
330 FPDF_PAGE page = LoadPage(0);
331 EXPECT_TRUE(page);
332 DoOpenActions();
333
334 // Timers fire at most once per AdvanceTime(), allow intervals
335 // to fire several times if possible.
336 delegate.AdvanceTime(1000);
337 delegate.AdvanceTime(1000);
338 delegate.AdvanceTime(1000);
339 delegate.AdvanceTime(1000);
340 delegate.AdvanceTime(1000);
341 UnloadPage(page);
342
343 const auto& alerts = delegate.GetAlerts();
344 EXPECT_EQ(2U, alerts.size());
345}
346
tsepez6cf5eca2017-01-12 11:21:12 -0800347TEST_F(FPDFFormFillEmbeddertest, BUG_679649) {
348 EmbedderTestTimerHandlingDelegate delegate;
349 SetDelegate(&delegate);
350
351 EXPECT_TRUE(OpenDocument("bug_679649.pdf"));
352 FPDF_PAGE page = LoadPage(0);
353 EXPECT_TRUE(page);
354
355 delegate.SetFailNextTimer();
356 DoOpenActions();
357 delegate.AdvanceTime(2000);
358 UnloadPage(page);
359
360 const auto& alerts = delegate.GetAlerts();
361 EXPECT_EQ(0u, alerts.size());
362}
363
Tom Sepezfb7021c2017-05-31 10:29:25 -0700364TEST_F(FPDFFormFillEmbeddertest, BUG_707673) {
365 EmbedderTestTimerHandlingDelegate delegate;
366 SetDelegate(&delegate);
367
368 EXPECT_TRUE(OpenDocument("bug_707673.pdf"));
369 FPDF_PAGE page = LoadPage(0);
370 EXPECT_TRUE(page);
371
372 DoOpenActions();
373 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
374 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
375 delegate.AdvanceTime(1000);
376 UnloadPage(page);
377
378 const auto& alerts = delegate.GetAlerts();
379 EXPECT_EQ(0u, alerts.size());
380}
381
Tom Sepez4d071792016-02-04 16:53:26 -0800382#endif // PDF_ENABLE_V8
Nicolas Pena742977f2017-04-13 15:28:20 -0400383
384TEST_F(FPDFFormFillEmbeddertest, FormText) {
385#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
386 const char md5_1[] = "5f11dbe575fe197a37c3fb422559f8ff";
387 const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d";
388 const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe";
389#else
Nicolas Pena00c3cfd2017-07-10 17:29:54 -0400390 const char md5_1[] = "a5e3ac74c2ee123ec6710e2f0ef8424a";
391 const char md5_2[] = "4526b09382e144d5506ad92149399de6";
392 const char md5_3[] = "80356067d860088864cf50ff85d8459e";
Nicolas Pena742977f2017-04-13 15:28:20 -0400393#endif
394 {
395 EXPECT_TRUE(OpenDocument("text_form.pdf"));
396 FPDF_PAGE page = LoadPage(0);
397 ASSERT_TRUE(page);
398 std::unique_ptr<void, FPDFBitmapDeleter> bitmap1(RenderPage(page));
399 CompareBitmap(bitmap1.get(), 300, 300, md5_1);
400
401 // Click on the textfield
402 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
403 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
404 FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
405 FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
406 FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
407
408 // Write "ABC"
409 FORM_OnChar(form_handle(), page, 65, 0);
410 FORM_OnChar(form_handle(), page, 66, 0);
411 FORM_OnChar(form_handle(), page, 67, 0);
412 std::unique_ptr<void, FPDFBitmapDeleter> bitmap2(RenderPage(page));
413 CompareBitmap(bitmap2.get(), 300, 300, md5_2);
414
415 // Take out focus by clicking out of the textfield
416 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
417 FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
418 FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
419 std::unique_ptr<void, FPDFBitmapDeleter> bitmap3(RenderPage(page));
420 CompareBitmap(bitmap3.get(), 300, 300, md5_3);
421
422 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
423
Nicolas Pena3ff54002017-07-05 11:55:35 -0400424 // Close page
Nicolas Pena742977f2017-04-13 15:28:20 -0400425 UnloadPage(page);
Nicolas Pena742977f2017-04-13 15:28:20 -0400426 }
427 // Check saved document
Nicolas Pena3ff54002017-07-05 11:55:35 -0400428 TestAndCloseSaved(300, 300, md5_3);
Nicolas Pena742977f2017-04-13 15:28:20 -0400429}
Diana Gagedce2d722017-06-20 11:17:11 -0700430
Lei Zhang839692f2017-08-25 23:23:57 -0700431TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) {
Diana Gagedce2d722017-06-20 11:17:11 -0700432 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700433 CheckSelection(L"");
Diana Gagedce2d722017-06-20 11:17:11 -0700434
435 // Test basic selection.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700436 TypeTextIntoTextField(3, 120.0, 120.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700437 SelectTextWithKeyboard(3, FWL_VKEY_Left, 123.0, 115.5);
438 CheckSelection(L"ABC");
Diana Gagedce2d722017-06-20 11:17:11 -0700439}
440
Lei Zhang839692f2017-08-25 23:23:57 -0700441TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicMouse) {
Diana Gagedce2d722017-06-20 11:17:11 -0700442 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700443 CheckSelection(L"");
Diana Gagedce2d722017-06-20 11:17:11 -0700444
445 // Test basic selection.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700446 TypeTextIntoTextField(3, 120.0, 120.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700447 SelectTextWithMouse(125.0, 102.0, 115.5);
448 CheckSelection(L"ABC");
Diana Gagedce2d722017-06-20 11:17:11 -0700449}
450
Lei Zhang839692f2017-08-25 23:23:57 -0700451TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsKeyBoard) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700452 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gagedce2d722017-06-20 11:17:11 -0700453
454 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700455 SelectTextWithKeyboard(1, FWL_VKEY_Right, 102.0, 115.5);
456 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700457
458 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700459 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
460 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700461
462 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700463 SelectTextWithKeyboard(6, FWL_VKEY_Left, 170.0, 115.5);
464 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700465
466 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700467 SelectTextWithKeyboard(6, FWL_VKEY_Right, 125.0, 115.5);
468 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700469
470 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700471 SelectTextWithKeyboard(1, FWL_VKEY_Left, 191.0, 115.5);
472 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700473}
474
Lei Zhang839692f2017-08-25 23:23:57 -0700475TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsMouse) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700476 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gagedce2d722017-06-20 11:17:11 -0700477
478 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700479 SelectTextWithMouse(102.0, 106.0, 115.5);
480 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700481
482 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700483 SelectTextWithMouse(191.0, 102.0, 115.5);
484 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700485
486 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700487 SelectTextWithMouse(170.0, 125.0, 115.5);
488 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700489
490 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700491 SelectTextWithMouse(125.0, 170.0, 115.5);
492 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700493
494 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700495 SelectTextWithMouse(191.0, 186.0, 115.5);
496 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700497}
Diana Gagecb50b5f2017-06-29 09:54:19 -0700498
Lei Zhang839692f2017-08-25 23:23:57 -0700499TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
500 GetSelectedTextEmptyAndBasicNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700501 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700502 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700503
504 // Non-editable comboboxes don't allow selection with keyboard.
Lei Zhang839692f2017-08-25 23:23:57 -0700505 SelectTextWithMouse(102.0, 142.0, 113.0);
506 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700507
508 // Select other another provided option.
Lei Zhang839692f2017-08-25 23:23:57 -0700509 SelectOption(0, 192.0, 110.0);
510 CheckSelection(L"Apple");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700511}
512
Lei Zhang839692f2017-08-25 23:23:57 -0700513TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700514 GetSelectedTextEmptyAndBasicEditableComboBoxKeyboard) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700515 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700516 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700517
518 // Test basic selection of text within user editable combobox using keyboard.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700519 TypeTextIntoTextField(3, 102.0, 62.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700520 SelectTextWithKeyboard(3, FWL_VKEY_Left, 128.0, 62.0);
521 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700522
523 // Select a provided option.
Lei Zhang839692f2017-08-25 23:23:57 -0700524 SelectOption(1, 192.0, 60.0);
525 CheckSelection(L"Bar");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700526}
527
Lei Zhang839692f2017-08-25 23:23:57 -0700528TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700529 GetSelectedTextEmptyAndBasicEditableComboBoxMouse) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700530 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700531 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700532
533 // Test basic selection of text within user editable combobox using mouse.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700534 TypeTextIntoTextField(3, 102.0, 62.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700535 SelectTextWithMouse(128.0, 103.0, 62.0);
536 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700537
538 // Select a provided option.
Lei Zhang839692f2017-08-25 23:23:57 -0700539 SelectOption(2, 192.0, 60.0);
540 CheckSelection(L"Qux");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700541}
542
Lei Zhang839692f2017-08-25 23:23:57 -0700543TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
544 GetSelectedTextFragmentsNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700545 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700546 SelectTextWithMouse(102.0, 107.0, 113.0);
547 CheckSelection(L"B");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700548
549 // Test selecting entire string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700550 SelectTextWithMouse(142.0, 102.0, 113.0);
551 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700552
553 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700554 SelectTextWithMouse(135.0, 117.0, 113.0);
555 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700556
557 // Test selecting middle section in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700558 SelectTextWithMouse(117.0, 135.0, 113.0);
559 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700560
561 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700562 SelectTextWithMouse(142.0, 138.0, 113.0);
563 CheckSelection(L"a");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700564
565 // Select another option and then reset selection as first three chars.
Lei Zhang839692f2017-08-25 23:23:57 -0700566 SelectOption(2, 192.0, 110.0);
567 CheckSelection(L"Cherry");
568 SelectTextWithMouse(102.0, 122.0, 113.0);
569 CheckSelection(L"Che");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700570}
571
Lei Zhang839692f2017-08-25 23:23:57 -0700572TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700573 GetSelectedTextFragmentsEditableComboBoxKeyboard) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700574 TypeTextIntoTextField(10, 102.0, 62.0);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700575
576 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700577 SelectTextWithKeyboard(1, FWL_VKEY_Right, 102.0, 62.0);
578 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700579
580 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700581 SelectTextWithKeyboard(10, FWL_VKEY_Left, 178.0, 62.0);
582 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700583
584 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700585 SelectTextWithKeyboard(5, FWL_VKEY_Left, 168.0, 62.0);
586 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700587
588 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700589 SelectTextWithKeyboard(5, FWL_VKEY_Right, 127.0, 62.0);
590 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700591
592 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700593 SelectTextWithKeyboard(1, FWL_VKEY_Left, 178.0, 62.0);
594 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700595
596 // Select a provided option and then reset selection as first two chars.
Lei Zhang839692f2017-08-25 23:23:57 -0700597 SelectOption(0, 192.0, 60.0);
598 CheckSelection(L"Foo");
599 SelectTextWithKeyboard(2, FWL_VKEY_Right, 102.0, 62.0);
600 CheckSelection(L"Fo");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700601}
602
Lei Zhang839692f2017-08-25 23:23:57 -0700603TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700604 GetSelectedTextFragmentsEditableComboBoxMouse) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700605 TypeTextIntoTextField(10, 102.0, 62.0);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700606
607 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700608 SelectTextWithMouse(102.0, 107.0, 62.0);
609 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700610
611 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700612 SelectTextWithMouse(178.0, 102.0, 62.0);
613 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700614
615 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700616 SelectTextWithMouse(168.0, 127.0, 62.0);
617 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700618
619 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700620 SelectTextWithMouse(127.0, 168.0, 62.0);
621 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700622
623 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700624 SelectTextWithMouse(178.0, 174.0, 62.0);
625 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700626}
Diana Gage1c7f1422017-07-24 11:19:52 -0700627
Lei Zhang839692f2017-08-25 23:23:57 -0700628TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700629 // Select entire contents of text field.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700630 TypeTextIntoTextField(12, 120.0, 120.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700631 SelectTextWithMouse(191.0, 102.0, 115.5);
632 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700633
634 // Test deleting current text selection. Select what remains after deletion to
635 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700636 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -0700637
Lei Zhang839692f2017-08-25 23:23:57 -0700638 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
639 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700640}
641
Lei Zhang839692f2017-08-25 23:23:57 -0700642TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700643 // Select middle section of text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700644 TypeTextIntoTextField(12, 120.0, 120.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700645 SelectTextWithMouse(170.0, 125.0, 115.5);
646 CheckSelection(L"DEFGHI");
Diana Gage1c7f1422017-07-24 11:19:52 -0700647
648 // Test deleting current text selection. Select what remains after deletion to
649 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700650 FORM_ReplaceSelection(form_handle(), page(), nullptr);
651 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
652 CheckSelection(L"ABCJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700653}
654
Lei Zhang839692f2017-08-25 23:23:57 -0700655TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700656 // Select first few characters of text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700657 TypeTextIntoTextField(12, 120.0, 120.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700658 SelectTextWithMouse(102.0, 132.0, 115.5);
659 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700660
661 // Test deleting current text selection. Select what remains after deletion to
662 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700663 FORM_ReplaceSelection(form_handle(), page(), nullptr);
664 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
665 CheckSelection(L"EFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700666}
667
Lei Zhang839692f2017-08-25 23:23:57 -0700668TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700669 // Select last few characters of text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700670 TypeTextIntoTextField(12, 120.0, 120.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700671 SelectTextWithMouse(191.0, 165.0, 115.5);
672 CheckSelection(L"IJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700673
674 // Test deleting current text selection. Select what remains after deletion to
675 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700676 FORM_ReplaceSelection(form_handle(), page(), nullptr);
677 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
678 CheckSelection(L"ABCDEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700679}
680
Lei Zhang839692f2017-08-25 23:23:57 -0700681TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteEmptyTextFieldSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700682 // Do not select text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700683 TypeTextIntoTextField(12, 120.0, 120.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700684 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700685
686 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700687 FORM_ReplaceSelection(form_handle(), page(), nullptr);
688 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
689 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700690}
691
Lei Zhang839692f2017-08-25 23:23:57 -0700692TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
693 DeleteEditableComboBoxEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700694 // Select entire contents of user-editable combobox text field.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700695 TypeTextIntoTextField(10, 102.0, 62.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700696 SelectTextWithMouse(178.0, 102.0, 62.0);
697 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700698
699 // Test deleting current text selection. Select what remains after deletion to
700 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700701 FORM_ReplaceSelection(form_handle(), page(), nullptr);
702 SelectTextWithMouse(178.0, 102.0, 62.0);
703 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700704}
705
Lei Zhang839692f2017-08-25 23:23:57 -0700706TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
707 DeleteEditableComboBoxSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700708 // Select middle section of text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700709 TypeTextIntoTextField(10, 102.0, 62.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700710 SelectTextWithMouse(168.0, 127.0, 62.0);
711 CheckSelection(L"DEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700712
713 // Test deleting current text selection. Select what remains after deletion to
714 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700715 FORM_ReplaceSelection(form_handle(), page(), nullptr);
716 SelectTextWithMouse(178.0, 102.0, 62.0);
717 CheckSelection(L"ABCIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700718}
719
Lei Zhang839692f2017-08-25 23:23:57 -0700720TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
721 DeleteEditableComboBoxSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700722 // Select first few characters of text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700723 TypeTextIntoTextField(10, 102.0, 62.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700724 SelectTextWithMouse(102.0, 132.0, 62.0);
725 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700726
727 // Test deleting current text selection. Select what remains after deletion to
728 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700729 FORM_ReplaceSelection(form_handle(), page(), nullptr);
730 SelectTextWithMouse(178.0, 102.0, 62.0);
731 CheckSelection(L"EFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700732}
733
Lei Zhang839692f2017-08-25 23:23:57 -0700734TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
735 DeleteEditableComboBoxSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700736 // Select last few characters of text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700737 TypeTextIntoTextField(10, 102.0, 62.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700738 SelectTextWithMouse(178.0, 152.0, 62.0);
739 CheckSelection(L"GHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700740
741 // Test deleting current text selection. Select what remains after deletion to
742 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700743 FORM_ReplaceSelection(form_handle(), page(), nullptr);
744 SelectTextWithMouse(178.0, 102.0, 62.0);
745 CheckSelection(L"ABCDEF");
Diana Gage1c7f1422017-07-24 11:19:52 -0700746}
747
Lei Zhang839692f2017-08-25 23:23:57 -0700748TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
749 DeleteEmptyEditableComboBoxSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700750 // Do not select text.
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700751 TypeTextIntoTextField(10, 102.0, 62.0);
Lei Zhang839692f2017-08-25 23:23:57 -0700752 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700753
754 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700755 FORM_ReplaceSelection(form_handle(), page(), nullptr);
756 SelectTextWithMouse(178.0, 102.0, 62.0);
757 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700758}
Diana Gageab390972017-07-28 17:07:39 -0700759
Lei Zhang839692f2017-08-25 23:23:57 -0700760TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInEmptyTextField) {
761 ClickOnFormFieldAtPoint(120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700762
763 // Test inserting text into empty text field.
764 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
765 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700766 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700767
768 // Select entire contents of text field to check that insertion worked
769 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700770 SelectTextWithMouse(195.0, 102.0, 115.5);
771 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700772}
773
Lei Zhang839692f2017-08-25 23:23:57 -0700774TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldLeft) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700775 TypeTextIntoTextField(8, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700776
777 // Click on the leftmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700778 ClickOnFormFieldAtPoint(102.0, 115.5);
Diana Gageab390972017-07-28 17:07:39 -0700779
780 // Test inserting text in front of existing text in text field.
781 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
782 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700783 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700784
785 // Select entire contents of text field to check that insertion worked
786 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700787 SelectTextWithMouse(195.0, 102.0, 115.5);
788 CheckSelection(L"HelloABCDEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700789}
790
Lei Zhang839692f2017-08-25 23:23:57 -0700791TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldMiddle) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700792 TypeTextIntoTextField(8, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700793
794 // Click on the middle of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700795 ClickOnFormFieldAtPoint(134.0, 115.5);
Diana Gageab390972017-07-28 17:07:39 -0700796
797 // Test inserting text in the middle of existing text in text field.
798 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
799 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700800 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700801
802 // Select entire contents of text field to check that insertion worked
803 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700804 SelectTextWithMouse(195.0, 102.0, 115.5);
805 CheckSelection(L"ABCDHelloEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700806}
807
Lei Zhang839692f2017-08-25 23:23:57 -0700808TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldRight) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700809 TypeTextIntoTextField(8, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700810
811 // Click on the rightmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700812 ClickOnFormFieldAtPoint(166.0, 115.5);
Diana Gageab390972017-07-28 17:07:39 -0700813
814 // Test inserting text behind existing text in text field.
815 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
816 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700817 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700818
819 // Select entire contents of text field to check that insertion worked
820 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700821 SelectTextWithMouse(195.0, 102.0, 115.5);
822 CheckSelection(L"ABCDEFGHHello");
Diana Gageab390972017-07-28 17:07:39 -0700823}
824
Lei Zhang839692f2017-08-25 23:23:57 -0700825TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700826 InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700827 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700828
829 // Select entire string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700830 SelectTextWithKeyboard(12, FWL_VKEY_Left, 195.0, 115.0);
831 CheckSelection(L"ABCDEFGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700832
833 // Test replacing text selection with text to be inserted.
834 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
835 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700836 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700837
838 // Select entire contents of text field to check that insertion worked
839 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700840 SelectTextWithMouse(195.0, 102.0, 115.5);
841 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700842}
843
Lei Zhang839692f2017-08-25 23:23:57 -0700844TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700845 InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700846 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700847
848 // Select left portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700849 SelectTextWithKeyboard(6, FWL_VKEY_Left, 148.0, 115.0);
850 CheckSelection(L"ABCDEF");
Diana Gageab390972017-07-28 17:07:39 -0700851
852 // Test replacing text selection with text to be inserted.
853 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
854 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700855 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700856
857 // Select entire contents of text field to check that insertion worked
858 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700859 SelectTextWithMouse(195.0, 102.0, 115.5);
860 CheckSelection(L"HelloGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700861}
862
Lei Zhang839692f2017-08-25 23:23:57 -0700863TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700864 InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700865 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700866
867 // Select middle portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700868 SelectTextWithKeyboard(6, FWL_VKEY_Left, 171.0, 115.0);
869 CheckSelection(L"DEFGHI");
Diana Gageab390972017-07-28 17:07:39 -0700870
871 // Test replacing text selection with text to be inserted.
872 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
873 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700874 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700875
876 // Select entire contents of text field to check that insertion worked
877 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700878 SelectTextWithMouse(195.0, 102.0, 115.5);
879 CheckSelection(L"ABCHelloJKL");
Diana Gageab390972017-07-28 17:07:39 -0700880}
881
Lei Zhang839692f2017-08-25 23:23:57 -0700882TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700883 InsertTextAndReplaceSelectionInPopulatedTextFieldRight) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700884 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700885
886 // Select right portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700887 SelectTextWithKeyboard(6, FWL_VKEY_Left, 195.0, 115.0);
888 CheckSelection(L"GHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700889
890 // Test replacing text selection with text to be inserted.
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 Zhang839692f2017-08-25 23:23:57 -0700897 SelectTextWithMouse(195.0, 102.0, 115.5);
898 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -0700899}
900
Lei Zhang839692f2017-08-25 23:23:57 -0700901TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
902 InsertTextInEmptyEditableComboBox) {
903 ClickOnFormFieldAtPoint(102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700904
905 // Test inserting text into empty user-editable combobox.
906 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
907 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700908 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700909
910 // Select entire contents of user-editable combobox text field to check that
911 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700912 SelectTextWithMouse(183.0, 102.0, 62.0);
913 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700914}
915
Lei Zhang839692f2017-08-25 23:23:57 -0700916TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
917 InsertTextInPopulatedEditableComboBoxLeft) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700918 TypeTextIntoTextField(6, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700919
920 // Click on the leftmost part of the user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700921 ClickOnFormFieldAtPoint(102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700922
923 // Test inserting text in front of existing text in user-editable combobox.
924 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
925 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700926 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700927
928 // Select entire contents of user-editable combobox text field to check that
929 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700930 SelectTextWithMouse(183.0, 102.0, 62.0);
931 CheckSelection(L"HelloABCDEF");
Diana Gageab390972017-07-28 17:07:39 -0700932}
933
Lei Zhang839692f2017-08-25 23:23:57 -0700934TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
935 InsertTextInPopulatedEditableComboBoxMiddle) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700936 TypeTextIntoTextField(6, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700937
938 // Click on the middle of the user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700939 ClickOnFormFieldAtPoint(126.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700940
941 // Test inserting text in the middle of existing text in user-editable
942 // combobox.
943 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
944 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700945 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700946
947 // Select entire contents of user-editable combobox text field to check that
948 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700949 SelectTextWithMouse(183.0, 102.0, 62.0);
950 CheckSelection(L"ABCHelloDEF");
Diana Gageab390972017-07-28 17:07:39 -0700951}
952
Lei Zhang839692f2017-08-25 23:23:57 -0700953TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
954 InsertTextInPopulatedEditableComboBoxRight) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700955 TypeTextIntoTextField(6, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700956
957 // Click on the rightmost part of the user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700958 ClickOnFormFieldAtPoint(150.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700959
960 // Test inserting text behind existing text in user-editable combobox.
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 user-editable combobox text field to check that
966 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700967 SelectTextWithMouse(183.0, 102.0, 62.0);
968 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -0700969}
970
Lei Zhang839692f2017-08-25 23:23:57 -0700971TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700972 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700973 TypeTextIntoTextField(10, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700974
975 // Select entire string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700976 SelectTextWithKeyboard(10, FWL_VKEY_Left, 183.0, 62.0);
977 CheckSelection(L"ABCDEFGHIJ");
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 user-editable combobox text field to check that
985 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700986 SelectTextWithMouse(183.0, 102.0, 62.0);
987 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700988}
989
Lei Zhang839692f2017-08-25 23:23:57 -0700990TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700991 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -0700992 TypeTextIntoTextField(10, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700993
994 // Select left portion of string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700995 SelectTextWithKeyboard(5, FWL_VKEY_Left, 142.0, 62.0);
996 CheckSelection(L"ABCDE");
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 user-editable combobox text field to check that
1004 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001005 SelectTextWithMouse(183.0, 102.0, 62.0);
1006 CheckSelection(L"HelloFGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001007}
1008
Lei Zhang839692f2017-08-25 23:23:57 -07001009TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001010 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001011 TypeTextIntoTextField(10, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -07001012
1013 // Select middle portion of string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -07001014 SelectTextWithKeyboard(5, FWL_VKEY_Left, 167.0, 62.0);
1015 CheckSelection(L"DEFGH");
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 user-editable combobox text field to check that
1023 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001024 SelectTextWithMouse(183.0, 102.0, 62.0);
1025 CheckSelection(L"ABCHelloIJ");
Diana Gageab390972017-07-28 17:07:39 -07001026}
1027
Lei Zhang839692f2017-08-25 23:23:57 -07001028TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001029 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001030 TypeTextIntoTextField(10, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -07001031
1032 // Select right portion of string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -07001033 SelectTextWithKeyboard(5, FWL_VKEY_Left, 183.0, 62.0);
1034 CheckSelection(L"FGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001035
1036 // Test replacing text selection with text to be inserted.
1037 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1038 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001039 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001040
1041 // Select entire contents of user-editable combobox text field to check that
1042 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001043 SelectTextWithMouse(183.0, 102.0, 62.0);
1044 CheckSelection(L"ABCDEHello");
Diana Gageab390972017-07-28 17:07:39 -07001045}
1046
Lei Zhang839692f2017-08-25 23:23:57 -07001047TEST_F(FPDFFormFillTextFormEmbeddertest,
1048 InsertTextInEmptyCharLimitTextFieldOverflow) {
Diana Gageab390972017-07-28 17:07:39 -07001049 // Click on the textfield.
Lei Zhang839692f2017-08-25 23:23:57 -07001050 ClickOnFormFieldAtPoint(195.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001051
1052 // Delete pre-filled contents of text field with char limit.
Lei Zhang839692f2017-08-25 23:23:57 -07001053 SelectTextWithMouse(195.0, 102.0, 60.0);
1054 CheckSelection(L"Elephant");
1055 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001056
1057 // Test inserting text into now empty text field so text to be inserted
1058 // exceeds the char limit and is cut off.
1059 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1060 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001061 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001062
1063 // Select entire contents of text field to check that insertion worked
1064 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001065 SelectTextWithMouse(195.0, 102.0, 60.0);
1066 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001067}
1068
Lei Zhang839692f2017-08-25 23:23:57 -07001069TEST_F(FPDFFormFillTextFormEmbeddertest,
1070 InsertTextInEmptyCharLimitTextFieldFit) {
Diana Gageab390972017-07-28 17:07:39 -07001071 // Click on the textfield.
Lei Zhang839692f2017-08-25 23:23:57 -07001072 ClickOnFormFieldAtPoint(195.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001073
1074 // Delete pre-filled contents of text field with char limit.
Lei Zhang839692f2017-08-25 23:23:57 -07001075 SelectTextWithMouse(195.0, 102.0, 60.0);
1076 CheckSelection(L"Elephant");
1077 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001078
1079 // Test inserting text into now empty text field so text to be inserted
1080 // exceeds the char limit and is cut off.
1081 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1082 GetFPDFWideString(L"Zebra");
Lei Zhang839692f2017-08-25 23:23:57 -07001083 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001084
1085 // Select entire contents of text field to check that insertion worked
1086 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001087 SelectTextWithMouse(195.0, 102.0, 60.0);
1088 CheckSelection(L"Zebra");
Diana Gageab390972017-07-28 17:07:39 -07001089}
1090
Lei Zhang839692f2017-08-25 23:23:57 -07001091TEST_F(FPDFFormFillTextFormEmbeddertest,
1092 InsertTextInPopulatedCharLimitTextFieldLeft) {
Diana Gageab390972017-07-28 17:07:39 -07001093 // Click on the leftmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001094 ClickOnFormFieldAtPoint(102.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001095
1096 // Test inserting text in front of existing text in text field.
1097 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1098 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001099 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001100
1101 // Select entire contents of text field to check that insertion worked
1102 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001103 SelectTextWithMouse(195.0, 102.0, 60.0);
1104 CheckSelection(L"HiElephant");
Diana Gageab390972017-07-28 17:07:39 -07001105}
1106
Lei Zhang839692f2017-08-25 23:23:57 -07001107TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001108 InsertTextInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001109 TypeTextIntoTextField(8, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001110
1111 // Click on the middle of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001112 ClickOnFormFieldAtPoint(134.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001113
1114 // Test inserting text in the middle of existing text in text field.
1115 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1116 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001117 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001118
1119 // Select entire contents of text field to check that insertion worked
1120 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001121 SelectTextWithMouse(195.0, 102.0, 60.0);
1122 CheckSelection(L"ElephHiant");
Diana Gageab390972017-07-28 17:07:39 -07001123}
1124
Lei Zhang839692f2017-08-25 23:23:57 -07001125TEST_F(FPDFFormFillTextFormEmbeddertest,
1126 InsertTextInPopulatedCharLimitTextFieldRight) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001127 TypeTextIntoTextField(8, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001128
1129 // Click on the rightmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001130 ClickOnFormFieldAtPoint(166.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001131
1132 // Test inserting text behind existing text in text field.
1133 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1134 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001135 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001136
1137 // Select entire contents of text field to check that insertion worked
1138 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001139 SelectTextWithMouse(195.0, 102.0, 60.0);
1140 CheckSelection(L"ElephantHi");
Diana Gageab390972017-07-28 17:07:39 -07001141}
1142
Lei Zhang839692f2017-08-25 23:23:57 -07001143TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001144 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001145 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001146
1147 // Select entire string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001148 SelectTextWithKeyboard(12, FWL_VKEY_Left, 195.0, 60.0);
1149 CheckSelection(L"Elephant");
Diana Gageab390972017-07-28 17:07:39 -07001150
1151 // Test replacing text selection with text to be inserted.
1152 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1153 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001154 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001155
1156 // Select entire contents of text field to check that insertion worked
1157 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001158 SelectTextWithMouse(195.0, 102.0, 60.0);
1159 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001160}
1161
Lei Zhang839692f2017-08-25 23:23:57 -07001162TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001163 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001164 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001165
1166 // Select left portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001167 SelectTextWithKeyboard(4, FWL_VKEY_Left, 122.0, 60.0);
1168 CheckSelection(L"Elep");
Diana Gageab390972017-07-28 17:07:39 -07001169
1170 // Test replacing text selection with text to be inserted.
1171 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1172 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001173 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001174
1175 // Select entire contents of text field to check that insertion worked
1176 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001177 SelectTextWithMouse(195.0, 102.0, 60.0);
1178 CheckSelection(L"Hippophant");
Diana Gageab390972017-07-28 17:07:39 -07001179}
1180
Lei Zhang839692f2017-08-25 23:23:57 -07001181TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001182 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001183 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001184
1185 // Select middle portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001186 SelectTextWithKeyboard(4, FWL_VKEY_Left, 136.0, 60.0);
1187 CheckSelection(L"epha");
Diana Gageab390972017-07-28 17:07:39 -07001188
1189 // Test replacing text selection with text to be inserted.
1190 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1191 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001192 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001193
1194 // Select entire contents of text field to check that insertion worked
1195 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001196 SelectTextWithMouse(195.0, 102.0, 60.0);
1197 CheckSelection(L"ElHippopnt");
Diana Gageab390972017-07-28 17:07:39 -07001198}
1199
Lei Zhang839692f2017-08-25 23:23:57 -07001200TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001201 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) {
Lei Zhang7bec2ff2017-08-25 23:28:23 -07001202 TypeTextIntoTextField(12, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001203
1204 // Select right portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001205 SelectTextWithKeyboard(4, FWL_VKEY_Left, 152.0, 60.0);
1206 CheckSelection(L"hant");
Diana Gageab390972017-07-28 17:07:39 -07001207
1208 // Test replacing text selection with text to be inserted.
1209 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1210 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001211 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001212
1213 // Select entire contents of text field to check that insertion worked
1214 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001215 SelectTextWithMouse(195.0, 102.0, 60.0);
1216 CheckSelection(L"ElepHippop");
Diana Gageab390972017-07-28 17:07:39 -07001217}